fix: withdraw/deposit converts from BZZ (10^16 base units) (#66)

* refactor: added toBZZbaseUnit function

* feat: added utility for attesting value is BZZ convertible to base units

* fix: conversion from 15 to 16 decimal places, added unsafe versions

* refactor: withdraw modal uses the safe conversion from BZZ

* refactor: added BigNumber and Token class to handle BZZ digits correctly

* refactor: extract deposit and withdraw functionality into single modal

* test: added tests for Token

* chore: removed unused component

* chore: addressed PR review, token decimal is now integer 0-18

* chore: added comment to clarify the value restriction on token amount
This commit is contained in:
Vojtech Simetka
2021-04-13 12:26:29 +02:00
committed by GitHub
parent 343e388498
commit 825772cf73
19 changed files with 411 additions and 238 deletions
+4 -4
View File
@@ -1,4 +1,4 @@
import React, { ReactElement } from 'react'
import type { ReactElement } from 'react'
import { makeStyles } from '@material-ui/core/styles'
import {
Table,
@@ -12,7 +12,7 @@ import {
CircularProgress,
} from '@material-ui/core'
import { ConvertBalanceToBZZ } from '../../utils/common'
import { fromBZZbaseUnit } from '../../utils'
import EthereumAddress from '../../components/EthereumAddress'
import ClipboardCopy from '../../components/ClipboardCopy'
import PeerDetailDrawer from './PeerDetailDrawer'
@@ -80,7 +80,7 @@ function ChequebookTable(props: Props): ReactElement {
<p style={{ marginBottom: '0px', fontFamily: 'monospace, monospace', display: 'flex' }}>
<span style={{ whiteSpace: 'nowrap', marginRight: '12px', paddingTop: '3px' }}>
{peerCheque.lastreceived?.payout
? `${ConvertBalanceToBZZ(peerCheque.lastreceived?.payout).toFixed(7).toLocaleString()} from`
? `${fromBZZbaseUnit(peerCheque.lastreceived?.payout).toFixed(7).toLocaleString()} from`
: '-'}
</span>
{peerCheque.lastreceived ? (
@@ -97,7 +97,7 @@ function ChequebookTable(props: Props): ReactElement {
<p style={{ marginBottom: '0px', fontFamily: 'monospace, monospace', display: 'flex' }}>
<span style={{ whiteSpace: 'nowrap', marginRight: '12px', paddingTop: '3px' }}>
{peerCheque.lastsent?.payout
? `${ConvertBalanceToBZZ(peerCheque.lastsent?.payout).toFixed(7).toLocaleString()} to`
? `${fromBZZbaseUnit(peerCheque.lastsent?.payout).toFixed(7).toLocaleString()} to`
: '-'}
</span>
{peerCheque.lastsent ? (