diff --git a/web/cashtab/src/components/Common/Ticker.js b/web/cashtab/src/components/Common/Ticker.js --- a/web/cashtab/src/components/Common/Ticker.js +++ b/web/cashtab/src/components/Common/Ticker.js @@ -12,6 +12,7 @@ coingeckoId: 'bitcoin-cash-abc-2', defaultFee: 5.01, dust: '0.00000546', // The minimum amount of BCHA that can be sent by the app + cashDecimals: 8, blockExplorerUrl: 'https://explorer.bitcoinabc.org', blockExplorerUrlTestnet: 'https://texplorer.bitcoinabc.org', tokenName: 'Bitcoin ABC SLP', diff --git a/web/cashtab/src/components/Send/Send.js b/web/cashtab/src/components/Send/Send.js --- a/web/cashtab/src/components/Send/Send.js +++ b/web/cashtab/src/components/Send/Send.js @@ -353,10 +353,12 @@ try { const txFeeSats = calcFee(BCH, slpBalancesAndUtxos.nonSlpUtxos); - const txFeeBch = txFeeSats / 1e8; + const txFeeBch = txFeeSats / 10 ** currency.cashDecimals; let value = balances.totalBalance - txFeeBch >= 0 - ? (balances.totalBalance - txFeeBch).toFixed(8) + ? (balances.totalBalance - txFeeBch).toFixed( + currency.cashDecimals, + ) : 0; setFormData({ diff --git a/web/cashtab/src/hooks/useWallet.js b/web/cashtab/src/hooks/useWallet.js --- a/web/cashtab/src/hooks/useWallet.js +++ b/web/cashtab/src/hooks/useWallet.js @@ -734,7 +734,7 @@ You received{' '} {Number( balances.totalBalance - previousBalances.totalBalance, - ).toFixed(8)}{' '} + ).toFixed(currency.cashDecimals)}{' '} BCH! ), diff --git a/web/cashtab/src/utils/__tests__/validation.test.js b/web/cashtab/src/utils/__tests__/validation.test.js --- a/web/cashtab/src/utils/__tests__/validation.test.js +++ b/web/cashtab/src/utils/__tests__/validation.test.js @@ -65,18 +65,18 @@ expectedValidationError, ); }); - it(`Returns precision error if ${currency.ticker} send amount has more than 8 decimal places`, () => { - const expectedValidationError = `${currency.ticker} transactions do not support more than 8 decimal places`; + it(`Returns precision error if ${currency.ticker} send amount has more than ${currency.cashDecimals} decimal places`, () => { + const expectedValidationError = `${currency.ticker} transactions do not support more than ${currency.cashDecimals} decimal places`; expect( shouldRejectAmountInput('17.123456789', currency.ticker, 20.0, 35), ).toBe(expectedValidationError); }); - it(`Returns expected crypto amount with 8 decimals of precision even if inputs have higher precision`, () => { + it(`Returns expected crypto amount with ${currency.cashDecimals} decimals of precision even if inputs have higher precision`, () => { expect(fiatToCrypto('10.97231694823432', 20.3231342349234234)).toBe( '0.53989295', ); }); - it(`Returns expected crypto amount with 8 decimals of precision even if inputs have lower precision`, () => { + it(`Returns expected crypto amount with ${currency.cashDecimals} decimals of precision even if inputs have lower precision`, () => { expect(fiatToCrypto('10.94', 10)).toBe('1.09400000'); }); }); diff --git a/web/cashtab/src/utils/validation.js b/web/cashtab/src/utils/validation.js --- a/web/cashtab/src/utils/validation.js +++ b/web/cashtab/src/utils/validation.js @@ -27,8 +27,10 @@ } else if (testedAmount.gt(totalCashBalance)) { error = `Amount cannot exceed your ${currency.ticker} balance`; } else if (!isNaN(testedAmount) && testedAmount.toString().includes('.')) { - if (testedAmount.toString().split('.')[1].length > 8) { - error = `${currency.ticker} transactions do not support more than 8 decimal places`; + if ( + testedAmount.toString().split('.')[1].length > currency.cashDecimals + ) { + error = `${currency.ticker} transactions do not support more than ${currency.cashDecimals} decimal places`; } } // return false if no error, or string error msg if error @@ -36,9 +38,8 @@ }; export const fiatToCrypto = (fiatAmount, fiatPrice) => { - // Return a string with no more than 8 decimal places let cryptoAmount = new BigNumber(fiatAmount) .div(new BigNumber(fiatPrice)) - .toFixed(8); + .toFixed(currency.cashDecimals); return cryptoAmount; };