@@ -9,14 +9,15 @@ import {
9
9
UNSTAKE_INTERCHANGES ,
10
10
} from '@suite-common/wallet-constants' ;
11
11
import { ComposeActionContext , selectSelectedDevice } from '@suite-common/wallet-core' ;
12
+ import { calculateEffectiveGasPrice } from '@suite-common/wallet-core/src/send/sendFormEthereumUtils' ;
12
13
import {
13
14
AddressDisplayOptions ,
14
15
ExternalOutput ,
15
16
PrecomposedTransaction ,
16
17
PrecomposedTransactionFinal ,
17
18
StakeFormState ,
18
19
} from '@suite-common/wallet-types' ;
19
- import { calculateEthFee , getAccountIdentity , isPending } from '@suite-common/wallet-utils' ;
20
+ import { calculateMaxEthFee , getAccountIdentity , isPending } from '@suite-common/wallet-utils' ;
20
21
import TrezorConnect , { FeeLevel } from '@trezor/connect' ;
21
22
import { BigNumber } from '@trezor/utils/src/bigNumber' ;
22
23
@@ -31,14 +32,18 @@ import {
31
32
32
33
import { calculate , composeStakingTransaction } from './stakeFormActions' ;
33
34
34
- const calculateTransaction = (
35
+ const calculateStakingTransaction = (
35
36
availableBalance : string ,
36
37
output : ExternalOutput ,
37
38
feeLevel : FeeLevel ,
38
39
compareWithAmount = true ,
39
40
symbol : NetworkSymbol ,
40
41
) : PrecomposedTransaction => {
41
- const feeInWei = calculateEthFee ( toWei ( feeLevel . feePerUnit , 'gwei' ) , feeLevel . feeLimit || '0' ) ;
42
+ const isEip1559 = feeLevel . maxPriorityFeePerGas !== undefined ;
43
+
44
+ const feeInWei = isEip1559
45
+ ? calculateMaxEthFee ( feeLevel . effectiveGasPrice , feeLevel . feeLimit )
46
+ : calculateMaxEthFee ( toWei ( feeLevel . feePerUnit , 'gwei' ) , feeLevel . feeLimit ) ;
42
47
43
48
const stakingParams = {
44
49
feeInBaseUnits : feeInWei ,
@@ -47,6 +52,8 @@ const calculateTransaction = (
47
52
minAmountForWithdrawalInBaseUnits : toWei ( MIN_ETH_FOR_WITHDRAWALS . toString ( ) , 'ether' ) ,
48
53
} ;
49
54
55
+ console . log ( 'feeLevel' , feeLevel ) ;
56
+
50
57
return calculate ( availableBalance , output , feeLevel , compareWithAmount , symbol , stakingParams ) ;
51
58
} ;
52
59
@@ -81,11 +88,20 @@ export const composeTransaction =
81
88
predefinedLevels . forEach ( l => ( l . feeLimit = customFeeLimit ) ) ;
82
89
}
83
90
// in case when selectedFee is set to 'custom' construct this FeeLevel from values
91
+ //TODO: calculate effective gas price here?
84
92
if ( formValues . selectedFee === 'custom' ) {
93
+ const calculatedEffectiveGasPrice = calculateEffectiveGasPrice (
94
+ formValues . customMaxPriorityFeePerGas ,
95
+ formValues . customMaxBaseFeePerGas ,
96
+ ) ;
85
97
predefinedLevels . push ( {
86
98
label : 'custom' ,
87
99
feePerUnit : formValues . feePerUnit ,
88
100
feeLimit : formValues . feeLimit ,
101
+ customMaxBaseFeePerGas : formValues . customMaxBaseFeePerGas ,
102
+ customMaxPriorityFeePerGas : formValues . customMaxPriorityFeePerGas ,
103
+ effectiveGasPrice : calculatedEffectiveGasPrice ,
104
+ maxPriorityFeePerGas : toWei ( Number ( formValues . customMaxPriorityFeePerGas ) , 'gwei' ) ,
89
105
blocks : - 1 ,
90
106
} ) ;
91
107
}
@@ -94,7 +110,7 @@ export const composeTransaction =
94
110
formValues ,
95
111
formState ,
96
112
predefinedLevels ,
97
- calculateTransaction ,
113
+ calculateStakingTransaction ,
98
114
undefined ,
99
115
customFeeLimit ,
100
116
) ;
@@ -150,6 +166,8 @@ export const signTransaction =
150
166
identity,
151
167
amount : formValues . outputs [ 0 ] . amount ,
152
168
gasPrice : transactionInfo . feePerByte ,
169
+ maxFeePerGas : transactionInfo . maxFeePerGas ,
170
+ maxPriorityFeePerGas : transactionInfo . maxPriorityFeePerGas ,
153
171
nonce,
154
172
chainId : network . chainId ,
155
173
} ) ;
@@ -161,6 +179,8 @@ export const signTransaction =
161
179
identity,
162
180
amount : formValues . outputs [ 0 ] . amount ,
163
181
gasPrice : transactionInfo . feePerByte ,
182
+ maxFeePerGas : transactionInfo . maxFeePerGas ,
183
+ maxPriorityFeePerGas : transactionInfo . maxPriorityFeePerGas ,
164
184
nonce,
165
185
chainId : network . chainId ,
166
186
interchanges : UNSTAKE_INTERCHANGES ,
@@ -172,6 +192,8 @@ export const signTransaction =
172
192
from : account . descriptor ,
173
193
identity,
174
194
gasPrice : transactionInfo . feePerByte ,
195
+ maxFeePerGas : transactionInfo . maxFeePerGas ,
196
+ maxPriorityFeePerGas : transactionInfo . maxPriorityFeePerGas ,
175
197
nonce,
176
198
chainId : network . chainId ,
177
199
} ) ;
0 commit comments