Browse Source

feature(sendcoins): tie sendcoins frontend to backend

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

8
app/lnd/methods/index.js

@ -95,11 +95,11 @@ export default function (lnd, event, msg, data) {
break break
case 'sendCoins': case 'sendCoins':
// Transaction looks like { txid: String } // Transaction looks like { txid: String }
// { addr, amount } = data // { amount, addr } = data
walletController.sendCoins(lnd, data) walletController.sendCoins(lnd, data)
.then((transaction) => { .then(({ txid }) => {
console.log('transaction: ', transaction) console.log('transactionId: ', transactionId)
event.sender.send('sendSuccessful', { transaction }) event.sender.send('sendSuccessful', { amount: data.amount, addr: data.addr, txid })
}) })
.catch(error => console.log('sendcoins error: ', error)) .catch(error => console.log('sendcoins error: ', error))
break break

3
app/reducers/ipc.js

@ -19,7 +19,7 @@ import {
pushclosechannelstatus pushclosechannelstatus
} from './channels' } from './channels'
import { receivePayments, paymentSuccessful } from './payment' import { receivePayments, paymentSuccessful, sendSuccessful } from './payment'
import { receiveInvoices, createdInvoice, receiveFormInvoice } from './invoice' import { receiveInvoices, createdInvoice, receiveFormInvoice } from './invoice'
import { receiveBalance } from './balance' import { receiveBalance } from './balance'
@ -40,6 +40,7 @@ const ipc = createIpc({
receiveBalance, receiveBalance,
paymentSuccessful, paymentSuccessful,
sendSuccessful,
channelSuccessful, channelSuccessful,
pushchannelupdated, pushchannelupdated,

13
app/reducers/payment.js

@ -1,5 +1,6 @@
import { createSelector } from 'reselect' import { createSelector } from 'reselect'
import { ipcRenderer } from 'electron' import { ipcRenderer } from 'electron'
import { btc, usd } from '../utils'
// ------------------------------------ // ------------------------------------
// Constants // Constants
@ -62,10 +63,22 @@ 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, crypto, 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 => {
console.log('amount: ', amount)
console.log('addr: ', addr)
console.log('txid: ', txid)
}
// ------------------------------------ // ------------------------------------
// Action Handlers // Action Handlers

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

@ -31,6 +31,7 @@ class App extends Component {
setPaymentType, setPaymentType,
createInvoice, createInvoice,
payInvoice, payInvoice,
sendCoins,
fetchInvoice, fetchInvoice,
currentTicker, currentTicker,
isOnchain, isOnchain,
@ -57,6 +58,7 @@ class App extends Component {
form={form} form={form}
createInvoice={createInvoice} createInvoice={createInvoice}
payInvoice={payInvoice} payInvoice={payInvoice}
sendCoins={sendCoins}
fetchInvoice={fetchInvoice} fetchInvoice={fetchInvoice}
formInvoice={formInvoice} formInvoice={formInvoice}
currentTicker={currentTicker} currentTicker={currentTicker}
@ -96,6 +98,7 @@ App.propTypes = {
setForm: PropTypes.func.isRequired, setForm: PropTypes.func.isRequired,
createInvoice: PropTypes.func.isRequired, createInvoice: PropTypes.func.isRequired,
payInvoice: PropTypes.func.isRequired, payInvoice: PropTypes.func.isRequired,
sendCoins: PropTypes.func.isRequired,
fetchInvoice: PropTypes.func.isRequired, fetchInvoice: PropTypes.func.isRequired,
fetchInfo: PropTypes.func.isRequired, fetchInfo: PropTypes.func.isRequired,
currentTicker: PropTypes.object, currentTicker: PropTypes.object,

4
app/routes/app/components/components/Form/Form.js

@ -19,6 +19,7 @@ const Form = ({
close, close,
createInvoice, createInvoice,
payInvoice, payInvoice,
sendCoins,
fetchInvoice, fetchInvoice,
formInvoice, formInvoice,
currentTicker, currentTicker,
@ -45,6 +46,8 @@ const Form = ({
setPaymentRequest={setPaymentRequest} setPaymentRequest={setPaymentRequest}
fetchInvoice={fetchInvoice} fetchInvoice={fetchInvoice}
payInvoice={payInvoice} payInvoice={payInvoice}
sendCoins={sendCoins}
currentTicker={currentTicker}
currency={currency} currency={currency}
crypto={crypto} crypto={crypto}
close={close} close={close}
@ -84,6 +87,7 @@ Form.propTypes = {
close: PropTypes.func.isRequired, close: PropTypes.func.isRequired,
createInvoice: PropTypes.func.isRequired, createInvoice: PropTypes.func.isRequired,
payInvoice: PropTypes.func.isRequired, payInvoice: PropTypes.func.isRequired,
sendCoins: PropTypes.func.isRequired,
fetchInvoice: PropTypes.func.isRequired, fetchInvoice: PropTypes.func.isRequired,
formInvoice: PropTypes.object.isRequired, formInvoice: PropTypes.object.isRequired,
currentTicker: PropTypes.object.isRequired, currentTicker: PropTypes.object.isRequired,

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

@ -24,16 +24,19 @@ class Pay extends Component {
setPaymentRequest, setPaymentRequest,
fetchInvoice, fetchInvoice,
payInvoice, payInvoice,
sendCoins,
currentTicker,
currency, currency,
crypto, crypto,
close, close,
isOnchain, isOnchain,
isLn isLn
} = this.props } = this.props
const payClicked = () => { const payClicked = () => {
if (!isOnchain || !isLn) { return } if (!isOnchain && !isLn) { return }
// if (isOnchain) { sendcoins() } if (isOnchain) { sendCoins({ value: onchainAmount, addr: payment_request, currency, crypto, rate: currentTicker.price_usd }) }
if (isLn) { payInvoice(payment_request) } if (isLn) { payInvoice(payment_request) }
close() close()
} }
@ -130,6 +133,8 @@ Pay.propTypes = {
setPaymentRequest: PropTypes.func.isRequired, setPaymentRequest: PropTypes.func.isRequired,
fetchInvoice: PropTypes.func.isRequired, fetchInvoice: PropTypes.func.isRequired,
payInvoice: PropTypes.func.isRequired, payInvoice: PropTypes.func.isRequired,
sendCoins: PropTypes.func.isRequired,
currentTicker: PropTypes.object.isRequired,
currency: PropTypes.string.isRequired, currency: PropTypes.string.isRequired,
crypto: PropTypes.string.isRequired, crypto: PropTypes.string.isRequired,
close: PropTypes.func.isRequired, close: PropTypes.func.isRequired,

3
app/routes/app/containers/AppContainer.js

@ -4,7 +4,7 @@ import { fetchTicker, setCurrency, tickerSelectors } from '../../../reducers/tic
import { fetchBalance } from '../../../reducers/balance' 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 { payInvoice } from '../../../reducers/payment' import { payInvoice, sendCoins } from '../../../reducers/payment'
import { fetchChannels } from '../../../reducers/channels' import { fetchChannels } from '../../../reducers/channels'
import { import {
setForm, setForm,
@ -31,6 +31,7 @@ const mapDispatchToProps = {
setPaymentType, setPaymentType,
createInvoice, createInvoice,
payInvoice, payInvoice,
sendCoins,
fetchChannels, fetchChannels,
fetchInvoice fetchInvoice
} }

Loading…
Cancel
Save