mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Fix use transaction time remaining (#9630)
* Only format timeRemaining if in useTransactionTimeRemaining if it is truthy * Only setTimeRemaining in useTransactionTimeRemaining if submitted time is a number * Use isSubmitted as a check, instead of isPending and submittedTime, before calculating timeRemaining
This commit is contained in:
parent
7925a767b8
commit
b1adc0d1e8
@ -50,9 +50,10 @@ export default function TransactionListItem ({ transactionGroup, isEarliestNonce
|
|||||||
displayedStatusKey,
|
displayedStatusKey,
|
||||||
isPending,
|
isPending,
|
||||||
senderAddress,
|
senderAddress,
|
||||||
|
isSubmitted,
|
||||||
} = useTransactionDisplayData(transactionGroup)
|
} = useTransactionDisplayData(transactionGroup)
|
||||||
|
|
||||||
const timeRemaining = useTransactionTimeRemaining(isPending, isEarliestNonce, submittedTime, gasPrice)
|
const timeRemaining = useTransactionTimeRemaining(isSubmitted, isEarliestNonce, submittedTime, gasPrice)
|
||||||
|
|
||||||
const isSignatureReq = category === TRANSACTION_CATEGORY_SIGNATURE_REQUEST
|
const isSignatureReq = category === TRANSACTION_CATEGORY_SIGNATURE_REQUEST
|
||||||
const isApproval = category === TRANSACTION_CATEGORY_APPROVAL
|
const isApproval = category === TRANSACTION_CATEGORY_APPROVAL
|
||||||
|
@ -27,6 +27,7 @@ const expectedResults = [
|
|||||||
secondaryCurrency: '-1 ETH',
|
secondaryCurrency: '-1 ETH',
|
||||||
isPending: false,
|
isPending: false,
|
||||||
displayedStatusKey: 'confirmed',
|
displayedStatusKey: 'confirmed',
|
||||||
|
isSubmitted: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: 'Send ETH',
|
title: 'Send ETH',
|
||||||
|
@ -23,6 +23,7 @@ import {
|
|||||||
TOKEN_CATEGORY_HASH,
|
TOKEN_CATEGORY_HASH,
|
||||||
SWAP,
|
SWAP,
|
||||||
SWAP_APPROVAL,
|
SWAP_APPROVAL,
|
||||||
|
SUBMITTED_STATUS,
|
||||||
} from '../helpers/constants/transactions'
|
} from '../helpers/constants/transactions'
|
||||||
import { getTokens } from '../ducks/metamask/metamask'
|
import { getTokens } from '../ducks/metamask/metamask'
|
||||||
import { useI18nContext } from './useI18nContext'
|
import { useI18nContext } from './useI18nContext'
|
||||||
@ -74,6 +75,7 @@ export function useTransactionDisplayData (transactionGroup) {
|
|||||||
|
|
||||||
const displayedStatusKey = getStatusKey(primaryTransaction)
|
const displayedStatusKey = getStatusKey(primaryTransaction)
|
||||||
const isPending = displayedStatusKey in PENDING_STATUS_HASH
|
const isPending = displayedStatusKey in PENDING_STATUS_HASH
|
||||||
|
const isSubmitted = displayedStatusKey === SUBMITTED_STATUS
|
||||||
|
|
||||||
const primaryValue = primaryTransaction.txParams?.value
|
const primaryValue = primaryTransaction.txParams?.value
|
||||||
let prefix = '-'
|
let prefix = '-'
|
||||||
@ -213,5 +215,6 @@ export function useTransactionDisplayData (transactionGroup) {
|
|||||||
) ? undefined : secondaryCurrency,
|
) ? undefined : secondaryCurrency,
|
||||||
displayedStatusKey,
|
displayedStatusKey,
|
||||||
isPending,
|
isPending,
|
||||||
|
isSubmitted,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,7 @@ function calcTransactionTimeRemaining (initialTimeEstimate, submittedTime) {
|
|||||||
* returns a string representing the number of minutes predicted for the transaction to be
|
* returns a string representing the number of minutes predicted for the transaction to be
|
||||||
* completed. Only returns this prediction if the transaction is the earliest pending
|
* completed. Only returns this prediction if the transaction is the earliest pending
|
||||||
* transaction, and the feature flag for showing timing is enabled.
|
* transaction, and the feature flag for showing timing is enabled.
|
||||||
* @param {bool} isPending - is the transaction currently pending
|
* @param {bool} isSubmitted - is the transaction currently in the 'submitted' state
|
||||||
* @param {bool} isEarliestNonce - is this transaction the earliest nonce in list
|
* @param {bool} isEarliestNonce - is this transaction the earliest nonce in list
|
||||||
* @param {number} submittedTime - the timestamp for when the transaction was submitted
|
* @param {number} submittedTime - the timestamp for when the transaction was submitted
|
||||||
* @param {number} currentGasPrice - gas price to use for calculation of time
|
* @param {number} currentGasPrice - gas price to use for calculation of time
|
||||||
@ -34,7 +34,7 @@ function calcTransactionTimeRemaining (initialTimeEstimate, submittedTime) {
|
|||||||
* @returns {string | undefined} i18n formatted string if applicable
|
* @returns {string | undefined} i18n formatted string if applicable
|
||||||
*/
|
*/
|
||||||
export function useTransactionTimeRemaining (
|
export function useTransactionTimeRemaining (
|
||||||
isPending,
|
isSubmitted,
|
||||||
isEarliestNonce,
|
isEarliestNonce,
|
||||||
submittedTime,
|
submittedTime,
|
||||||
currentGasPrice,
|
currentGasPrice,
|
||||||
@ -73,7 +73,7 @@ export function useTransactionTimeRemaining (
|
|||||||
if (
|
if (
|
||||||
(isMainNet &&
|
(isMainNet &&
|
||||||
(transactionTimeFeatureActive || forceAllow)) &&
|
(transactionTimeFeatureActive || forceAllow)) &&
|
||||||
isPending &&
|
isSubmitted &&
|
||||||
isEarliestNonce &&
|
isEarliestNonce &&
|
||||||
!isNaN(initialTimeEstimate)
|
!isNaN(initialTimeEstimate)
|
||||||
) {
|
) {
|
||||||
@ -93,10 +93,10 @@ export function useTransactionTimeRemaining (
|
|||||||
isMainNet,
|
isMainNet,
|
||||||
transactionTimeFeatureActive,
|
transactionTimeFeatureActive,
|
||||||
isEarliestNonce,
|
isEarliestNonce,
|
||||||
isPending,
|
|
||||||
submittedTime,
|
submittedTime,
|
||||||
initialTimeEstimate,
|
initialTimeEstimate,
|
||||||
forceAllow,
|
forceAllow,
|
||||||
|
isSubmitted,
|
||||||
])
|
])
|
||||||
|
|
||||||
// there are numerous checks to determine if time should be displayed.
|
// there are numerous checks to determine if time should be displayed.
|
||||||
@ -104,8 +104,10 @@ export function useTransactionTimeRemaining (
|
|||||||
// User is currently not on the mainnet
|
// User is currently not on the mainnet
|
||||||
// User does not have the transactionTime feature flag enabled
|
// User does not have the transactionTime feature flag enabled
|
||||||
// The transaction is not pending, or isn't the earliest nonce
|
// The transaction is not pending, or isn't the earliest nonce
|
||||||
const usedFormat = dontFormat
|
if (timeRemaining && dontFormat) {
|
||||||
? timeRemaining
|
return timeRemaining
|
||||||
: rtf.format(timeRemaining, 'minute')
|
} else if (timeRemaining) {
|
||||||
return timeRemaining ? usedFormat : undefined
|
return rtf.format(timeRemaining, 'minute')
|
||||||
|
}
|
||||||
|
return undefined
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,7 @@ import { useTransactionTimeRemaining } from '../../../hooks/useTransactionTimeRe
|
|||||||
import { usePrevious } from '../../../hooks/usePrevious'
|
import { usePrevious } from '../../../hooks/usePrevious'
|
||||||
import Mascot from '../../../components/ui/mascot'
|
import Mascot from '../../../components/ui/mascot'
|
||||||
import PulseLoader from '../../../components/ui/pulse-loader'
|
import PulseLoader from '../../../components/ui/pulse-loader'
|
||||||
import { getBlockExplorerUrlForTx } from '../../../helpers/utils/transactions.util'
|
import { getBlockExplorerUrlForTx, getStatusKey } from '../../../helpers/utils/transactions.util'
|
||||||
import CountdownTimer from '../countdown-timer'
|
import CountdownTimer from '../countdown-timer'
|
||||||
import {
|
import {
|
||||||
QUOTES_EXPIRED_ERROR,
|
QUOTES_EXPIRED_ERROR,
|
||||||
@ -28,6 +28,7 @@ import {
|
|||||||
QUOTES_NOT_AVAILABLE_ERROR,
|
QUOTES_NOT_AVAILABLE_ERROR,
|
||||||
OFFLINE_FOR_MAINTENANCE,
|
OFFLINE_FOR_MAINTENANCE,
|
||||||
} from '../../../helpers/constants/swaps'
|
} from '../../../helpers/constants/swaps'
|
||||||
|
import { SUBMITTED_STATUS } from '../../../helpers/constants/transactions'
|
||||||
import { ASSET_ROUTE, DEFAULT_ROUTE } from '../../../helpers/constants/routes'
|
import { ASSET_ROUTE, DEFAULT_ROUTE } from '../../../helpers/constants/routes'
|
||||||
|
|
||||||
import { getRenderableGasFeesForQuote } from '../swaps.util'
|
import { getRenderableGasFeesForQuote } from '../swaps.util'
|
||||||
@ -96,7 +97,14 @@ export default function AwaitingSwap ({
|
|||||||
rpcPrefs,
|
rpcPrefs,
|
||||||
)
|
)
|
||||||
|
|
||||||
const timeRemaining = useTransactionTimeRemaining(true, true, tradeTxData?.submittedTime, usedGasPrice, true, true)
|
const timeRemaining = useTransactionTimeRemaining(
|
||||||
|
getStatusKey(tradeTxData) === SUBMITTED_STATUS,
|
||||||
|
true,
|
||||||
|
tradeTxData?.submittedTime,
|
||||||
|
usedGasPrice,
|
||||||
|
true,
|
||||||
|
true,
|
||||||
|
)
|
||||||
const previousTimeRemaining = usePrevious(timeRemaining)
|
const previousTimeRemaining = usePrevious(timeRemaining)
|
||||||
const timeRemainingIsNumber = typeof timeRemaining === 'number' && !isNaN(timeRemaining)
|
const timeRemainingIsNumber = typeof timeRemaining === 'number' && !isNaN(timeRemaining)
|
||||||
const previousTimeRemainingIsNumber = typeof previousTimeRemaining === 'number' && !isNaN(previousTimeRemaining)
|
const previousTimeRemainingIsNumber = typeof previousTimeRemaining === 'number' && !isNaN(previousTimeRemaining)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user