Skip to content

Commit

Permalink
feat(suite): priority fees in trading wip
Browse files Browse the repository at this point in the history
  • Loading branch information
enjojoy committed Feb 26, 2025
1 parent 56841db commit 3b7cc44
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions packages/suite/src/hooks/wallet/useTradingRecomposeAndSign.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 };

Expand Down
31 changes: 28 additions & 3 deletions suite-common/wallet-utils/src/sendFormUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});

Expand All @@ -215,6 +224,7 @@ const getFeeLevels = ({ feeInfo, networkType }: GetFeeInfoProps) => {
feePerUnit: level.feePerUnit,
maxFeePerGas: level.maxFeePerGas,
maxPriorityFeePerGas: level.maxPriorityFeePerGas,
effectiveMaxFeePerGas: level.effectiveGasPrice,
feeLimit: level.feeLimit,
}));
}
Expand All @@ -228,20 +238,35 @@ 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,
};
});
}

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 = (
Expand Down

0 comments on commit 3b7cc44

Please sign in to comment.