From 44e73ae56ffa1995671faeeed4468210a778cf45 Mon Sep 17 00:00:00 2001 From: yuetloo Date: Wed, 28 Jun 2023 23:36:00 -0230 Subject: [PATCH 1/4] fix incorrect formatAmount when token decimals is not 18 --- vue-app/src/api/claims.ts | 6 +++--- vue-app/src/api/factory.ts | 12 +++++------ vue-app/src/api/round.ts | 20 +++++++++---------- vue-app/src/components/ClaimButton.vue | 7 +++---- vue-app/src/components/MatchingFundsModal.vue | 2 +- vue-app/src/components/RoundInformation.vue | 4 ++-- vue-app/src/stores/app.ts | 6 +++--- vue-app/src/utils/amounts.ts | 4 ++-- vue-app/src/views/TransactionSuccess.vue | 6 ++++-- 9 files changed, 34 insertions(+), 33 deletions(-) diff --git a/vue-app/src/api/claims.ts b/vue-app/src/api/claims.ts index 45e306865..82da4d757 100644 --- a/vue-app/src/api/claims.ts +++ b/vue-app/src/api/claims.ts @@ -1,4 +1,4 @@ -import { Contract, FixedNumber } from 'ethers' +import { Contract, BigNumber } from 'ethers' import sdk from '@/graphql/sdk' import { FundingRound } from './abi' @@ -9,10 +9,10 @@ export async function getAllocatedAmount( tokenDecimals: number, result: string, spent: string, -): Promise { +): Promise { const fundingRound = new Contract(fundingRoundAddress, FundingRound, provider) const allocatedAmount = await fundingRound.getAllocatedAmount(result, spent) - return FixedNumber.fromValue(allocatedAmount, tokenDecimals) + return allocatedAmount } export async function isFundsClaimed( diff --git a/vue-app/src/api/factory.ts b/vue-app/src/api/factory.ts index 2b7c4122c..32ea5795d 100644 --- a/vue-app/src/api/factory.ts +++ b/vue-app/src/api/factory.ts @@ -1,4 +1,4 @@ -import { FixedNumber } from 'ethers' +import { BigNumber } from 'ethers' import { factory } from './core' import sdk from '@/graphql/sdk' @@ -8,14 +8,14 @@ export interface Factory { nativeTokenSymbol: string nativeTokenDecimals: number userRegistryAddress: string - matchingPool: FixedNumber + matchingPool: BigNumber } export async function getFactoryInfo() { let nativeTokenAddress = '' let nativeTokenSymbol = '' let nativeTokenDecimals = 0 - let matchingPool = FixedNumber.from(0) + let matchingPool = BigNumber.from(0) let userRegistryAddress = '' let recipientRegistryAddress = '' @@ -39,7 +39,7 @@ export async function getFactoryInfo() { } try { - matchingPool = await getMatchingFunds(nativeTokenAddress, nativeTokenDecimals) + matchingPool = await getMatchingFunds(nativeTokenAddress) } catch (err) { /* eslint-disable-next-line no-console */ console.error('Failed to get matching pool', err) @@ -56,7 +56,7 @@ export async function getFactoryInfo() { } } -export async function getMatchingFunds(nativeTokenAddress: string, nativeTokenDecimals: number): Promise { +export async function getMatchingFunds(nativeTokenAddress: string): Promise { const matchingFunds = await factory.getMatchingFunds(nativeTokenAddress) - return FixedNumber.fromValue(matchingFunds, nativeTokenDecimals) + return matchingFunds } diff --git a/vue-app/src/api/round.ts b/vue-app/src/api/round.ts index e3299a577..ba6fc3e5c 100644 --- a/vue-app/src/api/round.ts +++ b/vue-app/src/api/round.ts @@ -1,4 +1,4 @@ -import { BigNumber, Contract, utils, FixedNumber } from 'ethers' +import { BigNumber, Contract, utils } from 'ethers' import { DateTime } from 'luxon' import { PubKey } from '@clrfund/maci-utils' @@ -30,9 +30,9 @@ export interface RoundInfo { startTime: DateTime signUpDeadline: DateTime votingDeadline: DateTime - totalFunds: FixedNumber - matchingPool: FixedNumber - contributions: FixedNumber + totalFunds: BigNumber + matchingPool: BigNumber + contributions: BigNumber contributors: number messages: number blogUrl?: string @@ -103,9 +103,9 @@ function toRoundInfo(data: any, network: string): RoundInfo { startTime: DateTime.fromSeconds(data.startTime), signUpDeadline: DateTime.fromSeconds(Number(data.startTime) + Number(data.signUpDuration)), votingDeadline: DateTime.fromSeconds(Number(data.startTime) + Number(data.votingDuration)), - totalFunds: FixedNumber.fromValue(totalFunds, nativeTokenDecimals), - matchingPool: FixedNumber.fromValue(matchingPool, nativeTokenDecimals), - contributions: FixedNumber.fromValue(contributions, nativeTokenDecimals), + totalFunds, + matchingPool, + contributions, contributors: data.contributorCount, messages: Number(data.messages), blogUrl: data.blogUrl, @@ -240,9 +240,9 @@ export async function getRoundInfo( startTime, signUpDeadline, votingDeadline, - totalFunds: FixedNumber.fromValue(totalFunds, nativeTokenDecimals), - matchingPool: FixedNumber.fromValue(matchingPool, nativeTokenDecimals), - contributions: FixedNumber.fromValue(contributions, nativeTokenDecimals), + totalFunds, + matchingPool, + contributions, contributors, messages: messages.toNumber(), } diff --git a/vue-app/src/components/ClaimButton.vue b/vue-app/src/components/ClaimButton.vue index 12f554ec2..6eff26bb5 100644 --- a/vue-app/src/components/ClaimButton.vue +++ b/vue-app/src/components/ClaimButton.vue @@ -27,13 +27,12 @@