Browse Source

Merge pull request #575 from Empact/fix/duplicate-transaction-notification

fix: only notify if we have not seen the transaction before
renovate/lint-staged-8.x
Ben Woosley 7 years ago
committed by GitHub
parent
commit
60dd6644a5
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 37
      app/reducers/transaction.js

37
app/reducers/transaction.js

@ -121,7 +121,9 @@ export const transactionError = (event, { error }) => dispatch => {
} }
// Listener for when a new transaction is pushed from the subscriber // Listener for when a new transaction is pushed from the subscriber
export const newTransaction = (event, { transaction }) => dispatch => { 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 // Fetch new balance
dispatch(fetchBalance()) dispatch(fetchBalance())
@ -130,17 +132,19 @@ export const newTransaction = (event, { transaction }) => dispatch => {
dispatch({ type: ADD_TRANSACTION, transaction }) dispatch({ type: ADD_TRANSACTION, transaction })
// HTML 5 desktop notification for the new transaction // HTML 5 desktop notification for the new transaction
const notifTitle = transaction.received if (transaction.received) {
? 'On-chain Transaction Received!' showNotification(
: 'On-chain Transaction Sent!' 'On-chain Transaction Received!',
const notifBody = transaction.received "Lucky you, you just received a new on-chain transaction. I'm jealous."
? "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." dispatch(newAddress('np2wkh')) // Generate a new address
} else {
showNotification(notifTitle, notifBody) showNotification(
'On-chain Transaction Sent!',
// Generate a new address "Hate to see 'em go but love to watch 'em leave. Your on-chain transaction successfully sent."
dispatch(newAddress('np2wkh')) )
}
}
} }
// ------------------------------------ // ------------------------------------
@ -156,15 +160,10 @@ const ACTION_HANDLERS = {
}), }),
[TRANSACTION_SUCCESSFULL]: state => ({ ...state, sendingTransaction: false }), [TRANSACTION_SUCCESSFULL]: state => ({ ...state, sendingTransaction: false }),
[TRANSACTION_FAILED]: state => ({ ...state, sendingTransaction: false }), [TRANSACTION_FAILED]: state => ({ ...state, sendingTransaction: false }),
[ADD_TRANSACTION]: (state, { transaction }) => { [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, ...state,
transactions: [transaction, ...state.transactions] transactions: [transaction, ...state.transactions]
} }),
},
[SHOW_SUCCESS_TRANSACTION_SCREEN]: (state, { txid }) => ({ [SHOW_SUCCESS_TRANSACTION_SCREEN]: (state, { txid }) => ({
...state, ...state,
successTransactionScreen: { show: true, txid } successTransactionScreen: { show: true, txid }

Loading…
Cancel
Save