From e7a819c3867c11f37b00ce449845bbc0aac44c8c Mon Sep 17 00:00:00 2001 From: Jack Mallers Date: Tue, 19 Sep 2017 14:30:52 -0500 Subject: [PATCH] fix(sendcoins): move sendcoins to new transaction reducer, remove unused code from payments --- app/lnd/methods/index.js | 4 ++-- app/reducers/ipc.js | 10 ++++----- app/reducers/payment.js | 22 ------------------- app/reducers/transaction.js | 4 ++-- app/routes/app/components/App.js | 3 +++ .../app/components/components/Form/Form.js | 8 ++++--- .../components/Form/components/Pay/Pay.js | 6 ++--- app/routes/app/containers/AppContainer.js | 4 +++- 8 files changed, 23 insertions(+), 38 deletions(-) diff --git a/app/lnd/methods/index.js b/app/lnd/methods/index.js index 9b69ec2f..eca3b570 100644 --- a/app/lnd/methods/index.js +++ b/app/lnd/methods/index.js @@ -101,8 +101,8 @@ export default function (lnd, event, msg, data) { // Transaction looks like { txid: String } // { amount, addr } = data walletController.sendCoins(lnd, data) - .then(({ txid }) => event.sender.send('sendSuccessful', { amount: data.amount, addr: data.addr, txid })) - .catch(error => event.sender.send('sendCoinsError', { error })) + .then(({ txid }) => event.sender.send('transactionSuccessful', { amount: data.amount, addr: data.addr, txid })) + .catch(error => event.sender.send('transactionError', { error })) break case 'openChannel': // Response is empty. Streaming updates on channel status and updates diff --git a/app/reducers/ipc.js b/app/reducers/ipc.js index 2f035923..c61ccd20 100644 --- a/app/reducers/ipc.js +++ b/app/reducers/ipc.js @@ -19,10 +19,10 @@ import { pushclosechannelstatus } from './channels' -import { receivePayments, paymentSuccessful, sendSuccessful, sendCoinsError } from './payment' +import { receivePayments, paymentSuccessful } from './payment' import { receiveInvoices, createdInvoice, receiveFormInvoice } from './invoice' import { receiveBalance } from './balance' -import { receiveTransactions } from './transaction' +import { receiveTransactions, transactionSuccessful, transactionError } from './transaction' // Import all receiving IPC event handlers and pass them into createIpc const ipc = createIpc({ @@ -41,8 +41,6 @@ const ipc = createIpc({ receiveBalance, paymentSuccessful, - sendSuccessful, - sendCoinsError, channelSuccessful, pushchannelupdated, @@ -61,7 +59,9 @@ const ipc = createIpc({ receiveAddress, receiveCryptocurrency, - receiveTransactions + receiveTransactions, + transactionSuccessful, + transactionError }) export default ipc diff --git a/app/reducers/payment.js b/app/reducers/payment.js index 4bfdf453..7a04bd7b 100644 --- a/app/reducers/payment.js +++ b/app/reducers/payment.js @@ -66,32 +66,10 @@ export const payInvoice = paymentRequest => (dispatch) => { ipcRenderer.send('lnd', { msg: 'sendPayment', data: { paymentRequest } }) } -export const sendCoins = ({ value, addr, currency, rate }) => (dispatch) => { - const amount = currency === 'usd' ? btc.btcToSatoshis(usd.usdToBtc(value, rate)) : btc.btcToSatoshis(value) - dispatch(sendPayment()) - ipcRenderer.send('lnd', { msg: 'sendCoins', data: { amount, addr } }) -} - // Receive IPC event for successful payment // TODO: Add payment to state, not a total re-fetch export const paymentSuccessful = () => fetchPayments() -export const sendSuccessful = (event, { amount, addr, txid }) => (dispatch) => { - // Close the form modal once the payment was succesful - dispatch(setForm({ modalOpen: false })) - // Show successful payment state - dispatch(showModal('SUCCESSFUL_SEND_COINS', { txid, amount, addr })) - // TODO: Add successful on-chain payment to payments list once payments list supports on-chain and LN - // dispatch({ type: PAYMENT_SUCCESSFULL, payment: { amount, addr, txid, pending: true } }) - dispatch({ type: PAYMENT_SUCCESSFULL }) - // Reset the payment form - dispatch(resetForm()) -} - -export const sendCoinsError = () => (dispatch) => { - dispatch({ type: PAYMENT_FAILED }) -} - // ------------------------------------ // Action Handlers diff --git a/app/reducers/transaction.js b/app/reducers/transaction.js index e671e324..c551ff24 100644 --- a/app/reducers/transaction.js +++ b/app/reducers/transaction.js @@ -41,7 +41,7 @@ export const receiveTransactions = (event, { transactions }) => dispatch => disp export const sendCoins = ({ value, addr, currency, rate }) => (dispatch) => { const amount = currency === 'usd' ? btc.btcToSatoshis(usd.usdToBtc(value, rate)) : btc.btcToSatoshis(value) - dispatch(sendPayment()) + dispatch(sendTransaction()) ipcRenderer.send('lnd', { msg: 'sendCoins', data: { amount, addr } }) } @@ -81,7 +81,7 @@ const ACTION_HANDLERS = { // Reducer // ------------------------------------ const initialState = { - sendingtransaction: false, + sendingTransaction: false, transactionLoading: false, transactions: [] } diff --git a/app/routes/app/components/App.js b/app/routes/app/components/App.js index 421be3fc..d2a01579 100644 --- a/app/routes/app/components/App.js +++ b/app/routes/app/components/App.js @@ -28,6 +28,7 @@ class App extends Component { setPubkey, setPaymentRequest, payment, + transaction: { sendingTransaction }, peers, setCurrency, setForm, @@ -64,6 +65,7 @@ class App extends Component { peers={peers} ticker={ticker} form={form} + sendingTransaction={sendingTransaction} createInvoice={createInvoice} payInvoice={payInvoice} sendCoins={sendCoins} @@ -103,6 +105,7 @@ App.propTypes = { setPubkey: PropTypes.func.isRequired, setPaymentRequest: PropTypes.func.isRequired, payment: PropTypes.object.isRequired, + transaction: PropTypes.object.isRequired, peers: PropTypes.array, setCurrency: PropTypes.func.isRequired, setForm: PropTypes.func.isRequired, diff --git a/app/routes/app/components/components/Form/Form.js b/app/routes/app/components/components/Form/Form.js index a57dafe9..e753d61a 100644 --- a/app/routes/app/components/components/Form/Form.js +++ b/app/routes/app/components/components/Form/Form.js @@ -22,7 +22,8 @@ const Form = ({ formInvoice, currentTicker, isOnchain, - isLn + isLn, + sendingTransaction }) => (
@@ -33,7 +34,7 @@ const Form = ({ { formType === 'pay' ? { - sendingPayment ? + sendingTransaction ? : null @@ -127,7 +127,7 @@ class Pay extends Component { } Pay.propTypes = { - sendingPayment: PropTypes.bool.isRequired, + sendingTransaction: PropTypes.bool.isRequired, invoiceAmount: PropTypes.string.isRequired, onchainAmount: PropTypes.string.isRequired, setOnchainAmount: PropTypes.func.isRequired, diff --git a/app/routes/app/containers/AppContainer.js b/app/routes/app/containers/AppContainer.js index 3f2e8153..27961910 100644 --- a/app/routes/app/containers/AppContainer.js +++ b/app/routes/app/containers/AppContainer.js @@ -5,7 +5,8 @@ import { fetchBalance } from '../../../reducers/balance' import { fetchInfo } from '../../../reducers/info' import { createInvoice, fetchInvoice } from '../../../reducers/invoice' import { hideModal } from '../../../reducers/modal' -import { payInvoice, sendCoins } from '../../../reducers/payment' +import { payInvoice } from '../../../reducers/payment' +import { sendCoins } from '../../../reducers/transaction' import { fetchChannels } from '../../../reducers/channels' import { setForm, @@ -42,6 +43,7 @@ const mapStateToProps = state => ({ ticker: state.ticker, balance: state.balance, payment: state.payment, + transaction: state.transaction, form: state.form, invoice: state.invoice, modal: state.modal,