diff --git a/app/lnd/methods/index.js b/app/lnd/methods/index.js index ab3129a8..7c1b634a 100644 --- a/app/lnd/methods/index.js +++ b/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 diff --git a/app/reducers/ipc.js b/app/reducers/ipc.js index 15a92e75..efee4e22 100644 --- a/app/reducers/ipc.js +++ b/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, diff --git a/app/reducers/payment.js b/app/reducers/payment.js index 448214f4..849cae8d 100644 --- a/app/reducers/payment.js +++ b/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 diff --git a/app/routes/app/components/App.js b/app/routes/app/components/App.js index bc6c4823..8d84b980 100644 --- a/app/routes/app/components/App.js +++ b/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, diff --git a/app/routes/app/components/components/Form/Form.js b/app/routes/app/components/components/Form/Form.js index bef452cf..88b9c709 100644 --- a/app/routes/app/components/components/Form/Form.js +++ b/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, diff --git a/app/routes/app/components/components/Form/components/Pay/Pay.js b/app/routes/app/components/components/Form/components/Pay/Pay.js index 9a084477..0aab1153 100644 --- a/app/routes/app/components/components/Form/components/Pay/Pay.js +++ b/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, diff --git a/app/routes/app/containers/AppContainer.js b/app/routes/app/containers/AppContainer.js index 6f3b21ad..f0b1d261 100644 --- a/app/routes/app/containers/AppContainer.js +++ b/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 }