Skip to content

Commit 52537f1

Browse files
committed
Dashboard: Fix Token Rewards UI not accounting for token decimals
1 parent dbadc23 commit 52537f1

File tree

4 files changed

+65
-18
lines changed

4 files changed

+65
-18
lines changed

apps/dashboard/src/app/(app)/team/[team_slug]/[project_slug]/contract/[chainIdOrSlug]/[contractAddress]/rewards/components/claim-rewards-page.stories.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,13 @@ function unclaimedFeesStub(token0Amount: bigint, token1Amount: bigint) {
3030
address: "0x1234567890123456789012345678901234567890",
3131
amount: token0Amount,
3232
symbol: "FOO",
33+
decimals: 18,
3334
},
3435
token1: {
3536
address: "0x0987654321098765432109876543210987654321",
3637
amount: token1Amount,
3738
symbol: "BAR",
39+
decimals: 18,
3840
},
3941
};
4042
}

apps/dashboard/src/app/(app)/team/[team_slug]/[project_slug]/contract/[chainIdOrSlug]/[contractAddress]/rewards/components/claim-rewards-page.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,13 @@ export function ClaimRewardsPage(props: {
2929
address: string;
3030
amount: bigint;
3131
symbol: string;
32+
decimals: number;
3233
};
3334
token1: {
3435
address: string;
3536
amount: bigint;
3637
symbol: string;
38+
decimals: number;
3739
};
3840
};
3941
chainSlug: string;
@@ -98,11 +100,13 @@ export function ClaimRewardsPageUI(props: {
98100
address: string;
99101
amount: bigint;
100102
symbol: string;
103+
decimals: number;
101104
};
102105
token1: {
103106
address: string;
104107
amount: bigint;
105108
symbol: string;
109+
decimals: number;
106110
};
107111
};
108112
recipient: string;
@@ -275,6 +279,7 @@ function TokenReward(props: {
275279
address: string;
276280
amount: bigint;
277281
symbol: string;
282+
decimals: number;
278283
};
279284
client: ThirdwebClient;
280285
chain: Chain;
@@ -303,7 +308,8 @@ function TokenReward(props: {
303308
</div>
304309
<div className="space-y-0.5">
305310
<p className="font-bold text-sm">
306-
{toTokens(props.token.amount, 18)} {props.token.symbol}
311+
{toTokens(props.token.amount, props.token.decimals)}{" "}
312+
{props.token.symbol}
307313
</p>
308314
<Link
309315
target="_blank"

apps/dashboard/src/app/(app)/team/[team_slug]/[project_slug]/contract/[chainIdOrSlug]/[contractAddress]/rewards/page.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export default async function Page(props: {
3131
const chain = info.clientContract.chain;
3232
const assetContractServer = info.serverContract;
3333
const serverClient = assetContractServer.client;
34+
const chainMetadata = info.chainMetadata;
3435

3536
const { address: entrypointContractAddress } =
3637
await getDeployedEntrypointERC20({
@@ -56,6 +57,7 @@ export default async function Page(props: {
5657

5758
// Note: must use server contract/client here
5859
const unclaimedFees = await getUnclaimedFees({
60+
chainMetadata,
5961
positionManager: getContract({
6062
address: reward.positionManager,
6163
chain,

apps/dashboard/src/app/(app)/team/[team_slug]/[project_slug]/contract/[chainIdOrSlug]/[contractAddress]/rewards/utils/unclaimed-fees.ts

Lines changed: 54 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
11
import type { ThirdwebContract } from "thirdweb";
2-
import { getContract, readContract } from "thirdweb";
2+
import {
3+
getAddress,
4+
getContract,
5+
NATIVE_TOKEN_ADDRESS,
6+
readContract,
7+
} from "thirdweb";
8+
import type { ChainMetadata } from "thirdweb/chains";
39
import { symbol } from "thirdweb/extensions/common";
10+
import { decimals } from "thirdweb/extensions/erc20";
411

512
const maxUint128 = 2n ** 128n - 1n;
613

714
export async function getUnclaimedFees(params: {
815
positionManager: ThirdwebContract;
16+
chainMetadata: ChainMetadata;
917
reward: {
1018
tokenId: bigint;
1119
recipient: string;
@@ -56,33 +64,62 @@ export async function getUnclaimedFees(params: {
5664
const token0Address = positionsResult[2];
5765
const token1Address = positionsResult[3];
5866

59-
const [token0Symbol, token1Symbol] = await Promise.all([
60-
symbol({
61-
contract: getContract({
62-
address: token0Address,
63-
chain,
64-
client,
65-
}),
66-
}),
67-
symbol({
68-
contract: getContract({
69-
address: token1Address,
70-
chain,
71-
client,
72-
}),
73-
}),
74-
]);
67+
const token0Contract = getContract({
68+
address: token0Address,
69+
chain,
70+
client,
71+
});
72+
73+
const token1Contract = getContract({
74+
address: token1Address,
75+
chain,
76+
client,
77+
});
78+
79+
const isToken0Native =
80+
getAddress(token0Address) === getAddress(NATIVE_TOKEN_ADDRESS);
81+
const isToken1Native =
82+
getAddress(token1Address) === getAddress(NATIVE_TOKEN_ADDRESS);
83+
84+
const nativeSymbol = params.chainMetadata.nativeCurrency.symbol;
85+
const nativeDecimals = params.chainMetadata.nativeCurrency.decimals;
86+
87+
const [token0Symbol, token1Symbol, token0Decimals, token1Decimals] =
88+
await Promise.all([
89+
isToken0Native
90+
? nativeSymbol
91+
: symbol({
92+
contract: token0Contract,
93+
}),
94+
isToken1Native
95+
? nativeSymbol
96+
: symbol({
97+
contract: token1Contract,
98+
}),
99+
isToken0Native
100+
? nativeDecimals
101+
: decimals({
102+
contract: token0Contract,
103+
}),
104+
isToken1Native
105+
? nativeDecimals
106+
: decimals({
107+
contract: token1Contract,
108+
}),
109+
]);
75110

76111
return {
77112
token0: {
78113
address: token0Address,
79114
amount: collectResult[0],
80115
symbol: token0Symbol,
116+
decimals: token0Decimals,
81117
},
82118
token1: {
83119
address: token1Address,
84120
amount: collectResult[1],
85121
symbol: token1Symbol,
122+
decimals: token1Decimals,
86123
},
87124
};
88125
}

0 commit comments

Comments
 (0)