@exodus/headless 2.0.0-alpha.6 → 2.0.0-alpha.61
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 +433 -0
- package/README.md +133 -4
- package/package.json +54 -17
- package/src/api.js +11 -31
- package/src/application.js +54 -39
- package/src/atoms/attach.js +31 -0
- package/src/atoms/base-asset-names-to-monitor.js +37 -0
- package/src/constants.js +37 -0
- package/src/dependencies/atoms.js +2 -21
- package/src/dependencies/index.js +8 -1
- package/src/dependencies/modules.js +2 -16
- package/src/dependencies/plugins.js +7 -0
- package/src/dependencies/utils.js +0 -4
- package/src/features/available-assets/index.js +15 -0
- package/src/features/balances/index.js +14 -0
- package/src/features/blockchain-metadata/api.js +22 -0
- package/src/features/blockchain-metadata/index.js +20 -0
- package/src/features/blockchain-metadata/plugin.js +30 -0
- package/src/features/blockchain-metadata/utils.js +11 -0
- package/src/features/enabled-assets/api.js +18 -0
- package/src/features/enabled-assets/index.js +26 -0
- package/src/features/enabled-assets/plugin.js +18 -0
- package/src/features/feature-flags/api.js +14 -0
- package/src/features/feature-flags/index.js +37 -0
- package/src/features/feature-flags/plugin.js +18 -0
- package/src/features/fees/index.js +16 -0
- package/src/features/fees/plugin.js +17 -0
- package/src/features/fiat-balances/index.js +10 -0
- package/src/features/fiat-balances/non-dust-balance-asset-names-atom.js +10 -0
- package/src/features/geolocation/index.js +20 -0
- package/src/features/geolocation/plugin.js +14 -0
- package/src/features/locale/api.js +13 -0
- package/src/features/locale/index.js +50 -0
- package/src/features/locale/plugin.js +14 -0
- package/src/features/market-history/index.js +69 -0
- package/src/features/market-history/plugin.js +21 -0
- package/src/features/nfts/api.js +13 -0
- package/src/features/nfts/index.js +33 -0
- package/src/features/nfts/plugin.js +23 -0
- package/src/features/pricing/api.js +14 -0
- package/src/features/pricing/index.js +35 -0
- package/src/features/rates/api.js +12 -0
- package/src/features/rates/index.js +22 -0
- package/src/features/rates/plugin.js +17 -0
- package/src/features/remote-config/api.js +13 -0
- package/src/features/remote-config/index.js +28 -0
- package/src/features/remote-config/plugin.js +20 -0
- package/src/features/wallet/api.js +34 -0
- package/src/features/wallet/index.js +24 -0
- package/src/features/wallet/locked-atom.js +10 -0
- package/src/features/wallet/restore-atom.js +10 -0
- package/src/features/wallet/restore-plugin.js +17 -0
- package/src/features/wallet-accounts/api.js +16 -0
- package/src/features/wallet-accounts/index.js +29 -0
- package/src/features/wallet-accounts/plugin.js +18 -0
- package/src/index.js +102 -18
- package/src/ioc.js +40 -7
- package/src/plugins/attach.js +25 -0
- package/src/plugins/index.js +5 -0
- package/src/plugins/log-lifecycle.js +26 -0
- package/src/unlock-encrypted-storage.js +1 -1
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@exodus/headless",
|
|
3
|
-
"version": "2.0.0-alpha.
|
|
4
|
-
"description": "The
|
|
5
|
-
"author": "Exodus Movement Inc",
|
|
3
|
+
"version": "2.0.0-alpha.61",
|
|
4
|
+
"description": "The platform-agnostic Exodus wallet SDK",
|
|
5
|
+
"author": "Exodus Movement Inc.",
|
|
6
6
|
"main": "src/index.js",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
@@ -17,40 +17,77 @@
|
|
|
17
17
|
"src",
|
|
18
18
|
"README.md",
|
|
19
19
|
"CHANGELOG.md",
|
|
20
|
-
"!**/__tests__",
|
|
20
|
+
"!**/__tests__/**",
|
|
21
21
|
"!**/*.test.js"
|
|
22
22
|
],
|
|
23
23
|
"scripts": {
|
|
24
24
|
"lint": "eslint . --ignore-path ../../.gitignore",
|
|
25
25
|
"lint:fix": "yarn lint --fix",
|
|
26
|
-
"test": "jest"
|
|
26
|
+
"test": "jest --runInBand"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@exodus/
|
|
30
|
-
"@exodus/
|
|
31
|
-
"@exodus/
|
|
29
|
+
"@exodus/ab-testing": "^6.0.0",
|
|
30
|
+
"@exodus/address-provider": "^5.0.0",
|
|
31
|
+
"@exodus/apy-rates": "^3.0.0",
|
|
32
|
+
"@exodus/atoms": "^5.2.1",
|
|
33
|
+
"@exodus/auto-enable-assets-plugin": "^4.0.1",
|
|
34
|
+
"@exodus/available-assets": "^2.0.2",
|
|
35
|
+
"@exodus/balances": "^6.0.1",
|
|
36
|
+
"@exodus/basic-utils": "^2.0.0",
|
|
37
|
+
"@exodus/blockchain-metadata": "^8.1.0",
|
|
38
|
+
"@exodus/config": "^7.0.0",
|
|
39
|
+
"@exodus/connected-origins": "^2.0.0",
|
|
40
|
+
"@exodus/crypto-news-monitor": "^3.0.0",
|
|
41
|
+
"@exodus/dependency-injection": "^2.0.0",
|
|
42
|
+
"@exodus/dependency-preprocessors": "^2.8.2",
|
|
43
|
+
"@exodus/enabled-assets": "^6.0.2",
|
|
44
|
+
"@exodus/exodus-pricing-client": "^1.2.0",
|
|
45
|
+
"@exodus/feature-flags": "^2.2.0",
|
|
46
|
+
"@exodus/fee-monitors": "^1.0.0",
|
|
32
47
|
"@exodus/fetch": "^1.2.1",
|
|
33
|
-
"@exodus/
|
|
34
|
-
"@exodus/
|
|
48
|
+
"@exodus/fusion": "^6.0.0",
|
|
49
|
+
"@exodus/geolocation": "^2.0.1",
|
|
50
|
+
"@exodus/key-identifier-provider": "^1.1.3",
|
|
51
|
+
"@exodus/keychain": "^4.1.0",
|
|
52
|
+
"@exodus/kyc": "^4.0.0",
|
|
53
|
+
"@exodus/market-history": "^3.1.2",
|
|
35
54
|
"@exodus/module": "^1.0.0",
|
|
36
|
-
"@exodus/
|
|
55
|
+
"@exodus/nfts": "^2.1.1",
|
|
56
|
+
"@exodus/rates-monitor": "^2.0.1",
|
|
57
|
+
"@exodus/top-movers-monitor": "^3.0.0",
|
|
58
|
+
"@exodus/wallet": "^6.0.1",
|
|
37
59
|
"@exodus/wallet-accounts": "^8.0.1",
|
|
38
|
-
"@exodus/wallet-compatibility-modes": "
|
|
39
|
-
"bip39": "2.6.0",
|
|
40
|
-
"
|
|
60
|
+
"@exodus/wallet-compatibility-modes": "^2.0.0",
|
|
61
|
+
"bip39": "^2.6.0",
|
|
62
|
+
"events": "^3.3.0",
|
|
63
|
+
"lodash": "npm:@exodus/lodash@^4.17.21-exodus.2",
|
|
41
64
|
"minimalistic-assert": "^1.0.1"
|
|
42
65
|
},
|
|
43
66
|
"devDependencies": {
|
|
67
|
+
"@exodus/algorand-lib": "^2.0.1",
|
|
68
|
+
"@exodus/algorand-meta": "^1.1.4",
|
|
69
|
+
"@exodus/bitcoin-lib": "^2.2.1",
|
|
70
|
+
"@exodus/bitcoin-meta": "^1.0.0",
|
|
71
|
+
"@exodus/currency": "^2.2.0",
|
|
44
72
|
"@exodus/ethereum-lib": "^2.22.2",
|
|
73
|
+
"@exodus/ethereum-meta": "^1.0.23",
|
|
45
74
|
"@exodus/models": "^8.11.1",
|
|
75
|
+
"@exodus/personal-notes": "^3.3.0",
|
|
76
|
+
"@exodus/referrals": "^6.0.2",
|
|
46
77
|
"@exodus/solana-lib": "^1.3.11",
|
|
47
|
-
"@exodus/
|
|
48
|
-
"@exodus/storage-
|
|
78
|
+
"@exodus/solana-meta": "^1.0.2",
|
|
79
|
+
"@exodus/storage-encrypted": "^1.1.2",
|
|
80
|
+
"@exodus/storage-memory": "^2.1.0",
|
|
49
81
|
"@exodus/wild-emitter": "^1.0.0",
|
|
50
82
|
"buffer-json": "^2.0.0",
|
|
83
|
+
"deepmerge": "^4.2.2",
|
|
84
|
+
"delay": "^5.0.0",
|
|
51
85
|
"eslint": "^8.33.0",
|
|
86
|
+
"eslint-plugin-simple-import-sort": "^7.0.0",
|
|
87
|
+
"events": "^3.3.0",
|
|
52
88
|
"jest": "^29.1.2",
|
|
89
|
+
"nock": "^13.3.1",
|
|
53
90
|
"p-defer": "^4.0.0"
|
|
54
91
|
},
|
|
55
|
-
"gitHead": "
|
|
92
|
+
"gitHead": "48de555ca2972a750f2323731d7db3cf63d2839c"
|
|
56
93
|
}
|
package/src/api.js
CHANGED
|
@@ -1,43 +1,23 @@
|
|
|
1
1
|
import { validateMnemonic as isMnemonicValid } from 'bip39'
|
|
2
2
|
|
|
3
3
|
const createApi = ({ ioc, port }) => {
|
|
4
|
-
const
|
|
4
|
+
const apis = ioc.getByType('api')
|
|
5
|
+
const { remoteConfig } = ioc.getByType('module')
|
|
6
|
+
const { feeMonitors, nftsMonitor } = ioc.getByType('monitor')
|
|
5
7
|
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
+
// TODO: do this on 'unload'
|
|
9
|
+
const stop = () => {
|
|
10
|
+
remoteConfig.stop()
|
|
11
|
+
feeMonitors.stop()
|
|
12
|
+
nftsMonitor?.stop()
|
|
13
|
+
}
|
|
8
14
|
|
|
9
15
|
return {
|
|
10
|
-
|
|
11
|
-
exists: () => wallet.exists(),
|
|
12
|
-
load: application.load,
|
|
13
|
-
unload: application.unload,
|
|
14
|
-
create: application.create,
|
|
15
|
-
lock: application.lock,
|
|
16
|
-
unlock: application.unlock,
|
|
17
|
-
import: application.import,
|
|
18
|
-
delete: application.delete,
|
|
19
|
-
getMnemonic: application.getMnemonic,
|
|
20
|
-
setBackedUp: application.setBackedUp,
|
|
21
|
-
changePassphrase: application.changePassphrase,
|
|
22
|
-
restoreFromCurrentPhrase: async ({ passphrase } = {}) => {
|
|
23
|
-
if (!passphrase) passphrase = await passphraseCache.get()
|
|
24
|
-
const mnemonic = await application.getMnemonic({ passphrase })
|
|
25
|
-
|
|
26
|
-
await application.import({ passphrase, mnemonic })
|
|
27
|
-
},
|
|
28
|
-
changeLockTimer: application.changeLockTimer,
|
|
29
|
-
isLocked: () => wallet.isLocked(),
|
|
30
|
-
},
|
|
31
|
-
walletAccounts: {
|
|
32
|
-
create: walletAccounts.create,
|
|
33
|
-
update: walletAccounts.update,
|
|
34
|
-
disable: walletAccounts.disable,
|
|
35
|
-
enable: walletAccounts.enable,
|
|
36
|
-
getEnabled: enabledWalletAccountsAtom.get,
|
|
37
|
-
},
|
|
16
|
+
...Object.assign({}, ...Object.values(apis)),
|
|
38
17
|
isMnemonicValid,
|
|
39
18
|
subscribe: port.subscribe.bind(port),
|
|
40
19
|
unsubscribe: port.unsubscribe.bind(port),
|
|
20
|
+
stop,
|
|
41
21
|
}
|
|
42
22
|
}
|
|
43
23
|
|
package/src/application.js
CHANGED
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
import ExodusModule from '@exodus/module'
|
|
4
4
|
import assert from 'minimalistic-assert'
|
|
5
5
|
|
|
6
|
+
import { LifecycleHook as Hook } from './constants'
|
|
7
|
+
|
|
6
8
|
// Because we are forced to restart wallet after deleting/importing, we need to store certain flags to persist state between executions
|
|
7
9
|
|
|
8
10
|
// Triggers deletetion logic when wallet starts.
|
|
@@ -17,22 +19,7 @@ const IMPORT_FLAG = 'importFlag'
|
|
|
17
19
|
// Set as true on import method is called, and set to false after restore is completed
|
|
18
20
|
const RESTORE_FLAG = 'restoreFlag'
|
|
19
21
|
|
|
20
|
-
const HOOKS = Object.
|
|
21
|
-
lock: 'lock',
|
|
22
|
-
unlock: 'unlock',
|
|
23
|
-
clear: 'clear',
|
|
24
|
-
import: 'import',
|
|
25
|
-
migrate: 'migrate',
|
|
26
|
-
start: 'start',
|
|
27
|
-
load: 'load',
|
|
28
|
-
unload: 'unload',
|
|
29
|
-
create: 'create',
|
|
30
|
-
backup: 'backup',
|
|
31
|
-
restore: 'restore',
|
|
32
|
-
'restore-completed': 'restore-completed',
|
|
33
|
-
'assets-synced': 'assets-synced',
|
|
34
|
-
'change-passphrase': 'change-passphrase',
|
|
35
|
-
})
|
|
22
|
+
const HOOKS = new Set(Object.values(Hook))
|
|
36
23
|
|
|
37
24
|
class Application extends ExodusModule {
|
|
38
25
|
#hooks = {}
|
|
@@ -50,6 +37,7 @@ class Application extends ExodusModule {
|
|
|
50
37
|
this.#storage = unsafeStorage.namespace('flags')
|
|
51
38
|
|
|
52
39
|
this.#applicationStarted = new Promise((resolve) => (this.#resolveStart = resolve))
|
|
40
|
+
this.setMaxListeners(Number.POSITIVE_INFINITY)
|
|
53
41
|
}
|
|
54
42
|
|
|
55
43
|
start = async () => {
|
|
@@ -68,12 +56,26 @@ class Application extends ExodusModule {
|
|
|
68
56
|
const walletExists = await this.#wallet.exists()
|
|
69
57
|
|
|
70
58
|
if (isImporting || !walletExists) {
|
|
71
|
-
await this.fire(
|
|
59
|
+
await this.fire(Hook.Clear)
|
|
72
60
|
}
|
|
73
61
|
|
|
74
|
-
if (isImporting) await this.fire(
|
|
62
|
+
if (isImporting) await this.fire(Hook.Import)
|
|
63
|
+
|
|
64
|
+
const [hasPassphraseSet, isLocked, isBackedUp, isRestoring] = await Promise.all([
|
|
65
|
+
this.#wallet.hasPassphraseSet(),
|
|
66
|
+
this.#wallet.isLocked(),
|
|
67
|
+
this.#wallet.isBackedUp(),
|
|
68
|
+
this.isRestoring(),
|
|
69
|
+
])
|
|
70
|
+
|
|
71
|
+
await this.fire(Hook.Start, {
|
|
72
|
+
walletExists,
|
|
73
|
+
hasPassphraseSet,
|
|
74
|
+
isLocked,
|
|
75
|
+
isBackedUp,
|
|
76
|
+
isRestoring,
|
|
77
|
+
})
|
|
75
78
|
|
|
76
|
-
await this.fire(HOOKS.start)
|
|
77
79
|
await this.#autoUnlock()
|
|
78
80
|
|
|
79
81
|
const locked = await this.#wallet.isLocked()
|
|
@@ -93,7 +95,7 @@ class Application extends ExodusModule {
|
|
|
93
95
|
this.isRestoring(),
|
|
94
96
|
])
|
|
95
97
|
|
|
96
|
-
await this.fire(
|
|
98
|
+
await this.fire(Hook.Load, {
|
|
97
99
|
walletExists,
|
|
98
100
|
hasPassphraseSet,
|
|
99
101
|
isLocked,
|
|
@@ -104,11 +106,11 @@ class Application extends ExodusModule {
|
|
|
104
106
|
unload = async () => {
|
|
105
107
|
await this.#applicationStarted
|
|
106
108
|
await this.#passphraseCache.scheduleClear()
|
|
107
|
-
await this.fire(
|
|
109
|
+
await this.fire(Hook.Unload)
|
|
108
110
|
}
|
|
109
111
|
|
|
110
112
|
hook = (hookName, listener) => {
|
|
111
|
-
assert(HOOKS
|
|
113
|
+
assert(HOOKS.has(hookName), `no such hook: ${hookName}`)
|
|
112
114
|
|
|
113
115
|
if (!this.#hooks[hookName]) {
|
|
114
116
|
this.#hooks[hookName] = []
|
|
@@ -118,13 +120,18 @@ class Application extends ExodusModule {
|
|
|
118
120
|
}
|
|
119
121
|
|
|
120
122
|
fire = async (hookName, params) => {
|
|
121
|
-
assert(HOOKS
|
|
123
|
+
assert(HOOKS.has(hookName), `no such hook: ${hookName}`)
|
|
122
124
|
this._logger.debug('firing hooks', hookName)
|
|
123
125
|
|
|
124
126
|
const hooks = this.#hooks[hookName] || []
|
|
125
127
|
|
|
126
128
|
for (let i = 0; i < hooks.length; i++) {
|
|
127
|
-
|
|
129
|
+
try {
|
|
130
|
+
await hooks[i](params)
|
|
131
|
+
} catch (err) {
|
|
132
|
+
this._logger.error(`application lifecycle hook failed: ${hookName}`, hooks[i], params)
|
|
133
|
+
throw err
|
|
134
|
+
}
|
|
128
135
|
}
|
|
129
136
|
|
|
130
137
|
this.emit(hookName, params)
|
|
@@ -136,7 +143,15 @@ class Application extends ExodusModule {
|
|
|
136
143
|
await this.#applicationStarted
|
|
137
144
|
await this.#wallet.create(opts)
|
|
138
145
|
|
|
139
|
-
await this.
|
|
146
|
+
const isLocked = await this.#wallet.isLocked()
|
|
147
|
+
|
|
148
|
+
await this.fire(Hook.Create, {
|
|
149
|
+
hasPassphraseSet: !!opts?.passphrase,
|
|
150
|
+
isBackedUp: false,
|
|
151
|
+
isLocked,
|
|
152
|
+
isRestoring: false,
|
|
153
|
+
walletExists: true,
|
|
154
|
+
})
|
|
140
155
|
}
|
|
141
156
|
|
|
142
157
|
import = async (opts) => {
|
|
@@ -148,16 +163,16 @@ class Application extends ExodusModule {
|
|
|
148
163
|
|
|
149
164
|
const walletExists = await this.#wallet.exists()
|
|
150
165
|
|
|
151
|
-
const { forceRestart, ...wallet } = opts
|
|
166
|
+
const { forceRestart, forgotPassphrase, ...wallet } = opts
|
|
152
167
|
|
|
153
168
|
await this.#wallet.import(wallet)
|
|
154
169
|
|
|
155
170
|
if (forceRestart || walletExists) {
|
|
156
171
|
await this.#storage.set(IMPORT_FLAG, true)
|
|
157
172
|
|
|
158
|
-
this.
|
|
173
|
+
await this.fire(Hook.Restart, { reason: 'import' })
|
|
159
174
|
} else {
|
|
160
|
-
await this.fire(
|
|
175
|
+
await this.fire(Hook.Import)
|
|
161
176
|
|
|
162
177
|
this._logger.log('wallet imported')
|
|
163
178
|
}
|
|
@@ -167,7 +182,7 @@ class Application extends ExodusModule {
|
|
|
167
182
|
|
|
168
183
|
setBackedUp = async () => {
|
|
169
184
|
await this.#wallet.setBackedUp()
|
|
170
|
-
await this.fire(
|
|
185
|
+
await this.fire(Hook.Backup)
|
|
171
186
|
}
|
|
172
187
|
|
|
173
188
|
lock = async (opts) => {
|
|
@@ -176,7 +191,7 @@ class Application extends ExodusModule {
|
|
|
176
191
|
await this.#applicationStarted
|
|
177
192
|
await this.#wallet.lock(opts)
|
|
178
193
|
await this.#passphraseCache.clear()
|
|
179
|
-
await this.fire(
|
|
194
|
+
await this.fire(Hook.Lock)
|
|
180
195
|
|
|
181
196
|
this._logger.log('locked')
|
|
182
197
|
}
|
|
@@ -185,13 +200,13 @@ class Application extends ExodusModule {
|
|
|
185
200
|
const isRestoring = await this.isRestoring()
|
|
186
201
|
|
|
187
202
|
if (isRestoring) {
|
|
188
|
-
await this.fire(
|
|
203
|
+
await this.fire(Hook.Restore)
|
|
189
204
|
await this.#storage.delete(RESTORE_FLAG)
|
|
190
205
|
await this.setBackedUp()
|
|
191
|
-
await this.fire(
|
|
206
|
+
await this.fire(Hook.RestoreCompleted)
|
|
192
207
|
}
|
|
193
208
|
|
|
194
|
-
this.fire(
|
|
209
|
+
this.fire(Hook.AssetsSynced)
|
|
195
210
|
}
|
|
196
211
|
|
|
197
212
|
#autoUnlock = async () => {
|
|
@@ -204,7 +219,7 @@ class Application extends ExodusModule {
|
|
|
204
219
|
this._logger.log('unlocking with cache')
|
|
205
220
|
|
|
206
221
|
await this.#wallet.unlock({ passphrase })
|
|
207
|
-
await this.fire(
|
|
222
|
+
await this.fire(Hook.Unlock)
|
|
208
223
|
|
|
209
224
|
this.#restoreIfNeeded()
|
|
210
225
|
|
|
@@ -220,8 +235,8 @@ class Application extends ExodusModule {
|
|
|
220
235
|
await this.#applicationStarted
|
|
221
236
|
await this.#wallet.unlock({ passphrase })
|
|
222
237
|
|
|
223
|
-
await this.fire(
|
|
224
|
-
await this.fire(
|
|
238
|
+
await this.fire(Hook.Migrate)
|
|
239
|
+
await this.fire(Hook.Unlock)
|
|
225
240
|
|
|
226
241
|
this.#restoreIfNeeded()
|
|
227
242
|
|
|
@@ -236,14 +251,14 @@ class Application extends ExodusModule {
|
|
|
236
251
|
await this.#applicationStarted
|
|
237
252
|
await this.#wallet.changePassphrase({ currentPassphrase, newPassphrase })
|
|
238
253
|
await this.#passphraseCache.set(newPassphrase)
|
|
239
|
-
await this.fire(
|
|
254
|
+
await this.fire(Hook.ChangePassphrase)
|
|
240
255
|
|
|
241
256
|
this._logger.log('passphrase changed')
|
|
242
257
|
}
|
|
243
258
|
|
|
244
|
-
delete = async () => {
|
|
259
|
+
delete = async ({ forgotPassphrase } = {}) => {
|
|
245
260
|
await this.#storage.set(DELETE_FLAG, true)
|
|
246
|
-
this.
|
|
261
|
+
await this.fire(Hook.Restart, { reason: 'delete', forgotPassphrase })
|
|
247
262
|
}
|
|
248
263
|
|
|
249
264
|
changeLockTimer = async ({ ttl }) => {
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
const emitAtomValue = async (opts) => {
|
|
2
|
+
const { port, atomId, atom } = opts
|
|
3
|
+
const value = 'value' in opts ? opts.value : await atom.get()
|
|
4
|
+
port.emit(atomId, value)
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export const emitFromAtoms = ({ atoms, port }) =>
|
|
8
|
+
Object.entries(atoms).forEach(async ([atomId, atom]) => emitAtomValue({ port, atomId, atom }))
|
|
9
|
+
|
|
10
|
+
const attachAtom = ({ port, application, logger, atom, atomId, lifecycleEvents }) => {
|
|
11
|
+
let loaded = false
|
|
12
|
+
|
|
13
|
+
lifecycleEvents.forEach((event) =>
|
|
14
|
+
application.on(event, async () => {
|
|
15
|
+
loaded = true
|
|
16
|
+
await emitAtomValue({ port, atomId, atom })
|
|
17
|
+
})
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
atom.observe((value) => {
|
|
21
|
+
if (loaded) emitAtomValue({ port, atomId, atom, value })
|
|
22
|
+
})
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const attachAtoms = ({ port, application, logger, atoms, lifecycleEvents = ['start'] }) => {
|
|
26
|
+
for (const [atomId, atom] of Object.entries(atoms)) {
|
|
27
|
+
attachAtom({ port, application, logger, atom, atomId, lifecycleEvents })
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export default attachAtoms
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { combine, compute } from '@exodus/atoms'
|
|
2
|
+
import { uniq } from 'lodash'
|
|
3
|
+
|
|
4
|
+
const getNetworks = (assetNames, assets) =>
|
|
5
|
+
uniq(
|
|
6
|
+
assetNames
|
|
7
|
+
.map((assetName) => assets[assetName]?.baseAsset.name)
|
|
8
|
+
.filter((assetName) => !!assetName && !assets[assetName].isCombined)
|
|
9
|
+
)
|
|
10
|
+
|
|
11
|
+
const createBaseAssetNamesToMonitorAtom = ({
|
|
12
|
+
assetsModule,
|
|
13
|
+
enabledAssetsAtom,
|
|
14
|
+
restoreAtom,
|
|
15
|
+
availableAssetNamesAtom,
|
|
16
|
+
}) => {
|
|
17
|
+
const selector = ({ isRestore, enabledAssets, availableAssetNames }) => {
|
|
18
|
+
const assetNames = isRestore ? availableAssetNames : Object.keys(enabledAssets)
|
|
19
|
+
return getNetworks(assetNames, assetsModule.getAssets())
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return compute({
|
|
23
|
+
atom: combine({
|
|
24
|
+
isRestore: restoreAtom,
|
|
25
|
+
enabledAssets: enabledAssetsAtom,
|
|
26
|
+
availableAssetNames: availableAssetNamesAtom,
|
|
27
|
+
}),
|
|
28
|
+
selector,
|
|
29
|
+
})
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export default {
|
|
33
|
+
id: 'baseAssetNamesToMonitorAtom',
|
|
34
|
+
type: 'atom',
|
|
35
|
+
factory: createBaseAssetNamesToMonitorAtom,
|
|
36
|
+
dependencies: ['assetsModule', 'availableAssetNamesAtom', 'enabledAssetsAtom', 'restoreAtom'],
|
|
37
|
+
}
|
package/src/constants.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export const atomsToAttach = [
|
|
2
|
+
'abTestingAtom',
|
|
3
|
+
'apyRatesAtom',
|
|
4
|
+
'availableAssetNamesAtom',
|
|
5
|
+
'balancesAtom',
|
|
6
|
+
'connectedOriginsAtom',
|
|
7
|
+
'cryptoNewsAtom',
|
|
8
|
+
'currencyAtom',
|
|
9
|
+
'enabledWalletAccountsAtom',
|
|
10
|
+
'featureFlagsAtom',
|
|
11
|
+
'geolocationAtom',
|
|
12
|
+
'kycAtom',
|
|
13
|
+
'languageAtom',
|
|
14
|
+
'nftsConfigAtom',
|
|
15
|
+
'personalNotesAtom',
|
|
16
|
+
'referralsAtom',
|
|
17
|
+
'topMoversAtom',
|
|
18
|
+
'walletAccountsAtom',
|
|
19
|
+
]
|
|
20
|
+
|
|
21
|
+
export const LifecycleHook = Object.freeze({
|
|
22
|
+
Lock: 'lock',
|
|
23
|
+
Unlock: 'unlock',
|
|
24
|
+
Clear: 'clear',
|
|
25
|
+
Import: 'import',
|
|
26
|
+
Migrate: 'migrate',
|
|
27
|
+
Start: 'start',
|
|
28
|
+
Restart: 'restart',
|
|
29
|
+
Load: 'load',
|
|
30
|
+
Unload: 'unload',
|
|
31
|
+
Create: 'create',
|
|
32
|
+
Backup: 'backup',
|
|
33
|
+
Restore: 'restore',
|
|
34
|
+
RestoreCompleted: 'restore-completed',
|
|
35
|
+
AssetsSynced: 'assets-synced',
|
|
36
|
+
ChangePassphrase: 'change-passphrase',
|
|
37
|
+
})
|
|
@@ -1,24 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
walletAccountsAtomDefinition,
|
|
4
|
-
enabledWalletAccountsAtomDefinition,
|
|
5
|
-
} from '@exodus/wallet-accounts/atoms'
|
|
6
|
-
import { withType } from './utils'
|
|
1
|
+
import baseAssetNamesToMonitorAtomDefinition from '../atoms/base-asset-names-to-monitor'
|
|
7
2
|
|
|
8
|
-
const createAtomDependencies = () =>
|
|
9
|
-
[
|
|
10
|
-
{
|
|
11
|
-
definition: {
|
|
12
|
-
id: 'lockedAtom',
|
|
13
|
-
factory: () => createInMemoryAtom({ defaultValue: true }),
|
|
14
|
-
dependencies: [],
|
|
15
|
-
},
|
|
16
|
-
},
|
|
17
|
-
{
|
|
18
|
-
definition: walletAccountsAtomDefinition,
|
|
19
|
-
storage: { namespace: 'walletAccounts' },
|
|
20
|
-
},
|
|
21
|
-
{ definition: enabledWalletAccountsAtomDefinition },
|
|
22
|
-
].map(withType('atom'))
|
|
3
|
+
const createAtomDependencies = () => [{ definition: baseAssetNamesToMonitorAtomDefinition }]
|
|
23
4
|
|
|
24
5
|
export default createAtomDependencies
|
|
@@ -3,10 +3,11 @@
|
|
|
3
3
|
|
|
4
4
|
import assert from 'minimalistic-assert'
|
|
5
5
|
|
|
6
|
-
import createConfigDependencies from './configs'
|
|
7
6
|
import createAdapterDependencies from './adapters'
|
|
8
7
|
import createAtomDependencies from './atoms'
|
|
8
|
+
import createConfigDependencies from './configs'
|
|
9
9
|
import createModuleDependencies from './modules'
|
|
10
|
+
import createPluginDependencies from './plugins'
|
|
10
11
|
import { wrapConstant } from './utils'
|
|
11
12
|
|
|
12
13
|
const adapterKeys = [
|
|
@@ -16,6 +17,9 @@ const adapterKeys = [
|
|
|
16
17
|
'legacyPrivToPub',
|
|
17
18
|
'seedStorage',
|
|
18
19
|
'unsafeStorage',
|
|
20
|
+
'fusion',
|
|
21
|
+
'fetch',
|
|
22
|
+
'freeze',
|
|
19
23
|
]
|
|
20
24
|
|
|
21
25
|
const createDependencies = ({ adapters, config }) => {
|
|
@@ -33,11 +37,14 @@ const createDependencies = ({ adapters, config }) => {
|
|
|
33
37
|
|
|
34
38
|
const adaptersTree = createAdapterDependencies({ adapters, config })
|
|
35
39
|
|
|
40
|
+
const plugins = createPluginDependencies()
|
|
41
|
+
|
|
36
42
|
return []
|
|
37
43
|
.concat(adaptersTree)
|
|
38
44
|
.concat(configs)
|
|
39
45
|
.concat(modules)
|
|
40
46
|
.concat(atoms)
|
|
47
|
+
.concat(plugins)
|
|
41
48
|
.concat(wrapConstant({ id: 'logger', type: 'module', value: logger }))
|
|
42
49
|
}
|
|
43
50
|
|
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
import { createKeychain } from '@exodus/keychain'
|
|
2
|
-
import walletDefinition from '@exodus/wallet/module'
|
|
3
|
-
import walletAccountsDefinition from '@exodus/wallet-accounts/module'
|
|
4
1
|
import createKeyIdentifierProvider from '@exodus/key-identifier-provider'
|
|
5
2
|
import walletCompatibilityModesDefinition from '@exodus/wallet-compatibility-modes/module'
|
|
6
3
|
|
|
7
4
|
import createApplication from '../application'
|
|
8
|
-
import { withType } from './utils'
|
|
9
5
|
import unlockEncryptedStorageDefinition from '../unlock-encrypted-storage'
|
|
6
|
+
import { withType } from './utils'
|
|
10
7
|
|
|
11
|
-
const createModuleDependencies = () =>
|
|
8
|
+
const createModuleDependencies = ({ config }) =>
|
|
12
9
|
[
|
|
13
10
|
{
|
|
14
11
|
definition: {
|
|
@@ -24,21 +21,10 @@ const createModuleDependencies = () =>
|
|
|
24
21
|
dependencies: [],
|
|
25
22
|
},
|
|
26
23
|
},
|
|
27
|
-
{
|
|
28
|
-
definition: {
|
|
29
|
-
id: 'keychain',
|
|
30
|
-
factory: createKeychain,
|
|
31
|
-
dependencies: ['legacyPrivToPub'],
|
|
32
|
-
},
|
|
33
|
-
},
|
|
34
|
-
{
|
|
35
|
-
definition: walletDefinition,
|
|
36
|
-
},
|
|
37
24
|
{
|
|
38
25
|
definition: walletCompatibilityModesDefinition,
|
|
39
26
|
},
|
|
40
27
|
{ definition: unlockEncryptedStorageDefinition },
|
|
41
|
-
{ definition: walletAccountsDefinition },
|
|
42
28
|
].map(withType('module'))
|
|
43
29
|
|
|
44
30
|
export default createModuleDependencies
|
|
@@ -2,10 +2,6 @@ export const wrapConstant = ({ id, type, value }) => ({
|
|
|
2
2
|
definition: { id, type, factory: () => value },
|
|
3
3
|
})
|
|
4
4
|
|
|
5
|
-
export const insertIf = (module, enabled) => {
|
|
6
|
-
return enabled ? [module] : []
|
|
7
|
-
}
|
|
8
|
-
|
|
9
5
|
export const withType =
|
|
10
6
|
(type) =>
|
|
11
7
|
({ definition, ...rest }) => ({
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { availableAssetNamesAtomDefinition } from '@exodus/available-assets/atoms'
|
|
2
|
+
import availableAssetsModuleDefinition from '@exodus/available-assets/module'
|
|
3
|
+
|
|
4
|
+
const availableAssets = () => ({
|
|
5
|
+
id: 'availableAssets',
|
|
6
|
+
definitions: [
|
|
7
|
+
{
|
|
8
|
+
definition: { type: 'module', ...availableAssetsModuleDefinition },
|
|
9
|
+
writesAtoms: ['availableAssetNamesAtom'],
|
|
10
|
+
},
|
|
11
|
+
{ definition: availableAssetNamesAtomDefinition },
|
|
12
|
+
],
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
export default availableAssets
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { balancesAtomDefinition } from '@exodus/balances/atoms'
|
|
2
|
+
import balancesDefinition from '@exodus/balances/module'
|
|
3
|
+
|
|
4
|
+
const balances = () => {
|
|
5
|
+
return {
|
|
6
|
+
id: 'balances',
|
|
7
|
+
definitions: [
|
|
8
|
+
{ definition: balancesDefinition, writesAtoms: ['balancesAtom'] },
|
|
9
|
+
{ definition: balancesAtomDefinition },
|
|
10
|
+
],
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export default balances
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
const createBlockchainMetadataApi = ({ blockchainMetadata }) => ({
|
|
2
|
+
blockchainMetadata: {
|
|
3
|
+
getTxLog: blockchainMetadata.getTxLog,
|
|
4
|
+
getLoadedTxLogs: blockchainMetadata.getLoadedTxLogs,
|
|
5
|
+
updateTxs: blockchainMetadata.updateTxs,
|
|
6
|
+
overwriteTxs: blockchainMetadata.overwriteTxs,
|
|
7
|
+
clearTxs: blockchainMetadata.clearTxs,
|
|
8
|
+
removeTxs: blockchainMetadata.removeTxs,
|
|
9
|
+
getAccountState: blockchainMetadata.getAccountState,
|
|
10
|
+
getLoadedAccountStates: blockchainMetadata.getLoadedAccountStates,
|
|
11
|
+
updateAccountState: blockchainMetadata.updateAccountState,
|
|
12
|
+
removeAccountState: blockchainMetadata.removeAccountState,
|
|
13
|
+
batch: blockchainMetadata.batch,
|
|
14
|
+
},
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
export default {
|
|
18
|
+
id: 'createBlockchainMetadataApi',
|
|
19
|
+
type: 'api',
|
|
20
|
+
factory: createBlockchainMetadataApi,
|
|
21
|
+
dependencies: ['blockchainMetadata'],
|
|
22
|
+
}
|