Skip to content

Commit fdc7f76

Browse files
committed
fix: use currency metadata helper
1 parent f1b25e6 commit fdc7f76

File tree

1 file changed

+17
-40
lines changed

1 file changed

+17
-40
lines changed

apps/dashboard/src/app/checkout/page.tsx

Lines changed: 17 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ import {
77
getContract,
88
NATIVE_TOKEN_ADDRESS,
99
} from "thirdweb";
10-
import { name, symbol } from "thirdweb/extensions/common";
11-
import { decimals } from "thirdweb/extensions/erc20";
10+
import { getCurrencyMetadata } from "thirdweb/extensions/erc20";
1211
import { checksumAddress } from "thirdweb/utils";
1312
import { CheckoutEmbed } from "./components/client/CheckoutEmbed.client";
1413

@@ -47,7 +46,6 @@ export default async function RoutesPage({
4746
}
4847
if (!amount || Array.isArray(amount)) {
4948
throw new Error("A single amount parameter is required.");
50-
5149
}
5250
if (Array.isArray(clientId)) {
5351
throw new Error("A single clientId parameter is required.");
@@ -62,43 +60,22 @@ export default async function RoutesPage({
6260
? createThirdwebClient({ clientId })
6361
: getThirdwebClient(undefined);
6462

65-
const token = await (async () => {
66-
if (
67-
checksumAddress(tokenAddress) ===
68-
"0x0000000000000000000000000000000000000000" ||
69-
checksumAddress(tokenAddress) ===
70-
"0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE"
71-
) {
72-
return {
73-
name: "Ether",
74-
symbol: "ETH",
75-
address: NATIVE_TOKEN_ADDRESS,
76-
decimals: 18,
77-
};
78-
} else {
79-
const tokenContract = getContract({
80-
client,
81-
// eslint-disable-next-line no-restricted-syntax
82-
chain: defineChain(Number(chainId)),
83-
address: tokenAddress,
84-
});
85-
const symbolPromise = symbol({ contract: tokenContract });
86-
const namePromise = name({ contract: tokenContract });
87-
const decimalsPromise = decimals({ contract: tokenContract });
88-
89-
const [symbolResult, nameResult, decimalsResult] = await Promise.all([
90-
symbolPromise,
91-
namePromise,
92-
decimalsPromise,
93-
]);
94-
return {
95-
name: nameResult,
96-
symbol: symbolResult,
97-
address: tokenAddress,
98-
decimals: Number(decimalsResult),
99-
};
100-
}
101-
})();
63+
const tokenContract = getContract({
64+
client,
65+
// eslint-disable-next-line no-restricted-syntax
66+
chain: defineChain(Number(chainId)),
67+
address: tokenAddress,
68+
});
69+
const { symbol, decimals, name } = await getCurrencyMetadata({
70+
contract: tokenContract,
71+
});
72+
const token = {
73+
symbol,
74+
decimals,
75+
name,
76+
address: checksumAddress(tokenAddress),
77+
chainId: Number(chainId),
78+
};
10279

10380
return (
10481
<div className="relative mx-auto flex h-screen w-screen flex-col items-center justify-center overflow-hidden border py-10">

0 commit comments

Comments
 (0)