diff --git a/src/routes/safe/components/AddressBook/index.jsx b/src/routes/safe/components/AddressBook/index.jsx index ddf1d259..d3176882 100644 --- a/src/routes/safe/components/AddressBook/index.jsx +++ b/src/routes/safe/components/AddressBook/index.jsx @@ -42,8 +42,7 @@ import RenameOwnerIcon from '~/routes/safe/components/Settings/ManageOwners/asse import type { OwnerRow } from '~/routes/safe/components/Settings/ManageOwners/dataFetcher' import RemoveOwnerIcon from '~/routes/safe/components/Settings/assets/icons/bin.svg' import RemoveOwnerIconDisabled from '~/routes/safe/components/Settings/assets/icons/disabled-bin.svg' -import { extendedSafeTokensSelector } from '~/routes/safe/container/selector' -import { addressBookQueryParamsSelector, safeSelector, safesListSelector } from '~/routes/safe/store/selectors' +import { addressBookQueryParamsSelector, safesListSelector } from '~/routes/safe/store/selectors' type Props = { classes: Object, @@ -86,10 +85,7 @@ const AddressBookTable = ({ classes }: Props) => { } }, [addressBook]) - const safe = useSelector(safeSelector) const safesList = useSelector(safesListSelector) - const activeTokens = useSelector(extendedSafeTokensSelector) - const { address, ethBalance, name } = safe const newEntryModalHandler = (entry: AddressBookEntry) => { setEditCreateEntryModalOpen(false) @@ -223,13 +219,9 @@ const AddressBookTable = ({ classes }: Props) => { /> setSendFundsModalOpen(false)} recipientAddress={selectedEntry && selectedEntry.entry ? selectedEntry.entry.address : undefined} - safeAddress={address} - safeName={name} - tokens={activeTokens} /> ) diff --git a/src/routes/safe/components/Balances/Collectibles/index.jsx b/src/routes/safe/components/Balances/Collectibles/index.jsx index a1f70ae7..0bb8e3af 100644 --- a/src/routes/safe/components/Balances/Collectibles/index.jsx +++ b/src/routes/safe/components/Balances/Collectibles/index.jsx @@ -10,7 +10,6 @@ import Paragraph from '~/components/layout/Paragraph' import type { NFTAssetsState, NFTTokensState } from '~/logic/collectibles/store/reducer/collectibles' import { nftAssetsSelector, nftTokensSelector } from '~/logic/collectibles/store/selectors' import SendModal from '~/routes/safe/components/Balances/SendModal' -import { safeSelector } from '~/routes/safe/store/selectors' import { fontColor, lg, screenSm, screenXs } from '~/theme/variables' const useStyles = makeStyles({ @@ -80,7 +79,6 @@ const Collectibles = () => { const classes = useStyles() const [selectedToken, setSelectedToken] = React.useState({}) const [sendNFTsModalOpen, setSendNFTsModalOpen] = React.useState(false) - const { address, ethBalance, name } = useSelector(safeSelector) const nftAssets: NFTAssetsState = useSelector(nftAssetsSelector) const nftTokens: NFTTokensState = useSelector(nftTokensSelector) const nftAssetsKeys = Object.keys(nftAssets) @@ -124,11 +122,8 @@ const Collectibles = () => { setSendNFTsModalOpen(false)} - safeAddress={address} - safeName={name} selectedToken={selectedToken} /> diff --git a/src/routes/safe/components/Balances/SendModal/index.jsx b/src/routes/safe/components/Balances/SendModal/index.jsx index 8898069d..5bf4d6d0 100644 --- a/src/routes/safe/components/Balances/SendModal/index.jsx +++ b/src/routes/safe/components/Balances/SendModal/index.jsx @@ -2,7 +2,6 @@ import CircularProgress from '@material-ui/core/CircularProgress' import { makeStyles } from '@material-ui/core/styles' import cn from 'classnames' -import { List } from 'immutable' import React, { Suspense, useEffect, useState } from 'react' import Modal from '~/components/Modal' @@ -33,16 +32,11 @@ type ActiveScreen = | 'reviewCollectible' type Props = { - onClose: () => void, - isOpen: boolean, - safeAddress: string, - safeName: string, - ethBalance: string, - tokens: List, - selectedToken?: string | NFTToken | {}, - createTransaction?: Function, activeScreenType: ActiveScreen, + isOpen: boolean, + onClose: () => void, recipientAddress?: string, + selectedToken?: string | NFTToken | {}, } type TxStateType = @@ -71,18 +65,7 @@ const useStyles = makeStyles({ }, }) -const SendModal = ({ - activeScreenType, - createTransaction, - ethBalance, - isOpen, - onClose, - recipientAddress, - safeAddress, - safeName, - selectedToken, - tokens, -}: Props) => { +const SendModal = ({ activeScreenType, isOpen, onClose, recipientAddress, selectedToken }: Props) => { const classes = useStyles() const [activeScreen, setActiveScreen] = useState(activeScreenType || 'chooseTxType') const [tx, setTx] = useState({}) @@ -129,50 +112,26 @@ const SendModal = ({ )} {activeScreen === 'sendFunds' && ( )} {activeScreen === 'reviewTx' && ( - + setActiveScreen('sendFunds')} tx={tx} /> )} {activeScreen === 'sendCustomTx' && ( )} {activeScreen === 'reviewCustomTx' && ( - + setActiveScreen('sendCustomTx')} tx={tx} /> )} {activeScreen === 'sendCollectible' && ( void, onPrev: () => void, - classes: Object, tx: Object, - tokens: List, - createTransaction: Function, - enqueueSnackbar: Function, - closeSnackbar: Function, } const ReviewCollectible = ({ closeSnackbar, enqueueSnackbar, onClose, onPrev, tx }: Props) => { diff --git a/src/routes/safe/components/Balances/SendModal/screens/ReviewCustomTx/index.jsx b/src/routes/safe/components/Balances/SendModal/screens/ReviewCustomTx/index.jsx index 794ec87a..5e2c11b1 100644 --- a/src/routes/safe/components/Balances/SendModal/screens/ReviewCustomTx/index.jsx +++ b/src/routes/safe/components/Balances/SendModal/screens/ReviewCustomTx/index.jsx @@ -1,9 +1,10 @@ // @flow import IconButton from '@material-ui/core/IconButton' -import { withStyles } from '@material-ui/core/styles' +import { makeStyles } from '@material-ui/core/styles' import Close from '@material-ui/icons/Close' import { withSnackbar } from 'notistack' import React, { useEffect, useState } from 'react' +import { useDispatch, useSelector } from 'react-redux' import ArrowDown from '../assets/arrow-down.svg' @@ -26,44 +27,37 @@ import { getEthAsToken } from '~/logic/tokens/utils/tokenHelpers' import { getWeb3 } from '~/logic/wallets/getWeb3' import SafeInfo from '~/routes/safe/components/Balances/SendModal/SafeInfo' import { setImageToPlaceholder } from '~/routes/safe/components/Balances/utils' +import createTransaction from '~/routes/safe/store/actions/createTransaction' +import { safeSelector } from '~/routes/safe/store/selectors' import { sm } from '~/theme/variables' type Props = { + closeSnackbar: () => void, + enqueueSnackbar: () => void, onClose: () => void, - setActiveScreen: Function, - classes: Object, - safeAddress: string, - safeName: string, - ethBalance: string, + onPrev: () => void, tx: Object, - createTransaction: Function, - enqueueSnackbar: Function, - closeSnackbar: Function, } -const ReviewCustomTx = ({ - classes, - closeSnackbar, - createTransaction, - enqueueSnackbar, - ethBalance, - onClose, - safeAddress, - safeName, - setActiveScreen, - tx, -}: Props) => { +const useStyles = makeStyles(styles) + +const ReviewCustomTx = ({ closeSnackbar, enqueueSnackbar, onClose, onPrev, tx }: Props) => { + const classes = useStyles() + const dispatch = useDispatch() + const { address: safeAddress, ethBalance, name: safeName } = useSelector(safeSelector) const [gasCosts, setGasCosts] = useState('< 0.001') useEffect(() => { let isCurrent = true - const estimateGas = async () => { - const web3 = getWeb3() - const { fromWei, toBN } = web3.utils - const estimatedGasCosts = await estimateTxGasCosts(safeAddress, tx.recipientAddress, tx.data.trim()) + const estimateGas = async () => { + const { fromWei, toBN } = getWeb3().utils + const txData = tx.data ? tx.data.trim() : '' + + const estimatedGasCosts = await estimateTxGasCosts(safeAddress, tx.recipientAddress, txData) const gasCostsAsEth = fromWei(toBN(estimatedGasCosts), 'ether') const formattedGasCosts = formatAmount(gasCostsAsEth) + if (isCurrent) { setGasCosts(formattedGasCosts) } @@ -79,18 +73,21 @@ const ReviewCustomTx = ({ const submitTx = async () => { const web3 = getWeb3() const txRecipient = tx.recipientAddress - const txData = tx.data.trim() - const txValue = tx.value ? web3.utils.toWei(tx.value, 'ether') : 0 + const txData = tx.data ? tx.data.trim() : '' + const txValue = tx.value ? web3.utils.toWei(tx.value, 'ether') : '0' + + dispatch( + createTransaction({ + safeAddress, + to: txRecipient, + valueInWei: txValue, + txData, + notifiedTransaction: TX_NOTIFICATION_TYPES.STANDARD_TX, + enqueueSnackbar, + closeSnackbar, + }), + ) - createTransaction({ - safeAddress, - to: txRecipient, - valueInWei: txValue, - txData, - notifiedTransaction: TX_NOTIFICATION_TYPES.STANDARD_TX, - enqueueSnackbar, - closeSnackbar, - }) onClose() } @@ -167,7 +164,7 @@ const ReviewCustomTx = ({ -