Browse Source

fix: do not assume chain on boot

Ensure that the state of the app is clean when it starts. Do not assume
that we are connecting to the bitcoin chain.
renovate/lint-staged-8.x
Tom Kirkpatrick 6 years ago
parent
commit
e282bda188
No known key found for this signature in database GPG Key ID: 72203A8EC5967EA8
  1. 3
      app/components/Wallet/ReceiveModal/ReceiveModal.js
  2. 7
      app/reducers/info.js
  3. 20
      app/reducers/ticker.js
  4. 5
      test/unit/reducers/__snapshots__/info.spec.js.snap
  5. 26
      test/unit/reducers/__snapshots__/ticker.spec.js.snap

3
app/components/Wallet/ReceiveModal/ReceiveModal.js

@ -102,7 +102,8 @@ class ReceiveModal extends React.Component {
<div className={styles.address}>
<h4>
<FormattedMessage {...messages.bitcoin_address} /> ({network.name})
<FormattedMessage {...messages.bitcoin_address} />{' '}
{network && network.name.toLowerCase() === 'testnet' && network.name}
</h4>
<p>
<span className={styles.data}>{address}</span>

7
app/reducers/info.js

@ -1,5 +1,6 @@
import bitcoin from 'bitcoinjs-lib'
import { ipcRenderer } from 'electron'
import get from 'lodash.get'
import db from 'store/db'
import { walletAddress } from './address'
@ -56,7 +57,7 @@ const networks = {
unitPrefix: 't'
},
mainnet: {
name: null, // no name since it is the presumed default
name: 'Mainnet',
explorerUrl: 'https://smartbit.com.au',
bitcoinJsNetwork: bitcoin.networks.bitcoin,
unitPrefix: ''
@ -76,6 +77,7 @@ const ACTION_HANDLERS = {
...state,
infoLoading: false,
network: data.testnet ? networks.testnet : networks.mainnet,
chain: get(data, 'chains[0]'),
data
})
}
@ -87,7 +89,8 @@ const initialState = {
infoLoading: false,
hasSynced: undefined,
network: {},
data: {}
data: {},
chain: null
}
// Selectors

20
app/reducers/ticker.js

@ -13,12 +13,18 @@ export const SET_FIAT_TICKER = 'SET_FIAT_TICKER'
export const GET_TICKERS = 'GET_TICKERS'
export const RECIEVE_TICKERS = 'RECIEVE_TICKERS'
// Map for crypto names to crypto tickers
// Map for crypto codes to crypto tickers
const cryptoTickers = {
bitcoin: 'btc',
litecoin: 'ltc'
}
// Map for crypto names to crypto tickers
const cryptoNames = {
bitcoin: 'Bitcoin',
litecoin: 'Litecoin'
}
// ------------------------------------
// Actions
// ------------------------------------
@ -70,7 +76,7 @@ export const fetchTicker = () => async dispatch => {
// Receive IPC event for receiveCryptocurrency
export const receiveCryptocurrency = (event, currency) => dispatch => {
dispatch({ type: SET_CURRENCY, currency: cryptoTickers[currency] })
dispatch({ type: SET_CRYPTO, crypto: cryptoTickers[currency] })
dispatch({ type: SET_CRYPTO, crypto: currency })
}
// ------------------------------------
@ -105,9 +111,11 @@ tickerSelectors.currentTicker = createSelector(
cryptoSelector,
bitcoinTickerSelector,
litecoinTickerSelector,
(crypto, btcTicker, ltcTicker) => (crypto === 'btc' ? btcTicker : ltcTicker)
(crypto, btcTicker, ltcTicker) => (crypto === 'bitcoin' ? btcTicker : ltcTicker)
)
tickerSelectors.cryptoName = createSelector(cryptoSelector, crypto => cryptoNames[crypto])
tickerSelectors.currencyFilters = createSelector(
infoSelectors.networkSelector,
currencyFiltersSelector,
@ -142,9 +150,9 @@ export { tickerSelectors }
// ------------------------------------
const initialState = {
tickerLoading: false,
currency: '',
fromCurrency: 'sats',
crypto: '',
currency: null,
fromCurrency: null,
crypto: null,
btcTicker: null,
ltcTicker: null,
fiatTicker: getDefaultCurrency(),

5
test/unit/reducers/__snapshots__/info.spec.js.snap

@ -2,6 +2,7 @@
exports[`reducers infoReducer should correctly getInfo 1`] = `
Object {
"chain": null,
"data": Object {},
"hasSynced": undefined,
"infoLoading": true,
@ -11,6 +12,7 @@ Object {
exports[`reducers infoReducer should correctly receiveInfo 1`] = `
Object {
"chain": undefined,
"data": "foo",
"hasSynced": undefined,
"infoLoading": false,
@ -28,7 +30,7 @@ Object {
"wif": 128,
},
"explorerUrl": "https://smartbit.com.au",
"name": null,
"name": "Mainnet",
"unitPrefix": "",
},
}
@ -36,6 +38,7 @@ Object {
exports[`reducers infoReducer should handle initial state 1`] = `
Object {
"chain": null,
"data": Object {},
"hasSynced": undefined,
"infoLoading": false,

26
test/unit/reducers/__snapshots__/ticker.spec.js.snap

@ -3,8 +3,8 @@
exports[`reducers tickerReducer should correctly getTicker 1`] = `
Object {
"btcTicker": null,
"crypto": "",
"currency": "",
"crypto": null,
"currency": null,
"currencyFilters": Array [
Object {
"key": "btc",
@ -44,7 +44,7 @@ Object {
"THB",
"TWB",
],
"fromCurrency": "sats",
"fromCurrency": null,
"ltcTicker": null,
"tickerLoading": true,
}
@ -53,8 +53,8 @@ Object {
exports[`reducers tickerReducer should correctly receiveTicker 1`] = `
Object {
"btcTicker": undefined,
"crypto": "",
"currency": "",
"crypto": null,
"currency": null,
"currencyFilters": Array [
Object {
"key": "btc",
@ -94,7 +94,7 @@ Object {
"THB",
"TWB",
],
"fromCurrency": "sats",
"fromCurrency": null,
"ltcTicker": undefined,
"tickerLoading": false,
}
@ -104,7 +104,7 @@ exports[`reducers tickerReducer should correctly setCrypto 1`] = `
Object {
"btcTicker": null,
"crypto": "foo",
"currency": "",
"currency": null,
"currencyFilters": Array [
Object {
"key": "btc",
@ -144,7 +144,7 @@ Object {
"THB",
"TWB",
],
"fromCurrency": "sats",
"fromCurrency": null,
"ltcTicker": null,
"tickerLoading": false,
}
@ -153,7 +153,7 @@ Object {
exports[`reducers tickerReducer should correctly setCurrency 1`] = `
Object {
"btcTicker": null,
"crypto": "",
"crypto": null,
"currency": "foo",
"currencyFilters": Array [
Object {
@ -194,7 +194,7 @@ Object {
"THB",
"TWB",
],
"fromCurrency": "",
"fromCurrency": null,
"ltcTicker": null,
"tickerLoading": false,
}
@ -203,8 +203,8 @@ Object {
exports[`reducers tickerReducer should handle initial state 1`] = `
Object {
"btcTicker": null,
"crypto": "",
"currency": "",
"crypto": null,
"currency": null,
"currencyFilters": Array [
Object {
"key": "btc",
@ -244,7 +244,7 @@ Object {
"THB",
"TWB",
],
"fromCurrency": "sats",
"fromCurrency": null,
"ltcTicker": null,
"tickerLoading": false,
}

Loading…
Cancel
Save