@ exodus/ fiat- 平衡
基于应用程序的地由和 用户首选的货币。对于加密计价余额,请核对 @ exodus/ 余额。 。 。 .
安装
pnpm add @exodus/fiat-balances
使用量
此特性设计为与 @exodus/headless。见 使用 sdk。 。 。 .
来玩吧
- 打开游乐场 https://exodus-hydra.pages.dev/ 页面存档备份,存于互联网档案馆
- 运行
selectors.fiatBalances.byAsset(store.getState())在Dev Tools Console中,通过已启用的钱包账户,按资产汇总来获取无益余额. - 试试其他选择者
selectors.fiatBalances。参见示例使用 测试。 。 。 . - 用平衡键锁定地址,勾选区块链显示器并检查您的平衡.
// 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 ETH balance in the user's preferred currency
selectors.fiatBalances.byAsset(store.getState()).ethereum.toDefaultString({ unit: true }) // 123.45 USD
// change currency
await exodus.locale.setCurrency('EUR')
selectors.fiatBalances.byAsset(store.getState()).ethereum.toDefaultString({ unit: true }) // 6.78 EUR
API 边
见 使用 sdk 更多关于特性插入SDK的细节。 注意,余额特性目前不提供顶级API,意在纯粹通过选择器使用.
如果你正在构建一个需要平衡的特性, 加上对 fiatBalancesAtom 现改为:.
const myModuleDefinition = {
id: 'myModule',
type: 'module',
factory: ({ fiatBalancesAtom }) => {
const doSomethingSpecial = async () => {
const { balances } = await fiatBalancesAtom.get()
console.log(
'>>> total wallet balance',
balances.totals.balance.toDefaultString({ unit: true })
)
}
return {
doSomethingSpecial,
}
},
dependencies: ['fiatBalancesAtom'],
}
UI 侧
见 使用 sdk 关于基本UI侧设置的更多细节.
import { selectors } from '~/ui/flux'
const MyComponent = () => {
const totalWalletBalance = useSelector(
selectors.fiatBalances.optimisticTotalBalance(store.getState())
) // returns a NumberUnit
// create a function to convert ethereum to the user's preferred currency
const ethToFiat = useSelector(selectors.fiatBalances.createAssetConversion('ethereum'))
const ethBalanceInFiat = ethToFiat(ethereum.currency.defaultUnit(1))
}