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 @@ -217,10 +217,8 @@ BCH, wallet, slpBalancesAndUtxos.nonSlpUtxos, - { - addresses: [filledAddress || cleanAddress], - values: [bchValue], - }, + filledAddress || cleanAddress, + bchValue, currency.defaultFee, callbackTxId, ); 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 @@ -25,8 +25,9 @@ 'bitcoincash:qrzuvj0vvnsz5949h4axercl5k420eygavv0awgz05', }, }, - addresses: ['bitcoincash:qr2npxqwznhp7gphatcqzexeclx0hhwdxg386ez36n'], - values: ['0.00000546'], + destinationAddress: + 'bitcoincash:qr2npxqwznhp7gphatcqzexeclx0hhwdxg386ez36n', + sendAmount: '0.00000546', expectedTxId: '7a39961bbd7e27d804fb3169ef38a83234710fbc53897a4eb0c98454854a26d1', expectedHex: [ 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 @@ -62,15 +62,22 @@ expectedHex, utxos, wallet, - addresses, - values, + destinationAddress, + sendAmount, } = sendBCHMock; BCH.RawTransactions.sendRawTransaction = jest .fn() .mockResolvedValue(expectedTxId); expect( - await sendBch(BCH, wallet, utxos, { addresses, values }, 1.01), + await sendBch( + BCH, + wallet, + utxos, + destinationAddress, + sendAmount, + 1.01, + ), ).toBe(`${currency.blockExplorerUrl}/tx/${expectedTxId}`); expect(BCH.RawTransactions.sendRawTransaction).toHaveBeenCalledWith( expectedHex, @@ -86,8 +93,8 @@ expectedHex, utxos, wallet, - addresses, - values, + destinationAddress, + sendAmount, } = sendBCHMock; BCH.RawTransactions.sendRawTransaction = jest @@ -98,7 +105,8 @@ BCH, wallet, utxos, - { addresses, values }, + destinationAddress, + sendAmount, 1.01, callback, ), @@ -112,7 +120,7 @@ it(`Throws error if called trying to send one base unit ${currency.ticker} more than available in utxo set`, async () => { const { sendBch } = useBCH(); const BCH = new BCHJS(); - const { expectedTxId, utxos, wallet, addresses } = sendBCHMock; + const { expectedTxId, utxos, wallet, destinationAddress } = sendBCHMock; const expectedTxFeeInSats = 229; @@ -129,10 +137,8 @@ BCH, wallet, utxos, - { - addresses, - values: [oneBaseUnitMoreThanBalance], - }, + destinationAddress, + oneBaseUnitMoreThanBalance, 1.01, ); expect(failedSendBch).rejects.toThrow(new Error('Insufficient funds')); @@ -140,10 +146,8 @@ BCH, wallet, utxos, - { - addresses, - values: null, - }, + destinationAddress, + null, 1.01, ); expect(nullValuesSendBch).toBe(null); @@ -152,7 +156,7 @@ it('Throws error on attempt to send one satoshi less than backend dust limit', async () => { const { sendBch } = useBCH(); const BCH = new BCHJS(); - const { expectedTxId, utxos, wallet, addresses } = sendBCHMock; + const { expectedTxId, utxos, wallet, destinationAddress } = sendBCHMock; BCH.RawTransactions.sendRawTransaction = jest .fn() .mockResolvedValue(expectedTxId); @@ -160,14 +164,10 @@ BCH, wallet, utxos, - { - addresses, - values: [ - new BigNumber(currency.dust) - .minus(new BigNumber('0.00000001')) - .toString(), - ], - }, + destinationAddress, + new BigNumber(currency.dust) + .minus(new BigNumber('0.00000001')) + .toString(), 1.01, ); expect(failedSendBch).rejects.toThrow(new Error('dust')); @@ -175,10 +175,8 @@ BCH, wallet, utxos, - { - addresses, - values: null, - }, + destinationAddress, + null, 1.01, ); expect(nullValuesSendBch).toBe(null); @@ -187,7 +185,7 @@ it('receives errors from the network and parses it', async () => { const { sendBch } = useBCH(); const BCH = new BCHJS(); - const { values, utxos, wallet, addresses } = sendBCHMock; + const { sendAmount, utxos, wallet, destinationAddress } = sendBCHMock; BCH.RawTransactions.sendRawTransaction = jest .fn() .mockImplementation(async () => { @@ -197,10 +195,8 @@ BCH, wallet, utxos, - { - addresses, - values, - }, + destinationAddress, + sendAmount, 1.01, ); await expect(insufficientPriority).rejects.toThrow( @@ -216,10 +212,8 @@ BCH, wallet, utxos, - { - addresses, - values, - }, + destinationAddress, + sendAmount, 1.01, ); await expect(txnMempoolConflict).rejects.toThrow( @@ -235,7 +229,8 @@ BCH, wallet, utxos, - { addresses, values }, + destinationAddress, + sendAmount, 1.01, ); await expect(networkError).rejects.toThrow(new Error('Network Error')); @@ -253,10 +248,8 @@ BCH, wallet, utxos, - { - addresses, - values, - }, + destinationAddress, + sendAmount, 1.01, ); await expect(tooManyAncestorsMempool).rejects.toThrow( 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 @@ -434,21 +434,20 @@ BCH, wallet, utxos, - { addresses, values, encodedOpReturn }, + destinationAddress, + sendAmount, feeInSatsPerByte, callbackTxId, + encodedOpReturn, ) => { // Note: callbackTxId is a callback function that accepts a txid as its only parameter try { - if (!values || values.length === 0) { + if (!sendAmount) { return null; } - const value = values.reduce( - (previous, current) => new BigNumber(current).plus(previous), - new BigNumber(0), - ); + const value = new BigNumber(sendAmount); // If user is attempting to send less than minimum accepted by the backend if (value.lt(new BigNumber(currency.dust))) { @@ -485,18 +484,8 @@ inputUtxos.push(utxo); txFee = encodedOpReturn - ? calcFee( - BCH, - inputUtxos, - addresses.length + 2, - feeInSatsPerByte, - ) - : calcFee( - BCH, - inputUtxos, - addresses.length + 1, - feeInSatsPerByte, - ); + ? calcFee(BCH, inputUtxos, 3, feeInSatsPerByte) + : calcFee(BCH, inputUtxos, 2, feeInSatsPerByte); if (originalAmount.minus(satoshisToSend).minus(txFee).gte(0)) { break; @@ -518,13 +507,11 @@ } // add output w/ address and amount to send - for (let i = 0; i < addresses.length; i++) { - const address = addresses[i]; - transactionBuilder.addOutput( - BCH.Address.toCashAddress(address), - BCH.BitcoinCash.toSatoshi(Number(values[i]).toFixed(8)), - ); - } + + transactionBuilder.addOutput( + BCH.Address.toCashAddress(destinationAddress), + BCH.BitcoinCash.toSatoshi(Number(sendAmount).toFixed(8)), + ); if ( remainder >=