@otoplo/wallet-common 0.1.11 → 0.1.13

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@otoplo/wallet-common",
3
- "version": "0.1.11",
3
+ "version": "0.1.13",
4
4
  "description": "Shared common library for internal use in Otoplo wallet",
5
5
  "license": "MIT",
6
6
  "author": "vgrunner",
@@ -1,22 +1,28 @@
1
1
  import type { Price } from "../types/wallet.types";
2
2
 
3
- export const currencySymbols = {
4
- usd: "$",
5
- eur: "",
6
- gbp: "£",
7
- cny: "¥",
8
- jpy: "¥",
9
- aud: "A$",
10
- cad: "C$",
11
- chf: "Fr"
12
- } as const;
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 Currency = keyof typeof currencySymbols;
14
+ export type CurrencyCode = typeof CURRENCIES[number]['code'];
15
15
 
16
- export const currencies = Object.keys(currencySymbols);
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 = currencies.join(",");
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: Currency): string {
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
- currencies.forEach(currency => {
42
+ currencyCodes.forEach(currency => {
37
43
  prices[currency] = { value: 0, change: 0 };
38
44
  });
39
45
  return prices;