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 <fernando.greco@gmail.com> Co-authored-by: Daniel Sanchez <daniel.sanchez@gnosis.pm>
This commit is contained in:
parent
57f7acd26e
commit
d6343a9bb1
|
@ -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 { GenericModal, Icon, ModalFooterConfirmation, Text, Title } from '@gnosis.pm/safe-react-components'
|
||||||
import { Transaction } from '@gnosis.pm/safe-apps-sdk-v1'
|
import { Transaction } from '@gnosis.pm/safe-apps-sdk-v1'
|
||||||
import styled from 'styled-components'
|
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 { fromTokenUnit } from 'src/logic/tokens/utils/humanReadableValue'
|
||||||
import createTransaction from 'src/logic/safe/store/actions/createTransaction'
|
import createTransaction from 'src/logic/safe/store/actions/createTransaction'
|
||||||
import { MULTI_SEND_ADDRESS } from 'src/logic/contracts/safeContracts'
|
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 { encodeMultiSendCall } from 'src/logic/safe/transactions/multisend'
|
||||||
|
|
||||||
import GasEstimationInfo from './GasEstimationInfo'
|
import GasEstimationInfo from './GasEstimationInfo'
|
||||||
|
@ -101,6 +101,9 @@ export const ConfirmTransactionModal = ({
|
||||||
onTxReject,
|
onTxReject,
|
||||||
}: OwnProps): React.ReactElement | null => {
|
}: OwnProps): React.ReactElement | null => {
|
||||||
const [estimatedSafeTxGas, setEstimatedSafeTxGas] = useState(0)
|
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 {
|
const {
|
||||||
gasEstimation,
|
gasEstimation,
|
||||||
|
@ -110,9 +113,9 @@ export const ConfirmTransactionModal = ({
|
||||||
gasCostFormatted,
|
gasCostFormatted,
|
||||||
txEstimationExecutionStatus,
|
txEstimationExecutionStatus,
|
||||||
} = useEstimateTransactionGas({
|
} = useEstimateTransactionGas({
|
||||||
txData: encodeMultiSendCall(txs),
|
txData: txData || '',
|
||||||
txRecipient: MULTI_SEND_ADDRESS,
|
txRecipient,
|
||||||
operation: DELEGATE_CALL,
|
operation,
|
||||||
})
|
})
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
@ -137,16 +140,14 @@ export const ConfirmTransactionModal = ({
|
||||||
}
|
}
|
||||||
|
|
||||||
const confirmTransactions = async () => {
|
const confirmTransactions = async () => {
|
||||||
const txData = encodeMultiSendCall(txs)
|
|
||||||
|
|
||||||
await dispatch(
|
await dispatch(
|
||||||
createTransaction(
|
createTransaction(
|
||||||
{
|
{
|
||||||
safeAddress,
|
safeAddress,
|
||||||
to: MULTI_SEND_ADDRESS,
|
to: txRecipient,
|
||||||
valueInWei: '0',
|
valueInWei: '0',
|
||||||
txData,
|
txData,
|
||||||
operation: DELEGATE_CALL,
|
operation,
|
||||||
notifiedTransaction: TX_NOTIFICATION_TYPES.STANDARD_TX,
|
notifiedTransaction: TX_NOTIFICATION_TYPES.STANDARD_TX,
|
||||||
origin: app.id,
|
origin: app.id,
|
||||||
navigateToTransactionsTab: false,
|
navigateToTransactionsTab: false,
|
||||||
|
|
Loading…
Reference in New Issue