From 3b7cc44ef554ddf4a4adeabec496995b5705313d Mon Sep 17 00:00:00 2001 From: Albina Nikiforova Date: Wed, 26 Feb 2025 13:28:12 +0100 Subject: [PATCH] feat(suite): priority fees in trading wip --- .../trading/form/useTradingExchangeForm.ts | 2 ++ .../wallet/useTradingRecomposeAndSign.ts | 4 +++ .../wallet-utils/src/sendFormUtils.ts | 31 +++++++++++++++++-- 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/packages/suite/src/hooks/wallet/trading/form/useTradingExchangeForm.ts b/packages/suite/src/hooks/wallet/trading/form/useTradingExchangeForm.ts index 91cbb02c716..c3e131d39ff 100644 --- a/packages/suite/src/hooks/wallet/trading/form/useTradingExchangeForm.ts +++ b/packages/suite/src/hooks/wallet/trading/form/useTradingExchangeForm.ts @@ -496,6 +496,8 @@ export const useTradingExchangeForm = ({ setMaxOutputId: values.setMaxOutputId, }); + console.log('result', result); + // in case of not success, recomposeAndSign shows notification if (result?.success) { const { txid } = result.payload; diff --git a/packages/suite/src/hooks/wallet/useTradingRecomposeAndSign.ts b/packages/suite/src/hooks/wallet/useTradingRecomposeAndSign.ts index 317e2b75950..e8ea3291db6 100644 --- a/packages/suite/src/hooks/wallet/useTradingRecomposeAndSign.ts +++ b/packages/suite/src/hooks/wallet/useTradingRecomposeAndSign.ts @@ -72,6 +72,8 @@ export const useTradingRecomposeAndSign = () => { feePerUnit: composed.feePerByte, maxFeePerGas: composed.maxFeePerGas, maxPriorityFeePerGas: composed.maxPriorityFeePerGas, + customMaxBaseFeePerGas: composed.maxFeePerGas, + customMaxPriorityFeePerGas: composed.maxPriorityFeePerGas, feeLimit: composed.feeLimit || '', estimatedFeeLimit: composed.estimatedFeeLimit, options, @@ -86,6 +88,8 @@ export const useTradingRecomposeAndSign = () => { const feeInfo = getFeeInfo({ networkType: account.networkType, feeInfo: fees[account.symbol], + customMaxFeePerGas: composed.maxFeePerGas, + customMaxPriorityFeePerGas: composed.maxPriorityFeePerGas, }); const composeContext = { account, network, feeInfo }; diff --git a/suite-common/wallet-utils/src/sendFormUtils.ts b/suite-common/wallet-utils/src/sendFormUtils.ts index 534a5f55e0e..bc52dcc4217 100644 --- a/suite-common/wallet-utils/src/sendFormUtils.ts +++ b/suite-common/wallet-utils/src/sendFormUtils.ts @@ -196,12 +196,21 @@ export const prepareEthereumTransaction = ( interface GetFeeInfoProps { feeInfo: FeeInfo; networkType: NetworkType; + customMaxFeePerGas?: string; + customMaxPriorityFeePerGas?: string; } -const getFeeLevels = ({ feeInfo, networkType }: GetFeeInfoProps) => { +const getFeeLevels = ({ + feeInfo, + networkType, + customMaxFeePerGas, + customMaxPriorityFeePerGas, +}: GetFeeInfoProps) => { const levels = feeInfo.levels.concat({ label: 'custom', feePerUnit: '0', + // maxFeePerGas: customMaxFeePerGas, + // maxPriorityFeePerGas: customMaxPriorityFeePerGas, blocks: -1, }); @@ -215,6 +224,7 @@ const getFeeLevels = ({ feeInfo, networkType }: GetFeeInfoProps) => { feePerUnit: level.feePerUnit, maxFeePerGas: level.maxFeePerGas, maxPriorityFeePerGas: level.maxPriorityFeePerGas, + effectiveMaxFeePerGas: level.effectiveGasPrice, feeLimit: level.feeLimit, })); } @@ -228,10 +238,20 @@ const getFeeLevels = ({ feeInfo, networkType }: GetFeeInfoProps) => { ? feeInfo.minFee.toString() : gwei.toString(); + const calculatedMaxFeePerGas = BigNumber.minimum( + new BigNumber(level?.maxFeePerGas || '0'), + new BigNumber(feeInfo.levels[0].baseFeePerGas || '0').plus( + level?.maxPriorityFeePerGas || '0', + ), + ).toFixed(); + return { ...level, feePerUnit, feeLimit: level.feeLimit, + maxFeePerGas: customMaxFeePerGas, + maxPriorityFeePerGas: customMaxPriorityFeePerGas, + effectiveMaxFeePerGas: calculatedMaxFeePerGas, }; }); } @@ -239,9 +259,14 @@ const getFeeLevels = ({ feeInfo, networkType }: GetFeeInfoProps) => { return levels; }; -export const getFeeInfo = ({ networkType, feeInfo }: GetFeeInfoProps): FeeInfo => ({ +export const getFeeInfo = ({ + networkType, + feeInfo, + customMaxFeePerGas, + customMaxPriorityFeePerGas, +}: GetFeeInfoProps): FeeInfo => ({ ...feeInfo, - levels: getFeeLevels({ networkType, feeInfo }), + levels: getFeeLevels({ networkType, feeInfo, customMaxFeePerGas, customMaxPriorityFeePerGas }), }); export const getInputState = (