Untitled
unknown
javascript
2 years ago
2.1 kB
5
Indexable
export const getTotalInvestmentMade = (transactions) => { let totalInvestment = 0 transactions?.forEach((transaction) => { if (transaction.type === 'INVESTMENT') { totalInvestment += parseFloat(transaction.amount) } }) return totalInvestment } export const getTotalDistributionMade = (transactions) => { let totalDistribution = 0 transactions?.forEach((transaction) => { if (transaction.type === 'DISTRIBUTION') { totalDistribution += parseFloat(transaction.amount) } }) return totalDistribution } export const getTotalInvestmentForAsset = (transactions, assetId) => { let totalInvestment = 0 transactions?.forEach((transaction) => { if (transaction.type === 'INVESTMENT' && transaction.asset === assetId) { totalInvestment += parseFloat(transaction.amount) } }) return totalInvestment } export const getTotalDistributionForAsset = (transactions, assetId) => { let totalDistribution = 0 transactions?.forEach((transaction) => { if (transaction.type === 'DISTRIBUTION' && transaction.asset === assetId) { totalDistribution += parseFloat(transaction.amount) } }) return totalDistribution } export const getNumberOfAssetInvestedIn = (transactions) => { let assetInvestedIn = [] transactions?.forEach((transaction) => { if (transaction.type === 'INVESTMENT' && !assetInvestedIn.includes(transaction.asset)) { assetInvestedIn.push(transaction.asset) } }) return assetInvestedIn.length } export const getAssetsInvestedIn = (transactions) => { let assetInvestedIn = [] transactions?.forEach((transaction) => { if (transaction.type === 'INVESTMENT' && !assetInvestedIn.includes(transaction.asset)) { assetInvestedIn.push(transaction.asset) } }) return assetInvestedIn } export const getAssetFromAssetList = (assets, assetId) => { return assets.filter(asset => asset.id === assetId)[0] }
Editor is loading...