@otoplo/wallet-common 0.1.11 → 0.1.12
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/package.json +1 -1
- package/src/utils/price.ts +21 -15
package/package.json
CHANGED
package/src/utils/price.ts
CHANGED
|
@@ -1,22 +1,28 @@
|
|
|
1
1
|
import type { Price } from "../types/wallet.types";
|
|
2
2
|
|
|
3
|
-
export const
|
|
4
|
-
usd:
|
|
5
|
-
eur:
|
|
6
|
-
gbp:
|
|
7
|
-
cny:
|
|
8
|
-
jpy:
|
|
9
|
-
aud:
|
|
10
|
-
cad:
|
|
11
|
-
chf:
|
|
12
|
-
|
|
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: 'cny', symbol: '¥', name: 'Chinese Yuan' },
|
|
8
|
+
{ code: 'jpy', symbol: '¥', name: 'Japanese Yen' },
|
|
9
|
+
{ code: 'aud', symbol: 'A$', name: 'Australian Dollar' },
|
|
10
|
+
{ code: 'cad', symbol: 'C$', name: 'Canadian Dollar' },
|
|
11
|
+
{ code: 'chf', symbol: 'Fr', name: 'Swiss Franc' },
|
|
12
|
+
] as const;
|
|
13
13
|
|
|
14
|
-
export type
|
|
14
|
+
export type CurrencyCode = typeof CURRENCIES[number]['code'];
|
|
15
15
|
|
|
16
|
-
export
|
|
16
|
+
export type CurrencySymbol = typeof CURRENCIES[number]['symbol'];
|
|
17
|
+
|
|
18
|
+
export const currencySymbols = Object.fromEntries(
|
|
19
|
+
CURRENCIES.map(c => [c.code, c.symbol])
|
|
20
|
+
) as Record<CurrencyCode, CurrencySymbol>;;
|
|
21
|
+
|
|
22
|
+
export const currencyCodes = CURRENCIES.map(c => c.code);
|
|
17
23
|
|
|
18
24
|
export async function getNexaPrices(): Promise<Record<string, number>> {
|
|
19
|
-
const vs_currencies =
|
|
25
|
+
const vs_currencies = currencyCodes.join(",");
|
|
20
26
|
|
|
21
27
|
const res = await fetch(`https://api.coingecko.com/api/v3/simple/price?ids=nexacoin&include_24hr_change=true&vs_currencies=${vs_currencies}`);
|
|
22
28
|
if (!res.ok) {
|
|
@@ -27,13 +33,13 @@ export async function getNexaPrices(): Promise<Record<string, number>> {
|
|
|
27
33
|
return data.nexacoin || {};
|
|
28
34
|
}
|
|
29
35
|
|
|
30
|
-
export function getCurrencySymbol(currency:
|
|
36
|
+
export function getCurrencySymbol(currency: CurrencyCode): string {
|
|
31
37
|
return currencySymbols[currency] || currency;
|
|
32
38
|
}
|
|
33
39
|
|
|
34
40
|
export function initializePrices(): Record<string, Price> {
|
|
35
41
|
const prices: Record<string, Price> = {};
|
|
36
|
-
|
|
42
|
+
currencyCodes.forEach(currency => {
|
|
37
43
|
prices[currency] = { value: 0, change: 0 };
|
|
38
44
|
});
|
|
39
45
|
return prices;
|