Skip to content

Commit 74d7049

Browse files
committed
fix(web): fix page crash at the Payment step
1 parent 56f3da3 commit 74d7049

File tree

3 files changed

+33
-12
lines changed

3 files changed

+33
-12
lines changed

web/src/utils/fetchNativeToken.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
1-
export const fetchNativeToken = (chain) => {
1+
const CHAIN_NATIVE_TOKENS = {
2+
42161: 'ETH',
3+
421614: 'ETH',
4+
};
5+
6+
export const fetchNativeToken = (chainId: number) => {
7+
const symbol = CHAIN_NATIVE_TOKENS[chainId] || 'Unknown';
28
return {
3-
symbol: chain?.nativeCurrency?.symbol,
4-
address: "native",
9+
symbol: symbol,
10+
address: 'native',
511
};
612
};

web/src/utils/initializeTokens.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,27 @@ import { IToken } from "context/NewTransactionContext";
33
import { fetchNativeToken } from "./fetchNativeToken";
44
import { fetchTokenInfo } from "./fetchTokenInfo";
55

6-
export const initializeTokens = async (address: string, setTokens, setLoading, chain, alchemyInstance: Alchemy) => {
6+
export const initializeTokens = async (address: string, setTokens, setLoading, chainId: number, alchemyInstance: Alchemy) => {
77
try {
88
setLoading(true);
9-
const nativeToken = fetchNativeToken(chain);
9+
const nativeToken = fetchNativeToken(chainId);
1010
const balances = await alchemyInstance.core.getTokenBalances(address);
1111
const tokenList = await Promise.all(
1212
balances.tokenBalances.map(async (token) => {
1313
const tokenInfo = await fetchTokenInfo(token.contractAddress, alchemyInstance);
14-
return {
15-
symbol: tokenInfo.symbol,
16-
address: tokenInfo.address,
17-
logo: tokenInfo.logo,
18-
} as IToken;
14+
if (tokenInfo) {
15+
return {
16+
symbol: tokenInfo.symbol,
17+
address: tokenInfo.address,
18+
logo: tokenInfo.logo,
19+
} as IToken;
20+
}
21+
return null;
1922
})
2023
);
2124
const allTokens = [nativeToken, ...tokenList];
22-
const customTokens = JSON.parse(localStorage.getItem("tokens")) || [];
25+
const customTokensString = localStorage.getItem("tokens");
26+
const customTokens = customTokensString ? JSON.parse(customTokensString) : [];
2327
const combinedTokens = [
2428
...allTokens,
2529
...customTokens.filter((customToken) => !allTokens.some((token) => token.address === customToken.address)),

web/vite.config.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,26 @@ export default defineConfig({
77
root: "src",
88
build: {
99
outDir: "../dist",
10+
rollupOptions: {
11+
onwarn: (warning, warn) => {
12+
if (warning.code === "MODULE_LEVEL_DIRECTIVE") {
13+
return;
14+
}
15+
warn(warning);
16+
},
17+
},
1018
},
1119
envPrefix: ["REACT_APP", "ALCHEMY", "WALLETCONNECT_PROJECT_ID"],
1220
plugins: [
1321
svgr({
1422
include: ["**/*.svg", "tsx:**/*.svg"],
23+
exclude: ["../node_modules/**/*"],
1524
}),
1625
tsconfigPaths({
1726
ignoreConfigErrors: true,
1827
}),
19-
nodePolyfills(),
28+
nodePolyfills({
29+
include: ["fs", "stream"],
30+
}),
2031
],
2132
});

0 commit comments

Comments
 (0)