@exodus/headless 2.0.0-alpha.45 → 2.0.0-alpha.47

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 CHANGED
@@ -3,6 +3,18 @@
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
+ ## [2.0.0-alpha.47](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/headless@2.0.0-alpha.46...@exodus/headless@2.0.0-alpha.47) (2023-06-18)
7
+
8
+ ### Features
9
+
10
+ - use(wallet) ([#1994](https://github.com/ExodusMovement/exodus-hydra/issues/1994)) ([6686257](https://github.com/ExodusMovement/exodus-hydra/commit/668625744087ee77068fc64671ce80ea0c3c62a4))
11
+
12
+ ## [2.0.0-alpha.46](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/headless@2.0.0-alpha.45...@exodus/headless@2.0.0-alpha.46) (2023-06-18)
13
+
14
+ ### Features
15
+
16
+ - use(featureFlags, apyRates, fees, addressProvider) ([#1993](https://github.com/ExodusMovement/exodus-hydra/issues/1993)) ([5aba49b](https://github.com/ExodusMovement/exodus-hydra/commit/5aba49bbea24f229900966c0abde5eb8932ac861))
17
+
6
18
  ## [2.0.0-alpha.45](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/headless@2.0.0-alpha.44...@exodus/headless@2.0.0-alpha.45) (2023-06-18)
7
19
 
8
20
  ### Features
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@exodus/headless",
3
- "version": "2.0.0-alpha.45",
3
+ "version": "2.0.0-alpha.47",
4
4
  "description": "The headless Exodus wallet SDK",
5
5
  "author": "Exodus Movement Inc",
6
6
  "main": "src/index.js",
@@ -88,5 +88,5 @@
88
88
  "nock": "^13.3.1",
89
89
  "p-defer": "^4.0.0"
90
90
  },
91
- "gitHead": "af48f92eb9e4b7758b6f145181c4c45a24cf5b65"
91
+ "gitHead": "003665277a4a7ee772af60ab555f5692b1f840f6"
92
92
  }
package/src/api.js CHANGED
@@ -5,14 +5,10 @@ const createApi = ({ ioc, port }) => {
5
5
 
6
6
  const { assetsModule } = ioc.getByType('adapter')
7
7
 
8
- const { addressProvider, application, enabledAssets, remoteConfig, wallet } =
9
- ioc.getByType('module')
8
+ const { enabledAssets, remoteConfig } = ioc.getByType('module')
10
9
 
11
10
  const { feeMonitors, nftsMonitor } = ioc.getByType('monitor')
12
11
 
13
- // TODO: decide where this belongs
14
- const { passphraseCache } = ioc.getAll()
15
-
16
12
  // TODO: do this on 'unload'
17
13
  const stop = () => {
18
14
  remoteConfig.stop()
@@ -22,28 +18,6 @@ const createApi = ({ ioc, port }) => {
22
18
 
23
19
  return {
24
20
  ...Object.assign({}, ...Object.values(apis)),
25
- wallet: {
26
- exists: () => wallet.exists(),
27
- start: application.start,
28
- load: application.load,
29
- unload: application.unload,
30
- create: application.create,
31
- lock: application.lock,
32
- unlock: application.unlock,
33
- import: application.import,
34
- delete: application.delete,
35
- getMnemonic: application.getMnemonic,
36
- setBackedUp: application.setBackedUp,
37
- changePassphrase: application.changePassphrase,
38
- restoreFromCurrentPhrase: async ({ passphrase } = {}) => {
39
- if (!passphrase) passphrase = await passphraseCache.get()
40
- const mnemonic = await application.getMnemonic({ passphrase })
41
-
42
- await application.import({ passphrase, mnemonic })
43
- },
44
- changeLockTimer: application.changeLockTimer,
45
- isLocked: () => wallet.isLocked(),
46
- },
47
21
  assets: {
48
22
  enable: enabledAssets.enable,
49
23
  disable: enabledAssets.disable,
@@ -53,11 +27,6 @@ const createApi = ({ ioc, port }) => {
53
27
  return asset.name
54
28
  },
55
29
  },
56
- addressProvider: {
57
- getAddress: addressProvider.getAddress.bind(addressProvider),
58
- getSupportedPurposes: addressProvider.getSupportedPurposes.bind(addressProvider),
59
- getReceiveAddress: addressProvider.getReceiveAddress.bind(addressProvider),
60
- },
61
30
  isMnemonicValid,
62
31
  subscribe: port.subscribe.bind(port),
63
32
  unsubscribe: port.unsubscribe.bind(port),
@@ -1,31 +1,17 @@
1
- import { apyRatesAtomDefinition } from '@exodus/apy-rates/atoms'
2
- import {
3
- createInMemoryAtom,
4
- createRemoteConfigAtomFactory,
5
- createStorageAtomFactory,
6
- } from '@exodus/atoms'
1
+ import { createRemoteConfigAtomFactory, createStorageAtomFactory } from '@exodus/atoms'
7
2
  import { availableAssetNamesAtomDefinition } from '@exodus/available-assets/atoms'
8
3
  import { balancesAtomDefinition } from '@exodus/balances/atoms'
9
4
  import {
10
5
  enabledAndDisabledAssetsAtomDefinition,
11
6
  enabledAssetsAtomDefinition,
12
7
  } from '@exodus/enabled-assets/atoms'
13
- import { featureFlagsAtomDefinition } from '@exodus/feature-flags/atoms'
14
8
 
15
9
  import baseAssetNamesToMonitorAtomDefinition from '../atoms/base-asset-names-to-monitor'
16
10
  import nonDustBalanceAssetNamesAtomDefinition from '../atoms/non-dust-balance-asset-names-atom'
17
- import restoreAtomDefinition from '../atoms/restore'
18
11
  import { withType } from './utils'
19
12
 
20
13
  const createAtomDependencies = () =>
21
14
  [
22
- {
23
- definition: {
24
- id: 'lockedAtom',
25
- factory: () => createInMemoryAtom({ defaultValue: true }),
26
- dependencies: [],
27
- },
28
- },
29
15
  {
30
16
  definition: enabledAndDisabledAssetsAtomDefinition,
31
17
  storage: { namespace: 'enabledAssets' },
@@ -66,10 +52,7 @@ const createAtomDependencies = () =>
66
52
  ],
67
53
  },
68
54
  { definition: balancesAtomDefinition },
69
- { definition: featureFlagsAtomDefinition },
70
55
  { definition: baseAssetNamesToMonitorAtomDefinition },
71
- { definition: restoreAtomDefinition },
72
- { definition: apyRatesAtomDefinition },
73
56
  ].map(withType('atom'))
74
57
 
75
58
  export default createAtomDependencies
@@ -4,11 +4,9 @@
4
4
  import assert from 'minimalistic-assert'
5
5
 
6
6
  import createAdapterDependencies from './adapters'
7
- import createAtomCollectionDependencies from './atom-collections'
8
7
  import createAtomDependencies from './atoms'
9
8
  import createConfigDependencies from './configs'
10
9
  import createModuleDependencies from './modules'
11
- import createMonitorDependencies from './monitors'
12
10
  import createPluginDependencies from './plugins'
13
11
  import { wrapConstant } from './utils'
14
12
 
@@ -35,12 +33,8 @@ const createDependencies = ({ adapters, config }) => {
35
33
 
36
34
  const modules = createModuleDependencies({ adapters, config })
37
35
 
38
- const monitors = createMonitorDependencies({ adapters, config })
39
-
40
36
  const atoms = createAtomDependencies({ adapters, config })
41
37
 
42
- const atomCollections = createAtomCollectionDependencies({ adapters, config })
43
-
44
38
  const adaptersTree = createAdapterDependencies({ adapters, config })
45
39
 
46
40
  const plugins = createPluginDependencies()
@@ -49,9 +43,7 @@ const createDependencies = ({ adapters, config }) => {
49
43
  .concat(adaptersTree)
50
44
  .concat(configs)
51
45
  .concat(modules)
52
- .concat(monitors)
53
46
  .concat(atoms)
54
- .concat(atomCollections)
55
47
  .concat(plugins)
56
48
  .concat(wrapConstant({ id: 'logger', type: 'module', value: logger }))
57
49
  }
@@ -1,12 +1,9 @@
1
- import createAddressProviderDependencies from '@exodus/address-provider'
2
1
  import availableAssetsModuleDefinition from '@exodus/available-assets/module'
3
2
  import balancesDefinition from '@exodus/balances/module'
4
3
  import enabledAssetsModuleDefinition from '@exodus/enabled-assets/module'
5
4
  import createExodusPricingClient from '@exodus/exodus-pricing-client'
6
- import featureFlagsDefinition from '@exodus/feature-flags/module'
7
5
  import createKeyIdentifierProvider from '@exodus/key-identifier-provider'
8
6
  import keychainDefinition from '@exodus/keychain/module'
9
- import walletDefinition from '@exodus/wallet/module'
10
7
  import walletCompatibilityModesDefinition from '@exodus/wallet-compatibility-modes/module'
11
8
 
12
9
  import createApplication from '../application'
@@ -32,10 +29,6 @@ const createModuleDependencies = ({ config }) =>
32
29
  {
33
30
  definition: keychainDefinition,
34
31
  },
35
- {
36
- definition: walletDefinition,
37
- writesAtoms: ['lockedAtom'],
38
- },
39
32
  {
40
33
  definition: walletCompatibilityModesDefinition,
41
34
  },
@@ -50,11 +43,6 @@ const createModuleDependencies = ({ config }) =>
50
43
  },
51
44
  },
52
45
  { definition: balancesDefinition, writesAtoms: ['balancesAtom'] },
53
- {
54
- definition: featureFlagsDefinition,
55
- writesAtoms: ['featureFlagAtoms'],
56
- },
57
- ...createAddressProviderDependencies(config.addressProvider),
58
46
  ].map(withType('module'))
59
47
 
60
48
  export default createModuleDependencies
package/src/index.js CHANGED
@@ -5,9 +5,13 @@ import attachAtoms from './atoms/attach'
5
5
  import { atomsToAttach } from './constants'
6
6
  import createIOC from './ioc'
7
7
  import abTesting from './modules/ab-testing'
8
+ import addressProvider from './modules/address-provider'
9
+ import apyRates from './modules/apy-rates'
8
10
  import blockchainMetadata from './modules/blockchain-metadata'
9
11
  import connectedOrigins from './modules/connected-origins'
10
12
  import cryptoNews from './modules/crypto-news'
13
+ import featureFlags from './modules/feature-flags'
14
+ import fees from './modules/fees'
11
15
  import geolocation from './modules/geolocation'
12
16
  import kyc from './modules/kyc'
13
17
  import locale from './modules/locale'
@@ -18,6 +22,7 @@ import rates from './modules/rates'
18
22
  import referrals from './modules/referrals'
19
23
  import remoteConfig from './modules/remote-config'
20
24
  import topMovers from './modules/top-movers'
25
+ import wallet from './modules/wallet'
21
26
  import walletAccounts from './modules/wallet-accounts'
22
27
  import attachPlugins from './plugins/attach'
23
28
 
@@ -25,12 +30,16 @@ const createExodus = ({ adapters, config, port }) => {
25
30
  const ioc = createIOC({ adapters, config })
26
31
  const { headless: headlessConfig, topMoversMonitor } = config
27
32
 
33
+ ioc.use(wallet())
28
34
  ioc.use(walletAccounts())
29
35
  ioc.use(blockchainMetadata())
30
36
  ioc.use(remoteConfig())
31
37
  ioc.use(geolocation())
32
38
  ioc.use(marketHistory())
39
+ ioc.use(fees())
33
40
  ioc.use(rates())
41
+ ioc.use(apyRates())
42
+ ioc.use(featureFlags())
34
43
  ioc.use(locale())
35
44
  ioc.use(nfts())
36
45
  ioc.use(kyc())
@@ -40,6 +49,7 @@ const createExodus = ({ adapters, config, port }) => {
40
49
  ioc.use(personalNotes())
41
50
  ioc.use(cryptoNews())
42
51
  ioc.use(topMovers({ config: topMoversMonitor }))
52
+ ioc.use(addressProvider({ config: config.addressProvider }))
43
53
 
44
54
  ioc.register({ definition: { id: 'port', type: 'port', factory: () => port } })
45
55
 
@@ -48,26 +58,15 @@ const createExodus = ({ adapters, config, port }) => {
48
58
 
49
59
  const { assetsModule, storage } = ioc.getByType('adapter')
50
60
 
51
- const { application, enabledAssets, featureFlags, unlockEncryptedStorage } =
52
- ioc.getByType('module')
53
-
54
- const { apyRatesMonitor, feeMonitors } = ioc.getByType('monitor')
55
-
56
- feeMonitors.on('fees-load', () => port.emit('fees-load', feeMonitors.getAllFeeData()))
57
- feeMonitors.on('fees-update', (payload) => port.emit('fees-update', payload))
61
+ const { application, enabledAssets, unlockEncryptedStorage } = ioc.getByType('module')
58
62
 
59
63
  application.hook('start', (payload) => {
60
- featureFlags.load()
61
-
62
64
  port.emit('start', payload)
63
65
  })
64
66
 
65
67
  application.hook('unlock', async () => {
66
68
  if (typeof storage.unlock === 'function') unlockEncryptedStorage(storage)
67
69
 
68
- feeMonitors.start()
69
- apyRatesMonitor.start()
70
-
71
70
  await assetsModule.load()
72
71
  await enabledAssets.load()
73
72
  })
@@ -81,7 +80,6 @@ const createExodus = ({ adapters, config, port }) => {
81
80
  //
82
81
  assetsModule.clear(),
83
82
  enabledAssets.clear(),
84
- featureFlags.clear(),
85
83
  ])
86
84
  })
87
85
 
@@ -0,0 +1,14 @@
1
+ const createAddressProviderApi = ({ addressProvider }) => ({
2
+ addressProvider: {
3
+ getAddress: addressProvider.getAddress.bind(addressProvider),
4
+ getSupportedPurposes: addressProvider.getSupportedPurposes.bind(addressProvider),
5
+ getReceiveAddress: addressProvider.getReceiveAddress.bind(addressProvider),
6
+ },
7
+ })
8
+
9
+ export default {
10
+ id: 'addressProviderApi',
11
+ type: 'api',
12
+ factory: createAddressProviderApi,
13
+ dependencies: ['addressProvider'],
14
+ }
@@ -0,0 +1,15 @@
1
+ import createAddressProviderDependencies from '@exodus/address-provider'
2
+
3
+ import { withType } from '../../dependencies/utils'
4
+ import addressProviderApi from './api'
5
+
6
+ const addressProvider = ({ config }) => {
7
+ const dependencies = createAddressProviderDependencies(config).map(withType('module'))
8
+
9
+ return {
10
+ id: 'addressProvider',
11
+ definitions: [...dependencies, { definition: addressProviderApi }],
12
+ }
13
+ }
14
+
15
+ export default addressProvider
@@ -0,0 +1,20 @@
1
+ import { apyRatesAtomDefinition } from '@exodus/apy-rates/atoms'
2
+ import apyRatesMonitorDefinition from '@exodus/apy-rates/monitor'
3
+
4
+ import apyRatesPlugin from './plugin'
5
+
6
+ const apyRates = () => {
7
+ return {
8
+ id: 'apyRates',
9
+ definitions: [
10
+ {
11
+ definition: apyRatesMonitorDefinition,
12
+ writesAtoms: ['apyRatesAtom'],
13
+ },
14
+ { definition: apyRatesAtomDefinition },
15
+ { definition: apyRatesPlugin },
16
+ ],
17
+ }
18
+ }
19
+
20
+ export default apyRates
@@ -0,0 +1,14 @@
1
+ const createApyRatesLifecyclePlugin = ({ apyRatesMonitor }) => {
2
+ const onUnlock = () => {
3
+ apyRatesMonitor.start()
4
+ }
5
+
6
+ return { onUnlock }
7
+ }
8
+
9
+ export default {
10
+ id: 'apyRatesLifecyclePlugin',
11
+ type: 'plugin',
12
+ factory: createApyRatesLifecyclePlugin,
13
+ dependencies: ['apyRatesMonitor'],
14
+ }
@@ -0,0 +1,35 @@
1
+ import {
2
+ featureFlagAtomsDefinition,
3
+ featureFlagsAtomDefinition,
4
+ remoteConfigFeatureFlagAtomsDefinition,
5
+ } from '@exodus/feature-flags/atoms'
6
+ import featureFlagsDefinition from '@exodus/feature-flags/module'
7
+
8
+ import featureFlagsPlugin from './plugin'
9
+
10
+ const featureFlags = () => {
11
+ return {
12
+ id: 'featureFlags',
13
+ definitions: [
14
+ {
15
+ definition: featureFlagsDefinition,
16
+ writesAtoms: ['featureFlagAtoms'],
17
+ },
18
+ {
19
+ definition: featureFlagAtomsDefinition,
20
+ storage: { namespace: 'featureFlags' },
21
+ aliases: [
22
+ {
23
+ implementationId: 'unsafeStorage',
24
+ interfaceId: 'storage',
25
+ },
26
+ ],
27
+ },
28
+ { definition: featureFlagsAtomDefinition },
29
+ { definition: remoteConfigFeatureFlagAtomsDefinition },
30
+ { definition: featureFlagsPlugin },
31
+ ],
32
+ }
33
+ }
34
+
35
+ export default featureFlags
@@ -0,0 +1,18 @@
1
+ const createFeatureFlagsLifecyclePlugin = ({ featureFlags }) => {
2
+ const onStart = () => {
3
+ featureFlags.load()
4
+ }
5
+
6
+ const onClear = async () => {
7
+ await featureFlags.clear()
8
+ }
9
+
10
+ return { onStart, onClear }
11
+ }
12
+
13
+ export default {
14
+ id: 'featureFlagsLifecyclePlugin',
15
+ type: 'plugin',
16
+ factory: createFeatureFlagsLifecyclePlugin,
17
+ dependencies: ['featureFlags'],
18
+ }
@@ -0,0 +1,16 @@
1
+ import feeMonitorsDefinition from '@exodus/fee-monitors/monitor'
2
+
3
+ import feesPlugin from './plugin'
4
+
5
+ const fees = () => {
6
+ return {
7
+ id: 'fees',
8
+ definitions: [
9
+ // ...
10
+ { definition: feeMonitorsDefinition },
11
+ { definition: feesPlugin },
12
+ ],
13
+ }
14
+ }
15
+
16
+ export default fees
@@ -0,0 +1,17 @@
1
+ const createFeesLifecyclePlugin = ({ feeMonitors, port }) => {
2
+ feeMonitors.on('fees-load', () => port.emit('fees-load', feeMonitors.getAllFeeData()))
3
+ feeMonitors.on('fees-update', (payload) => port.emit('fees-update', payload))
4
+
5
+ const onUnlock = () => {
6
+ feeMonitors.start()
7
+ }
8
+
9
+ return { onUnlock }
10
+ }
11
+
12
+ export default {
13
+ id: 'feesLifecyclePlugin',
14
+ type: 'plugin',
15
+ factory: createFeesLifecyclePlugin,
16
+ dependencies: ['feeMonitors', 'port'],
17
+ }
@@ -0,0 +1,34 @@
1
+ const createWalletApi = ({ wallet, application, passphraseCache }) => {
2
+ const restoreFromCurrentPhrase = async ({ passphrase } = {}) => {
3
+ if (!passphrase) passphrase = await passphraseCache.get()
4
+ const mnemonic = await application.getMnemonic({ passphrase })
5
+ await application.import({ passphrase, mnemonic })
6
+ }
7
+
8
+ return {
9
+ wallet: {
10
+ exists: () => wallet.exists(),
11
+ start: application.start,
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
+ changeLockTimer: application.changeLockTimer,
23
+ restoreFromCurrentPhrase,
24
+ isLocked: () => wallet.isLocked(),
25
+ },
26
+ }
27
+ }
28
+
29
+ export default {
30
+ id: 'walletApi',
31
+ type: 'api',
32
+ factory: createWalletApi,
33
+ dependencies: ['wallet', 'application', 'passphraseCache'],
34
+ }
@@ -0,0 +1,24 @@
1
+ import walletDefinition from '@exodus/wallet/module'
2
+
3
+ import walletApi from './api'
4
+ import lockedAtomDefinition from './locked-atom'
5
+ import restoreAtomDefinition from './restore-atom'
6
+ import restorePluginDefinition from './restore-plugin'
7
+
8
+ const wallet = () => {
9
+ return {
10
+ id: 'wallet',
11
+ definitions: [
12
+ {
13
+ definition: { type: 'module', ...walletDefinition },
14
+ writesAtoms: ['lockedAtom'],
15
+ },
16
+ { definition: lockedAtomDefinition },
17
+ { definition: restoreAtomDefinition },
18
+ { definition: restorePluginDefinition },
19
+ { definition: walletApi },
20
+ ],
21
+ }
22
+ }
23
+
24
+ export default wallet
@@ -0,0 +1,10 @@
1
+ import { createInMemoryAtom } from '@exodus/atoms'
2
+
3
+ const lockedAtomDefinition = {
4
+ id: 'lockedAtom',
5
+ type: 'atom',
6
+ factory: () => createInMemoryAtom({ defaultValue: true }),
7
+ dependencies: [],
8
+ }
9
+
10
+ export default lockedAtomDefinition
@@ -11,6 +11,7 @@ const restorePlugin = ({ restoreAtom }) => {
11
11
 
12
12
  export default {
13
13
  id: 'restorePlugin',
14
+ type: 'plugin',
14
15
  factory: restorePlugin,
15
16
  dependencies: ['restoreAtom'],
16
17
  }
@@ -1,6 +1,5 @@
1
1
  import autoEnableAssetsPlugin from '@exodus/auto-enable-assets-plugin'
2
2
 
3
3
  import logLifecyclePlugin from './log-lifecycle'
4
- import restorePlugin from './restore'
5
4
 
6
- export default [logLifecyclePlugin, restorePlugin, autoEnableAssetsPlugin]
5
+ export default [logLifecyclePlugin, autoEnableAssetsPlugin]
@@ -1,25 +0,0 @@
1
- import {
2
- featureFlagAtomsDefinition,
3
- remoteConfigFeatureFlagAtomsDefinition,
4
- } from '@exodus/feature-flags/atoms'
5
-
6
- import { withType } from './utils'
7
-
8
- const createAtomCollectionDependencies = () =>
9
- [
10
- {
11
- definition: remoteConfigFeatureFlagAtomsDefinition,
12
- },
13
- {
14
- definition: featureFlagAtomsDefinition,
15
- storage: { namespace: 'featureFlags' },
16
- aliases: [
17
- {
18
- implementationId: 'unsafeStorage',
19
- interfaceId: 'storage',
20
- },
21
- ],
22
- },
23
- ].map(withType('atom-collection'))
24
-
25
- export default createAtomCollectionDependencies
@@ -1,15 +0,0 @@
1
- import apyRatesMonitorDefinition from '@exodus/apy-rates/monitor'
2
- import feeMonitorsDefinition from '@exodus/fee-monitors/monitor'
3
-
4
- import { withType } from './utils'
5
-
6
- const createMonitorDependencies = ({ config }) =>
7
- [
8
- { definition: feeMonitorsDefinition },
9
- {
10
- definition: apyRatesMonitorDefinition,
11
- writesAtoms: ['apyRatesAtom'],
12
- },
13
- ].map(withType('monitor'))
14
-
15
- export default createMonitorDependencies