Browse Source

fix(sendcoins): move sendcoins to new transaction reducer, remove unused code from payments

renovate/lint-staged-8.x
Jack Mallers 7 years ago
parent
commit
e7a819c386
  1. 4
      app/lnd/methods/index.js
  2. 10
      app/reducers/ipc.js
  3. 22
      app/reducers/payment.js
  4. 4
      app/reducers/transaction.js
  5. 3
      app/routes/app/components/App.js
  6. 8
      app/routes/app/components/components/Form/Form.js
  7. 6
      app/routes/app/components/components/Form/components/Pay/Pay.js
  8. 4
      app/routes/app/containers/AppContainer.js

4
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

10
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

22
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

4
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: []
}

3
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,

8
app/routes/app/components/components/Form/Form.js

@ -22,7 +22,8 @@ const Form = ({
formInvoice,
currentTicker,
isOnchain,
isLn
isLn,
sendingTransaction
}) => (
<div className={`${styles.formContainer} ${isOpen ? styles.open : ''}`}>
<div className={styles.container}>
@ -33,7 +34,7 @@ const Form = ({
{
formType === 'pay' ?
<Pay
sendingPayment={sendingPayment}
sendingTransaction={sendingTransaction}
invoiceAmount={formInvoice.amount}
onchainAmount={onchainAmount}
setOnchainAmount={setOnchainAmount}
@ -87,7 +88,8 @@ Form.propTypes = {
formInvoice: PropTypes.object.isRequired,
currentTicker: PropTypes.object.isRequired,
isOnchain: PropTypes.bool.isRequired,
isLn: PropTypes.bool.isRequired
isLn: PropTypes.bool.isRequired,
sendingTransaction: PropTypes.bool.isRequired
}
export default Form

6
app/routes/app/components/components/Form/components/Pay/Pay.js

@ -16,7 +16,7 @@ class Pay extends Component {
render() {
const {
sendingPayment,
sendingTransaction,
invoiceAmount,
onchainAmount,
setOnchainAmount,
@ -43,7 +43,7 @@ class Pay extends Component {
return (
<div>
{
sendingPayment ?
sendingTransaction ?
<LoadingBolt />
:
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,

4
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,

Loading…
Cancel
Save