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 , variables , useMediaQuery } 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 ;
@@ -36,24 +39,26 @@ interface CustomFeeProps<TFieldValues extends FormState> {
36
39
control : Control ;
37
40
setValue : UseFormSetValue < TFieldValues > ;
38
41
getValues : UseFormGetValues < TFieldValues > ;
39
- changeFeeLimit ?: ( value : string ) => void ;
40
42
composedFeePerByte : string ;
43
+ shouldUsePriorityFees : boolean ;
41
44
}
42
45
43
46
export const CustomFee = < TFieldValues extends FormState > ( {
44
47
networkType,
45
48
feeInfo,
46
49
register,
47
50
control,
48
- changeFeeLimit,
49
51
composedFeePerByte,
52
+ shouldUsePriorityFees = false ,
50
53
...props
51
54
} : CustomFeeProps < TFieldValues > ) => {
52
55
const { translationString } = useTranslation ( ) ;
53
56
const isBelowLaptop = useMediaQuery ( `(max-width: ${ variables . SCREEN_SIZE . LG } )` ) ;
54
57
55
58
const locale = useSelector ( selectLanguage ) ;
56
59
60
+ console . log ( 'feeInfo' , feeInfo ) ;
61
+
57
62
// Type assertion allowing to make the component reusable, see https://stackoverflow.com/a/73624072.
58
63
const { getValues, setValue } = props as unknown as UseFormReturn < FormState > ;
59
64
const errors = props . errors as unknown as FieldErrors < FormState > ;
@@ -64,6 +69,11 @@ 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
+
67
77
const feePerUnitError = errors . feePerUnit ;
68
78
const feeLimitError = errors . feeLimit ;
69
79
@@ -169,7 +179,6 @@ export const CustomFee = <TFieldValues extends FormState>({
169
179
inputState = { getInputState ( feeLimitError ) }
170
180
name = { FEE_LIMIT }
171
181
data-testid = { FEE_LIMIT }
172
- onChange = { changeFeeLimit }
173
182
bottomText = {
174
183
feeLimitError ?. message ? (
175
184
< InputError
@@ -183,21 +192,57 @@ export const CustomFee = <TFieldValues extends FormState>({
183
192
) : (
184
193
< input type = "hidden" { ...register ( FEE_LIMIT as FieldPath < TFieldValues > ) } />
185
194
) }
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
- />
195
+
196
+ { shouldUsePriorityFees && feeInfo . levels [ 0 ] . ethFeeType === 'eip1559' ? (
197
+ < >
198
+ < NumberInput
199
+ label = { < Translation id = "TR_MAX_PRIORITY_FEE_PER_GAS" /> }
200
+ locale = { locale }
201
+ control = { control }
202
+ inputState = { getInputState ( feePerUnitError ) }
203
+ innerAddon = {
204
+ < Text variant = "tertiary" typographyStyle = "label" >
205
+ { feeUnits }
206
+ </ Text >
207
+ }
208
+ name = { MAX_PRIORITY_FEE_PER_GAS }
209
+ data-testid = { MAX_PRIORITY_FEE_PER_GAS }
210
+ rules = { feeRules }
211
+ bottomText = { feePerUnitError ?. message || null }
212
+ />
213
+ < NumberInput
214
+ label = { < Translation id = "TR_MAX_FEE_PER_GAS" /> }
215
+ locale = { locale }
216
+ control = { control }
217
+ inputState = { getInputState ( feePerUnitError ) }
218
+ innerAddon = {
219
+ < Text variant = "tertiary" typographyStyle = "label" >
220
+ { feeUnits }
221
+ </ Text >
222
+ }
223
+ name = { MAX_FEE_PER_GAS }
224
+ data-testid = { MAX_FEE_PER_GAS }
225
+ rules = { feeRules }
226
+ bottomText = { feePerUnitError ?. message || null }
227
+ />
228
+ </ >
229
+ ) : (
230
+ < NumberInput
231
+ label = { useFeeLimit ? < Translation id = "TR_GAS_PRICE" /> : undefined }
232
+ locale = { locale }
233
+ control = { control }
234
+ inputState = { getInputState ( feePerUnitError ) }
235
+ innerAddon = {
236
+ < Text variant = "tertiary" typographyStyle = "label" >
237
+ { feeUnits }
238
+ </ Text >
239
+ }
240
+ name = { FEE_PER_UNIT }
241
+ data-testid = { FEE_PER_UNIT }
242
+ rules = { feeRules }
243
+ bottomText = { feePerUnitError ?. message || null }
244
+ />
245
+ ) }
201
246
</ Grid >
202
247
{ feeDifferenceWarning && < Note > { feeDifferenceWarning } </ Note > }
203
248
</ Column >
0 commit comments