Skip to content

Commit ed38a20

Browse files
author
fborello-lambda
committed
refactor: only ask the rpc if everything fails
1 parent e35f14a commit ed38a20

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

store/zksync/tokens.ts

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -61,27 +61,23 @@ export const useZkSyncTokensStore = defineStore("zkSyncTokens", () => {
6161
}
6262

6363
const btL1Address = await provider.getBaseTokenContractAddress();
64-
if (btL1Address !== utils.ETH_ADDRESS) {
64+
if (btL1Address !== utils.ETH_ADDRESS && !baseToken) {
6565
const l1Rpc = useNetworkStore();
6666
const l1Provider = new ethers.providers.JsonRpcProvider(l1Rpc.l1Network?.rpcUrls.default.http[0]);
6767
const walletEthers = ethers.Wallet.createRandom();
6868
const connectedWallet = walletEthers.connect(l1Provider);
6969
const ERC20_L1 = new ethers.Contract(btL1Address, IERC20, connectedWallet);
7070
const ERC20_SYMBOL: string = (await ERC20_L1.symbol()) || "BT";
7171
const ERC20_DECIMALS = (await ERC20_L1.decimals()) || 18;
72-
if (!baseToken) {
73-
baseToken = {
74-
address: L2_BASE_TOKEN_ADDRESS,
75-
l1Address: btL1Address,
76-
symbol: ERC20_SYMBOL,
77-
name: ERC20_SYMBOL,
78-
decimals: ERC20_DECIMALS,
79-
iconUrl: "/img/era.svg",
80-
};
81-
}
82-
}
83-
84-
if (!baseToken) {
72+
baseToken = {
73+
address: L2_BASE_TOKEN_ADDRESS,
74+
l1Address: btL1Address,
75+
symbol: ERC20_SYMBOL,
76+
name: ERC20_SYMBOL,
77+
decimals: ERC20_DECIMALS,
78+
iconUrl: "/img/era.svg",
79+
};
80+
} else {
8581
baseToken = ethToken;
8682
}
8783

0 commit comments

Comments
 (0)