diff --git a/frontend/src/utils/contracts.ts b/frontend/src/utils/contracts.ts index 052adbe..f12e664 100644 --- a/frontend/src/utils/contracts.ts +++ b/frontend/src/utils/contracts.ts @@ -6,6 +6,7 @@ import { Bridge as IBridge } from "../types/Bridge"; import { Bridge__factory } from "../types/factories/Bridge__factory"; import { ERC20__factory } from "../types/factories/ERC20__factory"; import { Provider } from '@ethersproject/providers'; +import { ERC20Handler__factory } from "../types/factories/ERC20Handler__factory"; export const getSNTEthereum = (provider: Provider) => getSNTContract(provider, SNT_ETHEREUM); export const getSNTAvalanche = (provider: Provider) => getSNTContract(provider, SNT_AVALANCHE); @@ -21,3 +22,7 @@ export const getSetBalance = async (token: ERC20|undefined, account: string, set const balance = await token?.balanceOf(account); setState(balance); } + +export const getERC20Handler = (address: string, provider: Provider) => { + return ERC20Handler__factory.connect(address, provider) +} diff --git a/frontend/src/utils/events.ts b/frontend/src/utils/events.ts index fed5daa..b7febd9 100644 --- a/frontend/src/utils/events.ts +++ b/frontend/src/utils/events.ts @@ -1,21 +1,29 @@ import { Bridge as IBridge } from "../types/Bridge"; +import { ERC20Handler } from "../types/ERC20Handler"; +import { getERC20Handler } from "./contracts"; import { Event } from "ethers"; export interface EnrichedEvent extends Event { - decoded?: Array + decoded?: Array, + depositRecord?: object } export const getDepositEvents = async (ethereumBridge: IBridge|undefined, setState: Function) => { if(!ethereumBridge) return const events = ethereumBridge.filters.Deposit(null,null,null) const deposits: Event[] = await ethereumBridge.queryFilter(events) - const enriched = deposits.map(d => { + const enriched = deposits.map(async d => { const { data, topics, decode } = d if (!decode) return const decoded = decode(data, topics) const newD: EnrichedEvent = d newD.decoded = decoded + const handlerAddress = await ethereumBridge._resourceIDToHandlerAddress(decoded.resourceID) + const erc20Handler: ERC20Handler = getERC20Handler(handlerAddress, ethereumBridge.provider); + const depositRecord = await erc20Handler._depositRecords(decoded.destinationChainID, decoded.depositNonce); + newD.depositRecord = depositRecord; return newD }) - setState(enriched) + const resolved = await Promise.all(enriched) + setState(resolved) }