Skip to content

Commit 519d697

Browse files
authored
refactor: change MajorExponent type from bigint to Number (#2405)
1 parent e9b431c commit 519d697

File tree

3 files changed

+9
-16
lines changed

3 files changed

+9
-16
lines changed

src/domain/fiat/display-currency.ts

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
export const CENTS_PER_USD = 100
22

33
export const MajorExponent = {
4-
STANDARD: 2n,
5-
ONE: 1n,
6-
THREE: 3n,
4+
STANDARD: 2,
5+
ONE: 1,
6+
THREE: 3,
77
} as const
88

99
export const minorToMajorUnit = ({
@@ -12,10 +12,7 @@ export const minorToMajorUnit = ({
1212
}: {
1313
amount: number | bigint
1414
displayMajorExponent: CurrencyMajorExponent
15-
}) => {
16-
const majorExponent = Number(displayMajorExponent)
17-
return (Number(amount) / 10 ** majorExponent).toFixed(majorExponent)
18-
}
15+
}) => (Number(amount) / 10 ** displayMajorExponent).toFixed(displayMajorExponent)
1916

2017
export const usdMinorToMajorUnit = (amount: number | bigint) =>
2118
Number(minorToMajorUnit({ amount, displayMajorExponent: MajorExponent.STANDARD }))
@@ -26,10 +23,7 @@ export const majorToMinorUnit = ({
2623
}: {
2724
amount: number | bigint
2825
displayMajorExponent: CurrencyMajorExponent
29-
}) => {
30-
const majorExponent = Number(displayMajorExponent)
31-
return Number(Number(amount) * 10 ** majorExponent)
32-
}
26+
}) => Number(Number(amount) * 10 ** displayMajorExponent)
3327

3428
export const usdMajorToMinorUnit = (amount: number | bigint) =>
3529
majorToMinorUnit({ amount, displayMajorExponent: MajorExponent.STANDARD })

src/domain/payments/price-ratio.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,9 @@ export const DisplayPriceRatio = <S extends WalletCurrency, T extends DisplayCur
126126
amountInMinor: bigint
127127
currency: T
128128
}): NewDisplayAmount<T> => {
129-
const displayInMajor = (
130-
Number(amountInMinor) /
131-
10 ** Number(displayMajorExponent)
132-
).toFixed(Number(displayMajorExponent))
129+
const displayInMajor = (Number(amountInMinor) / 10 ** displayMajorExponent).toFixed(
130+
displayMajorExponent,
131+
)
133132

134133
return {
135134
amountInMinor,

src/domain/wallets/tx-history.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ const filterPendingIncoming = ({
3535
const settlementAmount = toSats(sats - fee)
3636

3737
const priceForMinorUnit =
38-
displayCurrencyPerSat.price * 10 ** Number(MajorExponent.STANDARD)
38+
displayCurrencyPerSat.price * 10 ** MajorExponent.STANDARD
3939

4040
const settlementDisplayAmount = minorToMajorUnit({
4141
amount: Math.round(priceForMinorUnit * settlementAmount),

0 commit comments

Comments
 (0)