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/confirm-page-container/confirm-page-container-content/confirm-page-container-content.component.js

265 lines
7.6 KiB
JavaScript
Raw Normal View History

import React, { Component } from 'react';
import PropTypes from 'prop-types';
import classnames from 'classnames';
import { Tabs, Tab } from '../../../ui/tabs';
import Button from '../../../ui/button';
Increase friction to bypass estimated revert (#12576) * If a transaction would revert/fail, 1. hide the gas estimate info. 2. Disable the confirm button. 3. All user to enable the confirm button anyways. 4. Do not show the default Transaction error message Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Always return a value for hasSimulationError Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Use primary button of action message Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Remove hasSimulationError from getErrorKey Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Lint fixes. Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Move confirm anyways logic to base component. Change message Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Disable edit if there's simulation error Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * hide confirm anyways button once clicked. Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Move Actionable Primary Action to flex-end Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Fix unit tests Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Fix nested ternary lint issues Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * add !confirmAnyways to conditions to show GasDetails. Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * ConfirmAnyways should be read from state Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Rename tryAnywayOption Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Lint fixes Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Remove await tick Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Lint issue fix Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Lint fixes after rebase Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * description should show that it's content being tested. Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * If a transaction would revert/fail, 1. hide the gas estimate info. 2. Disable the confirm button. 3. All user to enable the confirm button anyways. 4. Do not show the default Transaction error message Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Always return a value for hasSimulationError Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Use primary button of action message Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Remove hasSimulationError from getErrorKey Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Lint fixes. Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Move confirm anyways logic to base component. Change message Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Disable edit if there's simulation error Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * hide confirm anyways button once clicked. Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Move Actionable Primary Action to flex-end Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Fix unit tests Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Fix nested ternary lint issues Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * add !confirmAnyways to conditions to show GasDetails. Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * ConfirmAnyways should be read from state Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Rename tryAnywayOption Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Lint fixes Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Remove await tick Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Lint issue fix Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Lint fixes after rebase Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * description should show that it's content being tested. Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Move simulation fails message inline with gas details component (#12705) * Move simulation fails message inline with gas details component * Remove old unit tests Co-authored-by: Dan Miller <danjm.com@gmail.com> * lint fix * use an XOR operation. Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * The changes in this file are no longer needed because we hide the edit button now Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> Co-authored-by: Dan Miller <danjm.com@gmail.com>
2021-11-22 13:13:30 +01:00
import ActionableMessage from '../../../ui/actionable-message/actionable-message';
import { PageContainerFooter } from '../../../ui/page-container';
import ErrorMessage from '../../../ui/error-message';
import { INSUFFICIENT_FUNDS_ERROR_KEY } from '../../../../helpers/constants/error-keys';
import Typography from '../../../ui/typography';
import { TYPOGRAPHY } from '../../../../helpers/constants/design-system';
import DepositPopover from '../../deposit-popover/deposit-popover';
import { ConfirmPageContainerSummary, ConfirmPageContainerWarning } from '.';
export default class ConfirmPageContainerContent extends Component {
2021-06-13 00:25:24 +02:00
static contextTypes = {
t: PropTypes.func.isRequired,
};
static propTypes = {
action: PropTypes.string,
dataComponent: PropTypes.node,
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
dataHexComponent: PropTypes.node,
2018-07-06 20:58:41 +02:00
detailsComponent: PropTypes.node,
///: BEGIN:ONLY_INCLUDE_IN(flask)
insightComponent: PropTypes.node,
///: END:ONLY_INCLUDE_IN
2018-07-06 20:58:41 +02:00
errorKey: PropTypes.string,
errorMessage: PropTypes.string,
hideSubtitle: PropTypes.bool,
tokenAddress: PropTypes.string,
nonce: PropTypes.string,
subtitleComponent: PropTypes.node,
2018-07-06 20:58:41 +02:00
title: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
image: PropTypes.string,
titleComponent: PropTypes.node,
warning: PropTypes.string,
origin: PropTypes.string.isRequired,
ethGasPriceWarning: PropTypes.string,
// Footer
onCancelAll: PropTypes.func,
onCancel: PropTypes.func,
cancelText: PropTypes.string,
onSubmit: PropTypes.func,
submitText: PropTypes.string,
disabled: PropTypes.bool,
unapprovedTxCount: PropTypes.number,
rejectNText: PropTypes.string,
hideTitle: PropTypes.bool,
supportsEIP1559: PropTypes.bool,
hasTopBorder: PropTypes.bool,
nativeCurrency: PropTypes.string,
networkName: PropTypes.string,
toAddress: PropTypes.string,
transactionType: PropTypes.string,
isBuyableChain: PropTypes.bool,
};
state = {
setShowDepositPopover: false,
};
2020-11-03 00:41:28 +01:00
renderContent() {
const { detailsComponent, dataComponent } = this.props;
///: BEGIN:ONLY_INCLUDE_IN(flask)
const { insightComponent } = this.props;
if (insightComponent && (detailsComponent || dataComponent)) {
return this.renderTabs();
}
///: END:ONLY_INCLUDE_IN
if (detailsComponent && dataComponent) {
return this.renderTabs();
}
return (
detailsComponent ||
///: BEGIN:ONLY_INCLUDE_IN(flask)
insightComponent ||
///: END:ONLY_INCLUDE_IN
dataComponent
);
}
2020-11-03 00:41:28 +01:00
renderTabs() {
2021-06-13 00:25:24 +02:00
const { t } = this.context;
const {
detailsComponent,
dataComponent,
dataHexComponent,
///: BEGIN:ONLY_INCLUDE_IN(flask)
insightComponent,
///: END:ONLY_INCLUDE_IN
} = this.props;
return (
<Tabs>
2021-06-13 00:25:24 +02:00
<Tab
className="confirm-page-container-content__tab"
name={t('details')}
>
2020-11-03 00:41:28 +01:00
{detailsComponent}
</Tab>
{dataComponent && (
<Tab className="confirm-page-container-content__tab" name={t('data')}>
{dataComponent}
</Tab>
)}
{dataHexComponent && (
<Tab
className="confirm-page-container-content__tab"
name={t('dataHex')}
>
{dataHexComponent}
</Tab>
)}
{
///: BEGIN:ONLY_INCLUDE_IN(flask)
insightComponent
///: END:ONLY_INCLUDE_IN
}
</Tabs>
);
}
2020-11-03 00:41:28 +01:00
render() {
const {
action,
2018-07-06 20:58:41 +02:00
errorKey,
errorMessage,
title,
image,
titleComponent,
subtitleComponent,
hideSubtitle,
tokenAddress,
nonce,
detailsComponent,
dataComponent,
warning,
onCancelAll,
onCancel,
cancelText,
onSubmit,
submitText,
disabled,
unapprovedTxCount,
rejectNText,
origin,
ethGasPriceWarning,
hideTitle,
supportsEIP1559,
hasTopBorder,
nativeCurrency,
networkName,
toAddress,
transactionType,
isBuyableChain,
} = this.props;
const { t } = this.context;
const showInsuffienctFundsError =
supportsEIP1559 &&
(errorKey || errorMessage) &&
errorKey === INSUFFICIENT_FUNDS_ERROR_KEY;
Increase friction to bypass estimated revert (#12576) * If a transaction would revert/fail, 1. hide the gas estimate info. 2. Disable the confirm button. 3. All user to enable the confirm button anyways. 4. Do not show the default Transaction error message Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Always return a value for hasSimulationError Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Use primary button of action message Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Remove hasSimulationError from getErrorKey Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Lint fixes. Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Move confirm anyways logic to base component. Change message Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Disable edit if there's simulation error Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * hide confirm anyways button once clicked. Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Move Actionable Primary Action to flex-end Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Fix unit tests Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Fix nested ternary lint issues Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * add !confirmAnyways to conditions to show GasDetails. Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * ConfirmAnyways should be read from state Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Rename tryAnywayOption Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Lint fixes Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Remove await tick Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Lint issue fix Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Lint fixes after rebase Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * description should show that it's content being tested. Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * If a transaction would revert/fail, 1. hide the gas estimate info. 2. Disable the confirm button. 3. All user to enable the confirm button anyways. 4. Do not show the default Transaction error message Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Always return a value for hasSimulationError Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Use primary button of action message Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Remove hasSimulationError from getErrorKey Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Lint fixes. Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Move confirm anyways logic to base component. Change message Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Disable edit if there's simulation error Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * hide confirm anyways button once clicked. Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Move Actionable Primary Action to flex-end Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Fix unit tests Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Fix nested ternary lint issues Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * add !confirmAnyways to conditions to show GasDetails. Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * ConfirmAnyways should be read from state Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Rename tryAnywayOption Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Lint fixes Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Remove await tick Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Lint issue fix Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Lint fixes after rebase Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * description should show that it's content being tested. Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Move simulation fails message inline with gas details component (#12705) * Move simulation fails message inline with gas details component * Remove old unit tests Co-authored-by: Dan Miller <danjm.com@gmail.com> * lint fix * use an XOR operation. Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * The changes in this file are no longer needed because we hide the edit button now Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> Co-authored-by: Dan Miller <danjm.com@gmail.com>
2021-11-22 13:13:30 +01:00
const { setShowDepositPopover } = this.state;
return (
<div
className={classnames('confirm-page-container-content', {
'confirm-page-container-content--with-top-border': hasTopBorder,
})}
>
{warning ? <ConfirmPageContainerWarning warning={warning} /> : null}
{ethGasPriceWarning && (
<ConfirmPageContainerWarning warning={ethGasPriceWarning} />
)}
<ConfirmPageContainerSummary
className={classnames({
'confirm-page-container-summary--border':
!detailsComponent || !dataComponent,
})}
action={action}
title={title}
image={image}
titleComponent={titleComponent}
subtitleComponent={subtitleComponent}
hideSubtitle={hideSubtitle}
tokenAddress={tokenAddress}
nonce={nonce}
origin={origin}
hideTitle={hideTitle}
toAddress={toAddress}
transactionType={transactionType}
/>
2020-11-03 00:41:28 +01:00
{this.renderContent()}
{!supportsEIP1559 && (errorKey || errorMessage) && (
<div className="confirm-page-container-content__error-container">
<ErrorMessage errorMessage={errorMessage} errorKey={errorKey} />
</div>
)}
{showInsuffienctFundsError && (
<div className="confirm-page-container-content__error-container">
<ActionableMessage
className="actionable-message--warning"
message={
isBuyableChain ? (
<Typography variant={TYPOGRAPHY.H7} align="left">
{t('insufficientCurrencyBuyOrDeposit', [
nativeCurrency,
networkName,
<Button
type="inline"
className="confirm-page-container-content__link"
onClick={() =>
this.setState({ setShowDepositPopover: true })
}
key={`${nativeCurrency}-buy-button`}
>
{t('buyAsset', [nativeCurrency])}
</Button>,
])}
</Typography>
) : (
<Typography variant={TYPOGRAPHY.H7} align="left">
{t('insufficientCurrencyDeposit', [
nativeCurrency,
networkName,
])}
</Typography>
)
}
useIcon
iconFillColor="var(--color-error-default)"
type="danger"
/>
</div>
)}
{setShowDepositPopover && (
<DepositPopover
onClose={() => this.setState({ setShowDepositPopover: false })}
/>
)}
<PageContainerFooter
onCancel={onCancel}
cancelText={cancelText}
onSubmit={onSubmit}
submitText={submitText}
disabled={disabled}
>
{unapprovedTxCount > 1 ? (
<a onClick={onCancelAll}>{rejectNText}</a>
) : null}
</PageContainerFooter>
</div>
);
}
}