From 7ebf107a73291958514974df5960ae2b3b1f2648 Mon Sep 17 00:00:00 2001 From: abtestingalpha Date: Thu, 31 Aug 2023 13:58:22 -0400 Subject: [PATCH 1/2] Fixes off by 100 error --- packages/synapse-interface/utils/bigint/format.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/synapse-interface/utils/bigint/format.ts b/packages/synapse-interface/utils/bigint/format.ts index 46ed7d3a06..0fe59430a2 100644 --- a/packages/synapse-interface/utils/bigint/format.ts +++ b/packages/synapse-interface/utils/bigint/format.ts @@ -66,7 +66,7 @@ export const formatBigIntToPercentString = ( ) // Convert the bigint to a floating-point number, preserving the requested number of decimal places - const num = Number(bn) / Number(conversionFactor) + const num = (Number(bn) * 100) / Number(conversionFactor) // Format the number as a percentage string return `${num.toFixed(decimalPlaces)}%` From f9d5f9ab6743f5ec993ae8004f54102adbb5e439 Mon Sep 17 00:00:00 2001 From: abtestingalpha Date: Thu, 31 Aug 2023 13:58:55 -0400 Subject: [PATCH 2/2] Renames as SwapExchangeRateInfo, deprecates unused code --- ...eRateInfo.tsx => SwapExchangeRateInfo.tsx} | 99 +------------------ .../synapse-interface/pages/swap/SwapCard.tsx | 5 +- 2 files changed, 5 insertions(+), 99 deletions(-) rename packages/synapse-interface/components/{ExchangeRateInfo.tsx => SwapExchangeRateInfo.tsx} (50%) diff --git a/packages/synapse-interface/components/ExchangeRateInfo.tsx b/packages/synapse-interface/components/SwapExchangeRateInfo.tsx similarity index 50% rename from packages/synapse-interface/components/ExchangeRateInfo.tsx rename to packages/synapse-interface/components/SwapExchangeRateInfo.tsx index d422298659..8acae7b82c 100644 --- a/packages/synapse-interface/components/ExchangeRateInfo.tsx +++ b/packages/synapse-interface/components/SwapExchangeRateInfo.tsx @@ -1,8 +1,5 @@ -import { useState, useMemo, useEffect } from 'react' +import { useMemo } from 'react' import { CHAINS_BY_ID } from '@constants/chains' -import * as CHAINS from '@constants/chains/master' -import { useCoingeckoPrice } from '@hooks/useCoingeckoPrice' -import { useGasDropAmount } from '@/utils/hooks/useGasDropAmount' import Image from 'next/image' import { Token } from '@/utils/types' @@ -11,22 +8,17 @@ import { formatBigIntToString, } from '@/utils/bigint/format' -const ExchangeRateInfo = ({ +const SwapExchangeRateInfo = ({ fromAmount, toToken, exchangeRate, toChainId, - showGasDrop, }: { fromAmount: bigint toToken: Token exchangeRate: bigint toChainId: number - showGasDrop: boolean }) => { - const [gasDropChainId, setGasDropChainId] = useState(null) - const { gasDrop: gasDropAmount, loading } = useGasDropAmount(toChainId) - const safeExchangeRate = useMemo(() => exchangeRate ?? 0n, [exchangeRate]) // todo clean const safeFromAmount = useMemo(() => fromAmount ?? 0n, [fromAmount]) // todo clean const formattedExchangeRate = formatBigIntToString(safeExchangeRate, 18, 5) @@ -45,39 +37,12 @@ const ExchangeRateInfo = ({ } }, [numExchangeRate]) - const isGasDropped = useMemo(() => { - if (gasDropAmount) { - return gasDropAmount.gt(0) - } - }, [gasDropAmount]) - - useEffect(() => { - setGasDropChainId(toChainId) - }, [toChainId, isGasDropped]) - - const memoizedGasDropLabel = useMemo(() => { - if (!isGasDropped || !(toChainId == gasDropChainId)) return null - if (loading) return null - return - }, [toChainId, gasDropChainId, isGasDropped, loading]) - const expectedToChain = useMemo(() => { return toChainId && }, [toChainId]) return (
- {showGasDrop && ( -
- {memoizedGasDropLabel} -
- )}

Expected Price on

@@ -106,50 +71,6 @@ const ExchangeRateInfo = ({ ) } -const GasDropLabel = ({ - gasDropAmount, - toChainId, -}: { - gasDropAmount: bigint - toChainId: number -}) => { - let decimalsToDisplay - const symbol = CHAINS_BY_ID[toChainId].nativeCurrency.symbol - - if ([CHAINS.FANTOM.id].includes(toChainId)) { - decimalsToDisplay = 2 - } else if ( - [CHAINS.BNB.id, CHAINS.AVALANCHE.id, CHAINS.BOBA.id].includes(toChainId) - ) { - decimalsToDisplay = 3 - } else { - decimalsToDisplay = 4 - } - - const formattedGasDropAmount = formatBigIntToString( - gasDropAmount, - 18, - decimalsToDisplay - ) - - const airdropInDollars = getAirdropInDollars(symbol, formattedGasDropAmount) - - return ( -
- - Will also receive {formattedGasDropAmount}{' '} - - - {' '} - {symbol}{' '} - - {airdropInDollars && `($${airdropInDollars})`} - - -
- ) -} - const ChainInfoLabel = ({ chainId }: { chainId: number }) => { const chain = CHAINS_BY_ID[chainId] return chain ? ( @@ -166,18 +87,4 @@ const ChainInfoLabel = ({ chainId }: { chainId: number }) => { ) : null } -const getAirdropInDollars = ( - symbol: string, - formattedGasDropAmount: string -) => { - const price = useCoingeckoPrice(symbol) - - if (price) { - const airdropInDollars = parseFloat(formattedGasDropAmount) * price - - return airdropInDollars.toFixed(2) - } else { - return undefined - } -} -export default ExchangeRateInfo +export default SwapExchangeRateInfo diff --git a/packages/synapse-interface/pages/swap/SwapCard.tsx b/packages/synapse-interface/pages/swap/SwapCard.tsx index bdfcd47cf7..7822160e03 100644 --- a/packages/synapse-interface/pages/swap/SwapCard.tsx +++ b/packages/synapse-interface/pages/swap/SwapCard.tsx @@ -5,7 +5,7 @@ import { getWalletClient, switchNetwork } from '@wagmi/core' import { Address } from 'wagmi' import { sortByTokenBalance, sortByVisibilityRank } from '@utils/sortTokens' import { calculateExchangeRate } from '@utils/calculateExchangeRate' -import ExchangeRateInfo from '@components/ExchangeRateInfo' +import SwapExchangeRateInfo from '@components/SwapExchangeRateInfo' import { TransactionButton } from '@/components/buttons/TransactionButton' import BridgeInputContainer from '../../components/input/TokenAmountInput/index' import { approveToken } from '@/utils/approveToken' @@ -830,12 +830,11 @@ const SwapCard = ({ /> -
{ActionButton}