Skip to content

Commit

Permalink
Use own price service (#1207)
Browse files Browse the repository at this point in the history
  • Loading branch information
zzq0826 authored Jul 27, 2024
1 parent a826e1e commit 554d0c0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/hooks/useTokenPrice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ const useTokenPrice = tokenList => {
const tokens = tokenList.filter(token => token.chainId === CHAIN_ID.L1 && token.address).map(token => token.address)
const tokenAddresses = tokens.join("%2C")

const fetchEthPrice = fetch(`https://api.coingecko.com/api/v3/simple/price?ids=ethereum&vs_currencies=usd`)
const fetchEthPrice = fetch(`https://token-price-api-inky.vercel.app/simple/price?ids=ethereum&vs_currencies=usd`)
const fetchErc20Price = fetch(
`https://api.coingecko.com/api/v3/simple/token_price/ethereum?contract_addresses=${tokenAddresses}&vs_currencies=usd`,
`https://token-price-api-inky.vercel.app/simple/token_price/ethereum?contract_addresses=${tokenAddresses}&vs_currencies=usd`,
)

const results = await Promise.allSettled([fetchEthPrice, fetchErc20Price])
Expand Down
7 changes: 4 additions & 3 deletions src/pages/bridge/Send/SendTransaction/TransactionSummary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ const TransactionSummary: FC<Props> = props => {

const getDisplayedPrice = useCallback(
(amount = "", tokenAddress = "ethereum") => {
if (allowDisplayValue && tokenPrice.price?.[tokenAddress.toLowerCase()]) {
return (+amount * tokenPrice.price[tokenAddress.toLowerCase()].usd).toFixed(2)
if (allowDisplayValue && tokenPrice.price?.[tokenAddress]) {
return (+amount * tokenPrice.price[tokenAddress].usd).toFixed(2)
}
return ""
},
Expand All @@ -96,7 +96,8 @@ const TransactionSummary: FC<Props> = props => {
getDisplayedValue((l1GasFee ?? BigInt(0)) + l2GasFee + (l1DataFee ?? BigInt(0)))

let displayedPrice = ""
if (tokenPrice.price?.[selectedToken.address.toLowerCase()]) {

if (tokenPrice.price?.[selectedToken.address]) {
displayedPrice = (
Number(getDisplayedPrice(amount, selectedToken.address)) +
Number(getDisplayedPrice(BNToAmount((l1GasFee ?? BigInt(0)) + l2GasFee + (l1DataFee ?? BigInt(0)))))
Expand Down

0 comments on commit 554d0c0

Please sign in to comment.