Skip to content

Commit d220f38

Browse files
committed
fix(suite-native): fix customfee tests
1 parent 4fd8a6b commit d220f38

File tree

9 files changed

+35
-22
lines changed

9 files changed

+35
-22
lines changed

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,11 @@ describe('feesFormValidationSchema', () => {
6565
customFeePerUnit: '500000', // Valid for Ethereum and within maxFee limit
6666
customFeeLimit: '10000',
6767
};
68-
const context = createContext({ minimalFeeLimit: '21000' });
68+
69+
const context = createContext({
70+
minimalFeeLimit: '21000',
71+
translate: () => 'Value is too low.',
72+
});
6973

7074
await expect(feesFormValidationSchema.validate(data, { context })).rejects.toThrow(
7175
'Value is too low.',
@@ -98,7 +102,7 @@ describe('feesFormValidationSchema', () => {
98102

99103
it('should reject too many decimals for bitcoin', async () => {
100104
const data = { feeLevel: 'custom', customFeePerUnit: '100.123' };
101-
const context = createContext({ symbol: 'btc' });
105+
const context = createContext({ symbol: 'btc', translate: () => 'Too many decimals.' });
102106

103107
await expect(feesFormValidationSchema.validate(data, { context })).rejects.toThrow(
104108
'Too many decimals.',

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,15 @@ type CustomFeeBottomSheetProps = {
3131
};
3232

3333
export const CustomFeeBottomSheet = ({
34-
onClose,
35-
accountKey,
36-
feeValue,
37-
isFeeLoading,
38-
isSubmittable,
39-
isErrorBoxVisible,
40-
ref,
41-
onCustomFeeSet,
42-
}: CustomFeeBottomSheetProps) => {
34+
onClose,
35+
accountKey,
36+
feeValue,
37+
isFeeLoading,
38+
isSubmittable,
39+
isErrorBoxVisible,
40+
ref,
41+
onCustomFeeSet,
42+
}: CustomFeeBottomSheetProps) => {
4343
const symbol = useSelector((state: AccountsRootState) =>
4444
selectAccountNetworkSymbol(state, accountKey),
4545
);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export const CustomFeeInputs = ({ symbol }: CustomFeeInputsProps) => {
5050
const networkType = getNetworkType(symbol);
5151
const feeUnits = getFeeUnits(networkType);
5252
const formattedFeePerUnit = `${feeInfo?.minFee} ${feeUnits}`;
53-
const isEip1559Fee = networkType === 'ethereum' && isEip1559(feeInfo?.levels[0]);
53+
const isEip1559Fee = networkType === 'ethereum' && isEip1559(feeInfo?.levels?.[0]);
5454

5555
const handleFieldChangeValue =
5656
(fieldName: keyof FeesFormValues, transformer: (value: string) => string) =>

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,23 @@ import { FeesFormValues } from '../../../feesFormSchema';
99
type CustomFeeLabelProps = {
1010
networkType: NetworkType;
1111
};
12+
13+
const getFormattedFeeUnits = (fee: string, networkType: NetworkType) => {
14+
const value = Number(fee);
15+
switch (networkType) {
16+
case 'ethereum':
17+
return value.toFixed(2);
18+
default:
19+
return value;
20+
}
21+
};
1222
export const CustomFeeLabel = ({ networkType }: CustomFeeLabelProps) => {
1323
const feeUnits = getFeeUnits(networkType);
1424

1525
const { watch } = useFormContext<FeesFormValues>();
1626
const { customFeePerUnit } = watch();
1727

18-
const formattedFeePerUnit = `${Number(customFeePerUnit).toFixed(3)} ${feeUnits}`;
28+
const formattedFeePerUnit = `${getFormattedFeeUnits(customFeePerUnit, networkType)} ${feeUnits}`;
1929

2030
if (networkType === 'ethereum') {
2131
return (

suite-native/transaction-management/src/components/fees/CustomFee/__tests__/CustomFee.comp.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111

1212
import { getWalletState } from '../../../../__fixtures__/walletState';
1313
import { FeesFormType } from '../../../../feesFormSchema';
14-
import { useFeesForm } from '../../../../hooks';
14+
import { CustomFeeParams, useFeesForm } from '../../../../hooks';
1515
import { useCustomFee } from '../../../../hooks/fees/useCustomFee';
1616
import { CustomFee } from '../CustomFee';
1717

@@ -26,7 +26,7 @@ type CustomFeeProps = {
2626
accountKey: AccountKey;
2727
symbol: NetworkSymbol;
2828
formDraft: FormState | null | undefined;
29-
onCustomFeeSet: (feePerUnit: string, feeLimit?: string) => void;
29+
onCustomFeeSet: (customFeeParams: CustomFeeParams) => void;
3030
};
3131

3232
describe('CustomFee', () => {

suite-native/transaction-management/src/components/fees/CustomFee/__tests__/CustomFeeCard.comp.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ describe('CustomFeeCard', () => {
9090
form,
9191
});
9292

93-
expect(getByText('Limit: 11000 • Price: 1 Gwei')).toBeTruthy();
93+
expect(getByText('1.00 Gwei')).toBeTruthy();
9494
});
9595

9696
it('should not render if using wrong accountKey', async () => {

suite-native/transaction-management/src/components/fees/CustomFee/__tests__/CustomFeeLabel.comp.test.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,7 @@ describe('CustomFeeLabel', () => {
101101
form,
102102
});
103103

104-
expect(getByText(/Limit/)).toBeTruthy();
105-
expect(getByText(/Price/)).toBeTruthy();
104+
expect(getByText(/Gwei/)).toBeTruthy();
106105
});
107106

108107
it('should display fee per unit with Gwei units for ethereum', async () => {
@@ -128,7 +127,7 @@ describe('CustomFeeLabel', () => {
128127
form,
129128
});
130129

131-
expect(getByText(/25 Gwei/)).toBeTruthy();
130+
expect(getByText(/25.00 Gwei/)).toBeTruthy();
132131
});
133132
});
134133

suite-native/transaction-management/src/components/fees/FeeOptionList/__tests__/FeeOption.comp.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ describe('FeeOption', () => {
211211
transactionBytes: 250,
212212
});
213213

214-
expect(getByText('10 Gwei')).toBeTruthy();
214+
expect(getByText('10.00 Gwei')).toBeTruthy();
215215
});
216216
});
217217
});

suite-native/transaction-management/src/components/fees/FeeOptionList/__tests__/FeeOptionsList.comp.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,15 +124,15 @@ describe('FeeOptionsList', () => {
124124
expect(queryAllByTestId('BoxSkeleton').length).toBeGreaterThan(0);
125125
});
126126

127-
it('should filter out custom and low fee levels', async () => {
127+
it('should filter out custom and low fee levels for btc network', async () => {
128128
const feeLevels = {
129129
...createMockFeeLevels(),
130130
custom: createMockFeeLevel(),
131131
low: createMockFeeLevel(),
132132
};
133133

134134
const { getByText, queryByText } = await renderFeeOptionsList({
135-
props: { feeLevels },
135+
props: { feeLevels, symbol: 'btc' },
136136
});
137137

138138
expect(getByText(/Low/)).toBeTruthy();

0 commit comments

Comments
 (0)