@exodus/headless 2.0.0-alpha.48 → 2.0.0-alpha.5
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 +0 -323
- package/README.md +4 -133
- package/package.json +14 -53
- package/src/api.js +21 -22
- package/src/application.js +34 -44
- package/src/dependencies/atoms.js +4 -47
- package/src/dependencies/index.js +1 -8
- package/src/dependencies/modules.js +12 -18
- package/src/index.js +6 -74
- package/src/ioc.js +7 -40
- package/src/unlock-encrypted-storage.js +1 -1
- package/src/atoms/attach.js +0 -31
- package/src/atoms/base-asset-names-to-monitor.js +0 -36
- package/src/atoms/non-dust-balance-asset-names-atom.js +0 -10
- package/src/constants.js +0 -36
- package/src/dependencies/plugins.js +0 -7
- package/src/modules/ab-testing/api.js +0 -13
- package/src/modules/ab-testing/index.js +0 -26
- package/src/modules/ab-testing/plugin.js +0 -21
- package/src/modules/address-provider/api.js +0 -14
- package/src/modules/address-provider/index.js +0 -15
- package/src/modules/apy-rates/index.js +0 -20
- package/src/modules/apy-rates/plugin.js +0 -14
- package/src/modules/blockchain-metadata/api.js +0 -22
- package/src/modules/blockchain-metadata/index.js +0 -20
- package/src/modules/blockchain-metadata/plugin.js +0 -30
- package/src/modules/blockchain-metadata/utils.js +0 -11
- package/src/modules/connected-origins/api.js +0 -23
- package/src/modules/connected-origins/index.js +0 -31
- package/src/modules/connected-origins/plugin.js +0 -18
- package/src/modules/crypto-news/index.js +0 -20
- package/src/modules/crypto-news/plugin.js +0 -17
- package/src/modules/feature-flags/index.js +0 -35
- package/src/modules/feature-flags/plugin.js +0 -18
- package/src/modules/fees/index.js +0 -16
- package/src/modules/fees/plugin.js +0 -17
- package/src/modules/geolocation/index.js +0 -20
- package/src/modules/geolocation/plugin.js +0 -14
- package/src/modules/kyc/api.js +0 -14
- package/src/modules/kyc/index.js +0 -19
- package/src/modules/kyc/plugin.js +0 -21
- package/src/modules/locale/api.js +0 -13
- package/src/modules/locale/index.js +0 -50
- package/src/modules/locale/plugin.js +0 -14
- package/src/modules/market-history/index.js +0 -66
- package/src/modules/market-history/plugin.js +0 -21
- package/src/modules/nfts/api.js +0 -13
- package/src/modules/nfts/index.js +0 -33
- package/src/modules/nfts/plugin.js +0 -23
- package/src/modules/personal-notes/api.js +0 -12
- package/src/modules/personal-notes/index.js +0 -31
- package/src/modules/personal-notes/plugin.js +0 -15
- package/src/modules/rates/api.js +0 -12
- package/src/modules/rates/index.js +0 -22
- package/src/modules/rates/plugin.js +0 -17
- package/src/modules/referrals/api.js +0 -13
- package/src/modules/referrals/index.js +0 -28
- package/src/modules/referrals/plugin.js +0 -21
- package/src/modules/remote-config/api.js +0 -13
- package/src/modules/remote-config/index.js +0 -28
- package/src/modules/remote-config/plugin.js +0 -20
- package/src/modules/top-movers/index.js +0 -23
- package/src/modules/top-movers/plugin.js +0 -17
- package/src/modules/wallet/api.js +0 -34
- package/src/modules/wallet/index.js +0 -24
- package/src/modules/wallet/locked-atom.js +0 -10
- package/src/modules/wallet/restore-atom.js +0 -10
- package/src/modules/wallet/restore-plugin.js +0 -17
- package/src/modules/wallet-accounts/api.js +0 -16
- package/src/modules/wallet-accounts/index.js +0 -29
- package/src/modules/wallet-accounts/plugin.js +0 -18
- package/src/plugins/attach.js +0 -25
- package/src/plugins/index.js +0 -5
- package/src/plugins/log-lifecycle.js +0 -25
package/src/api.js
CHANGED
|
@@ -1,36 +1,35 @@
|
|
|
1
1
|
import { validateMnemonic as isMnemonicValid } from 'bip39'
|
|
2
2
|
|
|
3
3
|
const createApi = ({ ioc, port }) => {
|
|
4
|
-
const
|
|
4
|
+
const { passphraseCache } = ioc.getByType('adapter')
|
|
5
5
|
|
|
6
|
-
const {
|
|
7
|
-
|
|
8
|
-
const { enabledAssets, remoteConfig } = ioc.getByType('module')
|
|
9
|
-
|
|
10
|
-
const { feeMonitors, nftsMonitor } = ioc.getByType('monitor')
|
|
11
|
-
|
|
12
|
-
// TODO: do this on 'unload'
|
|
13
|
-
const stop = () => {
|
|
14
|
-
remoteConfig.stop()
|
|
15
|
-
feeMonitors.stop()
|
|
16
|
-
nftsMonitor?.stop()
|
|
17
|
-
}
|
|
6
|
+
const { application, wallet } = ioc.getByType('module')
|
|
18
7
|
|
|
19
8
|
return {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
9
|
+
wallet: {
|
|
10
|
+
exists: () => wallet.exists(),
|
|
11
|
+
load: application.load,
|
|
12
|
+
unload: application.unload,
|
|
13
|
+
create: application.create,
|
|
14
|
+
lock: application.lock,
|
|
15
|
+
unlock: application.unlock,
|
|
16
|
+
import: application.import,
|
|
17
|
+
delete: application.delete,
|
|
18
|
+
getMnemonic: application.getMnemonic,
|
|
19
|
+
setBackedUp: application.setBackedUp,
|
|
20
|
+
changePassphrase: application.changePassphrase,
|
|
21
|
+
restoreFromCurrentPhrase: async ({ passphrase } = {}) => {
|
|
22
|
+
if (!passphrase) passphrase = await passphraseCache.get()
|
|
23
|
+
const mnemonic = await application.getMnemonic({ passphrase })
|
|
24
|
+
|
|
25
|
+
await application.import({ passphrase, mnemonic })
|
|
28
26
|
},
|
|
27
|
+
changeLockTimer: application.changeLockTimer,
|
|
28
|
+
isLocked: () => wallet.isLocked(),
|
|
29
29
|
},
|
|
30
30
|
isMnemonicValid,
|
|
31
31
|
subscribe: port.subscribe.bind(port),
|
|
32
32
|
unsubscribe: port.unsubscribe.bind(port),
|
|
33
|
-
stop,
|
|
34
33
|
}
|
|
35
34
|
}
|
|
36
35
|
|
package/src/application.js
CHANGED
|
@@ -3,8 +3,6 @@
|
|
|
3
3
|
import ExodusModule from '@exodus/module'
|
|
4
4
|
import assert from 'minimalistic-assert'
|
|
5
5
|
|
|
6
|
-
import { LifecycleHook as Hook } from './constants'
|
|
7
|
-
|
|
8
6
|
// Because we are forced to restart wallet after deleting/importing, we need to store certain flags to persist state between executions
|
|
9
7
|
|
|
10
8
|
// Triggers deletetion logic when wallet starts.
|
|
@@ -19,7 +17,22 @@ const IMPORT_FLAG = 'importFlag'
|
|
|
19
17
|
// Set as true on import method is called, and set to false after restore is completed
|
|
20
18
|
const RESTORE_FLAG = 'restoreFlag'
|
|
21
19
|
|
|
22
|
-
const HOOKS =
|
|
20
|
+
const HOOKS = Object.freeze({
|
|
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
|
+
})
|
|
23
36
|
|
|
24
37
|
class Application extends ExodusModule {
|
|
25
38
|
#hooks = {}
|
|
@@ -37,7 +50,6 @@ class Application extends ExodusModule {
|
|
|
37
50
|
this.#storage = unsafeStorage.namespace('flags')
|
|
38
51
|
|
|
39
52
|
this.#applicationStarted = new Promise((resolve) => (this.#resolveStart = resolve))
|
|
40
|
-
this.setMaxListeners(Number.POSITIVE_INFINITY)
|
|
41
53
|
}
|
|
42
54
|
|
|
43
55
|
start = async () => {
|
|
@@ -56,26 +68,12 @@ class Application extends ExodusModule {
|
|
|
56
68
|
const walletExists = await this.#wallet.exists()
|
|
57
69
|
|
|
58
70
|
if (isImporting || !walletExists) {
|
|
59
|
-
await this.fire(
|
|
71
|
+
await this.fire(HOOKS.clear)
|
|
60
72
|
}
|
|
61
73
|
|
|
62
|
-
if (isImporting) await this.fire(
|
|
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
|
-
})
|
|
74
|
+
if (isImporting) await this.fire(HOOKS.import)
|
|
78
75
|
|
|
76
|
+
await this.fire(HOOKS.start)
|
|
79
77
|
await this.#autoUnlock()
|
|
80
78
|
|
|
81
79
|
const locked = await this.#wallet.isLocked()
|
|
@@ -95,7 +93,7 @@ class Application extends ExodusModule {
|
|
|
95
93
|
this.isRestoring(),
|
|
96
94
|
])
|
|
97
95
|
|
|
98
|
-
await this.fire(
|
|
96
|
+
await this.fire(HOOKS.load, {
|
|
99
97
|
walletExists,
|
|
100
98
|
hasPassphraseSet,
|
|
101
99
|
isLocked,
|
|
@@ -106,11 +104,11 @@ class Application extends ExodusModule {
|
|
|
106
104
|
unload = async () => {
|
|
107
105
|
await this.#applicationStarted
|
|
108
106
|
await this.#passphraseCache.scheduleClear()
|
|
109
|
-
await this.fire(
|
|
107
|
+
await this.fire(HOOKS.unload)
|
|
110
108
|
}
|
|
111
109
|
|
|
112
110
|
hook = (hookName, listener) => {
|
|
113
|
-
assert(HOOKS
|
|
111
|
+
assert(HOOKS[hookName], `no such hook: ${hookName}`)
|
|
114
112
|
|
|
115
113
|
if (!this.#hooks[hookName]) {
|
|
116
114
|
this.#hooks[hookName] = []
|
|
@@ -120,7 +118,7 @@ class Application extends ExodusModule {
|
|
|
120
118
|
}
|
|
121
119
|
|
|
122
120
|
fire = async (hookName, params) => {
|
|
123
|
-
assert(HOOKS
|
|
121
|
+
assert(HOOKS[hookName], `no such hook: ${hookName}`)
|
|
124
122
|
this._logger.debug('firing hooks', hookName)
|
|
125
123
|
|
|
126
124
|
const hooks = this.#hooks[hookName] || []
|
|
@@ -138,15 +136,7 @@ class Application extends ExodusModule {
|
|
|
138
136
|
await this.#applicationStarted
|
|
139
137
|
await this.#wallet.create(opts)
|
|
140
138
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
await this.fire(Hook.Create, {
|
|
144
|
-
hasPassphraseSet: !!opts?.passphrase,
|
|
145
|
-
isBackedUp: false,
|
|
146
|
-
isLocked,
|
|
147
|
-
isRestoring: false,
|
|
148
|
-
walletExists: true,
|
|
149
|
-
})
|
|
139
|
+
await this.fire(HOOKS.create, { hasPassphraseSet: !!opts?.passphrase })
|
|
150
140
|
}
|
|
151
141
|
|
|
152
142
|
import = async (opts) => {
|
|
@@ -167,7 +157,7 @@ class Application extends ExodusModule {
|
|
|
167
157
|
|
|
168
158
|
this.emit('restart', { reason: 'import' })
|
|
169
159
|
} else {
|
|
170
|
-
await this.fire(
|
|
160
|
+
await this.fire(HOOKS.import)
|
|
171
161
|
|
|
172
162
|
this._logger.log('wallet imported')
|
|
173
163
|
}
|
|
@@ -177,7 +167,7 @@ class Application extends ExodusModule {
|
|
|
177
167
|
|
|
178
168
|
setBackedUp = async () => {
|
|
179
169
|
await this.#wallet.setBackedUp()
|
|
180
|
-
await this.fire(
|
|
170
|
+
await this.fire(HOOKS.backup)
|
|
181
171
|
}
|
|
182
172
|
|
|
183
173
|
lock = async (opts) => {
|
|
@@ -186,7 +176,7 @@ class Application extends ExodusModule {
|
|
|
186
176
|
await this.#applicationStarted
|
|
187
177
|
await this.#wallet.lock(opts)
|
|
188
178
|
await this.#passphraseCache.clear()
|
|
189
|
-
await this.fire(
|
|
179
|
+
await this.fire(HOOKS.lock)
|
|
190
180
|
|
|
191
181
|
this._logger.log('locked')
|
|
192
182
|
}
|
|
@@ -195,13 +185,13 @@ class Application extends ExodusModule {
|
|
|
195
185
|
const isRestoring = await this.isRestoring()
|
|
196
186
|
|
|
197
187
|
if (isRestoring) {
|
|
198
|
-
await this.fire(
|
|
188
|
+
await this.fire(HOOKS.restore)
|
|
199
189
|
await this.#storage.delete(RESTORE_FLAG)
|
|
200
190
|
await this.setBackedUp()
|
|
201
|
-
await this.fire(
|
|
191
|
+
await this.fire(HOOKS['restore-completed'])
|
|
202
192
|
}
|
|
203
193
|
|
|
204
|
-
this.fire(
|
|
194
|
+
this.fire(HOOKS['assets-synced'])
|
|
205
195
|
}
|
|
206
196
|
|
|
207
197
|
#autoUnlock = async () => {
|
|
@@ -214,7 +204,7 @@ class Application extends ExodusModule {
|
|
|
214
204
|
this._logger.log('unlocking with cache')
|
|
215
205
|
|
|
216
206
|
await this.#wallet.unlock({ passphrase })
|
|
217
|
-
await this.fire(
|
|
207
|
+
await this.fire(HOOKS.unlock)
|
|
218
208
|
|
|
219
209
|
this.#restoreIfNeeded()
|
|
220
210
|
|
|
@@ -230,8 +220,8 @@ class Application extends ExodusModule {
|
|
|
230
220
|
await this.#applicationStarted
|
|
231
221
|
await this.#wallet.unlock({ passphrase })
|
|
232
222
|
|
|
233
|
-
await this.fire(
|
|
234
|
-
await this.fire(
|
|
223
|
+
await this.fire(HOOKS.migrate)
|
|
224
|
+
await this.fire(HOOKS.unlock)
|
|
235
225
|
|
|
236
226
|
this.#restoreIfNeeded()
|
|
237
227
|
|
|
@@ -246,7 +236,7 @@ class Application extends ExodusModule {
|
|
|
246
236
|
await this.#applicationStarted
|
|
247
237
|
await this.#wallet.changePassphrase({ currentPassphrase, newPassphrase })
|
|
248
238
|
await this.#passphraseCache.set(newPassphrase)
|
|
249
|
-
await this.fire(
|
|
239
|
+
await this.fire(HOOKS['change-passphrase'])
|
|
250
240
|
|
|
251
241
|
this._logger.log('passphrase changed')
|
|
252
242
|
}
|
|
@@ -1,58 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { availableAssetNamesAtomDefinition } from '@exodus/available-assets/atoms'
|
|
3
|
-
import { balancesAtomDefinition } from '@exodus/balances/atoms'
|
|
4
|
-
import {
|
|
5
|
-
enabledAndDisabledAssetsAtomDefinition,
|
|
6
|
-
enabledAssetsAtomDefinition,
|
|
7
|
-
} from '@exodus/enabled-assets/atoms'
|
|
8
|
-
|
|
9
|
-
import baseAssetNamesToMonitorAtomDefinition from '../atoms/base-asset-names-to-monitor'
|
|
10
|
-
import nonDustBalanceAssetNamesAtomDefinition from '../atoms/non-dust-balance-asset-names-atom'
|
|
1
|
+
import { createInMemoryAtom } from '@exodus/atoms'
|
|
11
2
|
import { withType } from './utils'
|
|
12
3
|
|
|
13
4
|
const createAtomDependencies = () =>
|
|
14
5
|
[
|
|
15
|
-
{
|
|
16
|
-
definition: enabledAndDisabledAssetsAtomDefinition,
|
|
17
|
-
storage: { namespace: 'enabledAssets' },
|
|
18
|
-
},
|
|
19
|
-
{ definition: enabledAssetsAtomDefinition },
|
|
20
|
-
{ definition: availableAssetNamesAtomDefinition },
|
|
21
|
-
{
|
|
22
|
-
definition: nonDustBalanceAssetNamesAtomDefinition,
|
|
23
|
-
},
|
|
24
|
-
{
|
|
25
|
-
definition: {
|
|
26
|
-
id: 'pricingServerUrlAtom',
|
|
27
|
-
factory: ({ config, remoteConfig }) =>
|
|
28
|
-
createRemoteConfigAtomFactory({ remoteConfig })({
|
|
29
|
-
path: config.pricingServerPath,
|
|
30
|
-
defaultValue: config.defaultPricingServerUrl,
|
|
31
|
-
}),
|
|
32
|
-
dependencies: ['config', 'remoteConfig'],
|
|
33
|
-
},
|
|
34
|
-
},
|
|
35
6
|
{
|
|
36
7
|
definition: {
|
|
37
|
-
id: '
|
|
38
|
-
factory: ({
|
|
39
|
-
|
|
40
|
-
key: 'mockConfig',
|
|
41
|
-
defaultValue: {},
|
|
42
|
-
isSoleWriter: true,
|
|
43
|
-
}),
|
|
44
|
-
dependencies: ['storage'],
|
|
8
|
+
id: 'lockedAtom',
|
|
9
|
+
factory: () => createInMemoryAtom({ defaultValue: true }),
|
|
10
|
+
dependencies: [],
|
|
45
11
|
},
|
|
46
|
-
storage: { namespace: 'mockConfig' },
|
|
47
|
-
aliases: [
|
|
48
|
-
{
|
|
49
|
-
implementationId: 'unsafeStorage',
|
|
50
|
-
interfaceId: 'storage',
|
|
51
|
-
},
|
|
52
|
-
],
|
|
53
12
|
},
|
|
54
|
-
{ definition: balancesAtomDefinition },
|
|
55
|
-
{ definition: baseAssetNamesToMonitorAtomDefinition },
|
|
56
13
|
].map(withType('atom'))
|
|
57
14
|
|
|
58
15
|
export default createAtomDependencies
|
|
@@ -3,11 +3,10 @@
|
|
|
3
3
|
|
|
4
4
|
import assert from 'minimalistic-assert'
|
|
5
5
|
|
|
6
|
+
import createConfigDependencies from './configs'
|
|
6
7
|
import createAdapterDependencies from './adapters'
|
|
7
8
|
import createAtomDependencies from './atoms'
|
|
8
|
-
import createConfigDependencies from './configs'
|
|
9
9
|
import createModuleDependencies from './modules'
|
|
10
|
-
import createPluginDependencies from './plugins'
|
|
11
10
|
import { wrapConstant } from './utils'
|
|
12
11
|
|
|
13
12
|
const adapterKeys = [
|
|
@@ -17,9 +16,6 @@ const adapterKeys = [
|
|
|
17
16
|
'legacyPrivToPub',
|
|
18
17
|
'seedStorage',
|
|
19
18
|
'unsafeStorage',
|
|
20
|
-
'fusion',
|
|
21
|
-
'fetch',
|
|
22
|
-
'freeze',
|
|
23
19
|
]
|
|
24
20
|
|
|
25
21
|
const createDependencies = ({ adapters, config }) => {
|
|
@@ -37,14 +33,11 @@ const createDependencies = ({ adapters, config }) => {
|
|
|
37
33
|
|
|
38
34
|
const adaptersTree = createAdapterDependencies({ adapters, config })
|
|
39
35
|
|
|
40
|
-
const plugins = createPluginDependencies()
|
|
41
|
-
|
|
42
36
|
return []
|
|
43
37
|
.concat(adaptersTree)
|
|
44
38
|
.concat(configs)
|
|
45
39
|
.concat(modules)
|
|
46
40
|
.concat(atoms)
|
|
47
|
-
.concat(plugins)
|
|
48
41
|
.concat(wrapConstant({ id: 'logger', type: 'module', value: logger }))
|
|
49
42
|
}
|
|
50
43
|
|
|
@@ -1,16 +1,13 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import enabledAssetsModuleDefinition from '@exodus/enabled-assets/module'
|
|
4
|
-
import createExodusPricingClient from '@exodus/exodus-pricing-client'
|
|
1
|
+
import { createKeychain } from '@exodus/keychain'
|
|
2
|
+
import walletDefinition from '@exodus/wallet/module'
|
|
5
3
|
import createKeyIdentifierProvider from '@exodus/key-identifier-provider'
|
|
6
|
-
import keychainDefinition from '@exodus/keychain/module'
|
|
7
4
|
import walletCompatibilityModesDefinition from '@exodus/wallet-compatibility-modes/module'
|
|
8
5
|
|
|
9
6
|
import createApplication from '../application'
|
|
10
|
-
import unlockEncryptedStorageDefinition from '../unlock-encrypted-storage'
|
|
11
7
|
import { withType } from './utils'
|
|
8
|
+
import unlockEncryptedStorageDefinition from '../unlock-encrypted-storage'
|
|
12
9
|
|
|
13
|
-
const createModuleDependencies = (
|
|
10
|
+
const createModuleDependencies = () =>
|
|
14
11
|
[
|
|
15
12
|
{
|
|
16
13
|
definition: {
|
|
@@ -27,22 +24,19 @@ const createModuleDependencies = ({ config }) =>
|
|
|
27
24
|
},
|
|
28
25
|
},
|
|
29
26
|
{
|
|
30
|
-
definition:
|
|
27
|
+
definition: {
|
|
28
|
+
id: 'keychain',
|
|
29
|
+
factory: createKeychain,
|
|
30
|
+
dependencies: ['legacyPrivToPub'],
|
|
31
|
+
},
|
|
31
32
|
},
|
|
32
33
|
{
|
|
33
|
-
definition:
|
|
34
|
+
definition: walletDefinition,
|
|
34
35
|
},
|
|
35
|
-
{ definition: unlockEncryptedStorageDefinition },
|
|
36
|
-
{ definition: enabledAssetsModuleDefinition, writesAtoms: ['enabledAndDisabledAssetsAtom'] },
|
|
37
|
-
{ definition: availableAssetsModuleDefinition, writesAtoms: ['availableAssetNamesAtom'] },
|
|
38
36
|
{
|
|
39
|
-
definition:
|
|
40
|
-
id: 'pricingClient',
|
|
41
|
-
factory: createExodusPricingClient,
|
|
42
|
-
dependencies: ['fetch', 'pricingServerUrlAtom'],
|
|
43
|
-
},
|
|
37
|
+
definition: walletCompatibilityModesDefinition,
|
|
44
38
|
},
|
|
45
|
-
{ definition:
|
|
39
|
+
{ definition: unlockEncryptedStorageDefinition },
|
|
46
40
|
].map(withType('module'))
|
|
47
41
|
|
|
48
42
|
export default createModuleDependencies
|
package/src/index.js
CHANGED
|
@@ -1,74 +1,24 @@
|
|
|
1
|
-
import { pick } from '@exodus/basic-utils'
|
|
2
|
-
|
|
3
|
-
import createApi from './api'
|
|
4
|
-
import attachAtoms from './atoms/attach'
|
|
5
|
-
import { atomsToAttach } from './constants'
|
|
6
1
|
import createIOC from './ioc'
|
|
7
|
-
import
|
|
8
|
-
import addressProvider from './modules/address-provider'
|
|
9
|
-
import apyRates from './modules/apy-rates'
|
|
10
|
-
import blockchainMetadata from './modules/blockchain-metadata'
|
|
11
|
-
import connectedOrigins from './modules/connected-origins'
|
|
12
|
-
import cryptoNews from './modules/crypto-news'
|
|
13
|
-
import featureFlags from './modules/feature-flags'
|
|
14
|
-
import fees from './modules/fees'
|
|
15
|
-
import geolocation from './modules/geolocation'
|
|
16
|
-
import kyc from './modules/kyc'
|
|
17
|
-
import locale from './modules/locale'
|
|
18
|
-
import marketHistory from './modules/market-history'
|
|
19
|
-
import nfts from './modules/nfts'
|
|
20
|
-
import personalNotes from './modules/personal-notes'
|
|
21
|
-
import rates from './modules/rates'
|
|
22
|
-
import referrals from './modules/referrals'
|
|
23
|
-
import remoteConfig from './modules/remote-config'
|
|
24
|
-
import topMovers from './modules/top-movers'
|
|
25
|
-
import wallet from './modules/wallet'
|
|
26
|
-
import walletAccounts from './modules/wallet-accounts'
|
|
27
|
-
import attachPlugins from './plugins/attach'
|
|
2
|
+
import createApi from './api'
|
|
28
3
|
|
|
29
4
|
const createExodus = ({ adapters, config, port }) => {
|
|
30
5
|
const ioc = createIOC({ adapters, config })
|
|
31
|
-
const { headless: headlessConfig, topMoversMonitor } = config
|
|
32
|
-
|
|
33
|
-
ioc.use(wallet())
|
|
34
|
-
ioc.use(walletAccounts())
|
|
35
|
-
ioc.use(blockchainMetadata())
|
|
36
|
-
ioc.use(remoteConfig())
|
|
37
|
-
ioc.use(geolocation())
|
|
38
|
-
ioc.use(marketHistory())
|
|
39
|
-
ioc.use(fees())
|
|
40
|
-
ioc.use(rates())
|
|
41
|
-
ioc.use(apyRates())
|
|
42
|
-
ioc.use(featureFlags())
|
|
43
|
-
ioc.use(locale())
|
|
44
|
-
ioc.use(nfts())
|
|
45
|
-
ioc.use(kyc())
|
|
46
|
-
ioc.use(referrals())
|
|
47
|
-
ioc.use(connectedOrigins())
|
|
48
|
-
ioc.use(abTesting())
|
|
49
|
-
ioc.use(personalNotes())
|
|
50
|
-
ioc.use(cryptoNews())
|
|
51
|
-
ioc.use(topMovers({ config: topMoversMonitor }))
|
|
52
|
-
ioc.use(addressProvider({ config: config.addressProvider }))
|
|
53
|
-
|
|
54
|
-
ioc.register({ definition: { id: 'port', type: 'port', factory: () => port } })
|
|
55
6
|
|
|
56
7
|
const resolve = () => {
|
|
57
8
|
ioc.resolve()
|
|
58
9
|
|
|
59
10
|
const { assetsModule, storage } = ioc.getByType('adapter')
|
|
60
11
|
|
|
61
|
-
const { application,
|
|
12
|
+
const { application, unlockEncryptedStorage } = ioc.getByType('module')
|
|
62
13
|
|
|
63
|
-
application.hook('start', (
|
|
64
|
-
port.emit('start'
|
|
14
|
+
application.hook('start', () => {
|
|
15
|
+
port.emit('start')
|
|
65
16
|
})
|
|
66
17
|
|
|
67
18
|
application.hook('unlock', async () => {
|
|
68
19
|
if (typeof storage.unlock === 'function') unlockEncryptedStorage(storage)
|
|
69
20
|
|
|
70
21
|
await assetsModule.load()
|
|
71
|
-
await enabledAssets.load()
|
|
72
22
|
})
|
|
73
23
|
|
|
74
24
|
application.on('unlock', () => {
|
|
@@ -76,14 +26,8 @@ const createExodus = ({ adapters, config, port }) => {
|
|
|
76
26
|
})
|
|
77
27
|
|
|
78
28
|
application.hook('clear', async () => {
|
|
79
|
-
await Promise.all([
|
|
80
|
-
//
|
|
81
|
-
assetsModule.clear(),
|
|
82
|
-
enabledAssets.clear(),
|
|
83
|
-
])
|
|
84
|
-
})
|
|
29
|
+
await Promise.all([assetsModule.clear()])
|
|
85
30
|
|
|
86
|
-
application.on('clear', () => {
|
|
87
31
|
port.emit('clear')
|
|
88
32
|
})
|
|
89
33
|
|
|
@@ -91,19 +35,7 @@ const createExodus = ({ adapters, config, port }) => {
|
|
|
91
35
|
port.emit('restart', payload)
|
|
92
36
|
})
|
|
93
37
|
|
|
94
|
-
|
|
95
|
-
port,
|
|
96
|
-
application,
|
|
97
|
-
logger: ioc.get('createLogger')('attachAtoms'),
|
|
98
|
-
atoms: pick(ioc.getByType('atom'), atomsToAttach),
|
|
99
|
-
lifecycleEvents: headlessConfig?.attachAtomsLifecycleEvents,
|
|
100
|
-
})
|
|
101
|
-
|
|
102
|
-
attachPlugins({
|
|
103
|
-
application,
|
|
104
|
-
plugins: ioc.getByType('plugin'),
|
|
105
|
-
logger: ioc.get('createLogger')('attachPlugins'),
|
|
106
|
-
})
|
|
38
|
+
application.start()
|
|
107
39
|
|
|
108
40
|
return createApi({ ioc, port })
|
|
109
41
|
}
|
package/src/ioc.js
CHANGED
|
@@ -1,56 +1,23 @@
|
|
|
1
1
|
import createIocContainer from '@exodus/dependency-injection'
|
|
2
2
|
import preprocess from '@exodus/dependency-preprocessors'
|
|
3
3
|
import alias from '@exodus/dependency-preprocessors/src/preprocessors/alias'
|
|
4
|
-
import devModeAtoms from '@exodus/dependency-preprocessors/src/preprocessors/dev-mode-atoms'
|
|
5
4
|
import logify from '@exodus/dependency-preprocessors/src/preprocessors/logify'
|
|
6
5
|
import namespaceConfig from '@exodus/dependency-preprocessors/src/preprocessors/namespace-config'
|
|
7
|
-
import namespaceStorage from '@exodus/dependency-preprocessors/src/preprocessors/namespace-storage'
|
|
8
|
-
import optional from '@exodus/dependency-preprocessors/src/preprocessors/optional'
|
|
9
|
-
import readOnlyAtoms from '@exodus/dependency-preprocessors/src/preprocessors/read-only-atoms'
|
|
10
|
-
import assert from 'minimalistic-assert'
|
|
11
6
|
|
|
12
7
|
import createDependencies from './dependencies'
|
|
13
8
|
|
|
14
9
|
const createIOC = ({ adapters, config }) => {
|
|
15
10
|
const { createLogger } = adapters
|
|
16
|
-
const { readOnlyAtoms: readOnlyAtomsConfig, devModeAtoms: devModeAtomsConfig } = config.ioc ?? {}
|
|
17
11
|
|
|
18
|
-
const
|
|
12
|
+
const logger = createLogger('exodus:ioc')
|
|
13
|
+
const dependencies = createDependencies({ adapters, config })
|
|
14
|
+
const preprocessors = [logify({ createLogger }), namespaceConfig(), alias()]
|
|
15
|
+
const definitions = preprocess({ dependencies, preprocessors })
|
|
16
|
+
const ioc = createIocContainer({ logger })
|
|
19
17
|
|
|
20
|
-
|
|
21
|
-
logify({ createLogger }),
|
|
22
|
-
namespaceConfig(),
|
|
23
|
-
alias(),
|
|
24
|
-
// NOTE: order matters, this should come after `alias`
|
|
25
|
-
namespaceStorage(),
|
|
26
|
-
readOnlyAtoms({
|
|
27
|
-
logger: createLogger('exodus:read-only-atoms'),
|
|
28
|
-
warn: true,
|
|
29
|
-
...readOnlyAtomsConfig,
|
|
30
|
-
}),
|
|
31
|
-
optional(),
|
|
32
|
-
...(devModeAtomsConfig ? [devModeAtoms(devModeAtomsConfig)] : []),
|
|
33
|
-
]
|
|
18
|
+
ioc.registerMultiple(definitions)
|
|
34
19
|
|
|
35
|
-
|
|
36
|
-
ioc.registerMultiple(preprocess({ dependencies, preprocessors }))
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
const register = (dependency) => {
|
|
40
|
-
registerMultiple([dependency])
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
const use = (module) => {
|
|
44
|
-
for (const { definition } of module.definitions) {
|
|
45
|
-
assert(definition.type, `ioc.use: "${definition.id}" is missing type field`)
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
registerMultiple(module.definitions)
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
registerMultiple(createDependencies({ adapters, config }))
|
|
52
|
-
|
|
53
|
-
return { ...ioc, register, registerMultiple, use }
|
|
20
|
+
return ioc
|
|
54
21
|
}
|
|
55
22
|
|
|
56
23
|
export default createIOC
|
package/src/atoms/attach.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
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
|
|
@@ -1,36 +0,0 @@
|
|
|
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
|
-
factory: createBaseAssetNamesToMonitorAtom,
|
|
35
|
-
dependencies: ['assetsModule', 'availableAssetNamesAtom', 'enabledAssetsAtom', 'restoreAtom'],
|
|
36
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { createInMemoryAtom } from '@exodus/atoms'
|
|
2
|
-
|
|
3
|
-
const nonDustBalanceAssetNamesAtomDefinition = {
|
|
4
|
-
id: 'nonDustBalanceAssetNamesAtom',
|
|
5
|
-
type: 'atom',
|
|
6
|
-
factory: () => createInMemoryAtom({ defaultValue: [] }),
|
|
7
|
-
dependencies: [],
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export default nonDustBalanceAssetNamesAtomDefinition
|