Skip to content

Commit

Permalink
fix: Better serialization in state
Browse files Browse the repository at this point in the history
The previous way was causing a loss of precision.
  • Loading branch information
RabbitDoge committed Dec 15, 2020
1 parent 27c9c90 commit 388d696
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 15 deletions.
4 changes: 3 additions & 1 deletion src/hooks/rework/useBnbBalance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ const useUserBnbBalance = () => {
console.error(error)
}
}
fetch()
if (account) {
fetch()
}
}, [account, web3, block])

return balance
Expand Down
8 changes: 4 additions & 4 deletions src/state/farms/fetchFarmUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ const fetchFarmUser = async (pid: number, account: string) => {
])

return {
allowance: new BigNumber(allowance).toNumber(),
tokenBalance: new BigNumber(tokenBalance).toNumber(),
allowance: new BigNumber(allowance).toJSON(),
tokenBalance: new BigNumber(tokenBalance).toJSON(),
// eslint-disable-next-line no-underscore-dangle
stakedBalance: new BigNumber(userInfo[0]._hex).toNumber(),
earnings: new BigNumber(earnings).toNumber(),
stakedBalance: new BigNumber(userInfo[0]._hex).toJSON(),
earnings: new BigNumber(earnings).toJSON(),
}
}

Expand Down
10 changes: 5 additions & 5 deletions src/state/farms/fetchFarms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,11 @@ const fetchFarms = async () => {

return {
...farmConfig,
tokenAmount: tokenAmount.toNumber(),
quoteTokenAmount: quoteTokenAmount.toNumber(),
lpTotalInQuoteToken: lpTotalInQuoteToken.toNumber(),
tokenPriceVsQuote: quoteTokenAmount.div(tokenAmount).toNumber(),
poolWeight: poolWeight.toNumber(),
tokenAmount: tokenAmount.toJSON(),
quoteTokenAmount: quoteTokenAmount.toJSON(),
lpTotalInQuoteToken: lpTotalInQuoteToken.toJSON(),
tokenPriceVsQuote: quoteTokenAmount.div(tokenAmount).toJSON(),
poolWeight: poolWeight.toJSON(),
}
}),
)
Expand Down
8 changes: 4 additions & 4 deletions src/state/pools/fetchPools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ export const fetchPoolsBlockLimits = async () => {
const endBlock = ends[index]
return {
sousId: cakePoolConfig.sousId,
startBlock: new BigNumber(startBlock).toNumber(),
endBlock: new BigNumber(endBlock).toNumber(),
startBlock: new BigNumber(startBlock).toJSON(),
endBlock: new BigNumber(endBlock).toJSON(),
}
})
}
Expand Down Expand Up @@ -64,11 +64,11 @@ export const fetchPoolsTotalStatking = async () => {
return [
...cakePools.map((p, index) => ({
sousId: p.sousId,
totalStaked: new BigNumber(cakePoolsTotalStaked[index]).toNumber(),
totalStaked: new BigNumber(cakePoolsTotalStaked[index]).toJSON(),
})),
...bnbPool.map((p, index) => ({
sousId: p.sousId,
totalStaked: new BigNumber(bnbPoolsTotalStaked[index]).toNumber(),
totalStaked: new BigNumber(bnbPoolsTotalStaked[index]).toJSON(),
})),
]
}
4 changes: 3 additions & 1 deletion src/views/Farms/components/FarmCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,9 @@ const FarmCard: React.FC<FarmCardProps> = ({ farm, removed }) => {
return farm.lpTotalInQuoteToken
}, [bnbPrice, cakePrice, farm.lpTotalInQuoteToken, farm.quoteTokenSymbol])

const totalValueFormated = totalValue ? `$${Number(totalValue.toFixed(0)).toLocaleString()}` : '-'
const totalValueFormated = totalValue
? `$${Number(totalValue).toLocaleString(undefined, { maximumFractionDigits: 0 })}`
: '-'

return (
<FCard>
Expand Down

0 comments on commit 388d696

Please sign in to comment.