From 201a132d09694cf4bd479a6b90d2ef7cdac83181 Mon Sep 17 00:00:00 2001 From: James Russell Orola Date: Tue, 30 Aug 2022 13:50:35 +0800 Subject: [PATCH 1/3] feat: removed geoblock wrapper comp --- src/pages/App.tsx | 65 ++++++++++++++++++++++------------------------- 1 file changed, 31 insertions(+), 34 deletions(-) diff --git a/src/pages/App.tsx b/src/pages/App.tsx index 4b2270a4..b3385d4a 100644 --- a/src/pages/App.tsx +++ b/src/pages/App.tsx @@ -15,7 +15,6 @@ import Demo from './Test/Demo' import TailwindDemo from './Test/TailwindDemo' import Pool from './Tailwind/Pool' import Swap from './Tailwind/Swap' -import GeoBlocked from 'components/Tailwind/Panels/GeoBlocked' const AppWrapper = styled.div` display: flex; @@ -55,38 +54,36 @@ const Marginer = styled.div` export default function App() { return ( - - - - - - - -
- - - - - - - - - - - - {(process.env.NODE_ENV === 'development' || process.env.REACT_APP_SHOW_DEMO === 'true') && ( - - )} - {(process.env.NODE_ENV === 'development' || process.env.REACT_APP_SHOW_DEMO === 'true') && ( - - )} - - - - - - - - + + + + + + +
+ + + + + + + + + + + + {(process.env.NODE_ENV === 'development' || process.env.REACT_APP_SHOW_DEMO === 'true') && ( + + )} + {(process.env.NODE_ENV === 'development' || process.env.REACT_APP_SHOW_DEMO === 'true') && ( + + )} + + + + + + + ) } From 7f2cac23b1e8b0b298724f0dad19cc365fa3079b Mon Sep 17 00:00:00 2001 From: James Russell Orola Date: Tue, 30 Aug 2022 14:20:51 +0800 Subject: [PATCH 2/3] fix: currency input not displaying balance on arb --- .../Tailwind/InputFields/CurrencyInput.tsx | 20 +++++++++++----- src/sushi-hooks/queries/useTokenBalance.ts | 3 +-- src/utils/bigNumberHelper.ts | 24 +++++++++++++++++++ 3 files changed, 39 insertions(+), 8 deletions(-) create mode 100644 src/utils/bigNumberHelper.ts diff --git a/src/components/Tailwind/InputFields/CurrencyInput.tsx b/src/components/Tailwind/InputFields/CurrencyInput.tsx index 70ef6a50..ca625920 100644 --- a/src/components/Tailwind/InputFields/CurrencyInput.tsx +++ b/src/components/Tailwind/InputFields/CurrencyInput.tsx @@ -6,9 +6,11 @@ import SelectButton from '../Buttons/SelectButton' import NumericalInput from 'components/NumericalInput' import TokenSelectModal from 'components/Tailwind/Modals/TokenSelectModal' import { formatNumber, NumberFormat } from 'utils/formatNumber' -import { useCurrencyBalance } from 'state/wallet/hooks' import { useActiveWeb3React } from 'hooks' import { MouseoverTooltip } from '../../Tooltip' +import useTokenBalance from 'sushi-hooks/queries/useTokenBalance' +import { formatUnits } from 'ethers/lib/utils' +import { bigNumberToNumber } from 'utils/bigNumberHelper' interface TokenInputProps { currency: Currency @@ -35,12 +37,16 @@ const TokenInput = ({ }: TokenInputProps) => { const [showModal, setShowModal] = useState(false) const { account } = useActiveWeb3React() - const currencyBalance = useCurrencyBalance(account ?? undefined, currency) + + const currencyBalance = useTokenBalance( + currency instanceof Token ? (currency as Token).address : undefined, + account ?? undefined + ) const onMax = () => { - balance = balance ? balance : currencyBalance?.toExact() - if (balance && Number(balance) > 0) { - didChangeValue(balance) + const _balance = balance ? balance : formatUnits(currencyBalance.value, currencyBalance.decimals) + if (_balance && Number(_balance) > 0) { + didChangeValue(_balance) } } @@ -79,7 +85,9 @@ const TokenInput = ({ {balance ? formatNumber(Number(balance), NumberFormat.long) - : currencyBalance?.toFixed(2, { groupSeparator: ',' }) || '-'} + : currencyBalance + ? formatNumber(bigNumberToNumber(currencyBalance.value, currencyBalance.decimals), NumberFormat.long) + : '-'} )} { const getBalance = async (contract: Contract | null, owner: string | null | undefined): Promise => { try { //console.log('token_contract:', contract) - const balance = await contract?.balanceOf(owner) - const decimals = await contract?.decimals() + const [balance, decimals] = await Promise.all([contract?.balanceOf(owner), contract?.decimals()]) return { value: BigNumber.from(balance), decimals: decimals } //todo: return as BigNumber as opposed toString since information will //return Fraction.from(BigNumber.from(balance), BigNumber.from(10).pow(decimals)).toString() diff --git a/src/utils/bigNumberHelper.ts b/src/utils/bigNumberHelper.ts new file mode 100644 index 00000000..39e0e811 --- /dev/null +++ b/src/utils/bigNumberHelper.ts @@ -0,0 +1,24 @@ +import { BigNumber } from 'ethers' +import { formatUnits, parseUnits } from 'ethers/lib/utils' + +export const bigNumberToNumber = (bn: BigNumber, decimals = 18) => { + const strValue = formatUnits(bn.toString(), decimals) + const parts = strValue.split('.') + const decimalDigits = parts[1] ?? '' + if (decimalDigits.length > 15) { + return parseFloat(parts[0] + '.' + decimalDigits.slice(0, 15)) + } else { + return parseFloat(strValue) + } +} + +export const numberToBigNumber = (n: number, decimals = 18) => { + return parseUnits(`${n.toFixed(decimals)}`, decimals) +} + +export const scale = (input: BigNumber | string, decimalPlaces: number) => { + const unscaled = typeof input === 'string' ? BigNumber.from(input) : input + const scalePow = BigNumber.from(decimalPlaces.toString()) + const scaleMul = BigNumber.from(10).pow(scalePow) + return unscaled.mul(scaleMul) +} From 00ac8618b0be75d71586705534cb2c149672241b Mon Sep 17 00:00:00 2001 From: James Russell Orola Date: Tue, 30 Aug 2022 14:43:14 +0800 Subject: [PATCH 3/3] fix: token balances on add liquidity --- src/pages/Tailwind/Pool/liquidity/AddLiquidity.tsx | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/pages/Tailwind/Pool/liquidity/AddLiquidity.tsx b/src/pages/Tailwind/Pool/liquidity/AddLiquidity.tsx index 2e1801cc..3f866b95 100644 --- a/src/pages/Tailwind/Pool/liquidity/AddLiquidity.tsx +++ b/src/pages/Tailwind/Pool/liquidity/AddLiquidity.tsx @@ -1,12 +1,13 @@ import React, { useState } from 'react' import { PoolData } from '../models/PoolData' -import { useTokenBalances } from 'state/wallet/hooks' import { useActiveWeb3React } from 'hooks' import SegmentControl from 'components/Tailwind/SegmentControl/SegmentControl' import MultiSidedLiquidity from './MultiSidedLiquidity' import SingleSidedLiquidity from './SingleSidedLiquidity' import AddLiquityModal from './AddLiquityModal' import ErrorModal from 'components/Tailwind/Modals/ErrorModal' +import useTokenBalance from 'sushi-hooks/queries/useTokenBalance' +import { TokenAmount } from '@halodao/sdk' interface AddLiquidityProps { pool: PoolData @@ -24,8 +25,12 @@ const AddLiquidity = ({ pool, isEnabled }: AddLiquidityProps) => { const [error, setError] = useState(undefined) const { account } = useActiveWeb3React() - const tokenBalances = useTokenBalances(account ?? undefined, [pool.token0, pool.token1]) - const balances = [tokenBalances[pool.token0.address], tokenBalances[pool.token1.address]] + const token0Balance = useTokenBalance(pool.token0.address, account ?? undefined) + const token1Balance = useTokenBalance(pool.token1.address, account ?? undefined) + const balances = [ + new TokenAmount(pool.token0, BigInt(token0Balance.value.toString())), + new TokenAmount(pool.token1, BigInt(token1Balance.value.toString())) + ] const disabledSegments = pool.pooled.total > 0 ? undefined : [1]