diff --git a/web/cashtab/src/components/Airdrop/Airdrop.js b/web/cashtab/src/components/Airdrop/Airdrop.js --- a/web/cashtab/src/components/Airdrop/Airdrop.js +++ b/web/cashtab/src/components/Airdrop/Airdrop.js @@ -23,7 +23,7 @@ import { getWalletState, convertEtokenToEcashAddr, - fromSmallestDenomination, + fromSatoshis, convertToEcashPrefix, convertEcashtoEtokenAddr, } from 'utils/cashMethods'; @@ -312,7 +312,7 @@ if (ignoreRecipientsBelowDust) { // minimum airdrop threshold const minEligibleAirdrop = new BigNumber( - fromSmallestDenomination(currency.dustSats), + fromSatoshis(currency.dustSats), ); // first calculation on expected pro rata airdrops @@ -628,9 +628,7 @@ />  Ignore airdrops below min. payment ( - {fromSmallestDenomination( - currency.dustSats, - )}{' '} + {fromSatoshis(currency.dustSats)}{' '} XEC) @@ -753,7 +751,7 @@ You need at least{' '} - {fromSmallestDenomination(currency.dustSats).toString()}{' '} + {fromSatoshis(currency.dustSats).toString()}{' '} {currency.ticker} ( {cashtabSettings ? `${ @@ -63,9 +63,8 @@ }` : '$'} {( - fromSmallestDenomination( - currency.dustSats, - ).toString() * fiatPrice + fromSatoshis(currency.dustSats).toString() * + fiatPrice ).toFixed(4)}{' '} {cashtabSettings ? `${currency.fiatCurrencies[ diff --git a/web/cashtab/src/hooks/__mocks__/sendBCH.js b/web/cashtab/src/hooks/__mocks__/sendBCH.js --- a/web/cashtab/src/hooks/__mocks__/sendBCH.js +++ b/web/cashtab/src/hooks/__mocks__/sendBCH.js @@ -1,4 +1,4 @@ -import { fromSmallestDenomination } from 'utils/cashMethods'; +import { fromSatoshis } from 'utils/cashMethods'; import { currency } from 'components/Common/Ticker'; export default { @@ -29,7 +29,7 @@ }, destinationAddress: 'bitcoincash:qr2npxqwznhp7gphatcqzexeclx0hhwdxg386ez36n', - sendAmount: fromSmallestDenomination(currency.dustSats).toString(), + sendAmount: fromSatoshis(currency.dustSats).toString(), expectedTxId: '7a39961bbd7e27d804fb3169ef38a83234710fbc53897a4eb0c98454854a26d1', expectedHex: [ diff --git a/web/cashtab/src/hooks/__tests__/migrations.test.js b/web/cashtab/src/hooks/__tests__/migrations.test.js --- a/web/cashtab/src/hooks/__tests__/migrations.test.js +++ b/web/cashtab/src/hooks/__tests__/migrations.test.js @@ -1,72 +1,65 @@ import { currency } from '../../components/Common/Ticker'; import BigNumber from 'bignumber.js'; import BCHJS from '@psf/bch-js'; -import { - fromSmallestDenomination, - toSmallestDenomination, -} from 'utils/cashMethods'; +import { fromSatoshis, toSatoshis } from 'utils/cashMethods'; describe('Testing functions for upgrading Cashtab', () => { it('Replacement currency.dustSats parameter parsing matches legacy DUST parameter', () => { expect( parseFloat( new BigNumber( - fromSmallestDenomination(currency.dustSats, 8).toString(), + fromSatoshis(currency.dustSats, 8).toString(), ).toFixed(8), ), ).toBe(0.0000055); }); - it('Replicate 8-decimal return value from instance of toSatoshi in TransactionBuilder with toSmallestDenomination', () => { + it('Replicate 8-decimal return value from instance of toSatoshi in TransactionBuilder with toSatoshis', () => { const BCH = new BCHJS(); const testSendAmount = '0.12345678'; - expect( - parseInt(toSmallestDenomination(new BigNumber(testSendAmount), 8)), - ).toBe(BCH.BitcoinCash.toSatoshi(Number(testSendAmount).toFixed(8))); + expect(parseInt(toSatoshis(new BigNumber(testSendAmount), 8))).toBe( + BCH.BitcoinCash.toSatoshi(Number(testSendAmount).toFixed(8)), + ); }); - it('Replicate 2-decimal return value from instance of toSatoshi in TransactionBuilder with toSmallestDenomination', () => { + it('Replicate 2-decimal return value from instance of toSatoshi in TransactionBuilder with toSatoshis', () => { const BCH = new BCHJS(); const testSendAmount = '0.12'; - expect( - parseInt(toSmallestDenomination(new BigNumber(testSendAmount), 8)), - ).toBe(BCH.BitcoinCash.toSatoshi(Number(testSendAmount).toFixed(8))); + expect(parseInt(toSatoshis(new BigNumber(testSendAmount), 8))).toBe( + BCH.BitcoinCash.toSatoshi(Number(testSendAmount).toFixed(8)), + ); }); - it('Replicate 8-decimal return value from instance of toSatoshi in remainder comparison with toSmallestDenomination', () => { + it('Replicate 8-decimal return value from instance of toSatoshi in remainder comparison with toSatoshis', () => { const BCH = new BCHJS(); - expect( - parseFloat(toSmallestDenomination(new BigNumber('0.00000546'), 8)), - ).toBe( + expect(parseFloat(toSatoshis(new BigNumber('0.00000546'), 8))).toBe( BCH.BitcoinCash.toSatoshi( parseFloat(new BigNumber('0.00000546').toFixed(8)), ), ); }); - it('toSmallestDenomination() returns false if input is not a BigNumber', () => { + it('toSatoshis() returns false if input is not a BigNumber', () => { const testInput = 132.12345678; - expect(toSmallestDenomination(testInput)).toBe(false); + expect(toSatoshis(testInput)).toBe(false); }); - it(`toSmallestDenomination() returns false if input is a BigNumber with more decimals than specified by cashDecimals parameter`, () => { + it(`toSatoshis() returns false if input is a BigNumber with more decimals than specified by cashDecimals parameter`, () => { const testInput = new BigNumber('132.123456789'); - expect(toSmallestDenomination(testInput, 8)).toBe(false); + expect(toSatoshis(testInput, 8)).toBe(false); }); - it(`toSmallestDenomination() returns expected value if input is a BigNumber with 8 decimal places`, () => { + it(`toSatoshis() returns expected value if input is a BigNumber with 8 decimal places`, () => { const testInput = new BigNumber('100.12345678'); - expect(toSmallestDenomination(testInput, 8)).toStrictEqual( + expect(toSatoshis(testInput, 8)).toStrictEqual( new BigNumber('10012345678'), ); }); - it(`toSmallestDenomination() returns expected value if input is a BigNumber with 2 decimal places`, () => { + it(`toSatoshis() returns expected value if input is a BigNumber with 2 decimal places`, () => { const testInput = new BigNumber('100.12'); - expect(toSmallestDenomination(testInput, 2)).toStrictEqual( - new BigNumber('10012'), - ); + expect(toSatoshis(testInput, 2)).toStrictEqual(new BigNumber('10012')); }); - it(`toSmallestDenomination() returns expected value if input is a BigNumber with 1 decimal place`, () => { + it(`toSatoshis() returns expected value if input is a BigNumber with 1 decimal place`, () => { const testInput = new BigNumber('100.1'); - expect(toSmallestDenomination(testInput, 8)).toStrictEqual( + expect(toSatoshis(testInput, 8)).toStrictEqual( new BigNumber('10010000000'), ); }); - it('toSmallestDenomination() returns exact result as toSatoshi but in BigNumber format', () => { + it('toSatoshis() returns exact result as toSatoshi but in BigNumber format', () => { const BCH = new BCHJS(); const testAmount = new BigNumber('0.12345678'); @@ -75,7 +68,7 @@ testAmount.toFixed(8), ); - const testAmountInCashDecimals = toSmallestDenomination(testAmount, 8); + const testAmountInCashDecimals = toSatoshis(testAmount, 8); expect(testAmountInSatoshis).toStrictEqual(12345678); expect(testAmountInCashDecimals).toStrictEqual( @@ -84,10 +77,7 @@ }); it(`BigNumber version of remainder variable is equivalent to Math.floor version`, () => { // Test case for sending 0.12345678 BCHA - let satoshisToSendTest = toSmallestDenomination( - new BigNumber('0.12345678'), - 8, - ); + let satoshisToSendTest = toSatoshis(new BigNumber('0.12345678'), 8); // Assume total BCHA available in utxos is 500 sats higher than 0.123456578 BCHA let originalAmountTest = satoshisToSendTest.plus(500); // Assume 229 byte tx fee @@ -107,32 +97,30 @@ const remainder = new BigNumber('12345678'); expect(parseInt(remainder)).toStrictEqual(12345678); }); - it('Replicates return value from instance of toBitcoinCash with fromSmallestDenomination and cashDecimals = 8', () => { + it('Replicates return value from instance of toBitcoinCash with fromSatoshis and cashDecimals = 8', () => { const BCH = new BCHJS(); const testSendAmount = '12345678'; - expect(fromSmallestDenomination(testSendAmount, 8)).toBe( + expect(fromSatoshis(testSendAmount, 8)).toBe( BCH.BitcoinCash.toBitcoinCash(testSendAmount), ); }); - it('Replicates largest possible digits return value from instance of toBitcoinCash with fromSmallestDenomination and cashDecimals = 8', () => { + it('Replicates largest possible digits return value from instance of toBitcoinCash with fromSatoshis and cashDecimals = 8', () => { const BCH = new BCHJS(); const testSendAmount = '1000000012345678'; - expect(fromSmallestDenomination(testSendAmount, 8)).toBe( + expect(fromSatoshis(testSendAmount, 8)).toBe( BCH.BitcoinCash.toBitcoinCash(testSendAmount), ); }); - it('Replicates smallest unit value return value from instance of toBitcoinCash with fromSmallestDenomination and cashDecimals = 8', () => { + it('Replicates smallest unit value return value from instance of toBitcoinCash with fromSatoshis and cashDecimals = 8', () => { const BCH = new BCHJS(); const testSendAmount = '1'; - expect(fromSmallestDenomination(testSendAmount, 8)).toBe( + expect(fromSatoshis(testSendAmount, 8)).toBe( BCH.BitcoinCash.toBitcoinCash(testSendAmount), ); }); it(`Converts dust limit in satoshis to dust limit in current app setting`, () => { - expect(fromSmallestDenomination(currency.dustSats, 8).toString()).toBe( - '0.0000055', - ); + expect(fromSatoshis(currency.dustSats, 8).toString()).toBe('0.0000055'); }); }); diff --git a/web/cashtab/src/hooks/__tests__/useBCH.test.js b/web/cashtab/src/hooks/__tests__/useBCH.test.js --- a/web/cashtab/src/hooks/__tests__/useBCH.test.js +++ b/web/cashtab/src/hooks/__tests__/useBCH.test.js @@ -38,7 +38,7 @@ import BCHJS from '@psf/bch-js'; // TODO: should be removed when external lib not needed anymore import { currency } from '../../components/Common/Ticker'; import BigNumber from 'bignumber.js'; -import { fromSmallestDenomination } from 'utils/cashMethods'; +import { fromSatoshis } from 'utils/cashMethods'; describe('useBCH hook', () => { it('gets Rest Api Url on testnet', () => { @@ -279,9 +279,7 @@ false, null, destinationAddress, - new BigNumber( - fromSmallestDenomination(currency.dustSats).toString(), - ) + new BigNumber(fromSatoshis(currency.dustSats).toString()) .minus(new BigNumber('0.00000001')) .toString(), ); diff --git a/web/cashtab/src/hooks/useBCH.js b/web/cashtab/src/hooks/useBCH.js --- a/web/cashtab/src/hooks/useBCH.js +++ b/web/cashtab/src/hooks/useBCH.js @@ -3,8 +3,8 @@ import { isValidTokenStats } from 'utils/validation'; import SlpWallet from 'minimal-slp-wallet'; import { - toSmallestDenomination, - fromSmallestDenomination, + toSatoshis, + fromSatoshis, batchArray, flattenBatchedHydratedUtxos, isValidStoredWallet, @@ -1434,9 +1434,7 @@ if ( value.lt( new BigNumber( - fromSmallestDenomination( - currency.dustSats, - ).toString(), + fromSatoshis(currency.dustSats).toString(), ), ) ) { @@ -1457,9 +1455,7 @@ if ( value.lt( new BigNumber( - fromSmallestDenomination( - currency.dustSats, - ).toString(), + fromSatoshis(currency.dustSats).toString(), ), ) ) { @@ -1476,9 +1472,9 @@ transactionBuilder = new BCH.TransactionBuilder(); else transactionBuilder = new BCH.TransactionBuilder('testnet'); - const satoshisToSend = toSmallestDenomination(value); + const satoshisToSend = toSatoshis(value); - // Throw validation error if toSmallestDenomination returns false + // Throw validation error if toSatoshis returns false if (!satoshisToSend) { const error = new Error( `Invalid decimal places for send amount`, @@ -1631,14 +1627,14 @@ ); transactionBuilder.addOutput( BCH.Address.toCashAddress(outputAddress), - parseInt(toSmallestDenomination(outputValue)), + parseInt(toSatoshis(outputValue)), ); } } else { // for one to one mode, add output w/ single address and amount to send transactionBuilder.addOutput( BCH.Address.toCashAddress(destinationAddress), - parseInt(toSmallestDenomination(value)), + parseInt(toSatoshis(value)), ); } 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 @@ -4,7 +4,7 @@ import useBCH from 'hooks/useBCH'; import BigNumber from 'bignumber.js'; import { - fromSmallestDenomination, + fromSatoshis, loadStoredWallet, isValidStoredWallet, isLegacyMigrationRequired, @@ -124,7 +124,7 @@ ); return { totalBalanceInSatoshis, - totalBalance: fromSmallestDenomination(totalBalanceInSatoshis), + totalBalance: fromSatoshis(totalBalanceInSatoshis), }; }; diff --git a/web/cashtab/src/utils/__tests__/cashMethods.test.js b/web/cashtab/src/utils/__tests__/cashMethods.test.js --- a/web/cashtab/src/utils/__tests__/cashMethods.test.js +++ b/web/cashtab/src/utils/__tests__/cashMethods.test.js @@ -1,7 +1,7 @@ import { ValidationError } from 'ecashaddrjs'; import BigNumber from 'bignumber.js'; import { - fromSmallestDenomination, + fromSatoshis, batchArray, flattenContactList, flattenBatchedHydratedUtxos, @@ -35,7 +35,7 @@ generateTxInput, generateTxOutput, signAndBuildTx, - toSmallestDenomination, + toSatoshis, } from 'utils/cashMethods'; import { currency } from 'components/Common/Ticker'; import { @@ -590,15 +590,13 @@ const { destinationAddress, wallet } = sendBCHMock; const isOneToMany = false; const singleSendValue = new BigNumber( - fromSmallestDenomination( + fromSatoshis( mockOneToOneSendXecTxBuilderObj.transaction.tx.outs[0].value, ), ); const totalInputUtxoValue = mockOneToOneSendXecTxBuilderObj.transaction.inputs[0].value; - const satoshisToSend = toSmallestDenomination( - new BigNumber(singleSendValue), - ); + const satoshisToSend = toSatoshis(new BigNumber(singleSendValue)); // for unit test purposes, calculate fee by subtracting satoshisToSend from totalInputUtxoValue // no change output to be subtracted in this tx const txFee = new BigNumber(totalInputUtxoValue).minus( @@ -681,9 +679,7 @@ const singleSendValue = null; // invalid due to singleSendValue being mandatory when isOneToMany is false const totalInputUtxoValue = mockOneToOneSendXecTxBuilderObj.transaction.inputs[0].value; - const satoshisToSend = toSmallestDenomination( - new BigNumber(singleSendValue), - ); + const satoshisToSend = toSatoshis(new BigNumber(singleSendValue)); // for unit test purposes, calculate fee by subtracting satoshisToSend from totalInputUtxoValue // no change output to be subtracted in this tx const txFee = new BigNumber(totalInputUtxoValue).minus(satoshisToSend); @@ -774,9 +770,7 @@ const outputAddressAndValue = mockSingleOutput.split(','); txBuilder.addOutput( outputAddressAndValue[0], // address - parseInt( - toSmallestDenomination(new BigNumber(outputAddressAndValue[1])), - ), // value + parseInt(toSatoshis(new BigNumber(outputAddressAndValue[1]))), // value ); const rawTxHex = signAndBuildTx(BCH, mockSingleInputUtxo, txBuilder); @@ -801,9 +795,7 @@ const outputAddressAndValue = mockMultipleOutputs[i].split(','); txBuilder.addOutput( outputAddressAndValue[0], // address - parseInt( - toSmallestDenomination(new BigNumber(outputAddressAndValue[1])), - ), // value + parseInt(toSatoshis(new BigNumber(outputAddressAndValue[1]))), // value ); } @@ -829,9 +821,7 @@ const outputAddressAndValue = mockSingleOutput.split(','); txBuilder.addOutput( outputAddressAndValue[0], // address - parseInt( - toSmallestDenomination(new BigNumber(outputAddressAndValue[1])), - ), // value + parseInt(toSatoshis(new BigNumber(outputAddressAndValue[1]))), // value ); const rawTxHex = signAndBuildTx(BCH, mockMultipleInputUtxos, txBuilder); @@ -857,9 +847,7 @@ const outputAddressAndValue = mockMultipleOutputs[i].split(','); txBuilder.addOutput( outputAddressAndValue[0], // address - parseInt( - toSmallestDenomination(new BigNumber(outputAddressAndValue[1])), - ), // value + parseInt(toSatoshis(new BigNumber(outputAddressAndValue[1]))), // value ); } @@ -900,20 +888,16 @@ describe('Correctly executes cash utility functions', () => { it(`Correctly converts smallest base unit to smallest decimal for cashDecimals = 2`, () => { - expect(fromSmallestDenomination(1, 2)).toBe(0.01); + expect(fromSatoshis(1, 2)).toBe(0.01); }); it(`Correctly converts largest base unit to smallest decimal for cashDecimals = 2`, () => { - expect(fromSmallestDenomination(1000000012345678, 2)).toBe( - 10000000123456.78, - ); + expect(fromSatoshis(1000000012345678, 2)).toBe(10000000123456.78); }); it(`Correctly converts smallest base unit to smallest decimal for cashDecimals = 8`, () => { - expect(fromSmallestDenomination(1, 8)).toBe(0.00000001); + expect(fromSatoshis(1, 8)).toBe(0.00000001); }); it(`Correctly converts largest base unit to smallest decimal for cashDecimals = 8`, () => { - expect(fromSmallestDenomination(1000000012345678, 8)).toBe( - 10000000.12345678, - ); + expect(fromSatoshis(1000000012345678, 8)).toBe(10000000.12345678); }); it(`Correctly converts an array of length 10 to an array of 4 arrays, each with max length 3`, () => { expect(batchArray(unbatchedArray, 3)).toStrictEqual( 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 @@ -23,7 +23,7 @@ parseInvalidSettingsForMigration, } from '../validation'; import { currency } from 'components/Common/Ticker.js'; -import { fromSmallestDenomination } from 'utils/cashMethods'; +import { fromSatoshis } from 'utils/cashMethods'; import { stStatsValid, noCovidStatsValid, @@ -90,17 +90,16 @@ }); it(`Returns error if ${ currency.ticker - } send amount is less than ${fromSmallestDenomination( + } send amount is less than ${fromSatoshis( currency.dustSats, ).toString()} minimum`, () => { - const expectedValidationError = `Send amount must be at least ${fromSmallestDenomination( + const expectedValidationError = `Send amount must be at least ${fromSatoshis( currency.dustSats, ).toString()} ${currency.ticker}`; expect( shouldRejectAmountInput( ( - fromSmallestDenomination(currency.dustSats).toString() - - 0.00000001 + fromSatoshis(currency.dustSats).toString() - 0.00000001 ).toString(), currency.ticker, 20.0, @@ -110,10 +109,10 @@ }); it(`Returns error if ${ currency.ticker - } send amount is less than ${fromSmallestDenomination( + } send amount is less than ${fromSatoshis( currency.dustSats, ).toString()} minimum in fiat currency`, () => { - const expectedValidationError = `Send amount must be at least ${fromSmallestDenomination( + const expectedValidationError = `Send amount must be at least ${fromSatoshis( currency.dustSats, ).toString()} ${currency.ticker}`; expect( @@ -380,12 +379,11 @@ expect(isValidEtokenAddress(addr)).toBe(false); }); it(`isValidXecSendAmount accepts the dust minimum`, () => { - const testXecSendAmount = fromSmallestDenomination(currency.dustSats); + const testXecSendAmount = fromSatoshis(currency.dustSats); expect(isValidXecSendAmount(testXecSendAmount)).toBe(true); }); it(`isValidXecSendAmount accepts arbitrary number above dust minimum`, () => { - const testXecSendAmount = - fromSmallestDenomination(currency.dustSats) + 1.75; + const testXecSendAmount = fromSatoshis(currency.dustSats) + 1.75; expect(isValidXecSendAmount(testXecSendAmount)).toBe(true); }); it(`isValidXecSendAmount rejects zero`, () => { @@ -397,9 +395,7 @@ expect(isValidXecSendAmount(testXecSendAmount)).toBe(false); }); it(`isValidXecSendAmount accepts arbitrary number above dust minimum as a string`, () => { - const testXecSendAmount = `${ - fromSmallestDenomination(currency.dustSats) + 1.75 - }`; + const testXecSendAmount = `${fromSatoshis(currency.dustSats) + 1.75}`; expect(isValidXecSendAmount(testXecSendAmount)).toBe(true); }); it(`isValidXecSendAmount rejects null`, () => { diff --git a/web/cashtab/src/utils/cashMethods.js b/web/cashtab/src/utils/cashMethods.js --- a/web/cashtab/src/utils/cashMethods.js +++ b/web/cashtab/src/utils/cashMethods.js @@ -129,11 +129,7 @@ } // If user is attempting to send an aggregate value that is less than minimum accepted by the backend if ( - value.lt( - new BigNumber( - fromSmallestDenomination(currency.dustSats).toString(), - ), - ) + value.lt(new BigNumber(fromSatoshis(currency.dustSats).toString())) ) { // Throw the same error given by the backend attempting to broadcast such a tx throw new Error('dust'); @@ -269,14 +265,14 @@ ); txBuilder.addOutput( BCH.Address.toCashAddress(outputAddress), - parseInt(toSmallestDenomination(outputValue)), + parseInt(toSatoshis(outputValue)), ); } } else { // for one to one mode, add output w/ single address and amount to send txBuilder.addOutput( BCH.Address.toCashAddress(destinationAddress), - parseInt(toSmallestDenomination(singleSendValue)), + parseInt(toSatoshis(singleSendValue)), ); } @@ -418,17 +414,14 @@ return amountSmallestDenomination; }; -export const fromSmallestDenomination = ( - amount, - cashDecimals = currency.cashDecimals, -) => { +export const fromSatoshis = (amount, cashDecimals = currency.cashDecimals) => { const amountBig = new BigNumber(amount); const multiplier = new BigNumber(10 ** (-1 * cashDecimals)); const amountInBaseUnits = amountBig.times(multiplier); return amountInBaseUnits.toNumber(); }; -export const toSmallestDenomination = ( +export const toSatoshis = ( sendAmount, cashDecimals = currency.cashDecimals, ) => { @@ -549,7 +542,7 @@ ); return { totalBalanceInSatoshis, - totalBalance: fromSmallestDenomination(totalBalanceInSatoshis), + totalBalance: fromSatoshis(totalBalanceInSatoshis), }; }; 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 @@ -1,6 +1,6 @@ import BigNumber from 'bignumber.js'; import { currency } from 'components/Common/Ticker.js'; -import { fromSmallestDenomination } from 'utils/cashMethods'; +import { fromSatoshis } from 'utils/cashMethods'; import cashaddr from 'ecashaddrjs'; // Validate cash amount @@ -24,10 +24,8 @@ error = 'Amount must be a number'; } else if (testedAmount.lte(0)) { error = 'Amount must be greater than 0'; - } else if ( - testedAmount.lt(fromSmallestDenomination(currency.dustSats).toString()) - ) { - error = `Send amount must be at least ${fromSmallestDenomination( + } else if (testedAmount.lt(fromSatoshis(currency.dustSats).toString())) { + error = `Send amount must be at least ${fromSatoshis( currency.dustSats, ).toString()} ${currency.ticker}`; } else if (testedAmount.gt(totalCashBalance)) { @@ -298,7 +296,7 @@ xecSendAmount !== null && typeof xecSendAmount !== 'undefined' && !isNaN(parseFloat(xecSendAmount)) && - parseFloat(xecSendAmount) >= fromSmallestDenomination(currency.dustSats) + parseFloat(xecSendAmount) >= fromSatoshis(currency.dustSats) ); }; @@ -418,9 +416,7 @@ let valueString = substring[1]; // if the XEC being sent is less than dust sats or contains extra values per line if ( - new BigNumber(valueString).lt( - fromSmallestDenomination(currency.dustSats), - ) || + new BigNumber(valueString).lt(fromSatoshis(currency.dustSats)) || substring.length !== 2 ) { isValid = false;