Browse Source

feature(payment error): error handling for LN payment

renovate/lint-staged-8.x
Jack Mallers 7 years ago
parent
commit
3dedf6c522
  1. 19
      app/components/GlobalError/GlobalError.js
  2. 5
      app/lnd/methods/index.js
  3. 3
      app/reducers/ipc.js
  4. 13
      app/reducers/payment.js
  5. 1
      app/reducers/transaction.js
  6. 10
      app/routes/app/containers/AppContainer.js

19
app/components/GlobalError/GlobalError.js

@ -3,16 +3,19 @@ import PropTypes from 'prop-types'
import { MdClose } from 'react-icons/lib/md' import { MdClose } from 'react-icons/lib/md'
import styles from './GlobalError.scss' import styles from './GlobalError.scss'
const GlobalError = ({ error, clearError }) => ( const GlobalError = ({ error, clearError }) => {
<div className={`${styles.container} ${!error && styles.closed}`}> console.log('error: ', error)
<div className={styles.content}> return (
<div className={styles.close} onClick={clearError}> <div className={`${styles.container} ${!error && styles.closed}`}>
<MdClose /> <div className={styles.content}>
<div className={styles.close} onClick={clearError}>
<MdClose />
</div>
<h2>{error}</h2>
</div> </div>
<h2>{error}</h2>
</div> </div>
</div> )
) }
GlobalError.propTypes = { GlobalError.propTypes = {

5
app/lnd/methods/index.js

@ -112,7 +112,10 @@ export default function (lnd, event, msg, data) {
// { paymentRequest } = data // { paymentRequest } = data
paymentsController.sendPaymentSync(lnd, data) paymentsController.sendPaymentSync(lnd, data)
.then(({ payment_route }) => event.sender.send('paymentSuccessful', Object.assign(data, { payment_route }))) .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 break
case 'sendCoins': case 'sendCoins':
// Transaction looks like { txid: String } // Transaction looks like { txid: String }

3
app/reducers/ipc.js

@ -21,7 +21,7 @@ import {
} from './channels' } from './channels'
import { lightningPaymentUri } from './payform' import { lightningPaymentUri } from './payform'
import { receivePayments, paymentSuccessful } from './payment' import { receivePayments, paymentSuccessful, paymentFailed } from './payment'
import { receiveInvoices, createdInvoice, receiveFormInvoice, invoiceUpdate } from './invoice' import { receiveInvoices, createdInvoice, receiveFormInvoice, invoiceUpdate } from './invoice'
import { receiveBalance } from './balance' import { receiveBalance } from './balance'
import { import {
@ -55,6 +55,7 @@ const ipc = createIpc({
lightningPaymentUri, lightningPaymentUri,
paymentSuccessful, paymentSuccessful,
paymentFailed,
channelSuccessful, channelSuccessful,
pushchannelupdated, pushchannelupdated,

13
app/reducers/payment.js

@ -4,6 +4,7 @@ import { fetchBalance } from './balance'
import { setFormType } from './form' import { setFormType } from './form'
import { resetPayForm } from './payform' import { resetPayForm } from './payform'
import { showModal } from './modal' import { showModal } from './modal'
import { setError } from './error'
// ------------------------------------ // ------------------------------------
// Constants // Constants
@ -47,12 +48,6 @@ export function paymentSuccessfull(payment) {
} }
} }
export function paymentFailed() {
return {
type: PAYMENT_FAILED
}
}
// Send IPC event for payments // Send IPC event for payments
export const fetchPayments = () => (dispatch) => { export const fetchPayments = () => (dispatch) => {
dispatch(getPayments()) dispatch(getPayments())
@ -87,6 +82,12 @@ export const paymentSuccessful = () => (dispatch) => {
dispatch(fetchBalance()) dispatch(fetchBalance())
} }
export const paymentFailed = (event, { error }) => (dispatch) => {
dispatch({ type: PAYMENT_FAILED })
console.log('error: ', error)
dispatch(setError(error))
}
// ------------------------------------ // ------------------------------------
// Action Handlers // Action Handlers

1
app/reducers/transaction.js

@ -70,6 +70,7 @@ export const transactionSuccessful = (event, { amount, addr, txid }) => (dispatc
export const transactionError = (event, { error }) => (dispatch) => { export const transactionError = (event, { error }) => (dispatch) => {
dispatch({ type: TRANSACTION_FAILED }) dispatch({ type: TRANSACTION_FAILED })
console.log('error: ', error)
dispatch(setError(error)) dispatch(setError(error))
} }

10
app/routes/app/containers/AppContainer.js

@ -49,15 +49,9 @@ const mapDispatchToProps = {
createInvoice, createInvoice,
fetchInvoice, fetchInvoice,
<<<<<<< HEAD fetchBlockHeight,
<<<<<<< HEAD clearError,
fetchBlockHeight
=======
clearError clearError
>>>>>>> feature(globalerror): clear error
=======
clearError
>>>>>>> 46b03abc5a79d74487165abf8656e69da020f3bc
} }
const mapStateToProps = state => ({ const mapStateToProps = state => ({

Loading…
Cancel
Save