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 } // Transaction looks like { txid: String }
// { amount, addr } = data // { amount, addr } = data
walletController.sendCoins(lnd, data) walletController.sendCoins(lnd, data)
.then(({ txid }) => event.sender.send('sendSuccessful', { amount: data.amount, addr: data.addr, txid })) .then(({ txid }) => event.sender.send('transactionSuccessful', { amount: data.amount, addr: data.addr, txid }))
.catch(error => event.sender.send('sendCoinsError', { error })) .catch(error => event.sender.send('transactionError', { error }))
break break
case 'openChannel': case 'openChannel':
// Response is empty. Streaming updates on channel status and updates // Response is empty. Streaming updates on channel status and updates

10
app/reducers/ipc.js

@ -19,10 +19,10 @@ import {
pushclosechannelstatus pushclosechannelstatus
} from './channels' } from './channels'
import { receivePayments, paymentSuccessful, sendSuccessful, sendCoinsError } from './payment' import { receivePayments, paymentSuccessful } from './payment'
import { receiveInvoices, createdInvoice, receiveFormInvoice } from './invoice' import { receiveInvoices, createdInvoice, receiveFormInvoice } from './invoice'
import { receiveBalance } from './balance' 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 // Import all receiving IPC event handlers and pass them into createIpc
const ipc = createIpc({ const ipc = createIpc({
@ -41,8 +41,6 @@ const ipc = createIpc({
receiveBalance, receiveBalance,
paymentSuccessful, paymentSuccessful,
sendSuccessful,
sendCoinsError,
channelSuccessful, channelSuccessful,
pushchannelupdated, pushchannelupdated,
@ -61,7 +59,9 @@ const ipc = createIpc({
receiveAddress, receiveAddress,
receiveCryptocurrency, receiveCryptocurrency,
receiveTransactions receiveTransactions,
transactionSuccessful,
transactionError
}) })
export default ipc export default ipc

22
app/reducers/payment.js

@ -66,32 +66,10 @@ export const payInvoice = paymentRequest => (dispatch) => {
ipcRenderer.send('lnd', { msg: 'sendPayment', data: { paymentRequest } }) 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 // Receive IPC event for successful payment
// TODO: Add payment to state, not a total re-fetch // TODO: Add payment to state, not a total re-fetch
export const paymentSuccessful = () => fetchPayments() 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 // 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) => { export const sendCoins = ({ value, addr, currency, rate }) => (dispatch) => {
const amount = currency === 'usd' ? btc.btcToSatoshis(usd.usdToBtc(value, rate)) : btc.btcToSatoshis(value) 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 } }) ipcRenderer.send('lnd', { msg: 'sendCoins', data: { amount, addr } })
} }
@ -81,7 +81,7 @@ const ACTION_HANDLERS = {
// Reducer // Reducer
// ------------------------------------ // ------------------------------------
const initialState = { const initialState = {
sendingtransaction: false, sendingTransaction: false,
transactionLoading: false, transactionLoading: false,
transactions: [] transactions: []
} }

3
app/routes/app/components/App.js

@ -28,6 +28,7 @@ class App extends Component {
setPubkey, setPubkey,
setPaymentRequest, setPaymentRequest,
payment, payment,
transaction: { sendingTransaction },
peers, peers,
setCurrency, setCurrency,
setForm, setForm,
@ -64,6 +65,7 @@ class App extends Component {
peers={peers} peers={peers}
ticker={ticker} ticker={ticker}
form={form} form={form}
sendingTransaction={sendingTransaction}
createInvoice={createInvoice} createInvoice={createInvoice}
payInvoice={payInvoice} payInvoice={payInvoice}
sendCoins={sendCoins} sendCoins={sendCoins}
@ -103,6 +105,7 @@ App.propTypes = {
setPubkey: PropTypes.func.isRequired, setPubkey: PropTypes.func.isRequired,
setPaymentRequest: PropTypes.func.isRequired, setPaymentRequest: PropTypes.func.isRequired,
payment: PropTypes.object.isRequired, payment: PropTypes.object.isRequired,
transaction: PropTypes.object.isRequired,
peers: PropTypes.array, peers: PropTypes.array,
setCurrency: PropTypes.func.isRequired, setCurrency: PropTypes.func.isRequired,
setForm: PropTypes.func.isRequired, setForm: PropTypes.func.isRequired,

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

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

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

@ -16,7 +16,7 @@ class Pay extends Component {
render() { render() {
const { const {
sendingPayment, sendingTransaction,
invoiceAmount, invoiceAmount,
onchainAmount, onchainAmount,
setOnchainAmount, setOnchainAmount,
@ -43,7 +43,7 @@ class Pay extends Component {
return ( return (
<div> <div>
{ {
sendingPayment ? sendingTransaction ?
<LoadingBolt /> <LoadingBolt />
: :
null null
@ -127,7 +127,7 @@ class Pay extends Component {
} }
Pay.propTypes = { Pay.propTypes = {
sendingPayment: PropTypes.bool.isRequired, sendingTransaction: PropTypes.bool.isRequired,
invoiceAmount: PropTypes.string.isRequired, invoiceAmount: PropTypes.string.isRequired,
onchainAmount: PropTypes.string.isRequired, onchainAmount: PropTypes.string.isRequired,
setOnchainAmount: PropTypes.func.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 { fetchInfo } from '../../../reducers/info'
import { createInvoice, fetchInvoice } from '../../../reducers/invoice' import { createInvoice, fetchInvoice } from '../../../reducers/invoice'
import { hideModal } from '../../../reducers/modal' 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 { fetchChannels } from '../../../reducers/channels'
import { import {
setForm, setForm,
@ -42,6 +43,7 @@ const mapStateToProps = state => ({
ticker: state.ticker, ticker: state.ticker,
balance: state.balance, balance: state.balance,
payment: state.payment, payment: state.payment,
transaction: state.transaction,
form: state.form, form: state.form,
invoice: state.invoice, invoice: state.invoice,
modal: state.modal, modal: state.modal,

Loading…
Cancel
Save