1
1
import { useCallback } from 'react' ;
2
2
3
+ import { fromWei } from 'web3-utils' ;
4
+
3
5
import { notificationsActions } from '@suite-common/toast-notifications' ;
4
6
import { networks } from '@suite-common/wallet-config' ;
5
7
import { DEFAULT_PAYMENT , DEFAULT_VALUES } from '@suite-common/wallet-constants' ;
6
8
import { composeSendFormTransactionFeeLevelsThunk } from '@suite-common/wallet-core' ;
9
+ import { calculateBaseFeeFromEffectiveGasPrice } from '@suite-common/wallet-core/src/send/sendFormEthereumUtils' ;
7
10
import { FormState } from '@suite-common/wallet-types' ;
8
11
import type { Account , FormOptions } from '@suite-common/wallet-types' ;
9
12
import { getFeeInfo } from '@suite-common/wallet-utils' ;
@@ -57,6 +60,13 @@ export const useTradingRecomposeAndSign = () => {
57
60
}
58
61
// prepare the fee levels, set custom values from composed
59
62
// 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
+ ) ;
60
70
const formState : FormState = {
61
71
...DEFAULT_VALUES ,
62
72
outputs : [
@@ -70,6 +80,17 @@ export const useTradingRecomposeAndSign = () => {
70
80
setMaxOutputId : ! composed . token ?. contract ? setMaxOutputId : undefined ,
71
81
selectedFee,
72
82
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 ,
73
94
feeLimit : composed . feeLimit || '' ,
74
95
estimatedFeeLimit : composed . estimatedFeeLimit ,
75
96
options,
@@ -124,16 +145,20 @@ export const useTradingRecomposeAndSign = () => {
124
145
125
146
return ;
126
147
}
148
+ //TODO priority
127
149
formState . feeLimit = normalLevels . normal . feeLimit ;
128
150
}
129
151
130
152
// compose transaction again to recalculate fees based on real account values
131
153
const composedLevels = await dispatch (
154
+ //max fee per gas is empty
132
155
composeSendFormTransactionFeeLevelsThunk ( {
133
156
formState,
134
157
composeContext,
135
158
} ) ,
136
159
) . unwrap ( ) ;
160
+
161
+ console . log ( 'composedLevels123' , composedLevels ) ;
137
162
if ( ! selectedFee || ! composedLevels ) {
138
163
dispatch (
139
164
notificationsActions . addToast ( {
0 commit comments