From 554d0c0fb578e15d870b3bb9ef33b32e9da44d1a Mon Sep 17 00:00:00 2001 From: zzq0826 <770166635@qq.com> Date: Sat, 27 Jul 2024 14:38:30 +0800 Subject: [PATCH] Use own price service (#1207) --- src/hooks/useTokenPrice.ts | 4 ++-- .../bridge/Send/SendTransaction/TransactionSummary.tsx | 7 ++++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/hooks/useTokenPrice.ts b/src/hooks/useTokenPrice.ts index 2bd02b220..dd88b5f35 100644 --- a/src/hooks/useTokenPrice.ts +++ b/src/hooks/useTokenPrice.ts @@ -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]) diff --git a/src/pages/bridge/Send/SendTransaction/TransactionSummary.tsx b/src/pages/bridge/Send/SendTransaction/TransactionSummary.tsx index 01e233440..b3a3bb034 100644 --- a/src/pages/bridge/Send/SendTransaction/TransactionSummary.tsx +++ b/src/pages/bridge/Send/SendTransaction/TransactionSummary.tsx @@ -80,8 +80,8 @@ const TransactionSummary: FC = 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 "" }, @@ -96,7 +96,8 @@ const TransactionSummary: FC = 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)))))