Browse Source

fix(currentTicker): fix tests and lint errors

renovate/lint-staged-8.x
Jack Mallers 8 years ago
parent
commit
f03710daa4
  1. 4
      app/api/index.js
  2. 5
      app/lnd/methods/index.js
  3. 4
      app/reducers/ipc.js
  4. 11
      app/reducers/ticker.js
  5. 3
      app/routes/activity/components/Activity.js
  6. 3
      app/routes/activity/components/components/Invoices.js
  7. 3
      app/routes/activity/components/components/Payments.js
  8. 7
      app/routes/app/components/App.js
  9. 5
      app/routes/app/components/components/Form/Form.js
  10. 3
      app/routes/app/components/components/Nav.js
  11. 7
      app/routes/wallet/components/Wallet.js
  12. 3
      app/routes/wallet/components/components/Channels/Channels.js
  13. 5
      app/routes/wallet/components/components/Channels/components/Channel/Channel.js
  14. 3
      app/routes/wallet/components/components/Channels/components/ChannelForm/ChannelForm.js
  15. 3
      app/routes/wallet/components/components/Channels/components/ClosedPendingChannel/ClosedPendingChannel.js
  16. 3
      app/routes/wallet/components/components/Channels/components/OpenPendingChannel/OpenPendingChannel.js
  17. 3
      app/routes/wallet/containers/WalletContainer.js
  18. 30
      test/reducers/__snapshots__/ticker.spec.js.snap
  19. 21
      test/reducers/ticker.spec.js

4
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] }
}))
.then(axios.spread((btcTicker, ltcTicker) => ({ btcTicker: btcTicker[0], ltcTicker: ltcTicker[0] })))
}

5
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':

4
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

11
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
}

3
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

3
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

3
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

7
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 <div>Loading...</div> }
return (
<div>
<Form
@ -85,6 +88,8 @@ App.propTypes = {
createInvoice: PropTypes.func.isRequired,
payInvoice: PropTypes.func.isRequired,
fetchInvoice: PropTypes.func.isRequired,
fetchInfo: PropTypes.func.isRequired,
currentTicker: PropTypes.object,
children: PropTypes.object.isRequired
}

5
app/routes/app/components/components/Form/Form.js

@ -10,7 +10,7 @@ const Form = ({
setAmount,
setMessage,
setPaymentRequest,
ticker: { currency, btcTicker },
ticker: { currency },
isOpen,
close,
createInvoice,
@ -122,7 +122,8 @@ Form.propTypes = {
createInvoice: PropTypes.func.isRequired,
payInvoice: PropTypes.func.isRequired,
fetchInvoice: PropTypes.func.isRequired,
formInvoice: PropTypes.object.isRequired
formInvoice: PropTypes.object.isRequired,
currentTicker: PropTypes.object.isRequired
}
export default Form

3
app/routes/app/components/components/Nav.js

@ -92,7 +92,8 @@ Nav.propTypes = {
ticker: PropTypes.object.isRequired,
balance: PropTypes.object.isRequired,
setCurrency: PropTypes.func.isRequired,
formClicked: PropTypes.func.isRequired
formClicked: PropTypes.func.isRequired,
currentTicker: PropTypes.object.isRequired
}
export default Nav

7
app/routes/wallet/components/Wallet.js

@ -7,9 +7,8 @@ import styles from './Wallet.scss'
class Wallet extends Component {
componentWillMount() {
const { fetchInfo, fetchPeers, fetchChannels, newAddress } = this.props
const { fetchPeers, fetchChannels, newAddress } = this.props
fetchInfo()
fetchPeers()
fetchChannels()
newAddress('p2pkh')
@ -84,7 +83,6 @@ class Wallet extends Component {
}
Wallet.propTypes = {
fetchInfo: PropTypes.func.isRequired,
fetchPeers: PropTypes.func.isRequired,
fetchChannels: PropTypes.func.isRequired,
info: PropTypes.object.isRequired,
@ -102,7 +100,8 @@ Wallet.propTypes = {
allChannels: PropTypes.array.isRequired,
openChannel: PropTypes.func.isRequired,
newAddress: PropTypes.func.isRequired,
address: PropTypes.object.isRequired
address: PropTypes.object.isRequired,
currentTicker: PropTypes.object.isRequired
}

3
app/routes/wallet/components/components/Channels/Channels.js

@ -84,7 +84,8 @@ Channels.propTypes = {
channelForm: PropTypes.object.isRequired,
setChannelForm: PropTypes.func.isRequired,
allChannels: PropTypes.array.isRequired,
openChannel: PropTypes.func.isRequired
openChannel: PropTypes.func.isRequired,
currentTicker: PropTypes.object.isRequired
}
export default Channels

5
app/routes/wallet/components/components/Channels/components/Channel/Channel.js

@ -3,7 +3,7 @@ import PropTypes from 'prop-types'
import { btc } from '../../../../../../../utils'
import styles from './Channel.scss'
const Channel = ({ ticker, channel, setChannel }) => (
const Channel = ({ ticker, channel, setChannel, currentTicker }) => (
<li className={styles.channel} onClick={() => setChannel(channel)}>
<h1 className={styles.status}>Status: Open</h1>
<div className={styles.left}>
@ -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

3
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

3
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

3
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

3
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,

30
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,
}
`;

21
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()
})
})
})

Loading…
Cancel
Save