Inform the user if a Safe-App initiate a malformed TX (#895)

* @gnosis.pm/safe-react-components from NPM

* Infor is TX is malformed

* review fixes

* improve names

* review fixes

* trigger build
This commit is contained in:
nicolas 2020-05-14 10:50:04 -03:00 committed by GitHub
parent b1db9df3db
commit 77e4987919
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 60 additions and 26 deletions

View File

@ -136,7 +136,7 @@
},
"dependencies": {
"@gnosis.pm/safe-contracts": "1.1.1-dev.2",
"@gnosis.pm/safe-react-components": "https://github.com/gnosis/safe-react-components.git#a057248",
"@gnosis.pm/safe-react-components": "^0.1.0",
"@gnosis.pm/util-contracts": "2.0.6",
"@ledgerhq/hw-transport-node-hid": "5.15.0",
"@material-ui/core": "4.9.14",

View File

@ -1,9 +1,11 @@
// @flow
import { Icon, ModalFooterConfirmation, Text, Title } from '@gnosis.pm/safe-react-components'
import { BigNumber } from 'bignumber.js'
import React from 'react'
import styled from 'styled-components'
import { AddressInfo, Collapse, DividerLine, ModalFooterConfirmation, ModalTitle, TextBox } from '~/components-v2'
import { AddressInfo, Collapse, DividerLine, ModalTitle, TextBox } from '~/components-v2'
import { mustBeEthereumAddress } from '~/components/forms/validator'
import Bold from '~/components/layout/Bold'
import Heading from '~/components/layout/Heading'
import Img from '~/components/layout/Img'
@ -27,6 +29,19 @@ const CollapseContent = styled.div`
}
`
const IconText = styled.div`
display: flex;
align-items: center;
span {
margin-right: 4px;
}
`
const isTxValid = (t) => {
const isAddressValid = mustBeEthereumAddress(t.to) === undefined
return isAddressValid && t.value !== undefined && typeof t.value === 'number' && t.data && typeof t.data === 'string'
}
const confirmTransactions = (
safeAddress: string,
safeName: string,
@ -38,9 +53,22 @@ const confirmTransactions = (
closeModal: () => void,
onConfirm: () => void,
) => {
const areTxsMalformed = txs.some((t) => !isTxValid(t))
const title = <ModalTitle iconUrl={iconApp} title={nameApp} />
const body = (
const body = areTxsMalformed ? (
<>
<IconText>
<Icon color="error" size="md" type="info" />
<Title size="xs">Transaction error</Title>
</IconText>
<Text size="lg">
This Safe App initiated a transaction which cannot be processed. Please get in touch with the developer of this
Safe App for more information.
</Text>
</>
) : (
<>
<AddressInfo ethBalance={ethBalance} safeAddress={safeAddress} safeName={safeName} />
<DividerLine withArrow />
@ -67,8 +95,15 @@ const confirmTransactions = (
})}
</>
)
const footer = (
<ModalFooterConfirmation cancelText="Cancel" handleCancel={closeModal} handleOk={onConfirm} okText="Submit" />
<ModalFooterConfirmation
cancelText="Cancel"
handleCancel={closeModal}
handleOk={onConfirm}
okDisabled={areTxsMalformed}
okText="Submit"
/>
)
openModal({

View File

@ -27,28 +27,26 @@ const sendTransactions = (
const web3 = getWeb3()
const multiSend = new web3.eth.Contract(multiSendAbi, multiSendAddress)
const encodeMultiSendCalldata = multiSend.methods
.multiSend(
`0x${txs
.map((tx) =>
[
web3.eth.abi.encodeParameter('uint8', 0).slice(-2),
web3.eth.abi.encodeParameter('address', tx.to).slice(-40),
web3.eth.abi.encodeParameter('uint256', tx.value).slice(-64),
web3.eth.abi.encodeParameter('uint256', web3.utils.hexToBytes(tx.data).length).slice(-64),
tx.data.replace(/^0x/, ''),
].join(''),
)
.join('')}`,
const joinedTxs = txs
.map((tx) =>
[
web3.eth.abi.encodeParameter('uint8', 0).slice(-2),
web3.eth.abi.encodeParameter('address', tx.to).slice(-40),
web3.eth.abi.encodeParameter('uint256', tx.value).slice(-64),
web3.eth.abi.encodeParameter('uint256', web3.utils.hexToBytes(tx.data).length).slice(-64),
tx.data.replace(/^0x/, ''),
].join(''),
)
.encodeABI()
.join('')
const encodeMultiSendCallData = multiSend.methods.multiSend(`0x${joinedTxs}`).encodeABI()
return dispatch(
createTransaction({
safeAddress,
to: multiSendAddress,
valueInWei: 0,
txData: encodeMultiSendCalldata,
txData: encodeMultiSendCallData,
notifiedTransaction: 'STANDARD_TX',
enqueueSnackbar,
closeSnackbar,

View File

@ -1246,9 +1246,10 @@
solc "0.5.14"
truffle "^5.1.21"
"@gnosis.pm/safe-react-components@https://github.com/gnosis/safe-react-components.git#a057248":
version "0.1.1"
resolved "https://github.com/gnosis/safe-react-components.git#a05724802f5fc74dd759ba8d9c916eb82cf67ef0"
"@gnosis.pm/safe-react-components@^0.1.0":
version "0.1.0"
resolved "https://registry.yarnpkg.com/@gnosis.pm/safe-react-components/-/safe-react-components-0.1.0.tgz#3ff7e3d974cf301ed6c1d898c442c081ff7da675"
integrity sha512-ehDBaAgNFqbXx/eqjLivTtHlXvy/4XPH05r0IZ/+9idDjY3eh9eOjAewS9DFtPqLicp/92tVQOzmcEbTNGJ8JQ==
dependencies:
classnames "^2.2.6"
polished "^3.5.1"
@ -15474,11 +15475,11 @@ polished@3.6.3:
"@babel/runtime" "^7.9.2"
polished@^3.5.1:
version "3.5.2"
resolved "https://registry.yarnpkg.com/polished/-/polished-3.5.2.tgz#ca132b8cd68f7ffa95ae9d423f03e7a14fda1062"
integrity sha512-vWoRDg3gY5RQBtUfcj9MRN10VCIf4EkdUikGxyXItg2Hnwk+eIVtdBiLajN0ldFeT3Vq4r/QNbjrQdhqBKrTug==
version "3.6.3"
resolved "https://registry.yarnpkg.com/polished/-/polished-3.6.3.tgz#68f4fe7ffad46530733029b939dd12978200cb59"
integrity sha512-QJ0q0b6gX1+0OJtPMfgVJxV0vg5XTa4im+Rca989dAtmsd/fEky3X+0A+V+OUXq1nyiDGplJwqD853dTS0gkPg==
dependencies:
"@babel/runtime" "^7.8.7"
"@babel/runtime" "^7.9.2"
popper.js@^1.16.1-lts:
version "1.16.1"