add nr of sales for user (#231)

This commit is contained in:
mihaisc 2021-10-05 13:51:47 +03:00 committed by GitHub
parent 1abd5324a4
commit ec0c282658
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 1 deletions

View File

@ -214,6 +214,7 @@ type User @entity {
sharesOwned: [PoolShare!] @derivedFrom(field: "userAddress")
tokenBalancesOwned: [TokenBalance!] @derivedFrom(field: "userAddress")
tokensOwned: [Datatoken!] @derivedFrom(field: "minter")
nrSales: Int
poolTransactions: [PoolTransaction!] @derivedFrom(field: "userAddress")
poolTransactionsTokenValues: [PoolTransactionTokenValues!]
@derivedFrom(field: "userAddress")

View File

@ -237,6 +237,7 @@ export function updatePoolSwapVolume(
export function createUserEntity(address: string): void {
if (User.load(address) == null) {
const user = new User(address)
user.nrSales = 0
user.save()
}
}

View File

@ -6,7 +6,8 @@ import {
Global,
PoolFactory,
TokenBalance,
TokenOrder
TokenOrder,
User
} from '../@types/schema'
import {
tokenToDecimal,
@ -155,6 +156,11 @@ export function handleOrderStarted(event: OrderStarted): void {
factory.orderCount = factory.orderCount.plus(BigInt.fromI32(1))
factory.totalOrderVolume = factory.totalOrderVolume.plus(order.amount)
factory.save()
const user = User.load(datatoken.minter)
user.nrSales = user.nrSales + 1
user.save()
const gStats: Global | null = getGlobalStats()
gStats.orderCount = factory.orderCount
gStats.totalOrderVolume = factory.totalOrderVolume