From 39a9377558d8dd08081da124c302440118e59315 Mon Sep 17 00:00:00 2001 From: Ben Woosley Date: Thu, 19 Jul 2018 16:32:44 -0400 Subject: [PATCH 1/2] fix: only notify if we have not seen the transaction before LND errs on the side of providing redundant transaction reports, so we should filter before issuing notifications. --- app/reducers/transaction.js | 46 ++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 24 deletions(-) diff --git a/app/reducers/transaction.js b/app/reducers/transaction.js index ddba8e1b..2e3e4fcd 100644 --- a/app/reducers/transaction.js +++ b/app/reducers/transaction.js @@ -121,26 +121,29 @@ export const transactionError = (event, { error }) => dispatch => { } // Listener for when a new transaction is pushed from the subscriber -export const newTransaction = (event, { transaction }) => dispatch => { - // Fetch new balance - dispatch(fetchBalance()) +export const newTransaction = (event, { transaction }) => (dispatch, getState) => { + // add the transaction only if we are not already aware of it + if (!getState().transactions.find(tx => tx.tx_hash === transaction.tx_hash)) { + // Fetch new balance + dispatch(fetchBalance()) - decorateTransaction(transaction) + decorateTransaction(transaction) - dispatch({ type: ADD_TRANSACTION, transaction }) + dispatch({ type: ADD_TRANSACTION, transaction }) - // HTML 5 desktop notification for the new transaction - const notifTitle = transaction.received - ? 'On-chain Transaction Received!' - : 'On-chain Transaction Sent!' - const notifBody = transaction.received - ? "Lucky you, you just received a new on-chain transaction. I'm jealous." - : "Hate to see 'em go but love to watch 'em leave. Your on-chain transaction successfully sent." + // HTML 5 desktop notification for the new transaction + const notifTitle = transaction.received + ? 'On-chain Transaction Received!' + : 'On-chain Transaction Sent!' + const notifBody = transaction.received + ? "Lucky you, you just received a new on-chain transaction. I'm jealous." + : "Hate to see 'em go but love to watch 'em leave. Your on-chain transaction successfully sent." - showNotification(notifTitle, notifBody) + showNotification(notifTitle, notifBody) - // Generate a new address - dispatch(newAddress('np2wkh')) + // Generate a new address + dispatch(newAddress('np2wkh')) + } } // ------------------------------------ @@ -156,15 +159,10 @@ const ACTION_HANDLERS = { }), [TRANSACTION_SUCCESSFULL]: state => ({ ...state, sendingTransaction: false }), [TRANSACTION_FAILED]: state => ({ ...state, sendingTransaction: false }), - [ADD_TRANSACTION]: (state, { transaction }) => { - // add the transaction only if we are not already aware of it - return state.transactions.find(tx => tx.tx_hash === transaction.tx_hash) - ? state - : { - ...state, - transactions: [transaction, ...state.transactions] - } - }, + [ADD_TRANSACTION]: (state, { transaction }) => ({ + ...state, + transactions: [transaction, ...state.transactions] + }), [SHOW_SUCCESS_TRANSACTION_SCREEN]: (state, { txid }) => ({ ...state, successTransactionScreen: { show: true, txid } From b2c9f98f77c1ab673c2937321014f075549f0e7d Mon Sep 17 00:00:00 2001 From: Ben Woosley Date: Fri, 20 Jul 2018 12:59:24 -0400 Subject: [PATCH 2/2] fix: only generate a new address on new incoming transaction Outgoing transactions reference a historical utxo, and do not tie information to the current receive address, so don't call for generating a new one. --- app/reducers/transaction.js | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/app/reducers/transaction.js b/app/reducers/transaction.js index 2e3e4fcd..3f65d025 100644 --- a/app/reducers/transaction.js +++ b/app/reducers/transaction.js @@ -132,17 +132,18 @@ export const newTransaction = (event, { transaction }) => (dispatch, getState) = dispatch({ type: ADD_TRANSACTION, transaction }) // HTML 5 desktop notification for the new transaction - const notifTitle = transaction.received - ? 'On-chain Transaction Received!' - : 'On-chain Transaction Sent!' - const notifBody = transaction.received - ? "Lucky you, you just received a new on-chain transaction. I'm jealous." - : "Hate to see 'em go but love to watch 'em leave. Your on-chain transaction successfully sent." - - showNotification(notifTitle, notifBody) - - // Generate a new address - dispatch(newAddress('np2wkh')) + if (transaction.received) { + showNotification( + 'On-chain Transaction Received!', + "Lucky you, you just received a new on-chain transaction. I'm jealous." + ) + dispatch(newAddress('np2wkh')) // Generate a new address + } else { + showNotification( + 'On-chain Transaction Sent!', + "Hate to see 'em go but love to watch 'em leave. Your on-chain transaction successfully sent." + ) + } } }