fix sending tokens

This commit is contained in:
Mikhail Mikheev 2019-05-27 16:12:13 +04:00
parent c3fba307c2
commit 5edc8b821a
5 changed files with 31 additions and 10 deletions

View File

@ -82,7 +82,7 @@ export const generateMetamaskSignature = async (
operation,
txGasEstimate,
)
console.log({sender})
const jsonTypedData = JSON.stringify(typedData)
const signedTypedData = {
method: 'eth_signTypedData_v3',

View File

@ -94,7 +94,14 @@ const Receive = ({
</Block>
<Block align="center" className={classes.addressContainer}>
<Identicon address={safeAddress} diameter={32} />
<Paragraph onClick={copyToClipboard} className={classes.address}>{safeAddress}</Paragraph>
<Paragraph
onClick={() => {
copyToClipboard(safeAddress)
}}
className={classes.address}
>
{safeAddress}
</Paragraph>
<Link className={classes.open} to={etherScanLink} target="_blank">
<OpenInNew style={openIconStyle} />
</Link>

View File

@ -102,7 +102,7 @@ const ReviewTx = ({
</Row>
<Row margin="md" align="center">
<Img src={tx.token.logoUri} height={28} alt={tx.token.name} onError={setImageToPlaceholder} />
<Paragraph size="md" noMargin>
<Paragraph size="md" noMargin className={classes.amount}>
{tx.amount}
{' '}
{tx.token.symbol}

View File

@ -24,6 +24,9 @@ export const styles = () => ({
container: {
padding: `${md} ${lg}`,
},
amount: {
marginLeft: sm,
},
buttonRow: {
height: '84px',
justifyContent: 'center',

View File

@ -13,28 +13,39 @@ import { getStandardTokenContract } from '~/logic/tokens/store/actions/fetchToke
export const ADD_TRANSACTIONS = 'ADD_TRANSACTIONS'
export const addTransactions = createAction<string, *>(ADD_TRANSACTIONS)
const createTransaction = (safeAddress: string, to: string, valueInEth: string, token: Token, openSnackbar: Function) => async (
dispatch: ReduxDispatch<GlobalState>,
) => {
const createTransaction = (
safeAddress: string,
to: string,
valueInEth: string,
token: Token,
openSnackbar: Function,
) => async (dispatch: ReduxDispatch<GlobalState>) => {
const isSendingETH = isEther(token.symbol)
const safeInstance = await getSafeEthereumInstance(safeAddress)
const web3 = getWeb3()
const from = web3.currentProvider.selectedAddress
const threshold = await safeInstance.getThreshold()
const nonce = await safeInstance.nonce()
const valueInWei = web3.utils.toWei(valueInEth, 'ether')
const txRecipient = isSendingETH ? to : token.address
let valueInWei = web3.utils.toWei(valueInEth, 'ether')
const isExecution = threshold.toNumber() === 1
let txData = EMPTY_DATA
if (!isEther(token.symbol)) {
if (!isSendingETH) {
const StandardToken = await getStandardTokenContract()
const sendToken = await StandardToken.at(token.address)
txData = sendToken.contract.transfer(to, valueInWei).encodeABI()
txData = sendToken.contract.methods.transfer(to, valueInWei).encodeABI()
// valueInWei should be 0 if we send tokens
// the real value is encoded in txData and will be used by the contract
// if valueInWei > 0 it would send ETH from the safe
valueInWei = 0
}
let txHash
if (isExecution) {
txHash = await executeTransaction(safeInstance, to, valueInWei, txData, CALL, nonce, from)
txHash = await executeTransaction(safeInstance, txRecipient, valueInWei, txData, CALL, nonce, from)
openSnackbar('Transaction has been submitted', 'success')
} else {
// txHash = await approveTransaction(safeAddress, to, valueInWei, txData, CALL, nonce)