New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@exodus/balances

Package Overview
Dependencies
Maintainers
0
Versions
66
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@exodus/balances - npm Package Compare versions

Comparing version 11.2.2 to 12.0.0

17

atoms/has-balance.js

@@ -1,2 +0,2 @@

import { compute } from '@exodus/atoms'
import { compute, createStorageAtomFactory } from '@exodus/atoms'
import { flatMap, map } from 'lodash'

@@ -6,3 +6,3 @@

const createHasBalanceAtom = ({ balancesAtom }) => {
const createComputedAtom = ({ balancesAtom }) => {
const selector = ({ balances } = {}) => {

@@ -16,2 +16,15 @@ const numberUnits = flatMap(balances, (value) => map(value, 'balance'))

const createHasBalanceAtom = ({ balancesAtom, storage }) => {
const storageAtom = createStorageAtomFactory({ storage })({
key: 'hasBalance',
defaultValue: false,
isSoleWriter: true,
})
const computedAtom = createComputedAtom({ balancesAtom })
// eslint-disable-next-line @exodus/hydra/no-eternal-subscription
computedAtom.observe((value) => storageAtom.set(value))
return storageAtom
}
export default createHasBalanceAtom

2

atoms/index.js

@@ -15,3 +15,3 @@ import createBalancesAtom from './balances'

factory: createHasBalanceAtom,
dependencies: ['balancesAtom'],
dependencies: ['balancesAtom', 'storage'],
}

@@ -6,2 +6,21 @@ # Change Log

## [12.0.0](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/balances@11.2.2...@exodus/balances@12.0.0) (2023-11-23)
### ⚠ BREAKING CHANGES
- use `assetsAtom` instead of legacy event (#4838)
### Features
- has balance stored ([#4856](https://github.com/ExodusMovement/exodus-hydra/issues/4856)) ([510ffd5](https://github.com/ExodusMovement/exodus-hydra/commit/510ffd517c22bbbcb16441275f1ab71ffcc7de90))
### Bug Fixes
- cleanup subscriptions on stop ([#4814](https://github.com/ExodusMovement/exodus-hydra/issues/4814)) ([d053582](https://github.com/ExodusMovement/exodus-hydra/commit/d0535826c2023dd4d3273b367bbcc5cca6e4bb95))
- zero balance after send is ignore ([#4725](https://github.com/ExodusMovement/exodus-hydra/issues/4725)) ([56c5d35](https://github.com/ExodusMovement/exodus-hydra/commit/56c5d35ca1643e869c112d0166df036ec988088f))
### Code Refactoring
- use `assetsAtom` instead of legacy event ([#4838](https://github.com/ExodusMovement/exodus-hydra/issues/4838)) ([33260c3](https://github.com/ExodusMovement/exodus-hydra/commit/33260c3fd48286d00a940a4e5ec4956326f8c3c1))
## [11.2.2](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/balances@11.2.1...@exodus/balances@11.2.2) (2023-11-06)

@@ -8,0 +27,0 @@

@@ -25,5 +25,9 @@ import balancesDefinition from './module'

{ definition: balancesAtomDefinition },
{ definition: hasBalanceAtomDefinition },
{
definition: hasBalanceAtomDefinition,
storage: { namespace: 'balances' },
aliases: [{ implementationId: 'unsafeStorage', interfaceId: 'storage' }],
},
{ definition: balancesReportDefinition },
{ definition: balancesPluginDefinition },
{ definition: balancesPluginDefinition, writesAtoms: ['hasBalanceAtom'] },
],

@@ -30,0 +34,0 @@ }

@@ -24,2 +24,3 @@ import { isNumberUnit } from '@exodus/currency'

#assetsModule
#assetsAtom
#balanceFields

@@ -36,5 +37,7 @@ #walletAccounts = [] // string[]

#loaded = false
#subscriptions = []
constructor({
assetsModule,
assetsAtom,
enabledWalletAccountsAtom,

@@ -50,2 +53,3 @@ config: { balanceFields },

this.#assetsModule = assetsModule
this.#assetsAtom = assetsAtom
this.#balanceFields = balanceFields

@@ -98,19 +102,23 @@ this.#balancesAtom = balancesAtom

this.#loaded = true
this.#enabledWalletAccountsAtom.observe((payload) => {
this.#setWalletAccounts(Object.keys(payload))
})
this.#accountStatesAtom.observe(({ changes }) =>
flattenToPaths(changes).forEach(([walletAccount, assetName, accountState]) =>
this.#handleAccountStateUpdate({ walletAccount, assetName, accountState })
)
this.#subscriptions.push(
this.#enabledWalletAccountsAtom.observe((payload) => {
this.#setWalletAccounts(Object.keys(payload))
}),
this.#accountStatesAtom.observe(({ changes }) =>
flattenToPaths(changes).forEach(([walletAccount, assetName, accountState]) =>
this.#handleAccountStateUpdate({ walletAccount, assetName, accountState })
)
),
this.#txLogsAtom.observe(({ changes }) =>
flattenToPaths(changes).forEach(([walletAccount, assetName, txLog]) =>
this.#handleTxLogUpdate({ walletAccount, assetName, txLog })
)
),
this.#assetsAtom.observe(({ added }) => {
if (added.length > 0) {
this.#onAssetsChanged(added)
}
})
)
this.#txLogsAtom.observe(({ changes }) =>
flattenToPaths(changes).forEach(([walletAccount, assetName, txLog]) =>
this.#handleTxLogUpdate({ walletAccount, assetName, txLog })
)
)
this.#assetsModule.on('assets-add', this.#onAssetsChanged)
}

@@ -167,3 +175,4 @@

const balances = asset.api.getBalances({ asset, accountState, txLog })
if (!balances || isEmpty(balances) || !balances.balance) return null
if (!balances || isEmpty(balances) || !balances.balance)
return Object.fromEntries(this.#balanceFields.map((field) => [field, asset.currency.ZERO]))
if (!balances.balance.unitType.equals(asset.currency)) {

@@ -388,2 +397,7 @@ this.emit('error', {

}
stop = () => {
this.#subscriptions.forEach((unsubscribe) => unsubscribe())
this.#subscriptions = []
}
}

@@ -405,2 +419,3 @@

'accountStatesAtom',
'assetsAtom',
],

@@ -407,0 +422,0 @@ }

{
"name": "@exodus/balances",
"version": "11.2.2",
"version": "12.0.0",
"description": "Tracks crypto balances across enabled wallet accounts.",

@@ -48,3 +48,3 @@ "author": "Exodus Movement Inc.",

"@exodus/assets-base": "^8.1.10",
"@exodus/assets-feature": "^3.7.0",
"@exodus/assets-feature": "^4.0.0",
"@exodus/bitcoin-meta": "^1.0.1",

@@ -56,3 +56,3 @@ "@exodus/blockchain-metadata": "^9.0.1",

"@exodus/storage-memory": "*",
"@exodus/wallet-accounts": "^14.2.0",
"@exodus/wallet-accounts": "^14.3.0",
"eslint": "^8.44.0",

@@ -63,3 +63,3 @@ "events": "^3.3.0",

},
"gitHead": "1c23ddca93850c0a40da742a5cefd2e42b554356"
"gitHead": "0c943e6a82e29239305544665711c1b1b4a98fce"
}
import { createAtomObserver } from '@exodus/atoms'
const createBalancesPlugin = ({ balancesAtom, port, balances }) => {
const createBalancesPlugin = ({ balancesAtom, port, balances, hasBalanceAtom }) => {
const balancesAtomObserver = createAtomObserver({

@@ -11,3 +11,11 @@ port,

const hasBalanceAtomObserver = createAtomObserver({
port,
atom: hasBalanceAtom,
event: 'hasBalance',
})
hasBalanceAtomObserver.register()
const onLoad = () => {
hasBalanceAtomObserver.start()
balancesAtomObserver.start()

@@ -20,7 +28,14 @@

balancesAtomObserver.unregister()
hasBalanceAtomObserver.unregister()
balances.stop()
}
const onClear = async () => {
await hasBalanceAtom.set(undefined)
}
return {
onLoad,
onStop,
onClear,
}

@@ -33,5 +48,5 @@ }

factory: createBalancesPlugin,
dependencies: ['balancesAtom', 'port', 'balances'],
dependencies: ['balancesAtom', 'port', 'balances', 'hasBalanceAtom'],
}
export default balancesPluginDefinition

@@ -46,4 +46,11 @@ import id from './id'

return setAccounts(state, payload.balances)
return {
hasBalance: state.hasBalance,
...setAccounts(state, payload.balances),
}
},
hasBalance: (state, payload) => ({
...state,
hasBalance: payload,
}),
},

@@ -50,0 +57,0 @@ selectorDefinitions: [...helper.selectorDefinitions, ...selectorDefinitions],

import helper from './multi-account-helper'
const initialState = helper.createInitialState()
const initialState = {
hasBalance: false,
...helper.createInitialState(),
}
export default initialState
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc