From 3dedf6c522731c29134adc0416dbf1679466309e Mon Sep 17 00:00:00 2001 From: Jack Mallers Date: Wed, 25 Oct 2017 12:26:19 -0500 Subject: [PATCH] feature(payment error): error handling for LN payment --- app/components/GlobalError/GlobalError.js | 19 +++++++++++-------- app/lnd/methods/index.js | 5 ++++- app/reducers/ipc.js | 3 ++- app/reducers/payment.js | 13 +++++++------ app/reducers/transaction.js | 1 + app/routes/app/containers/AppContainer.js | 10 ++-------- 6 files changed, 27 insertions(+), 24 deletions(-) diff --git a/app/components/GlobalError/GlobalError.js b/app/components/GlobalError/GlobalError.js index 75f09a1e..cf566b03 100644 --- a/app/components/GlobalError/GlobalError.js +++ b/app/components/GlobalError/GlobalError.js @@ -3,16 +3,19 @@ import PropTypes from 'prop-types' import { MdClose } from 'react-icons/lib/md' import styles from './GlobalError.scss' -const GlobalError = ({ error, clearError }) => ( -
-
-
- +const GlobalError = ({ error, clearError }) => { + console.log('error: ', error) + return ( +
+
+
+ +
+

{error}

-

{error}

-
-) + ) +} GlobalError.propTypes = { diff --git a/app/lnd/methods/index.js b/app/lnd/methods/index.js index 2b51fa71..609db7c0 100644 --- a/app/lnd/methods/index.js +++ b/app/lnd/methods/index.js @@ -112,7 +112,10 @@ export default function (lnd, event, msg, data) { // { paymentRequest } = data paymentsController.sendPaymentSync(lnd, data) .then(({ payment_route }) => event.sender.send('paymentSuccessful', Object.assign(data, { payment_route }))) - .catch(error => console.log('payinvoice error: ', error)) + .catch(error => { + console.log('payinvoice error: ', error) + event.sender.send('paymentFailed', { error: error.toString() }) + }) break case 'sendCoins': // Transaction looks like { txid: String } diff --git a/app/reducers/ipc.js b/app/reducers/ipc.js index a0789e30..544d6820 100644 --- a/app/reducers/ipc.js +++ b/app/reducers/ipc.js @@ -21,7 +21,7 @@ import { } from './channels' import { lightningPaymentUri } from './payform' -import { receivePayments, paymentSuccessful } from './payment' +import { receivePayments, paymentSuccessful, paymentFailed } from './payment' import { receiveInvoices, createdInvoice, receiveFormInvoice, invoiceUpdate } from './invoice' import { receiveBalance } from './balance' import { @@ -55,6 +55,7 @@ const ipc = createIpc({ lightningPaymentUri, paymentSuccessful, + paymentFailed, channelSuccessful, pushchannelupdated, diff --git a/app/reducers/payment.js b/app/reducers/payment.js index 795e88ea..0ef8024d 100644 --- a/app/reducers/payment.js +++ b/app/reducers/payment.js @@ -4,6 +4,7 @@ import { fetchBalance } from './balance' import { setFormType } from './form' import { resetPayForm } from './payform' import { showModal } from './modal' +import { setError } from './error' // ------------------------------------ // Constants @@ -47,12 +48,6 @@ export function paymentSuccessfull(payment) { } } -export function paymentFailed() { - return { - type: PAYMENT_FAILED - } -} - // Send IPC event for payments export const fetchPayments = () => (dispatch) => { dispatch(getPayments()) @@ -87,6 +82,12 @@ export const paymentSuccessful = () => (dispatch) => { dispatch(fetchBalance()) } +export const paymentFailed = (event, { error }) => (dispatch) => { + dispatch({ type: PAYMENT_FAILED }) + console.log('error: ', error) + dispatch(setError(error)) +} + // ------------------------------------ // Action Handlers diff --git a/app/reducers/transaction.js b/app/reducers/transaction.js index 62b446e4..2d007e9c 100644 --- a/app/reducers/transaction.js +++ b/app/reducers/transaction.js @@ -70,6 +70,7 @@ export const transactionSuccessful = (event, { amount, addr, txid }) => (dispatc export const transactionError = (event, { error }) => (dispatch) => { dispatch({ type: TRANSACTION_FAILED }) + console.log('error: ', error) dispatch(setError(error)) } diff --git a/app/routes/app/containers/AppContainer.js b/app/routes/app/containers/AppContainer.js index 66ffa42a..3b86d34b 100644 --- a/app/routes/app/containers/AppContainer.js +++ b/app/routes/app/containers/AppContainer.js @@ -49,15 +49,9 @@ const mapDispatchToProps = { createInvoice, fetchInvoice, -<<<<<<< HEAD -<<<<<<< HEAD - fetchBlockHeight -======= + fetchBlockHeight, + clearError, clearError ->>>>>>> feature(globalerror): clear error -======= - clearError ->>>>>>> 46b03abc5a79d74487165abf8656e69da020f3bc } const mapStateToProps = state => ({