@otoplo/wallet-common 0.4.2 → 0.4.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +175 -194
- package/dist/index.js.map +1 -1
- package/dist/types/services/market.d.ts +1 -1
- package/dist/types/services/market.d.ts.map +1 -1
- package/dist/types/services/transaction.d.ts.map +1 -1
- package/dist/types/utils/common.d.ts +42 -4
- package/dist/types/utils/common.d.ts.map +1 -1
- package/dist/types/utils/index.d.ts +0 -1
- package/dist/types/utils/index.d.ts.map +1 -1
- package/dist/types/utils/vault.d.ts +3 -0
- package/dist/types/utils/vault.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/services/market.ts +1 -1
- package/src/services/transaction.ts +2 -1
- package/src/utils/common.ts +26 -15
- package/src/utils/index.ts +0 -1
- package/src/utils/vault.ts +12 -2
- package/dist/types/utils/market.d.ts +0 -45
- package/dist/types/utils/market.d.ts.map +0 -1
- package/src/utils/market.ts +0 -43
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { WalletDB } from '../persistence/wallet-db';
|
|
2
2
|
import { MarketData } from '../types/wallet.types';
|
|
3
|
-
import { CurrencyCode } from '../utils/
|
|
3
|
+
import { CurrencyCode } from '../utils/common';
|
|
4
4
|
export type MarketEvent = {
|
|
5
5
|
type: 'market_data_updated';
|
|
6
6
|
currency: CurrencyCode;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"market.d.ts","sourceRoot":"","sources":["../../../src/services/market.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,
|
|
1
|
+
{"version":3,"file":"market.d.ts","sourceRoot":"","sources":["../../../src/services/market.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAA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
|
2
2
|
import { Balance } from '../types/wallet.types';
|
|
3
3
|
export declare const HD_WALLET_ID = -1;
|
|
4
4
|
export declare const MAX_INT64 = 9223372036854775807n;
|
|
5
|
-
export declare const
|
|
6
|
-
|
|
5
|
+
export declare const CURRENCIES: {
|
|
6
|
+
readonly usd: {
|
|
7
|
+
readonly symbol: "$";
|
|
8
|
+
readonly name: "US Dollar";
|
|
9
|
+
};
|
|
10
|
+
readonly eur: {
|
|
11
|
+
readonly symbol: "€";
|
|
12
|
+
readonly name: "Euro";
|
|
13
|
+
};
|
|
14
|
+
readonly gbp: {
|
|
15
|
+
readonly symbol: "£";
|
|
16
|
+
readonly name: "British Pound";
|
|
17
|
+
};
|
|
18
|
+
readonly aud: {
|
|
19
|
+
readonly symbol: "A$";
|
|
20
|
+
readonly name: "Australian Dollar";
|
|
21
|
+
};
|
|
22
|
+
readonly cad: {
|
|
23
|
+
readonly symbol: "CA$";
|
|
24
|
+
readonly name: "Canadian Dollar";
|
|
25
|
+
};
|
|
26
|
+
readonly chf: {
|
|
27
|
+
readonly symbol: "CHF";
|
|
28
|
+
readonly name: "Swiss Franc";
|
|
29
|
+
};
|
|
30
|
+
readonly inr: {
|
|
31
|
+
readonly symbol: "₹";
|
|
32
|
+
readonly name: "Indian Rupee";
|
|
33
|
+
};
|
|
34
|
+
readonly cny: {
|
|
35
|
+
readonly symbol: "CN¥";
|
|
36
|
+
readonly name: "Chinese Yuan";
|
|
37
|
+
};
|
|
38
|
+
readonly jpy: {
|
|
39
|
+
readonly symbol: "¥";
|
|
40
|
+
readonly name: "Japanese Yen";
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
export type CurrencyCode = keyof typeof CURRENCIES;
|
|
44
|
+
export declare const currencyCodes: CurrencyCode[];
|
|
7
45
|
export declare function isTestnet(): boolean;
|
|
8
46
|
export declare function isGenesisHashValid(hash: string): boolean;
|
|
9
47
|
export declare function isValidNexaAddress(address: string, type?: AddressType): boolean;
|
|
10
48
|
export declare function getExplorerUrl(): string;
|
|
11
49
|
export declare function currentTimestamp(): number;
|
|
12
|
-
export declare function estimateDateByFutureBlock(current: number, future: number): string;
|
|
13
50
|
export declare function isNullOrEmpty(arg?: string | any[] | null): arg is undefined | [] | null | '';
|
|
14
51
|
export declare function truncateStringMiddle(str?: string, maxLength?: number): string;
|
|
15
52
|
export declare function capitalizeFirstLetter(str: string): string;
|
|
@@ -22,5 +59,6 @@ export declare function sumTokensBalance(balances: Record<string, Balance>[]): R
|
|
|
22
59
|
export declare function getFileMediaType(filename: string): 'video' | 'audio' | 'image' | 'unknown';
|
|
23
60
|
export declare function getFileMimeType(filename: string): string;
|
|
24
61
|
export declare function sleep(ms: number): Promise<void>;
|
|
25
|
-
export declare function prettifyAmount(amount: string | number): string;
|
|
62
|
+
export declare function prettifyAmount(amount: string | number | bigint): string;
|
|
63
|
+
export declare function calculateFiatValue(amount: string | number, price: number, currency: CurrencyCode, locale?: string): string;
|
|
26
64
|
//# sourceMappingURL=common.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../../src/utils/common.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,WAAW,EAAsC,MAAM,YAAY,CAAC;AACtF,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAGrD,eAAO,MAAM,YAAY,KAAK,CAAC;AAC/B,eAAO,MAAM,SAAS,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../../src/utils/common.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,WAAW,EAAsC,MAAM,YAAY,CAAC;AACtF,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAGrD,eAAO,MAAM,YAAY,KAAK,CAAC;AAC/B,eAAO,MAAM,SAAS,uBAAuB,CAAC;AAE9C,eAAO,MAAM,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;C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AAO,GAAG,OAAO,GAAG,OAAO,GAAG,SAAS,CAM1F;AAED,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAMxD;AAED,wBAAgB,KAAK,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAE/C;AAED,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,CAEvE;AAED,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,SAAU,GAAG,MAAM,CAM3H"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AACvB,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC"}
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { PublicKey, ScriptElement, Script } from 'libnexa-ts';
|
|
2
|
+
export declare const VAULT_FIRST_BLOCK = 274710;
|
|
3
|
+
export declare const VAULT_SCRIPT_PREFIX = "0014461ad25081cb0119d034385ff154c8d3ad6bdd76";
|
|
2
4
|
export declare function getVaultTemplate(): Script;
|
|
3
5
|
export declare function getVaultTemplateHash(): Uint8Array;
|
|
4
6
|
export declare function generateVaultConstraint(pubKey: PublicKey): Script;
|
|
5
7
|
export declare function getVaultConstraintHash(pubKey: PublicKey): Uint8Array;
|
|
6
8
|
export declare function generateVaultVisibleArgs(args: number[]): ScriptElement[];
|
|
7
9
|
export declare function generateVaultAddress(pubKey: PublicKey, args: number[]): string | undefined;
|
|
10
|
+
export declare function estimateDateByFutureBlock(current: number, future: number): string;
|
|
8
11
|
//# sourceMappingURL=vault.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vault.d.ts","sourceRoot":"","sources":["../../../src/utils/vault.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,aAAa,EAAC,MAAM,YAAY,CAAC;AAC1D,OAAO,EAAqC,MAAM,EAAgB,MAAM,YAAY,CAAC;AAErF,wBAAgB,gBAAgB,IAAI,MAAM,CAKzC;AAED,wBAAgB,oBAAoB,IAAI,UAAU,CAGjD;AAED,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,SAAS,GAAG,MAAM,CAEjE;AAED,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,SAAS,GAAG,UAAU,CAGpE;AAED,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,aAAa,EAAE,CAExE;AAED,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,MAAM,GAAG,SAAS,CAU1F"}
|
|
1
|
+
{"version":3,"file":"vault.d.ts","sourceRoot":"","sources":["../../../src/utils/vault.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,aAAa,EAAC,MAAM,YAAY,CAAC;AAC1D,OAAO,EAAqC,MAAM,EAAgB,MAAM,YAAY,CAAC;AAErF,eAAO,MAAM,iBAAiB,SAAS,CAAC;AACxC,eAAO,MAAM,mBAAmB,iDAAkD,CAAC;AAEnF,wBAAgB,gBAAgB,IAAI,MAAM,CAKzC;AAED,wBAAgB,oBAAoB,IAAI,UAAU,CAGjD;AAED,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,SAAS,GAAG,MAAM,CAEjE;AAED,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,SAAS,GAAG,UAAU,CAGpE;AAED,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,aAAa,EAAE,CAExE;AAED,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,MAAM,GAAG,SAAS,CAU1F;AAED,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAKjF"}
|
package/package.json
CHANGED
package/src/services/market.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { WalletDB } from "../persistence/wallet-db";
|
|
2
2
|
import type { MarketData } from "../types/wallet.types";
|
|
3
|
-
import {
|
|
3
|
+
import { type CurrencyCode, currencyCodes } from "../utils/common";
|
|
4
4
|
|
|
5
5
|
interface MarketDataResponse {
|
|
6
6
|
id: string;
|
|
@@ -3,7 +3,8 @@ import { Address, AddressType, Transaction, TransactionBuilder, UnitUtils } from
|
|
|
3
3
|
import type { KeyManager } from "./key";
|
|
4
4
|
import type { RostrumService } from "./rostrum";
|
|
5
5
|
import type { AssetMovement, TransactionDTO, TransactionType } from "../types/db.types";
|
|
6
|
-
import { currentTimestamp, isNullOrEmpty, isValidNexaAddress, MAX_INT64, tokenAmountToAssetAmount, tokenIdToHex
|
|
6
|
+
import { currentTimestamp, isNullOrEmpty, isValidNexaAddress, MAX_INT64, tokenAmountToAssetAmount, tokenIdToHex } from "../utils/common";
|
|
7
|
+
import { VAULT_FIRST_BLOCK } from "../utils/vault";
|
|
7
8
|
import type { WalletDB } from "../persistence/wallet-db";
|
|
8
9
|
import type { ITXHistory } from "../types/rostrum.types";
|
|
9
10
|
import type { AddressKey } from "../types/wallet.types";
|
package/src/utils/common.ts
CHANGED
|
@@ -4,8 +4,22 @@ import bigDecimal from 'js-big-decimal';
|
|
|
4
4
|
|
|
5
5
|
export const HD_WALLET_ID = -1;
|
|
6
6
|
export const MAX_INT64 = 9223372036854775807n;
|
|
7
|
-
|
|
8
|
-
export const
|
|
7
|
+
|
|
8
|
+
export const CURRENCIES = {
|
|
9
|
+
usd: { symbol: '$', name: 'US Dollar' },
|
|
10
|
+
eur: { symbol: '€', name: 'Euro' },
|
|
11
|
+
gbp: { symbol: '£', name: 'British Pound' },
|
|
12
|
+
aud: { symbol: 'A$', name: 'Australian Dollar' },
|
|
13
|
+
cad: { symbol: 'CA$', name: 'Canadian Dollar' },
|
|
14
|
+
chf: { symbol: 'CHF', name: 'Swiss Franc' },
|
|
15
|
+
inr: { symbol: '₹', name: 'Indian Rupee' },
|
|
16
|
+
cny: { symbol: 'CN¥', name: 'Chinese Yuan' },
|
|
17
|
+
jpy: { symbol: '¥', name: 'Japanese Yen' },
|
|
18
|
+
} as const satisfies Record<string, { symbol: string; name: string }>;
|
|
19
|
+
|
|
20
|
+
export type CurrencyCode = keyof typeof CURRENCIES;
|
|
21
|
+
|
|
22
|
+
export const currencyCodes = Object.keys(CURRENCIES) as CurrencyCode[];
|
|
9
23
|
|
|
10
24
|
export function isTestnet(): boolean {
|
|
11
25
|
return Networks.defaultNetwork == Networks.testnet;
|
|
@@ -30,13 +44,6 @@ export function currentTimestamp(): number {
|
|
|
30
44
|
return Math.floor(Date.now() / 1000);
|
|
31
45
|
}
|
|
32
46
|
|
|
33
|
-
export function estimateDateByFutureBlock(current: number, future: number): string {
|
|
34
|
-
const estimateMins = (future - current) * 2;
|
|
35
|
-
const time = new Date();
|
|
36
|
-
time.setMinutes(time.getMinutes() + estimateMins);
|
|
37
|
-
return time.toLocaleDateString();
|
|
38
|
-
}
|
|
39
|
-
|
|
40
47
|
export function isNullOrEmpty(arg?: string | any[] | null): arg is undefined | [] | null | '' {
|
|
41
48
|
return !arg || arg.length === 0;
|
|
42
49
|
}
|
|
@@ -163,10 +170,14 @@ export function sleep(ms: number): Promise<void> {
|
|
|
163
170
|
return new Promise(resolve => setTimeout(resolve, ms));
|
|
164
171
|
}
|
|
165
172
|
|
|
166
|
-
export function prettifyAmount(amount: string | number): string {
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
173
|
+
export function prettifyAmount(amount: string | number | bigint): string {
|
|
174
|
+
return new bigDecimal(amount).stripTrailingZero().getPrettyValue();
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
export function calculateFiatValue(amount: string | number, price: number, currency: CurrencyCode, locale = 'en-US'): string {
|
|
178
|
+
const value = bigDecimal.multiply(amount, price);
|
|
179
|
+
return new Intl.NumberFormat(locale, {
|
|
180
|
+
style: 'currency',
|
|
181
|
+
currency,
|
|
182
|
+
}).format(Number(value));
|
|
172
183
|
}
|
package/src/utils/index.ts
CHANGED
package/src/utils/vault.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
import type { PublicKey, ScriptElement} from "libnexa-ts";
|
|
1
|
+
import type { PublicKey, ScriptElement} from "libnexa-ts";
|
|
2
2
|
import { Address, BNExtended, Hash, Opcode, Script, ScriptOpcode } from "libnexa-ts";
|
|
3
3
|
|
|
4
|
+
export const VAULT_FIRST_BLOCK = 274710;
|
|
5
|
+
export const VAULT_SCRIPT_PREFIX = "0014461ad25081cb0119d034385ff154c8d3ad6bdd76";
|
|
6
|
+
|
|
4
7
|
export function getVaultTemplate(): Script {
|
|
5
8
|
return Script.empty()
|
|
6
9
|
.add(Opcode.OP_FROMALTSTACK).add(Opcode.OP_DROP)
|
|
@@ -36,4 +39,11 @@ export function generateVaultAddress(pubKey: PublicKey, args: number[]): string
|
|
|
36
39
|
const visibleArgs = generateVaultVisibleArgs(args);
|
|
37
40
|
const address = Address.fromScriptTemplate(templateHash, constraintHash, visibleArgs);
|
|
38
41
|
return address.toString();
|
|
39
|
-
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function estimateDateByFutureBlock(current: number, future: number): string {
|
|
45
|
+
const estimateMins = (future - current) * 2;
|
|
46
|
+
const time = new Date();
|
|
47
|
+
time.setMinutes(time.getMinutes() + estimateMins);
|
|
48
|
+
return time.toLocaleDateString();
|
|
49
|
+
}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
export declare const CURRENCIES: readonly [{
|
|
2
|
-
readonly code: "usd";
|
|
3
|
-
readonly symbol: "$";
|
|
4
|
-
readonly name: "US Dollar";
|
|
5
|
-
}, {
|
|
6
|
-
readonly code: "eur";
|
|
7
|
-
readonly symbol: "€";
|
|
8
|
-
readonly name: "Euro";
|
|
9
|
-
}, {
|
|
10
|
-
readonly code: "gbp";
|
|
11
|
-
readonly symbol: "£";
|
|
12
|
-
readonly name: "British Pound";
|
|
13
|
-
}, {
|
|
14
|
-
readonly code: "aud";
|
|
15
|
-
readonly symbol: "A$";
|
|
16
|
-
readonly name: "Australian Dollar";
|
|
17
|
-
}, {
|
|
18
|
-
readonly code: "cad";
|
|
19
|
-
readonly symbol: "C$";
|
|
20
|
-
readonly name: "Canadian Dollar";
|
|
21
|
-
}, {
|
|
22
|
-
readonly code: "chf";
|
|
23
|
-
readonly symbol: "Fr";
|
|
24
|
-
readonly name: "Swiss Franc";
|
|
25
|
-
}, {
|
|
26
|
-
readonly code: "inr";
|
|
27
|
-
readonly symbol: "₹";
|
|
28
|
-
readonly name: "Indian Rupee";
|
|
29
|
-
}, {
|
|
30
|
-
readonly code: "cny";
|
|
31
|
-
readonly symbol: "¥";
|
|
32
|
-
readonly name: "Chinese Yuan";
|
|
33
|
-
}, {
|
|
34
|
-
readonly code: "jpy";
|
|
35
|
-
readonly symbol: "¥";
|
|
36
|
-
readonly name: "Japanese Yen";
|
|
37
|
-
}];
|
|
38
|
-
export type CurrencyCode = typeof CURRENCIES[number]['code'];
|
|
39
|
-
export type CurrencySymbol = typeof CURRENCIES[number]['symbol'];
|
|
40
|
-
export declare const currencySymbols: Record<CurrencyCode, CurrencySymbol>;
|
|
41
|
-
export declare const currencyCodes: ("usd" | "eur" | "gbp" | "aud" | "cad" | "chf" | "inr" | "cny" | "jpy")[];
|
|
42
|
-
export declare function getCurrencySymbol(currency: CurrencyCode): string;
|
|
43
|
-
export declare function calculateFiatValue(amount: string | number, price: number, currency?: CurrencyCode): string;
|
|
44
|
-
export declare function formatMoney(value: string | number, currency: CurrencyCode, locale?: string): string;
|
|
45
|
-
//# sourceMappingURL=market.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"market.d.ts","sourceRoot":"","sources":["../../../src/utils/market.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAUb,CAAC;AAEX,MAAM,MAAM,YAAY,GAAG,OAAO,UAAU,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC;AAE7D,MAAM,MAAM,cAAc,GAAG,OAAO,UAAU,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,CAAC;AAEjE,eAAO,MAAM,eAAe,EAEvB,MAAM,CAAC,YAAY,EAAE,cAAc,CAAC,CAAC;AAE1C,eAAO,MAAM,aAAa,2EAA8B,CAAC;AAEzD,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,YAAY,GAAG,MAAM,CAEhE;AAGD,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,YAAY,GAAG,MAAM,CAI1G;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,SAAU,GAAG,MAAM,CAOpG"}
|
package/src/utils/market.ts
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import bigDecimal from "js-big-decimal";
|
|
2
|
-
|
|
3
|
-
export const CURRENCIES = [
|
|
4
|
-
{ code: 'usd', symbol: '$', name: 'US Dollar' },
|
|
5
|
-
{ code: 'eur', symbol: '€', name: 'Euro' },
|
|
6
|
-
{ code: 'gbp', symbol: '£', name: 'British Pound' },
|
|
7
|
-
{ code: 'aud', symbol: 'A$', name: 'Australian Dollar' },
|
|
8
|
-
{ code: 'cad', symbol: 'C$', name: 'Canadian Dollar' },
|
|
9
|
-
{ code: 'chf', symbol: 'Fr', name: 'Swiss Franc' },
|
|
10
|
-
{ code: 'inr', symbol: '₹', name: 'Indian Rupee' },
|
|
11
|
-
{ code: 'cny', symbol: '¥', name: 'Chinese Yuan' },
|
|
12
|
-
{ code: 'jpy', symbol: '¥', name: 'Japanese Yen' },
|
|
13
|
-
] as const;
|
|
14
|
-
|
|
15
|
-
export type CurrencyCode = typeof CURRENCIES[number]['code'];
|
|
16
|
-
|
|
17
|
-
export type CurrencySymbol = typeof CURRENCIES[number]['symbol'];
|
|
18
|
-
|
|
19
|
-
export const currencySymbols = Object.fromEntries(
|
|
20
|
-
CURRENCIES.map(c => [c.code, c.symbol])
|
|
21
|
-
) as Record<CurrencyCode, CurrencySymbol>;
|
|
22
|
-
|
|
23
|
-
export const currencyCodes = CURRENCIES.map(c => c.code);
|
|
24
|
-
|
|
25
|
-
export function getCurrencySymbol(currency: CurrencyCode): string {
|
|
26
|
-
return currencySymbols[currency] || currency;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
export function calculateFiatValue(amount: string | number, price: number, currency?: CurrencyCode): string {
|
|
31
|
-
const value = bigDecimal.multiply(amount, price);
|
|
32
|
-
const rounded = bigDecimal.round(value, 2, bigDecimal.RoundingModes.HALF_DOWN);
|
|
33
|
-
return currency ? formatMoney(rounded, currency) : rounded;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export function formatMoney(value: string | number, currency: CurrencyCode, locale = 'en-US'): string {
|
|
37
|
-
return new Intl.NumberFormat(locale, {
|
|
38
|
-
style: 'currency',
|
|
39
|
-
currency,
|
|
40
|
-
maximumFractionDigits: 2,
|
|
41
|
-
minimumFractionDigits: 2
|
|
42
|
-
}).format(Number(value));
|
|
43
|
-
}
|