@exodus/balances
This Exodus SDK feature tracks the crypto-denominated balances for all enabled wallet accounts. For fiat-denominated balances, check out @exodus/fiat-balances.
Install
npm i @exodus/balancesUsage
This feature is designed to be used together with @exodus/headless. See using the sdk.
API Side
See using the sdk for more details on how features plug into the SDK. Note that the balances feature currently doesn’t provide a top level API and is meant to be used purely through selectors.
If you’re building a feature that requires balances, add a dependency on the balancesAtom as below. See also the available balance fields .
const myModuleDefinition = {
id: 'myModule',
type: 'module',
factory: ({ balancesAtom }) => {
const doSomethingSpecial = async () => {
// {
// [walletAccount]: {
// [assetName]: {
// // e.g. 'total', 'spendable', 'unconfirmedSent', 'unconfirmedReceived'
// [balanceField]: NumberUnit, // see @exodus/currency
// }
// }
// }
const { balances } = await balancesAtom.get();
// ...
};
return {
doSomethingSpecial,
};
},
dependencies: ['balancesAtom'],
};UI Side
See using the sdk for more details on basic UI-side setup.
import { selectors } from '~/ui/flux';
const MyComponent = () => {
const bitcoinBalance = useSelector(
selectors.balances.createSpendable({
assetName: 'bitcoin',
walletAccount: 'exodus_0',
})
); // returns a NumberUnit
};To read balances aggregated by asset across all enabled wallet accounts, use selectors.balances.byAsset:
const AggregateView = () => {
const balancesByAsset = useSelector(selectors.balances.byAsset);
// { bitcoin: NumberUnit, ethereum: NumberUnit, ... }
};See tests for additional selector usage examples.
Contributing
Do NOT introduce any asset specifics like if (assetName === 'dogicorn') balance = balance.mul(2). All asset-specifics belong in asset.api.getBalances or other APIs inside the
asset libraries.
