Skip to content
This repository was archived by the owner on Nov 10, 2023. It is now read-only.

Commit f00e49c

Browse files
committed
Fix: catch batch errors
1 parent 1925c1f commit f00e49c

File tree

2 files changed

+26
-13
lines changed

2 files changed

+26
-13
lines changed

src/logic/exceptions/registry.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ enum ErrorCodes {
3030
_616 = '616: Failed to retrieve recommended nonce',
3131
_617 = '617: Error fetching safeTxGas',
3232
_618 = '618: Error fetching fee history',
33+
_619 = '619: Failed prepairing a multisend tx',
3334
_700 = '700: Failed to read from local/session storage',
3435
_701 = '701: Failed to write to local/session storage',
3536
_702 = '702: Failed to remove from local/session storage',

src/routes/safe/components/Transactions/TxList/BatchExecute.tsx

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import { Dispatch } from 'src/logic/safe/store/actions/types'
1818
import { ModalHeader } from 'src/routes/safe/components/Balances/SendModal/screens/ModalHeader'
1919
import Row from 'src/components/layout/Row'
2020
import Paragraph from 'src/components/layout/Paragraph'
21-
import { GnosisSafe } from 'src/types/contracts/gnosis_safe'
2221
import Hairline from 'src/components/layout/Hairline'
2322
import { getInteractionTitle } from 'src/routes/safe/components/Transactions/helpers/utils'
2423
import PrefixedEthHashInfo from 'src/components/PrefixedEthHashInfo'
@@ -42,6 +41,7 @@ import { sameAddressAsSafeSelector } from 'src/routes/safe/container/selector'
4241
import { TransactionFailText } from 'src/components/TransactionFailText'
4342
import { EstimationStatus } from 'src/logic/hooks/useEstimateTransactionGas'
4443
import { BatchExecuteButton } from 'src/routes/safe/components/Transactions/TxList/BatchExecuteButton'
44+
import { Errors, logError } from 'src/logic/exceptions/CodedException'
4545

4646
const DecodedTransactions = ({
4747
transactions,
@@ -102,10 +102,12 @@ async function getTxDetails(transactions: Transaction[], dispatch: Dispatch) {
102102
async function getBatchExecuteData(
103103
dispatch: Dispatch,
104104
transactions: Transaction[],
105-
safeInstance: GnosisSafe,
106105
safeAddress: string,
106+
safeVersion: string,
107107
account: string,
108108
) {
109+
const safeInstance = getGnosisSafeInstanceAt(safeAddress, safeVersion)
110+
109111
const txs: MultiSendTx[] = transactions.map((transaction) => {
110112
const txInfo = getTxInfo(transaction, safeAddress)
111113
const confirmations = getTxConfirmations(transaction)
@@ -129,11 +131,11 @@ export const BatchExecute = React.memo((): ReactElement | null => {
129131
const dispatch = useDispatch<Dispatch>()
130132
const { address: safeAddress, currentVersion } = useSelector(currentSafe)
131133
const account = useSelector(userAccountSelector)
132-
const safeInstance = getGnosisSafeInstanceAt(safeAddress, currentVersion)
133134
const multiSendContractAddress = getMultisendContractAddress()
134135
const batchableTransactions = useSelector(getBatchableTransactions)
135136
const [txsWithDetails, setTxsWithDetails] = useState<Transaction[]>([])
136137
const [isModalOpen, setModalOpen] = useState(false)
138+
const [error, setError] = useState<Error>()
137139
const [buttonStatus, setButtonStatus] = useState(ButtonStatus.LOADING)
138140
const [multiSendCallData, setMultiSendCallData] = useState(EMPTY_DATA)
139141
const isSameAddressAsSafe = useSelector(sameAddressAsSafeSelector)
@@ -153,15 +155,21 @@ export const BatchExecute = React.memo((): ReactElement | null => {
153155
const transactionsWithDetails = await getTxDetails(batchableTransactions, dispatch)
154156
setTxsWithDetails(transactionsWithDetails)
155157

156-
const batchExecuteData = await getBatchExecuteData(
157-
dispatch,
158-
transactionsWithDetails,
159-
safeInstance,
160-
safeAddress,
161-
account,
162-
)
163-
setButtonStatus(isSameAddressAsSafe ? ButtonStatus.DISABLED : ButtonStatus.READY)
164-
setMultiSendCallData(batchExecuteData)
158+
try {
159+
const batchExecuteData = await getBatchExecuteData(
160+
dispatch,
161+
transactionsWithDetails,
162+
safeAddress,
163+
currentVersion,
164+
account,
165+
)
166+
setButtonStatus(isSameAddressAsSafe ? ButtonStatus.DISABLED : ButtonStatus.READY)
167+
setMultiSendCallData(batchExecuteData)
168+
} catch (err) {
169+
logError(Errors._619, err.message)
170+
setError(err)
171+
setButtonStatus(ButtonStatus.DISABLED)
172+
}
165173
}
166174

167175
const handleBatchExecute = async () => {
@@ -226,7 +234,11 @@ export const BatchExecute = React.memo((): ReactElement | null => {
226234
Be aware that if any of the included transactions revert, none of them will be executed. This will result in
227235
the loss of the allocated transaction fees.
228236
</Paragraph>
229-
<TransactionFailText estimationStatus={EstimationStatus.SUCCESS} isExecution isCreation={false} />
237+
<TransactionFailText
238+
estimationStatus={error ? EstimationStatus.FAILURE : EstimationStatus.SUCCESS}
239+
isExecution
240+
isCreation={false}
241+
/>
230242
</ModalContent>
231243
<Modal.Footer withoutBorder>
232244
<Modal.Footer.Buttons

0 commit comments

Comments
 (0)