9
9
} from 'react-hook-form' ;
10
10
11
11
import { BigNumber } from '@trezor/utils/src/bigNumber' ;
12
- import { Note , Banner , variables , Grid , Column , useMediaQuery , Text } from '@trezor/components' ;
12
+ import { Note , Banner , Grid , Column , Text } from '@trezor/components' ;
13
13
import { getInputState , getFeeUnits , isInteger } from '@suite-common/wallet-utils' ;
14
14
import { FeeInfo , FormState } from '@suite-common/wallet-types' ;
15
15
import { NetworkType } from '@suite-common/wallet-config' ;
@@ -28,6 +28,9 @@ import { InputError } from '../InputError';
28
28
const FEE_PER_UNIT = 'feePerUnit' ;
29
29
const FEE_LIMIT = 'feeLimit' ;
30
30
31
+ const MAX_FEE_PER_GAS = 'maxFeePerGas' ;
32
+ const MAX_PRIORITY_FEE_PER_GAS = 'maxPriorityFeePerGas' ;
33
+
31
34
interface CustomFeeProps < TFieldValues extends FormState > {
32
35
networkType : NetworkType ;
33
36
feeInfo : FeeInfo ;
@@ -38,6 +41,7 @@ interface CustomFeeProps<TFieldValues extends FormState> {
38
41
getValues : UseFormGetValues < TFieldValues > ;
39
42
changeFeeLimit ?: ( value : string ) => void ;
40
43
composedFeePerByte : string ;
44
+ shouldUsePriorityFees : boolean ;
41
45
}
42
46
43
47
export const CustomFee = < TFieldValues extends FormState > ( {
@@ -47,10 +51,11 @@ export const CustomFee = <TFieldValues extends FormState>({
47
51
control,
48
52
changeFeeLimit,
49
53
composedFeePerByte,
54
+ shouldUsePriorityFees = false ,
50
55
...props
51
56
} : CustomFeeProps < TFieldValues > ) => {
52
57
const { translationString } = useTranslation ( ) ;
53
- const isBelowLaptop = useMediaQuery ( `(max-width: ${ variables . SCREEN_SIZE . LG } )` ) ;
58
+ // const isBelowLaptop = useMediaQuery(`(max-width: ${variables.SCREEN_SIZE.LG})`);
54
59
55
60
const locale = useSelector ( selectLanguage ) ;
56
61
@@ -64,6 +69,13 @@ export const CustomFee = <TFieldValues extends FormState>({
64
69
const feeUnits = getFeeUnits ( networkType ) ;
65
70
const estimatedFeeLimit = getValues ( 'estimatedFeeLimit' ) ;
66
71
72
+ const maxFeePerGas = shouldUsePriorityFees ? getValues ( MAX_FEE_PER_GAS ) : undefined ; //only for priority fees on evms
73
+ const maxPriorityFeePerGas = shouldUsePriorityFees
74
+ ? getValues ( MAX_PRIORITY_FEE_PER_GAS )
75
+ : undefined ;
76
+
77
+ console . log ( 'customFees' , shouldUsePriorityFees , maxFeePerGas , maxPriorityFeePerGas ) ;
78
+
67
79
const feePerUnitError = errors . feePerUnit ;
68
80
const feeLimitError = errors . feeLimit ;
69
81
@@ -160,7 +172,7 @@ export const CustomFee = <TFieldValues extends FormState>({
160
172
>
161
173
< Translation id = "TR_CUSTOM_FEE_WARNING" />
162
174
</ Banner >
163
- < Grid gap = { spacings . xs } columns = { useFeeLimit && ! isBelowLaptop ? 2 : 1 } >
175
+ < Grid gap = { spacings . xs } columns = { 1 } >
164
176
{ useFeeLimit ? (
165
177
< NumberInput
166
178
label = { < Translation id = "TR_GAS_LIMIT" /> }
@@ -183,21 +195,57 @@ export const CustomFee = <TFieldValues extends FormState>({
183
195
) : (
184
196
< input type = "hidden" { ...register ( FEE_LIMIT as FieldPath < TFieldValues > ) } />
185
197
) }
186
- < NumberInput
187
- label = { useFeeLimit ? < Translation id = "TR_GAS_PRICE" /> : undefined }
188
- locale = { locale }
189
- control = { control }
190
- inputState = { getInputState ( feePerUnitError ) }
191
- innerAddon = {
192
- < Text variant = "tertiary" typographyStyle = "label" >
193
- { feeUnits }
194
- </ Text >
195
- }
196
- name = { FEE_PER_UNIT }
197
- data-testid = { FEE_PER_UNIT }
198
- rules = { feeRules }
199
- bottomText = { feePerUnitError ?. message || null }
200
- />
198
+
199
+ { shouldUsePriorityFees ? (
200
+ < >
201
+ < NumberInput
202
+ label = { < Translation id = "TR_MAX_PRIORITY_FEE_PER_GAS" /> }
203
+ locale = { locale }
204
+ control = { control }
205
+ inputState = { getInputState ( feePerUnitError ) }
206
+ innerAddon = {
207
+ < Text variant = "tertiary" typographyStyle = "label" >
208
+ { feeUnits }
209
+ </ Text >
210
+ }
211
+ name = { MAX_PRIORITY_FEE_PER_GAS }
212
+ data-testid = { MAX_PRIORITY_FEE_PER_GAS }
213
+ rules = { feeRules }
214
+ bottomText = { feePerUnitError ?. message || null }
215
+ />
216
+ < NumberInput
217
+ label = { < Translation id = "TR_MAX_FEE_PER_GAS" /> }
218
+ locale = { locale }
219
+ control = { control }
220
+ inputState = { getInputState ( feePerUnitError ) }
221
+ innerAddon = {
222
+ < Text variant = "tertiary" typographyStyle = "label" >
223
+ { feeUnits }
224
+ </ Text >
225
+ }
226
+ name = { MAX_FEE_PER_GAS }
227
+ data-testid = { MAX_FEE_PER_GAS }
228
+ rules = { feeRules }
229
+ bottomText = { feePerUnitError ?. message || null }
230
+ />
231
+ </ >
232
+ ) : (
233
+ < NumberInput
234
+ label = { useFeeLimit ? < Translation id = "TR_GAS_PRICE" /> : undefined }
235
+ locale = { locale }
236
+ control = { control }
237
+ inputState = { getInputState ( feePerUnitError ) }
238
+ innerAddon = {
239
+ < Text variant = "tertiary" typographyStyle = "label" >
240
+ { feeUnits }
241
+ </ Text >
242
+ }
243
+ name = { FEE_PER_UNIT }
244
+ data-testid = { FEE_PER_UNIT }
245
+ rules = { feeRules }
246
+ bottomText = { feePerUnitError ?. message || null }
247
+ />
248
+ ) }
201
249
</ Grid >
202
250
{ feeDifferenceWarning && < Note > { feeDifferenceWarning } </ Note > }
203
251
</ Column >
0 commit comments