UNPKG

@cranberry-money/shared-utils

Version:

Shared utility functions for Blueberry platform

28 lines 1.06 kB
import { getChainName, BLOCKCHAIN } from '@cranberry-money/shared-constants'; /** * Calculate aggregated wallet totals by blockchain type. * Sums native balances and market values for BTC and ETH wallets. */ export function calculateWalletTotals(wallets) { return wallets.reduce((acc, wallet) => { const balance = parseFloat(wallet.nativeBalance) || 0; const marketValue = parseFloat(wallet.marketValue) || 0; const chain = getChainName(wallet.chain); if (chain === BLOCKCHAIN.BITCOIN) { acc.btc += balance; acc.btcMarketValue += marketValue; } else if (chain === BLOCKCHAIN.ETHEREUM) { acc.eth += balance; acc.ethMarketValue += marketValue; } return acc; }, { btc: 0, eth: 0, btcMarketValue: 0, ethMarketValue: 0 }); } /** * Filter wallets by blockchain type. */ export function filterWalletsByChain(wallets, blockchain) { return wallets.filter((w) => getChainName(w.chain) === blockchain); } //# sourceMappingURL=wallet.js.map