Browse Source

Replace info.isTestnet with info.network

This holds network-specific information, initially the explorerUrl and the
bitcoinJsNetwork.
renovate/lint-staged-8.x
Ben Woosley 7 years ago
parent
commit
7d39aec678
No known key found for this signature in database GPG Key ID: 6EE5F3785F78B345
  1. 6
      app/components/Activity/ActivityModal.js
  2. 8
      app/components/Activity/TransactionModal.js
  3. 6
      app/components/Contacts/Network.js
  4. 6
      app/components/Wallet/Wallet.js
  5. 35
      app/reducers/info.js
  6. 6
      app/reducers/payform.js
  7. 2
      app/routes/activity/containers/ActivityContainer.js
  8. 4
      app/routes/app/containers/AppContainer.js
  9. 13
      app/utils/blockExplorer.js
  10. 17
      test/reducers/__snapshots__/info.spec.js.snap

6
app/components/Activity/ActivityModal.js

@ -14,7 +14,7 @@ const ActivityModal = ({
modalProps,
ticker,
currentTicker,
isTestnet,
network,
hideActivityModal,
toggleCurrencyProps
@ -37,7 +37,7 @@ const ActivityModal = ({
</div>
<SpecificModal
{...modalProps}
isTestnet={isTestnet}
network={network}
ticker={ticker}
currentTicker={currentTicker}
toggleCurrencyProps={toggleCurrencyProps}
@ -51,7 +51,7 @@ ActivityModal.propTypes = {
currentTicker: PropTypes.object.isRequired,
toggleCurrencyProps: PropTypes.object.isRequired,
isTestnet: PropTypes.bool.isRequired,
network: PropTypes.object.isRequired,
modalType: PropTypes.string,
modalProps: PropTypes.object.isRequired,

8
app/components/Activity/TransactionModal.js

@ -19,7 +19,7 @@ const TransactionModal = ({
transaction,
ticker,
currentTicker,
isTestnet,
network,
toggleCurrencyProps: {
setActivityModalCurrencyFilters,
@ -38,7 +38,7 @@ const TransactionModal = ({
<section className={styles.details}>
<div>
<Isvg src={link} />
<span className={styles.link} onClick={() => blockExplorer.showTransaction(isTestnet, transaction.tx_hash)}>On-Chain</span>
<span className={styles.link} onClick={() => blockExplorer.showTransaction(network, transaction.tx_hash)}>On-Chain</span>
</div>
<div>
<Value value={transaction.total_fees} currency={ticker.currency} currentTicker={currentTicker} />
@ -76,7 +76,7 @@ const TransactionModal = ({
</div>
<footer className={styles.footer}>
<p onClick={() => blockExplorer.showTransaction(isTestnet, transaction.tx_hash)}>{transaction.tx_hash}</p>
<p onClick={() => blockExplorer.showTransaction(network, transaction.tx_hash)}>{transaction.tx_hash}</p>
</footer>
</div>
)
@ -88,7 +88,7 @@ TransactionModal.propTypes = {
toggleCurrencyProps: PropTypes.object.isRequired,
isTestnet: PropTypes.bool.isRequired
network: PropTypes.object.isRequired
}
export default TransactionModal

6
app/components/Contacts/Network.js

@ -53,7 +53,7 @@ class Network extends Component {
suggestedNodesProps,
isTestnet
network
} = this.props
const refreshClicked = () => {
@ -226,7 +226,7 @@ class Network extends Component {
<span>{displayNodeName(channel)}</span>
{
selectedChannel === channel &&
<span onClick={() => blockExplorer.showTransaction(isTestnet, channel.channel_point.split(':')[0])}>
<span onClick={() => blockExplorer.showTransaction(network, channel.channel_point.split(':')[0])}>
<FaExternalLink />
</span>
}
@ -316,7 +316,7 @@ Network.propTypes = {
ticker: PropTypes.object.isRequired,
suggestedNodesProps: PropTypes.object.isRequired,
isTestnet: PropTypes.bool.isRequired,
network: PropTypes.object.isRequired,
fetchChannels: PropTypes.func.isRequired,
openContactsForm: PropTypes.func.isRequired,

6
app/components/Wallet/Wallet.js

@ -27,7 +27,7 @@ const Wallet = ({
currencyName,
setCurrency,
setWalletCurrencyFilters,
isTestnet
network
}) => {
const usdAmount = btc.satoshisToUsd((parseInt(balance.walletBalance, 10) + parseInt(balance.channelBalance, 10)), currentTicker.price_usd)
@ -113,7 +113,7 @@ const Wallet = ({
{
// TODO(jimmymow): remove this
// eslint-disable-next-line
}Successfully <span className={styles.txLink} onClick={() => blockExplorer.showTransaction(isTestnet, successTransactionScreen.txid)}>sent</span> transaction
}Successfully <span className={styles.txLink} onClick={() => blockExplorer.showTransaction(network, successTransactionScreen.txid)}>sent</span> transaction
</section>
</span>
}
@ -134,7 +134,7 @@ Wallet.propTypes = {
openReceiveModal: PropTypes.func.isRequired,
showPayLoadingScreen: PropTypes.bool.isRequired,
showSuccessPayScreen: PropTypes.bool.isRequired,
isTestnet: PropTypes.bool.isRequired,
network: PropTypes.object.isRequired,
successTransactionScreen: PropTypes.object.isRequired,
currentCurrencyFilters: PropTypes.array.isRequired,
currencyName: PropTypes.string.isRequired,

35
app/reducers/info.js

@ -1,6 +1,6 @@
import { createSelector } from 'reselect'
import bitcoin from 'bitcoinjs-lib'
import { ipcRenderer } from 'electron'
import { blockExplorer } from 'utils'
// ------------------------------------
// Constants
@ -36,6 +36,16 @@ export const receiveInfo = (event, data) => (dispatch) => {
dispatch({ type: RECEIVE_INFO, data })
}
const networks = {
testnet: {
explorerUrl: 'https://testnet.smartbit.com.au',
bitcoinJsNetwork: bitcoin.networks.testnet
},
mainnet: {
explorerUrl: 'https://smartbit.com.au',
bitcoinJsNetwork: bitcoin.networks.bitcoin
}
}
// IPC info fetch failed
// export const infoFailed = (event, data) => dispatch => {}
@ -44,7 +54,12 @@ export const receiveInfo = (event, data) => (dispatch) => {
// ------------------------------------
const ACTION_HANDLERS = {
[GET_INFO]: state => ({ ...state, infoLoading: true }),
[RECEIVE_INFO]: (state, { data }) => ({ ...state, infoLoading: false, data }),
[RECEIVE_INFO]: (state, { data }) => ({
...state,
infoLoading: false,
network: (data.testnet ? networks.testnet : networks.mainnet),
data
}),
[SET_WALLET_CURRENCY_FILTERS]: (state, { showWalletCurrencyFilters }) => ({ ...state, showWalletCurrencyFilters })
}
@ -53,23 +68,15 @@ const ACTION_HANDLERS = {
// ------------------------------------
const initialState = {
infoLoading: false,
network: {},
data: {},
showWalletCurrencyFilters: false
}
// Selectors
const infoSelectors = {}
const testnetSelector = state => state.info.data.testnet
infoSelectors.isTestnet = createSelector(
testnetSelector,
isTestnet => (!!isTestnet)
)
infoSelectors.explorerLinkBase = createSelector(
infoSelectors.isTestnet,
isTestnet => (isTestnet ? blockExplorer.testnetUrl : blockExplorer.mainnetUrl)
)
infoSelectors.testnetSelector = state => state.info.data.testnet
infoSelectors.networkSelector = state => state.info.network
export { infoSelectors }

6
app/reducers/payform.js

@ -5,6 +5,7 @@ import isEmpty from 'lodash/isEmpty'
import { setFormType } from './form'
import { tickerSelectors } from './ticker'
import { infoSelectors } from './info'
import { btc, bech32 } from '../utils'
// Initial State
@ -124,9 +125,10 @@ const currencySelector = state => state.ticker.currency
payFormSelectors.isOnchain = createSelector(
payInputSelector,
(input) => {
infoSelectors.networkSelector,
(input, network) => {
try {
bitcoin.address.toOutputScript(input, bitcoin.networks.testnet)
bitcoin.address.toOutputScript(input, network.bitcoinJsNetwork)
return true
} catch (e) {
return false

2
app/routes/activity/containers/ActivityContainer.js

@ -97,7 +97,7 @@ const mergeProps = (stateProps, dispatchProps, ownProps) => ({
successTransactionScreen: stateProps.transaction.successTransactionScreen,
currentCurrencyFilters: stateProps.currentCurrencyFilters,
currencyName: stateProps.currencyName,
isTestnet: stateProps.info.data.testnet,
network: stateProps.info.network,
setCurrency: dispatchProps.setCurrency,
setWalletCurrencyFilters: dispatchProps.setWalletCurrencyFilters,

4
app/routes/app/containers/AppContainer.js

@ -299,7 +299,7 @@ const mergeProps = (stateProps, dispatchProps, ownProps) => {
nodes: stateProps.network.nodes,
nonActiveFilters: stateProps.nonActiveFilters,
ticker: stateProps.ticker,
isTestnet: stateProps.info.data.testnet,
network: stateProps.info.network,
fetchChannels: dispatchProps.fetchChannels,
openContactsForm: dispatchProps.openContactsForm,
@ -356,7 +356,7 @@ const mergeProps = (stateProps, dispatchProps, ownProps) => {
modalProps: stateProps.activity.modal.modalProps,
ticker: stateProps.ticker,
currentTicker: stateProps.currentTicker,
isTestnet: stateProps.info.data.testnet,
network: stateProps.info.network,
hideActivityModal: dispatchProps.hideActivityModal,

13
app/utils/blockExplorer.js

@ -1,13 +1,10 @@
import { shell } from 'electron'
const testnetUrl = 'https://testnet.smartbit.com.au'
const mainnetUrl = 'https://smartbit.com.au'
const showTransaction = (network, txid) =>
shell.openExternal(`${network.explorerUrl}/tx/${txid}`)
const showTransaction = (isTestnet, txid) =>
(isTestnet ? shell.openExternal(`${testnetUrl}/tx/${txid}`) : shell.openExternal(`${mainnetUrl}/tx/${txid}`))
const showBlock = (isTestnet, blockHash) =>
(isTestnet ? shell.openExternal(`${testnetUrl}/block/${blockHash}`) : shell.openExternal(`${mainnetUrl}/block/${blockHash}`))
const showBlock = (network, blockHash) =>
shell.openExternal(`${network.explorerUrl}/block/${blockHash}`)
const showChannelClosing = channel =>
showTransaction(channel.closing_txid)
@ -16,8 +13,6 @@ const showChannelPoint = channel =>
showTransaction(channel.channel.channel_point.split(':')[0])
export default {
testnetUrl,
mainnetUrl,
showTransaction,
showBlock,
showChannelClosing,

17
test/reducers/__snapshots__/info.spec.js.snap

@ -4,6 +4,7 @@ exports[`reducers infoReducer should correctly getInfo 1`] = `
Object {
"data": Object {},
"infoLoading": true,
"network": Object {},
"showWalletCurrencyFilters": false,
}
`;
@ -12,6 +13,21 @@ exports[`reducers infoReducer should correctly receiveInfo 1`] = `
Object {
"data": "foo",
"infoLoading": false,
"network": Object {
"bitcoinJsNetwork": Object {
"bech32": "bc",
"bip32": Object {
"private": 76066276,
"public": 76067358,
},
"messagePrefix": "Bitcoin Signed Message:
",
"pubKeyHash": 0,
"scriptHash": 5,
"wif": 128,
},
"explorerUrl": "https://smartbit.com.au",
},
"showWalletCurrencyFilters": false,
}
`;
@ -20,6 +36,7 @@ exports[`reducers infoReducer should handle initial state 1`] = `
Object {
"data": Object {},
"infoLoading": false,
"network": Object {},
"showWalletCurrencyFilters": false,
}
`;

Loading…
Cancel
Save