diff --git a/app/api/index.js b/app/api/index.js index 3873274d..272f1557 100644 --- a/app/api/index.js +++ b/app/api/index.js @@ -12,7 +12,5 @@ export function requestTicker(id) { export function requestTickers(ids) { return axios.all(ids.map(id => requestTicker(id))) - .then(axios.spread((btcTicker, ltcTicker) => { - return { btcTicker: btcTicker[0], ltcTicker: ltcTicker[0] } - })) -} \ No newline at end of file + .then(axios.spread((btcTicker, ltcTicker) => ({ btcTicker: btcTicker[0], ltcTicker: ltcTicker[0] }))) +} diff --git a/app/lnd/methods/index.js b/app/lnd/methods/index.js index 6782a3d1..7f8c12c9 100644 --- a/app/lnd/methods/index.js +++ b/app/lnd/methods/index.js @@ -20,7 +20,10 @@ export default function (lnd, event, msg, data) { switch (msg) { case 'info': info(lnd) - .then(infoData => event.sender.send('receiveInfo', infoData)) + .then((infoData) => { + event.sender.send('receiveInfo', infoData) + event.sender.send('receiveCryptocurrency', infoData.chains[0]) + }) .catch(error => console.log('info error: ', error)) break case 'newaddress': diff --git a/app/reducers/ipc.js b/app/reducers/ipc.js index a0823a20..7fadc84e 100644 --- a/app/reducers/ipc.js +++ b/app/reducers/ipc.js @@ -1,6 +1,7 @@ import createIpc from 'redux-electron-ipc' import { receiveInfo } from './info' import { receiveAddress } from './address' +import { receiveCryptocurrency } from './ticker' import { receivePeers, connectSuccess, disconnectSuccess } from './peers' import { receiveChannels, @@ -32,7 +33,8 @@ const ipc = createIpc({ pushchannelstatus, connectSuccess, disconnectSuccess, - receiveAddress + receiveAddress, + receiveCryptocurrency }) export default ipc diff --git a/app/reducers/ticker.js b/app/reducers/ticker.js index e426508e..c796a99f 100644 --- a/app/reducers/ticker.js +++ b/app/reducers/ticker.js @@ -45,7 +45,7 @@ export function recieveTickers({ btcTicker, ltcTicker }) { } } -export const fetchTicker = (id) => async (dispatch) => { +export const fetchTicker = () => async (dispatch) => { dispatch(getTickers()) const tickers = await requestTickers(['bitcoin', 'litecoin']) dispatch(recieveTickers(tickers)) @@ -54,8 +54,7 @@ export const fetchTicker = (id) => async (dispatch) => { } // Receive IPC event for receiveCryptocurrency -export const receiveCryptocurrency = (event, currency) => dispatch => { - console.log('currency: ', currency) +export const receiveCryptocurrency = (event, currency) => (dispatch) => { dispatch({ type: SET_CURRENCY, currency: cryptoTickers[currency] }) dispatch({ type: SET_CRYPTO, crypto: cryptoTickers[currency] }) } @@ -83,7 +82,7 @@ tickerSelectors.currentTicker = createSelector( cryptoSelector, bitcoinTickerSelector, litecoinTickerSelector, - (crypto, btcTicker, ltcTicker) => crypto === 'btc' ? btcTicker : ltcTicker + (crypto, btcTicker, ltcTicker) => (crypto === 'btc' ? btcTicker : ltcTicker) ) export { tickerSelectors } @@ -93,8 +92,8 @@ export { tickerSelectors } // ------------------------------------ const initialState = { tickerLoading: false, - currency: 'btc', - crypto: 'btc', + currency: '', + crypto: '', btcTicker: null, ltcTicker: null } @@ -103,4 +102,4 @@ export default function tickerReducer(state = initialState, action) { const handler = ACTION_HANDLERS[action.type] return handler ? handler(state, action) : state -} \ No newline at end of file +} diff --git a/app/routes/activity/components/Activity.js b/app/routes/activity/components/Activity.js index f22ad27a..85692c8e 100644 --- a/app/routes/activity/components/Activity.js +++ b/app/routes/activity/components/Activity.js @@ -106,7 +106,8 @@ Activity.propTypes = { setPayment: PropTypes.func.isRequired, setInvoice: PropTypes.func.isRequired, paymentModalOpen: PropTypes.bool.isRequired, - invoiceModalOpen: PropTypes.bool.isRequired + invoiceModalOpen: PropTypes.bool.isRequired, + currentTicker: PropTypes.object.isRequired } export default Activity diff --git a/app/routes/activity/components/components/Invoices.js b/app/routes/activity/components/components/Invoices.js index 443f3440..b95d657d 100644 --- a/app/routes/activity/components/components/Invoices.js +++ b/app/routes/activity/components/components/Invoices.js @@ -108,7 +108,8 @@ Invoices.propTypes = { invoices: PropTypes.array.isRequired, ticker: PropTypes.object.isRequired, setInvoice: PropTypes.func.isRequired, - invoiceModalOpen: PropTypes.bool.isRequired + invoiceModalOpen: PropTypes.bool.isRequired, + currentTicker: PropTypes.object.isRequired } export default Invoices diff --git a/app/routes/activity/components/components/Payments.js b/app/routes/activity/components/components/Payments.js index 442a1996..9117084a 100644 --- a/app/routes/activity/components/components/Payments.js +++ b/app/routes/activity/components/components/Payments.js @@ -108,7 +108,8 @@ Payments.propTypes = { payments: PropTypes.array.isRequired, ticker: PropTypes.object.isRequired, setPayment: PropTypes.func.isRequired, - paymentModalOpen: PropTypes.bool.isRequired + paymentModalOpen: PropTypes.bool.isRequired, + currentTicker: PropTypes.object.isRequired } export default Payments diff --git a/app/routes/app/components/App.js b/app/routes/app/components/App.js index 30d51a02..3a51c121 100644 --- a/app/routes/app/components/App.js +++ b/app/routes/app/components/App.js @@ -6,10 +6,11 @@ import styles from './App.scss' class App extends Component { componentWillMount() { - const { fetchTicker, fetchBalance } = this.props + const { fetchTicker, fetchBalance, fetchInfo } = this.props fetchTicker() fetchBalance() + fetchInfo() } render() { @@ -33,6 +34,8 @@ class App extends Component { children } = this.props + if (!currentTicker) { return
Loading...
} + return (
( +const Channel = ({ ticker, channel, setChannel, currentTicker }) => (
  • setChannel(channel)}>

    Status: Open

    @@ -59,7 +59,8 @@ const Channel = ({ ticker, channel, setChannel }) => ( Channel.propTypes = { ticker: PropTypes.object.isRequired, channel: PropTypes.object.isRequired, - setChannel: PropTypes.func.isRequired + setChannel: PropTypes.func.isRequired, + currentTicker: PropTypes.object.isRequired } export default Channel 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 54a4d8fc..872638f6 100644 --- a/app/routes/wallet/components/components/Channels/components/ChannelForm/ChannelForm.js +++ b/app/routes/wallet/components/components/Channels/components/ChannelForm/ChannelForm.js @@ -129,7 +129,8 @@ ChannelForm.propTypes = { setForm: PropTypes.func.isRequired, ticker: PropTypes.object.isRequired, peers: PropTypes.array.isRequired, - openChannel: PropTypes.func.isRequired + openChannel: PropTypes.func.isRequired, + currentTicker: PropTypes.object.isRequired } export default ChannelForm diff --git a/app/routes/wallet/components/components/Channels/components/ClosedPendingChannel/ClosedPendingChannel.js b/app/routes/wallet/components/components/Channels/components/ClosedPendingChannel/ClosedPendingChannel.js index efd03f29..2bd3a307 100644 --- a/app/routes/wallet/components/components/Channels/components/ClosedPendingChannel/ClosedPendingChannel.js +++ b/app/routes/wallet/components/components/Channels/components/ClosedPendingChannel/ClosedPendingChannel.js @@ -59,7 +59,8 @@ const ClosedPendingChannel = ({ ticker, channel: { channel, closing_txid }, curr ClosedPendingChannel.propTypes = { ticker: PropTypes.object.isRequired, - channel: PropTypes.object.isRequired + channel: PropTypes.object.isRequired, + currentTicker: PropTypes.object.isRequired } export default ClosedPendingChannel diff --git a/app/routes/wallet/components/components/Channels/components/OpenPendingChannel/OpenPendingChannel.js b/app/routes/wallet/components/components/Channels/components/OpenPendingChannel/OpenPendingChannel.js index fd1fd71a..5e2eeb28 100644 --- a/app/routes/wallet/components/components/Channels/components/OpenPendingChannel/OpenPendingChannel.js +++ b/app/routes/wallet/components/components/Channels/components/OpenPendingChannel/OpenPendingChannel.js @@ -59,7 +59,8 @@ const OpenPendingChannel = ({ ticker, channel: { channel }, currentTicker }) => OpenPendingChannel.propTypes = { ticker: PropTypes.object.isRequired, - channel: PropTypes.object.isRequired + channel: PropTypes.object.isRequired, + currentTicker: PropTypes.object.isRequired } export default OpenPendingChannel diff --git a/app/routes/wallet/containers/WalletContainer.js b/app/routes/wallet/containers/WalletContainer.js index f428da93..e9bc00b2 100644 --- a/app/routes/wallet/containers/WalletContainer.js +++ b/app/routes/wallet/containers/WalletContainer.js @@ -1,6 +1,5 @@ import { connect } from 'react-redux' import { newAddress } from '../../../reducers/address' -import { fetchInfo } from '../../../reducers/info' import { tickerSelectors } from '../../../reducers/ticker' import { fetchPeers, @@ -23,8 +22,6 @@ import Wallet from '../components/Wallet' const mapDispatchToProps = { newAddress, - fetchInfo, - fetchPeers, setPeer, connectRequest, diff --git a/test/reducers/__snapshots__/ticker.spec.js.snap b/test/reducers/__snapshots__/ticker.spec.js.snap index c5123d6e..06102a8b 100644 --- a/test/reducers/__snapshots__/ticker.spec.js.snap +++ b/test/reducers/__snapshots__/ticker.spec.js.snap @@ -3,17 +3,29 @@ exports[`reducers tickerReducer should correctly getTicker 1`] = ` Object { "btcTicker": null, - "crypto": "btc", - "currency": "btc", + "crypto": "", + "currency": "", + "ltcTicker": null, "tickerLoading": true, } `; exports[`reducers tickerReducer should correctly receiveTicker 1`] = ` Object { - "btcTicker": "f", - "crypto": "btc", - "currency": "btc", + "btcTicker": undefined, + "crypto": "", + "currency": "", + "ltcTicker": undefined, + "tickerLoading": false, +} +`; + +exports[`reducers tickerReducer should correctly setCrypto 1`] = ` +Object { + "btcTicker": null, + "crypto": "foo", + "currency": "", + "ltcTicker": null, "tickerLoading": false, } `; @@ -21,8 +33,9 @@ Object { exports[`reducers tickerReducer should correctly setCurrency 1`] = ` Object { "btcTicker": null, - "crypto": "btc", + "crypto": "", "currency": "foo", + "ltcTicker": null, "tickerLoading": false, } `; @@ -30,8 +43,9 @@ Object { exports[`reducers tickerReducer should handle initial state 1`] = ` Object { "btcTicker": null, - "crypto": "btc", - "currency": "btc", + "crypto": "", + "currency": "", + "ltcTicker": null, "tickerLoading": false, } `; diff --git a/test/reducers/ticker.spec.js b/test/reducers/ticker.spec.js index 113e8c4a..3ac6ab40 100644 --- a/test/reducers/ticker.spec.js +++ b/test/reducers/ticker.spec.js @@ -1,7 +1,8 @@ import tickerReducer, { SET_CURRENCY, - GET_TICKER, - RECIEVE_TICKER + SET_CRYPTO, + GET_TICKERS, + RECIEVE_TICKERS } from '../../app/reducers/ticker' describe('reducers', () => { @@ -14,24 +15,32 @@ describe('reducers', () => { expect(SET_CURRENCY).toEqual('SET_CURRENCY') }) + it('should have SET_CRYPTO', () => { + expect(SET_CRYPTO).toEqual('SET_CRYPTO') + }) + it('should have GET_TICKER', () => { - expect(GET_TICKER).toEqual('GET_TICKER') + expect(GET_TICKERS).toEqual('GET_TICKERS') }) it('should have RECIEVE_TICKER', () => { - expect(RECIEVE_TICKER).toEqual('RECIEVE_TICKER') + expect(RECIEVE_TICKERS).toEqual('RECIEVE_TICKERS') }) it('should correctly setCurrency', () => { expect(tickerReducer(undefined, { type: SET_CURRENCY, currency: 'foo' })).toMatchSnapshot() }) + it('should correctly setCrypto', () => { + expect(tickerReducer(undefined, { type: SET_CRYPTO, crypto: 'foo' })).toMatchSnapshot() + }) + it('should correctly getTicker', () => { - expect(tickerReducer(undefined, { type: GET_TICKER })).toMatchSnapshot() + expect(tickerReducer(undefined, { type: GET_TICKERS })).toMatchSnapshot() }) it('should correctly receiveTicker', () => { - expect(tickerReducer(undefined, { type: RECIEVE_TICKER, ticker: 'foo' })).toMatchSnapshot() + expect(tickerReducer(undefined, { type: RECIEVE_TICKERS, ticker: 'foo' })).toMatchSnapshot() }) }) })