Skip to content

Commit 64034c0

Browse files
committed
Dashboard: Fix Token Rewards UI not accounting for token decimals (#8164)
<!-- ## title your PR with this format: "[SDK/Dashboard/Portal] Feature/Fix: Concise title for the changes" If you did not copy the branch name from Linear, paste the issue tag here (format is TEAM-0000): ## Notes for the reviewer Anything important to call out? Be sure to also clarify these in your comments. ## How to test Unit tests, playground, etc. --> <!-- start pr-codex --> --- ## PR-Codex overview This PR focuses on enhancing the handling of token rewards by adding `decimals` properties for tokens in various components and improving the retrieval of metadata related to tokens. ### Detailed summary - Added `decimals` property to `token0` and `token1` in `claim-rewards-page.stories.tsx`. - Introduced `chainMetadata` in `page.tsx`. - Updated `ClaimRewardsPageUI` to utilize `decimals` for token amounts. - Refactored `getUnclaimedFees` to fetch `decimals` and `symbol` for tokens. - Improved token contract retrieval logic in `getUnclaimedFees`. > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` <!-- end pr-codex --> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - New Features - Token amounts now display using each token’s specific decimals. - Chain metadata is passed to unclaimed-fees retrieval to source native token symbol and decimals. - Bug Fixes - Removed hardcoded 18-decimal assumption so amounts render correctly for tokens with different precisions. - Tests - Story/test stubs updated to include decimals for token objects for more realistic scenarios. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent 90c1e57 commit 64034c0

File tree

4 files changed

+58
-18
lines changed

4 files changed

+58
-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: 47 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
import type { ThirdwebContract } from "thirdweb";
2-
import { getContract, readContract } from "thirdweb";
2+
import { getAddress, getContract, readContract, ZERO_ADDRESS } from "thirdweb";
3+
import type { ChainMetadata } from "thirdweb/chains";
34
import { symbol } from "thirdweb/extensions/common";
5+
import { decimals } from "thirdweb/extensions/erc20";
46

57
const maxUint128 = 2n ** 128n - 1n;
68

79
export async function getUnclaimedFees(params: {
810
positionManager: ThirdwebContract;
11+
chainMetadata: ChainMetadata;
912
reward: {
1013
tokenId: bigint;
1114
recipient: string;
@@ -56,33 +59,60 @@ export async function getUnclaimedFees(params: {
5659
const token0Address = positionsResult[2];
5760
const token1Address = positionsResult[3];
5861

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-
]);
62+
const token0Contract = getContract({
63+
address: token0Address,
64+
chain,
65+
client,
66+
});
67+
68+
const token1Contract = getContract({
69+
address: token1Address,
70+
chain,
71+
client,
72+
});
73+
74+
const isToken0Native = getAddress(token0Address) === getAddress(ZERO_ADDRESS);
75+
const isToken1Native = getAddress(token1Address) === getAddress(ZERO_ADDRESS);
76+
77+
const nativeSymbol = params.chainMetadata.nativeCurrency.symbol;
78+
const nativeDecimals = params.chainMetadata.nativeCurrency.decimals;
79+
80+
const [token0Symbol, token1Symbol, token0Decimals, token1Decimals] =
81+
await Promise.all([
82+
isToken0Native
83+
? nativeSymbol
84+
: symbol({
85+
contract: token0Contract,
86+
}),
87+
isToken1Native
88+
? nativeSymbol
89+
: symbol({
90+
contract: token1Contract,
91+
}),
92+
isToken0Native
93+
? nativeDecimals
94+
: decimals({
95+
contract: token0Contract,
96+
}),
97+
isToken1Native
98+
? nativeDecimals
99+
: decimals({
100+
contract: token1Contract,
101+
}),
102+
]);
75103

76104
return {
77105
token0: {
78106
address: token0Address,
79107
amount: collectResult[0],
80108
symbol: token0Symbol,
109+
decimals: token0Decimals,
81110
},
82111
token1: {
83112
address: token1Address,
84113
amount: collectResult[1],
85114
symbol: token1Symbol,
115+
decimals: token1Decimals,
86116
},
87117
};
88118
}

0 commit comments

Comments
 (0)