Browse Source

Merge pull request #427 from Empact/network

Prefix testnet units with 't'
renovate/lint-staged-8.x
Ben Woosley 7 years ago
committed by GitHub
parent
commit
742a3dd26b
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      app/components/Activity/ActivityModal.js
  2. 8
      app/components/Activity/TransactionModal.js
  3. 6
      app/components/Contacts/Network.js
  4. 8
      app/components/Wallet/ReceiveModal.js
  5. 6
      app/components/Wallet/Wallet.js
  6. 39
      app/reducers/info.js
  7. 6
      app/reducers/payform.js
  8. 12
      app/reducers/ticker.js
  9. 20
      app/routes/activity/containers/ActivityContainer.js
  10. 5
      app/routes/app/containers/AppContainer.js
  11. 13
      app/utils/blockExplorer.js
  12. 19
      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,

8
app/components/Wallet/ReceiveModal.js

@ -38,7 +38,8 @@ class ReceiveModal extends React.Component {
pubkey,
address,
alias,
closeReceiveModal
closeReceiveModal,
network
} = this.props
const { qrCodeType } = this.state
@ -87,7 +88,7 @@ class ReceiveModal extends React.Component {
</div>
<div className={styles.address}>
<h4>Bitcoin Address</h4>
<h4>Bitcoin {network.name} Address</h4>
<p>
<span className={styles.data}>{address}</span>
<span onClick={() => copyOnClick(address)} className={`${styles.copy} hint--left`} data-hint='Copy address'>
@ -103,6 +104,9 @@ class ReceiveModal extends React.Component {
}
ReceiveModal.propTypes = {
network: PropTypes.shape({
name: PropTypes.string
}).isRequired,
isOpen: PropTypes.bool.isRequired,
pubkey: PropTypes.string,
address: PropTypes.string.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,

39
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,20 @@ export const receiveInfo = (event, data) => (dispatch) => {
dispatch({ type: RECEIVE_INFO, data })
}
const networks = {
testnet: {
name: 'Testnet',
explorerUrl: 'https://testnet.smartbit.com.au',
bitcoinJsNetwork: bitcoin.networks.testnet,
unitPrefix: 't'
},
mainnet: {
name: null, // no name since it is the presumed default
explorerUrl: 'https://smartbit.com.au',
bitcoinJsNetwork: bitcoin.networks.bitcoin,
unitPrefix: ''
}
}
// IPC info fetch failed
// export const infoFailed = (event, data) => dispatch => {}
@ -44,7 +58,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 +72,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

12
app/reducers/ticker.js

@ -1,5 +1,7 @@
import { createSelector } from 'reselect'
import { requestTickers } from '../api'
import { infoSelectors } from './info'
// ------------------------------------
// Constants
// ------------------------------------
@ -97,11 +99,13 @@ tickerSelectors.currentCurrencyFilters = createSelector(
tickerSelectors.currencyName = createSelector(
currencySelector,
(currency) => {
if (currency === 'btc') { return 'BTC' }
if (currency === 'sats') { return 'satoshis' }
infoSelectors.networkSelector,
(currency, network) => {
let unit = currency
if (currency === 'btc') { unit = 'BTC' }
if (currency === 'sats') { unit = 'satoshis' }
return currency
return `${network.unitPrefix}${unit}`
}
)

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

@ -81,8 +81,12 @@ const mapStateToProps = state => ({
showPayLoadingScreen: payFormSelectors.showPayLoadingScreen(state)
})
const mergeProps = (stateProps, dispatchProps, ownProps) => {
const walletProps = {
const mergeProps = (stateProps, dispatchProps, ownProps) => ({
...stateProps,
...dispatchProps,
...ownProps,
walletProps: {
balance: stateProps.balance,
address: stateProps.address.address,
info: stateProps.info,
@ -93,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,
@ -102,14 +106,6 @@ const mergeProps = (stateProps, dispatchProps, ownProps) => {
openPayForm: () => dispatchProps.setFormType('PAY_FORM'),
openRequestForm: () => dispatchProps.setFormType('REQUEST_FORM')
}
return {
...stateProps,
...dispatchProps,
...ownProps,
walletProps
}
}
})
export default connect(mapStateToProps, mapDispatchToProps, mergeProps)(Activity)

5
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,
@ -376,6 +376,7 @@ const mergeProps = (stateProps, dispatchProps, ownProps) => {
const receiveModalProps = {
isOpen: stateProps.address.walletModal,
network: stateProps.info.network,
pubkey: stateProps.info.data.identity_pubkey,
address: stateProps.address.address,
alias: stateProps.info.data.alias,

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,

19
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,23 @@ 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",
"name": null,
"unitPrefix": "",
},
"showWalletCurrencyFilters": false,
}
`;
@ -20,6 +38,7 @@ exports[`reducers infoReducer should handle initial state 1`] = `
Object {
"data": Object {},
"infoLoading": false,
"network": Object {},
"showWalletCurrencyFilters": false,
}
`;

Loading…
Cancel
Save