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
case 'sendCoins':
// Transaction looks like { txid: String }
// { addr, amount } = data
// { amount, addr } = data
walletController.sendCoins(lnd, data)
.then((transaction) => {
console.log('transaction: ', transaction)
event.sender.send('sendSuccessful', { transaction })
.then(({ txid }) => {
console.log('transactionId: ', transactionId)
event.sender.send('sendSuccessful', { amount: data.amount, addr: data.addr, txid })
})
.catch(error => console.log('sendcoins error: ', error))
break

3
app/reducers/ipc.js

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

13
app/reducers/payment.js

@ -1,5 +1,6 @@
import { createSelector } from 'reselect'
import { ipcRenderer } from 'electron'
import { btc, usd } from '../utils'
// ------------------------------------
// Constants
@ -62,10 +63,22 @@ export const payInvoice = paymentRequest => (dispatch) => {
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
// TODO: Add payment to state, not a total re-fetch
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

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

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

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

@ -19,6 +19,7 @@ const Form = ({
close,
createInvoice,
payInvoice,
sendCoins,
fetchInvoice,
formInvoice,
currentTicker,
@ -45,6 +46,8 @@ const Form = ({
setPaymentRequest={setPaymentRequest}
fetchInvoice={fetchInvoice}
payInvoice={payInvoice}
sendCoins={sendCoins}
currentTicker={currentTicker}
currency={currency}
crypto={crypto}
close={close}
@ -84,6 +87,7 @@ Form.propTypes = {
close: PropTypes.func.isRequired,
createInvoice: PropTypes.func.isRequired,
payInvoice: PropTypes.func.isRequired,
sendCoins: PropTypes.func.isRequired,
fetchInvoice: PropTypes.func.isRequired,
formInvoice: 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,
fetchInvoice,
payInvoice,
sendCoins,
currentTicker,
currency,
crypto,
close,
isOnchain,
isLn
} = this.props
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) }
close()
}
@ -130,6 +133,8 @@ Pay.propTypes = {
setPaymentRequest: PropTypes.func.isRequired,
fetchInvoice: PropTypes.func.isRequired,
payInvoice: PropTypes.func.isRequired,
sendCoins: PropTypes.func.isRequired,
currentTicker: PropTypes.object.isRequired,
currency: PropTypes.string.isRequired,
crypto: PropTypes.string.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 { fetchInfo } from '../../../reducers/info'
import { createInvoice, fetchInvoice } from '../../../reducers/invoice'
import { payInvoice } from '../../../reducers/payment'
import { payInvoice, sendCoins } from '../../../reducers/payment'
import { fetchChannels } from '../../../reducers/channels'
import {
setForm,
@ -31,6 +31,7 @@ const mapDispatchToProps = {
setPaymentType,
createInvoice,
payInvoice,
sendCoins,
fetchChannels,
fetchInvoice
}

Loading…
Cancel
Save