Skip to content

Commit ed06a75

Browse files
committed
chore(suite): wip
1 parent b4104f3 commit ed06a75

File tree

13 files changed

+200
-37
lines changed

13 files changed

+200
-37
lines changed

packages/suite/src/components/suite/modals/ReduxModal/TransactionReviewModal/TransactionReviewSummary.tsx

+20-14
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { formatDurationStrict } from '@suite-common/suite-utils';
2-
import { NetworkType, networks } from '@suite-common/wallet-config';
2+
import { NetworkType, getNetworkFeatures, networks } from '@suite-common/wallet-config';
33
import { FeeInfo, GeneralPrecomposedTransactionFinal, StakeType } from '@suite-common/wallet-types';
44
import { getFee } from '@suite-common/wallet-utils';
55
import { Box, IconButton, Note, Row, Text } from '@trezor/components';
@@ -47,14 +47,22 @@ export const TransactionReviewSummary = ({
4747
const fees = useSelector(state => state.wallet.fees);
4848
const locale = useLocales();
4949
const { symbol, accountType, index, networkType } = account;
50+
5051
const network = networks[symbol];
51-
const fee = getFee(networkType, tx);
52+
53+
const baseFee = fees[symbol].levels[0].baseFeePerGas;
54+
const hasEip1559Feature = getNetworkFeatures(symbol).includes('eip1559');
55+
const shouldUsePriorityFees = !!tx.fee && hasEip1559Feature && !!baseFee;
56+
const fee = getFee({ account, tx, shouldUsePriorityFees });
57+
5258
const estimateTime = getEstimatedTime(networkType, fees[account.symbol], tx);
5359

5460
const formFeeRate = drafts[currentAccountKey]?.feePerUnit;
5561
const isFeeCustom = drafts[currentAccountKey]?.selectedFee === 'custom';
5662
const isComposedFeeRateDifferent = isFeeCustom && formFeeRate !== fee;
5763

64+
const isEthereumNetworkType = networkType === 'ethereum';
65+
5866
return (
5967
<Row columnGap={spacings.md} rowGap={spacings.xxs} flexWrap="wrap">
6068
<Row gap={spacings.xxs}>
@@ -74,25 +82,23 @@ export const TransactionReviewSummary = ({
7482
</Note>
7583
)}
7684

77-
{!!tx.feeLimit && network.networkType !== 'solana' && (
85+
{!!tx.feeLimit && network.networkType !== 'solana' && !hasEip1559Feature && (
7886
<Note iconName="gasPump">
7987
<Translation id="TR_GAS_LIMIT" />
8088
{': '}
8189
{tx.feeLimit}
8290
</Note>
8391
)}
8492

85-
{networkType === 'ethereum' ? (
86-
<Note iconName="gasPump">
87-
<Translation id="TR_GAS_PRICE" />
88-
{': '}
89-
<FeeRate feeRate={fee} networkType={network.networkType} symbol={symbol} />
90-
</Note>
91-
) : (
92-
<Note iconName="receipt">
93-
<FeeRate feeRate={fee} networkType={network.networkType} symbol={symbol} />
94-
</Note>
95-
)}
93+
<Note iconName={isEthereumNetworkType ? 'gasPump' : 'receipt'}>
94+
{isEthereumNetworkType && (
95+
<>
96+
<Translation id="TR_GAS_PRICE" />
97+
{': '}
98+
</>
99+
)}
100+
<FeeRate feeRate={fee} networkType={network.networkType} symbol={symbol} />
101+
</Note>
96102

97103
{isComposedFeeRateDifferent && network.networkType === 'bitcoin' && (
98104
<Translation id="TR_FEE_RATE_CHANGED" />

packages/suite/src/hooks/wallet/form/useCompose.ts

+30-3
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@ import { useCallback, useEffect, useRef, useState } from 'react';
22
import { FieldPath, UseFormReturn } from 'react-hook-form';
33

44
import { isFulfilled } from '@reduxjs/toolkit';
5+
import { fromWei } from 'web3-utils';
56

67
import { COMPOSE_ERROR_TYPES } from '@suite-common/wallet-constants';
78
import {
89
ComposeActionContext,
910
composeSendFormTransactionFeeLevelsThunk,
1011
} from '@suite-common/wallet-core';
12+
import { calculateBaseFeeFromEffectiveGasPrice } from '@suite-common/wallet-core/src/send/sendFormEthereumUtils';
1113
import {
1214
FormState,
1315
PrecomposedLevels,
@@ -170,7 +172,17 @@ export const useCompose = <TFieldValues extends FormState>({
170172
const prevLevel = composedLevels[prev || 'normal'];
171173
const levels = {
172174
...composedLevels,
173-
custom: prevLevel,
175+
custom: {
176+
...prevLevel,
177+
maxFeePerGas:
178+
'effectiveGasPrice' in prevLevel
179+
? prevLevel.effectiveGasPrice
180+
: undefined,
181+
maxPriorityFeePerGas:
182+
'maxPriorityFeePerGas' in prevLevel
183+
? prevLevel.maxPriorityFeePerGas
184+
: undefined,
185+
},
174186
} as
175187
| (PrecomposedLevels & { custom: PrecomposedTransaction })
176188
| (PrecomposedLevelsCardano & { custom: PrecomposedTransactionCardano });
@@ -208,9 +220,24 @@ export const useCompose = <TFieldValues extends FormState>({
208220
composed;
209221
setValue('feePerUnit', feePerByte);
210222
setValue('feeLimit', feeLimit || '');
211-
setValue('effectiveGasPrice', effectiveGasPrice || '');
223+
setValue('maxFeePerGas', effectiveGasPrice || '');
212224
setValue('maxPriorityFeePerGas', maxPriorityFeePerGas || '');
213-
setValue('customMaxPriorityFeePerGas', maxPriorityFeePerGas || '');
225+
setValue(
226+
'customMaxBaseFeePerGas',
227+
fromWei(
228+
Number(
229+
calculateBaseFeeFromEffectiveGasPrice({
230+
effectiveGasPriceWei: effectiveGasPrice || '0',
231+
maxPriorityFeePerGasWei: maxPriorityFeePerGas || '0',
232+
}),
233+
),
234+
'gwei',
235+
),
236+
);
237+
setValue(
238+
'customMaxPriorityFeePerGas',
239+
fromWei(maxPriorityFeePerGas || '0', 'gwei'),
240+
);
214241
}
215242
}
216243
// or do nothing, use default composed tx

packages/suite/src/hooks/wallet/form/useFees.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { useEffect, useRef } from 'react';
22
import { FieldPath, UseFormReturn } from 'react-hook-form';
33

4-
import { fromWei } from 'web3-utils';
4+
import { fromWei, toWei } from 'web3-utils';
55

66
import { calculateEffectiveGasPrice } from '@suite-common/wallet-core/src/send/sendFormEthereumUtils';
77
import {
@@ -146,8 +146,9 @@ export const useFees = <TFieldValues extends FormState>({
146146
feePerUnit,
147147
feeLimit,
148148
blocks: -1,
149-
maxPriorityFeePerGas: customMaxPriorityFeePerGas,
150-
maxFeePerGas: effectiveGasPrice,
149+
maxPriorityFeePerGas: toWei(customMaxPriorityFeePerGas || '0', 'gwei'),
150+
// maxFeePerGas: effectiveGasPrice,
151+
maxFeePerGas: '60606060',
151152
effectiveGasPrice,
152153
}),
153154
);

packages/suite/src/hooks/wallet/trading/form/common/useTradingComposeTransaction.ts

+2
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,8 @@ export const useTradingComposeTransaction = <T extends TradingSellExchangeFormPr
138138
clearErrors(FORM_OUTPUT_AMOUNT);
139139
}
140140

141+
console.log('composed3232', composed);
142+
141143
dispatch(saveComposedTransactionInfo({ selectedFee: selectedFeeLevel, composed }));
142144
setValue('estimatedFeeLimit', composed.estimatedFeeLimit, { shouldDirty: true });
143145
}

packages/suite/src/hooks/wallet/trading/form/useTradingExchangeForm.ts

+5
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ export const useTradingExchangeForm = ({
105105
recomposeAndSign,
106106
} = useTradingRecomposeAndSign();
107107

108+
console.log('selectedFeeRecomposedAndSigned123', selectedFeeRecomposedAndSigned, composed); //max fee per gas is empty
109+
108110
const [amountLimits, setAmountLimits] = useState<CryptoAmountLimitProps | undefined>(undefined);
109111

110112
const [innerQuotes, setInnerQuotes] = useState<ExchangeTrade[] | undefined>(
@@ -504,6 +506,8 @@ export const useTradingExchangeForm = ({
504506
setMaxOutputId: values.setMaxOutputId,
505507
});
506508

509+
console.log('selectedQuote123 result', result);
510+
507511
// in case of not success, recomposeAndSign shows notification
508512
if (result?.success) {
509513
const { txid } = result.payload;
@@ -553,6 +557,7 @@ export const useTradingExchangeForm = ({
553557
sendAddress &&
554558
selectedTrade.sendStringAmount
555559
) {
560+
console.log('SNED TX');
556561
const sendStringAmount = shouldSendInSats
557562
? amountToSmallestUnit(selectedTrade.sendStringAmount, decimals)
558563
: selectedTrade.sendStringAmount;

packages/suite/src/hooks/wallet/useSendForm.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -124,12 +124,13 @@ export const useSendForm = (props: UseSendFormProps): SendContextValues => {
124124
if (lastUsedFee) {
125125
feeEnhancement.selectedFee = lastUsedFee.label;
126126
if (lastUsedFee.label === 'custom') {
127-
feeEnhancement.feePerUnit = lastUsedFee.feePerUnit;
127+
feeEnhancement.feePerUnit = lastUsedFee.feePerUnit ?? '0';
128128
feeEnhancement.feeLimit = lastUsedFee.feeLimit;
129129
feeEnhancement.customMaxPriorityFeePerGas =
130130
lastUsedFee.customMaxPriorityFeePerGas;
131131
feeEnhancement.customMaxBaseFeePerGas = lastUsedFee.customMaxBaseFeePerGas;
132132
feeEnhancement.maxFeePerGas = lastUsedFee.maxFeePerGas;
133+
feeEnhancement.maxPriorityFeePerGas = lastUsedFee.maxPriorityFeePerGas;
133134
}
134135
}
135136
}

packages/suite/src/hooks/wallet/useSendFormCompose.ts

+14-4
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@ import { FieldPath, UseFormReturn } from 'react-hook-form';
33
import { useDispatch } from 'react-redux';
44

55
import { isFulfilled } from '@reduxjs/toolkit';
6+
import { fromWei } from 'web3-utils';
67

78
import { isChanged } from '@suite-common/suite-utils';
89
import { COMPOSE_ERROR_TYPES } from '@suite-common/wallet-constants';
910
import { composeSendFormTransactionFeeLevelsThunk } from '@suite-common/wallet-core';
11+
import { calculateBaseFeeFromEffectiveGasPrice } from '@suite-common/wallet-core/src/send/sendFormEthereumUtils';
1012
import {
1113
ExcludedUtxos,
1214
FormState,
@@ -262,12 +264,20 @@ export const useSendFormCompose = ({
262264
setValue('selectedFee', nearest);
263265
if (nearest === 'custom') {
264266
// @ts-expect-error: type = error already filtered above
265-
const { feePerByte, feeLimit, maxPriorityFeePerGas, maxBaseFeePerGas } =
266-
composed;
267+
const { feePerByte, feeLimit, maxPriorityFeePerGas, maxFeePerGas } = composed;
267268
setValue('feePerUnit', feePerByte);
268269
setValue('feeLimit', feeLimit || '');
269-
setValue('customMaxPriorityFeePerGas', maxPriorityFeePerGas || '');
270-
setValue('customMaxBaseFeePerGas', maxBaseFeePerGas || '');
270+
setValue(
271+
'customMaxPriorityFeePerGas',
272+
fromWei(maxPriorityFeePerGas || '0', 'gwei'),
273+
);
274+
setValue(
275+
'customMaxBaseFeePerGas',
276+
calculateBaseFeeFromEffectiveGasPrice({
277+
effectiveGasPriceWei: maxFeePerGas || '0',
278+
maxPriorityFeePerGasWei: maxPriorityFeePerGas || '0',
279+
}),
280+
);
271281
}
272282
setDraftSaveRequest(true);
273283
}

packages/suite/src/hooks/wallet/useTradingRecomposeAndSign.ts

+25
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
import { useCallback } from 'react';
22

3+
import { fromWei } from 'web3-utils';
4+
35
import { notificationsActions } from '@suite-common/toast-notifications';
46
import { networks } from '@suite-common/wallet-config';
57
import { DEFAULT_PAYMENT, DEFAULT_VALUES } from '@suite-common/wallet-constants';
68
import { composeSendFormTransactionFeeLevelsThunk } from '@suite-common/wallet-core';
9+
import { calculateBaseFeeFromEffectiveGasPrice } from '@suite-common/wallet-core/src/send/sendFormEthereumUtils';
710
import { FormState } from '@suite-common/wallet-types';
811
import type { Account, FormOptions } from '@suite-common/wallet-types';
912
import { getFeeInfo } from '@suite-common/wallet-utils';
@@ -57,6 +60,13 @@ export const useTradingRecomposeAndSign = () => {
5760
}
5861
// prepare the fee levels, set custom values from composed
5962
// WORKAROUND: sendFormEthereumActions and sendFormRippleActions use form outputs instead of composed transaction data
63+
const customMaxBaseFeePerGas = fromWei(
64+
calculateBaseFeeFromEffectiveGasPrice({
65+
effectiveGasPriceWei: composed.maxFeePerGas || '0',
66+
maxPriorityFeePerGasWei: composed.maxPriorityFeePerGas,
67+
}) || '0',
68+
'gwei',
69+
);
6070
const formState: FormState = {
6171
...DEFAULT_VALUES,
6272
outputs: [
@@ -70,6 +80,17 @@ export const useTradingRecomposeAndSign = () => {
7080
setMaxOutputId: !composed.token?.contract ? setMaxOutputId : undefined,
7181
selectedFee,
7282
feePerUnit: composed.feePerByte,
83+
maxFeePerGas:
84+
calculateBaseFeeFromEffectiveGasPrice({
85+
effectiveGasPriceWei: composed.maxFeePerGas || '0',
86+
maxPriorityFeePerGasWei: composed.maxPriorityFeePerGas,
87+
}) || '0',
88+
maxPriorityFeePerGas: composed.maxPriorityFeePerGas,
89+
customMaxBaseFeePerGas,
90+
customMaxPriorityFeePerGas: composed.maxPriorityFeePerGas
91+
? fromWei(composed.maxPriorityFeePerGas, 'gwei')
92+
: undefined,
93+
effectiveGasPrice: composed.maxFeePerGas,
7394
feeLimit: composed.feeLimit || '',
7495
estimatedFeeLimit: composed.estimatedFeeLimit,
7596
options,
@@ -124,16 +145,20 @@ export const useTradingRecomposeAndSign = () => {
124145

125146
return;
126147
}
148+
//TODO priority
127149
formState.feeLimit = normalLevels.normal.feeLimit;
128150
}
129151

130152
// compose transaction again to recalculate fees based on real account values
131153
const composedLevels = await dispatch(
154+
//max fee per gas is empty
132155
composeSendFormTransactionFeeLevelsThunk({
133156
formState,
134157
composeContext,
135158
}),
136159
).unwrap();
160+
161+
console.log('composedLevels123', composedLevels);
137162
if (!selectedFee || !composedLevels) {
138163
dispatch(
139164
notificationsActions.addToast({

packages/suite/src/hooks/wallet/useTradingRedirect.ts

+6
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ interface ExchangeOfferRedirectParams {
5252
selectedFee?: FeeLevel['label'];
5353
feePerByte?: string;
5454
feeLimit?: string;
55+
maxFeePerGas?: string;
56+
maxPriorityFeePerGas?: string;
5557
}
5658

5759
interface DetailRedirectParams {
@@ -158,6 +160,8 @@ export const useTradingRedirect = () => {
158160
orderId,
159161
feeLimit,
160162
feePerByte,
163+
maxFeePerGas,
164+
maxPriorityFeePerGas,
161165
selectedFee,
162166
} = params;
163167
const request: ExchangeTradeQuoteRequest = {
@@ -172,6 +176,8 @@ export const useTradingRedirect = () => {
172176
feeLimit,
173177
feePerByte: feePerByte || '',
174178
fee: '', // fee is not passed by redirect, will be recalculated
179+
maxFeePerGas,
180+
maxPriorityFeePerGas,
175181
};
176182
dispatch(saveComposedTransactionInfo({ selectedFee: selectedFee || 'normal', composed }));
177183
dispatch(tradingExchangeActions.saveTransactionId(orderId));

packages/suite/src/support/messages.ts

+32
Original file line numberDiff line numberDiff line change
@@ -3465,6 +3465,18 @@ export default defineMessages({
34653465
id: 'TR_CURRENT_FEE_CUSTOM_FEES',
34663466
defaultMessage: 'Current network fee:',
34673467
},
3468+
TR_CURRENT_BASE_FEE: {
3469+
id: 'TR_CURRENT_BASE_FEE',
3470+
defaultMessage: 'Current network base fee:',
3471+
},
3472+
TR_MAX_BASE_FEE_PER_GAS: {
3473+
id: 'TR_MAX_BASE_FEE_PER_GAS',
3474+
defaultMessage: 'Max base fee',
3475+
},
3476+
TR_CUSTOM_MAX_BASE_FEE_USE_NETWORK_BASE_FEE: {
3477+
id: 'TR_CUSTOM_MAX_BASE_FEE_USE_NETWORK_BASE_FEE',
3478+
defaultMessage: 'Use network base fee',
3479+
},
34683480
GAS_LIMIT_IS_NOT_SET: {
34693481
id: 'GAS_LIMIT_IS_NOT_SET',
34703482
defaultMessage: 'Set gas limit for this transaction',
@@ -5614,6 +5626,10 @@ export default defineMessages({
56145626
description: 'Label in Send form for Ethereum network type',
56155627
id: 'MAX_FEE',
56165628
},
5629+
WHY_FEES: {
5630+
defaultMessage: 'Why fees?',
5631+
id: 'WHY_FEES',
5632+
},
56175633
EXPECTED_FEE: {
56185634
defaultMessage: 'Expected fee',
56195635
description: 'Label in Send form for Solana network type',
@@ -5639,6 +5655,18 @@ export default defineMessages({
56395655
defaultMessage: 'Low',
56405656
id: 'FEE_LEVEL_LOW',
56415657
},
5658+
FEE_LEVEL_MEDIUM: {
5659+
defaultMessage: 'Medium',
5660+
id: 'FEE_LEVEL_MEDIUM',
5661+
},
5662+
TR_MAX_PRIORITY_FEE_PER_GAS: {
5663+
defaultMessage: 'Priority fee',
5664+
id: 'TR_MAX_PRIORITY_FEE_PER_GAS',
5665+
},
5666+
TR_MAX_FEE_PER_GAS: {
5667+
defaultMessage: 'Max fee',
5668+
id: 'TR_MAX_FEE_PER_GAS',
5669+
},
56425670
CUSTOM_FEE_IS_NOT_SET: {
56435671
defaultMessage:
56445672
'Enter the fee rate you want to spend in order to complete this transaction.',
@@ -5652,6 +5680,10 @@ export default defineMessages({
56525680
defaultMessage: 'Enter a fee between {minFee} and {maxFee}',
56535681
id: 'CUSTOM_FEE_NOT_IN_RANGE',
56545682
},
5683+
TR_CUSTOM_FEE_BASE_FEE_BELOW_CURRENT: {
5684+
defaultMessage: 'Custom base fee can not be below current network base fee.',
5685+
id: 'TR_CUSTOM_FEE_BASE_FEE_BELOW_CURRENT',
5686+
},
56555687
CUSTOM_FEE_LIMIT_BELOW_RECOMMENDED: {
56565688
defaultMessage: 'Gas limit too low',
56575689
id: 'CUSTOM_FEE_LIMIT_BELOW_RECOMMENDED',

0 commit comments

Comments
 (0)