@otoplo/wallet-common 0.1.15 → 0.2.0
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 +555 -579
- package/dist/index.js.map +1 -1
- package/dist/types/persistence/datastore/db.d.ts +5 -3
- package/dist/types/persistence/datastore/db.d.ts.map +1 -1
- package/dist/types/persistence/wallet-db.d.ts +10 -18
- package/dist/types/persistence/wallet-db.d.ts.map +1 -1
- package/dist/types/services/asset.d.ts +5 -9
- package/dist/types/services/asset.d.ts.map +1 -1
- package/dist/types/services/cache.d.ts +4 -2
- package/dist/types/services/cache.d.ts.map +1 -1
- package/dist/types/services/wallet.d.ts +2 -1
- package/dist/types/services/wallet.d.ts.map +1 -1
- package/dist/types/state/hooks.d.ts +2 -1
- package/dist/types/state/hooks.d.ts.map +1 -1
- package/dist/types/state/slices/market.d.ts +54 -0
- package/dist/types/state/slices/market.d.ts.map +1 -0
- package/dist/types/state/slices/status.d.ts +0 -27
- package/dist/types/state/slices/status.d.ts.map +1 -1
- package/dist/types/state/slices/wallet.d.ts +21 -220
- package/dist/types/state/slices/wallet.d.ts.map +1 -1
- package/dist/types/state/store.d.ts +3 -0
- package/dist/types/state/store.d.ts.map +1 -1
- package/dist/types/types/db.types.d.ts +16 -11
- package/dist/types/types/db.types.d.ts.map +1 -1
- package/dist/types/types/wallet.types.d.ts +39 -14
- package/dist/types/types/wallet.types.d.ts.map +1 -1
- package/dist/types/utils/asset.d.ts +3 -6
- package/dist/types/utils/asset.d.ts.map +1 -1
- package/dist/types/utils/common.d.ts +0 -1
- package/dist/types/utils/common.d.ts.map +1 -1
- package/dist/types/utils/enums.d.ts +0 -4
- package/dist/types/utils/enums.d.ts.map +1 -1
- package/dist/types/utils/index.d.ts +1 -1
- package/dist/types/utils/index.d.ts.map +1 -1
- package/dist/types/utils/{price.d.ts → market.d.ts} +19 -13
- package/dist/types/utils/market.d.ts.map +1 -0
- package/package.json +4 -5
- package/src/persistence/datastore/db.ts +5 -3
- package/src/persistence/wallet-db.ts +28 -28
- package/src/services/asset.ts +69 -162
- package/src/services/cache.ts +12 -2
- package/src/services/wallet.ts +23 -21
- package/src/state/hooks.ts +3 -1
- package/src/state/slices/market.ts +47 -0
- package/src/state/slices/status.ts +2 -31
- package/src/state/slices/wallet.ts +8 -13
- package/src/state/store.ts +3 -0
- package/src/types/db.types.ts +17 -12
- package/src/types/wallet.types.ts +40 -16
- package/src/utils/asset.ts +12 -52
- package/src/utils/common.ts +0 -6
- package/src/utils/enums.ts +0 -5
- package/src/utils/index.ts +1 -1
- package/src/utils/market.ts +97 -0
- package/dist/types/utils/price.d.ts.map +0 -1
- package/src/utils/price.ts +0 -46
package/src/utils/price.ts
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import type { Price } from "../types/wallet.types";
|
|
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: '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
|
-
|
|
14
|
-
export type CurrencyCode = typeof CURRENCIES[number]['code'];
|
|
15
|
-
|
|
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);
|
|
23
|
-
|
|
24
|
-
export async function getNexaPrices(): Promise<Record<string, number>> {
|
|
25
|
-
const vs_currencies = currencyCodes.join(",");
|
|
26
|
-
|
|
27
|
-
const res = await fetch(`https://api.coingecko.com/api/v3/simple/price?ids=nexacoin&include_24hr_change=true&vs_currencies=${vs_currencies}`);
|
|
28
|
-
if (!res.ok) {
|
|
29
|
-
throw new Error("Failed to fetch price");
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
const data = await res.json();
|
|
33
|
-
return data.nexacoin || {};
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export function getCurrencySymbol(currency: CurrencyCode): string {
|
|
37
|
-
return currencySymbols[currency] || currency;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export function initializePrices(): Record<string, Price> {
|
|
41
|
-
const prices: Record<string, Price> = {};
|
|
42
|
-
currencyCodes.forEach(currency => {
|
|
43
|
-
prices[currency] = { value: 0, change: 0 };
|
|
44
|
-
});
|
|
45
|
-
return prices;
|
|
46
|
-
}
|