mirror of
https://github.com/zhigang1992/wallet.git
synced 2026-01-12 22:53:27 +08:00
refactor: allow bigint in createMoney
This commit is contained in:
@@ -27,7 +27,7 @@ export function PsbtUnsignedOutputItem({
|
||||
|
||||
const isOutputCurrentAddress =
|
||||
addressFromScript === addressNativeSegwit || addressFromScript === addressTaproot;
|
||||
const outputValueAsMoney = createMoney(Number(output.amount), 'BTC');
|
||||
const outputValueAsMoney = createMoney(output.amount, 'BTC');
|
||||
|
||||
return (
|
||||
<PsbtDecodedNodeLayout
|
||||
|
||||
@@ -6,7 +6,6 @@ import BigNumber from 'bignumber.js';
|
||||
import { CryptoCurrencies } from '@shared/models/currencies.model';
|
||||
import { MarketData, createMarketData, createMarketPair } from '@shared/models/market.model';
|
||||
import { Money, createMoney, currencyDecimalsMap } from '@shared/models/money.model';
|
||||
import { createMoneyFromDecimal } from '@shared/models/money.model';
|
||||
|
||||
import { calculateMeanAverage } from '@app/common/math/calculate-averages';
|
||||
import { convertAmountToFractionalUnit } from '@app/common/money/calculate-money';
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import BigNumber from 'bignumber.js';
|
||||
|
||||
import { BTC_DECIMALS, STX_DECIMALS } from '@shared/constants';
|
||||
import { isUndefined } from '@shared/utils';
|
||||
import { isBigInt, isUndefined } from '@shared/utils';
|
||||
|
||||
import type { Currencies } from './currencies.model';
|
||||
|
||||
export type NumType = BigNumber | number;
|
||||
export type NumType = BigNumber | bigint | number;
|
||||
|
||||
export interface Money {
|
||||
readonly amount: BigNumber;
|
||||
@@ -52,7 +52,7 @@ export function createMoneyFromDecimal(
|
||||
): Money {
|
||||
throwWhenDecimalUnknown(symbol, resolution);
|
||||
const decimals = getDecimalsOfSymbolIfKnown(symbol) ?? resolution;
|
||||
const amount = new BigNumber(value).shiftedBy(decimals);
|
||||
const amount = new BigNumber(isBigInt(value) ? value.toString() : value).shiftedBy(decimals);
|
||||
return Object.freeze({ amount, symbol, decimals });
|
||||
}
|
||||
|
||||
@@ -64,6 +64,6 @@ export function createMoneyFromDecimal(
|
||||
export function createMoney(value: NumType, symbol: Currencies, resolution?: number): Money {
|
||||
throwWhenDecimalUnknown(symbol, resolution);
|
||||
const decimals = getDecimalsOfSymbolIfKnown(symbol) ?? resolution;
|
||||
const amount = new BigNumber(value);
|
||||
const amount = new BigNumber(isBigInt(value) ? value.toString() : value);
|
||||
return Object.freeze({ amount, symbol, decimals });
|
||||
}
|
||||
|
||||
@@ -6,6 +6,10 @@ export function isString(value: unknown): value is string {
|
||||
return typeof value === 'string';
|
||||
}
|
||||
|
||||
export function isBigInt(value: unknown): value is bigint {
|
||||
return typeof value === 'bigint';
|
||||
}
|
||||
|
||||
export function isUndefined(value: unknown): value is undefined {
|
||||
return typeof value === 'undefined';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user