diff --git a/package.json b/package.json index 6d4f97e..f46dcdb 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "ghost-dao-interface", "private": true, - "version": "0.6.8", + "version": "0.6.9", "type": "module", "scripts": { "dev": "vite", diff --git a/src/containers/Dex/PoolContainer.jsx b/src/containers/Dex/PoolContainer.jsx index 787a881..acec9f3 100644 --- a/src/containers/Dex/PoolContainer.jsx +++ b/src/containers/Dex/PoolContainer.jsx @@ -131,7 +131,35 @@ const PoolContainer = ({ } } - }, [addressBottom, balanceTop, balanceBottom, amountTop, amountBottom, tokenAddresses, pairReserves]) + }, [addressBottom, balanceTop, balanceBottom, amountTop, amountBottom, tokenAddresses, pairReserves]); + + const poolShares = useMemo(() => { + const hundred = new DecimalBigNumber(1n, 2); + if (lpTotalSupply?._value == 0n) { + return { currentShares: lpTotalSupply, nextShares: lpTotalSupply }; + } + const currentShares = lpBalance.div(lpTotalSupply).div(hundred); + const nextShares = (lpBalance.add(estimatedAmountOut)).div(lpTotalSupply).div(hundred); + return { currentShares, nextShares }; + }, [lpBalance, lpTotalSupply, estimatedAmountOut]); + + const poolPrices = useMemo(() => { + const amountIn = addressTop.toUpperCase() === tokenAddresses.token0.toUpperCase() + ? pairReserves.reserve0 + : pairReserves.reserve1; + + const amountOut = addressBottom.toUpperCase() === tokenAddresses.token1.toUpperCase() + ? pairReserves.reserve1 + : pairReserves.reserve0; + + let priceIn = "0"; + let priceOut = "0"; + + if (amountIn?._value > 0n) priceIn = (amountOut.div(amountIn)).toString(); + if (amountOut?._value > 0n) priceOut = (amountIn.div(amountOut)).toString(); + + return { priceIn , priceOut } + }, [addressTop, addressBottom, balanceTop, tokenAddresses, pairReserves]); const addLiquidityInner = async () => { setIsPending(true); @@ -218,7 +246,7 @@ const PoolContainer = ({ } arrowOnClick={onSwap} /> - {!isSmallScreen && - Current Balance: - {formatNumber(lpBalance, formatDecimals)} LP + Current: + {!isSmallScreen ? `1 ${tokenNameTop} = ` : ""}{formatCurrency(poolPrices.priceIn, formatDecimals, tokenNameBottom)} - Total Supply: - {formatNumber(lpTotalSupply, formatDecimals)} LP + Current: + {!isSmallScreen ? `1 ${tokenNameBottom} = ` : ""}{formatCurrency(poolPrices.priceOut, formatDecimals, tokenNameTop)} - Extra Balance: - ~{formatNumber(estimatedAmountOut, formatDecimals)} LP + Current Pool Share: + {formatNumber(poolShares.currentShares, formatDecimals)}% - } + + Next Pool Share: + {formatNumber(poolShares.nextShares, formatDecimals)}% + + { + const decimals = 7; + const shares = Math.pow(10, decimals); + const one = BigInt(shares * 100); + + const floatSlippage = slippage === "" ? 0 : parseFloat(slippage); + const bigIntSlippage = one - BigInt(Math.round(floatSlippage * shares)); + const slippageDecimalBigNumber = new DecimalBigNumber(bigIntSlippage, 2); + + const bigIntAmount = BigInt(Math.round(amountBottom * shares)); + const amountDecimalBigNumber = new DecimalBigNumber(bigIntAmount, decimals); + + const tmpResult = amountDecimalBigNumber.mul(slippageDecimalBigNumber); + const result = new DecimalBigNumber(tmpResult?._value, tmpResult?._decimals + decimals); + return result?.toString(); + }, [amountBottom, amountBottom, slippage, balanceBottom]); const buttonText = useMemo(() => { let text = "Swap"; @@ -215,7 +236,7 @@ const SwapContainer = ({ } arrowOnClick={onSwap} /> - {!isSmallScreen && - Current price: - {formatCurrency(currentPrice, formatDecimals, tokenNameTop)} + Current: + {!isSmallScreen ? `1 ${tokenNameTop} = ` : ""}{formatCurrency(currentPrice, formatDecimals, tokenNameBottom)} - Next price: - {formatCurrency(nextPrice === "" ? currentPrice : nextPrice, formatDecimals, tokenNameTop)} + Next: + {!isSmallScreen ? `1 ${tokenNameTop} = ` : ""}{formatCurrency(nextPrice === "" ? currentPrice : nextPrice, formatDecimals, tokenNameBottom)} - Transaction deadline: + Min. Receive: + {formatCurrency(minReceived, formatDecimals, tokenNameBottom)} + + + Tx. Deadline: ~{prettifySecondsInDays(secondsToWait)} - } +