@exodus/ui-config 3.1.1 → 3.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md ADDED
@@ -0,0 +1,49 @@
1
+ # Change Log
2
+
3
+ All notable changes to this project will be documented in this file.
4
+ See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
+
6
+ ## [3.3.0](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/ui-config@3.2.0...@exodus/ui-config@3.3.0) (2023-11-13)
7
+
8
+ ### Features
9
+
10
+ - support default value in ui config ([#4751](https://github.com/ExodusMovement/exodus-hydra/issues/4751)) ([74bc7c7](https://github.com/ExodusMovement/exodus-hydra/commit/74bc7c7f7a707e5e209d5c880feaa3f6a41e7c5a))
11
+
12
+ ## [3.2.0](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/ui-config@3.1.1...@exodus/ui-config@3.2.0) (2023-10-04)
13
+
14
+ ### Features
15
+
16
+ - **ui-config:** do not emit using atom id ([#4342](https://github.com/ExodusMovement/exodus-hydra/issues/4342)) ([df9d7b6](https://github.com/ExodusMovement/exodus-hydra/commit/df9d7b67bbca1c351128afd2e7a76a718dd71a79))
17
+ - **ui-config:** support unecrypted ui-configs ([#4286](https://github.com/ExodusMovement/exodus-hydra/issues/4286)) ([b4f7923](https://github.com/ExodusMovement/exodus-hydra/commit/b4f792369c145a7d84b30bf2e2237f9be053caf9))
18
+
19
+ ## [3.1.1](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/ui-config@3.1.0...@exodus/ui-config@3.1.1) (2023-09-19)
20
+
21
+ ### Bug Fixes
22
+
23
+ - **ui-config:** watch on app restart ([#4086](https://github.com/ExodusMovement/exodus-hydra/issues/4086)) ([cc7ef5b](https://github.com/ExodusMovement/exodus-hydra/commit/cc7ef5b3b8df9d3a28fd6277a695e3778948a745))
24
+
25
+ ## [3.1.0](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/ui-config@3.0.0...@exodus/ui-config@3.1.0) (2023-09-05)
26
+
27
+ ### Features
28
+
29
+ - ui-config redux ([#3842](https://github.com/ExodusMovement/exodus-hydra/issues/3842)) ([d9e9f33](https://github.com/ExodusMovement/exodus-hydra/commit/d9e9f33cd6d2d0b96f48a821d2eb3f331ebb570c))
30
+
31
+ ## [3.0.0](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/ui-config@2.0.0...@exodus/ui-config@3.0.0) (2023-09-01)
32
+
33
+ ### ⚠ BREAKING CHANGES
34
+
35
+ - **ui-config:** expose utils to compute events (#3819)
36
+
37
+ ### Features
38
+
39
+ - **ui-config:** expose utils to compute events ([#3819](https://github.com/ExodusMovement/exodus-hydra/issues/3819)) ([32d8bfd](https://github.com/ExodusMovement/exodus-hydra/commit/32d8bfd0a992ee25c9771dfe875683a4b8c8ae3d))
40
+
41
+ ## [2.0.0](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/ui-config@1.0.0...@exodus/ui-config@2.0.0) (2023-08-11)
42
+
43
+ ### ⚠ BREAKING CHANGES
44
+
45
+ - change ui config data structure (#3294)
46
+
47
+ ### Features
48
+
49
+ - change ui config data structure ([#3294](https://github.com/ExodusMovement/exodus-hydra/issues/3294)) ([eaceb99](https://github.com/ExodusMovement/exodus-hydra/commit/eaceb99ad4310255ff70769435f16f2daa43ce5a))
package/api/index.js CHANGED
@@ -1,26 +1,17 @@
1
- import { mapValues } from '@exodus/basic-utils'
2
- import { merge } from 'lodash'
1
+ const createUiConfigApiDefinition = ({ configValues }) => {
2
+ const atomIds = configValues.map((v) => v.atomId)
3
3
 
4
- const createUiConfigApiDefinition = ({ atomIds, atomConfigMap }) => {
5
4
  return {
6
5
  definition: {
7
6
  type: 'api',
8
7
  id: 'uiConfig',
9
8
  factory: ({ ...atoms }) => {
10
- const uiConfig = merge(
11
- ...Object.values(
12
- mapValues(atoms, (atom, atomId) => ({
13
- // assetsShowPriceMapAtom -> getAssetsShowPriceMap, setAssetsShowPriceMap
14
- [atomConfigMap[atomId]]: {
15
- set: atom.set,
16
- get: atom.get,
17
- },
18
- }))
19
- )
20
- )
21
- return {
22
- uiConfig,
23
- }
9
+ const uiConfig = configValues.reduce((acc, { id, atomId }) => {
10
+ acc[id] = { get: atoms[atomId].get, set: atoms[atomId].set }
11
+ return acc
12
+ }, {})
13
+
14
+ return { uiConfig }
24
15
  },
25
16
  dependencies: atomIds,
26
17
  },
package/atoms/index.js ADDED
@@ -0,0 +1,19 @@
1
+ import { createStorageAtomFactory } from '@exodus/atoms'
2
+
3
+ const createUiConfigAtomDefinitions = ({ configValues }) => {
4
+ return configValues.map(({ id, atomId, encrypted, defaultValue }) => ({
5
+ definition: {
6
+ id: atomId,
7
+ type: 'atom',
8
+ factory: ({ storage }) =>
9
+ createStorageAtomFactory({ storage })({ key: id, isSoleWriter: true, defaultValue }),
10
+ dependencies: ['storage'],
11
+ },
12
+ aliases: [
13
+ { implementationId: encrypted ? 'storage' : 'unsafeStorage', interfaceId: 'storage' },
14
+ ],
15
+ storage: { namespace: 'uiConfig' },
16
+ }))
17
+ }
18
+
19
+ export default createUiConfigAtomDefinitions
package/index.js CHANGED
@@ -1,39 +1,19 @@
1
- import { createStorageAtomFactory } from '@exodus/atoms'
2
-
3
1
  import createUiConfigApiDefinition from './api'
2
+ import createUiConfigAtomDefinitions from './atoms'
4
3
  import createUiConfigPluginDefinition from './plugin'
5
4
  import { getAtomId } from './utils'
6
5
 
7
6
  export { getConfigReduxEvents, getEventReduxMap } from './utils'
8
7
 
9
8
  const createUiConfigFeatureDefinition = ({ config }) => {
10
- const configValues = Object.values(config)
11
- const configAtomMap = Object.fromEntries(configValues.map(({ id }) => [id, getAtomId(id)]))
12
- const atomConfigMap = Object.fromEntries(
13
- Object.keys(configAtomMap).map((configId) => [configAtomMap[configId], configId])
14
- )
15
- const atoms = configValues.map(({ id }) => ({
16
- definition: {
17
- id: configAtomMap[id],
18
- type: 'atom',
19
- factory: ({ storage, config }) =>
20
- createStorageAtomFactory({ storage })({
21
- key: id,
22
- isSoleWriter: true,
23
- }),
24
- dependencies: ['storage'],
25
- },
26
- storage: { namespace: 'uiConfig' },
27
- }))
28
-
29
- const atomIds = Object.keys(atomConfigMap)
9
+ const configValues = Object.values(config).map((v) => ({ ...v, atomId: getAtomId(v.id) }))
30
10
 
31
11
  return {
32
12
  id: 'uiConfigFeatureDefinition',
33
13
  definitions: [
34
- ...atoms,
35
- createUiConfigApiDefinition({ atomIds, atomConfigMap }),
36
- createUiConfigPluginDefinition({ atomIds, atomConfigMap }),
14
+ ...createUiConfigAtomDefinitions({ configValues }),
15
+ createUiConfigApiDefinition({ configValues }),
16
+ createUiConfigPluginDefinition({ configValues }),
37
17
  ],
38
18
  }
39
19
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@exodus/ui-config",
3
- "version": "3.1.1",
3
+ "version": "3.3.0",
4
4
  "description": "Helper for storing various UI-specific settings/config.",
5
5
  "author": "Exodus Movement Inc.",
6
6
  "license": "UNLICENSED",
@@ -14,12 +14,14 @@
14
14
  },
15
15
  "main": "index.js",
16
16
  "files": [
17
- "README.md",
18
- "utils.js",
19
- "plugin",
20
17
  "api",
21
- "utils",
18
+ "atoms",
19
+ "plugin",
22
20
  "redux",
21
+ "utils",
22
+ "CHANGELOG.md",
23
+ "utils.js",
24
+ "README.md",
23
25
  "!**/__tests__/**"
24
26
  ],
25
27
  "scripts": {
@@ -28,9 +30,9 @@
28
30
  "test": "jest"
29
31
  },
30
32
  "dependencies": {
31
- "@exodus/atoms": "^5.7.0",
33
+ "@exodus/atoms": "^6.0.1",
32
34
  "@exodus/basic-utils": "^2.1.0",
33
- "@exodus/formatting": "^1.2.0",
35
+ "@exodus/formatting": "^1.2.1",
34
36
  "lodash": "^4.17.21"
35
37
  },
36
38
  "devDependencies": {
@@ -39,5 +41,5 @@
39
41
  "jest": "^29.1.2",
40
42
  "redux": "^4.2.1"
41
43
  },
42
- "gitHead": "09e3da68a572818d13afe37482019e1a91c5df73"
44
+ "gitHead": "de55f8221ff7aaad1386858dbccd93951f7e7004"
43
45
  }
package/plugin/index.js CHANGED
@@ -1,27 +1,29 @@
1
1
  import { createAtomObserver } from '@exodus/atoms'
2
2
 
3
- const factory = ({ port, ...atoms }) => {
4
- const atomObservers = Object.entries(atoms).map(([atomId, atom]) =>
5
- createAtomObserver({ port, atom, event: atomId })
6
- )
3
+ const createUiConfigPluginDefinition = ({ configValues }) => {
4
+ const atomIds = configValues.map((v) => v.atomId)
7
5
 
8
- atomObservers.forEach((observer) => observer.register())
6
+ const factory = ({ port, ...atoms }) => {
7
+ const atomObservers = configValues.map(({ id, atomId }) =>
8
+ createAtomObserver({ port, atom: atoms[atomId], event: id })
9
+ )
10
+
11
+ return {
12
+ onLoad: () => atomObservers.forEach((observer) => observer.start()),
13
+ onClear: () => Promise.all(Object.values(atoms).map((atom) => atom.set(undefined))),
14
+ onStop: () => atomObservers.forEach((observer) => observer.unregister()),
15
+ }
16
+ }
9
17
 
10
18
  return {
11
- onLoad: () => atomObservers.forEach((observer) => observer.start()),
12
- onClear: () => Promise.all(Object.values(atoms).map((atom) => atom.set(undefined))),
13
- onStop: () => atomObservers.forEach((observer) => observer.unregister()),
19
+ definition: {
20
+ type: 'plugin',
21
+ id: 'uiConfigPlugin',
22
+ factory,
23
+ dependencies: ['port', ...atomIds],
24
+ },
25
+ writesAtoms: atomIds,
14
26
  }
15
27
  }
16
28
 
17
- const createUiConfigPluginDefinition = ({ atomIds }) => ({
18
- definition: {
19
- type: 'plugin',
20
- id: 'uiConfigPlugin',
21
- factory,
22
- dependencies: ['port', ...atomIds],
23
- },
24
- writesAtoms: atomIds,
25
- })
26
-
27
29
  export default createUiConfigPluginDefinition
package/redux/index.js CHANGED
@@ -1,17 +1,12 @@
1
1
  import id from './id'
2
- import { getAtomId } from '../utils'
3
2
 
4
3
  const createUiConfigReduxDefinition = (config) => {
5
4
  const configValues = Object.values(config)
6
- const configAtomMap = configValues.map(({ id }) => [id, getAtomId(id)])
5
+
7
6
  const initialState = Object.fromEntries(configValues.map(({ id }) => [id, undefined]))
7
+
8
8
  const eventReducers = Object.fromEntries(
9
- configAtomMap.map(([configId, atomId]) => [
10
- atomId,
11
- (state, payload) => {
12
- return { ...state, [configId]: payload }
13
- },
14
- ])
9
+ configValues.map(({ id }) => [id, (state, payload) => ({ ...state, [id]: payload })])
15
10
  )
16
11
 
17
12
  return {