fix: display very small numbers as .toString(10)

pull/2/merge
Szymon Lesisz 6 years ago
parent b67315e180
commit 4d43a4acc4

@ -130,22 +130,19 @@ export const calculateFee = (gasPrice: string, gasLimit: string): string => {
export const calculateTotal = (amount: string, gasPrice: string, gasLimit: string): string => {
try {
// return new BigNumber(amount).plus( calculateFee(gasPrice, gasLimit) ).toString();
const fee = calculateFee(gasPrice, gasLimit);
return new BigNumber(amount).plus( calculateFee(gasPrice, gasLimit) ).toFixed(16);
return new BigNumber(amount).plus( calculateFee(gasPrice, gasLimit) ).toString(10);
} catch (error) {
return '0';
}
}
export const calculateMaxAmount = (balance: string, gasPrice: string, gasLimit: string): string => {
export const calculateMaxAmount = (balance: BigNumber, gasPrice: string, gasLimit: string): string => {
try {
// TODO - minus pendings
const fee = calculateFee(gasPrice, gasLimit);
const b = new BigNumber(balance);
const max = b.minus(fee);
const max = balance.minus(fee);
if (max.lessThan(0)) return '0';
return max.toString();
return max.toString(10);
} catch (error) {
return '0';
}
@ -181,10 +178,10 @@ export const calculate = (prevProps: Props, props: Props) => {
if (isToken) {
const token: ?Token = findToken(tokens, account.address, state.currency, account.deviceState);
if (token) {
state.amount = new BigNumber(token.balance).minus(pendingAmount).toString();
state.amount = new BigNumber(token.balance).minus(pendingAmount).toString(10);
}
} else {
const b = new BigNumber(account.balance).minus(pendingAmount).toString();
const b = new BigNumber(account.balance).minus(pendingAmount);
state.amount = calculateMaxAmount(b, state.gasPrice, state.gasLimit);
}
}
@ -203,8 +200,8 @@ export const calculate = (prevProps: Props, props: Props) => {
export const getFeeLevels = (symbol: string, gasPrice: BigNumber | string, gasLimit: string, selected?: FeeLevel): Array<FeeLevel> => {
const price: BigNumber = typeof gasPrice === 'string' ? new BigNumber(gasPrice) : gasPrice
const quarter: BigNumber = price.dividedBy(4);
const high: string = price.plus(quarter.times(2)).toString();
const low: string = price.minus(quarter.times(2)).toString();
const high: string = price.plus(quarter.times(2)).toString(10);
const low: string = price.minus(quarter.times(2)).toString(10);
const customLevel: FeeLevel = selected && selected.value === 'Custom' ? {
value: 'Custom',
@ -226,7 +223,7 @@ export const getFeeLevels = (symbol: string, gasPrice: BigNumber | string, gasLi
{
value: 'Normal',
gasPrice: gasPrice.toString(),
label: `${ calculateFee(price.toString(), gasLimit) } ${ symbol }`
label: `${ calculateFee(price.toString(10), gasLimit) } ${ symbol }`
},
{
value: 'Low',
@ -843,7 +840,7 @@ export const onSend = (): AsyncAction => {
if (!token) return;
const contract = web3.erc20.at(token.address);
const amountValue: string = new BigNumber(currentState.amount).times( Math.pow(10, token.decimals) ).toString();
const amountValue: string = new BigNumber(currentState.amount).times( Math.pow(10, token.decimals) ).toString(10);
data = contract.transfer.getData(currentState.address, amountValue, {
from: account.address,

@ -275,7 +275,7 @@ export function getTokenBalance(token: Token): AsyncAction {
contract.balanceOf(token.ethAddress, (error: Error, balance: BigNumber) => {
if (balance) {
const newBalance: string = balance.dividedBy( Math.pow(10, token.decimals) ).toString();
const newBalance: string = balance.dividedBy( Math.pow(10, token.decimals) ).toString(10);
if (newBalance !== token.balance) {
dispatch(TokenActions.setBalance(
token.address,
@ -371,7 +371,7 @@ export const getTokenBalanceAsync = (erc20: ContractFactory, token: Token): Prom
if (error) {
reject(error);
} else {
const newBalance: string = balance.dividedBy( Math.pow(10, token.decimals) ).toString();
const newBalance: string = balance.dividedBy( Math.pow(10, token.decimals) ).toString(10);
resolve(newBalance);
}
});

@ -36,7 +36,7 @@ const Summary = (props: Props) => {
const explorerLink: string = `${network.explorer.address}${account.address}`;
const pendingAmount: BigNumber = stateUtils.getPendingAmount(pending, network.symbol);
const balance: string = new BigNumber(account.balance).minus(pendingAmount).toString();
const balance: string = new BigNumber(account.balance).minus(pendingAmount).toString(10);
return (
<div>

@ -39,7 +39,7 @@ const AccountSelection = (props: Props): ?React$Element<string> => {
if (account.balance !== '') {
const pending = stateUtils.getAccountPendingTx(props.pending, account);
const pendingAmount: BigNumber = stateUtils.getPendingAmount(pending, selectedCoin.symbol);
const availableBalance: string = new BigNumber(account.balance).minus(pendingAmount).toString();
const availableBalance: string = new BigNumber(account.balance).minus(pendingAmount).toString(10);
if (fiatRate) {
const accountBalance = new BigNumber(availableBalance);

Loading…
Cancel
Save