Skip to content

Commit

Permalink
Fix issue with ERC20 balance check always hitting Polygon (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
taylanpince authored Jun 7, 2024
1 parent 0989289 commit dbb72c6
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions src/components/views/SendERC20View.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useEffect, useState } from 'react'
import { Box, Text, Button, TextInput, Spinner, Select } from '@0xsequence/design-system'
import { ethers } from 'ethers'
import { node, sequence } from '../../main'
import { sequence } from '../../main'
import { FeeOption, isSentTransactionResponse, Network, erc20 } from '@0xsequence/waas'
import { checkTransactionFeeOptions, TransactionFeeOptions } from './TransactionFeeOptions.tsx'

Expand Down Expand Up @@ -46,6 +46,7 @@ export function SendERC20View(props: { network?: Network }) {

setTokenBalance('...')

const node = new ethers.providers.JsonRpcProvider(`https://nodes.sequence.app/${props.network?.name}`)
const contract = new ethers.Contract(
tokenAddress,
[
Expand All @@ -56,14 +57,18 @@ export function SendERC20View(props: { network?: Network }) {
node
)

const [balance, decimals, symbol] = await Promise.all([
contract.balanceOf(sequence.getAddress()),
contract.decimals(),
contract.symbol()
])

setDecimals(decimals)
setTokenBalance(`${ethers.utils.formatUnits(balance, decimals)} ${symbol}`)
try {
const [balance, decimals, symbol] = await Promise.all([
contract.balanceOf(sequence.getAddress()),
contract.decimals(),
contract.symbol()
])

setDecimals(decimals)
setTokenBalance(`${ethers.utils.formatUnits(balance, decimals)} ${symbol}`)
} catch (e) {
setTokenBalance('---')
}
}

const checkFeeOptions = async () => {
Expand Down

0 comments on commit dbb72c6

Please sign in to comment.