Skip to content

Commit d860f21

Browse files
refactor: remove unnecessary syntax from lookups
1 parent 4f7559b commit d860f21

File tree

2 files changed

+13
-20
lines changed

2 files changed

+13
-20
lines changed

apps/mobile/src/features/approver/components/fees/bitcoin-fee-sheet.tsx

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ import BigNumber from 'bignumber.js';
55

66
import { AverageBitcoinFeeRates, FeeTypes } from '@leather.io/models';
77
import { SheetRef } from '@leather.io/ui/native';
8-
import { baseCurrencyAmountInQuoteWithFallback, createMoney, match } from '@leather.io/utils';
8+
import { baseCurrencyAmountInQuoteWithFallback, createMoney } from '@leather.io/utils';
99

1010
import { BitcoinFeeOption } from './bitcoin-fee-option';
1111
import { FeeSheetLayout } from './fee-sheet.layout';
1212

13-
const feeTypeArr = [FeeTypes.Low, FeeTypes.Middle, FeeTypes.High, FeeTypes.Custom];
13+
const feeTypes = [FeeTypes.Low, FeeTypes.Middle, FeeTypes.High, FeeTypes.Custom];
1414

1515
interface FeesSheetProps {
1616
sheetRef: RefObject<SheetRef>;
@@ -36,25 +36,24 @@ export function FeesSheet({
3636
function getUsd(fee: number) {
3737
if (!fee) return createMoney(0, 'USD');
3838
const btcBalance = createMoney(fee, 'BTC');
39-
const usdBalance = baseCurrencyAmountInQuoteWithFallback(btcBalance, btcMarketData);
40-
return usdBalance;
39+
return baseCurrencyAmountInQuoteWithFallback(btcBalance, btcMarketData);
4140
}
4241

4342
function getFee(feeType: FeeTypes) {
44-
const feeRate = match<FeeTypes>()(feeType, {
43+
const feeRate = {
4544
[FeeTypes.Low]: fees?.hourFee ?? BigNumber(0),
4645
[FeeTypes.Middle]: fees?.halfHourFee ?? BigNumber(0),
4746
[FeeTypes.High]: fees?.fastestFee ?? BigNumber(0),
4847
[FeeTypes.Unknown]: BigNumber(0),
4948
[FeeTypes.Custom]: BigNumber(currentFeeRate),
50-
});
49+
}[feeType];
5150
const fee = txSize * feeRate.toNumber();
5251
return { feeRate, fee };
5352
}
5453

5554
return (
5655
<FeeSheetLayout sheetRef={sheetRef}>
57-
{feeTypeArr.map(feeType => {
56+
{feeTypes.map(feeType => {
5857
const { feeRate, fee } = getFee(feeType);
5958
return (
6059
<BitcoinFeeOption

apps/mobile/src/features/approver/utils.tsx

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,15 @@ import { match } from '@leather.io/utils';
1212
export type ApproverState = 'start' | 'submitting' | 'submitted';
1313

1414
function getBaseFeeData(feeType: FeeTypes) {
15-
const feeMatcher = match<FeeTypes>();
16-
const icon = feeMatcher(feeType, {
15+
const icon = {
1716
[FeeTypes.Low]: <AnimalSnailIcon />,
1817
[FeeTypes.Middle]: <AnimalRabbitIcon />,
1918
[FeeTypes.High]: <AnimalEagleIcon />,
2019
[FeeTypes.Custom]: <AnimalChameleonIcon />,
2120
[FeeTypes.Unknown]: <AnimalChameleonIcon />,
22-
});
21+
}[feeType];
2322

24-
const title = feeMatcher(feeType, {
23+
const title = {
2524
[FeeTypes.Low]: t({
2625
id: 'approver.fee.type.low',
2726
message: 'Slow',
@@ -42,14 +41,13 @@ function getBaseFeeData(feeType: FeeTypes) {
4241
id: 'approver.fee.type.unknown',
4342
message: 'Unknown',
4443
}),
45-
});
44+
}[feeType];
4645
return { icon, title };
4746
}
4847

4948
export function getBitcoinFeeData(feeType: FeeTypes) {
50-
const feeMatcher = match<FeeTypes>();
5149
const { icon, title } = getBaseFeeData(feeType);
52-
const time = feeMatcher(feeType, {
50+
const time = {
5351
[FeeTypes.Low]: t({
5452
id: 'approver.bitcoin.fee.speed.low',
5553
message: '~40 mins',
@@ -70,12 +68,8 @@ export function getBitcoinFeeData(feeType: FeeTypes) {
7068
id: 'approver.fee.speed.unknown',
7169
message: 'Unknown',
7270
}),
73-
});
74-
return {
75-
icon,
76-
title,
77-
time,
78-
};
71+
}[feeType];
72+
return { icon, title, time };
7973
}
8074

8175
export function getStacksFeeData(feeType: FeeTypes) {

0 commit comments

Comments
 (0)