@exodus/headless 2.0.0-alpha.149 → 2.0.0-alpha.15
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 -1019
- package/README.md +11 -34
- package/package.json +32 -63
- package/src/api.js +86 -0
- package/src/application.js +30 -75
- package/src/atoms/attach.js +40 -0
- package/src/constants.js +9 -18
- package/src/dependencies/atoms.js +117 -2
- package/src/dependencies/index.js +9 -2
- package/src/dependencies/modules.js +45 -5
- package/src/dependencies/monitors.js +33 -0
- package/src/dependencies/utils.js +4 -0
- package/src/index.js +80 -91
- package/src/ioc.js +11 -49
- package/src/plugins/attach.js +7 -28
- package/src/plugins/index.js +1 -3
- package/src/plugins/log-lifecycle.js +0 -1
- package/src/unlock-encrypted-storage.js +0 -2
- package/src/utils/blockchain-metadata.js +48 -0
- package/src/api/debug.js +0 -13
- package/src/api/index.js +0 -19
- package/src/api/reporting.js +0 -39
- package/src/atoms/base-asset-names-to-monitor.js +0 -40
- package/src/migrations/attach.js +0 -62
- package/src/utils/fusion.js +0 -17
- package/src/utils/promises.js +0 -7
|
@@ -1,5 +1,120 @@
|
|
|
1
|
-
import
|
|
1
|
+
import {
|
|
2
|
+
createInMemoryAtom,
|
|
3
|
+
createRemoteConfigAtomFactory,
|
|
4
|
+
createStorageAtomFactory,
|
|
5
|
+
createFusionAtomFactory,
|
|
6
|
+
} from '@exodus/atoms'
|
|
7
|
+
import {
|
|
8
|
+
walletAccountsAtomDefinition,
|
|
9
|
+
enabledWalletAccountsAtomDefinition,
|
|
10
|
+
} from '@exodus/wallet-accounts/atoms'
|
|
11
|
+
import {
|
|
12
|
+
enabledAndDisabledAssetsAtomDefinition,
|
|
13
|
+
enabledAssetsAtomDefinition,
|
|
14
|
+
} from '@exodus/enabled-assets/atoms'
|
|
15
|
+
import { availableAssetNamesAtomDefinition } from '@exodus/available-assets/atoms'
|
|
16
|
+
import { ratesAtomDefinition } from '@exodus/rates-monitor/atoms'
|
|
17
|
+
import { balancesAtomDefinition } from '@exodus/balances/atoms'
|
|
18
|
+
import createGeolocationAtom from '@exodus/geolocation'
|
|
2
19
|
|
|
3
|
-
|
|
20
|
+
import { withType } from './utils'
|
|
21
|
+
|
|
22
|
+
const createAtomDependencies = () =>
|
|
23
|
+
[
|
|
24
|
+
{
|
|
25
|
+
definition: {
|
|
26
|
+
id: 'lockedAtom',
|
|
27
|
+
factory: () => createInMemoryAtom({ defaultValue: true }),
|
|
28
|
+
dependencies: [],
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
definition: walletAccountsAtomDefinition,
|
|
33
|
+
storage: { namespace: 'walletAccounts' },
|
|
34
|
+
},
|
|
35
|
+
{ definition: enabledWalletAccountsAtomDefinition },
|
|
36
|
+
{
|
|
37
|
+
definition: enabledAndDisabledAssetsAtomDefinition,
|
|
38
|
+
storage: { namespace: 'enabledAssets' },
|
|
39
|
+
},
|
|
40
|
+
{ definition: enabledAssetsAtomDefinition },
|
|
41
|
+
{ definition: availableAssetNamesAtomDefinition },
|
|
42
|
+
{
|
|
43
|
+
definition: {
|
|
44
|
+
id: 'pricingServerUrlAtom',
|
|
45
|
+
factory: ({ config, remoteConfig }) =>
|
|
46
|
+
createRemoteConfigAtomFactory({ remoteConfig })({
|
|
47
|
+
path: config.pricingServerPath,
|
|
48
|
+
defaultValue: config.defaultPricingServerUrl,
|
|
49
|
+
}),
|
|
50
|
+
dependencies: ['config', 'remoteConfig'],
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
definition: {
|
|
55
|
+
id: 'languageAtom',
|
|
56
|
+
factory: ({ storage, config }) =>
|
|
57
|
+
createStorageAtomFactory({ storage })({
|
|
58
|
+
key: 'language',
|
|
59
|
+
defaultValue: config.defaultValue,
|
|
60
|
+
isSoleWriter: true,
|
|
61
|
+
}),
|
|
62
|
+
dependencies: ['storage', 'config'],
|
|
63
|
+
},
|
|
64
|
+
aliases: [
|
|
65
|
+
{
|
|
66
|
+
implementationId: 'unsafeStorage',
|
|
67
|
+
interfaceId: 'storage',
|
|
68
|
+
},
|
|
69
|
+
],
|
|
70
|
+
storage: { namespace: 'locale' },
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
definition: {
|
|
74
|
+
id: 'currencyAtom',
|
|
75
|
+
factory: ({ fusion, config }) =>
|
|
76
|
+
createFusionAtomFactory({ fusion })({
|
|
77
|
+
path: `private.currency`,
|
|
78
|
+
defaultValue: config.defaultValue,
|
|
79
|
+
}),
|
|
80
|
+
dependencies: ['fusion', 'config'],
|
|
81
|
+
},
|
|
82
|
+
},
|
|
83
|
+
// TODO: move to @exodus/market-history
|
|
84
|
+
{
|
|
85
|
+
definition: {
|
|
86
|
+
id: 'marketHistoryClearCacheAtom',
|
|
87
|
+
factory: ({ config }) => createInMemoryAtom(config),
|
|
88
|
+
dependencies: ['config'],
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
// TODO: move to @exodus/market-history
|
|
92
|
+
{
|
|
93
|
+
definition: {
|
|
94
|
+
id: 'remoteConfigClearMarketHistoryCacheAtom',
|
|
95
|
+
factory: ({ config, remoteConfig }) =>
|
|
96
|
+
createRemoteConfigAtomFactory({ remoteConfig })(config),
|
|
97
|
+
dependencies: ['config', 'remoteConfig'],
|
|
98
|
+
},
|
|
99
|
+
},
|
|
100
|
+
// TODO: move to @exodus/market-history
|
|
101
|
+
{
|
|
102
|
+
definition: {
|
|
103
|
+
id: 'marketHistoryRefreshIntervalAtom',
|
|
104
|
+
factory: ({ config, remoteConfig }) =>
|
|
105
|
+
createRemoteConfigAtomFactory({ remoteConfig })(config),
|
|
106
|
+
dependencies: ['config', 'remoteConfig'],
|
|
107
|
+
},
|
|
108
|
+
},
|
|
109
|
+
{ definition: balancesAtomDefinition },
|
|
110
|
+
{ definition: ratesAtomDefinition },
|
|
111
|
+
{
|
|
112
|
+
definition: {
|
|
113
|
+
id: 'geolocationAtom',
|
|
114
|
+
factory: createGeolocationAtom,
|
|
115
|
+
dependencies: ['config'],
|
|
116
|
+
},
|
|
117
|
+
},
|
|
118
|
+
].map(withType('atom'))
|
|
4
119
|
|
|
5
120
|
export default createAtomDependencies
|
|
@@ -3,18 +3,22 @@
|
|
|
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
|
|
10
|
+
import createMonitorDependencies from './monitors'
|
|
11
11
|
import { wrapConstant } from './utils'
|
|
12
|
+
import createPluginDependencies from './plugins'
|
|
12
13
|
|
|
13
14
|
const adapterKeys = [
|
|
15
|
+
// ...
|
|
16
|
+
'assetsModule',
|
|
14
17
|
'createLogger',
|
|
15
18
|
'legacyPrivToPub',
|
|
16
19
|
'seedStorage',
|
|
17
20
|
'unsafeStorage',
|
|
21
|
+
'fusion',
|
|
18
22
|
'fetch',
|
|
19
23
|
'freeze',
|
|
20
24
|
]
|
|
@@ -30,6 +34,8 @@ const createDependencies = ({ adapters, config }) => {
|
|
|
30
34
|
|
|
31
35
|
const modules = createModuleDependencies({ adapters, config })
|
|
32
36
|
|
|
37
|
+
const monitors = createMonitorDependencies({ adapters, config })
|
|
38
|
+
|
|
33
39
|
const atoms = createAtomDependencies({ adapters, config })
|
|
34
40
|
|
|
35
41
|
const adaptersTree = createAdapterDependencies({ adapters, config })
|
|
@@ -40,6 +46,7 @@ const createDependencies = ({ adapters, config }) => {
|
|
|
40
46
|
.concat(adaptersTree)
|
|
41
47
|
.concat(configs)
|
|
42
48
|
.concat(modules)
|
|
49
|
+
.concat(monitors)
|
|
43
50
|
.concat(atoms)
|
|
44
51
|
.concat(plugins)
|
|
45
52
|
.concat(wrapConstant({ id: 'logger', type: 'module', value: logger }))
|
|
@@ -1,17 +1,27 @@
|
|
|
1
|
+
import EventEmitter from 'events/'
|
|
2
|
+
import createRemoteConfig from '@exodus/config/remote'
|
|
3
|
+
import keychainDefinition from '@exodus/keychain/module'
|
|
4
|
+
import walletDefinition from '@exodus/wallet/module'
|
|
5
|
+
import walletAccountsDefinition from '@exodus/wallet-accounts/module'
|
|
6
|
+
import blockchainMetadataDefinition from '@exodus/blockchain-metadata/module'
|
|
7
|
+
import enabledAssetsModuleDefinition from '@exodus/enabled-assets/module'
|
|
8
|
+
import availableAssetsModuleDefinition from '@exodus/available-assets/module'
|
|
1
9
|
import createKeyIdentifierProvider from '@exodus/key-identifier-provider'
|
|
2
10
|
import walletCompatibilityModesDefinition from '@exodus/wallet-compatibility-modes/module'
|
|
11
|
+
import balancesDefinition from '@exodus/balances/module'
|
|
3
12
|
|
|
4
13
|
import createApplication from '../application'
|
|
5
|
-
import unlockEncryptedStorageDefinition from '../unlock-encrypted-storage'
|
|
6
14
|
import { withType } from './utils'
|
|
15
|
+
import unlockEncryptedStorageDefinition from '../unlock-encrypted-storage'
|
|
16
|
+
import createExodusPricingClient from '@exodus/exodus-pricing-client'
|
|
7
17
|
|
|
8
|
-
const createModuleDependencies = (
|
|
18
|
+
const createModuleDependencies = () =>
|
|
9
19
|
[
|
|
10
20
|
{
|
|
11
21
|
definition: {
|
|
12
22
|
id: 'application',
|
|
13
23
|
factory: createApplication,
|
|
14
|
-
dependencies: ['unsafeStorage', 'passphraseCache
|
|
24
|
+
dependencies: ['unsafeStorage', 'passphraseCache', 'wallet', 'logger'],
|
|
15
25
|
},
|
|
16
26
|
},
|
|
17
27
|
{
|
|
@@ -21,12 +31,42 @@ const createModuleDependencies = ({ config }) =>
|
|
|
21
31
|
dependencies: [],
|
|
22
32
|
},
|
|
23
33
|
},
|
|
34
|
+
{
|
|
35
|
+
definition: keychainDefinition,
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
definition: walletDefinition,
|
|
39
|
+
writesAtoms: ['lockedAtom'],
|
|
40
|
+
},
|
|
24
41
|
{
|
|
25
42
|
definition: walletCompatibilityModesDefinition,
|
|
26
|
-
storage: { namespace: 'walletCompatibilityModes' },
|
|
27
|
-
aliases: [{ implementationId: 'unsafeStorage', interfaceId: 'storage' }],
|
|
28
43
|
},
|
|
29
44
|
{ definition: unlockEncryptedStorageDefinition },
|
|
45
|
+
{ definition: walletAccountsDefinition, writesAtoms: ['walletAccountsAtom'] },
|
|
46
|
+
{
|
|
47
|
+
definition: blockchainMetadataDefinition,
|
|
48
|
+
storage: { namespace: ['blockchain', 'v1'] },
|
|
49
|
+
},
|
|
50
|
+
{ definition: enabledAssetsModuleDefinition, writesAtoms: ['enabledAndDisabledAssetsAtom'] },
|
|
51
|
+
{
|
|
52
|
+
definition: {
|
|
53
|
+
id: 'remoteConfig',
|
|
54
|
+
factory: (deps) => {
|
|
55
|
+
const eventEmitter = new EventEmitter().setMaxListeners(Number.POSITIVE_INFINITY)
|
|
56
|
+
return createRemoteConfig({ eventEmitter, ...deps })
|
|
57
|
+
},
|
|
58
|
+
dependencies: ['fetch', 'freeze', 'config', 'logger'],
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
{ definition: availableAssetsModuleDefinition, writesAtoms: ['availableAssetNamesAtom'] },
|
|
62
|
+
{
|
|
63
|
+
definition: {
|
|
64
|
+
id: 'pricingClient',
|
|
65
|
+
factory: createExodusPricingClient,
|
|
66
|
+
dependencies: ['fetch', 'pricingServerUrlAtom'],
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
{ definition: balancesDefinition, writesAtoms: ['balancesAtom'] },
|
|
30
70
|
].map(withType('module'))
|
|
31
71
|
|
|
32
72
|
export default createModuleDependencies
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import marketHistoryMonitorDefinition from '@exodus/market-history/module'
|
|
2
|
+
import ratesMonitorDefinition from '@exodus/rates-monitor/module'
|
|
3
|
+
|
|
4
|
+
import { withType } from './utils'
|
|
5
|
+
|
|
6
|
+
const createModuleDependencies = () =>
|
|
7
|
+
[
|
|
8
|
+
{
|
|
9
|
+
definition: marketHistoryMonitorDefinition,
|
|
10
|
+
storage: { namespace: 'marketHistory' },
|
|
11
|
+
aliases: [
|
|
12
|
+
{
|
|
13
|
+
implementationId: 'unsafeStorage',
|
|
14
|
+
interfaceId: 'storage',
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
implementationId: 'marketHistoryClearCacheAtom',
|
|
18
|
+
interfaceId: 'clearCacheAtom',
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
implementationId: 'remoteConfigClearMarketHistoryCacheAtom',
|
|
22
|
+
interfaceId: 'remoteConfigClearCacheAtom',
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
implementationId: 'marketHistoryRefreshIntervalAtom',
|
|
26
|
+
interfaceId: 'remoteConfigRefreshIntervalAtom',
|
|
27
|
+
},
|
|
28
|
+
],
|
|
29
|
+
},
|
|
30
|
+
{ definition: ratesMonitorDefinition, writesAtoms: ['ratesAtom'] },
|
|
31
|
+
].map(withType('monitor'))
|
|
32
|
+
|
|
33
|
+
export default createModuleDependencies
|
|
@@ -2,6 +2,10 @@ 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
|
+
|
|
5
9
|
export const withType =
|
|
6
10
|
(type) =>
|
|
7
11
|
({ definition, ...rest }) => ({
|
package/src/index.js
CHANGED
|
@@ -1,125 +1,114 @@
|
|
|
1
|
-
import
|
|
2
|
-
import assetsFeature from '@exodus/assets-feature'
|
|
3
|
-
import availableAssets from '@exodus/available-assets'
|
|
4
|
-
import balances from '@exodus/balances'
|
|
5
|
-
import blockchainMetadata from '@exodus/blockchain-metadata'
|
|
6
|
-
import enabledAssets from '@exodus/enabled-assets'
|
|
7
|
-
import featureFlags from '@exodus/feature-flags'
|
|
8
|
-
import fees from '@exodus/fee-data-monitors'
|
|
9
|
-
import geolocation from '@exodus/geolocation'
|
|
10
|
-
import keychain from '@exodus/keychain'
|
|
11
|
-
import locale from '@exodus/locale'
|
|
12
|
-
import pricing from '@exodus/pricing'
|
|
13
|
-
import publicKeyStore from '@exodus/public-key-store'
|
|
14
|
-
import rates from '@exodus/rates-monitor'
|
|
15
|
-
import remoteConfig from '@exodus/remote-config'
|
|
16
|
-
import restoreProgressTracker from '@exodus/restore-progress-tracker'
|
|
17
|
-
import startupCounter from '@exodus/startup-counter'
|
|
18
|
-
import transactionSigner from '@exodus/tx-signer'
|
|
19
|
-
import wallet from '@exodus/wallet'
|
|
20
|
-
import walletAccounts from '@exodus/wallet-accounts'
|
|
21
|
-
|
|
22
|
-
import createApi from './api'
|
|
1
|
+
import { pick } from '@exodus/basic-utils'
|
|
23
2
|
import createIOC from './ioc'
|
|
24
|
-
import
|
|
3
|
+
import createApi from './api'
|
|
4
|
+
import {
|
|
5
|
+
createAccountStatesUpdateHandler,
|
|
6
|
+
createLoadWalletAccountsHandler,
|
|
7
|
+
} from './utils/blockchain-metadata'
|
|
8
|
+
|
|
25
9
|
import attachPlugins from './plugins/attach'
|
|
10
|
+
import attachAtoms from './atoms/attach'
|
|
11
|
+
import { atomsToAttach } from './constants'
|
|
26
12
|
|
|
27
13
|
const createExodus = ({ adapters, config, port }) => {
|
|
28
14
|
const ioc = createIOC({ adapters, config })
|
|
29
|
-
|
|
30
|
-
ioc.use(addressProvider({ config: config.addressProvider }))
|
|
31
|
-
ioc.use(assetsFeature())
|
|
32
|
-
ioc.use(availableAssets())
|
|
33
|
-
ioc.use(balances(config.balances))
|
|
34
|
-
ioc.use(blockchainMetadata())
|
|
35
|
-
ioc.use(enabledAssets())
|
|
36
|
-
ioc.use(featureFlags())
|
|
37
|
-
ioc.use(fees())
|
|
38
|
-
ioc.use(geolocation())
|
|
39
|
-
ioc.use(keychain(config.keychain))
|
|
40
|
-
ioc.use(locale())
|
|
41
|
-
ioc.use(pricing())
|
|
42
|
-
ioc.use(publicKeyStore())
|
|
43
|
-
ioc.use(rates())
|
|
44
|
-
ioc.use(remoteConfig())
|
|
45
|
-
ioc.use(restoreProgressTracker())
|
|
46
|
-
ioc.use(startupCounter())
|
|
47
|
-
ioc.use(transactionSigner())
|
|
48
|
-
ioc.use(wallet())
|
|
49
|
-
ioc.use(walletAccounts())
|
|
50
|
-
|
|
51
|
-
ioc.register({ definition: { id: 'port', type: 'port', factory: () => port } })
|
|
15
|
+
const { headless: headlessConfig } = config
|
|
52
16
|
|
|
53
17
|
const resolve = () => {
|
|
54
18
|
ioc.resolve()
|
|
55
19
|
|
|
56
|
-
const {
|
|
57
|
-
|
|
58
|
-
const { application, wallet, unlockEncryptedStorage } = ioc.getByType('module')
|
|
59
|
-
|
|
60
|
-
const { migrations } = ioc.getAll()
|
|
61
|
-
|
|
62
|
-
application.on('start', (payload) => port.emit('start', payload))
|
|
63
|
-
|
|
64
|
-
application.hook('load', (args) => port.emit('pre-load', args))
|
|
65
|
-
|
|
66
|
-
application.on('load', (args) => port.emit('load', args))
|
|
67
|
-
|
|
68
|
-
application.on('create', async ({ hasPassphraseSet }) => {
|
|
69
|
-
const isLocked = await wallet.isLocked()
|
|
20
|
+
const { assetsModule, storage } = ioc.getByType('adapter')
|
|
70
21
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
22
|
+
const {
|
|
23
|
+
application,
|
|
24
|
+
blockchainMetadata,
|
|
25
|
+
enabledAssets,
|
|
26
|
+
remoteConfig,
|
|
27
|
+
unlockEncryptedStorage,
|
|
28
|
+
walletAccounts,
|
|
29
|
+
} = ioc.getByType('module')
|
|
30
|
+
|
|
31
|
+
const { marketHistory, ratesMonitor } = ioc.getByType('monitor')
|
|
32
|
+
|
|
33
|
+
const handleLoadWalletAccounts = createLoadWalletAccountsHandler({
|
|
34
|
+
blockchainMetadata,
|
|
35
|
+
port,
|
|
36
|
+
config,
|
|
78
37
|
})
|
|
79
38
|
|
|
80
|
-
|
|
39
|
+
const handleAccountStatesUpdate = createAccountStatesUpdateHandler({
|
|
40
|
+
blockchainMetadata,
|
|
41
|
+
port,
|
|
42
|
+
config,
|
|
43
|
+
})
|
|
81
44
|
|
|
82
|
-
|
|
45
|
+
blockchainMetadata.on('load-wallet-accounts', handleLoadWalletAccounts)
|
|
46
|
+
blockchainMetadata.on('tx-logs-update', (payload) => port.emit('tx-logs-update', payload))
|
|
47
|
+
blockchainMetadata.on('account-states-update', handleAccountStatesUpdate)
|
|
83
48
|
|
|
84
|
-
|
|
49
|
+
remoteConfig.on('sync', ({ current }) => port.emit('remote-config', current))
|
|
85
50
|
|
|
86
|
-
|
|
51
|
+
// TODO: migrate to marketHistoryAtom. Will be easier once it's on headless
|
|
52
|
+
marketHistory.on('market-history', (payload) => port.emit('market-history', payload))
|
|
87
53
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
})
|
|
54
|
+
// TODO: migrate to ratesAtom. Will be easier once it's on headless
|
|
55
|
+
ratesMonitor.on('rates', (payload) => port.emit('rates', payload))
|
|
91
56
|
|
|
92
|
-
application.
|
|
57
|
+
application.hook('start', () => {
|
|
58
|
+
remoteConfig.load()
|
|
93
59
|
|
|
94
|
-
|
|
60
|
+
port.emit('start')
|
|
61
|
+
})
|
|
95
62
|
|
|
96
63
|
application.hook('unlock', async () => {
|
|
97
64
|
if (typeof storage.unlock === 'function') unlockEncryptedStorage(storage)
|
|
98
65
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
66
|
+
remoteConfig.sync()
|
|
67
|
+
marketHistory.start()
|
|
68
|
+
ratesMonitor.start()
|
|
69
|
+
|
|
70
|
+
await assetsModule.load()
|
|
71
|
+
await walletAccounts.load()
|
|
72
|
+
await Promise.all([
|
|
73
|
+
//
|
|
74
|
+
blockchainMetadata.load(),
|
|
75
|
+
enabledAssets.load(),
|
|
76
|
+
])
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
application.on('unlock', () => {
|
|
80
|
+
port.emit('unlock')
|
|
102
81
|
})
|
|
103
82
|
|
|
104
|
-
application.
|
|
83
|
+
application.hook('clear', async () => {
|
|
84
|
+
await Promise.all([
|
|
85
|
+
//
|
|
86
|
+
assetsModule.clear(),
|
|
87
|
+
walletAccounts.clear(),
|
|
88
|
+
blockchainMetadata.clear(),
|
|
89
|
+
enabledAssets.clear(),
|
|
90
|
+
])
|
|
105
91
|
|
|
106
|
-
|
|
92
|
+
port.emit('clear')
|
|
93
|
+
})
|
|
107
94
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
adapters,
|
|
111
|
-
application,
|
|
112
|
-
atoms: ioc.getByType('atom'),
|
|
113
|
-
modules: ioc.getByType('module'),
|
|
95
|
+
application.on('restart', (payload) => {
|
|
96
|
+
port.emit('restart', payload)
|
|
114
97
|
})
|
|
115
98
|
|
|
116
|
-
|
|
99
|
+
attachAtoms({
|
|
100
|
+
port,
|
|
117
101
|
application,
|
|
118
|
-
|
|
119
|
-
|
|
102
|
+
logger: ioc.get('createLogger')('attachAtoms'),
|
|
103
|
+
atoms: pick(ioc.getByType('atom'), atomsToAttach),
|
|
104
|
+
lifecycleEvents: headlessConfig?.attachAtomsLifecycleEvents,
|
|
120
105
|
})
|
|
121
106
|
|
|
122
|
-
|
|
107
|
+
attachPlugins({ application, plugins: ioc.getByType('plugin') })
|
|
108
|
+
|
|
109
|
+
application.start()
|
|
110
|
+
|
|
111
|
+
return createApi({ ioc, port })
|
|
123
112
|
}
|
|
124
113
|
|
|
125
114
|
return { ...ioc, resolve }
|
package/src/ioc.js
CHANGED
|
@@ -1,43 +1,22 @@
|
|
|
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 configPreprocessor from '@exodus/dependency-preprocessors/src/preprocessors/config'
|
|
5
|
-
import devModeAtoms from '@exodus/dependency-preprocessors/src/preprocessors/dev-mode-atoms'
|
|
6
4
|
import logify from '@exodus/dependency-preprocessors/src/preprocessors/logify'
|
|
5
|
+
import namespaceConfig from '@exodus/dependency-preprocessors/src/preprocessors/namespace-config'
|
|
7
6
|
import namespaceStorage from '@exodus/dependency-preprocessors/src/preprocessors/namespace-storage'
|
|
8
|
-
import optional from '@exodus/dependency-preprocessors/src/preprocessors/optional'
|
|
9
|
-
import performanceMonitor from '@exodus/dependency-preprocessors/src/preprocessors/performance-monitor'
|
|
10
7
|
import readOnlyAtoms from '@exodus/dependency-preprocessors/src/preprocessors/read-only-atoms'
|
|
11
|
-
import assert from 'minimalistic-assert'
|
|
12
8
|
|
|
13
9
|
import createDependencies from './dependencies'
|
|
14
10
|
|
|
15
11
|
const createIOC = ({ adapters, config }) => {
|
|
16
|
-
const { createLogger
|
|
17
|
-
const {
|
|
18
|
-
readOnlyAtoms: readOnlyAtomsConfig,
|
|
19
|
-
devModeAtoms: devModeAtomsConfig,
|
|
20
|
-
performanceMonitor: performanceMonitorConfig,
|
|
21
|
-
} = config.ioc ?? {}
|
|
22
|
-
|
|
23
|
-
const ioc = createIocContainer({ logger: createLogger('exodus:ioc') })
|
|
24
|
-
|
|
25
|
-
const performanceLogger = createLogger('exodus:performance')
|
|
12
|
+
const { createLogger } = adapters
|
|
13
|
+
const { readOnlyAtoms: readOnlyAtomsConfig } = config.ioc ?? {}
|
|
26
14
|
|
|
15
|
+
const logger = createLogger('exodus:ioc')
|
|
16
|
+
const dependencies = createDependencies({ adapters, config })
|
|
27
17
|
const preprocessors = [
|
|
28
18
|
logify({ createLogger }),
|
|
29
|
-
|
|
30
|
-
performanceMonitor({
|
|
31
|
-
now: performance.now,
|
|
32
|
-
onAboveThreshold:
|
|
33
|
-
performance.onAboveThreshold ??
|
|
34
|
-
(({ id, method, async, duration }) =>
|
|
35
|
-
performanceLogger.log(
|
|
36
|
-
`${id}.${method} ${async ? 'resolved after' : 'took'} ${duration}ms`
|
|
37
|
-
)),
|
|
38
|
-
config: performanceMonitorConfig,
|
|
39
|
-
}),
|
|
40
|
-
configPreprocessor(),
|
|
19
|
+
namespaceConfig(),
|
|
41
20
|
alias(),
|
|
42
21
|
// NOTE: order matters, this should come after `alias`
|
|
43
22
|
namespaceStorage(),
|
|
@@ -46,30 +25,13 @@ const createIOC = ({ adapters, config }) => {
|
|
|
46
25
|
warn: true,
|
|
47
26
|
...readOnlyAtomsConfig,
|
|
48
27
|
}),
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
const registerMultiple = (dependencies) => {
|
|
54
|
-
ioc.registerMultiple(preprocess({ dependencies, preprocessors }))
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
const register = (dependency) => {
|
|
58
|
-
registerMultiple([dependency])
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
const use = (feature) => {
|
|
62
|
-
for (const { definition } of feature.definitions) {
|
|
63
|
-
assert(definition.type, `ioc.use: "${definition.id}" is missing type field`)
|
|
64
|
-
definition.namespace = feature.id
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
registerMultiple(feature.definitions)
|
|
68
|
-
}
|
|
28
|
+
]
|
|
29
|
+
const definitions = preprocess({ dependencies, preprocessors })
|
|
30
|
+
const ioc = createIocContainer({ logger })
|
|
69
31
|
|
|
70
|
-
registerMultiple(
|
|
32
|
+
ioc.registerMultiple(definitions)
|
|
71
33
|
|
|
72
|
-
return
|
|
34
|
+
return ioc
|
|
73
35
|
}
|
|
74
36
|
|
|
75
37
|
export default createIOC
|
package/src/plugins/attach.js
CHANGED
|
@@ -1,38 +1,17 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { kebabCase, memoize } from 'lodash'
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
hookName,
|
|
7
|
-
])
|
|
3
|
+
// e.g. onUnlock -> unlock -> onUnlock, onChangePassphrase -> change-passphrase
|
|
4
|
+
const getApplicationHookName = memoize((lifecycleMethod) =>
|
|
5
|
+
kebabCase(lifecycleMethod.replace(/^on/, ''))
|
|
8
6
|
)
|
|
9
7
|
|
|
10
|
-
const attachPlugins = ({ plugins, application
|
|
11
|
-
const timeFn = (fn, name) => {
|
|
12
|
-
const pluginWrapper = async (...args) => {
|
|
13
|
-
const start = Date.now()
|
|
14
|
-
try {
|
|
15
|
-
return await fn(...args)
|
|
16
|
-
} finally {
|
|
17
|
-
logger.debug(name, `${Date.now() - start}ms`)
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
Object.defineProperty(pluginWrapper, 'name', { value: name, writable: false })
|
|
22
|
-
|
|
23
|
-
return pluginWrapper
|
|
24
|
-
}
|
|
25
|
-
|
|
8
|
+
const attachPlugins = ({ plugins, application }) => {
|
|
26
9
|
Object.entries(plugins).forEach(([name, lifecycleMethods]) => {
|
|
27
10
|
const entries = Object.entries(lifecycleMethods || {})
|
|
28
11
|
|
|
29
12
|
for (const [lifecycleMethod, fn] of entries) {
|
|
30
|
-
const hookName =
|
|
31
|
-
|
|
32
|
-
application.hook(hookName, timeFn(fn, `plugin ${name}.${lifecycleMethod}`))
|
|
33
|
-
} else {
|
|
34
|
-
logger.error(`plugin "${name}" declares unsupported lifecycle method "${lifecycleMethod}"`)
|
|
35
|
-
}
|
|
13
|
+
const hookName = getApplicationHookName(lifecycleMethod)
|
|
14
|
+
application.hook(hookName, fn)
|
|
36
15
|
}
|
|
37
16
|
})
|
|
38
17
|
}
|
package/src/plugins/index.js
CHANGED
|
@@ -9,7 +9,6 @@ const logLifecycle = {
|
|
|
9
9
|
onImport: () => logger.debug('onImport'),
|
|
10
10
|
onMigrate: () => logger.debug('onMigrate'),
|
|
11
11
|
onStart: () => logger.debug('onStart'),
|
|
12
|
-
onRestart: () => logger.debug('onRestart'),
|
|
13
12
|
onLoad: () => logger.debug('onLoad'),
|
|
14
13
|
onUnload: () => logger.debug('onUnload'),
|
|
15
14
|
onCreate: () => logger.debug('onCreate'),
|
|
@@ -12,10 +12,8 @@ const createUnlockEncryptedStorage = ({ keychain }) => {
|
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
// eslint-disable-next-line @exodus/export-default/named
|
|
16
15
|
export default {
|
|
17
16
|
id: 'unlockEncryptedStorage',
|
|
18
|
-
type: 'module',
|
|
19
17
|
factory: createUnlockEncryptedStorage,
|
|
20
18
|
dependencies: ['keychain'],
|
|
21
19
|
}
|