@exodus/balances 13.16.1 → 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 +6 -0
- 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 -497
- package/module/mockable-balances.d.ts +1 -0
- package/module/mockable-balances.js +1 -27
- package/package.json +23 -17
- 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 -8
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,12 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [13.17.0](https://github.com/ExodusMovement/exodus/compare/@exodus/balances@13.16.1...@exodus/balances@13.17.0) (2026-11-13)
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
- **balances:** migrate to TypeScript ([#48879](https://github.com/ExodusMovement/exodus/issues/48879)) ([6f6294b](https://github.com/ExodusMovement/exodus/commit/6f6294bb458c26ba5e59d1cc9125ab39ce7a909e))
|
|
11
|
+
|
|
6
12
|
## [13.16.1](https://github.com/ExodusMovement/exodus/compare/@exodus/balances@13.16.0...@exodus/balances@13.16.1) (2026-10-09)
|
|
7
13
|
|
|
8
14
|
**Note:** Version bump only for package @exodus/balances
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from '../lib/atoms/asset-names-with-balance.js'
|
|
@@ -1,40 +1 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const setsAreEqual = (setA, setB) => {
|
|
4
|
-
if (setA.size !== setB.size) {
|
|
5
|
-
return false
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
for (const item of setA) {
|
|
9
|
-
if (!setB.has(item)) {
|
|
10
|
-
return false
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
return true
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
const createAssetNamesWithBalanceAtom = ({ balancesAtom }) => {
|
|
18
|
-
let previousValue = new Set()
|
|
19
|
-
const selector = ({ balances }) => {
|
|
20
|
-
const assetsWithBalances = new Set()
|
|
21
|
-
|
|
22
|
-
Object.values(balances).forEach((accountBalances) => {
|
|
23
|
-
Object.keys(accountBalances).forEach((assetName) => {
|
|
24
|
-
if (!accountBalances[assetName]?.balance.isZero) {
|
|
25
|
-
assetsWithBalances.add(assetName)
|
|
26
|
-
}
|
|
27
|
-
})
|
|
28
|
-
})
|
|
29
|
-
|
|
30
|
-
if (!setsAreEqual(assetsWithBalances, previousValue)) {
|
|
31
|
-
previousValue = assetsWithBalances
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
return previousValue
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
return compute({ atom: balancesAtom, selector })
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export default createAssetNamesWithBalanceAtom
|
|
1
|
+
export { default } from '../lib/atoms/asset-names-with-balance.js'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from '../lib/atoms/asset-total-wallet-amounts.js'
|
|
@@ -1,47 +1 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const numberUnitMapsAreEqual = (mapA, mapB) => {
|
|
4
|
-
if (mapA.size !== mapB.size) {
|
|
5
|
-
return false
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
for (const [key, val] of mapA) {
|
|
9
|
-
const itemB = mapB.get(key)
|
|
10
|
-
if (!itemB || !itemB.equals(val)) {
|
|
11
|
-
return false
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
return true
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
const createAssetTotalWalletAmountsAtom = ({ balancesAtom }) => {
|
|
19
|
-
let previousValue = new Map()
|
|
20
|
-
const selector = ({ balances }) => {
|
|
21
|
-
const assetsWithBalances = new Map()
|
|
22
|
-
|
|
23
|
-
Object.values(balances).forEach((accountBalances) => {
|
|
24
|
-
Object.keys(accountBalances).forEach((assetName) => {
|
|
25
|
-
const accountAssetBalance = accountBalances[assetName] && accountBalances[assetName].balance
|
|
26
|
-
if (accountAssetBalance) {
|
|
27
|
-
if (assetsWithBalances.has(assetName)) {
|
|
28
|
-
const currentAssetBalance = assetsWithBalances.get(assetName)
|
|
29
|
-
assetsWithBalances.set(assetName, accountAssetBalance.add(currentAssetBalance))
|
|
30
|
-
} else {
|
|
31
|
-
assetsWithBalances.set(assetName, accountAssetBalance)
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
})
|
|
35
|
-
})
|
|
36
|
-
|
|
37
|
-
if (!numberUnitMapsAreEqual(assetsWithBalances, previousValue)) {
|
|
38
|
-
previousValue = assetsWithBalances
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
return previousValue
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
return dedupe(compute({ atom: balancesAtom, selector }))
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export default createAssetTotalWalletAmountsAtom
|
|
1
|
+
export { default } from '../lib/atoms/asset-total-wallet-amounts.js'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from '../lib/atoms/assets-with-balance-count.js'
|
|
@@ -1,8 +1 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const createAssetsWithBalanceCountAtom = ({ assetNamesWithBalanceAtom }) => {
|
|
4
|
-
const selector = (assetNamesWithBalance) => assetNamesWithBalance.size
|
|
5
|
-
return compute({ atom: assetNamesWithBalanceAtom, selector })
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export default createAssetsWithBalanceCountAtom
|
|
1
|
+
export { default } from '../lib/atoms/assets-with-balance-count.js'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from '../lib/atoms/balances.js'
|
package/atoms/balances.js
CHANGED
|
@@ -1,6 +1 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
// oxlint-disable-next-line @exodus/oxlint-plugin-hydra/in-memory-atom-default-value
|
|
4
|
-
const createBalancesAtom = () => createInMemoryAtom()
|
|
5
|
-
|
|
6
|
-
export default createBalancesAtom
|
|
1
|
+
export { default } from '../lib/atoms/balances.js'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from '../lib/atoms/funded-wallet-accounts.js'
|
|
@@ -1,25 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import { mapValues } from '@exodus/basic-utils'
|
|
3
|
-
|
|
4
|
-
const computeFundedWalletAccounts = ({ walletAccounts, balances }) => {
|
|
5
|
-
return mapValues(walletAccounts, (_, key) => {
|
|
6
|
-
const walletAccountBalaces = balances.balances[key] || {}
|
|
7
|
-
return Object.values(walletAccountBalaces).some(({ balance }) => !balance.isZero)
|
|
8
|
-
})
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
const createFundedWalletAccountsAtom = ({ balancesAtom, enabledWalletAccountsAtom }) => {
|
|
12
|
-
const walletAccountsBalanceAtom = combine({
|
|
13
|
-
walletAccounts: enabledWalletAccountsAtom,
|
|
14
|
-
balances: balancesAtom,
|
|
15
|
-
})
|
|
16
|
-
|
|
17
|
-
return dedupe(
|
|
18
|
-
compute({
|
|
19
|
-
atom: walletAccountsBalanceAtom,
|
|
20
|
-
selector: computeFundedWalletAccounts,
|
|
21
|
-
})
|
|
22
|
-
)
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export default createFundedWalletAccountsAtom
|
|
1
|
+
export { default } from '../lib/atoms/funded-wallet-accounts.js'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from '../lib/atoms/has-balance.js'
|
package/atoms/has-balance.js
CHANGED
|
@@ -1,31 +1 @@
|
|
|
1
|
-
|
|
2
|
-
// eslint-disable-next-line no-restricted-imports -- TODO: Fix this the next time the file is edited.
|
|
3
|
-
import lodash from 'lodash'
|
|
4
|
-
|
|
5
|
-
const { flatMap, map } = lodash
|
|
6
|
-
|
|
7
|
-
// balancesAtom schema: { balances: { [walletAccount]: { [assetName]: { balance: NumberUnit } } } } }
|
|
8
|
-
|
|
9
|
-
const createComputedAtom = ({ balancesAtom }) => {
|
|
10
|
-
const selector = ({ balances } = {}) => {
|
|
11
|
-
const numberUnits = flatMap(balances, (value) => map(value, 'balance'))
|
|
12
|
-
return numberUnits.some((numberUnit) => (numberUnit ? !numberUnit.isZero : false))
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
return compute({ atom: balancesAtom, selector })
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
const createHasBalanceAtom = ({ balancesAtom, storage }) => {
|
|
19
|
-
const storageAtom = createStorageAtomFactory({ storage })({
|
|
20
|
-
key: 'hasBalance',
|
|
21
|
-
defaultValue: false,
|
|
22
|
-
isSoleWriter: true,
|
|
23
|
-
})
|
|
24
|
-
const computedAtom = createComputedAtom({ balancesAtom })
|
|
25
|
-
// oxlint-disable-next-line @exodus/oxlint-plugin-hydra/no-eternal-subscription
|
|
26
|
-
computedAtom.observe((value) => storageAtom.set(value))
|
|
27
|
-
|
|
28
|
-
return storageAtom
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export default createHasBalanceAtom
|
|
1
|
+
export { default } from '../lib/atoms/has-balance.js'
|
package/atoms/index.d.ts
ADDED
package/atoms/index.js
CHANGED
|
@@ -1,54 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
id: 'balancesAtom',
|
|
10
|
-
type: 'atom',
|
|
11
|
-
factory: createBalancesAtom,
|
|
12
|
-
dependencies: [],
|
|
13
|
-
public: true,
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export const hasBalanceAtomDefinition = {
|
|
17
|
-
id: 'hasBalanceAtom',
|
|
18
|
-
type: 'atom',
|
|
19
|
-
factory: createHasBalanceAtom,
|
|
20
|
-
dependencies: ['balancesAtom', 'storage'],
|
|
21
|
-
public: true,
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export const fundedWalletAccountsAtomDefinition = {
|
|
25
|
-
id: 'fundedWalletAccountsAtom',
|
|
26
|
-
type: 'atom',
|
|
27
|
-
factory: createFundedWalletAccountsAtom,
|
|
28
|
-
dependencies: ['balancesAtom', 'enabledWalletAccountsAtom'],
|
|
29
|
-
public: true,
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export const assetNamesWithBalanceAtomDefinition = {
|
|
33
|
-
id: 'assetNamesWithBalanceAtom',
|
|
34
|
-
type: 'atom',
|
|
35
|
-
factory: createAssetNamesWithBalanceAtom,
|
|
36
|
-
dependencies: ['balancesAtom'],
|
|
37
|
-
public: true,
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export const assetsWithBalanceCountAtomDefinition = {
|
|
41
|
-
id: 'assetsWithBalanceCountAtom',
|
|
42
|
-
type: 'atom',
|
|
43
|
-
factory: createAssetsWithBalanceCountAtom,
|
|
44
|
-
dependencies: ['assetNamesWithBalanceAtom'],
|
|
45
|
-
public: true,
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export const assetsTotalWalletAmountsDefinition = {
|
|
49
|
-
id: 'assetsTotalWalletAmountsAtom',
|
|
50
|
-
type: 'atom',
|
|
51
|
-
factory: createAssetsTotalWalletAmountsAtom,
|
|
52
|
-
dependencies: ['balancesAtom'],
|
|
53
|
-
public: true,
|
|
54
|
-
}
|
|
1
|
+
export {
|
|
2
|
+
balancesAtomDefinition,
|
|
3
|
+
hasBalanceAtomDefinition,
|
|
4
|
+
fundedWalletAccountsAtomDefinition,
|
|
5
|
+
assetNamesWithBalanceAtomDefinition,
|
|
6
|
+
assetsWithBalanceCountAtomDefinition,
|
|
7
|
+
assetsTotalWalletAmountsDefinition,
|
|
8
|
+
} from '../lib/atoms/index.js'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from './lib/default-config.js'
|
package/default-config.js
CHANGED
|
@@ -1,26 +1 @@
|
|
|
1
|
-
|
|
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
|
-
|
|
18
|
-
const config = {
|
|
19
|
-
balanceFieldsConfig,
|
|
20
|
-
balanceFields: balanceFieldsConfig
|
|
21
|
-
.flatMap((fieldConfig) => [fieldConfig.name, fieldConfig.legacyName])
|
|
22
|
-
.filter(Boolean), // wallets can reduce the number of exposed fields,
|
|
23
|
-
assetsToTrackForBalances: [],
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export default config
|
|
1
|
+
export { default } from './lib/default-config.js'
|
package/index.d.ts
CHANGED
|
@@ -1,35 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import type NumberUnit from '@exodus/currency'
|
|
4
|
-
|
|
5
|
-
declare const balances: (walletConfig?: Record<string, unknown>) => {
|
|
6
|
-
id: string
|
|
7
|
-
definitions: unknown[]
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export type Balances = Partial<AssetBalances>
|
|
11
|
-
|
|
12
|
-
type WalletAccountName = string
|
|
13
|
-
|
|
14
|
-
type AssetName = string
|
|
15
|
-
|
|
16
|
-
export type BalancesByAssetSource = Record<WalletAccountName, Record<AssetName, Balances>>
|
|
17
|
-
|
|
18
|
-
export type BalanceChange = {
|
|
19
|
-
from: NumberUnit
|
|
20
|
-
to: NumberUnit
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export type BalanceChanges = Record<
|
|
24
|
-
WalletAccountName,
|
|
25
|
-
Record<AssetName, Partial<Record<BalanceFieldName, BalanceChange>>>
|
|
26
|
-
>
|
|
27
|
-
|
|
28
|
-
export type BalancesAtomValue = {
|
|
29
|
-
balances: BalancesByAssetSource
|
|
30
|
-
changes?: BalanceChanges
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export type BalancesAtom = Atom<BalancesAtomValue>
|
|
34
|
-
|
|
35
|
-
export default balances
|
|
1
|
+
export { default } from './lib/index.js'
|
|
2
|
+
export type * from './lib/types.js'
|
package/index.js
CHANGED
|
@@ -1,65 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
balancesAtomDefinition,
|
|
4
|
-
hasBalanceAtomDefinition,
|
|
5
|
-
fundedWalletAccountsAtomDefinition,
|
|
6
|
-
assetsWithBalanceCountAtomDefinition,
|
|
7
|
-
assetNamesWithBalanceAtomDefinition,
|
|
8
|
-
assetsTotalWalletAmountsDefinition,
|
|
9
|
-
} from './atoms/index.js'
|
|
10
|
-
import balancesReportDefinition from './report/index.js'
|
|
11
|
-
import {
|
|
12
|
-
balancesLifecyclePluginDefinition,
|
|
13
|
-
balancesAnalyticsPluginDefinition,
|
|
14
|
-
} from './plugins/index.js'
|
|
15
|
-
import typeforce from '@exodus/typeforce'
|
|
16
|
-
import defaultConfig from './default-config.js'
|
|
17
|
-
import mockableBalancesDefinition from './module/mockable-balances.js'
|
|
18
|
-
import { safeString } from '@exodus/safe-string'
|
|
19
|
-
|
|
20
|
-
const balances = (walletConfig) => {
|
|
21
|
-
const config = {
|
|
22
|
-
...defaultConfig,
|
|
23
|
-
balanceFields: walletConfig?.balanceFields || defaultConfig.balanceFields,
|
|
24
|
-
assetsToTrackForBalances:
|
|
25
|
-
walletConfig?.assetsToTrackForBalances || defaultConfig.assetsToTrackForBalances,
|
|
26
|
-
}
|
|
27
|
-
typeforce(
|
|
28
|
-
{
|
|
29
|
-
balanceFields: typeforce.arrayOf('String'),
|
|
30
|
-
balanceFieldsConfig: typeforce.arrayOf('Object'),
|
|
31
|
-
assetsToTrackForBalances: typeforce.arrayOf('Object'),
|
|
32
|
-
},
|
|
33
|
-
config,
|
|
34
|
-
true
|
|
35
|
-
)
|
|
36
|
-
|
|
37
|
-
return {
|
|
38
|
-
id: safeString`balances`,
|
|
39
|
-
definitions: [
|
|
40
|
-
{
|
|
41
|
-
definition: walletConfig?.importReport ? mockableBalancesDefinition : balancesDefinition,
|
|
42
|
-
config,
|
|
43
|
-
},
|
|
44
|
-
{ definition: balancesAtomDefinition },
|
|
45
|
-
{ definition: assetNamesWithBalanceAtomDefinition },
|
|
46
|
-
{ definition: assetsWithBalanceCountAtomDefinition },
|
|
47
|
-
{
|
|
48
|
-
definition: hasBalanceAtomDefinition,
|
|
49
|
-
storage: { namespace: 'balances' },
|
|
50
|
-
aliases: [{ implementationId: 'unsafeStorage', interfaceId: 'storage' }],
|
|
51
|
-
},
|
|
52
|
-
{ definition: fundedWalletAccountsAtomDefinition },
|
|
53
|
-
{ definition: balancesReportDefinition },
|
|
54
|
-
{ definition: balancesLifecyclePluginDefinition },
|
|
55
|
-
{ definition: assetsTotalWalletAmountsDefinition },
|
|
56
|
-
{
|
|
57
|
-
if: { registered: ['analytics'] },
|
|
58
|
-
definition: balancesAnalyticsPluginDefinition,
|
|
59
|
-
config: { assetsToTrackForBalances: config.assetsToTrackForBalances },
|
|
60
|
-
},
|
|
61
|
-
],
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
export default balances
|
|
1
|
+
export { default } from './lib/index.js'
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { compute } from '@exodus/atoms';
|
|
2
|
+
const setsAreEqual = (setA, setB) => {
|
|
3
|
+
if (setA.size !== setB.size) {
|
|
4
|
+
return false;
|
|
5
|
+
}
|
|
6
|
+
for (const item of setA) {
|
|
7
|
+
if (!setB.has(item)) {
|
|
8
|
+
return false;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
return true;
|
|
12
|
+
};
|
|
13
|
+
const createAssetNamesWithBalanceAtom = ({ balancesAtom }) => {
|
|
14
|
+
let previousValue = new Set();
|
|
15
|
+
const selector = ({ balances }) => {
|
|
16
|
+
const assetsWithBalances = new Set();
|
|
17
|
+
Object.values(balances).forEach((accountBalances) => {
|
|
18
|
+
Object.keys(accountBalances).forEach((assetName) => {
|
|
19
|
+
if (!accountBalances[assetName]?.balance.isZero) {
|
|
20
|
+
assetsWithBalances.add(assetName);
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
if (!setsAreEqual(assetsWithBalances, previousValue)) {
|
|
25
|
+
previousValue = assetsWithBalances;
|
|
26
|
+
}
|
|
27
|
+
return previousValue;
|
|
28
|
+
};
|
|
29
|
+
return compute({ atom: balancesAtom, selector });
|
|
30
|
+
};
|
|
31
|
+
export default createAssetNamesWithBalanceAtom;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { compute, dedupe } from '@exodus/atoms';
|
|
2
|
+
const numberUnitMapsAreEqual = (mapA, mapB) => {
|
|
3
|
+
if (mapA.size !== mapB.size) {
|
|
4
|
+
return false;
|
|
5
|
+
}
|
|
6
|
+
for (const [key, val] of mapA) {
|
|
7
|
+
const itemB = mapB.get(key);
|
|
8
|
+
if (!itemB || !itemB.equals(val)) {
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
return true;
|
|
13
|
+
};
|
|
14
|
+
const createAssetTotalWalletAmountsAtom = ({ balancesAtom, }) => {
|
|
15
|
+
let previousValue = new Map();
|
|
16
|
+
const selector = ({ balances }) => {
|
|
17
|
+
const assetsWithBalances = new Map();
|
|
18
|
+
Object.values(balances).forEach((accountBalances) => {
|
|
19
|
+
Object.keys(accountBalances).forEach((assetName) => {
|
|
20
|
+
const accountAssetBalance = accountBalances[assetName]?.balance;
|
|
21
|
+
if (accountAssetBalance) {
|
|
22
|
+
if (assetsWithBalances.has(assetName)) {
|
|
23
|
+
const currentAssetBalance = assetsWithBalances.get(assetName);
|
|
24
|
+
assetsWithBalances.set(assetName, accountAssetBalance.add(currentAssetBalance));
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
assetsWithBalances.set(assetName, accountAssetBalance);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
if (!numberUnitMapsAreEqual(assetsWithBalances, previousValue)) {
|
|
33
|
+
previousValue = assetsWithBalances;
|
|
34
|
+
}
|
|
35
|
+
return previousValue;
|
|
36
|
+
};
|
|
37
|
+
return dedupe(compute({ atom: balancesAtom, selector }));
|
|
38
|
+
};
|
|
39
|
+
export default createAssetTotalWalletAmountsAtom;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { ReadonlyAtom } from '@exodus/atoms';
|
|
2
|
+
declare const createAssetsWithBalanceCountAtom: ({ assetNamesWithBalanceAtom, }: {
|
|
3
|
+
assetNamesWithBalanceAtom: ReadonlyAtom<Set<string>>;
|
|
4
|
+
}) => ReadonlyAtom<number>;
|
|
5
|
+
export default createAssetsWithBalanceCountAtom;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { compute } from '@exodus/atoms';
|
|
2
|
+
const createAssetsWithBalanceCountAtom = ({ assetNamesWithBalanceAtom, }) => {
|
|
3
|
+
const selector = (assetNamesWithBalance) => assetNamesWithBalance.size;
|
|
4
|
+
return compute({ atom: assetNamesWithBalanceAtom, selector });
|
|
5
|
+
};
|
|
6
|
+
export default createAssetsWithBalanceCountAtom;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { FundedWalletAccountsAtom, BalancesAtom } from '../types.js';
|
|
2
|
+
import type { ReadonlyAtom } from '@exodus/atoms';
|
|
3
|
+
import type { WalletAccount } from '@exodus/models';
|
|
4
|
+
declare const createFundedWalletAccountsAtom: ({ balancesAtom, enabledWalletAccountsAtom, }: {
|
|
5
|
+
balancesAtom: BalancesAtom;
|
|
6
|
+
enabledWalletAccountsAtom: ReadonlyAtom<Record<string, WalletAccount>>;
|
|
7
|
+
}) => FundedWalletAccountsAtom;
|
|
8
|
+
export default createFundedWalletAccountsAtom;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { combine, compute, dedupe } from '@exodus/atoms';
|
|
2
|
+
import { mapValues } from '@exodus/basic-utils';
|
|
3
|
+
const computeFundedWalletAccounts = ({ walletAccounts, balances, }) => {
|
|
4
|
+
return mapValues(walletAccounts, (_, key) => {
|
|
5
|
+
const walletAccountBalaces = balances.balances[key] || {};
|
|
6
|
+
return Object.values(walletAccountBalaces).some(({ balance }) => !balance.isZero);
|
|
7
|
+
});
|
|
8
|
+
};
|
|
9
|
+
const createFundedWalletAccountsAtom = ({ balancesAtom, enabledWalletAccountsAtom, }) => {
|
|
10
|
+
const walletAccountsBalanceAtom = combine({
|
|
11
|
+
walletAccounts: enabledWalletAccountsAtom,
|
|
12
|
+
balances: balancesAtom,
|
|
13
|
+
});
|
|
14
|
+
return dedupe(compute({
|
|
15
|
+
atom: walletAccountsBalanceAtom,
|
|
16
|
+
selector: computeFundedWalletAccounts,
|
|
17
|
+
}));
|
|
18
|
+
};
|
|
19
|
+
export default createFundedWalletAccountsAtom;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Storage } from '@exodus/storage-interface';
|
|
2
|
+
import type { HasBalanceAtom, BalancesAtom } from '../types.js';
|
|
3
|
+
declare const createHasBalanceAtom: ({ balancesAtom, storage, }: {
|
|
4
|
+
balancesAtom: BalancesAtom;
|
|
5
|
+
storage: Storage<boolean>;
|
|
6
|
+
}) => HasBalanceAtom;
|
|
7
|
+
export default createHasBalanceAtom;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { compute, createStorageAtomFactory } from '@exodus/atoms';
|
|
2
|
+
import lodash from 'lodash';
|
|
3
|
+
const { flatMap, map } = lodash;
|
|
4
|
+
const createComputedAtom = ({ balancesAtom }) => {
|
|
5
|
+
const selector = ({ balances } = { balances: {} }) => {
|
|
6
|
+
const numberUnits = flatMap(balances, (value) => map(value, 'balance'));
|
|
7
|
+
return numberUnits.some((numberUnit) => (numberUnit ? !numberUnit.isZero : false));
|
|
8
|
+
};
|
|
9
|
+
return compute({ atom: balancesAtom, selector });
|
|
10
|
+
};
|
|
11
|
+
const createHasBalanceAtom = ({ balancesAtom, storage, }) => {
|
|
12
|
+
const storageAtom = createStorageAtomFactory({ storage })({
|
|
13
|
+
key: 'hasBalance',
|
|
14
|
+
defaultValue: false,
|
|
15
|
+
isSoleWriter: true,
|
|
16
|
+
});
|
|
17
|
+
const computedAtom = createComputedAtom({ balancesAtom });
|
|
18
|
+
computedAtom.observe((value) => storageAtom.set(value));
|
|
19
|
+
return storageAtom;
|
|
20
|
+
};
|
|
21
|
+
export default createHasBalanceAtom;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
export declare const balancesAtomDefinition: {
|
|
2
|
+
readonly id: "balancesAtom";
|
|
3
|
+
readonly type: "atom";
|
|
4
|
+
readonly factory: () => import("@exodus/atoms").Atom<import("../types.js").BalancesAtomValue>;
|
|
5
|
+
readonly dependencies: readonly [];
|
|
6
|
+
readonly public: true;
|
|
7
|
+
};
|
|
8
|
+
export declare const hasBalanceAtomDefinition: {
|
|
9
|
+
readonly id: "hasBalanceAtom";
|
|
10
|
+
readonly type: "atom";
|
|
11
|
+
readonly factory: ({ balancesAtom, storage, }: {
|
|
12
|
+
balancesAtom: import("../types.js").BalancesAtom;
|
|
13
|
+
storage: import("@exodus/storage-interface").Storage<boolean>;
|
|
14
|
+
}) => import("../types.js").HasBalanceAtom;
|
|
15
|
+
readonly dependencies: readonly ["balancesAtom", "storage"];
|
|
16
|
+
readonly public: true;
|
|
17
|
+
};
|
|
18
|
+
export declare const fundedWalletAccountsAtomDefinition: {
|
|
19
|
+
readonly id: "fundedWalletAccountsAtom";
|
|
20
|
+
readonly type: "atom";
|
|
21
|
+
readonly factory: ({ balancesAtom, enabledWalletAccountsAtom, }: {
|
|
22
|
+
balancesAtom: import("../types.js").BalancesAtom;
|
|
23
|
+
enabledWalletAccountsAtom: import("@exodus/atoms").ReadonlyAtom<Record<string, import("@exodus/models").WalletAccount>>;
|
|
24
|
+
}) => import("../types.js").FundedWalletAccountsAtom;
|
|
25
|
+
readonly dependencies: readonly ["balancesAtom", "enabledWalletAccountsAtom"];
|
|
26
|
+
readonly public: true;
|
|
27
|
+
};
|
|
28
|
+
export declare const assetNamesWithBalanceAtomDefinition: {
|
|
29
|
+
readonly id: "assetNamesWithBalanceAtom";
|
|
30
|
+
readonly type: "atom";
|
|
31
|
+
readonly factory: ({ balancesAtom }: {
|
|
32
|
+
balancesAtom: import("../types.js").BalancesAtom;
|
|
33
|
+
}) => import("@exodus/atoms").ReadonlyAtom<Set<string>>;
|
|
34
|
+
readonly dependencies: readonly ["balancesAtom"];
|
|
35
|
+
readonly public: true;
|
|
36
|
+
};
|
|
37
|
+
export declare const assetsWithBalanceCountAtomDefinition: {
|
|
38
|
+
readonly id: "assetsWithBalanceCountAtom";
|
|
39
|
+
readonly type: "atom";
|
|
40
|
+
readonly factory: ({ assetNamesWithBalanceAtom, }: {
|
|
41
|
+
assetNamesWithBalanceAtom: import("@exodus/atoms").ReadonlyAtom<Set<string>>;
|
|
42
|
+
}) => import("@exodus/atoms").ReadonlyAtom<number>;
|
|
43
|
+
readonly dependencies: readonly ["assetNamesWithBalanceAtom"];
|
|
44
|
+
readonly public: true;
|
|
45
|
+
};
|
|
46
|
+
export declare const assetsTotalWalletAmountsDefinition: {
|
|
47
|
+
readonly id: "assetsTotalWalletAmountsAtom";
|
|
48
|
+
readonly type: "atom";
|
|
49
|
+
readonly factory: ({ balancesAtom, }: {
|
|
50
|
+
balancesAtom: import("../types.js").BalancesAtom;
|
|
51
|
+
}) => import("../types.js").AssetTotalWalletAmountsAtom;
|
|
52
|
+
readonly dependencies: readonly ["balancesAtom"];
|
|
53
|
+
readonly public: true;
|
|
54
|
+
};
|