From 94a4cca456ff439943141505fce3aa481074378f Mon Sep 17 00:00:00 2001 From: Jack Mallers Date: Thu, 31 Aug 2017 22:47:53 -0500 Subject: [PATCH] fix(explorer link): dynamically set explorer link --- app/reducers/info.js | 17 +++++++++++++++++ app/routes/wallet/components/Wallet.js | 7 +++++-- .../components/components/Channels/Channels.js | 10 +++++++--- .../components/ChannelModal/ChannelModal.js | 7 ++++--- .../ClosedPendingChannel.js | 7 ++++--- .../OpenPendingChannel/OpenPendingChannel.js | 7 ++++--- app/routes/wallet/containers/WalletContainer.js | 5 ++++- 7 files changed, 45 insertions(+), 15 deletions(-) diff --git a/app/reducers/info.js b/app/reducers/info.js index 9be0c5a2..885c7ce3 100644 --- a/app/reducers/info.js +++ b/app/reducers/info.js @@ -1,3 +1,4 @@ +import { createSelector } from 'reselect' import { ipcRenderer } from 'electron' // ------------------------------------ // Constants @@ -39,6 +40,22 @@ const initialState = { data: {} } +// Selectors +const infoSelectors = {} +const testnetSelector = state => state.info.data.testnet + +infoSelectors.isTestnet = createSelector( + testnetSelector, + isTestnet => (!!isTestnet) +) + +infoSelectors.explorerLinkBase = createSelector( + infoSelectors.isTestnet, + isTestnet => isTestnet ? 'https://testnet.smartbit.com.au' : 'https://smartbit.com.au' +) + +export { infoSelectors } + export default function infoReducer(state = initialState, action) { const handler = ACTION_HANDLERS[action.type] diff --git a/app/routes/wallet/components/Wallet.js b/app/routes/wallet/components/Wallet.js index 54a774b0..a831cc05 100644 --- a/app/routes/wallet/components/Wallet.js +++ b/app/routes/wallet/components/Wallet.js @@ -31,7 +31,8 @@ class Wallet extends Component { disconnectRequest, allChannels, openChannel, - currentTicker + currentTicker, + explorerLinkBase } = this.props return ( @@ -75,6 +76,7 @@ class Wallet extends Component { setChannelForm={setChannelForm} openChannel={openChannel} currentTicker={currentTicker} + explorerLinkBase={explorerLinkBase} /> @@ -101,7 +103,8 @@ Wallet.propTypes = { openChannel: PropTypes.func.isRequired, newAddress: PropTypes.func.isRequired, address: PropTypes.object.isRequired, - currentTicker: PropTypes.object.isRequired + currentTicker: PropTypes.object.isRequired, + explorerLinkBase: PropTypes.string.isRequired } diff --git a/app/routes/wallet/components/components/Channels/Channels.js b/app/routes/wallet/components/components/Channels/Channels.js index 9c3eb2c8..6f49d872 100644 --- a/app/routes/wallet/components/components/Channels/Channels.js +++ b/app/routes/wallet/components/components/Channels/Channels.js @@ -19,10 +19,11 @@ const Channels = ({ setChannelForm, allChannels, openChannel, - currentTicker + currentTicker, + explorerLinkBase }) => (
- +

Channels

@@ -45,6 +46,7 @@ const Channels = ({ channel={channel} ticker={ticker} currentTicker={currentTicker} + explorerLinkBase={explorerLinkBase} /> ) } else if (Object.prototype.hasOwnProperty.call(channel, 'closing_txid')) { @@ -54,6 +56,7 @@ const Channels = ({ channel={channel} ticker={ticker} currentTicker={currentTicker} + explorerLinkBase={explorerLinkBase} /> ) } @@ -85,7 +88,8 @@ Channels.propTypes = { setChannelForm: PropTypes.func.isRequired, allChannels: PropTypes.array.isRequired, openChannel: PropTypes.func.isRequired, - currentTicker: PropTypes.object.isRequired + currentTicker: PropTypes.object.isRequired, + explorerLinkBase: PropTypes.string.isRequired } export default Channels diff --git a/app/routes/wallet/components/components/Channels/components/ChannelModal/ChannelModal.js b/app/routes/wallet/components/components/Channels/components/ChannelModal/ChannelModal.js index db603583..1839ad4a 100644 --- a/app/routes/wallet/components/components/Channels/components/ChannelModal/ChannelModal.js +++ b/app/routes/wallet/components/components/Channels/components/ChannelModal/ChannelModal.js @@ -4,7 +4,7 @@ import PropTypes from 'prop-types' import ReactModal from 'react-modal' import styles from './ChannelModal.scss' -const ChannelModal = ({ isOpen, resetChannel, channel }) => { +const ChannelModal = ({ isOpen, resetChannel, channel, explorerLinkBase }) => { const customStyles = { overlay: { cursor: 'pointer', @@ -39,7 +39,7 @@ const ChannelModal = ({ isOpen, resetChannel, channel }) => {

shell.openExternal(`https://testnet.smartbit.com.au/tx/${channel.channel_point.split(':')[0]}`)} + onClick={() => shell.openExternal(`${explorerLinkBase}/tx/${channel.channel_point.split(':')[0]}`)} > {channel.channel_point}

@@ -88,7 +88,8 @@ const ChannelModal = ({ isOpen, resetChannel, channel }) => { ChannelModal.propTypes = { isOpen: PropTypes.bool.isRequired, resetChannel: PropTypes.func.isRequired, - channel: PropTypes.object + channel: PropTypes.object, + explorerLinkBase: PropTypes.string.isRequired } export default ChannelModal 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 2bd3a307..db76117a 100644 --- a/app/routes/wallet/components/components/Channels/components/ClosedPendingChannel/ClosedPendingChannel.js +++ b/app/routes/wallet/components/components/Channels/components/ClosedPendingChannel/ClosedPendingChannel.js @@ -4,8 +4,8 @@ import PropTypes from 'prop-types' import { btc } from '../../../../../../../utils' import styles from './ClosedPendingChannel.scss' -const ClosedPendingChannel = ({ ticker, channel: { channel, closing_txid }, currentTicker }) => ( -
  • shell.openExternal(`https://testnet.smartbit.com.au/tx/${closing_txid}`)}> +const ClosedPendingChannel = ({ ticker, channel: { channel, closing_txid }, currentTicker, explorerLinkBase }) => ( +
  • shell.openExternal(`${explorerLinkBase}/tx/${closing_txid}`)}>

    Status: Closing

    @@ -60,7 +60,8 @@ const ClosedPendingChannel = ({ ticker, channel: { channel, closing_txid }, curr ClosedPendingChannel.propTypes = { ticker: PropTypes.object.isRequired, channel: PropTypes.object.isRequired, - currentTicker: PropTypes.object.isRequired + currentTicker: PropTypes.object.isRequired, + explorerLinkBase: PropTypes.string.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 5e2eeb28..5f24d26d 100644 --- a/app/routes/wallet/components/components/Channels/components/OpenPendingChannel/OpenPendingChannel.js +++ b/app/routes/wallet/components/components/Channels/components/OpenPendingChannel/OpenPendingChannel.js @@ -4,8 +4,8 @@ import PropTypes from 'prop-types' import { btc } from '../../../../../../../utils' import styles from './OpenPendingChannel.scss' -const OpenPendingChannel = ({ ticker, channel: { channel }, currentTicker }) => ( -
  • shell.openExternal(`https://testnet.smartbit.com.au/tx/${channel.channel_point.split(':')[0]}`)}> +const OpenPendingChannel = ({ ticker, channel: { channel }, currentTicker, explorerLinkBase }) => ( +
  • shell.openExternal(`${explorerLinkBase}/tx/${channel.channel_point.split(':')[0]}`)}>

    Status: Pending

    @@ -60,7 +60,8 @@ const OpenPendingChannel = ({ ticker, channel: { channel }, currentTicker }) => OpenPendingChannel.propTypes = { ticker: PropTypes.object.isRequired, channel: PropTypes.object.isRequired, - currentTicker: PropTypes.object.isRequired + currentTicker: PropTypes.object.isRequired, + explorerLinkBase: PropTypes.string.isRequired } export default OpenPendingChannel diff --git a/app/routes/wallet/containers/WalletContainer.js b/app/routes/wallet/containers/WalletContainer.js index e9bc00b2..529f44dd 100644 --- a/app/routes/wallet/containers/WalletContainer.js +++ b/app/routes/wallet/containers/WalletContainer.js @@ -1,4 +1,5 @@ import { connect } from 'react-redux' +import { infoSelectors } from '../../../reducers/info' import { newAddress } from '../../../reducers/address' import { tickerSelectors } from '../../../reducers/ticker' import { @@ -49,7 +50,9 @@ const mapStateToProps = state => ({ peerModalOpen: peersSelectors.peerModalOpen(state), channelModalOpen: channelsSelectors.channelModalOpen(state), - currentTicker: tickerSelectors.currentTicker(state) + currentTicker: tickerSelectors.currentTicker(state), + + explorerLinkBase: infoSelectors.explorerLinkBase(state) }) export default connect(mapStateToProps, mapDispatchToProps)(Wallet)