Skip to content

Commit

Permalink
chore: fetch inside try
Browse files Browse the repository at this point in the history
  • Loading branch information
Keyrxng committed Feb 20, 2024
1 parent ebd54e1 commit 7fab1b4
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions static/scripts/rewards/web3/erc20-permit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ import { insertErc20PermitTableData } from "../render-transaction/insert-table-d
export async function processERC20(tokenAddress: string, provider: JsonRpcProvider, permit: Erc20Permit, table: Element) {
let symbol = tokenAddress === tokens[0].address ? tokens[0].name : tokenAddress === tokens[1].address ? tokens[1].name : "";
let decimals = tokenAddress === tokens[0].address ? 18 : tokenAddress === tokens[1].address ? 18 : -1;
const contract = await getErc20Contract(tokenAddress, provider);

if (!symbol || decimals === -1) {
try {
const contract = await getErc20Contract(tokenAddress, provider);
symbol = contract.symbol();
decimals = contract.decimals();
} catch (err) {
Expand All @@ -29,16 +29,15 @@ export async function processERC20(tokenAddress: string, provider: JsonRpcProvid
}

export async function fetchTreasury(contractAddr: string, owner: string, provider: JsonRpcProvider) {
const contract = await getErc20Contract(contractAddr, provider);

try {
const contract = await getErc20Contract(contractAddr, provider);
const [balance, allowance] = await Promise.all([contract.balanceOf(owner), contract.allowance(owner, permit2Address)]);
return { balance, allowance } as { balance: BigNumber; allowance: BigNumber };
} catch (err) {
console.log(err);
console.log(contractAddr);
throw new Error(`Error fetching treasury data for token address: ${contractAddr}`);
}

return { balance: BigNumber.from(0), allowance: BigNumber.from(0) };
}

export function claimErc20PermitHandler(permit: Erc20Permit, provider: JsonRpcProvider) {
Expand Down

0 comments on commit 7fab1b4

Please sign in to comment.