From 33395438af7ec79dd212d3663b52c3a8a2776a24 Mon Sep 17 00:00:00 2001 From: mmv Date: Wed, 29 May 2019 12:34:57 +0400 Subject: [PATCH] Fix sending funds with Gnosis Safe extension --- src/components/Header/component/CircleDot.jsx | 12 +++++++-- .../ProviderInfo/ProviderAccesible.jsx | 16 ++++++------ .../ProviderInfo/ProviderDisconnected.jsx | 8 ++++-- src/components/Header/index.jsx | 25 +++++++++++-------- src/components/Header/selector.js | 2 +- src/logic/safe/transactions/gas.js | 6 ++--- src/logic/safe/transactions/send.js | 6 ++--- .../safe/store/actions/createTransaction.js | 12 +++++---- 8 files changed, 54 insertions(+), 33 deletions(-) diff --git a/src/components/Header/component/CircleDot.jsx b/src/components/Header/component/CircleDot.jsx index ef208715..57e710eb 100644 --- a/src/components/Header/component/CircleDot.jsx +++ b/src/components/Header/component/CircleDot.jsx @@ -61,7 +61,15 @@ const buildDotStyleFrom = (size: number, top: number, right: number, mode: Mode) }) const KeyRing = ({ - classes, circleSize, keySize, dotSize, dotTop, dotRight, mode, center = false, hideDot = false, + classes, + circleSize, + keySize, + dotSize, + dotTop, + dotRight, + mode, + center = false, + hideDot = false, }: Props) => { const keyStyle = buildKeyStyleFrom(circleSize, center, dotSize) const dotStyle = buildDotStyleFrom(dotSize, dotTop, dotRight, mode) @@ -80,7 +88,7 @@ const KeyRing = ({ className={isWarning ? classes.warning : undefined} /> - { !hideDot && } + {!hideDot && } ) diff --git a/src/components/Header/component/ProviderInfo/ProviderAccesible.jsx b/src/components/Header/component/ProviderInfo/ProviderAccesible.jsx index 2b338285..e8b5a9c9 100644 --- a/src/components/Header/component/ProviderInfo/ProviderAccesible.jsx +++ b/src/components/Header/component/ProviderInfo/ProviderAccesible.jsx @@ -54,18 +54,20 @@ const ProviderInfo = ({ return ( - { connected && + {connected && ( - } - { !connected && - - } + )} + {!connected && } - {providerText} - {cutAddress} + + {providerText} + + + {cutAddress} + ) diff --git a/src/components/Header/component/ProviderInfo/ProviderDisconnected.jsx b/src/components/Header/component/ProviderInfo/ProviderDisconnected.jsx index 2133bff9..4f7c0b88 100644 --- a/src/components/Header/component/ProviderInfo/ProviderDisconnected.jsx +++ b/src/components/Header/component/ProviderInfo/ProviderDisconnected.jsx @@ -33,8 +33,12 @@ const ProviderDesconnected = ({ classes }: Props) => ( - Not Connected - Connect Wallet + + Not Connected + + + Connect Wallet + ) diff --git a/src/components/Header/index.jsx b/src/components/Header/index.jsx index 1ea89441..4ff64c7f 100644 --- a/src/components/Header/index.jsx +++ b/src/components/Header/index.jsx @@ -27,22 +27,19 @@ class HeaderComponent extends React.PureComponent { } componentDidMount() { - this.props.fetchProvider(this.props.openSnackbar) - } - - componentDidCatch(error: Error, info: Info) { - this.setState({ hasError: true }) - this.props.openSnackbar(WALLET_ERROR_MSG, 'error') - - logComponentStack(error, info) + this.onConnect() } onDisconnect = () => { - this.props.removeProvider(this.props.openSnackbar) + const { removeProvider, openSnackbar } = this.props + + removeProvider(openSnackbar) } onConnect = () => { - this.props.fetchProvider(this.props.openSnackbar) + const { fetchProvider, openSnackbar } = this.props + + fetchProvider(openSnackbar) } getProviderInfoBased = () => { @@ -79,6 +76,14 @@ class HeaderComponent extends React.PureComponent { ) } + componentDidCatch(error: Error, info: Info) { + const { openSnackbar } = this.props + this.setState({ hasError: true }) + openSnackbar(WALLET_ERROR_MSG, 'error') + + logComponentStack(error, info) + } + render() { const info = this.getProviderInfoBased() const details = this.getProviderDetailsBased() diff --git a/src/components/Header/selector.js b/src/components/Header/selector.js index 9e9baad2..fb7e5e77 100644 --- a/src/components/Header/selector.js +++ b/src/components/Header/selector.js @@ -16,7 +16,7 @@ export type SelectorProps = { available: boolean, } -export default createStructuredSelector({ +export default createStructuredSelector({ provider: providerNameSelector, userAddress: userAccountSelector, network: networkSelector, diff --git a/src/logic/safe/transactions/gas.js b/src/logic/safe/transactions/gas.js index 49ab82f5..1ae8e0d0 100644 --- a/src/logic/safe/transactions/gas.js +++ b/src/logic/safe/transactions/gas.js @@ -2,7 +2,7 @@ import { BigNumber } from 'bignumber.js' import { getWeb3 } from '~/logic/wallets/getWeb3' import { EMPTY_DATA } from '~/logic/wallets/ethTransactions' -import { getSafeEthereumInstance } from '../safeFrontendOperations' +import { getGnosisSafeInstanceAt } from '~/logic/contracts/safeContracts' const estimateDataGasCosts = (data) => { const reducer = (accumulator, currentValue) => { @@ -68,7 +68,7 @@ export const generateTxGasEstimateFrom = async ( try { let safeInstance = safe if (!safeInstance) { - safeInstance = await getSafeEthereumInstance(safeAddress) + safeInstance = await getGnosisSafeInstanceAt(safeAddress) } const estimateData = safeInstance.contract.methods.requiredTxGas(to, valueInWei, data, operation).encodeABI() @@ -100,7 +100,7 @@ export const calculateTxFee = async ( try { let safeInstance = safe if (!safeInstance) { - safeInstance = await getSafeEthereumInstance(safeAddress) + safeInstance = await getGnosisSafeInstanceAt(safeAddress) } // https://gnosis-safe.readthedocs.io/en/latest/contracts/signatures.html#pre-validated-signatures diff --git a/src/logic/safe/transactions/send.js b/src/logic/safe/transactions/send.js index ee4e93cd..9252e274 100644 --- a/src/logic/safe/transactions/send.js +++ b/src/logic/safe/transactions/send.js @@ -4,7 +4,7 @@ import { getStandardTokenContract } from '~/logic/tokens/store/actions/fetchToke import { EMPTY_DATA } from '~/logic/wallets/ethTransactions' import { isEther } from '~/logic/tokens/utils/tokenHelpers' import { type Token } from '~/logic/tokens/store/model/token' -import { getSafeEthereumInstance } from '../safeFrontendOperations' +import { getGnosisSafeInstanceAt } from '~/logic/contracts/safeContracts' export const CALL = 0 const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000' @@ -42,13 +42,13 @@ export const executeTransaction = async ( return tx } catch (error) { // eslint-disable-next-line - console.log('Error calculating tx gas estimation ' + error) + console.log('Error executing the TX: ' + error) return 0 } } export const createTransaction = async (safeAddress: string, to: string, valueInEth: string, token: Token) => { - const safeInstance = await getSafeEthereumInstance(safeAddress) + const safeInstance = await getGnosisSafeInstanceAt(safeAddress) const web3 = getWeb3() const from = web3.currentProvider.selectedAddress const threshold = await safeInstance.getThreshold() diff --git a/src/routes/safe/store/actions/createTransaction.js b/src/routes/safe/store/actions/createTransaction.js index 7ba8704a..9471bcd0 100644 --- a/src/routes/safe/store/actions/createTransaction.js +++ b/src/routes/safe/store/actions/createTransaction.js @@ -1,12 +1,13 @@ // @flow -import type { Dispatch as ReduxDispatch } from 'redux' +import type { Dispatch as ReduxDispatch, GetState } from 'redux' import { createAction } from 'redux-actions' import { getWeb3 } from '~/logic/wallets/getWeb3' import { EMPTY_DATA } from '~/logic/wallets/ethTransactions' import { type Token } from '~/logic/tokens/store/model/token' +import { userAccountSelector } from '~/logic/wallets/store/selectors' import { type GlobalState } from '~/store' import { isEther } from '~/logic/tokens/utils/tokenHelpers' -import { getSafeEthereumInstance } from '~/logic/safe/safeFrontendOperations' +import { getGnosisSafeInstanceAt } from '~/logic/contracts/safeContracts' import { executeTransaction, CALL } from '~/logic/safe/transactions' import { getStandardTokenContract } from '~/logic/tokens/store/actions/fetchTokens' @@ -19,12 +20,13 @@ const createTransaction = ( valueInEth: string, token: Token, openSnackbar: Function, -) => async (dispatch: ReduxDispatch) => { +) => async (dispatch: ReduxDispatch, getState: GetState) => { const isSendingETH = isEther(token.symbol) + const state: GlobalState = getState() - const safeInstance = await getSafeEthereumInstance(safeAddress) + const safeInstance = await getGnosisSafeInstanceAt(safeAddress) const web3 = getWeb3() - const from = web3.currentProvider.selectedAddress + const from = userAccountSelector(state) const threshold = await safeInstance.getThreshold() const nonce = await safeInstance.nonce() const txRecipient = isSendingETH ? to : token.address