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") sharesOwned: [PoolShare!] @derivedFrom(field: "userAddress")
tokenBalancesOwned: [TokenBalance!] @derivedFrom(field: "userAddress") tokenBalancesOwned: [TokenBalance!] @derivedFrom(field: "userAddress")
tokensOwned: [Datatoken!] @derivedFrom(field: "minter") tokensOwned: [Datatoken!] @derivedFrom(field: "minter")
nrSales: Int
poolTransactions: [PoolTransaction!] @derivedFrom(field: "userAddress") poolTransactions: [PoolTransaction!] @derivedFrom(field: "userAddress")
poolTransactionsTokenValues: [PoolTransactionTokenValues!] poolTransactionsTokenValues: [PoolTransactionTokenValues!]
@derivedFrom(field: "userAddress") @derivedFrom(field: "userAddress")

View File

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

View File

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