Skip to content

Commit

Permalink
adds reservedEth total
Browse files Browse the repository at this point in the history
  • Loading branch information
coffee-converter committed Nov 25, 2020
1 parent a188373 commit bdcd8cb
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
1 change: 1 addition & 0 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type User @entity {
transactions: [Transaction!]! @derivedFrom(field: "sender")
reservations: [Reservation!]! @derivedFrom(field: "user")
referrals: [Referral!]! @derivedFrom(field: "referrer")
reservedEth: BigInt!
referredEth: BigInt!
}

Expand Down
7 changes: 5 additions & 2 deletions src/mapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ function getOrCreateUser(id: string): User | null {
let user = User.load(id)
if (user == null) {
user = new User(id)
user.reservedEth = BigInt.fromI32(0)
user.referredEth = BigInt.fromI32(0)
}
return user
Expand Down Expand Up @@ -49,7 +50,7 @@ export function handleReferralAdded(event: ReferralAdded): void {
}
referral.save()

referrer.referredEth = referrer.referredEth.plus(event.params.amount)
referrer.referredEth = referrer.referredEth.plus(referral.amount)
referrer.save()
}

Expand All @@ -61,7 +62,6 @@ export function handleWiseReservation(event: WiseReservation): void {

let userID = event.transaction.from.toHexString()
let user = getOrCreateUser(userID)
user.save()

let reservationID = event.transaction.hash.toHexString() + "-" + event.params.investmentDay.toString()
let reservation = Reservation.load(reservationID)
Expand All @@ -73,6 +73,9 @@ export function handleWiseReservation(event: WiseReservation): void {
reservation.amount = event.params.amount
}
reservation.save()

user.reservedEth = user.reservedEth.plus(reservation.amount)
user.save()
}

/*
Expand Down

0 comments on commit bdcd8cb

Please sign in to comment.