Skip to content

Commit ff612aa

Browse files
committed
feat(suite-native): add eip1559 custom fee inputs
1 parent f3eb837 commit ff612aa

File tree

4 files changed

+65
-18
lines changed

4 files changed

+65
-18
lines changed

suite-native/transaction-management/src/components/fees/CustomFee/CustomFeeInputs.tsx

Lines changed: 55 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { G } from '@mobily/ts-belt';
44

55
import { NetworkSymbol, getNetworkType } from '@suite-common/wallet-config';
66
import { FeesRootState, selectConvertedNetworkFeeInfo } from '@suite-common/wallet-core';
7-
import { getFeeUnits } from '@suite-common/wallet-utils';
7+
import { getFeeUnits, isEip1559 } from '@suite-common/wallet-utils';
88
import { Hint, Text, VStack } from '@suite-native/atoms';
99
import { TextInputField, useFormContext } from '@suite-native/forms';
1010
import { integerTransformer, useAmountInputTransformers } from '@suite-native/helpers';
@@ -32,11 +32,14 @@ export const CustomFeeInputs = ({ symbol }: CustomFeeInputsProps) => {
3232

3333
const customFeeLimitName = 'customFeeLimit';
3434
const feePerUnitFieldName = 'customFeePerUnit';
35+
const maxFeePerGasFieldName = 'customMaxFeePerGas';
36+
const maxPriorityFeePerGasFieldName = 'customMaxPriorityFeePerGas';
3537
const hasFeePerByteError = G.isNotNullable(errors[feePerUnitFieldName]);
3638

3739
const networkType = getNetworkType(symbol);
3840
const feeUnits = getFeeUnits(networkType);
3941
const formattedFeePerUnit = `${feeInfo?.minFee} ${feeUnits}`;
42+
const isEip1559Fee = networkType === 'ethereum' && isEip1559(feeInfo?.levels[0]);
4043

4144
const handleFieldChangeValue =
4245
(fieldName: keyof FeesFormValues, transformer: (value: string) => string) =>
@@ -61,19 +64,57 @@ export const CustomFeeInputs = ({ symbol }: CustomFeeInputsProps) => {
6164
onChangeText={handleFieldChangeValue(customFeeLimitName, integerTransformer)}
6265
/>
6366
)}
64-
<TextInputField
65-
label={
66-
networkType === 'ethereum'
67-
? translate('transactionManagement.fees.custom.bottomSheet.label.gasPrice')
68-
: translate('transactionManagement.fees.custom.bottomSheet.label.feeRate')
69-
}
70-
name={feePerUnitFieldName}
71-
testID={`@transactionManagement/${feePerUnitFieldName}-input`}
72-
accessibilityLabel="address input"
73-
keyboardType={networkType === 'bitcoin' ? 'decimal-pad' : 'number-pad'}
74-
rightIcon={<Text color="textSubdued">{feeUnits}</Text>}
75-
onChangeText={handleFieldChangeValue(feePerUnitFieldName, cryptoAmountTransformer)}
76-
/>
67+
{isEip1559Fee ? (
68+
<>
69+
<TextInputField
70+
label={translate(
71+
'transactionManagement.fees.custom.bottomSheet.label.maxFeePerGas',
72+
)}
73+
name={maxFeePerGasFieldName}
74+
testID={`@transactionManagement/${maxFeePerGasFieldName}-input`}
75+
accessibilityLabel="address input"
76+
keyboardType="number-pad"
77+
onChangeText={handleFieldChangeValue(
78+
maxFeePerGasFieldName,
79+
integerTransformer,
80+
)}
81+
/>
82+
<TextInputField
83+
label={translate(
84+
'transactionManagement.fees.custom.bottomSheet.label.maxPriorityFeePerGas',
85+
)}
86+
name={maxPriorityFeePerGasFieldName}
87+
testID={`@transactionManagement/${maxPriorityFeePerGasFieldName}-input`}
88+
accessibilityLabel="address input"
89+
keyboardType="number-pad"
90+
onChangeText={handleFieldChangeValue(
91+
maxPriorityFeePerGasFieldName,
92+
integerTransformer,
93+
)}
94+
/>
95+
</>
96+
) : (
97+
<TextInputField
98+
label={
99+
networkType === 'ethereum'
100+
? translate(
101+
'transactionManagement.fees.custom.bottomSheet.label.gasPrice',
102+
)
103+
: translate(
104+
'transactionManagement.fees.custom.bottomSheet.label.feeRate',
105+
)
106+
}
107+
name={feePerUnitFieldName}
108+
testID={`@transactionManagement/${feePerUnitFieldName}-input`}
109+
accessibilityLabel="address input"
110+
keyboardType={networkType === 'bitcoin' ? 'decimal-pad' : 'number-pad'}
111+
rightIcon={<Text color="textSubdued">{feeUnits}</Text>}
112+
onChangeText={handleFieldChangeValue(
113+
feePerUnitFieldName,
114+
cryptoAmountTransformer,
115+
)}
116+
/>
117+
)}
77118
{networkType !== 'ethereum' && !hasFeePerByteError && (
78119
<Hint variant="info">
79120
<Translation

suite-native/transaction-management/src/feesFormSchema.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ export const feesFormValidationSchema = yup.object({
7676
return feeBig.lte(maxFee);
7777
},
7878
),
79+
80+
// FIXME: add validations
7981
customFeeLimit: yup
8082
.string()
8183
.test(
@@ -97,6 +99,8 @@ export const feesFormValidationSchema = yup.object({
9799
return feeBig.gte(minimalFeeLimit);
98100
},
99101
),
102+
// FIXME: add validations
103+
customMaxFeePerGas: yup.string(),
100104
});
101105

102106
export type FeesFormValues = yup.InferType<typeof feesFormValidationSchema>;

suite-native/transaction-management/src/hooks/fees/useFeeCalculation.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ export const useFeeCalculation = ({
4040
const feeLevels = useSelector(selectFeeLevels);
4141
const { symbol } = account ?? {};
4242

43+
const normalFee = isFinalPrecomposedTransaction(feeLevels.normal)
44+
? (feeLevels.normal as PrecomposedTransactionFinal)
45+
: null;
46+
4347
const form = useFeesForm({
4448
accountKey,
4549
defaultFeeLevel: selectedFee,
@@ -55,10 +59,6 @@ export const useFeeCalculation = ({
5559
selectConvertedNetworkFeeLevelFeePerUnit(state, symbol, selectedFeeLevel),
5660
);
5761

58-
const normalFee = isFinalPrecomposedTransaction(feeLevels.normal)
59-
? (feeLevels.normal as PrecomposedTransactionFinal)
60-
: null;
61-
6262
const { areFeesLoading } = useFeesFetching({
6363
networkSymbol: symbol,
6464
isRefetchDisabled: selectedFeeLevel === 'custom' || selectedSetMaxOutputId !== undefined,

suite-native/transaction-management/src/hooks/fees/useFeesForm.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ export const useFeesForm = ({
5757
feeLevel: defaultFeeLevel,
5858
customFeePerUnit: trimmedFeePerUnit,
5959
customFeeLimit: normalFee?.feeLimit,
60+
customMaxFeePerGas: normalFee?.maxFeePerGas,
61+
customMaxPriorityFeePerGas: normalFee?.maxPriorityFeePerGas,
6062
},
6163
context: {
6264
networkFeeInfo,

0 commit comments

Comments
 (0)