Skip to content

Commit

Permalink
Cast to bigNumber values returned by contracts
Browse files Browse the repository at this point in the history
  • Loading branch information
fernandomg committed Mar 16, 2018
1 parent d5f825a commit b5e8c22
Showing 1 changed file with 8 additions and 23 deletions.
31 changes: 8 additions & 23 deletions src/components/crowdsale/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,23 +153,14 @@ export function getAccumulativeCrowdsaleData() {
if (!crowdsaleContract) return noContractAlert()

let getWeiRaised = crowdsaleContract.methods.weiRaised().call().then((weiRaised) => {
let newWeiRaised
if (crowdsalePageStore.weiRaised) {
newWeiRaised = crowdsalePageStore.weiRaised + parseInt(weiRaised, 10);
} else {
newWeiRaised = parseInt(weiRaised, 10);
}

crowdsalePageStore.setProperty('weiRaised', newWeiRaised)
crowdsalePageStore.setProperty('ethRaised', parseFloat(web3.utils.fromWei(toFixed(crowdsalePageStore.weiRaised).toString(), 'ether')))
const storedWeiRaised = toBigNumber(crowdsalePageStore.weiRaised)
crowdsalePageStore.setProperty('weiRaised', storedWeiRaised.plus(weiRaised).toFixed())
crowdsalePageStore.setProperty('ethRaised', web3.utils.fromWei(crowdsalePageStore.weiRaised, 'ether'))
})

let getTokensSold = crowdsaleContract.methods.tokensSold().call().then((tokensSold) => {
if (crowdsalePageStore.tokensSold) {
crowdsalePageStore.setProperty('tokensSold', crowdsalePageStore.tokensSold + parseInt(tokensSold, 10))
} else {
crowdsalePageStore.setProperty('tokensSold', parseInt(tokensSold, 10))
}
const storedTokensSold = toBigNumber(crowdsalePageStore.tokensSold)
crowdsalePageStore.setProperty('tokensSold', storedTokensSold.plus(tokensSold).toFixed())
})

let getMaximumSellableTokens = crowdsaleContract.methods.maximumSellableTokens().call().then((maximumSellableTokens) => {
Expand All @@ -181,15 +172,9 @@ export function getAccumulativeCrowdsaleData() {
})

let getInvestors = crowdsaleContract.methods.investorCount().call().then((investors) => {
const oldInvestors = crowdsalePageStore.investors
const investorsCount = parseInt(investors, 10)

if (oldInvestors) {
crowdsalePageStore.setProperty('investors', oldInvestors + investorsCount);
} else {
crowdsalePageStore.setProperty('investors', investorsCount);
}
});
const storedInvestorsCount = toBigNumber(crowdsalePageStore.investors)
crowdsalePageStore.setProperty('investors', storedInvestorsCount.plus(investors).toFixed())
})

return Promise.all([getWeiRaised, getTokensSold, getMaximumSellableTokens, getInvestors])
})
Expand Down

0 comments on commit b5e8c22

Please sign in to comment.