@exodus/atoms 2.5.1 → 2.6.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/README.md +91 -0
- package/package.json +2 -2
- package/src/factories/disabled-assets.js +17 -0
- package/src/index.js +1 -0
package/README.md
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
# `@exodus/atoms`
|
|
2
|
+
|
|
3
|
+
Module to store and manage wallet accounts instances.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
yarn add @exodus/atoms
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## What is an atom?
|
|
12
|
+
|
|
13
|
+
An atom is a data source wrapper that exposes a single piece of data through 3 different methods:
|
|
14
|
+
|
|
15
|
+
- **get()**: read data
|
|
16
|
+
- **set(newValue)**: write data
|
|
17
|
+
- **observe(async (data) => {})**: observes data changes. Will be called initially with current data value. Observers are awaited in series.
|
|
18
|
+
|
|
19
|
+
## Data sources
|
|
20
|
+
|
|
21
|
+
This library provides helpers for creating atoms from multiple data sources we use in our apps
|
|
22
|
+
|
|
23
|
+
| | get | set | observe |
|
|
24
|
+
| ------------- | --- | ----- | ------- |
|
|
25
|
+
| Memory | ✅ | ✅ | ✅ |
|
|
26
|
+
| Storage | ✅ | 🟡 \* | ✅ |
|
|
27
|
+
| Fusion | ✅ | ✅ | ✅ |
|
|
28
|
+
| Remote config | ✅ | ❌ | ✅ |
|
|
29
|
+
| Local config | ✅ | ✅ | ✅ |
|
|
30
|
+
| Event emitter | ✅ | ❌ | ✅ |
|
|
31
|
+
|
|
32
|
+
\* A storage atom needs a special `isSoleWriter` param to allow write access. This is because storage instances can overlap, e.g. a parent namespace can mutate a child namespace, and our [storage-spec](https://github.com/ExodusMovement/exodus-hydra/tree/master/modules/storage-spec) doesn't currently provide for detecting changes across those instances.
|
|
33
|
+
|
|
34
|
+
## Usage
|
|
35
|
+
|
|
36
|
+
```js
|
|
37
|
+
import {
|
|
38
|
+
createInMemoryAtom,
|
|
39
|
+
createStorageAtomFactory,
|
|
40
|
+
createFusionAtomFactory,
|
|
41
|
+
createRemoteConfigAtomFactory,
|
|
42
|
+
fromEventEmitter,
|
|
43
|
+
} from '@exodus/atoms'
|
|
44
|
+
|
|
45
|
+
// In memory atoms
|
|
46
|
+
const availableAssetNamesAtom = createInMemoryAtom({
|
|
47
|
+
defaultValue: {},
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
// Storage atoms
|
|
51
|
+
const storageAtomFactory = createStorageAtomFactory({ storage })
|
|
52
|
+
|
|
53
|
+
const acceptedTermsAtom = storageAtomFactory({
|
|
54
|
+
key: 'acceptedTerms',
|
|
55
|
+
defaultValue: false,
|
|
56
|
+
isSoleWriter: true,
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
// Fusion atoms
|
|
60
|
+
const fusionAtomFactory = createFusionAtomFactory({ fusion })
|
|
61
|
+
|
|
62
|
+
const shareActivityAtom = createFusionAtom({
|
|
63
|
+
path: 'shareActivity',
|
|
64
|
+
defaultValue: true,
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
// Remote config atoms
|
|
68
|
+
const createRemoteConfigAtom = createRemoteConfigAtomFactory({ remoteConfig })
|
|
69
|
+
|
|
70
|
+
const fiatOnrampConfigAtom = createRemoteConfigAtom({
|
|
71
|
+
path: `dapps.fiatOnramp`,
|
|
72
|
+
defaultValue: {},
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
// Event emitter
|
|
76
|
+
const geolocationAtom = fromEventEmitter({
|
|
77
|
+
emitter: geolocation,
|
|
78
|
+
event: 'geolocation',
|
|
79
|
+
get: geolocation.get,
|
|
80
|
+
})
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## Helper functions
|
|
84
|
+
|
|
85
|
+
### compute({ atom, selector })
|
|
86
|
+
|
|
87
|
+
Computes an atom from another by applying a selector function to the observed data source. Returned atom is read-only, i.e. **set** will fail.
|
|
88
|
+
|
|
89
|
+
### withSerialization({ atom, serialize, deserialize })
|
|
90
|
+
|
|
91
|
+
Computes an atom from another by serializing it's data after reading it and deserializing it before writing it.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@exodus/atoms",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.6.0",
|
|
4
4
|
"main": "src/index.js",
|
|
5
5
|
"author": "Exodus Movement Inc.",
|
|
6
6
|
"scripts": {
|
|
@@ -30,5 +30,5 @@
|
|
|
30
30
|
"delay": "^5.0.0",
|
|
31
31
|
"jest": "^29.1.2"
|
|
32
32
|
},
|
|
33
|
-
"gitHead": "
|
|
33
|
+
"gitHead": "485c99f84ca2f34c485e20411778f786e9b00c31"
|
|
34
34
|
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { compute } from '../index'
|
|
2
|
+
|
|
3
|
+
const createDisabledAssetsAtom = ({ enabledAndDisabledAssetsAtom }) => {
|
|
4
|
+
const selector = (values) =>
|
|
5
|
+
Object.fromEntries(
|
|
6
|
+
Object.keys(values.disabled)
|
|
7
|
+
.filter((assetName) => {
|
|
8
|
+
const disabled = values.disabled[assetName]
|
|
9
|
+
return disabled === true
|
|
10
|
+
})
|
|
11
|
+
.map((assetName) => [assetName, true])
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
return compute({ atom: enabledAndDisabledAssetsAtom, selector })
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export default createDisabledAssetsAtom
|
package/src/index.js
CHANGED
|
@@ -5,6 +5,7 @@ export { default as createStorageAtomFactory } from './factories/storage'
|
|
|
5
5
|
export { default as createLocalConfigAtomFactory } from './factories/local-config'
|
|
6
6
|
export { default as createRemoteConfigAtomFactory } from './factories/remote-config'
|
|
7
7
|
export { default as createEnabledAssetsAtom } from './factories/enabled-assets'
|
|
8
|
+
export { default as createDisabledAssetsAtom } from './factories/disabled-assets'
|
|
8
9
|
export { default as fromEventEmitter } from './event-emitter'
|
|
9
10
|
export { default as compute } from './enhancers/compute'
|
|
10
11
|
export { default as difference } from './enhancers/difference'
|