fix bug related to missing pledges on first time load

This commit is contained in:
Barry Gitarts 2019-01-28 12:13:03 -05:00
parent c5cd136e17
commit c918c456ed
2 changed files with 10 additions and 2 deletions

View File

@ -57,7 +57,7 @@ function SimpleCard(props) {
<Typography variant="h5" className={classes.cardTitle}>
{title}
</Typography>
{!!transfers &&
{!!transfers && !!pledges.length &&
Object.entries(getDepositWithdrawTotals({ transfers, pledges, vaultEvents }))
.map(token => {
const [name, amounts] = token

View File

@ -42,14 +42,22 @@ export const getPledgesWaitingCommit = createSelector(
const formatAndSumDepositWithdraws = (deposits, pledges, withdraws) => {
const tokens = {}
let incomplete = false
deposits.forEach(deposit => {
const { amount, to } = deposit.returnValues
const { token } = pledges.find(p => Number(p.pledgeId) === Number(to))
const pledge = pledges.find(p => Number(p.pledgeId) === Number(to))
if (!pledge) {
incomplete = true
return
}
const { token } = pledge
const tokenName = getTokenLabel(token)
if (tokens[tokenName]) tokens[tokenName]['deposits'] = BigInt(tokens[tokenName]['deposits']) + BigInt(amount)
else tokens[tokenName] = { 'deposits': BigInt(amount) }
})
if (incomplete) return {}
withdraws
.filter(w => !isNaN(Number(w.returnValues.ref.slice(2))))
.forEach(withdraw => {