Skip to content

Commit f3eb837

Browse files
committed
feat(suite-native): add eip1559 standard fee options
1 parent c45e110 commit f3eb837

File tree

3 files changed

+34
-7
lines changed

3 files changed

+34
-7
lines changed

suite-common/wallet-core/src/fees/feesReducer.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { createReducer } from '@reduxjs/toolkit';
22

33
import { createWeakMapSelector } from '@suite-common/redux-utils';
4-
import { formatDuration } from '@suite-common/suite-utils';
4+
import { formatDurationStrict } from '@suite-common/suite-utils';
55
import { NetworkSymbol, getNetworkType } from '@suite-common/wallet-config';
66
import { FeeInfo, FeeLevelLabel, FeesState, FeesStatus } from '@suite-common/wallet-types';
77
import { getConvertedOrDefaultFeeInfo } from '@suite-common/wallet-utils';
@@ -96,11 +96,19 @@ export const selectNetworkFeeLevel = createMemoizedSelector(
9696
);
9797

9898
export const selectConvertedNetworkFeeLevelTimeEstimate = createMemoizedSelector(
99-
[selectConvertedNetworkFeeInfo, selectNetworkFeeLevel],
100-
(networkFeeInfo, feeLevel): string | null => {
99+
[
100+
selectConvertedNetworkFeeInfo,
101+
selectNetworkFeeLevel,
102+
(_state: FeesRootState, symbol?: NetworkSymbol) => symbol,
103+
],
104+
(networkFeeInfo, feeLevel, symbol): string | null => {
101105
if (!feeLevel || !networkFeeInfo) return null;
102106

103-
return formatDuration(networkFeeInfo.blockTime * feeLevel.blocks * 60);
107+
const networkType = symbol ? getNetworkType(symbol) : null;
108+
109+
const multiplier = networkType === 'bitcoin' ? 60 : 1;
110+
111+
return formatDurationStrict(networkFeeInfo.blockTime * feeLevel.blocks * multiplier);
104112
},
105113
);
106114

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

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@ import Animated, {
88
} from 'react-native-reanimated';
99
import { useSelector } from 'react-redux';
1010

11-
import { type NetworkSymbol, type NetworkType, getNetworkType } from '@suite-common/wallet-config';
11+
import {
12+
type NetworkSymbol,
13+
type NetworkType,
14+
getNetworkType,
15+
hasNetworkSettlementLayer,
16+
} from '@suite-common/wallet-config';
1217
import {
1318
FeesRootState,
1419
selectConvertedNetworkFeeLevelFeePerUnit,
@@ -19,7 +24,7 @@ import {
1924
GeneralPrecomposedTransactionFinal,
2025
isFinalPrecomposedTransaction,
2126
} from '@suite-common/wallet-types';
22-
import { getFeeUnits } from '@suite-common/wallet-utils';
27+
import { getFeeUnits, isEip1559 } from '@suite-common/wallet-utils';
2328
import { Box, HStack, Radio, Text, VStack } from '@suite-native/atoms';
2429
import { CryptoAmountFormatter, CryptoToFiatAmountFormatter } from '@suite-native/formatters';
2530
import { EmptyAmountSkeleton } from '@suite-native/formatters/src/components/EmptyAmountSkeleton';
@@ -42,6 +47,9 @@ export type FeeOptionProps = {
4247
};
4348

4449
const feeLabelsMap = {
50+
// FIXME: is this correct?
51+
//@ts-expect-error
52+
low: 'transactionManagement.fees.levels.low',
4553
economy: 'transactionManagement.fees.levels.low',
4654
normal: 'transactionManagement.fees.levels.normal',
4755
high: 'transactionManagement.fees.levels.high',
@@ -64,16 +72,25 @@ const getFeePerUnit = ({
6472
feeLevel,
6573
transactionBytes,
6674
backendFeePerUnit = '0',
75+
symbol,
6776
}: {
6877
networkType: NetworkType;
6978
feeLevel: GeneralPrecomposedTransaction;
7079
transactionBytes: number;
7180
backendFeePerUnit: string;
81+
symbol: NetworkSymbol;
7282
}): string => {
7383
if (!isFinalPrecomposedTransaction(feeLevel)) {
7484
return backendFeePerUnit;
7585
}
7686

87+
if (networkType === 'ethereum') {
88+
const decimals = hasNetworkSettlementLayer(symbol) ? 4 : 2;
89+
const value = Number(isEip1559(feeLevel) ? feeLevel.maxFeePerGas : feeLevel.feePerByte);
90+
91+
return value.toFixed(decimals);
92+
}
93+
7794
if (networkType === 'bitcoin') {
7895
const feePerVb = Number(feeLevel.fee) / transactionBytes;
7996

@@ -142,6 +159,7 @@ export const FeeOption = ({
142159
feeLevel,
143160
transactionBytes,
144161
backendFeePerUnit: backendFeePerUnit ?? '0',
162+
symbol,
145163
});
146164

147165
const formattedFeePerUnit = `${feePerUnit} ${feeUnits}`;

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,10 @@ export const FeeOptionsList = ({
3535
isLoading,
3636
onSelectedFeeLevel,
3737
}: FeeOptionsListProps) => {
38+
// FIXME: removed low fee, check if its correct
3839
const predefinedFeeLevels = pipe(
3940
feeLevels,
40-
D.filterWithKey(key => key !== 'custom' && key !== 'low'),
41+
D.filterWithKey(key => key !== 'custom'),
4142
);
4243

4344
const transactionBytes = getTransactionBytes(predefinedFeeLevels);

0 commit comments

Comments
 (0)