1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-27 04:46:10 +01:00
metamask-extension/ui/components/app/transaction-status-label/transaction-status-label.js

141 lines
4.3 KiB
JavaScript
Raw Normal View History

import React from 'react';
import PropTypes from 'prop-types';
import classnames from 'classnames';
///: BEGIN:ONLY_INCLUDE_IN(build-mmi)
import { useSelector } from 'react-redux';
///: END:ONLY_INCLUDE_IN
import Tooltip from '../../ui/tooltip';
import { useI18nContext } from '../../../hooks/useI18nContext';
import {
TransactionGroupStatus,
TransactionStatus,
} from '../../../../shared/constants/transaction';
///: BEGIN:ONLY_INCLUDE_IN(build-mmi)
import { getTransactionStatusMap } from '../../../selectors/institutional/selectors';
import { getCurrentKeyring } from '../../../selectors';
///: END:ONLY_INCLUDE_IN
const QUEUED_PSEUDO_STATUS = 'queued';
///: BEGIN:ONLY_INCLUDE_IN(build-mmi)
const CUSTODIAN_PSEUDO_STATUS = 'inCustody';
///: END:ONLY_INCLUDE_IN
/**
* A note about status logic for this component:
* Approved, Signed and Submitted statuses are all treated, effectively
* as pending. Transactions are only approved or signed for less than a
* second, usually, and ultimately should be rendered in the UI no
* differently than a pending transaction.
*
* Confirmed transactions are not especially highlighted except that their
* status label will be the date the transaction was finalized.
*/
const pendingStatusHash = {
[TransactionStatus.submitted]: TransactionGroupStatus.pending,
[TransactionStatus.approved]: TransactionGroupStatus.pending,
[TransactionStatus.signed]: TransactionGroupStatus.pending,
};
2018-07-30 20:53:54 +02:00
const statusToClassNameHash = {
[TransactionStatus.unapproved]: 'transaction-status-label--unapproved',
[TransactionStatus.rejected]: 'transaction-status-label--rejected',
[TransactionStatus.failed]: 'transaction-status-label--failed',
[TransactionStatus.dropped]: 'transaction-status-label--dropped',
[TransactionGroupStatus.cancelled]: 'transaction-status-label--cancelled',
[QUEUED_PSEUDO_STATUS]: 'transaction-status-label--queued',
[TransactionGroupStatus.pending]: 'transaction-status-label--pending',
///: BEGIN:ONLY_INCLUDE_IN(build-mmi)
[CUSTODIAN_PSEUDO_STATUS]: 'transaction-status--custodian',
///: END:ONLY_INCLUDE_IN
};
2018-07-30 20:53:54 +02:00
export default function TransactionStatusLabel({
2020-11-03 00:41:28 +01:00
status,
date,
error,
isEarliestNonce,
className,
Feature: Transaction Insights (#12881) * integration for tx decoding confirmation and history view * upgrading @truffle/decoder to latest release 5.1.0 * Update acorn and colors patches * feat: remove redundant styling * feat: basic integration for nickname components * feat: wiring functionality of adding new nickname * feat: wire functionality of showing nickname modal * feat: link the nickname popover with add/update popover * feat: moving forward with address nicknames integration * feat: fixing a bug related to passing chainId in addressBook * feat: populating memo prop in addressbook entry * feat: add explorer link * feat: bug fixing update nickname component * feat: fix proptypes * feat: adding tooltip for copying nickname address * featL fix styling for tx-details page * feat: optimize code for error handling * feat: limiting transaction decoding to tx with data * feat: remove tree UI component * feat: adding request to check for tx decoding supported networks * feat: showing data hex component * feat: fix react warnings * feat: remove extra margin in tx decoding * Remove unused package @truffle/source-map-utils * Ensure messages get translated * feat: link tx-decoding addresses with nicknames * Omit value for boolean attributes * Fix props reading in CopyRawData * fix: fixing issue with transaltion * Fix lint errors in TransactionDecoding - Remove unused import - Reorder imports - Address conflict between caught `error` and error state flag by renaming state flag to `hasError` - Fix requestUrl identifier casing and use of template string - Ensure `useEffect` gets passed the deps it needs - Add scope braces around case statement where it's needed - Omit literal `true` for boolean jsx attribute - Refactor nested ternary as `if` statements * fix: revert fetchWithCache modifications * Fix linting for TransactionListItemDetails - Remove unused import - Fix import spacing - Remove unused prop dereference - Fix string interpolation for translated From/To * Moving to popover pattern * fix: sass color variable * Omit value for boolean attribute * Remove changes from modal.js * fix: refactor nickname popovers * Ensure const gets declared before it's used * Fix linting for ConfirmTransactionBase - Remove unused prop chainId - Stop destructuring an unused field * fix: refactor usage of nicknames popovers in send-content-container * fix: remove extra prop updateAccountNicknameModal * fix: refactor code for address.component * fix: remove extra tooltip * Ensure NicknamePopovers always returns component * Fix linting for NicknamePopover component - Fix useCallback deps - Switch ternary to logical-or * Fix linting for SenderToRecipient ... by fixing import order * Remove unused addressCopied state * Delete empty file * fix: remove sender-to-recipient.container * fix: refactor usage of nickname popovers in confirm-page-container * fix: bug related to state variable * Stylelint fix * Lint fix * Change "Total Amount" to "Total" * Lint fix locales * Update address-book.spec.js * e2e test update * Update e2e tests * Fix issue where absence of function params in data hex tab would result in rendering a string * Fix border radius, and width and height in small notification windows, of the update-nickname-popover * Remove fake await * Clean up * Clean up Co-authored-by: Alaa Hadad <alaahd@Alaas-MacBook-M1-Pro-14-inch.local> Co-authored-by: Dan Miller <danjm.com@gmail.com> Co-authored-by: g. nicholas d'andrea <gnidan@trufflesuite.com>
2021-12-01 18:22:08 +01:00
statusOnly,
///: BEGIN:ONLY_INCLUDE_IN(build-mmi)
custodyStatus,
custodyStatusDisplayText,
///: END:ONLY_INCLUDE_IN
2020-11-03 00:41:28 +01:00
}) {
const t = useI18nContext();
let tooltipText = error?.rpc?.message || error?.message;
let statusKey = status;
if (pendingStatusHash[status]) {
statusKey = isEarliestNonce
? TransactionGroupStatus.pending
: QUEUED_PSEUDO_STATUS;
}
let statusText = statusKey && t(statusKey);
///: BEGIN:ONLY_INCLUDE_IN(build-mmi)
statusText = custodyStatusDisplayText || t(statusKey);
///: END:ONLY_INCLUDE_IN
if (statusKey === TransactionStatus.confirmed && !statusOnly) {
statusText = date;
}
///: BEGIN:ONLY_INCLUDE_IN(build-mmi)
const transactionStatusMap = useSelector(getTransactionStatusMap);
const currentKeyring = useSelector(getCurrentKeyring);
const custodyType = currentKeyring?.type.split(' - ')[1]?.toLowerCase();
if (
custodyStatus &&
transactionStatusMap &&
transactionStatusMap[custodyType]
) {
const custodyStatusInfo = transactionStatusMap[custodyType][custodyStatus];
const shortText = custodyStatusInfo?.shortText || custodyStatus;
const longText = custodyStatusInfo?.longText;
if (error) {
tooltipText = error.message;
statusText =
custodyStatus === 'aborted'
? custodyStatusDisplayText
: t('snapResultError');
} else {
tooltipText = custodyStatusDisplayText || longText || custodyStatus;
statusText = custodyStatusDisplayText || shortText;
}
}
///: END:ONLY_INCLUDE_IN
return (
<Tooltip
position="top"
title={tooltipText}
2020-11-03 00:41:28 +01:00
wrapperClassName={classnames(
'transaction-status-label',
`transaction-status-label--${statusKey}`,
2020-11-03 00:41:28 +01:00
className,
statusToClassNameHash[statusKey],
)}
>
2020-11-03 00:41:28 +01:00
{statusText}
</Tooltip>
);
}
2018-07-30 20:53:54 +02:00
TransactionStatusLabel.propTypes = {
status: PropTypes.string,
className: PropTypes.string,
date: PropTypes.string,
error: PropTypes.object,
isEarliestNonce: PropTypes.bool,
Feature: Transaction Insights (#12881) * integration for tx decoding confirmation and history view * upgrading @truffle/decoder to latest release 5.1.0 * Update acorn and colors patches * feat: remove redundant styling * feat: basic integration for nickname components * feat: wiring functionality of adding new nickname * feat: wire functionality of showing nickname modal * feat: link the nickname popover with add/update popover * feat: moving forward with address nicknames integration * feat: fixing a bug related to passing chainId in addressBook * feat: populating memo prop in addressbook entry * feat: add explorer link * feat: bug fixing update nickname component * feat: fix proptypes * feat: adding tooltip for copying nickname address * featL fix styling for tx-details page * feat: optimize code for error handling * feat: limiting transaction decoding to tx with data * feat: remove tree UI component * feat: adding request to check for tx decoding supported networks * feat: showing data hex component * feat: fix react warnings * feat: remove extra margin in tx decoding * Remove unused package @truffle/source-map-utils * Ensure messages get translated * feat: link tx-decoding addresses with nicknames * Omit value for boolean attributes * Fix props reading in CopyRawData * fix: fixing issue with transaltion * Fix lint errors in TransactionDecoding - Remove unused import - Reorder imports - Address conflict between caught `error` and error state flag by renaming state flag to `hasError` - Fix requestUrl identifier casing and use of template string - Ensure `useEffect` gets passed the deps it needs - Add scope braces around case statement where it's needed - Omit literal `true` for boolean jsx attribute - Refactor nested ternary as `if` statements * fix: revert fetchWithCache modifications * Fix linting for TransactionListItemDetails - Remove unused import - Fix import spacing - Remove unused prop dereference - Fix string interpolation for translated From/To * Moving to popover pattern * fix: sass color variable * Omit value for boolean attribute * Remove changes from modal.js * fix: refactor nickname popovers * Ensure const gets declared before it's used * Fix linting for ConfirmTransactionBase - Remove unused prop chainId - Stop destructuring an unused field * fix: refactor usage of nicknames popovers in send-content-container * fix: remove extra prop updateAccountNicknameModal * fix: refactor code for address.component * fix: remove extra tooltip * Ensure NicknamePopovers always returns component * Fix linting for NicknamePopover component - Fix useCallback deps - Switch ternary to logical-or * Fix linting for SenderToRecipient ... by fixing import order * Remove unused addressCopied state * Delete empty file * fix: remove sender-to-recipient.container * fix: refactor usage of nickname popovers in confirm-page-container * fix: bug related to state variable * Stylelint fix * Lint fix * Change "Total Amount" to "Total" * Lint fix locales * Update address-book.spec.js * e2e test update * Update e2e tests * Fix issue where absence of function params in data hex tab would result in rendering a string * Fix border radius, and width and height in small notification windows, of the update-nickname-popover * Remove fake await * Clean up * Clean up Co-authored-by: Alaa Hadad <alaahd@Alaas-MacBook-M1-Pro-14-inch.local> Co-authored-by: Dan Miller <danjm.com@gmail.com> Co-authored-by: g. nicholas d'andrea <gnidan@trufflesuite.com>
2021-12-01 18:22:08 +01:00
statusOnly: PropTypes.bool,
///: BEGIN:ONLY_INCLUDE_IN(build-mmi)
custodyStatus: PropTypes.string,
custodyStatusDisplayText: PropTypes.string,
///: END:ONLY_INCLUDE_IN
};