From 0ffee10f19aae89f8276257252ccdbe233694a48 Mon Sep 17 00:00:00 2001 From: Mark Stacey Date: Mon, 9 Sep 2019 16:59:00 -0300 Subject: [PATCH] Prevent invalid inline speed-ups (#7085) Speeding up anything but the pending transaction with the lowest nonce is ineffectual, as the transaction with the lowest nonce blocks the others from completing first. The inline speed-up button in the transaction activity log has been removed for these invalid cases. The button will show up in the activity log for the pending transaction with the lowest nonce, but not for the others. Closes #6844 --- ...transaction-activity-log.component.test.js | 52 ++++++++++++++++++- .../transaction-activity-log.component.js | 9 ++-- ...transaction-list-item-details.component.js | 3 ++ .../transaction-list-item.component.js | 3 ++ .../transaction-list.component.js | 1 + 5 files changed, 63 insertions(+), 5 deletions(-) diff --git a/ui/app/components/app/transaction-activity-log/tests/transaction-activity-log.component.test.js b/ui/app/components/app/transaction-activity-log/tests/transaction-activity-log.component.test.js index a2946e53d..b070b76ea 100644 --- a/ui/app/components/app/transaction-activity-log/tests/transaction-activity-log.component.test.js +++ b/ui/app/components/app/transaction-activity-log/tests/transaction-activity-log.component.test.js @@ -51,7 +51,7 @@ describe('TransactionActivityLog Component', () => { assert.ok(wrapper.hasClass('test-class')) }) - it('should render inline retry and cancel buttons', () => { + it('should render inline retry and cancel buttons for earliest pending transaction', () => { const activities = [ { eventKey: 'transactionCreated', @@ -90,6 +90,7 @@ describe('TransactionActivityLog Component', () => { onCancel={() => {}} onRetry={() => {}} primaryTransactionStatus="pending" + isEarliestNonce={true} />, { context: { t: (str1, str2) => str2 ? str1 + str2 : str1 } } ) @@ -98,4 +99,53 @@ describe('TransactionActivityLog Component', () => { assert.ok(wrapper.hasClass('test-class')) assert.equal(wrapper.find('.transaction-activity-log__action-link').length, 2) }) + + it('should not render inline retry and cancel buttons for newer pending transactions', () => { + const activities = [ + { + eventKey: 'transactionCreated', + hash: '0xa', + id: 1, + timestamp: 1, + value: '0x1', + }, { + eventKey: 'transactionSubmitted', + hash: '0xa', + id: 1, + timestamp: 2, + value: '0x1', + }, { + eventKey: 'transactionResubmitted', + hash: '0x7d09d337fc6f5d6fe2dbf3a6988d69532deb0a82b665f9180b5a20db377eea87', + id: 2, + timestamp: 3, + value: '0x1', + }, { + eventKey: 'transactionCancelAttempted', + hash: '0x7d09d337fc6f5d6fe2dbf3a6988d69532deb0a82b665f9180b5a20db377eea87', + id: 3, + timestamp: 4, + value: '0x1', + }, + ] + + const wrapper = shallow( + {}} + onRetry={() => {}} + primaryTransactionStatus="pending" + isEarliestNonce={false} + />, + { context: { t: (str1, str2) => str2 ? str1 + str2 : str1 } } + ) + + assert.ok(wrapper.hasClass('transaction-activity-log')) + assert.ok(wrapper.hasClass('test-class')) + assert.equal(wrapper.find('.transaction-activity-log__action-link').length, 0) + }) }) diff --git a/ui/app/components/app/transaction-activity-log/transaction-activity-log.component.js b/ui/app/components/app/transaction-activity-log/transaction-activity-log.component.js index de4d29750..b37d5efa0 100644 --- a/ui/app/components/app/transaction-activity-log/transaction-activity-log.component.js +++ b/ui/app/components/app/transaction-activity-log/transaction-activity-log.component.js @@ -23,6 +23,7 @@ export default class TransactionActivityLog extends PureComponent { onCancel: PropTypes.func, onRetry: PropTypes.func, primaryTransaction: PropTypes.object, + isEarliestNonce: PropTypes.bool, } handleActivityClick = hash => { @@ -37,11 +38,11 @@ export default class TransactionActivityLog extends PureComponent { renderInlineRetry (index, activity) { const { t } = this.context - const { inlineRetryIndex, primaryTransaction = {}, onRetry } = this.props + const { inlineRetryIndex, primaryTransaction = {}, onRetry, isEarliestNonce } = this.props const { status } = primaryTransaction const { id } = activity - return status !== CONFIRMED_STATUS && index === inlineRetryIndex + return isEarliestNonce && status !== CONFIRMED_STATUS && index === inlineRetryIndex ? (
diff --git a/ui/app/components/app/transaction-list-item/transaction-list-item.component.js b/ui/app/components/app/transaction-list-item/transaction-list-item.component.js index f4f8d97b2..47c94acf2 100644 --- a/ui/app/components/app/transaction-list-item/transaction-list-item.component.js +++ b/ui/app/components/app/transaction-list-item/transaction-list-item.component.js @@ -25,6 +25,7 @@ export default class TransactionListItem extends PureComponent { showCancel: PropTypes.bool, hasEnoughCancelGas: PropTypes.bool, showRetry: PropTypes.bool, + isEarliestNonce: PropTypes.bool, showFiat: PropTypes.bool, token: PropTypes.object, tokenData: PropTypes.object, @@ -172,6 +173,7 @@ export default class TransactionListItem extends PureComponent { tokenData, transactionGroup, rpcPrefs, + isEarliestNonce, } = this.props const { txParams = {} } = transaction const { showTransactionDetails } = this.state @@ -224,6 +226,7 @@ export default class TransactionListItem extends PureComponent { transactionGroup={transactionGroup} onRetry={this.handleRetry} showRetry={showRetry} + isEarliestNonce={isEarliestNonce} onCancel={this.handleCancel} showCancel={showCancel} cancelDisabled={!hasEnoughCancelGas} diff --git a/ui/app/components/app/transaction-list/transaction-list.component.js b/ui/app/components/app/transaction-list/transaction-list.component.js index 157e7200b..00ae1c657 100644 --- a/ui/app/components/app/transaction-list/transaction-list.component.js +++ b/ui/app/components/app/transaction-list/transaction-list.component.js @@ -102,6 +102,7 @@ export default class TransactionList extends PureComponent { key={`${transactionGroup.nonce}:${index}`} showRetry={isPendingTx && this.shouldShowRetry(transactionGroup, index === 0)} showCancel={isPendingTx && this.shouldShowCancel(transactionGroup)} + isEarliestNonce={isPendingTx && index === 0} token={selectedToken} assetImages={assetImages} />