Browse Source

Merge pull request #884 from mrfelton/fix/do-not-assume-chain-on-boot

fix: do not assume chain on boot
renovate/lint-staged-8.x
JimmyMow 6 years ago
committed by GitHub
parent
commit
36ccb62cfc
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  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}> <div className={styles.address}>
<h4> <h4>
<FormattedMessage {...messages.bitcoin_address} /> ({network.name}) <FormattedMessage {...messages.bitcoin_address} />{' '}
{network && network.name.toLowerCase() === 'testnet' && network.name}
</h4> </h4>
<p> <p>
<span className={styles.data}>{address}</span> <span className={styles.data}>{address}</span>

7
app/reducers/info.js

@ -1,5 +1,6 @@
import bitcoin from 'bitcoinjs-lib' import bitcoin from 'bitcoinjs-lib'
import { ipcRenderer } from 'electron' import { ipcRenderer } from 'electron'
import get from 'lodash.get'
import db from 'store/db' import db from 'store/db'
import { walletAddress } from './address' import { walletAddress } from './address'
@ -56,7 +57,7 @@ const networks = {
unitPrefix: 't' unitPrefix: 't'
}, },
mainnet: { mainnet: {
name: null, // no name since it is the presumed default name: 'Mainnet',
explorerUrl: 'https://smartbit.com.au', explorerUrl: 'https://smartbit.com.au',
bitcoinJsNetwork: bitcoin.networks.bitcoin, bitcoinJsNetwork: bitcoin.networks.bitcoin,
unitPrefix: '' unitPrefix: ''
@ -76,6 +77,7 @@ const ACTION_HANDLERS = {
...state, ...state,
infoLoading: false, infoLoading: false,
network: data.testnet ? networks.testnet : networks.mainnet, network: data.testnet ? networks.testnet : networks.mainnet,
chain: get(data, 'chains[0]'),
data data
}) })
} }
@ -87,7 +89,8 @@ const initialState = {
infoLoading: false, infoLoading: false,
hasSynced: undefined, hasSynced: undefined,
network: {}, network: {},
data: {} data: {},
chain: null
} }
// Selectors // 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 GET_TICKERS = 'GET_TICKERS'
export const RECIEVE_TICKERS = 'RECIEVE_TICKERS' export const RECIEVE_TICKERS = 'RECIEVE_TICKERS'
// Map for crypto names to crypto tickers // Map for crypto codes to crypto tickers
const cryptoTickers = { const cryptoTickers = {
bitcoin: 'btc', bitcoin: 'btc',
litecoin: 'ltc' litecoin: 'ltc'
} }
// Map for crypto names to crypto tickers
const cryptoNames = {
bitcoin: 'Bitcoin',
litecoin: 'Litecoin'
}
// ------------------------------------ // ------------------------------------
// Actions // Actions
// ------------------------------------ // ------------------------------------
@ -70,7 +76,7 @@ export const fetchTicker = () => async dispatch => {
// Receive IPC event for receiveCryptocurrency // Receive IPC event for receiveCryptocurrency
export const receiveCryptocurrency = (event, currency) => dispatch => { export const receiveCryptocurrency = (event, currency) => dispatch => {
dispatch({ type: SET_CURRENCY, currency: cryptoTickers[currency] }) 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, cryptoSelector,
bitcoinTickerSelector, bitcoinTickerSelector,
litecoinTickerSelector, 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( tickerSelectors.currencyFilters = createSelector(
infoSelectors.networkSelector, infoSelectors.networkSelector,
currencyFiltersSelector, currencyFiltersSelector,
@ -142,9 +150,9 @@ export { tickerSelectors }
// ------------------------------------ // ------------------------------------
const initialState = { const initialState = {
tickerLoading: false, tickerLoading: false,
currency: '', currency: null,
fromCurrency: 'sats', fromCurrency: null,
crypto: '', crypto: null,
btcTicker: null, btcTicker: null,
ltcTicker: null, ltcTicker: null,
fiatTicker: getDefaultCurrency(), fiatTicker: getDefaultCurrency(),

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

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

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

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

Loading…
Cancel
Save