From 2f94c0207bdebee618c8c57c7678748b97e3d9ce Mon Sep 17 00:00:00 2001 From: NeOMakinG <14963751+NeOMakinG@users.noreply.github.com> Date: Tue, 24 Sep 2024 16:01:51 +0800 Subject: [PATCH] fix: fiat amount lps gas fee maths (#7787) --- .../RemoveLiquidity/RemoveLiquidityInput.tsx | 32 ++++++++++++++----- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/src/pages/ThorChainLP/components/RemoveLiquidity/RemoveLiquidityInput.tsx b/src/pages/ThorChainLP/components/RemoveLiquidity/RemoveLiquidityInput.tsx index e22c1232665..95302aa7966 100644 --- a/src/pages/ThorChainLP/components/RemoveLiquidity/RemoveLiquidityInput.tsx +++ b/src/pages/ThorChainLP/components/RemoveLiquidity/RemoveLiquidityInput.tsx @@ -449,9 +449,30 @@ export const RemoveLiquidityInput: React.FC = ({ [estimatedPoolAssetFeesData?.txFeeCryptoBaseUnit, poolAssetFeeAsset?.precision], ) + const poolAssetFeeAssetDustAmountCryptoPrecision = useMemo(() => { + if (!poolAssetFeeAsset) return 0 + + return fromBaseUnit(poolAssetFeeAssetDustAmountCryptoBaseUnit, poolAssetFeeAsset?.precision) + }, [poolAssetFeeAssetDustAmountCryptoBaseUnit, poolAssetFeeAsset]) + + const poolAssetFeeAssetDustAmountFiatUserCurrency = useMemo(() => { + return bnOrZero(poolAssetFeeAssetDustAmountCryptoPrecision).times( + poolAssetFeeAssetMarketData.price, + ) + }, [poolAssetFeeAssetMarketData.price, poolAssetFeeAssetDustAmountCryptoPrecision]) + + // We also include the dust amount in the gas fee as it's deducted in the input validation + // This will result in displaying gas fees and dust amounts as a single value in the UI const poolAssetGasFeeFiatUserCurrency = useMemo( - () => bnOrZero(poolAssetTxFeeCryptoPrecision).times(poolAssetFeeAssetMarketData.price), - [poolAssetFeeAssetMarketData.price, poolAssetTxFeeCryptoPrecision], + () => + bnOrZero(poolAssetTxFeeCryptoPrecision) + .times(poolAssetFeeAssetMarketData.price) + .plus(poolAssetFeeAssetDustAmountFiatUserCurrency), + [ + poolAssetFeeAssetMarketData.price, + poolAssetTxFeeCryptoPrecision, + poolAssetFeeAssetDustAmountFiatUserCurrency, + ], ) const runeProtocolFeeCryptoPrecision = useMemo(() => { @@ -842,11 +863,6 @@ export const RemoveLiquidityInput: React.FC = ({ poolAssetFeeAsset?.precision, ) - const poolAssetFeeAssetDustAmountCryptoPrecision = fromBaseUnit( - poolAssetFeeAssetDustAmountCryptoBaseUnit, - poolAssetFeeAsset?.precision, - ) - return bnOrZero(poolAssetTxFeeCryptoPrecision) .plus(poolAssetFeeAssetDustAmountCryptoPrecision) .lte(poolAssetFeeAssetBalanceCryptoPrecision) @@ -855,8 +871,8 @@ export const RemoveLiquidityInput: React.FC = ({ withdrawType, poolAssetFeeAsset, poolAssetFeeAssetBalanceCryptoBaseUnit, - poolAssetFeeAssetDustAmountCryptoBaseUnit, poolAssetTxFeeCryptoPrecision, + poolAssetFeeAssetDustAmountCryptoPrecision, ]) const hasEnoughRuneBalanceForTx = useMemo(() => {