@exodus/balances 13.16.0 → 13.17.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/CHANGELOG.md +10 -0
- package/README.md +1 -1
- package/atoms/asset-names-with-balance.d.ts +1 -0
- package/atoms/asset-names-with-balance.js +1 -40
- package/atoms/asset-total-wallet-amounts.d.ts +1 -0
- package/atoms/asset-total-wallet-amounts.js +1 -47
- package/atoms/assets-with-balance-count.d.ts +1 -0
- package/atoms/assets-with-balance-count.js +1 -8
- package/atoms/balances.d.ts +1 -0
- package/atoms/balances.js +1 -6
- package/atoms/funded-wallet-accounts.d.ts +1 -0
- package/atoms/funded-wallet-accounts.js +1 -25
- package/atoms/has-balance.d.ts +1 -0
- package/atoms/has-balance.js +1 -31
- package/atoms/index.d.ts +8 -0
- package/atoms/index.js +8 -54
- package/default-config.d.ts +1 -0
- package/default-config.js +1 -26
- package/index.d.ts +2 -35
- package/index.js +1 -65
- package/lib/atoms/asset-names-with-balance.d.ts +5 -0
- package/lib/atoms/asset-names-with-balance.js +31 -0
- package/lib/atoms/asset-total-wallet-amounts.d.ts +5 -0
- package/lib/atoms/asset-total-wallet-amounts.js +39 -0
- package/lib/atoms/assets-with-balance-count.d.ts +5 -0
- package/lib/atoms/assets-with-balance-count.js +6 -0
- package/lib/atoms/balances.d.ts +3 -0
- package/lib/atoms/balances.js +3 -0
- package/lib/atoms/funded-wallet-accounts.d.ts +8 -0
- package/lib/atoms/funded-wallet-accounts.js +19 -0
- package/lib/atoms/has-balance.d.ts +7 -0
- package/lib/atoms/has-balance.js +21 -0
- package/lib/atoms/index.d.ts +54 -0
- package/lib/atoms/index.js +48 -0
- package/lib/default-config.d.ts +3 -0
- package/lib/default-config.js +24 -0
- package/lib/index.d.ts +187 -0
- package/lib/index.js +49 -0
- package/lib/module/balances-utils.d.ts +13 -0
- package/lib/module/balances-utils.js +70 -0
- package/lib/module/index.d.ts +11 -0
- package/lib/module/index.js +367 -0
- package/lib/module/mockable-balances.d.ts +16 -0
- package/lib/module/mockable-balances.js +21 -0
- package/lib/module/types.d.ts +80 -0
- package/lib/module/types.js +1 -0
- package/lib/plugins/analytics.d.ts +18 -0
- package/lib/plugins/analytics.js +30 -0
- package/lib/plugins/index.d.ts +35 -0
- package/lib/plugins/index.js +22 -0
- package/lib/plugins/lifecycle.d.ts +14 -0
- package/lib/plugins/lifecycle.js +32 -0
- package/lib/redux/id.d.ts +2 -0
- package/lib/redux/id.js +1 -0
- package/lib/redux/index.d.ts +588 -0
- package/lib/redux/index.js +53 -0
- package/lib/redux/initial-state.d.ts +3 -0
- package/lib/redux/initial-state.js +6 -0
- package/lib/redux/multi-account-helper.d.ts +463 -0
- package/lib/redux/multi-account-helper.js +23 -0
- package/lib/redux/selectors/by-asset.d.ts +12 -0
- package/lib/redux/selectors/by-asset.js +19 -0
- package/lib/redux/selectors/create-balance-selectors.d.ts +70 -0
- package/lib/redux/selectors/create-balance-selectors.js +32 -0
- package/lib/redux/selectors/create-balances.d.ts +11 -0
- package/lib/redux/selectors/create-balances.js +13 -0
- package/lib/redux/selectors/create-fuel-threshold.d.ts +19 -0
- package/lib/redux/selectors/create-fuel-threshold.js +22 -0
- package/lib/redux/selectors/create-requires-fuel-threshold.d.ts +19 -0
- package/lib/redux/selectors/create-requires-fuel-threshold.js +29 -0
- package/lib/redux/selectors/create-unconfirmed-balance.d.ts +15 -0
- package/lib/redux/selectors/create-unconfirmed-balance.js +14 -0
- package/lib/redux/selectors/get-balance-for-field.d.ts +14 -0
- package/lib/redux/selectors/get-balance-for-field.js +19 -0
- package/lib/redux/selectors/get-balance-selectors.d.ts +68 -0
- package/lib/redux/selectors/get-balance-selectors.js +32 -0
- package/lib/redux/selectors/get-balances.d.ts +10 -0
- package/lib/redux/selectors/get-balances.js +13 -0
- package/lib/redux/selectors/get-unconfirmed-balance.d.ts +19 -0
- package/lib/redux/selectors/get-unconfirmed-balance.js +27 -0
- package/lib/redux/selectors/index.d.ts +339 -0
- package/lib/redux/selectors/index.js +22 -0
- package/lib/redux/types.d.ts +45 -0
- package/lib/redux/types.js +1 -0
- package/lib/report/index.d.ts +34 -0
- package/lib/report/index.js +51 -0
- package/lib/types.d.ts +24 -0
- package/lib/types.js +1 -0
- package/module/balances-utils.d.ts +1 -0
- package/module/balances-utils.js +1 -86
- package/module/index.d.ts +2 -0
- package/module/index.js +2 -490
- package/module/mockable-balances.d.ts +1 -0
- package/module/mockable-balances.js +1 -27
- package/package.json +36 -29
- package/plugins/analytics.d.ts +1 -0
- package/plugins/analytics.js +1 -48
- package/plugins/index.d.ts +4 -0
- package/plugins/index.js +4 -24
- package/plugins/lifecycle.d.ts +1 -0
- package/plugins/lifecycle.js +1 -40
- package/redux/id.d.ts +1 -0
- package/redux/id.js +1 -1
- package/redux/index.d.ts +2 -0
- package/redux/index.js +1 -61
- package/redux/initial-state.d.ts +1 -0
- package/redux/initial-state.js +1 -8
- package/redux/multi-account-helper.d.ts +1 -0
- package/redux/multi-account-helper.js +1 -14
- package/redux/selectors/by-asset.d.ts +1 -0
- package/redux/selectors/by-asset.js +1 -25
- package/redux/selectors/create-balance-selectors.d.ts +1 -0
- package/redux/selectors/create-balance-selectors.js +1 -48
- package/redux/selectors/create-balances.d.ts +1 -0
- package/redux/selectors/create-balances.js +1 -26
- package/redux/selectors/create-fuel-threshold.d.ts +1 -0
- package/redux/selectors/create-fuel-threshold.js +1 -32
- package/redux/selectors/create-requires-fuel-threshold.d.ts +1 -0
- package/redux/selectors/create-requires-fuel-threshold.js +1 -59
- package/redux/selectors/create-unconfirmed-balance.d.ts +1 -0
- package/redux/selectors/create-unconfirmed-balance.js +1 -28
- package/redux/selectors/get-balance-for-field.d.ts +1 -0
- package/redux/selectors/get-balance-for-field.js +1 -34
- package/redux/selectors/get-balance-selectors.d.ts +1 -0
- package/redux/selectors/get-balance-selectors.js +1 -42
- package/redux/selectors/get-balances.d.ts +1 -0
- package/redux/selectors/get-balances.js +1 -24
- package/redux/selectors/get-unconfirmed-balance.d.ts +2 -0
- package/redux/selectors/get-unconfirmed-balance.js +2 -43
- package/redux/selectors/index.d.ts +1 -0
- package/redux/selectors/index.js +1 -23
- package/report/index.d.ts +1 -0
- package/report/index.js +1 -61
- package/tsconfig.json +0 -4
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import createAssetNamesWithBalanceAtom from './asset-names-with-balance.js';
|
|
2
|
+
import createAssetsWithBalanceCountAtom from './assets-with-balance-count.js';
|
|
3
|
+
import createBalancesAtom from './balances.js';
|
|
4
|
+
import createFundedWalletAccountsAtom from './funded-wallet-accounts.js';
|
|
5
|
+
import createHasBalanceAtom from './has-balance.js';
|
|
6
|
+
import createAssetsTotalWalletAmountsAtom from './asset-total-wallet-amounts.js';
|
|
7
|
+
export const balancesAtomDefinition = {
|
|
8
|
+
id: 'balancesAtom',
|
|
9
|
+
type: 'atom',
|
|
10
|
+
factory: createBalancesAtom,
|
|
11
|
+
dependencies: [],
|
|
12
|
+
public: true,
|
|
13
|
+
};
|
|
14
|
+
export const hasBalanceAtomDefinition = {
|
|
15
|
+
id: 'hasBalanceAtom',
|
|
16
|
+
type: 'atom',
|
|
17
|
+
factory: createHasBalanceAtom,
|
|
18
|
+
dependencies: ['balancesAtom', 'storage'],
|
|
19
|
+
public: true,
|
|
20
|
+
};
|
|
21
|
+
export const fundedWalletAccountsAtomDefinition = {
|
|
22
|
+
id: 'fundedWalletAccountsAtom',
|
|
23
|
+
type: 'atom',
|
|
24
|
+
factory: createFundedWalletAccountsAtom,
|
|
25
|
+
dependencies: ['balancesAtom', 'enabledWalletAccountsAtom'],
|
|
26
|
+
public: true,
|
|
27
|
+
};
|
|
28
|
+
export const assetNamesWithBalanceAtomDefinition = {
|
|
29
|
+
id: 'assetNamesWithBalanceAtom',
|
|
30
|
+
type: 'atom',
|
|
31
|
+
factory: createAssetNamesWithBalanceAtom,
|
|
32
|
+
dependencies: ['balancesAtom'],
|
|
33
|
+
public: true,
|
|
34
|
+
};
|
|
35
|
+
export const assetsWithBalanceCountAtomDefinition = {
|
|
36
|
+
id: 'assetsWithBalanceCountAtom',
|
|
37
|
+
type: 'atom',
|
|
38
|
+
factory: createAssetsWithBalanceCountAtom,
|
|
39
|
+
dependencies: ['assetNamesWithBalanceAtom'],
|
|
40
|
+
public: true,
|
|
41
|
+
};
|
|
42
|
+
export const assetsTotalWalletAmountsDefinition = {
|
|
43
|
+
id: 'assetsTotalWalletAmountsAtom',
|
|
44
|
+
type: 'atom',
|
|
45
|
+
factory: createAssetsTotalWalletAmountsAtom,
|
|
46
|
+
dependencies: ['balancesAtom'],
|
|
47
|
+
public: true,
|
|
48
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
const balanceFieldsConfig = [
|
|
2
|
+
{ name: 'total', legacyName: 'balance', default: 'zero' },
|
|
3
|
+
{ name: 'spendable', legacyName: 'spendableBalance', default: 'total' },
|
|
4
|
+
{ name: 'unconfirmedSent', default: 'zero' },
|
|
5
|
+
{ name: 'unconfirmedReceived', default: 'zero' },
|
|
6
|
+
{ name: 'unspendable', default: 'zero' },
|
|
7
|
+
{ name: 'walletReserve', default: 'zero' },
|
|
8
|
+
{ name: 'networkReserve', default: 'zero' },
|
|
9
|
+
{ name: 'staking', default: 'zero' },
|
|
10
|
+
{ name: 'staked', default: 'zero' },
|
|
11
|
+
{ name: 'stakeable', default: 'zero' },
|
|
12
|
+
{ name: 'unstaking', default: 'zero' },
|
|
13
|
+
{ name: 'unstaked', default: 'zero' },
|
|
14
|
+
{ name: 'rewards', default: 'zero' },
|
|
15
|
+
{ name: 'frozen', default: 'zero' },
|
|
16
|
+
];
|
|
17
|
+
const config = {
|
|
18
|
+
balanceFieldsConfig,
|
|
19
|
+
balanceFields: balanceFieldsConfig
|
|
20
|
+
.flatMap((fieldConfig) => [fieldConfig.name, fieldConfig.legacyName])
|
|
21
|
+
.filter((field) => Boolean(field)),
|
|
22
|
+
assetsToTrackForBalances: [],
|
|
23
|
+
};
|
|
24
|
+
export default config;
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import type { BalancesConfig } from './module/types.js';
|
|
2
|
+
declare const balances: (walletConfig?: Partial<BalancesConfig>) => {
|
|
3
|
+
readonly id: import("@exodus/safe-string").SafeString;
|
|
4
|
+
readonly definitions: readonly [{
|
|
5
|
+
definition: {
|
|
6
|
+
readonly id: "balances";
|
|
7
|
+
readonly type: "module";
|
|
8
|
+
readonly factory: (opts: {
|
|
9
|
+
config: {
|
|
10
|
+
importReport: import("./types.js").BalancesByAssetSource;
|
|
11
|
+
};
|
|
12
|
+
balancesAtom: import("./types.js").BalancesAtom;
|
|
13
|
+
}) => import("./module/types.js").BalancesModule;
|
|
14
|
+
readonly dependencies: readonly ["config", "balancesAtom"];
|
|
15
|
+
readonly public: true;
|
|
16
|
+
};
|
|
17
|
+
config: {
|
|
18
|
+
importReport: import("./types.js").BalancesByAssetSource;
|
|
19
|
+
balanceFields: string[];
|
|
20
|
+
assetsToTrackForBalances: {
|
|
21
|
+
assetName: string;
|
|
22
|
+
analyticsName: string;
|
|
23
|
+
}[];
|
|
24
|
+
balanceFieldsConfig: import("./module/types.js").BalanceFieldConfig[];
|
|
25
|
+
};
|
|
26
|
+
} | {
|
|
27
|
+
definition: {
|
|
28
|
+
readonly id: "balances";
|
|
29
|
+
readonly type: "module";
|
|
30
|
+
readonly factory: (opts: import("./module/types.js").Options) => import("./module/types.js").BalancesModule;
|
|
31
|
+
readonly dependencies: readonly ["assetsAtom", "availableAssetNamesAtom", "enabledWalletAccountsAtom", "config", "logger", "balancesAtom", "blockchainMetadataAtom", "feeDataAtom", "errorTracking"];
|
|
32
|
+
readonly public: true;
|
|
33
|
+
};
|
|
34
|
+
config: {
|
|
35
|
+
balanceFields: string[];
|
|
36
|
+
assetsToTrackForBalances: {
|
|
37
|
+
assetName: string;
|
|
38
|
+
analyticsName: string;
|
|
39
|
+
}[];
|
|
40
|
+
balanceFieldsConfig: import("./module/types.js").BalanceFieldConfig[];
|
|
41
|
+
importReport?: import("./types.js").BalancesByAssetSource;
|
|
42
|
+
};
|
|
43
|
+
}, {
|
|
44
|
+
readonly definition: {
|
|
45
|
+
readonly id: "balancesAtom";
|
|
46
|
+
readonly type: "atom";
|
|
47
|
+
readonly factory: () => import("@exodus/atoms").Atom<import("./types.js").BalancesAtomValue>;
|
|
48
|
+
readonly dependencies: readonly [];
|
|
49
|
+
readonly public: true;
|
|
50
|
+
};
|
|
51
|
+
}, {
|
|
52
|
+
readonly definition: {
|
|
53
|
+
readonly id: "assetNamesWithBalanceAtom";
|
|
54
|
+
readonly type: "atom";
|
|
55
|
+
readonly factory: ({ balancesAtom }: {
|
|
56
|
+
balancesAtom: import("./types.js").BalancesAtom;
|
|
57
|
+
}) => import("@exodus/atoms").ReadonlyAtom<Set<string>>;
|
|
58
|
+
readonly dependencies: readonly ["balancesAtom"];
|
|
59
|
+
readonly public: true;
|
|
60
|
+
};
|
|
61
|
+
}, {
|
|
62
|
+
readonly definition: {
|
|
63
|
+
readonly id: "assetsWithBalanceCountAtom";
|
|
64
|
+
readonly type: "atom";
|
|
65
|
+
readonly factory: ({ assetNamesWithBalanceAtom, }: {
|
|
66
|
+
assetNamesWithBalanceAtom: import("@exodus/atoms").ReadonlyAtom<Set<string>>;
|
|
67
|
+
}) => import("@exodus/atoms").ReadonlyAtom<number>;
|
|
68
|
+
readonly dependencies: readonly ["assetNamesWithBalanceAtom"];
|
|
69
|
+
readonly public: true;
|
|
70
|
+
};
|
|
71
|
+
}, {
|
|
72
|
+
readonly definition: {
|
|
73
|
+
readonly id: "hasBalanceAtom";
|
|
74
|
+
readonly type: "atom";
|
|
75
|
+
readonly factory: ({ balancesAtom, storage, }: {
|
|
76
|
+
balancesAtom: import("./types.js").BalancesAtom;
|
|
77
|
+
storage: import("@exodus/storage-interface").Storage<boolean>;
|
|
78
|
+
}) => import("./types.js").HasBalanceAtom;
|
|
79
|
+
readonly dependencies: readonly ["balancesAtom", "storage"];
|
|
80
|
+
readonly public: true;
|
|
81
|
+
};
|
|
82
|
+
readonly storage: {
|
|
83
|
+
readonly namespace: "balances";
|
|
84
|
+
};
|
|
85
|
+
readonly aliases: readonly [{
|
|
86
|
+
readonly implementationId: "unsafeStorage";
|
|
87
|
+
readonly interfaceId: "storage";
|
|
88
|
+
}];
|
|
89
|
+
}, {
|
|
90
|
+
readonly definition: {
|
|
91
|
+
readonly id: "fundedWalletAccountsAtom";
|
|
92
|
+
readonly type: "atom";
|
|
93
|
+
readonly factory: ({ balancesAtom, enabledWalletAccountsAtom, }: {
|
|
94
|
+
balancesAtom: import("./types.js").BalancesAtom;
|
|
95
|
+
enabledWalletAccountsAtom: import("@exodus/atoms").ReadonlyAtom<Record<string, import("@exodus/models").WalletAccount>>;
|
|
96
|
+
}) => import("./types.js").FundedWalletAccountsAtom;
|
|
97
|
+
readonly dependencies: readonly ["balancesAtom", "enabledWalletAccountsAtom"];
|
|
98
|
+
readonly public: true;
|
|
99
|
+
};
|
|
100
|
+
}, {
|
|
101
|
+
readonly definition: {
|
|
102
|
+
readonly id: "balancesReport";
|
|
103
|
+
readonly type: "report";
|
|
104
|
+
readonly factory: ({ enabledWalletAccountsAtom, balancesAtom, }: {
|
|
105
|
+
enabledWalletAccountsAtom: import("@exodus/atoms").ReadonlyAtom<Record<string, import("@exodus/models").WalletAccount>>;
|
|
106
|
+
balancesAtom: import("./types.js").BalancesAtom;
|
|
107
|
+
}) => {
|
|
108
|
+
namespace: string;
|
|
109
|
+
export: ({ walletExists, isLocked }?: {
|
|
110
|
+
walletExists?: boolean;
|
|
111
|
+
isLocked?: boolean;
|
|
112
|
+
}) => Promise<Record<string, {
|
|
113
|
+
balances: Record<string, string>;
|
|
114
|
+
}> | {
|
|
115
|
+
error: import("@exodus/errors").SafeError;
|
|
116
|
+
} | null>;
|
|
117
|
+
getSchema: import("@exodus/basic-utils/lib/memoize.js").MemoizedFunction<() => import("@exodus/zod").ZodNullable<import("@exodus/zod").ZodRecord<import("@exodus/zod").ZodString, import("@exodus/zod").ZodUnion<[import("@exodus/zod").ZodObject<{
|
|
118
|
+
balances: import("@exodus/zod").ZodRecord<import("@exodus/zod").ZodString, import("@exodus/zod").ZodString>;
|
|
119
|
+
}, "strict", import("@exodus/zod").ZodTypeAny, {
|
|
120
|
+
balances: Record<string, string>;
|
|
121
|
+
}, {
|
|
122
|
+
balances: Record<string, string>;
|
|
123
|
+
}>, import("@exodus/zod").ZodType<import("@exodus/errors").SafeError, import("@exodus/zod").ZodTypeDef, import("@exodus/errors").SafeError>]>>>>;
|
|
124
|
+
};
|
|
125
|
+
readonly dependencies: readonly ["enabledWalletAccountsAtom", "balancesAtom"];
|
|
126
|
+
readonly public: true;
|
|
127
|
+
};
|
|
128
|
+
}, {
|
|
129
|
+
readonly definition: {
|
|
130
|
+
readonly id: "balancesLifecyclePlugin";
|
|
131
|
+
readonly type: "plugin";
|
|
132
|
+
readonly factory: ({ balancesAtom, port, balances, hasBalanceAtom, }: {
|
|
133
|
+
balancesAtom: import("./types.js").BalancesAtom;
|
|
134
|
+
port: import("@exodus/atoms").Port<import("./types.js").BalancesAtomValue | boolean | undefined>;
|
|
135
|
+
balances: import("./module/types.js").BalancesModule;
|
|
136
|
+
hasBalanceAtom: import("./types.js").HasBalanceAtom;
|
|
137
|
+
}) => {
|
|
138
|
+
onLoad: () => void;
|
|
139
|
+
onStop: () => void;
|
|
140
|
+
onClear: () => Promise<void>;
|
|
141
|
+
};
|
|
142
|
+
readonly dependencies: readonly ["balancesAtom", "port", "balances", "hasBalanceAtom"];
|
|
143
|
+
readonly public: true;
|
|
144
|
+
};
|
|
145
|
+
}, {
|
|
146
|
+
readonly definition: {
|
|
147
|
+
readonly id: "assetsTotalWalletAmountsAtom";
|
|
148
|
+
readonly type: "atom";
|
|
149
|
+
readonly factory: ({ balancesAtom, }: {
|
|
150
|
+
balancesAtom: import("./types.js").BalancesAtom;
|
|
151
|
+
}) => import("./types.js").AssetTotalWalletAmountsAtom;
|
|
152
|
+
readonly dependencies: readonly ["balancesAtom"];
|
|
153
|
+
readonly public: true;
|
|
154
|
+
};
|
|
155
|
+
}, {
|
|
156
|
+
readonly if: {
|
|
157
|
+
readonly registered: readonly ["analytics"];
|
|
158
|
+
};
|
|
159
|
+
readonly definition: {
|
|
160
|
+
readonly id: "balancesAnalyticsPlugin";
|
|
161
|
+
readonly type: "plugin";
|
|
162
|
+
readonly factory: ({ analytics, hasBalanceAtom, assetsWithBalanceCountAtom, assetsTotalWalletAmountsAtom, config: { assetsToTrackForBalances }, }: {
|
|
163
|
+
analytics: {
|
|
164
|
+
requireDefaultEventProperties(keys: string[]): void;
|
|
165
|
+
setDefaultEventProperties(properties: Record<string, boolean | number>): void;
|
|
166
|
+
};
|
|
167
|
+
hasBalanceAtom: Pick<import("./types.js").HasBalanceAtom, "get" | "observe">;
|
|
168
|
+
assetsWithBalanceCountAtom: import("@exodus/atoms").ReadonlyAtom<number>;
|
|
169
|
+
assetsTotalWalletAmountsAtom: import("@exodus/atoms").ReadonlyAtom<Map<string, import("@exodus/currency").default>>;
|
|
170
|
+
config: Pick<BalancesConfig, "assetsToTrackForBalances">;
|
|
171
|
+
}) => {
|
|
172
|
+
onStart: () => void;
|
|
173
|
+
onStop: () => void;
|
|
174
|
+
};
|
|
175
|
+
readonly dependencies: readonly ["analytics", "hasBalanceAtom", "assetsWithBalanceCountAtom", "assetsTotalWalletAmountsAtom", "config?"];
|
|
176
|
+
readonly public: true;
|
|
177
|
+
};
|
|
178
|
+
readonly config: {
|
|
179
|
+
readonly assetsToTrackForBalances: {
|
|
180
|
+
assetName: string;
|
|
181
|
+
analyticsName: string;
|
|
182
|
+
}[];
|
|
183
|
+
};
|
|
184
|
+
}];
|
|
185
|
+
};
|
|
186
|
+
export type * from './types.js';
|
|
187
|
+
export default balances;
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import balancesDefinition from './module/index.js';
|
|
2
|
+
import { balancesAtomDefinition, hasBalanceAtomDefinition, fundedWalletAccountsAtomDefinition, assetsWithBalanceCountAtomDefinition, assetNamesWithBalanceAtomDefinition, assetsTotalWalletAmountsDefinition, } from './atoms/index.js';
|
|
3
|
+
import balancesReportDefinition from './report/index.js';
|
|
4
|
+
import { balancesLifecyclePluginDefinition, balancesAnalyticsPluginDefinition, } from './plugins/index.js';
|
|
5
|
+
import typeforce from '@exodus/typeforce';
|
|
6
|
+
import defaultConfig from './default-config.js';
|
|
7
|
+
import mockableBalancesDefinition from './module/mockable-balances.js';
|
|
8
|
+
import { safeString } from '@exodus/safe-string';
|
|
9
|
+
const balances = (walletConfig) => {
|
|
10
|
+
const config = {
|
|
11
|
+
...defaultConfig,
|
|
12
|
+
balanceFields: walletConfig?.balanceFields || defaultConfig.balanceFields,
|
|
13
|
+
assetsToTrackForBalances: walletConfig?.assetsToTrackForBalances || defaultConfig.assetsToTrackForBalances,
|
|
14
|
+
};
|
|
15
|
+
typeforce({
|
|
16
|
+
balanceFields: typeforce.arrayOf('String'),
|
|
17
|
+
balanceFieldsConfig: typeforce.arrayOf('Object'),
|
|
18
|
+
assetsToTrackForBalances: typeforce.arrayOf('Object'),
|
|
19
|
+
}, config, true);
|
|
20
|
+
return {
|
|
21
|
+
id: safeString `balances`,
|
|
22
|
+
definitions: [
|
|
23
|
+
walletConfig?.importReport
|
|
24
|
+
? {
|
|
25
|
+
definition: mockableBalancesDefinition,
|
|
26
|
+
config: { ...config, importReport: walletConfig.importReport },
|
|
27
|
+
}
|
|
28
|
+
: { definition: balancesDefinition, config },
|
|
29
|
+
{ definition: balancesAtomDefinition },
|
|
30
|
+
{ definition: assetNamesWithBalanceAtomDefinition },
|
|
31
|
+
{ definition: assetsWithBalanceCountAtomDefinition },
|
|
32
|
+
{
|
|
33
|
+
definition: hasBalanceAtomDefinition,
|
|
34
|
+
storage: { namespace: 'balances' },
|
|
35
|
+
aliases: [{ implementationId: 'unsafeStorage', interfaceId: 'storage' }],
|
|
36
|
+
},
|
|
37
|
+
{ definition: fundedWalletAccountsAtomDefinition },
|
|
38
|
+
{ definition: balancesReportDefinition },
|
|
39
|
+
{ definition: balancesLifecyclePluginDefinition },
|
|
40
|
+
{ definition: assetsTotalWalletAmountsDefinition },
|
|
41
|
+
{
|
|
42
|
+
if: { registered: ['analytics'] },
|
|
43
|
+
definition: balancesAnalyticsPluginDefinition,
|
|
44
|
+
config: { assetsToTrackForBalances: config.assetsToTrackForBalances },
|
|
45
|
+
},
|
|
46
|
+
],
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
export default balances;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Logger } from '@exodus/atoms';
|
|
2
|
+
import type { BalanceAsset, BalanceFieldConfig, FieldBalances } from './types.js';
|
|
3
|
+
import type NumberUnit from '@exodus/currency';
|
|
4
|
+
export declare const processAssetBalances: ({ balances, zero, balanceFieldsConfig, }: {
|
|
5
|
+
balances: FieldBalances;
|
|
6
|
+
zero: NumberUnit;
|
|
7
|
+
balanceFieldsConfig: BalanceFieldConfig[];
|
|
8
|
+
}) => FieldBalances;
|
|
9
|
+
export declare const validateBalances: ({ balances, asset, logger, }: {
|
|
10
|
+
balances: FieldBalances;
|
|
11
|
+
asset: BalanceAsset;
|
|
12
|
+
logger: Pick<Logger, "warn">;
|
|
13
|
+
}) => Record<string, NumberUnit>;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { mapValues } from '@exodus/basic-utils';
|
|
2
|
+
function resolveFieldBalance({ balances, fieldConfig, zero, processedBalances, }) {
|
|
3
|
+
if (balances[fieldConfig.name]) {
|
|
4
|
+
return balances[fieldConfig.name];
|
|
5
|
+
}
|
|
6
|
+
if (fieldConfig.legacyName && balances[fieldConfig.legacyName]) {
|
|
7
|
+
return balances[fieldConfig.legacyName];
|
|
8
|
+
}
|
|
9
|
+
if (fieldConfig.default && fieldConfig.default === 'zero') {
|
|
10
|
+
return zero;
|
|
11
|
+
}
|
|
12
|
+
if (fieldConfig.default && processedBalances[fieldConfig.default] !== null) {
|
|
13
|
+
if (processedBalances[fieldConfig.default] === undefined) {
|
|
14
|
+
throw new Error(`Field config "${fieldConfig.default}" must be defined before "${fieldConfig.name}"`);
|
|
15
|
+
}
|
|
16
|
+
return processedBalances[fieldConfig.default];
|
|
17
|
+
}
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
export const processAssetBalances = ({ balances, zero, balanceFieldsConfig, }) => {
|
|
21
|
+
return balanceFieldsConfig.reduce((processedBalances, fieldConfig) => {
|
|
22
|
+
const balance = resolveFieldBalance({
|
|
23
|
+
balances,
|
|
24
|
+
fieldConfig,
|
|
25
|
+
zero,
|
|
26
|
+
processedBalances,
|
|
27
|
+
});
|
|
28
|
+
if (balance !== null) {
|
|
29
|
+
processedBalances[fieldConfig.name] = balance;
|
|
30
|
+
if (fieldConfig.legacyName) {
|
|
31
|
+
processedBalances[fieldConfig.legacyName] = balance;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return processedBalances;
|
|
35
|
+
}, {});
|
|
36
|
+
};
|
|
37
|
+
export const validateBalances = ({ balances, asset, logger, }) => {
|
|
38
|
+
const assetName = asset.name;
|
|
39
|
+
const zero = asset.currency.ZERO;
|
|
40
|
+
const log = (error) => {
|
|
41
|
+
logger.warn(error.fn, error.error, error.args);
|
|
42
|
+
};
|
|
43
|
+
return mapValues(balances, (balance, field) => {
|
|
44
|
+
if (!balance) {
|
|
45
|
+
return balance;
|
|
46
|
+
}
|
|
47
|
+
if (!balance.unitType.equals(asset.currency)) {
|
|
48
|
+
log({
|
|
49
|
+
fn: 'getAssetBalances',
|
|
50
|
+
error: `asset.api.getBalances ${assetName} returns different ${field} currency`,
|
|
51
|
+
args: {
|
|
52
|
+
balanceUnit: balance.unitType.defaultUnit.unitName,
|
|
53
|
+
assetUnit: asset.currency.defaultUnit.unitName,
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
return zero;
|
|
57
|
+
}
|
|
58
|
+
if (balance.isNegative) {
|
|
59
|
+
log({
|
|
60
|
+
fn: 'getAssetBalances',
|
|
61
|
+
error: `asset.api.getBalances ${assetName} returns negative ${field}`,
|
|
62
|
+
args: {
|
|
63
|
+
amount: balance.toDefaultString({ unit: true }),
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
return zero;
|
|
67
|
+
}
|
|
68
|
+
return balance;
|
|
69
|
+
});
|
|
70
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { BalancesModule, Options } from './types.js';
|
|
2
|
+
import type { BalancesByAssetSource } from '../types.js';
|
|
3
|
+
export declare const cloneBalances: (balances: BalancesByAssetSource) => BalancesByAssetSource;
|
|
4
|
+
declare const balancesDefinition: {
|
|
5
|
+
readonly id: "balances";
|
|
6
|
+
readonly type: "module";
|
|
7
|
+
readonly factory: (opts: Options) => BalancesModule;
|
|
8
|
+
readonly dependencies: readonly ["assetsAtom", "availableAssetNamesAtom", "enabledWalletAccountsAtom", "config", "logger", "balancesAtom", "blockchainMetadataAtom", "feeDataAtom", "errorTracking"];
|
|
9
|
+
readonly public: true;
|
|
10
|
+
};
|
|
11
|
+
export default balancesDefinition;
|