From 70dacfedf7e1c849d11c42a44690e940bfe1bdd1 Mon Sep 17 00:00:00 2001 From: tunghp2002 Date: Wed, 23 Oct 2024 10:14:11 +0700 Subject: [PATCH 01/11] [Update] - Update message in case perform Liquid staking have XCM --- .../services/earning-service/handlers/special.ts | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/packages/extension-base/src/services/earning-service/handlers/special.ts b/packages/extension-base/src/services/earning-service/handlers/special.ts index 9d95dda327..411e5a450c 100644 --- a/packages/extension-base/src/services/earning-service/handlers/special.ts +++ b/packages/extension-base/src/services/earning-service/handlers/special.ts @@ -3,7 +3,7 @@ import { TransactionError } from '@subwallet/extension-base/background/errors/TransactionError'; import { AmountData, ChainType, ExtrinsicType } from '@subwallet/extension-base/background/KoniTypes'; -import { ALL_ACCOUNT_KEY } from '@subwallet/extension-base/constants'; +import { ALL_ACCOUNT_KEY, XCM_FEE_RATIO } from '@subwallet/extension-base/constants'; import { YIELD_POOL_STAT_REFRESH_INTERVAL } from '@subwallet/extension-base/koni/api/yield/helper/utils'; import KoniState from '@subwallet/extension-base/koni/background/handlers/State'; import { createXcmExtrinsic } from '@subwallet/extension-base/services/balance-service/transfer/xcm'; @@ -345,26 +345,27 @@ export default abstract class BaseSpecialStakingPoolHandler extends BasePoolHand const missingAmount = bnAmount.sub(bnInputTokenBalance); // TODO: what if input token is not LOCAL ?? const xcmFee = new BN(path.totalFee[1].amount || '0'); + const xcmAmount = missingAmount.add(xcmFee); + const existentialDeposit = new BN(this.nativeToken.minAmount || '0'); const bnAltInputTokenBalance = new BN(altInputTokenBalance.value || '0'); - if (!bnAltInputTokenBalance.sub(xcmAmount).sub(xcmFee).gt(BN_ZERO)) { + if (!bnAltInputTokenBalance.sub(xcmAmount).sub(xcmFee).sub(existentialDeposit).gt(BN_ZERO)) { processValidation.failedStep = path.steps[1]; processValidation.ok = false; processValidation.status = YieldValidationStatus.NOT_ENOUGH_BALANCE; - const maxBn = bnInputTokenBalance.add(new BN(altInputTokenBalance.value)).sub(xcmFee).sub(xcmFee); + const bnMaxXCM = new BN(altInputTokenBalance.value).sub(xcmFee.mul(new BN(XCM_FEE_RATIO))).sub(existentialDeposit); + const maxBn = bnInputTokenBalance.add(bnMaxXCM); const maxValue = formatNumber(maxBn.toString(), inputTokenInfo.decimals || 0); + const maxXCMValue = formatNumber(bnMaxXCM.toString(), inputTokenInfo.decimals || 0); - const altInputTokenInfo = this.state.getAssetBySlug(altInputTokenSlug); const symbol = altInputTokenInfo.symbol; const altNetwork = this.state.getChainInfo(altInputTokenInfo.originChain); const inputNetworkName = this.chainInfo.name; const altNetworkName = altNetwork.name; const currentValue = formatNumber(bnInputTokenBalance.toString(), inputTokenInfo.decimals || 0); - const bnMaxXCM = new BN(altInputTokenBalance.value).sub(xcmFee).sub(xcmFee); - const maxXCMValue = formatNumber(bnMaxXCM.toString(), inputTokenInfo.decimals || 0); processValidation.message = t( 'You can only enter a maximum of {{maxValue}} {{symbol}}, which is {{currentValue}} {{symbol}} ({{inputNetworkName}}) and {{maxXCMValue}} {{symbol}} ({{altNetworkName}}). Lower your amount and try again.', From d5550e32708acf9da2acd1b7b47e0a94e52c8958 Mon Sep 17 00:00:00 2001 From: tunghp2002 Date: Wed, 27 Nov 2024 17:21:22 +0700 Subject: [PATCH 02/11] [Add] Extension - Handle negative number --- .../src/services/earning-service/handlers/special.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/extension-base/src/services/earning-service/handlers/special.ts b/packages/extension-base/src/services/earning-service/handlers/special.ts index 411e5a450c..d1e81a6195 100644 --- a/packages/extension-base/src/services/earning-service/handlers/special.ts +++ b/packages/extension-base/src/services/earning-service/handlers/special.ts @@ -357,9 +357,10 @@ export default abstract class BaseSpecialStakingPoolHandler extends BasePoolHand processValidation.status = YieldValidationStatus.NOT_ENOUGH_BALANCE; const bnMaxXCM = new BN(altInputTokenBalance.value).sub(xcmFee.mul(new BN(XCM_FEE_RATIO))).sub(existentialDeposit); - const maxBn = bnInputTokenBalance.add(bnMaxXCM); + const preCheckBnMaxXCM = bnMaxXCM.lte(BN_ZERO) ? BN_ZERO : bnMaxXCM; + const maxBn = bnInputTokenBalance.add(preCheckBnMaxXCM); const maxValue = formatNumber(maxBn.toString(), inputTokenInfo.decimals || 0); - const maxXCMValue = formatNumber(bnMaxXCM.toString(), inputTokenInfo.decimals || 0); + const maxXCMValue = formatNumber(preCheckBnMaxXCM.toString(), inputTokenInfo.decimals || 0); const symbol = altInputTokenInfo.symbol; const altNetwork = this.state.getChainInfo(altInputTokenInfo.originChain); From d0fa8c0f47c9b7b84b4c065fbe0a33da2cd795a7 Mon Sep 17 00:00:00 2001 From: tunghp2002 Date: Thu, 19 Dec 2024 11:49:27 +0700 Subject: [PATCH 03/11] [Update] Fix acala liquid staking screen --- .../src/services/earning-service/handlers/special.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/extension-base/src/services/earning-service/handlers/special.ts b/packages/extension-base/src/services/earning-service/handlers/special.ts index d1e81a6195..c7ed9cb532 100644 --- a/packages/extension-base/src/services/earning-service/handlers/special.ts +++ b/packages/extension-base/src/services/earning-service/handlers/special.ts @@ -347,7 +347,7 @@ export default abstract class BaseSpecialStakingPoolHandler extends BasePoolHand const xcmFee = new BN(path.totalFee[1].amount || '0'); const xcmAmount = missingAmount.add(xcmFee); - const existentialDeposit = new BN(this.nativeToken.minAmount || '0'); + const existentialDeposit = new BN(altInputTokenInfo.minAmount || '0'); const bnAltInputTokenBalance = new BN(altInputTokenBalance.value || '0'); From 142010c6397467ed329701489e2262493e1f8330 Mon Sep 17 00:00:00 2001 From: tunghp2002 Date: Wed, 25 Dec 2024 09:03:53 +0700 Subject: [PATCH 04/11] [Update] Add number for alt token --- .../src/services/earning-service/handlers/special.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/extension-base/src/services/earning-service/handlers/special.ts b/packages/extension-base/src/services/earning-service/handlers/special.ts index c7ed9cb532..65bc06cc6a 100644 --- a/packages/extension-base/src/services/earning-service/handlers/special.ts +++ b/packages/extension-base/src/services/earning-service/handlers/special.ts @@ -96,20 +96,24 @@ export default abstract class BaseSpecialStakingPoolHandler extends BasePoolHand ]); const bnInputAssetBalance = new BN(inputAssetBalance.value); - const bnAltInputAssetBalance = new BN(altInputAssetBalance.value); + const bnMinJoinPool = new BN(poolInfo.statistic.earningThreshold.join); const inputTokenInfo = this.state.chainService.getAssetBySlug(this.inputAsset); const altInputTokenInfo = this.state.chainService.getAssetBySlug(this.altInputAsset); + const existentialDeposit = new BN(altInputTokenInfo.minAmount || '0'); + const bnAltInputAssetBalance = new BN(altInputAssetBalance.value).sub(existentialDeposit); + const preCheckAltInputAssetBalance = bnAltInputAssetBalance.gt(BN_ZERO) ? bnAltInputAssetBalance : BN_ZERO; - if (bnInputAssetBalance.add(bnAltInputAssetBalance).lt(bnMinJoinPool)) { + if (bnInputAssetBalance.add(preCheckAltInputAssetBalance).lt(bnMinJoinPool)) { const originChain = this.state.getChainInfo(inputTokenInfo.originChain); const altChain = this.state.getChainInfo(altInputTokenInfo.originChain); const parsedMinJoinPool = formatNumber(bnMinJoinPool.toString(), inputAssetInfo.decimals || 0); + const parsedMinAltJoinPool = formatNumber((bnMinJoinPool.add(existentialDeposit)).toString(), inputAssetInfo.decimals || 0); return { passed: false, - errorMessage: `You need at least ${parsedMinJoinPool} ${inputTokenInfo.symbol} (${originChain.name}) or ${altInputTokenInfo.symbol} (${altChain.name}) to start earning` + errorMessage: `You need at least ${parsedMinJoinPool} ${inputTokenInfo.symbol} (${originChain.name}) or ${parsedMinAltJoinPool} ${altInputTokenInfo.symbol} (${altChain.name}) to start earning` }; } From 22e1de58e7660565a20df2726a38daaf36984215 Mon Sep 17 00:00:00 2001 From: tunghp2002 Date: Wed, 25 Dec 2024 11:03:20 +0700 Subject: [PATCH 05/11] [Update] Refactor code by use util --- .../earning-service/handlers/special.ts | 28 +++++++++++++------ 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/packages/extension-base/src/services/earning-service/handlers/special.ts b/packages/extension-base/src/services/earning-service/handlers/special.ts index 65bc06cc6a..12d480c3f2 100644 --- a/packages/extension-base/src/services/earning-service/handlers/special.ts +++ b/packages/extension-base/src/services/earning-service/handlers/special.ts @@ -7,7 +7,7 @@ import { ALL_ACCOUNT_KEY, XCM_FEE_RATIO } from '@subwallet/extension-base/consta import { YIELD_POOL_STAT_REFRESH_INTERVAL } from '@subwallet/extension-base/koni/api/yield/helper/utils'; import KoniState from '@subwallet/extension-base/koni/background/handlers/State'; import { createXcmExtrinsic } from '@subwallet/extension-base/services/balance-service/transfer/xcm'; -import { _getChainNativeTokenSlug } from '@subwallet/extension-base/services/chain-service/utils'; +import { _getAssetDecimals, _getAssetExistentialDeposit, _getAssetName, _getAssetSymbol, _getChainNativeTokenSlug } from '@subwallet/extension-base/services/chain-service/utils'; import { BaseYieldStepDetail, BasicTxErrorType, HandleYieldStepData, OptimalYieldPath, OptimalYieldPathParams, RequestCrossChainTransfer, RequestEarlyValidateYield, ResponseEarlyValidateYield, RuntimeDispatchInfo, SpecialYieldPoolInfo, SpecialYieldPoolMetadata, SubmitYieldJoinData, SubmitYieldStepData, TransactionData, UnstakingInfo, YieldPoolInfo, YieldPoolTarget, YieldPoolType, YieldProcessValidation, YieldStepBaseInfo, YieldStepType, YieldTokenBaseInfo, YieldValidationStatus } from '@subwallet/extension-base/types'; import { createPromiseHandler, formatNumber, PromiseHandler } from '@subwallet/extension-base/utils'; import { t } from 'i18next'; @@ -101,19 +101,27 @@ export default abstract class BaseSpecialStakingPoolHandler extends BasePoolHand const inputTokenInfo = this.state.chainService.getAssetBySlug(this.inputAsset); const altInputTokenInfo = this.state.chainService.getAssetBySlug(this.altInputAsset); - const existentialDeposit = new BN(altInputTokenInfo.minAmount || '0'); + + const existentialDeposit = new BN(_getAssetExistentialDeposit(altInputTokenInfo)); const bnAltInputAssetBalance = new BN(altInputAssetBalance.value).sub(existentialDeposit); const preCheckAltInputAssetBalance = bnAltInputAssetBalance.gt(BN_ZERO) ? bnAltInputAssetBalance : BN_ZERO; if (bnInputAssetBalance.add(preCheckAltInputAssetBalance).lt(bnMinJoinPool)) { const originChain = this.state.getChainInfo(inputTokenInfo.originChain); const altChain = this.state.getChainInfo(altInputTokenInfo.originChain); + + const originSymbol = _getAssetSymbol(inputTokenInfo); + const altSymbol = _getAssetSymbol(altInputTokenInfo); + + const originName = originChain.name; + const altName = altChain.name; + const parsedMinJoinPool = formatNumber(bnMinJoinPool.toString(), inputAssetInfo.decimals || 0); const parsedMinAltJoinPool = formatNumber((bnMinJoinPool.add(existentialDeposit)).toString(), inputAssetInfo.decimals || 0); return { passed: false, - errorMessage: `You need at least ${parsedMinJoinPool} ${inputTokenInfo.symbol} (${originChain.name}) or ${parsedMinAltJoinPool} ${altInputTokenInfo.symbol} (${altChain.name}) to start earning` + errorMessage: `You need at least ${parsedMinJoinPool} ${originSymbol} (${originName}) or ${parsedMinAltJoinPool} ${altSymbol} (${altName}) to start earning` }; } @@ -363,14 +371,16 @@ export default abstract class BaseSpecialStakingPoolHandler extends BasePoolHand const bnMaxXCM = new BN(altInputTokenBalance.value).sub(xcmFee.mul(new BN(XCM_FEE_RATIO))).sub(existentialDeposit); const preCheckBnMaxXCM = bnMaxXCM.lte(BN_ZERO) ? BN_ZERO : bnMaxXCM; const maxBn = bnInputTokenBalance.add(preCheckBnMaxXCM); - const maxValue = formatNumber(maxBn.toString(), inputTokenInfo.decimals || 0); - const maxXCMValue = formatNumber(preCheckBnMaxXCM.toString(), inputTokenInfo.decimals || 0); + const inputTokenDecimal = _getAssetDecimals(inputTokenInfo); + + const maxValue = formatNumber(maxBn.toString(), inputTokenDecimal); + const maxXCMValue = formatNumber(preCheckBnMaxXCM.toString(), inputTokenDecimal); + + const symbol = _getAssetSymbol(altInputTokenInfo); - const symbol = altInputTokenInfo.symbol; - const altNetwork = this.state.getChainInfo(altInputTokenInfo.originChain); const inputNetworkName = this.chainInfo.name; - const altNetworkName = altNetwork.name; - const currentValue = formatNumber(bnInputTokenBalance.toString(), inputTokenInfo.decimals || 0); + const altNetworkName = _getAssetName(altInputTokenInfo); + const currentValue = formatNumber(bnInputTokenBalance.toString(), inputTokenDecimal); processValidation.message = t( 'You can only enter a maximum of {{maxValue}} {{symbol}}, which is {{currentValue}} {{symbol}} ({{inputNetworkName}}) and {{maxXCMValue}} {{symbol}} ({{altNetworkName}}). Lower your amount and try again.', From dc320dad276a6b1a9a7bf113303352db71cab585 Mon Sep 17 00:00:00 2001 From: tunghp2002 Date: Mon, 30 Dec 2024 14:21:05 +0700 Subject: [PATCH 06/11] For test --- .../src/services/earning-service/handlers/special.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/extension-base/src/services/earning-service/handlers/special.ts b/packages/extension-base/src/services/earning-service/handlers/special.ts index 12d480c3f2..ba833f454f 100644 --- a/packages/extension-base/src/services/earning-service/handlers/special.ts +++ b/packages/extension-base/src/services/earning-service/handlers/special.ts @@ -370,6 +370,8 @@ export default abstract class BaseSpecialStakingPoolHandler extends BasePoolHand const bnMaxXCM = new BN(altInputTokenBalance.value).sub(xcmFee.mul(new BN(XCM_FEE_RATIO))).sub(existentialDeposit); const preCheckBnMaxXCM = bnMaxXCM.lte(BN_ZERO) ? BN_ZERO : bnMaxXCM; + + console.log('Precheck', preCheckBnMaxXCM); const maxBn = bnInputTokenBalance.add(preCheckBnMaxXCM); const inputTokenDecimal = _getAssetDecimals(inputTokenInfo); From c7ca8e5011d451efad4c0d192e1fde7940a77133 Mon Sep 17 00:00:00 2001 From: tunghp2002 Date: Tue, 31 Dec 2024 09:42:03 +0700 Subject: [PATCH 07/11] [Update] Fix logic earning and xcm --- .../src/koni/background/handlers/Extension.ts | 5 ++-- .../earning-service/handlers/special.ts | 25 ++++++++----------- 2 files changed, 12 insertions(+), 18 deletions(-) diff --git a/packages/extension-base/src/koni/background/handlers/Extension.ts b/packages/extension-base/src/koni/background/handlers/Extension.ts index 7a33f1698c..6a6b5485c5 100644 --- a/packages/extension-base/src/koni/background/handlers/Extension.ts +++ b/packages/extension-base/src/koni/background/handlers/Extension.ts @@ -1779,7 +1779,6 @@ export default class KoniExtension { const substrateApi = this.#koniState.chainService.getSubstrateApi(originTokenInfo.originChain); const chainInfoMap = this.#koniState.chainService.getChainInfoMap(); const destinationTokenInfo = this.#koniState.getXcmEqualAssetByChain(destChain, originTokenInfo.slug); - const existentialDeposit = originTokenInfo.minAmount || '0'; if (destinationTokenInfo) { const [bnMockExecutionFee, { value }] = await Promise.all([ @@ -1788,9 +1787,9 @@ export default class KoniExtension { ]); const bnMaxTransferable = new BigN(value); - const estimatedFee = bnMockExecutionFee.multipliedBy(XCM_FEE_RATIO).plus(new BigN(existentialDeposit)); + const txFee = bnMockExecutionFee.multipliedBy(XCM_FEE_RATIO); - return bnMaxTransferable.minus(estimatedFee); + return bnMaxTransferable.minus(txFee); } return new BigN(0); diff --git a/packages/extension-base/src/services/earning-service/handlers/special.ts b/packages/extension-base/src/services/earning-service/handlers/special.ts index ba833f454f..4d151978b3 100644 --- a/packages/extension-base/src/services/earning-service/handlers/special.ts +++ b/packages/extension-base/src/services/earning-service/handlers/special.ts @@ -103,10 +103,11 @@ export default abstract class BaseSpecialStakingPoolHandler extends BasePoolHand const altInputTokenInfo = this.state.chainService.getAssetBySlug(this.altInputAsset); const existentialDeposit = new BN(_getAssetExistentialDeposit(altInputTokenInfo)); - const bnAltInputAssetBalance = new BN(altInputAssetBalance.value).sub(existentialDeposit); - const preCheckAltInputAssetBalance = bnAltInputAssetBalance.gt(BN_ZERO) ? bnAltInputAssetBalance : BN_ZERO; + const bnAltInputAssetBalance = new BN(altInputAssetBalance.value); + + if (bnInputAssetBalance.add(bnAltInputAssetBalance).lt(bnMinJoinPool)) { + const missingAmount = bnMinJoinPool.sub(bnInputAssetBalance.sub(bnAltInputAssetBalance)); - if (bnInputAssetBalance.add(preCheckAltInputAssetBalance).lt(bnMinJoinPool)) { const originChain = this.state.getChainInfo(inputTokenInfo.originChain); const altChain = this.state.getChainInfo(altInputTokenInfo.originChain); @@ -116,8 +117,8 @@ export default abstract class BaseSpecialStakingPoolHandler extends BasePoolHand const originName = originChain.name; const altName = altChain.name; - const parsedMinJoinPool = formatNumber(bnMinJoinPool.toString(), inputAssetInfo.decimals || 0); - const parsedMinAltJoinPool = formatNumber((bnMinJoinPool.add(existentialDeposit)).toString(), inputAssetInfo.decimals || 0); + const parsedMinJoinPool = formatNumber(missingAmount.toString(), inputAssetInfo.decimals || 0); + const parsedMinAltJoinPool = formatNumber((missingAmount.add(existentialDeposit)).toString(), inputAssetInfo.decimals || 0); return { passed: false, @@ -359,24 +360,18 @@ export default abstract class BaseSpecialStakingPoolHandler extends BasePoolHand const xcmFee = new BN(path.totalFee[1].amount || '0'); const xcmAmount = missingAmount.add(xcmFee); - const existentialDeposit = new BN(altInputTokenInfo.minAmount || '0'); const bnAltInputTokenBalance = new BN(altInputTokenBalance.value || '0'); - if (!bnAltInputTokenBalance.sub(xcmAmount).sub(xcmFee).sub(existentialDeposit).gt(BN_ZERO)) { + if (!bnAltInputTokenBalance.sub(xcmAmount).sub(xcmFee).gt(BN_ZERO)) { processValidation.failedStep = path.steps[1]; processValidation.ok = false; processValidation.status = YieldValidationStatus.NOT_ENOUGH_BALANCE; - const bnMaxXCM = new BN(altInputTokenBalance.value).sub(xcmFee.mul(new BN(XCM_FEE_RATIO))).sub(existentialDeposit); - const preCheckBnMaxXCM = bnMaxXCM.lte(BN_ZERO) ? BN_ZERO : bnMaxXCM; - - console.log('Precheck', preCheckBnMaxXCM); - const maxBn = bnInputTokenBalance.add(preCheckBnMaxXCM); + const bnMaxXCM = new BN(altInputTokenBalance.value).sub(xcmFee.mul(new BN(XCM_FEE_RATIO))); const inputTokenDecimal = _getAssetDecimals(inputTokenInfo); - - const maxValue = formatNumber(maxBn.toString(), inputTokenDecimal); - const maxXCMValue = formatNumber(preCheckBnMaxXCM.toString(), inputTokenDecimal); + const maxValue = formatNumber(bnMaxXCM.toString(), inputTokenDecimal); + const maxXCMValue = formatNumber(bnMaxXCM.toString(), inputTokenDecimal); const symbol = _getAssetSymbol(altInputTokenInfo); From 320d586666de5ecb858c5caf504b84ca13dc2766 Mon Sep 17 00:00:00 2001 From: tunghp2002 Date: Tue, 31 Dec 2024 15:38:36 +0700 Subject: [PATCH 08/11] [Fixed] Fixed missing amount display --- .../src/services/earning-service/handlers/special.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/extension-base/src/services/earning-service/handlers/special.ts b/packages/extension-base/src/services/earning-service/handlers/special.ts index 4d151978b3..05d1f8a509 100644 --- a/packages/extension-base/src/services/earning-service/handlers/special.ts +++ b/packages/extension-base/src/services/earning-service/handlers/special.ts @@ -106,7 +106,7 @@ export default abstract class BaseSpecialStakingPoolHandler extends BasePoolHand const bnAltInputAssetBalance = new BN(altInputAssetBalance.value); if (bnInputAssetBalance.add(bnAltInputAssetBalance).lt(bnMinJoinPool)) { - const missingAmount = bnMinJoinPool.sub(bnInputAssetBalance.sub(bnAltInputAssetBalance)); + const missingAmount = bnMinJoinPool.sub(bnInputAssetBalance).sub(bnAltInputAssetBalance); const originChain = this.state.getChainInfo(inputTokenInfo.originChain); const altChain = this.state.getChainInfo(altInputTokenInfo.originChain); From dc299652cdbf94b88b077fbf8c3b805931cbca5f Mon Sep 17 00:00:00 2001 From: tunghp2002 Date: Tue, 31 Dec 2024 18:02:39 +0700 Subject: [PATCH 09/11] [Update] Change content --- .../src/services/earning-service/handlers/special.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/extension-base/src/services/earning-service/handlers/special.ts b/packages/extension-base/src/services/earning-service/handlers/special.ts index 05d1f8a509..58dd7a2bdd 100644 --- a/packages/extension-base/src/services/earning-service/handlers/special.ts +++ b/packages/extension-base/src/services/earning-service/handlers/special.ts @@ -122,7 +122,7 @@ export default abstract class BaseSpecialStakingPoolHandler extends BasePoolHand return { passed: false, - errorMessage: `You need at least ${parsedMinJoinPool} ${originSymbol} (${originName}) or ${parsedMinAltJoinPool} ${altSymbol} (${altName}) to start earning` + errorMessage: `You need to deposit an additional ${parsedMinJoinPool} ${originSymbol} (${originName}) or ${parsedMinAltJoinPool} ${altSymbol} (${altName}) to start earning` }; } From 4629d9bebd476d37a6288c70c0df5c3b7e57c2f0 Mon Sep 17 00:00:00 2001 From: tunghp2002 Date: Thu, 2 Jan 2025 09:58:05 +0700 Subject: [PATCH 10/11] [Fix] Sum --- .../src/services/earning-service/handlers/special.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/extension-base/src/services/earning-service/handlers/special.ts b/packages/extension-base/src/services/earning-service/handlers/special.ts index 58dd7a2bdd..97f1820644 100644 --- a/packages/extension-base/src/services/earning-service/handlers/special.ts +++ b/packages/extension-base/src/services/earning-service/handlers/special.ts @@ -370,7 +370,8 @@ export default abstract class BaseSpecialStakingPoolHandler extends BasePoolHand const bnMaxXCM = new BN(altInputTokenBalance.value).sub(xcmFee.mul(new BN(XCM_FEE_RATIO))); const inputTokenDecimal = _getAssetDecimals(inputTokenInfo); - const maxValue = formatNumber(bnMaxXCM.toString(), inputTokenDecimal); + const maxBn = bnInputTokenBalance.add(new BN(altInputTokenBalance.value)).sub(xcmFee).sub(xcmFee); + const maxValue = formatNumber(maxBn.toString(), inputTokenInfo.decimals || 0); const maxXCMValue = formatNumber(bnMaxXCM.toString(), inputTokenDecimal); const symbol = _getAssetSymbol(altInputTokenInfo); From b660a020a3f13206f0794ffc1356ed524ac33e13 Mon Sep 17 00:00:00 2001 From: tunghp2002 Date: Thu, 2 Jan 2025 12:40:56 +0700 Subject: [PATCH 11/11] [Hot fix] Format popup message --- .../src/services/earning-service/handlers/special.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/extension-base/src/services/earning-service/handlers/special.ts b/packages/extension-base/src/services/earning-service/handlers/special.ts index 97f1820644..cfbb4d994e 100644 --- a/packages/extension-base/src/services/earning-service/handlers/special.ts +++ b/packages/extension-base/src/services/earning-service/handlers/special.ts @@ -107,7 +107,7 @@ export default abstract class BaseSpecialStakingPoolHandler extends BasePoolHand if (bnInputAssetBalance.add(bnAltInputAssetBalance).lt(bnMinJoinPool)) { const missingAmount = bnMinJoinPool.sub(bnInputAssetBalance).sub(bnAltInputAssetBalance); - + const isTheSame = missingAmount.toString() === bnMinJoinPool.toString(); const originChain = this.state.getChainInfo(inputTokenInfo.originChain); const altChain = this.state.getChainInfo(altInputTokenInfo.originChain); @@ -118,11 +118,13 @@ export default abstract class BaseSpecialStakingPoolHandler extends BasePoolHand const altName = altChain.name; const parsedMinJoinPool = formatNumber(missingAmount.toString(), inputAssetInfo.decimals || 0); + const formatparsedMinJoinPool = isTheSame ? parsedMinJoinPool : Number(parsedMinJoinPool) + 0.01; const parsedMinAltJoinPool = formatNumber((missingAmount.add(existentialDeposit)).toString(), inputAssetInfo.decimals || 0); + const formatParsedMinAltJoinPool = isTheSame ? parsedMinAltJoinPool : Number(parsedMinAltJoinPool) + 0.01; return { passed: false, - errorMessage: `You need to deposit an additional ${parsedMinJoinPool} ${originSymbol} (${originName}) or ${parsedMinAltJoinPool} ${altSymbol} (${altName}) to start earning` + errorMessage: `You need to deposit an additional ${formatparsedMinJoinPool} ${originSymbol} (${originName}) or ${formatParsedMinAltJoinPool} ${altSymbol} (${altName}) to start earning` }; }