Skip to content

Commit

Permalink
Iterate over all user addresses in listenForTransactions
Browse files Browse the repository at this point in the history
  • Loading branch information
ccali11 committed Jun 27, 2023
1 parent cbfe641 commit aa9978f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 10 deletions.
21 changes: 14 additions & 7 deletions apps/web/src/composables/contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,14 +224,21 @@ export default function useContracts() {
}

async function setUserContractTotals(eventTotals: any) {
const exchangeCurrentStaked = eventTotals.StakeDeposited - eventTotals.WithdrawalInitiated
const usdCurrentStaked = exchangeCurrentStaked * (await getCurrentPrice({ coin: 'ETH', currency: 'USD' }))
const exchangeCurrentStakedRounded = Math.round(exchangeCurrentStaked * 100) / 100
const usdCurrentStakedRounded = Math.round(usdCurrentStaked * 100) / 100
currentStaked.value = {
exchange: exchangeCurrentStakedRounded.toString() + ' ETH',
usd: '$ ' + usdCurrentStakedRounded
/* CurrentStaked */
if (eventTotals.StakeDeposited > 0) {
const exchangeCurrentStaked = eventTotals.StakeDeposited - eventTotals.WithdrawalInitiated
const usdCurrentStaked = exchangeCurrentStaked * (await getCurrentPrice({ coin: 'ETH', currency: 'USD' }))
const exchangeCurrentStakedRounded = Math.round(exchangeCurrentStaked * 100) / 100
const usdCurrentStakedRounded = Math.round(usdCurrentStaked * 100) / 100
currentStaked.value = {
exchange: exchangeCurrentStakedRounded.toString() + ' ETH',
usd: '$ ' + usdCurrentStakedRounded
}
}

/* Staking Rewards */

/* TotalDeposited */
}

// TODO: Add listener / subscription "StakeRebalanced(uint256 amount)" (to composable somewhere)
Expand Down
20 changes: 17 additions & 3 deletions apps/web/src/composables/ethers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,25 @@ export default function useEthers() {
const promises = [] as Array<Promise<any>>
transactions.map((tx) => {
if (addresses.includes(tx.from.toLowerCase())) {
promises.push(getUserContractEventsTotals(tx.from as string))
// TODO: Replace this with a method called RefreshUserContractTotals
user.value?.accounts?.forEach((account: Account) => {
const { address } = account
promises.push(getUserContractEventsTotals(address))
})
}
})
const userEventTotals = (await Promise.all(promises)).reduce((acc, curr) => {
return {
StakeDeposited: acc.StakeDeposited + curr.StakeDeposited,
StakeRebalanced: acc.StakeRebalanced + curr.StakeRebalanced,
WithdrawalInitiated: acc.WithdrawalInitiated + curr.WithdrawalInitiated,
}
}, {
StakeDeposited: 0,
StakeRebalanced: 0,
WithdrawalInitiated: 0,
})
const userEventTotals = await Promise.all(promises)
if (userEventTotals.length > 0) await setUserContractTotals(userEventTotals[0])
await setUserContractTotals(userEventTotals)
})
await new Promise(() => {
// Wait indefinitely using a Promise that never resolves
Expand Down

0 comments on commit aa9978f

Please sign in to comment.