From 73ac1d818b2012acd1046e9e783ecf41f5550673 Mon Sep 17 00:00:00 2001 From: Jeff Cruikshank Date: Tue, 19 Dec 2023 14:04:01 -0800 Subject: [PATCH] Special handling for MEMPOOL_CONFLICT txn status --- .../core/src/utils/getTransactionResult.ts | 11 +++++- .../WalletSendTransactionResultDialog.tsx | 38 ++++++++++++------- 2 files changed, 33 insertions(+), 16 deletions(-) diff --git a/packages/core/src/utils/getTransactionResult.ts b/packages/core/src/utils/getTransactionResult.ts index 82d605b230..d453a5715a 100644 --- a/packages/core/src/utils/getTransactionResult.ts +++ b/packages/core/src/utils/getTransactionResult.ts @@ -28,9 +28,16 @@ export default function getTransactionResult(transaction): { // At least one node has accepted our transaction as pending const pendingNodeResponse = transaction.sentTo.find((item) => item[1] === mempoolInclusionStatus.PENDING); - if (pendingNodeResponse) { + + // Note: A refactoring of this is probably warranted, especially if additional mempool statuses need special handling + // + // For now, MEMPOOL_CONFLICT will be treated as a failure, but we'll display an error explaining that the full node + // will retry to include the txn if the conflicts are resolved. + const ignoredMempoolStatuses = ['MEMPOOL_CONFLICT']; + + if (pendingNodeResponse && !ignoredMempoolStatuses.includes(pendingNodeResponse[2])) { return { - message: t`Transaction has sent to a full node and is pending inclusion into the mempool. ${pendingNodeResponse[2]}`, + message: t`Transaction has been sent to a full node and is pending inclusion into the mempool. ${pendingNodeResponse[2]}`, success: true, }; } diff --git a/packages/wallets/src/components/WalletSendTransactionResultDialog.tsx b/packages/wallets/src/components/WalletSendTransactionResultDialog.tsx index b687bcda9c..3494febeaf 100644 --- a/packages/wallets/src/components/WalletSendTransactionResultDialog.tsx +++ b/packages/wallets/src/components/WalletSendTransactionResultDialog.tsx @@ -1,5 +1,5 @@ import { AlertDialog, Flex } from '@chia-network/core'; -import { Trans } from '@lingui/macro'; +import { Trans, t } from '@lingui/macro'; import React from 'react'; type WalletSendTransactionResultDialogProps = { @@ -12,6 +12,10 @@ function WalletSendTransactionResultDialogTitle(success: boolean, message: strin return Success; } + if (message === 'MEMPOOL_CONFLICT') { + return Mempool Conflict; + } + if (message === 'INVALID_FEE_TOO_CLOSE_TO_ZERO' || message === 'INVALID_FEE_LOW_FEE') { return Mempool Full; } @@ -27,22 +31,28 @@ function WalletSendTransactionResultDialogContent( return message ?? Transaction has successfully been sent to a full node and included in the mempool.; } + let message1; + let message2; + + if (message === 'MEMPOOL_CONFLICT') { + message1 = t`The transaction is pending inclusion in the mempool because it conflicts with one or more other transactions + already in the mempool. The transaction will be retried periodically, and may be included in the mempool if + the conflicting transactions are removed.`; + } + if (message === 'INVALID_FEE_TOO_CLOSE_TO_ZERO' || message === 'INVALID_FEE_LOW_FEE') { + message1 = t`The transaction could not be immediately included in the mempool because the specified fee is too low. The + transaction will be retried periodically, and may be included in the mempool once fees are lower, or if + space becomes available.`; + message2 = t`If you would like to speed up the transaction, please delete unconfirmed transactions and retry with a + higher fee.`; + } + + if (message1) { return ( - - - The transaction could not be immediately included in the mempool because the specified fee is too low. The - transaction will be retried periodically, and may be included in the mempool once fees are lower, or if - space becomes available. - - - - - If you would like to speed up the transaction, please delete unconfirmed transactions and retry with a - higher fee. - - + {message1} + {message2 && {message2}} ); }