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
65
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@exodus/balances

Tracks crypto balances across enabled wallet accounts.

  • 13.2.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.6K
decreased by-17.18%
Maintainers
0
Weekly downloads
 
Created
Source

@exodus/balances

Install

yarn add @exodus/balances

Usage

Like all Exodus SDK features, the balances feature consists of:

  • A feature that plugs into the Exodus SDK in your logical or actual background process. This provides the balancesAtom to other features.
  • A redux module that plugs into the Exodus SDK in the UI process. This provides selectors for getting various balances.

Setup

In the background process, plug balances into the SDK:

import balances from '@exodus/balances'

// sdk is an instance of `@exodus/argo` or `@exodus/headless`
sdk.use(balances())

In the UI process, plug the balances redux module into the SDK:

import { setupRedux } from '@exodus/redux-dependency-injection'
import balances from '@exodus/balances/redux'

const { selectors, createHandleEvent, reducers, initialState } = setupRedux({
  dependencies: [
    // other redux modules
    // ...
    balances,
  ],
})

const handleEvent = createHandleEvent(store) // store is a redux store

Connect the background process to the UI process. In a multi-process app, you will need a transport layer:

// forward SDK events to the UI process so the relevant redux module can handle them
sdk.subscribe(({ type, payload }) => handleEvent(type, payload))

Consuming Balances

In your feature you can now depend on the balancesAtom

const myModuleFactory = ({ balancesAtom }) => {
  const doSomethingSpecial = async () => {
    // {
    //   [walletAccount]: {
    //     [assetName]: {
    //       // e.g. 'total', 'spendable', 'unconfirmedSent', 'unconfirmedReceived'
    //       [balanceField]: NumberUnit, // see @exodus/currency
    //     }
    //   }
    // }
    const { balances } = await balancesAtom.get()
    // ...
  }

  return {
    doSomethingSpecial,
  }
}

const myModuleDefinition = {
  id: 'myModule',
  type: 'module',
  factory: myModuleFactory,
  dependencies: ['balancesAtom'],
}
// in UI
const MyComponent = () => {
  const bitcoinBalance = useSelector(
    selectors.balances.createSpendable({
      assetName: 'bitcoin',
      walletAccount: 'exodus_0',
    })
  ) // returns a NumberUnit
}

Playground

Try the balances selectors in the sdk-playground.

In this repo root, run:

yarn --cwd apps/sdk-playground dev

Open http://localhost:8008 in the browser and run the following in the dev tools console:

// mock your ethereum address with one that has a balance
await exodus.debug.addressProvider.mockAddress({
  assetName: 'ethereum',
  walletAccount: 'exodus_0',
  address: '0x1111111111111111111111111111111111111111',
})
// force tick the ethereum monitor, or wait a while
await exodus.txLogMonitors.update({ assetName: 'ethereum', refresh: true })
// check your balance
selectors.balances.createTotal({ assetName: 'ethereum', walletAccount: 'exodus_0' })(
  store.getState()
)

Contributing

WARNING: no asset specifics!

If you introduce any asset specifics like if (assetName === 'dogicorn') balance = balance.mul(2), you will be fired immediately. This is a safety measure to save you from @feri42's wrath. All asset-specifics belong in asset.api.getBalances or other APIs inside the asset libraries.

FAQs

Package last updated on 18 Jul 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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