From d6343a9bb1a7b3c097b8f07cc49f58bf9e26116e Mon Sep 17 00:00:00 2001 From: Mikhail Mikheev Date: Wed, 27 Jan 2021 20:35:14 +0400 Subject: [PATCH] Feature: Single tx safe apps interactions should not use multisend (#1792) * Don't use multisend if txs.length = 1 * calc txData inside useMemo * fix sending txs from apps, use correct operation/recipient Co-authored-by: Fernando Co-authored-by: Daniel Sanchez --- .../components/ConfirmTransactionModal.tsx | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/routes/safe/components/Apps/components/ConfirmTransactionModal.tsx b/src/routes/safe/components/Apps/components/ConfirmTransactionModal.tsx index fd199a37..02c371ae 100644 --- a/src/routes/safe/components/Apps/components/ConfirmTransactionModal.tsx +++ b/src/routes/safe/components/Apps/components/ConfirmTransactionModal.tsx @@ -1,4 +1,4 @@ -import React, { useEffect, useState } from 'react' +import React, { useEffect, useState, useMemo } from 'react' import { GenericModal, Icon, ModalFooterConfirmation, Text, Title } from '@gnosis.pm/safe-react-components' import { Transaction } from '@gnosis.pm/safe-apps-sdk-v1' import styled from 'styled-components' @@ -18,7 +18,7 @@ import { SafeApp } from 'src/routes/safe/components/Apps/types.d' import { fromTokenUnit } from 'src/logic/tokens/utils/humanReadableValue' import createTransaction from 'src/logic/safe/store/actions/createTransaction' import { MULTI_SEND_ADDRESS } from 'src/logic/contracts/safeContracts' -import { DELEGATE_CALL, TX_NOTIFICATION_TYPES } from 'src/logic/safe/transactions' +import { CALL, DELEGATE_CALL, TX_NOTIFICATION_TYPES } from 'src/logic/safe/transactions' import { encodeMultiSendCall } from 'src/logic/safe/transactions/multisend' import GasEstimationInfo from './GasEstimationInfo' @@ -101,6 +101,9 @@ export const ConfirmTransactionModal = ({ onTxReject, }: OwnProps): React.ReactElement | null => { const [estimatedSafeTxGas, setEstimatedSafeTxGas] = useState(0) + const txRecipient: string | undefined = useMemo(() => (txs.length > 1 ? MULTI_SEND_ADDRESS : txs[0]?.to), [txs]) + const txData: string | undefined = useMemo(() => (txs.length > 1 ? encodeMultiSendCall(txs) : txs[0]?.data), [txs]) + const operation = useMemo(() => (txs.length > 1 ? DELEGATE_CALL : CALL), [txs]) const { gasEstimation, @@ -110,9 +113,9 @@ export const ConfirmTransactionModal = ({ gasCostFormatted, txEstimationExecutionStatus, } = useEstimateTransactionGas({ - txData: encodeMultiSendCall(txs), - txRecipient: MULTI_SEND_ADDRESS, - operation: DELEGATE_CALL, + txData: txData || '', + txRecipient, + operation, }) useEffect(() => { @@ -137,16 +140,14 @@ export const ConfirmTransactionModal = ({ } const confirmTransactions = async () => { - const txData = encodeMultiSendCall(txs) - await dispatch( createTransaction( { safeAddress, - to: MULTI_SEND_ADDRESS, + to: txRecipient, valueInWei: '0', txData, - operation: DELEGATE_CALL, + operation, notifiedTransaction: TX_NOTIFICATION_TYPES.STANDARD_TX, origin: app.id, navigateToTransactionsTab: false,