From 6c87563aa2895078e92fe063f75e18ed767add95 Mon Sep 17 00:00:00 2001 From: Jack Mallers Date: Tue, 22 Aug 2017 16:58:31 -0500 Subject: [PATCH] fix(lnd-ipc): fix linting errors --- app/api/index.js | 34 +--- app/lnd/config/index.js | 7 +- app/lnd/index.js | 2 +- app/lnd/lib/lightning.js | 9 +- app/lnd/methods/allchannels.js | 3 - app/lnd/methods/channelbalance.js | 2 +- app/lnd/methods/channels.js | 2 +- app/lnd/methods/createinvoice.js | 4 +- app/lnd/methods/index.js | 156 +++++++++--------- app/lnd/methods/invoice.js | 8 +- app/lnd/methods/invoices.js | 4 +- app/lnd/methods/openchannel.js | 23 +-- app/lnd/methods/payinvoice.js | 4 +- app/lnd/methods/payments.js | 4 +- app/lnd/methods/peers.js | 2 +- app/lnd/methods/pendingchannels.js | 2 +- app/lnd/methods/walletbalance.js | 2 +- app/lnd/push/channel.js | 6 +- app/lnd/utils/index.js | 15 +- app/reducers/activity.js | 54 ------ app/reducers/balance.js | 7 +- app/reducers/channels.js | 12 +- app/reducers/index.js | 4 +- app/reducers/invoice.js | 6 +- app/reducers/ipc.js | 34 ++-- app/reducers/payment.js | 6 +- app/reducers/peers.js | 12 +- app/reducers/ticker.js | 2 +- app/routes/app/components/App.js | 3 - .../components/ChannelForm/ChannelForm.js | 1 - 30 files changed, 180 insertions(+), 250 deletions(-) delete mode 100644 app/lnd/methods/allchannels.js delete mode 100644 app/reducers/activity.js diff --git a/app/api/index.js b/app/api/index.js index a83ab3c0..f1b5bb2f 100644 --- a/app/api/index.js +++ b/app/api/index.js @@ -1,38 +1,6 @@ import axios from 'axios' -export function callApi(endpoint, method = 'get', data = null) { - const BASE_URL = 'http://localhost:3000/api/' - let payload - - if (data) { - payload = { - headers: { - 'Content-Type': 'application/json' - }, - method, - data, - url: `${BASE_URL}${endpoint}` - } - } else { - payload = { - headers: { - 'Content-Type': 'application/json' - }, - method, - url: `${BASE_URL}${endpoint}` - } - } - - return axios(payload) - .then(response => response.data) - .catch(error => error) -} - -export function callApis(endpoints) { - return axios.all(endpoints.map(endpoint => callApi(endpoint))) -} - -export function requestTicker() { +export default function requestTicker() { const BASE_URL = 'https://api.coinmarketcap.com/v1/ticker/bitcoin/' return axios({ method: 'get', diff --git a/app/lnd/config/index.js b/app/lnd/config/index.js index e409c073..3c0f7d2f 100644 --- a/app/lnd/config/index.js +++ b/app/lnd/config/index.js @@ -1,4 +1,9 @@ +// Cert will be located depending on your machine +// Mac OS X: /Users/user/Library/Application Support/Lnd/tls.cert +// Linux: ~/.lnd/tls.cert +// Windows: TODO find out where cert is located for windows machine export default { lightningRpc: `${__dirname}/rpc.proto`, - lightningHost: 'localhost:10009' + lightningHost: 'localhost:10009', + cert: '/Users/jmow/Library/Application Support/Lnd/tls.cert' } diff --git a/app/lnd/index.js b/app/lnd/index.js index c2a87208..5660126a 100644 --- a/app/lnd/index.js +++ b/app/lnd/index.js @@ -4,4 +4,4 @@ import methods from './methods' const lnd = lightning(config.lightningRpc, config.lightningHost) -export default (event, msg, data) => methods(lnd, event, msg, data) \ No newline at end of file +export default (event, msg, data) => methods(lnd, event, msg, data) diff --git a/app/lnd/lib/lightning.js b/app/lnd/lib/lightning.js index fb8cdc1e..7162f537 100644 --- a/app/lnd/lib/lightning.js +++ b/app/lnd/lib/lightning.js @@ -1,13 +1,14 @@ import fs from 'fs' import grpc from 'grpc' +import config from '../config' -module.exports = (path, host, cert) => { - process.env['GRPC_SSL_CIPHER_SUITES'] = 'HIGH+ECDSA' +module.exports = (path, host) => { + process.env.GRPC_SSL_CIPHER_SUITES = 'HIGH+ECDSA' const rpc = grpc.load(path) - const lndCert = fs.readFileSync('/Users/jmow/Library/Application Support/Lnd/tls.cert') + const lndCert = fs.readFileSync(config.cert) const credentials = grpc.credentials.createSsl(lndCert) return new rpc.lnrpc.Lightning(host, credentials) -} \ No newline at end of file +} diff --git a/app/lnd/methods/allchannels.js b/app/lnd/methods/allchannels.js deleted file mode 100644 index 3754e973..00000000 --- a/app/lnd/methods/allchannels.js +++ /dev/null @@ -1,3 +0,0 @@ -export default function(channels, pendingchannels) { - return Promise.all([channels, pendingchannels]) -} \ No newline at end of file diff --git a/app/lnd/methods/channelbalance.js b/app/lnd/methods/channelbalance.js index c3c65413..135a6b6e 100644 --- a/app/lnd/methods/channelbalance.js +++ b/app/lnd/methods/channelbalance.js @@ -7,4 +7,4 @@ export default function channelbalance(lnd) { resolve(data) }) }) -} \ No newline at end of file +} diff --git a/app/lnd/methods/channels.js b/app/lnd/methods/channels.js index 6b274762..512fec27 100644 --- a/app/lnd/methods/channels.js +++ b/app/lnd/methods/channels.js @@ -7,4 +7,4 @@ export default function channels(lnd) { resolve(data) }) }) -} \ No newline at end of file +} diff --git a/app/lnd/methods/createinvoice.js b/app/lnd/methods/createinvoice.js index bd8b21bc..c7fbba35 100644 --- a/app/lnd/methods/createinvoice.js +++ b/app/lnd/methods/createinvoice.js @@ -3,8 +3,8 @@ export default function createInvoice(lnd, { memo, value }) { return new Promise((resolve, reject) => { lnd.addInvoice({ memo, value }, (err, data) => { if (err) { reject(err) } - + resolve(data) }) }) -} \ No newline at end of file +} diff --git a/app/lnd/methods/index.js b/app/lnd/methods/index.js index 1b728e9b..6636bb6f 100644 --- a/app/lnd/methods/index.js +++ b/app/lnd/methods/index.js @@ -1,4 +1,3 @@ -import allchannels from './allchannels' import channelbalance from './channelbalance' import channels from './channels' import connectpeer from './connectpeer' @@ -14,94 +13,101 @@ import peers from './peers' import pendingchannels from './pendingchannels' import walletbalance from './walletbalance' -export default function(lnd, event, msg, data) { - switch(msg) { +export default function (lnd, event, msg, data) { + switch (msg) { case 'info': - info(lnd) - .then(info =>event.sender.send('receiveInfo', info)) - .catch(error => console.log('info error: ', error)) - break - case 'peers': + info(lnd) + .then(infoData => event.sender.send('receiveInfo', infoData)) + .catch(error => console.log('info error: ', error)) + break + case 'peers': // Data looks like { peers: [] } - peers(lnd) - .then(peers => event.sender.send('receivePeers', peers)) - .catch(error => console.log('peers error: ', error)) - break - case 'channels': - // Data looks like [ { channels: [channel, channel, channel] }, { total_limbo_balance: 0, pending_open_channels: [], pending_closing_channels: [], pending_force_closing_channels: [] } ] - Promise.all([channels, pendingchannels].map(func => func(lnd))) - .then(data => event.sender.send('receiveChannels', { channels: data[0].channels, pendingChannels: data[1] })) - .catch(error => console.log('channels error: ', error)) - break - case 'payments': + peers(lnd) + .then(peersData => event.sender.send('receivePeers', peersData)) + .catch(error => console.log('peers error: ', error)) + break + case 'channels': + // Data looks like + // [ { channels: [] }, { total_limbo_balance: 0, pending_open_channels: [], pending_closing_channels: [], pending_force_closing_channels: [] } ] + Promise.all([channels, pendingchannels].map(func => func(lnd))) + .then(channelsData => + event.sender.send('receiveChannels', { channels: channelsData[0].channels, pendingChannels: channelsData[1] }) + ) + .catch(error => console.log('channels error: ', error)) + break + case 'payments': // Data looks like { payments: [] } - payments(lnd) - .then(payments => event.sender.send('receivePayments', payments)) - .catch(error => console.log('payments error: ', error)) - break - case 'invoices': + payments(lnd) + .then(paymentsData => event.sender.send('receivePayments', paymentsData)) + .catch(error => console.log('payments error: ', error)) + break + case 'invoices': // Data looks like { invoices: [] } - invoices(lnd) - .then(invoices => event.sender.send('receiveInvoices', invoices)) - .catch(error => console.log('invoices error: ', error)) - break - case 'invoice': + invoices(lnd) + .then(invoicesData => event.sender.send('receiveInvoices', invoicesData)) + .catch(error => console.log('invoices error: ', error)) + break + case 'invoice': // Data looks like { invoices: [] } - invoice(data.payreq) - .then(invoice => event.sender.send('receiveInvoice', invoice)) - .catch(error => console.log('invoice error: ', error)) - break - case 'balance': + invoice(data.payreq) + .then(invoiceData => event.sender.send('receiveInvoice', invoiceData)) + .catch(error => console.log('invoice error: ', error)) + break + case 'balance': // Balance looks like [ { balance: '129477456' }, { balance: '243914' } ] - Promise.all([walletbalance, channelbalance].map(func => func(lnd))) - .then(balance => event.sender.send('receiveBalance', { walletBalance: balance[0].balance, channelBalance: balance[1].balance })) - .catch(error => console.log('balance error: ', error)) - break - case 'createInvoice': + Promise.all([walletbalance, channelbalance].map(func => func(lnd))) + .then(balance => event.sender.send('receiveBalance', { walletBalance: balance[0].balance, channelBalance: balance[1].balance })) + .catch(error => console.log('balance error: ', error)) + break + case 'createInvoice': // Invoice looks like { r_hash: Buffer, payment_request: '' } // { memo, value } = data - createinvoice(lnd, data) - .then(invoice => event.sender.send('createdInvoice', Object.assign(invoice, { memo: data.memo, value: data.value, r_hash: new Buffer(invoice.r_hash,'hex').toString('hex') }))) - .catch(error => console.log('createInvoice error: ', error)) - break - case 'sendPayment': + createinvoice(lnd, data) + .then(newinvoice => + event.sender.send( + 'createdInvoice', + Object.assign(newinvoice, { memo: data.memo, value: data.value, r_hash: new Buffer(newinvoice.r_hash, 'hex').toString('hex') }) + ) + ) + .catch(error => console.log('createInvoice error: ', error)) + break + case 'sendPayment': // Payment looks like { payment_preimage: Buffer, payment_route: Object } // { paymentRequest } = data - payinvoice(lnd, data) - .then(({ payment_route }) => event.sender.send('paymentSuccessful', Object.assign(data, { payment_route }))) - .catch(error => console.log('payinvoice error: ', error)) - break - case 'openChannel': + payinvoice(lnd, data) + .then(({ payment_route }) => event.sender.send('paymentSuccessful', Object.assign(data, { payment_route }))) + .catch(error => console.log('payinvoice error: ', error)) + break + case 'openChannel': // Response is empty. Streaming updates on channel status and updates // { pubkey, localamt, pushamt } = data - openchannel(lnd, event, data) - .then(channel => { - console.log('CHANNEL: ', channel) - event.sender.send('channelSuccessful', { channel }) - }) - .catch(error => console.log('openChannel error: ', error)) - break - case 'connectPeer': + openchannel(lnd, event, data) + .then((channel) => { + console.log('CHANNEL: ', channel) + event.sender.send('channelSuccessful', { channel }) + }) + .catch(error => console.log('openChannel error: ', error)) + break + case 'connectPeer': // Returns a peer_id. Pass the pubkey, host and peer_id so we can add a new peer to the list // { pubkey, host } = data - connectpeer(lnd, data) - .then(({ peer_id }) => { - console.log('peer_id: ', peer_id) - event.sender.send('connectSuccess', { pub_key: data.pubkey, address: data.host, peer_id }) - }) - .catch(error => console.log('connectPeer error: ', error)) - break - case 'disconnectPeer': + connectpeer(lnd, data) + .then(({ peer_id }) => { + console.log('peer_id: ', peer_id) + event.sender.send('connectSuccess', { pub_key: data.pubkey, address: data.host, peer_id }) + }) + .catch(error => console.log('connectPeer error: ', error)) + break + case 'disconnectPeer': // Empty response. Pass back pubkey on success to remove it from the peers list // { pubkey } = data - disconnectpeer(lnd, data) - .then(() => { - console.log('pubkey: ', data.pubkey) - event.sender.send('disconnectSuccess', { pubkey: data.pubkey }) - }) - .catch(error => console.log('disconnectPeer error: ', error)) - break - default: - return + disconnectpeer(lnd, data) + .then(() => { + console.log('pubkey: ', data.pubkey) + event.sender.send('disconnectSuccess', { pubkey: data.pubkey }) + }) + .catch(error => console.log('disconnectPeer error: ', error)) + break + default: } -} \ No newline at end of file +} diff --git a/app/lnd/methods/invoice.js b/app/lnd/methods/invoice.js index b738b436..2c1f4efa 100644 --- a/app/lnd/methods/invoice.js +++ b/app/lnd/methods/invoice.js @@ -3,6 +3,10 @@ import { decodeInvoice } from '../utils' // LND Get Invoice export default function invoice(payreq) { return new Promise((resolve, reject) => { - resolve(decodeInvoice(payreq)) + try { + resolve(decodeInvoice(payreq)) + } catch (error) { + reject(error) + } }) -} \ No newline at end of file +} diff --git a/app/lnd/methods/invoices.js b/app/lnd/methods/invoices.js index 682aeb02..9cad0746 100644 --- a/app/lnd/methods/invoices.js +++ b/app/lnd/methods/invoices.js @@ -3,8 +3,8 @@ export default function invoices(lnd) { return new Promise((resolve, reject) => { lnd.listInvoices({}, (err, data) => { if (err) { reject(err) } - + resolve(data) }) }) -} \ No newline at end of file +} diff --git a/app/lnd/methods/openchannel.js b/app/lnd/methods/openchannel.js index a75f7400..1282ee87 100644 --- a/app/lnd/methods/openchannel.js +++ b/app/lnd/methods/openchannel.js @@ -1,18 +1,19 @@ -import pushchannel from '../push/channel' import bitcore from 'bitcore-lib' +import pushchannel from '../push/channel' + const BufferUtil = bitcore.util.buffer -export default function openchannel(lnd, event, data) { - const { pubkey, localamt, pushamt } = data - const payload = { +export default function openchannel(lnd, event, payload) { + const { pubkey, localamt, pushamt } = payload + const res = { node_pubkey: BufferUtil.hexToBuffer(pubkey), - local_funding_amount: Number(localamt), - push_sat: Number(pushamt) + local_funding_amount: Number(localamt), + push_sat: Number(pushamt) } - return new Promise((resolve, reject) => - pushchannel(lnd, event, payload) - .then(data => resolve(data)) - .catch(error => reject(err)) + return new Promise((resolve, reject) => + pushchannel(lnd, event, res) + .then(data => resolve(data)) + .catch(error => reject(error)) ) -} \ No newline at end of file +} diff --git a/app/lnd/methods/payinvoice.js b/app/lnd/methods/payinvoice.js index 3ae8e097..43bfa3b8 100644 --- a/app/lnd/methods/payinvoice.js +++ b/app/lnd/methods/payinvoice.js @@ -3,8 +3,8 @@ export default function payinvoice(lnd, { paymentRequest }) { return new Promise((resolve, reject) => { lnd.sendPaymentSync({ payment_request: paymentRequest }, (err, data) => { if (err) { reject(err) } - + resolve(data) }) }) -} \ No newline at end of file +} diff --git a/app/lnd/methods/payments.js b/app/lnd/methods/payments.js index 2182b1dc..a276c3bd 100644 --- a/app/lnd/methods/payments.js +++ b/app/lnd/methods/payments.js @@ -3,8 +3,8 @@ export default function payments(lnd) { return new Promise((resolve, reject) => { lnd.listPayments({}, (err, data) => { if (err) { reject(err) } - + resolve(data) }) }) -} \ No newline at end of file +} diff --git a/app/lnd/methods/peers.js b/app/lnd/methods/peers.js index a7231ef0..1b604c1c 100644 --- a/app/lnd/methods/peers.js +++ b/app/lnd/methods/peers.js @@ -7,4 +7,4 @@ export default function peers(lnd) { resolve(data) }) }) -} \ No newline at end of file +} diff --git a/app/lnd/methods/pendingchannels.js b/app/lnd/methods/pendingchannels.js index cc7d4a15..4408e750 100644 --- a/app/lnd/methods/pendingchannels.js +++ b/app/lnd/methods/pendingchannels.js @@ -7,4 +7,4 @@ export default function channels(lnd) { resolve(data) }) }) -} \ No newline at end of file +} diff --git a/app/lnd/methods/walletbalance.js b/app/lnd/methods/walletbalance.js index 7a830747..e6db48a6 100644 --- a/app/lnd/methods/walletbalance.js +++ b/app/lnd/methods/walletbalance.js @@ -7,4 +7,4 @@ export default function walletbalance(lnd) { resolve(data) }) }) -} \ No newline at end of file +} diff --git a/app/lnd/push/channel.js b/app/lnd/push/channel.js index 7b48da38..4a115dec 100644 --- a/app/lnd/push/channel.js +++ b/app/lnd/push/channel.js @@ -2,15 +2,15 @@ export default function pushchannel(lnd, event, payload) { return new Promise((resolve, reject) => { try { const call = lnd.openChannel(payload) - + call.on('data', data => event.sender.send('pushchannelupdated', { data })) call.on('end', () => event.sender.send('pushchannelend')) call.on('error', error => event.sender.send('pushchannelerror', { error })) call.on('status', status => event.sender.send('pushchannelstatus', { status })) - + resolve(null, payload) } catch (error) { reject(error, null) } }) -} \ No newline at end of file +} diff --git a/app/lnd/utils/index.js b/app/lnd/utils/index.js index 92489035..39cf69c0 100644 --- a/app/lnd/utils/index.js +++ b/app/lnd/utils/index.js @@ -3,8 +3,8 @@ import zbase32 from 'zbase32' function convertBigEndianBufferToLong(longBuffer) { let longValue = 0 const byteArray = Buffer.from(longBuffer).swap64() - - for (let i = byteArray.length - 1; i >= 0; i--) { + + for (let i = byteArray.length - 1; i >= 0; i -= 1) { longValue = (longValue * 256) + byteArray[i] } @@ -19,9 +19,6 @@ export function decodeInvoice(payreq) { + bufferHexRotated.substr(0, bufferHexRotated.length - 1) const buffer = Buffer.from(bufferHex, 'hex') - const pubKeyBuffer = buffer.slice(0, 33) - const pubKeyHex = pubKeyBuffer.toString('hex') - const paymentHashBuffer = buffer.slice(33, 65) const paymentHashHex = paymentHashBuffer.toString('hex') @@ -32,6 +29,10 @@ export function decodeInvoice(payreq) { return { payreq, amount, - r_hash: paymentHashHex, + r_hash: paymentHashHex } -} \ No newline at end of file +} + +export default { + decodeInvoice +} diff --git a/app/reducers/activity.js b/app/reducers/activity.js deleted file mode 100644 index cb391f4d..00000000 --- a/app/reducers/activity.js +++ /dev/null @@ -1,54 +0,0 @@ -import { callApis } from '../api' -// ------------------------------------ -// Constants -// ------------------------------------ -export const GET_ACTIVITY = 'GET_ACTIVITY' -export const RECEIVE_ACTIVITY = 'RECEIVE_ACTIVITY' - -// ------------------------------------ -// Actions -// ------------------------------------ -export function getActivity() { - return { - type: GET_ACTIVITY - } -} - -export function receiveActvity(data) { - return { - type: RECEIVE_ACTIVITY, - payments: data[0].data.payments.reverse(), - invoices: data[1].data.invoices.reverse() - } -} - -export const fetchActivity = () => async (dispatch) => { - dispatch(getActivity()) - const activity = await callApis(['payments', 'invoices']) - dispatch(receiveActvity(activity)) -} - -// ------------------------------------ -// Action Handlers -// ------------------------------------ -const ACTION_HANDLERS = { - [GET_ACTIVITY]: state => ({ ...state, activityLoading: true }), - [RECEIVE_ACTIVITY]: (state, { payments, invoices }) => ( - { ...state, activityLoading: false, payments, invoices } - ) -} - -// ------------------------------------ -// Reducer -// ------------------------------------ -const initialState = { - activityLoading: false, - payments: [], - invoices: [] -} - -export default function activityReducer(state = initialState, action) { - const handler = ACTION_HANDLERS[action.type] - - return handler ? handler(state, action) : state -} diff --git a/app/reducers/balance.js b/app/reducers/balance.js index ab5a3a13..db49a64c 100644 --- a/app/reducers/balance.js +++ b/app/reducers/balance.js @@ -14,13 +14,16 @@ export function getBalance() { } } +// Send IPC event for balance export const fetchBalance = () => async (dispatch) => { dispatch(getBalance()) ipcRenderer.send('lnd', { msg: 'balance' }) } -// Receive IPC event for peers -export const receiveBalance = (event, { walletBalance, channelBalance }) => dispatch => dispatch({ type: RECEIVE_BALANCE, walletBalance, channelBalance }) +// Receive IPC event for balance +export const receiveBalance = (event, { walletBalance, channelBalance }) => dispatch => ( + dispatch({ type: RECEIVE_BALANCE, walletBalance, channelBalance }) +) // ------------------------------------ // Action Handlers diff --git a/app/reducers/channels.js b/app/reducers/channels.js index 898876f6..9003c5b5 100644 --- a/app/reducers/channels.js +++ b/app/reducers/channels.js @@ -66,34 +66,34 @@ export const fetchChannels = () => async (dispatch) => { export const receiveChannels = (event, { channels, pendingChannels }) => dispatch => dispatch({ type: RECEIVE_CHANNELS, channels, pendingChannels }) // Send IPC event for opening a channel -export const openChannel = ({ pubkey, localamt, pushamt }) => dispatch => { +export const openChannel = ({ pubkey, localamt, pushamt }) => (dispatch) => { dispatch(openingChannel()) ipcRenderer.send('lnd', { msg: 'openChannel', data: { pubkey, localamt, pushamt } }) } // TODO: Decide how to handle streamed updates for channels // Receive IPC event for openChannel -export const channelSuccessful = (event, { channel }) => dispatch => { +export const channelSuccessful = () => (dispatch) => { dispatch(fetchChannels()) } // Receive IPC event for updated channel -export const pushchannelupdated = (event, data) => dispatch => { +export const pushchannelupdated = () => (dispatch) => { dispatch(fetchChannels()) } // Receive IPC event for channel end -export const pushchannelend = (event, data) => dispatch => { +export const pushchannelend = () => (dispatch) => { dispatch(fetchChannels()) } // Receive IPC event for channel error -export const pushchannelerror = (event, data) => dispatch => { +export const pushchannelerror = () => (dispatch) => { dispatch(fetchChannels()) } // Receive IPC event for channel status -export const pushchannelstatus = (event, data) => dispatch => { +export const pushchannelstatus = () => (dispatch) => { dispatch(fetchChannels()) } diff --git a/app/reducers/index.js b/app/reducers/index.js index a77099ec..d7df67f8 100644 --- a/app/reducers/index.js +++ b/app/reducers/index.js @@ -9,7 +9,6 @@ import peers from './peers' import channels from './channels' import form from './form' import invoice from './invoice' -import activity from './activity' const rootReducer = combineReducers({ router, @@ -20,8 +19,7 @@ const rootReducer = combineReducers({ peers, channels, form, - invoice, - activity + invoice }) export default rootReducer diff --git a/app/reducers/invoice.js b/app/reducers/invoice.js index aceb5735..8cedcc2b 100644 --- a/app/reducers/invoice.js +++ b/app/reducers/invoice.js @@ -69,7 +69,7 @@ export function invoiceFailed() { } // Send IPC event for a specific invoice -export const fetchInvoice = payreq => dispatch => { +export const fetchInvoice = payreq => (dispatch) => { dispatch(getInvoice()) ipcRenderer.send('lnd', { msg: 'invoice', data: { payreq } }) } @@ -78,7 +78,7 @@ export const fetchInvoice = payreq => dispatch => { export const receiveFormInvoice = (event, formInvoice) => dispatch => dispatch({ type: RECEIVE_FORM_INVOICE, formInvoice }) // Send IPC event for invoices -export const fetchInvoices = () => dispatch => { +export const fetchInvoices = () => (dispatch) => { dispatch(getInvoices()) ipcRenderer.send('lnd', { msg: 'invoices' }) } @@ -87,7 +87,7 @@ export const fetchInvoices = () => dispatch => { export const receiveInvoices = (event, { invoices }) => dispatch => dispatch({ type: RECEIVE_INVOICES, invoices }) // Send IPC event for creating an invoice -export const createInvoice = (amount, memo, currency, rate) => dispatch => { +export const createInvoice = (amount, memo, currency, rate) => (dispatch) => { const value = currency === 'btc' ? btc.btcToSatoshis(amount) : btc.btcToSatoshis(usd.usdToBtc(amount, rate)) dispatch(sendInvoice()) ipcRenderer.send('lnd', { msg: 'createInvoice', data: { value, memo } }) diff --git a/app/reducers/ipc.js b/app/reducers/ipc.js index 4980ed05..3d2ade7c 100644 --- a/app/reducers/ipc.js +++ b/app/reducers/ipc.js @@ -15,22 +15,22 @@ import { receiveBalance } from './balance' // Import all receiving IPC event handlers and pass them into createIpc const ipc = createIpc({ - 'receiveInfo': receiveInfo, - 'receivePeers': receivePeers, - 'receiveChannels': receiveChannels, - 'receivePayments': receivePayments, - 'receiveInvoices': receiveInvoices, - 'receiveInvoice': receiveFormInvoice, - 'receiveBalance': receiveBalance, - 'createdInvoice': createdInvoice, - 'paymentSuccessful': paymentSuccessful, - 'channelSuccessful': channelSuccessful, - 'pushchannelupdated': pushchannelupdated, - 'pushchannelend': pushchannelend, - 'pushchannelerror': pushchannelerror, - 'pushchannelstatus': pushchannelstatus, - 'connectSuccess': connectSuccess, - 'disconnectSuccess': disconnectSuccess + receiveInfo, + receivePeers, + receiveChannels, + receivePayments, + receiveInvoices, + receiveInvoice: receiveFormInvoice, + receiveBalance, + createdInvoice, + paymentSuccessful, + channelSuccessful, + pushchannelupdated, + pushchannelend, + pushchannelerror, + pushchannelstatus, + connectSuccess, + disconnectSuccess }) -export default ipc \ No newline at end of file +export default ipc diff --git a/app/reducers/payment.js b/app/reducers/payment.js index 99378969..448214f4 100644 --- a/app/reducers/payment.js +++ b/app/reducers/payment.js @@ -1,6 +1,5 @@ import { createSelector } from 'reselect' import { ipcRenderer } from 'electron' -import { callApi } from '../api' // ------------------------------------ // Constants @@ -50,7 +49,7 @@ export function paymentFailed() { } // Send IPC event for payments -export const fetchPayments = () => dispatch => { +export const fetchPayments = () => (dispatch) => { dispatch(getPayments()) ipcRenderer.send('lnd', { msg: 'payments' }) } @@ -58,12 +57,13 @@ export const fetchPayments = () => dispatch => { // Receive IPC event for payments export const receivePayments = (event, { payments }) => dispatch => dispatch({ type: RECEIVE_PAYMENTS, payments }) -export const payInvoice = paymentRequest => dispatch => { +export const payInvoice = paymentRequest => (dispatch) => { dispatch(sendPayment()) ipcRenderer.send('lnd', { msg: 'sendPayment', data: { paymentRequest } }) } // Receive IPC event for successful payment +// TODO: Add payment to state, not a total re-fetch export const paymentSuccessful = () => fetchPayments() diff --git a/app/reducers/peers.js b/app/reducers/peers.js index f75e8505..e6aec70e 100644 --- a/app/reducers/peers.js +++ b/app/reducers/peers.js @@ -75,7 +75,7 @@ export const fetchPeers = () => async (dispatch) => { export const receivePeers = (event, { peers }) => dispatch => dispatch({ type: RECEIVE_PEERS, peers }) // Send IPC event for connecting to a peer -export const connectRequest = ({ pubkey, host }) => dispatch => { +export const connectRequest = ({ pubkey, host }) => (dispatch) => { dispatch(connectPeer()) ipcRenderer.send('lnd', { msg: 'connectPeer', data: { pubkey, host } }) } @@ -84,7 +84,7 @@ export const connectRequest = ({ pubkey, host }) => dispatch => { export const connectSuccess = (event, peer) => dispatch => dispatch({ type: CONNECT_SUCCESS, peer }) // Send IPC send for disconnecting from a peer -export const disconnectRequest = ({ pubkey }) => dispatch => { +export const disconnectRequest = ({ pubkey }) => (dispatch) => { dispatch(disconnectPeer()) ipcRenderer.send('lnd', { msg: 'disconnectPeer', data: { pubkey } }) } @@ -97,11 +97,15 @@ export const disconnectSuccess = (event, { pubkey }) => dispatch => dispatch({ t // ------------------------------------ const ACTION_HANDLERS = { [DISCONNECT_PEER]: state => ({ ...state, disconnecting: true }), - [DISCONNECT_SUCCESS]: (state, { pubkey }) => ({ ...state, disconnecting: false, peer: null, peers: state.peers.filter(peer => peer.pub_key !== pubkey) }), + [DISCONNECT_SUCCESS]: (state, { pubkey }) => ( + { ...state, disconnecting: false, peer: null, peers: state.peers.filter(peer => peer.pub_key !== pubkey) } + ), [DISCONNECT_FAILURE]: state => ({ ...state, disconnecting: false }), [CONNECT_PEER]: state => ({ ...state, connecting: true }), - [CONNECT_SUCCESS]: (state, { peer }) => ({ ...state, connecting: false, peerForm: { pubkey: '', host: '', isOpen: false }, peers: [...state.peers, peer] }), + [CONNECT_SUCCESS]: (state, { peer }) => ( + { ...state, connecting: false, peerForm: { pubkey: '', host: '', isOpen: false }, peers: [...state.peers, peer] } + ), [CONNECT_FAILURE]: state => ({ ...state, connecting: false }), [SET_PEER_FORM]: (state, { form }) => ({ ...state, peerForm: Object.assign({}, state.peerForm, form) }), diff --git a/app/reducers/ticker.js b/app/reducers/ticker.js index 552d98b2..6e9a5fdb 100644 --- a/app/reducers/ticker.js +++ b/app/reducers/ticker.js @@ -1,4 +1,4 @@ -import { requestTicker } from '../api' +import requestTicker from '../api' // ------------------------------------ // Constants // ------------------------------------ diff --git a/app/routes/app/components/App.js b/app/routes/app/components/App.js index 8c06d483..1571f911 100644 --- a/app/routes/app/components/App.js +++ b/app/routes/app/components/App.js @@ -1,4 +1,3 @@ -import { ipcRenderer } from 'electron' import React, { Component } from 'react' import PropTypes from 'prop-types' import Form from './components/Form' @@ -29,7 +28,6 @@ class App extends Component { setForm, createInvoice, payInvoice, - fetchChannels, fetchInvoice, children } = this.props @@ -83,7 +81,6 @@ App.propTypes = { setForm: PropTypes.func.isRequired, createInvoice: PropTypes.func.isRequired, payInvoice: PropTypes.func.isRequired, - fetchChannels: PropTypes.func.isRequired, fetchInvoice: PropTypes.func.isRequired, children: PropTypes.object.isRequired } diff --git a/app/routes/wallet/components/components/Channels/components/ChannelForm/ChannelForm.js b/app/routes/wallet/components/components/Channels/components/ChannelForm/ChannelForm.js index 01329542..fdc3160e 100644 --- a/app/routes/wallet/components/components/Channels/components/ChannelForm/ChannelForm.js +++ b/app/routes/wallet/components/components/Channels/components/ChannelForm/ChannelForm.js @@ -14,7 +14,6 @@ const ChannelForm = ({ form, setForm, ticker, peers, openChannel }) => { openChannel({ pubkey: node_key, localamt, pushamt }) setForm({ isOpen: false }) - } const customStyles = {