Skip to content

Commit

Permalink
refactor: only ask the rpc if everything fails
Browse files Browse the repository at this point in the history
  • Loading branch information
fborello-lambda committed Aug 5, 2024
1 parent e35f14a commit 7a26484
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions store/zksync/tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,16 @@ export const useZkSyncTokensStore = defineStore("zkSyncTokens", () => {
};
}

const btL1Address = await provider.getBaseTokenContractAddress();
if (btL1Address !== utils.ETH_ADDRESS) {
const l1Rpc = useNetworkStore();
const l1Provider = new ethers.providers.JsonRpcProvider(l1Rpc.l1Network?.rpcUrls.default.http[0]);
const walletEthers = ethers.Wallet.createRandom();
const connectedWallet = walletEthers.connect(l1Provider);
const ERC20_L1 = new ethers.Contract(btL1Address, IERC20, connectedWallet);
const ERC20_SYMBOL: string = (await ERC20_L1.symbol()) || "BT";
const ERC20_DECIMALS = (await ERC20_L1.decimals()) || 18;
if (!baseToken) {
if (!baseToken) {
const btL1Address = await provider.getBaseTokenContractAddress();
if (btL1Address !== utils.ETH_ADDRESS) {
const l1Rpc = useNetworkStore();
const l1Provider = new ethers.providers.JsonRpcProvider(l1Rpc.l1Network?.rpcUrls.default.http[0]);
const walletEthers = ethers.Wallet.createRandom();
const connectedWallet = walletEthers.connect(l1Provider);
const ERC20_L1 = new ethers.Contract(btL1Address, IERC20, connectedWallet);
const ERC20_SYMBOL: string = (await ERC20_L1.symbol()) || "BT";
const ERC20_DECIMALS = (await ERC20_L1.decimals()) || 18;
baseToken = {
address: L2_BASE_TOKEN_ADDRESS,
l1Address: btL1Address,
Expand All @@ -78,13 +78,11 @@ export const useZkSyncTokensStore = defineStore("zkSyncTokens", () => {
decimals: ERC20_DECIMALS,
iconUrl: "/img/era.svg",
};
} else {
baseToken = ethToken;
}
}

if (!baseToken) {
baseToken = ethToken;
}

const tokens = explorerTokens.length ? explorerTokens : configTokens;
let nonBaseOrEthExplorerTokens: Token[] = [];
if (tokens) {
Expand Down

0 comments on commit 7a26484

Please sign in to comment.