From 095e2eb3e5655dc5a343907d29b68e60e46e5c9b Mon Sep 17 00:00:00 2001 From: Jyoti Puri Date: Fri, 22 Nov 2024 05:58:31 +0530 Subject: [PATCH] feat: display native values returned from decoding api (#28374) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## **Description** display native values returned from decoding api ## **Related issues** Fixes: https://github.com/MetaMask/MetaMask-planning/issues/3617 ## **Manual testing steps** 1. Enable signature decoding api 2. On test dapp submit permit request 3. Check simulation section ## **Screenshots/Recordings** Screenshot 2024-11-08 at 10 21 09 AM For NFT collection: Screenshot 2024-11-11 at 6 33 54 PM ## **Pre-merge author checklist** - [X] I've followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Extension Coding Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md). - [X] I've completed the PR template to the best of my ability - [X] I’ve included tests if applicable - [X] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [X] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **Pre-merge reviewer checklist** - [ ] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [ ] I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots. --------- Co-authored-by: MetaMask Bot Co-authored-by: digiwand <20778143+digiwand@users.noreply.github.com> --- .../expandable-row.test.tsx.snap | 2 +- .../info/row/__snapshots__/row.test.tsx.snap | 4 +- .../__snapshots__/alert-row.test.tsx.snap | 2 +- ui/components/app/confirm/info/row/row.tsx | 2 +- .../info/__snapshots__/info.test.tsx.snap | 62 ++++----- .../__snapshots__/approve.test.tsx.snap | 30 ++--- .../approve-details.test.tsx.snap | 4 +- .../approve-static-simulation.test.tsx.snap | 4 +- .../__snapshots__/spending-cap.test.tsx.snap | 4 +- .../base-transaction-info.test.tsx.snap | 10 +- .../native-transfer.test.tsx.snap | 10 +- .../nft-token-transfer.test.tsx.snap | 10 +- .../__snapshots__/personal-sign.test.tsx.snap | 4 +- .../set-approval-for-all-info.test.tsx.snap | 10 +- ...al-for-all-static-simulation.test.tsx.snap | 6 +- ...al-for-all-static-simulation.test.tsx.snap | 4 +- .../advanced-details.test.tsx.snap | 8 +- .../edit-gas-fees-row.test.tsx.snap | 2 +- .../gas-fees-details.test.tsx.snap | 4 +- .../__snapshots__/gas-fees-row.test.tsx.snap | 2 +- .../gas-fees-section.test.tsx.snap | 4 +- .../transaction-data.test.tsx.snap | 96 +++++++------- .../transaction-details.test.tsx.snap | 4 +- .../token-details-section.test.tsx.snap | 4 +- .../token-transfer.test.tsx.snap | 10 +- .../__snapshots__/typed-sign-v1.test.tsx.snap | 6 +- .../__snapshots__/typed-sign.test.tsx.snap | 114 ++++++++--------- .../permit-simulation.test.tsx.snap | 16 +-- .../decoded-simulation.test.tsx.snap | 24 ++-- .../decoded-simulation/decoded-simulation.tsx | 33 +++-- .../default-simulation.test.tsx.snap | 14 ++- .../native-value-display.test.tsx | 20 +++ .../native-value-display.tsx | 118 ++++++++++++++++++ .../__snapshots__/value-display.test.tsx.snap | 3 +- .../value-display/value-display.tsx | 4 +- .../components/confirm/info/utils.ts | 18 +++ .../row/__snapshots__/dataTree.test.tsx.snap | 56 ++++----- .../typedSignDataV1.test.tsx.snap | 4 +- .../__snapshots__/typedSignData.test.tsx.snap | 30 ++--- .../__snapshots__/confirm.test.tsx.snap | 106 ++++++++-------- 40 files changed, 521 insertions(+), 347 deletions(-) create mode 100644 ui/pages/confirmations/components/confirm/info/typed-sign/permit-simulation/native-value-display/native-value-display.test.tsx create mode 100644 ui/pages/confirmations/components/confirm/info/typed-sign/permit-simulation/native-value-display/native-value-display.tsx diff --git a/ui/components/app/confirm/info/row/__snapshots__/expandable-row.test.tsx.snap b/ui/components/app/confirm/info/row/__snapshots__/expandable-row.test.tsx.snap index 3559558bc2cb..6db2cb117876 100644 --- a/ui/components/app/confirm/info/row/__snapshots__/expandable-row.test.tsx.snap +++ b/ui/components/app/confirm/info/row/__snapshots__/expandable-row.test.tsx.snap @@ -3,7 +3,7 @@ exports[`ConfirmInfoExpandableRow should match snapshot 1`] = `
@@ -707,7 +707,7 @@ exports[` renders component for approve request 1`] = ` class="mm-box mm-box--padding-left-2" >
@@ -799,7 +799,7 @@ exports[` renders component for approve request 1`] = `
diff --git a/ui/pages/confirmations/components/confirm/info/approve/approve-details/__snapshots__/approve-details.test.tsx.snap b/ui/pages/confirmations/components/confirm/info/approve/approve-details/__snapshots__/approve-details.test.tsx.snap index 17d04e237fb2..027fc5c8b074 100644 --- a/ui/pages/confirmations/components/confirm/info/approve/approve-details/__snapshots__/approve-details.test.tsx.snap +++ b/ui/pages/confirmations/components/confirm/info/approve/approve-details/__snapshots__/approve-details.test.tsx.snap @@ -11,7 +11,7 @@ exports[` renders component for approve details 1`] = ` data-testid="advanced-details-data-section" >
renders component for approve details for setApprova data-testid="advanced-details-data-section" >
renders component 1`] = ` data-testid="confirmation__simulation_section" >
renders component 1`] = `
renders component 1`] = ` data-testid="confirmation__approve-spending-cap-section" >
renders component 1`] = ` style="height: 1px; margin-left: -8px; margin-right: -8px;" />
diff --git a/ui/pages/confirmations/components/confirm/info/base-transaction-info/__snapshots__/base-transaction-info.test.tsx.snap b/ui/pages/confirmations/components/confirm/info/base-transaction-info/__snapshots__/base-transaction-info.test.tsx.snap index 47d28a0ba29d..d7054050f710 100644 --- a/ui/pages/confirmations/components/confirm/info/base-transaction-info/__snapshots__/base-transaction-info.test.tsx.snap +++ b/ui/pages/confirmations/components/confirm/info/base-transaction-info/__snapshots__/base-transaction-info.test.tsx.snap @@ -15,7 +15,7 @@ exports[` renders component for contract interaction requ class="mm-box mm-box--display-flex mm-box--flex-direction-row mm-box--justify-content-space-between mm-box--align-items-center" >
renders component for contract interaction requ data-testid="transaction-details-section" >
@@ -142,7 +142,7 @@ exports[` renders component for contract interaction requ
@@ -239,7 +239,7 @@ exports[` renders component for contract interaction requ data-testid="gas-fee-section" >
@@ -303,7 +303,7 @@ exports[` renders component for contract interaction requ
diff --git a/ui/pages/confirmations/components/confirm/info/native-transfer/__snapshots__/native-transfer.test.tsx.snap b/ui/pages/confirmations/components/confirm/info/native-transfer/__snapshots__/native-transfer.test.tsx.snap index 7a488072fd42..dcfe4ff35624 100644 --- a/ui/pages/confirmations/components/confirm/info/native-transfer/__snapshots__/native-transfer.test.tsx.snap +++ b/ui/pages/confirmations/components/confirm/info/native-transfer/__snapshots__/native-transfer.test.tsx.snap @@ -27,7 +27,7 @@ exports[`NativeTransferInfo renders correctly 1`] = ` class="mm-box mm-box--display-flex mm-box--flex-direction-row mm-box--justify-content-space-between mm-box--align-items-center" >
@@ -301,7 +301,7 @@ exports[`NativeTransferInfo renders correctly 1`] = `
diff --git a/ui/pages/confirmations/components/confirm/info/nft-token-transfer/__snapshots__/nft-token-transfer.test.tsx.snap b/ui/pages/confirmations/components/confirm/info/nft-token-transfer/__snapshots__/nft-token-transfer.test.tsx.snap index 3ff774c6770b..e835130ff73c 100644 --- a/ui/pages/confirmations/components/confirm/info/nft-token-transfer/__snapshots__/nft-token-transfer.test.tsx.snap +++ b/ui/pages/confirmations/components/confirm/info/nft-token-transfer/__snapshots__/nft-token-transfer.test.tsx.snap @@ -55,7 +55,7 @@ exports[`NFTTokenTransferInfo renders correctly 1`] = ` class="mm-box mm-box--display-flex mm-box--flex-direction-row mm-box--justify-content-space-between mm-box--align-items-center" >
@@ -329,7 +329,7 @@ exports[`NFTTokenTransferInfo renders correctly 1`] = `
diff --git a/ui/pages/confirmations/components/confirm/info/personal-sign/__snapshots__/personal-sign.test.tsx.snap b/ui/pages/confirmations/components/confirm/info/personal-sign/__snapshots__/personal-sign.test.tsx.snap index 92ac3628363e..8932bc3bb41d 100644 --- a/ui/pages/confirmations/components/confirm/info/personal-sign/__snapshots__/personal-sign.test.tsx.snap +++ b/ui/pages/confirmations/components/confirm/info/personal-sign/__snapshots__/personal-sign.test.tsx.snap @@ -6,7 +6,7 @@ exports[`PersonalSignInfo handle reverse string properly 1`] = ` class="mm-box mm-box--margin-bottom-4 mm-box--padding-2 mm-box--background-color-background-default mm-box--rounded-md" >
renders component for approve request 1`] = ` data-testid="confirmation__simulation_section" >
renders component for approve request 1`] = `
renders component for approve request 1`] = ` data-testid="confirmation__approve-details" >
@@ -160,7 +160,7 @@ exports[` renders component for approve request 1`] = ` data-testid="gas-fee-section" >
@@ -224,7 +224,7 @@ exports[` renders component for approve request 1`] = `
diff --git a/ui/pages/confirmations/components/confirm/info/set-approval-for-all-info/revoke-set-approval-for-all-static-simulation/__snapshots__/revoke-set-approval-for-all-static-simulation.test.tsx.snap b/ui/pages/confirmations/components/confirm/info/set-approval-for-all-info/revoke-set-approval-for-all-static-simulation/__snapshots__/revoke-set-approval-for-all-static-simulation.test.tsx.snap index 8c94061320fe..abe3dca0bbc6 100644 --- a/ui/pages/confirmations/components/confirm/info/set-approval-for-all-info/revoke-set-approval-for-all-static-simulation/__snapshots__/revoke-set-approval-for-all-static-simulation.test.tsx.snap +++ b/ui/pages/confirmations/components/confirm/info/set-approval-for-all-info/revoke-set-approval-for-all-static-simulation/__snapshots__/revoke-set-approval-for-all-static-simulation.test.tsx.snap @@ -7,7 +7,7 @@ exports[` renders component for setAp data-testid="confirmation__simulation_section" >
renders component for setAp
renders component for setAp
renders component for approve req data-testid="confirmation__simulation_section" >
renders component for approve req
renders component when the prop override is passed data-testid="advanced-details-nonce-section" >
renders component when the prop override is passed data-testid="advanced-details-data-section" >
renders component when the state property is true 1 data-testid="advanced-details-nonce-section" >
renders component when the state property is true 1 data-testid="advanced-details-data-section" >
renders component 1`] = `
diff --git a/ui/pages/confirmations/components/confirm/info/shared/gas-fees-details/__snapshots__/gas-fees-details.test.tsx.snap b/ui/pages/confirmations/components/confirm/info/shared/gas-fees-details/__snapshots__/gas-fees-details.test.tsx.snap index 4941dcd656d9..8cc9a9c3bfb5 100644 --- a/ui/pages/confirmations/components/confirm/info/shared/gas-fees-details/__snapshots__/gas-fees-details.test.tsx.snap +++ b/ui/pages/confirmations/components/confirm/info/shared/gas-fees-details/__snapshots__/gas-fees-details.test.tsx.snap @@ -3,7 +3,7 @@ exports[` renders component for gas fees section 1`] = `
@@ -67,7 +67,7 @@ exports[` renders component for gas fees section 1`] = `
diff --git a/ui/pages/confirmations/components/confirm/info/shared/gas-fees-row/__snapshots__/gas-fees-row.test.tsx.snap b/ui/pages/confirmations/components/confirm/info/shared/gas-fees-row/__snapshots__/gas-fees-row.test.tsx.snap index 5de2d2361b38..94432ffdf196 100644 --- a/ui/pages/confirmations/components/confirm/info/shared/gas-fees-row/__snapshots__/gas-fees-row.test.tsx.snap +++ b/ui/pages/confirmations/components/confirm/info/shared/gas-fees-row/__snapshots__/gas-fees-row.test.tsx.snap @@ -3,7 +3,7 @@ exports[` renders component 1`] = `
renders component for gas fees section 1`] = ` data-testid="gas-fee-section" >
@@ -73,7 +73,7 @@ exports[` renders component for gas fees section 1`] = `
diff --git a/ui/pages/confirmations/components/confirm/info/shared/transaction-data/__snapshots__/transaction-data.test.tsx.snap b/ui/pages/confirmations/components/confirm/info/shared/transaction-data/__snapshots__/transaction-data.test.tsx.snap index cc66da7a1375..99732c7e3410 100644 --- a/ui/pages/confirmations/components/confirm/info/shared/transaction-data/__snapshots__/transaction-data.test.tsx.snap +++ b/ui/pages/confirmations/components/confirm/info/shared/transaction-data/__snapshots__/transaction-data.test.tsx.snap @@ -7,7 +7,7 @@ exports[`TransactionData renders decoded data with names and descriptions 1`] = data-testid="advanced-details-data-section" >
@@ -146,7 +146,7 @@ exports[`TransactionData renders decoded data with names and descriptions 1`] =
@@ -197,7 +197,7 @@ exports[`TransactionData renders decoded data with names and descriptions 1`] = style="height: 1px; margin-left: -8px; margin-right: -8px;" />
@@ -305,7 +305,7 @@ exports[`TransactionData renders decoded data with names and descriptions 1`] =
@@ -350,7 +350,7 @@ exports[`TransactionData renders decoded data with names and descriptions 1`] =
@@ -395,7 +395,7 @@ exports[`TransactionData renders decoded data with names and descriptions 1`] =
@@ -517,7 +517,7 @@ exports[`TransactionData renders decoded data with names and descriptions 1`] =
@@ -568,7 +568,7 @@ exports[`TransactionData renders decoded data with names and descriptions 1`] = style="height: 1px; margin-left: -8px; margin-right: -8px;" />
@@ -676,7 +676,7 @@ exports[`TransactionData renders decoded data with names and descriptions 1`] =
@@ -732,7 +732,7 @@ exports[`TransactionData renders decoded data with names and descriptions 1`] =
@@ -783,7 +783,7 @@ exports[`TransactionData renders decoded data with names and descriptions 1`] = style="height: 1px; margin-left: -8px; margin-right: -8px;" />
@@ -891,7 +891,7 @@ exports[`TransactionData renders decoded data with names and descriptions 1`] =
@@ -947,7 +947,7 @@ exports[`TransactionData renders decoded data with names and descriptions 1`] =
@@ -1005,7 +1005,7 @@ exports[`TransactionData renders decoded data with no names 1`] = ` data-testid="advanced-details-data-section" >
@@ -1068,7 +1068,7 @@ exports[`TransactionData renders decoded data with no names 1`] = ` class="mm-box mm-box--padding-left-2" >
@@ -1113,7 +1113,7 @@ exports[`TransactionData renders decoded data with no names 1`] = `
@@ -1169,7 +1169,7 @@ exports[`TransactionData renders decoded data with no names 1`] = `
@@ -1225,7 +1225,7 @@ exports[`TransactionData renders decoded data with tuples and arrays 1`] = ` data-testid="advanced-details-data-section" >
@@ -1304,7 +1304,7 @@ exports[`TransactionData renders decoded data with tuples and arrays 1`] = ` class="mm-box mm-box--padding-left-2" >
@@ -1360,7 +1360,7 @@ exports[`TransactionData renders decoded data with tuples and arrays 1`] = `
@@ -1398,7 +1398,7 @@ exports[`TransactionData renders decoded data with tuples and arrays 1`] = ` class="mm-box mm-box--padding-left-2" >
@@ -1436,7 +1436,7 @@ exports[`TransactionData renders decoded data with tuples and arrays 1`] = ` class="mm-box mm-box--padding-left-2" >
@@ -1474,7 +1474,7 @@ exports[`TransactionData renders decoded data with tuples and arrays 1`] = ` class="mm-box mm-box--padding-left-2" >
@@ -1530,7 +1530,7 @@ exports[`TransactionData renders decoded data with tuples and arrays 1`] = `
@@ -1575,7 +1575,7 @@ exports[`TransactionData renders decoded data with tuples and arrays 1`] = `
@@ -1620,7 +1620,7 @@ exports[`TransactionData renders decoded data with tuples and arrays 1`] = `
@@ -1666,7 +1666,7 @@ exports[`TransactionData renders decoded data with tuples and arrays 1`] = `
@@ -1704,7 +1704,7 @@ exports[`TransactionData renders decoded data with tuples and arrays 1`] = ` class="mm-box mm-box--padding-left-2" >
@@ -1760,7 +1760,7 @@ exports[`TransactionData renders decoded data with tuples and arrays 1`] = `
@@ -1805,7 +1805,7 @@ exports[`TransactionData renders decoded data with tuples and arrays 1`] = `
@@ -1850,7 +1850,7 @@ exports[`TransactionData renders decoded data with tuples and arrays 1`] = `
@@ -1896,7 +1896,7 @@ exports[`TransactionData renders decoded data with tuples and arrays 1`] = `
@@ -1934,7 +1934,7 @@ exports[`TransactionData renders decoded data with tuples and arrays 1`] = ` class="mm-box mm-box--padding-left-2" >
@@ -1990,7 +1990,7 @@ exports[`TransactionData renders decoded data with tuples and arrays 1`] = `
@@ -2035,7 +2035,7 @@ exports[`TransactionData renders decoded data with tuples and arrays 1`] = `
@@ -2080,7 +2080,7 @@ exports[`TransactionData renders decoded data with tuples and arrays 1`] = `
@@ -2127,7 +2127,7 @@ exports[`TransactionData renders decoded data with tuples and arrays 1`] = `
@@ -2183,7 +2183,7 @@ exports[`TransactionData renders decoded data with tuples and arrays 1`] = `
@@ -2229,7 +2229,7 @@ exports[`TransactionData renders decoded data with tuples and arrays 1`] = `
@@ -2287,7 +2287,7 @@ exports[`TransactionData renders raw hexadecimal if no decoded data 1`] = ` data-testid="advanced-details-data-section" >
renders component for transaction details 1`] = data-testid="transaction-details-section" >
@@ -60,7 +60,7 @@ exports[` renders component for transaction details 1`] =
diff --git a/ui/pages/confirmations/components/confirm/info/token-transfer/__snapshots__/token-details-section.test.tsx.snap b/ui/pages/confirmations/components/confirm/info/token-transfer/__snapshots__/token-details-section.test.tsx.snap index dcedd06b1557..6ab7ebb270b7 100644 --- a/ui/pages/confirmations/components/confirm/info/token-transfer/__snapshots__/token-details-section.test.tsx.snap +++ b/ui/pages/confirmations/components/confirm/info/token-transfer/__snapshots__/token-details-section.test.tsx.snap @@ -7,7 +7,7 @@ exports[`TokenDetailsSection renders correctly 1`] = ` data-testid="confirmation__transaction-flow" >
@@ -330,7 +330,7 @@ exports[`TokenTransferInfo renders correctly 1`] = `
diff --git a/ui/pages/confirmations/components/confirm/info/typed-sign-v1/__snapshots__/typed-sign-v1.test.tsx.snap b/ui/pages/confirmations/components/confirm/info/typed-sign-v1/__snapshots__/typed-sign-v1.test.tsx.snap index d4b07b83a269..e80d317f574b 100644 --- a/ui/pages/confirmations/components/confirm/info/typed-sign-v1/__snapshots__/typed-sign-v1.test.tsx.snap +++ b/ui/pages/confirmations/components/confirm/info/typed-sign-v1/__snapshots__/typed-sign-v1.test.tsx.snap @@ -6,7 +6,7 @@ exports[`TypedSignInfo correctly renders typed sign data request 1`] = ` class="mm-box mm-box--margin-bottom-4 mm-box--padding-2 mm-box--background-color-background-default mm-box--rounded-md" >
-

- Spending cap -

+
+

+ Spending cap +

+
+
, @@ -44,17 +38,10 @@ const StateChangeRow = ({ const { assetType, changeType, amount, contractAddress, tokenID } = stateChange; return ( - - - {getStateChangeLabelMap(t, changeType)} - + {(assetType === TokenStandard.ERC20 || assetType === TokenStandard.ERC721) && ( - )} - + {assetType === 'NATIVE' && ( + + )} + ); }; diff --git a/ui/pages/confirmations/components/confirm/info/typed-sign/permit-simulation/default-simulation/__snapshots__/default-simulation.test.tsx.snap b/ui/pages/confirmations/components/confirm/info/typed-sign/permit-simulation/default-simulation/__snapshots__/default-simulation.test.tsx.snap index a378d0befcc4..2b6dee2b8c0c 100644 --- a/ui/pages/confirmations/components/confirm/info/typed-sign/permit-simulation/default-simulation/__snapshots__/default-simulation.test.tsx.snap +++ b/ui/pages/confirmations/components/confirm/info/typed-sign/permit-simulation/default-simulation/__snapshots__/default-simulation.test.tsx.snap @@ -7,7 +7,7 @@ exports[`DefaultSimulation renders component correctly 1`] = ` data-testid="confirmation__simulation_section" >
{ + it('renders component correctly', async () => { + const mockStore = configureMockStore([])(mockState); + + const { findByText } = renderWithProvider( + , + mockStore, + ); + + expect(await findByText('<0.000001')).toBeInTheDocument(); + expect(await findByText('ETH')).toBeInTheDocument(); + }); +}); diff --git a/ui/pages/confirmations/components/confirm/info/typed-sign/permit-simulation/native-value-display/native-value-display.tsx b/ui/pages/confirmations/components/confirm/info/typed-sign/permit-simulation/native-value-display/native-value-display.tsx new file mode 100644 index 000000000000..b198680f4e96 --- /dev/null +++ b/ui/pages/confirmations/components/confirm/info/typed-sign/permit-simulation/native-value-display/native-value-display.tsx @@ -0,0 +1,118 @@ +import { BigNumber } from 'bignumber.js'; +import { Hex } from '@metamask/utils'; +import React, { useMemo } from 'react'; +import { useSelector } from 'react-redux'; + +import { TokenStandard } from '../../../../../../../../../shared/constants/transaction'; +import { calcTokenAmount } from '../../../../../../../../../shared/lib/transactions-controller-utils'; +import { + Box, + Text, +} from '../../../../../../../../components/component-library'; +import { + BlockSize, + BorderRadius, + Display, + JustifyContent, + TextAlign, +} from '../../../../../../../../helpers/constants/design-system'; +import Tooltip from '../../../../../../../../components/ui/tooltip'; +import { shortenString } from '../../../../../../../../helpers/utils/util'; +import { selectConversionRateByChainId } from '../../../../../../../../selectors'; +import { AssetPill } from '../../../../../simulation-details/asset-pill'; +import { + formatAmount, + formatAmountMaxPrecision, +} from '../../../../../simulation-details/formatAmount'; +import { IndividualFiatDisplay } from '../../../../../simulation-details/fiat-display'; +import { getAmountColors } from '../../../utils'; + +const NATIVE_DECIMALS = 18; + +type PermitSimulationValueDisplayParams = { + /** ID of the associated chain. */ + chainId: Hex; + + /** The token amount */ + value: number | string; + + /** True if value is being credited to wallet */ + credit?: boolean; + + /** True if value is being debited to wallet */ + debit?: boolean; +}; + +const NativeValueDisplay: React.FC = ({ + chainId, + value, + credit, + debit, +}) => { + const conversionRate = useSelector((state) => + selectConversionRateByChainId(state, chainId), + ); + + const { fiatValue, tokenValue, tokenValueMaxPrecision } = useMemo(() => { + if (!value) { + return { tokenValue: null, tokenValueMaxPrecision: null }; + } + + const tokenAmount = calcTokenAmount(value, NATIVE_DECIMALS); + + return { + fiatValue: conversionRate + ? new BigNumber(tokenAmount).times(String(conversionRate)).toNumber() + : undefined, + tokenValue: formatAmount('en-US', tokenAmount), + tokenValueMaxPrecision: formatAmountMaxPrecision('en-US', tokenAmount), + }; + }, [conversionRate, value]); + + const { color, backgroundColor } = getAmountColors(credit, debit); + + return ( + + + + + + {credit && '+ '} + {debit && '- '} + {tokenValue !== null && + shortenString(tokenValue || '', { + truncatedCharLimit: 15, + truncatedStartChars: 15, + truncatedEndChars: 0, + skipCharacterInEnd: true, + })} + + + + + + + {fiatValue && } + + + ); +}; + +export default NativeValueDisplay; diff --git a/ui/pages/confirmations/components/confirm/info/typed-sign/permit-simulation/value-display/__snapshots__/value-display.test.tsx.snap b/ui/pages/confirmations/components/confirm/info/typed-sign/permit-simulation/value-display/__snapshots__/value-display.test.tsx.snap index 26def806c6fa..37e3a25ad5b6 100644 --- a/ui/pages/confirmations/components/confirm/info/typed-sign/permit-simulation/value-display/__snapshots__/value-display.test.tsx.snap +++ b/ui/pages/confirmations/components/confirm/info/typed-sign/permit-simulation/value-display/__snapshots__/value-display.test.tsx.snap @@ -3,7 +3,8 @@ exports[`PermitSimulationValueDisplay renders component correctly 1`] = `
+ + {credit && '+ '} + {debit && '- '} {tokenValue !== null && shortenString(tokenValue || '', { truncatedCharLimit: 15, diff --git a/ui/pages/confirmations/components/confirm/info/utils.ts b/ui/pages/confirmations/components/confirm/info/utils.ts index a80d604fed83..0ad8479ac7b9 100644 --- a/ui/pages/confirmations/components/confirm/info/utils.ts +++ b/ui/pages/confirmations/components/confirm/info/utils.ts @@ -1,4 +1,8 @@ import { DecodedTransactionDataResponse } from '../../../../../../shared/types/transaction-decode'; +import { + BackgroundColor, + TextColor, +} from '../../../../../helpers/constants/design-system'; export function getIsRevokeSetApprovalForAll( value: DecodedTransactionDataResponse | undefined, @@ -9,3 +13,17 @@ export function getIsRevokeSetApprovalForAll( return isRevokeSetApprovalForAll; } + +export const getAmountColors = (credit?: boolean, debit?: boolean) => { + let color = TextColor.textDefault; + let backgroundColor = BackgroundColor.backgroundAlternative; + + if (credit) { + color = TextColor.successDefault; + backgroundColor = BackgroundColor.successMuted; + } else if (debit) { + color = TextColor.errorDefault; + backgroundColor = BackgroundColor.errorMuted; + } + return { color, backgroundColor }; +}; diff --git a/ui/pages/confirmations/components/confirm/row/__snapshots__/dataTree.test.tsx.snap b/ui/pages/confirmations/components/confirm/row/__snapshots__/dataTree.test.tsx.snap index 68d8aab887be..783f16274d19 100644 --- a/ui/pages/confirmations/components/confirm/row/__snapshots__/dataTree.test.tsx.snap +++ b/ui/pages/confirmations/components/confirm/row/__snapshots__/dataTree.test.tsx.snap @@ -6,7 +6,7 @@ exports[`DataTree correctly renders reverse strings 1`] = ` class="mm-box mm-box--width-full" >