From 365f4cdfb0d267419f94c4b7abfce1b919cc5d31 Mon Sep 17 00:00:00 2001 From: mmv Date: Tue, 24 Sep 2019 17:20:48 +0400 Subject: [PATCH] Refactor getEtherscanLink --- config/env.js | 43 ++++++++++--------- scripts/start.js | 1 - src/components/EtherscanBtn/index.jsx | 12 ++---- src/components/EtherscanLink/index.jsx | 12 ++---- .../component/ProviderDetails/UserDetails.jsx | 2 +- src/config/index.js | 5 +-- src/logic/wallets/getWeb3.js | 8 +++- src/routes/opening/component/index.jsx | 4 +- src/routes/safe/components/Layout.jsx | 2 +- .../ManageOwners/AddOwnerModal/index.jsx | 3 -- .../AddOwnerModal/screens/Review/index.jsx | 12 +++--- .../ManageOwners/EditOwnerModal/index.jsx | 4 +- .../ManageOwners/RemoveOwnerModal/index.jsx | 4 -- .../screens/CheckOwner/index.jsx | 5 +-- .../RemoveOwnerModal/screens/Review/index.jsx | 12 +++--- .../ManageOwners/ReplaceOwnerModal/index.jsx | 5 +-- .../screens/OwnerForm/index.jsx | 5 +-- .../screens/Review/index.jsx | 8 ++-- .../Settings/ManageOwners/index.jsx | 3 -- .../TxsTable/ExpandedTx/OwnersColumn/List.jsx | 2 +- .../TxsTable/ExpandedTx/index.jsx | 2 +- .../Transactions/TxsTable/index.jsx | 10 ++--- 22 files changed, 67 insertions(+), 97 deletions(-) diff --git a/config/env.js b/config/env.js index 5d0ab7b7..7ed7d2c1 100644 --- a/config/env.js +++ b/config/env.js @@ -1,28 +1,29 @@ +// @flow // Grab NODE_ENV and REACT_APP_* environment variables and prepare them to be // injected into the application via DefinePlugin in Webpack configuration. -var REACT_APP = /^REACT_APP_/i; +const REACT_APP = /^REACT_APP_/i function getClientEnvironment(publicUrl) { - var processEnv = Object - .keys(process.env) - .filter(key => REACT_APP.test(key)) - .reduce((env, key) => { - env[key] = JSON.stringify(process.env[key]); - return env; - }, { - // Useful for determining whether we’re running in production mode. - // Most importantly, it switches React into the correct mode. - 'NODE_ENV': JSON.stringify( - process.env.NODE_ENV || 'development' - ), - // Useful for resolving the correct path to static assets in `public`. - // For example, . - // This should only be used as an escape hatch. Normally you would put - // images into the `src` and `import` them in code to get their paths. - 'PUBLIC_URL': JSON.stringify(publicUrl) - }); - return {'process.env': processEnv}; + const processEnv = Object.keys(process.env) + .filter((key) => REACT_APP.test(key)) + .reduce( + (env, key) => { + env[key] = JSON.stringify(process.env[key]) + return env + }, + { + // Useful for determining whether we’re running in production mode. + // Most importantly, it switches React into the correct mode. + NODE_ENV: JSON.stringify(process.env.NODE_ENV || 'development'), + // Useful for resolving the correct path to static assets in `public`. + // For example, . + // This should only be used as an escape hatch. Normally you would put + // images into the `src` and `import` them in code to get their paths. + PUBLIC_URL: JSON.stringify(publicUrl), + }, + ) + return { 'process.env': processEnv } } -module.exports = getClientEnvironment; +module.exports = getClientEnvironment diff --git a/scripts/start.js b/scripts/start.js index cc80e9bb..d57ef6f1 100644 --- a/scripts/start.js +++ b/scripts/start.js @@ -1,6 +1,5 @@ /*eslint-disable*/ process.env.NODE_ENV = 'development' -process.env.NETWORK = 'mainnet' // Load environment variables from .env file. Suppress warnings using silent // if this file is missing. dotenv will never modify any environment variables diff --git a/src/components/EtherscanBtn/index.jsx b/src/components/EtherscanBtn/index.jsx index 7c8548b8..be02c48a 100644 --- a/src/components/EtherscanBtn/index.jsx +++ b/src/components/EtherscanBtn/index.jsx @@ -2,11 +2,9 @@ import React from 'react' import Tooltip from '@material-ui/core/Tooltip' import { withStyles } from '@material-ui/core/styles' -import { connect } from 'react-redux' import Img from '~/components/layout/Img' import { getEtherScanLink } from '~/logic/wallets/getWeb3' import { xs } from '~/theme/variables' -import { networkSelector } from '~/logic/wallets/store/selectors' import SearchIcon from './search.svg' const styles = () => ({ @@ -26,17 +24,16 @@ const styles = () => ({ type EtherscanBtnProps = { type: 'tx' | 'address', value: string, - currentNetwork: string, classes: Object, } const EtherscanBtn = ({ - type, value, currentNetwork, classes, + type, value, classes, }: EtherscanBtnProps) => ( ( - (state) => ({ currentNetwork: networkSelector(state) }), - null, -)(EtherscanBtnWithStyles) +export default EtherscanBtnWithStyles diff --git a/src/components/EtherscanLink/index.jsx b/src/components/EtherscanLink/index.jsx index f824f6e9..1e47de16 100644 --- a/src/components/EtherscanLink/index.jsx +++ b/src/components/EtherscanLink/index.jsx @@ -1,11 +1,9 @@ // @flow import React from 'react' -import { connect } from 'react-redux' import OpenInNew from '@material-ui/icons/OpenInNew' import { getEtherScanLink } from '~/logic/wallets/getWeb3' import { shortVersionOf } from '~/logic/wallets/ethAddresses' import { secondary } from '~/theme/variables' -import { networkSelector } from '~/logic/wallets/store/selectors' const openIconStyle = { height: '13px', @@ -15,17 +13,13 @@ const openIconStyle = { type EtherscanLinkProps = { type: 'tx' | 'address', value: string, - currentNetwork: string, } -const EtherscanLink = ({ type, value, currentNetwork }: EtherscanLinkProps) => ( - +const EtherscanLink = ({ type, value }: EtherscanLinkProps) => ( + {shortVersionOf(value, 4)} ) -export default connect( - (state) => ({ currentNetwork: networkSelector(state) }), - null, -)(EtherscanLink) +export default EtherscanLink diff --git a/src/components/Header/component/ProviderDetails/UserDetails.jsx b/src/components/Header/component/ProviderDetails/UserDetails.jsx index 1bdd6027..f6d70e06 100644 --- a/src/components/Header/component/ProviderDetails/UserDetails.jsx +++ b/src/components/Header/component/ProviderDetails/UserDetails.jsx @@ -123,7 +123,7 @@ const UserDetails = ({ {address} {userAddress && ( - + )} diff --git a/src/config/index.js b/src/config/index.js index 335608c9..fa1189d2 100644 --- a/src/config/index.js +++ b/src/config/index.js @@ -13,18 +13,17 @@ const configuration = () => { } if (process.env.NODE_ENV === 'production') { - if (process.env.NETWORK === 'mainnet') { + if (process.env.REACT_APP_NETWORK === 'mainnet') { return mainnetProdConfig } return prodConfig } - console.log(process.env) return devConfig } -export const getNetwork = () => (process.env.NETWORK === 'mainnet' ? ETHEREUM_NETWORK.MAIN : ETHEREUM_NETWORK.RINKEBY) +export const getNetwork = () => (process.env.REACT_APP_NETWORK === 'mainnet' ? ETHEREUM_NETWORK.MAIN : ETHEREUM_NETWORK.RINKEBY) const getConfig = ensureOnce(configuration) diff --git a/src/logic/wallets/getWeb3.js b/src/logic/wallets/getWeb3.js index 17445eb2..1532cd0e 100644 --- a/src/logic/wallets/getWeb3.js +++ b/src/logic/wallets/getWeb3.js @@ -2,6 +2,7 @@ import Web3 from 'web3' import ENS from 'ethereum-ens' import type { ProviderProps } from '~/logic/wallets/store/model/provider' +import { getNetwork } from '~/config/index' export const ETHEREUM_NETWORK = { MAIN: 'MAIN', @@ -33,7 +34,12 @@ export const ETHEREUM_NETWORK_IDS = { 42: ETHEREUM_NETWORK.KOVAN, } -export const getEtherScanLink = (type: 'address' | 'tx', value: string, network: string) => `https://${network.toLowerCase() === 'mainnet' ? '' : `${network.toLowerCase()}.`}etherscan.io/${type}/${value}` +export const getEtherScanLink = (type: 'address' | 'tx', value: string) => { + const network = getNetwork() + return `https://${ + network.toLowerCase() === 'mainnet' ? '' : `${network.toLowerCase()}.` + }etherscan.io/${type}/${value}` +} let web3 export const getWeb3 = () => web3 || (window.web3 && new Web3(window.web3.currentProvider)) || (window.ethereum && new Web3(window.ethereum)) diff --git a/src/routes/opening/component/index.jsx b/src/routes/opening/component/index.jsx index d200d02e..b55fa3ff 100644 --- a/src/routes/opening/component/index.jsx +++ b/src/routes/opening/component/index.jsx @@ -39,7 +39,7 @@ const styles = { } const Opening = ({ - classes, name = 'Safe creation process', tx, network, + classes, name = 'Safe creation process', tx, }: Props) => ( @@ -70,7 +70,7 @@ const Opening = ({ Follow progress on {' '} { } const { address, ethBalance, name } = safe - const etherScanLink = getEtherScanLink('address', address, network) + const etherScanLink = getEtherScanLink('address', address) return ( <> diff --git a/src/routes/safe/components/Settings/ManageOwners/AddOwnerModal/index.jsx b/src/routes/safe/components/Settings/ManageOwners/AddOwnerModal/index.jsx index 1ace6021..a5fb4549 100644 --- a/src/routes/safe/components/Settings/ManageOwners/AddOwnerModal/index.jsx +++ b/src/routes/safe/components/Settings/ManageOwners/AddOwnerModal/index.jsx @@ -26,7 +26,6 @@ type Props = { safeName: string, owners: List, threshold: number, - network: string, addSafeOwner: Function, createTransaction: Function, } @@ -58,7 +57,6 @@ const AddOwner = ({ safeName, owners, threshold, - network, createTransaction, addSafeOwner, }: Props) => { @@ -138,7 +136,6 @@ const AddOwner = ({ onClose={onClose} safeName={safeName} owners={owners} - network={network} values={values} onClickBack={onClickBack} onSubmit={onAddOwner} diff --git a/src/routes/safe/components/Settings/ManageOwners/AddOwnerModal/screens/Review/index.jsx b/src/routes/safe/components/Settings/ManageOwners/AddOwnerModal/screens/Review/index.jsx index a952e8d6..ec6b9054 100644 --- a/src/routes/safe/components/Settings/ManageOwners/AddOwnerModal/screens/Review/index.jsx +++ b/src/routes/safe/components/Settings/ManageOwners/AddOwnerModal/screens/Review/index.jsx @@ -31,14 +31,13 @@ type Props = { classes: Object, safeName: string, owners: List, - network: string, values: Object, onClickBack: Function, onSubmit: Function, } const ReviewAddOwner = ({ - classes, onClose, safeName, owners, network, values, onClickBack, onSubmit, + classes, onClose, safeName, owners, values, onClickBack, onSubmit, }: Props) => { const handleSubmit = () => { onSubmit() @@ -80,7 +79,6 @@ const ReviewAddOwner = ({ {values.threshold} {' '} out of - {' '} {owners.size + 1} {' '} owner(s) @@ -112,7 +110,7 @@ const ReviewAddOwner = ({ {owner.address} - + @@ -141,7 +139,11 @@ const ReviewAddOwner = ({ {values.ownerAddress} - + diff --git a/src/routes/safe/components/Settings/ManageOwners/EditOwnerModal/index.jsx b/src/routes/safe/components/Settings/ManageOwners/EditOwnerModal/index.jsx index 6fe47db6..b4e29f44 100644 --- a/src/routes/safe/components/Settings/ManageOwners/EditOwnerModal/index.jsx +++ b/src/routes/safe/components/Settings/ManageOwners/EditOwnerModal/index.jsx @@ -34,7 +34,6 @@ type Props = { isOpen: boolean, safeAddress: string, ownerAddress: string, - network: string, selectedOwnerName: string, editSafeOwner: Function, } @@ -47,7 +46,6 @@ const EditOwnerComponent = ({ ownerAddress, selectedOwnerName, editSafeOwner, - network, }: Props) => { const handleSubmit = (values) => { editSafeOwner({ safeAddress, ownerAddress, ownerName: values.ownerName }) @@ -94,7 +92,7 @@ const EditOwnerComponent = ({ {ownerAddress} - + diff --git a/src/routes/safe/components/Settings/ManageOwners/RemoveOwnerModal/index.jsx b/src/routes/safe/components/Settings/ManageOwners/RemoveOwnerModal/index.jsx index c245965b..b7f71111 100644 --- a/src/routes/safe/components/Settings/ManageOwners/RemoveOwnerModal/index.jsx +++ b/src/routes/safe/components/Settings/ManageOwners/RemoveOwnerModal/index.jsx @@ -28,7 +28,6 @@ type Props = { ownerName: string, owners: List, threshold: number, - network: string, createTransaction: Function, removeSafeOwner: Function, } @@ -71,7 +70,6 @@ const RemoveOwner = ({ ownerName, owners, threshold, - network, createTransaction, removeSafeOwner, }: Props) => { @@ -136,7 +134,6 @@ const RemoveOwner = ({ onClose={onClose} ownerAddress={ownerAddress} ownerName={ownerName} - network={network} onSubmit={ownerSubmitted} /> )} @@ -154,7 +151,6 @@ const RemoveOwner = ({ onClose={onClose} safeName={safeName} owners={owners} - network={network} values={values} ownerAddress={ownerAddress} ownerName={ownerName} diff --git a/src/routes/safe/components/Settings/ManageOwners/RemoveOwnerModal/screens/CheckOwner/index.jsx b/src/routes/safe/components/Settings/ManageOwners/RemoveOwnerModal/screens/CheckOwner/index.jsx index 06946a08..d4eb2a21 100644 --- a/src/routes/safe/components/Settings/ManageOwners/RemoveOwnerModal/screens/CheckOwner/index.jsx +++ b/src/routes/safe/components/Settings/ManageOwners/RemoveOwnerModal/screens/CheckOwner/index.jsx @@ -29,12 +29,11 @@ type Props = { classes: Object, ownerAddress: string, ownerName: string, - network: string, onSubmit: Function, } const CheckOwner = ({ - classes, onClose, ownerAddress, ownerName, network, onSubmit, + classes, onClose, ownerAddress, ownerName, onSubmit, }: Props) => { const handleSubmit = (values) => { onSubmit(values) @@ -69,7 +68,7 @@ const CheckOwner = ({ {ownerAddress} - + diff --git a/src/routes/safe/components/Settings/ManageOwners/RemoveOwnerModal/screens/Review/index.jsx b/src/routes/safe/components/Settings/ManageOwners/RemoveOwnerModal/screens/Review/index.jsx index 3aa956ae..1f29c38b 100644 --- a/src/routes/safe/components/Settings/ManageOwners/RemoveOwnerModal/screens/Review/index.jsx +++ b/src/routes/safe/components/Settings/ManageOwners/RemoveOwnerModal/screens/Review/index.jsx @@ -31,7 +31,6 @@ type Props = { classes: Object, safeName: string, owners: List, - network: string, values: Object, ownerAddress: string, ownerName: string, @@ -44,7 +43,6 @@ const ReviewRemoveOwner = ({ onClose, safeName, owners, - network, values, ownerAddress, ownerName, @@ -91,10 +89,10 @@ const ReviewRemoveOwner = ({ {values.threshold} {' '} -out of + out of {owners.size - 1} {' '} -owner(s) + owner(s) @@ -104,7 +102,7 @@ owner(s) {owners.size - 1} {' '} -Safe owner(s) + Safe owner(s) @@ -126,7 +124,7 @@ Safe owner(s) @@ -160,7 +158,7 @@ Safe owner(s) diff --git a/src/routes/safe/components/Settings/ManageOwners/ReplaceOwnerModal/index.jsx b/src/routes/safe/components/Settings/ManageOwners/ReplaceOwnerModal/index.jsx index 27705bf2..14c37e41 100644 --- a/src/routes/safe/components/Settings/ManageOwners/ReplaceOwnerModal/index.jsx +++ b/src/routes/safe/components/Settings/ManageOwners/ReplaceOwnerModal/index.jsx @@ -4,6 +4,7 @@ import { List } from 'immutable' import { withStyles } from '@material-ui/core/styles' import { SharedSnackbarConsumer } from '~/components/SharedSnackBar' import Modal from '~/components/Modal' +import { type Owner } from '~/routes/safe/store/models/owner' import { getGnosisSafeInstanceAt, SENTINEL_ADDRESS } from '~/logic/contracts/safeContracts' import OwnerForm from './screens/OwnerForm' import ReviewReplaceOwner from './screens/Review' @@ -25,7 +26,6 @@ type Props = { ownerAddress: string, ownerName: string, owners: List, - network: string, threshold: string, createTransaction: Function, replaceSafeOwner: Function, @@ -73,7 +73,6 @@ const ReplaceOwner = ({ ownerAddress, ownerName, owners, - network, threshold, createTransaction, replaceSafeOwner, @@ -136,7 +135,6 @@ const ReplaceOwner = ({ ownerAddress={ownerAddress} ownerName={ownerName} owners={owners} - network={network} onSubmit={ownerSubmitted} /> )} @@ -145,7 +143,6 @@ const ReplaceOwner = ({ onClose={onClose} safeName={safeName} owners={owners} - network={network} values={values} ownerAddress={ownerAddress} ownerName={ownerName} diff --git a/src/routes/safe/components/Settings/ManageOwners/ReplaceOwnerModal/screens/OwnerForm/index.jsx b/src/routes/safe/components/Settings/ManageOwners/ReplaceOwnerModal/screens/OwnerForm/index.jsx index 35929396..ce62108e 100644 --- a/src/routes/safe/components/Settings/ManageOwners/ReplaceOwnerModal/screens/OwnerForm/index.jsx +++ b/src/routes/safe/components/Settings/ManageOwners/ReplaceOwnerModal/screens/OwnerForm/index.jsx @@ -46,13 +46,12 @@ type Props = { classes: Object, ownerAddress: string, ownerName: string, - network: string, onSubmit: Function, owners: List, } const OwnerForm = ({ - classes, onClose, ownerAddress, ownerName, network, onSubmit, owners, + classes, onClose, ownerAddress, ownerName, onSubmit, owners, }: Props) => { const handleSubmit = (values) => { onSubmit(values) @@ -102,7 +101,7 @@ const OwnerForm = ({ diff --git a/src/routes/safe/components/Settings/ManageOwners/ReplaceOwnerModal/screens/Review/index.jsx b/src/routes/safe/components/Settings/ManageOwners/ReplaceOwnerModal/screens/Review/index.jsx index bfce4e73..0a956687 100644 --- a/src/routes/safe/components/Settings/ManageOwners/ReplaceOwnerModal/screens/Review/index.jsx +++ b/src/routes/safe/components/Settings/ManageOwners/ReplaceOwnerModal/screens/Review/index.jsx @@ -31,7 +31,6 @@ type Props = { classes: Object, safeName: string, owners: List, - network: string, values: Object, ownerAddress: string, ownerName: string, @@ -45,7 +44,6 @@ const ReviewRemoveOwner = ({ onClose, safeName, owners, - network, values, ownerAddress, ownerName, @@ -129,7 +127,7 @@ const ReviewRemoveOwner = ({ @@ -161,7 +159,7 @@ const ReviewRemoveOwner = ({ {ownerAddress} - + @@ -187,7 +185,7 @@ const ReviewRemoveOwner = ({ {values.ownerAddress} - + diff --git a/src/routes/safe/components/Settings/ManageOwners/index.jsx b/src/routes/safe/components/Settings/ManageOwners/index.jsx index 21aeaa01..436788f0 100644 --- a/src/routes/safe/components/Settings/ManageOwners/index.jsx +++ b/src/routes/safe/components/Settings/ManageOwners/index.jsx @@ -219,7 +219,6 @@ class ManageOwners extends React.Component { safeName={safeName} owners={owners} threshold={threshold} - network={network} userAddress={userAddress} createTransaction={createTransaction} addSafeOwner={addSafeOwner} @@ -233,7 +232,6 @@ class ManageOwners extends React.Component { ownerName={selectedOwnerName} owners={owners} threshold={threshold} - network={network} userAddress={userAddress} createTransaction={createTransaction} removeSafeOwner={removeSafeOwner} @@ -259,7 +257,6 @@ class ManageOwners extends React.Component { ownerAddress={selectedOwnerAddress} selectedOwnerName={selectedOwnerName} owners={owners} - network={network} editSafeOwner={editSafeOwner} /> diff --git a/src/routes/safe/components/Transactions/TxsTable/ExpandedTx/OwnersColumn/List.jsx b/src/routes/safe/components/Transactions/TxsTable/ExpandedTx/OwnersColumn/List.jsx index e443b758..25b0de46 100644 --- a/src/routes/safe/components/Transactions/TxsTable/ExpandedTx/OwnersColumn/List.jsx +++ b/src/routes/safe/components/Transactions/TxsTable/ExpandedTx/OwnersColumn/List.jsx @@ -41,7 +41,7 @@ const OwnerComponent = withStyles(styles)(({ owner, classes, isExecutor }: Owner + {shortVersionOf(owner.address, 4)} {' '} diff --git a/src/routes/safe/components/Transactions/TxsTable/ExpandedTx/index.jsx b/src/routes/safe/components/Transactions/TxsTable/ExpandedTx/index.jsx index e5f000e1..461fdbf3 100644 --- a/src/routes/safe/components/Transactions/TxsTable/ExpandedTx/index.jsx +++ b/src/routes/safe/components/Transactions/TxsTable/ExpandedTx/index.jsx @@ -74,7 +74,7 @@ const ExpandedTx = ({ TX hash: {tx.executionTxHash ? ( - + {shortVersionOf(tx.executionTxHash, 4)} diff --git a/src/routes/safe/components/Transactions/TxsTable/index.jsx b/src/routes/safe/components/Transactions/TxsTable/index.jsx index cb563b8b..d3fa5605 100644 --- a/src/routes/safe/components/Transactions/TxsTable/index.jsx +++ b/src/routes/safe/components/Transactions/TxsTable/index.jsx @@ -39,7 +39,6 @@ type Props = { safeAddress: string, createTransaction: Function, processTransaction: Function, - currentNetwork: string, } const TxsTable = ({ @@ -52,16 +51,15 @@ const TxsTable = ({ safeAddress, createTransaction, processTransaction, - currentNetwork, }: Props) => { const [expandedTx, setExpandedTx] = useState(null) const handleTxExpand = (safeTxHash) => { - setExpandedTx(prevTx => (prevTx === safeTxHash ? null : safeTxHash)) + setExpandedTx((prevTx) => (prevTx === safeTxHash ? null : safeTxHash)) } const columns = generateColumns() - const autoColumns = columns.filter(c => !c.custom) + const autoColumns = columns.filter((c) => !c.custom) const filteredData = getTxTableData(transactions) return ( @@ -118,7 +116,6 @@ const TxsTable = ({ threshold={threshold} owners={owners} granted={granted} - currentNetwork={currentNetwork} userAddress={userAddress} createTransaction={createTransaction} processTransaction={processTransaction} @@ -127,8 +124,7 @@ const TxsTable = ({ - )) - } + ))} )