Skip to content

Commit

Permalink
fix(transfer): disable RBF for manual channel funding (#2294)
Browse files Browse the repository at this point in the history
  • Loading branch information
pwltr authored Oct 7, 2024
1 parent baee6f8 commit b3f9f30
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 67 deletions.
6 changes: 2 additions & 4 deletions src/screens/Settings/AddressViewer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -644,10 +644,8 @@ const AddressViewer = ({
return;
}
updateSendTransaction({
transaction: {
...transactionRes.value,
outputs: [{ address: receiveAddress.value, value: 0, index: 0 }],
},
...transactionRes.value,
outputs: [{ address: receiveAddress.value, value: 0, index: 0 }],
});
dispatch(updateUi({ fromAddressViewer: true }));
sendMax({
Expand Down
2 changes: 1 addition & 1 deletion src/screens/Transfer/SpendingAmount.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ const SpendingAmount = ({
useCallback(() => {
const setupTransfer = async (): Promise<void> => {
await resetSendTransaction();
await setupOnChainTransaction();
await setupOnChainTransaction({ rbf: false });
refreshBlocktankInfo().then();
};
setupTransfer();
Expand Down
4 changes: 2 additions & 2 deletions src/screens/Wallets/Send/Amount.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,11 @@ const Amount = ({ navigation }: SendScreenProps<'Amount'>): ReactElement => {
return;
}
if (isMaxSendAmount && amount !== availableAmount) {
updateSendTransaction({ transaction: { max: false } });
updateSendTransaction({ max: false });
}

if (!isMaxSendAmount && amount === availableAmount) {
updateSendTransaction({ transaction: { max: true } });
updateSendTransaction({ max: true });
}
}, [isMaxSendAmount, amount, availableAmount, transaction?.lightningInvoice]);

Expand Down
12 changes: 4 additions & 8 deletions src/store/actions/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -319,15 +319,11 @@ export const getChangeAddress = async ({
* @param {Partial<ISendTransaction>} transaction
* @returns {Promise<Result<string>>}
*/
export const updateSendTransaction = ({
transaction,
}: {
transaction: Partial<ISendTransaction>;
}): Result<string> => {
export const updateSendTransaction = (
transaction: Partial<ISendTransaction>,
): Result<string> => {
const tx = getOnChainWalletTransaction();
return tx.updateSendTransaction({
transaction,
});
return tx.updateSendTransaction({ transaction });
};

/**
Expand Down
16 changes: 7 additions & 9 deletions src/store/utils/blocktank.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,15 +282,13 @@ export const startChannelPurchase = async ({
}

updateSendTransaction({
transaction: {
outputs: [
{
address: buyChannelData.payment.onchain.address,
value: amountToSend,
index: 0,
},
],
},
outputs: [
{
address: buyChannelData.payment.onchain.address,
value: amountToSend,
index: 0,
},
],
});

const fees = getFeesStore().onchain;
Expand Down
30 changes: 13 additions & 17 deletions src/utils/scanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -843,12 +843,10 @@ export const handleData = async ({
sendNavigation.navigate('Amount');

updateSendTransaction({
transaction: {
label: message,
outputs: [{ address: address, value: sats, index: 0 }],
lightningInvoice: undefined,
slashTagsUrl: slashTagsUrl,
},
label: message,
outputs: [{ address: address, value: sats, index: 0 }],
lightningInvoice: undefined,
slashTagsUrl: slashTagsUrl,
});

return ok({
Expand Down Expand Up @@ -884,17 +882,15 @@ export const handleData = async ({
}

updateSendTransaction({
transaction: {
outputs: [
{
address: '',
value: invoiceAmount,
index: 0,
},
],
lightningInvoice: lightningPaymentRequest,
slashTagsUrl,
},
outputs: [
{
address: '',
value: invoiceAmount,
index: 0,
},
],
lightningInvoice: lightningPaymentRequest,
slashTagsUrl,
});

return ok({
Expand Down
34 changes: 9 additions & 25 deletions src/utils/wallet/transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,20 +89,14 @@ export const getTotalFee = ({
});
};

interface ICreateTransaction {
selectedWallet?: TWalletName;
selectedNetwork?: EAvailableNetwork;
transactionData?: ISendTransaction;
}

/**
* Creates complete signed transaction using the transaction data store
* @param {ISendTransaction} [transactionData]
* @returns {Promise<Result<{id: string, hex: string}>>}
*/
export const createTransaction = async ({
transactionData,
}: ICreateTransaction = {}): Promise<Result<{ id: string; hex: string }>> => {
export const createTransaction = async (
transactionData?: ISendTransaction,
): Promise<Result<{ id: string; hex: string }>> => {
try {
const transaction = getOnChainWalletTransaction();
const createTxRes = await transaction.createTransaction({
Expand Down Expand Up @@ -690,10 +684,8 @@ export const updateSendAmount = ({
}

updateSendTransaction({
transaction: {
outputs: [{ ...currentOutput, value: amount }],
max,
},
outputs: [{ ...currentOutput, value: amount }],
max,
});

return ok('');
Expand Down Expand Up @@ -747,15 +739,11 @@ export const updateMessage = async ({
if (max) {
_transaction.outputs = [{ address, value: inputTotal - newFee, index }];
//Update the tx value with the new fee to continue sending the max amount.
updateSendTransaction({
transaction: _transaction,
});
updateSendTransaction(_transaction);
return ok('Successfully updated the message.');
}
if (totalNewAmount <= inputTotal) {
updateSendTransaction({
transaction: _transaction,
});
updateSendTransaction(_transaction);
}
return ok('Successfully updated the message.');
};
Expand Down Expand Up @@ -816,11 +804,7 @@ const runCoinSelect = async ({
fee: autoCoinSelectResponse.value.fee,
inputs: autoCoinSelectResponse.value.inputs,
};
updateSendTransaction({
selectedWallet,
selectedNetwork,
transaction: updatedTx,
});
updateSendTransaction(updatedTx);
return ok('Successfully updated tx.');
}
return ok('No need to update transaction.');
Expand Down Expand Up @@ -913,7 +897,7 @@ export const broadcastBoost = async ({
}
const transaction = transactionDataResponse.value;

const rawTx = await createTransaction({});
const rawTx = await createTransaction();
if (rawTx.isErr()) {
return err(rawTx.error.message);
}
Expand Down
3 changes: 2 additions & 1 deletion src/utils/wallet/transfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ export const createFundedChannel = async ({
const address = getAddressFromScriptPubKey(output_script, network);

updateSendTransaction({
transaction: { outputs: [{ address, value: value_satoshis, index: 0 }] },
rbf: false,
outputs: [{ address, value: value_satoshis, index: 0 }],
});

const createTxResult = await createTransaction();
Expand Down

0 comments on commit b3f9f30

Please sign in to comment.