From 68db058782a779139769e267273426ec11d71402 Mon Sep 17 00:00:00 2001 From: Alex Coseru Date: Sun, 20 Feb 2022 14:36:26 +0200 Subject: [PATCH] dispenser updates (#341) --- src/mappings/dispenser.ts | 11 +++-------- src/mappings/utils/dispenserUtils.ts | 15 ++++++++++----- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/mappings/dispenser.ts b/src/mappings/dispenser.ts index 2a63cec..98ecc79 100644 --- a/src/mappings/dispenser.ts +++ b/src/mappings/dispenser.ts @@ -11,7 +11,7 @@ import { decimal } from './utils/constants' import { getDispenser, getDispenserGraphID, - updateDispenserBalance + updateDispenserDetails } from './utils/dispenserUtils' import { weiToDecimal } from './utils/generic' import { addDispenser } from './utils/globalUtils' @@ -45,6 +45,7 @@ export function handleNewDispenser(event: DispenserCreated): void { dispenser.save() addDispenser() + updateDispenserDetails(event.address, event.params.datatokenAddress) } export function handleActivate(event: DispenserActivated): void { @@ -88,13 +89,7 @@ export function handleTokensDispensed(event: TokensDispensed): void { const dispenserTransaction = new DispenserTransaction(id) const dispenser = getDispenser(dispenserID) - dispenser.balance = updateDispenserBalance( - event.address, - event.params.datatokenAddress - ) - - dispenser.save() - + updateDispenserDetails(event.address, event.params.datatokenAddress) dispenserTransaction.dispenser = dispenser.id const user = getUser(event.params.userAddress.toHex()) dispenserTransaction.user = user.id diff --git a/src/mappings/utils/dispenserUtils.ts b/src/mappings/utils/dispenserUtils.ts index 6be37ec..3ddeafb 100644 --- a/src/mappings/utils/dispenserUtils.ts +++ b/src/mappings/utils/dispenserUtils.ts @@ -1,6 +1,6 @@ import { Dispenser } from '../../@types/schema' import { getToken } from './tokenUtils' -import { Address, BigDecimal } from '@graphprotocol/graph-ts' +import { Address } from '@graphprotocol/graph-ts' import { weiToDecimal } from './generic' import { Dispenser as DispenserContract } from '../../@types/Dispenser/Dispenser' @@ -25,16 +25,21 @@ export function getDispenser(dispenserID: string): Dispenser { return dispenser } -export function updateDispenserBalance( +export function updateDispenserDetails( contractAddress: Address, datatokenAddress: Address -): BigDecimal { +): void { + const dispenserID = getDispenserGraphID(contractAddress, datatokenAddress) + const dispenser = getDispenser(dispenserID) const contract = DispenserContract.bind(contractAddress) const dispenserDetails = contract.try_status(datatokenAddress) - if (dispenserDetails == null) return BigDecimal.fromString('0') + if (dispenserDetails == null) return const token = getToken(datatokenAddress, true) - return weiToDecimal( + dispenser.balance = weiToDecimal( dispenserDetails.value.value5.toBigDecimal(), token.decimals ) + dispenser.isMinter = dispenserDetails.value.value2 + dispenser.active = dispenserDetails.value.value0 + dispenser.save() }