From b52ccad9fb4703b6471480a702946043b2509204 Mon Sep 17 00:00:00 2001 From: sahar-fehri Date: Tue, 26 Sep 2023 13:24:47 +0200 Subject: [PATCH] fix: fix contract address display in confirmation page --- test/data/mock-state.json | 8 ++++++++ .../confirm-page-container-container.test.js | 2 ++ ...m-page-container-content.component.test.js | 19 +++++++++++++++++-- ...onfirm-page-container-summary.component.js | 13 ++++++++----- 4 files changed, 35 insertions(+), 7 deletions(-) diff --git a/test/data/mock-state.json b/test/data/mock-state.json index be994991cb49..2cf3c4226c2e 100644 --- a/test/data/mock-state.json +++ b/test/data/mock-state.json @@ -20,6 +20,14 @@ "warning": null, "customTokenAmount": "10" }, + "confirmTransaction": { + "txData": { + "txParams": { + "gas": "0x153e2", + "value": "0x0" + } + } + }, "history": { "mostRecentOverviewPage": "/mostRecentOverviewPage" }, diff --git a/ui/components/app/confirm-page-container/confirm-page-container-container.test.js b/ui/components/app/confirm-page-container/confirm-page-container-container.test.js index 6432fad41027..a6afdcfc6368 100644 --- a/ui/components/app/confirm-page-container/confirm-page-container-container.test.js +++ b/ui/components/app/confirm-page-container/confirm-page-container-container.test.js @@ -319,6 +319,8 @@ describe('Confirm Page Container Container Test', () => { }; mockState.metamask.addressBook = addressBook; + mockState.confirmTransaction.txData.txParams.to = + '0x7a1A4Ad9cc746a70ee58568466f7996dD0aCE4E8'; const store = configureMockStore()(mockState); diff --git a/ui/components/app/confirm-page-container/confirm-page-container-content/confirm-page-container-content.component.test.js b/ui/components/app/confirm-page-container/confirm-page-container-content/confirm-page-container-content.component.test.js index f81301c195ec..5261d935c185 100644 --- a/ui/components/app/confirm-page-container/confirm-page-container-content/confirm-page-container-content.component.test.js +++ b/ui/components/app/confirm-page-container/confirm-page-container-content/confirm-page-container-content.component.test.js @@ -7,6 +7,7 @@ import { INSUFFICIENT_FUNDS_ERROR_KEY, TRANSACTION_ERROR_KEY, } from '../../../../helpers/constants/error-keys'; +import { shortenAddress } from '../../../../helpers/utils/util'; import ConfirmPageContainerContent from './confirm-page-container-content.component'; describe('Confirm Page Container Content', () => { @@ -25,6 +26,17 @@ describe('Confirm Page Container Content', () => { }, }, }, + identities: {}, + tokenList: {}, + }, + confirmTransaction: { + txData: { + txParams: { + gas: '0x153e2', + value: '0x0', + to: '0x0BC30598F0F386371eB3d2195AcAA14C7566534b', + }, + }, }, }; @@ -106,7 +118,7 @@ describe('Confirm Page Container Content', () => { expect(props.onCancel).toHaveBeenCalledTimes(1); }); - it('render contract address name from addressBook in title for contract', async () => { + it('render contract address in the content component', async () => { props.disabled = false; props.toAddress = '0x06195827297c7A80a443b6894d3BDB8824b43896'; props.transactionType = TransactionType.contractInteraction; @@ -114,8 +126,11 @@ describe('Confirm Page Container Content', () => { , store, ); + const expectedAddress = shortenAddress( + mockStore.confirmTransaction.txData.txParams.to, + ); - expect(queryByText('Address Book Account 1')).toBeInTheDocument(); + expect(queryByText(`${expectedAddress}`)).toBeInTheDocument(); }); it('render simple title without address name for simple send', async () => { diff --git a/ui/components/app/confirm-page-container/confirm-page-container-content/confirm-page-container-summary/confirm-page-container-summary.component.js b/ui/components/app/confirm-page-container/confirm-page-container-content/confirm-page-container-summary/confirm-page-container-summary.component.js index 46a3f068f42e..2421f11ee39b 100644 --- a/ui/components/app/confirm-page-container/confirm-page-container-content/confirm-page-container-summary/confirm-page-container-summary.component.js +++ b/ui/components/app/confirm-page-container/confirm-page-container-content/confirm-page-container-summary/confirm-page-container-summary.component.js @@ -9,7 +9,7 @@ import { TransactionType } from '../../../../../../shared/constants/transaction' import { toChecksumHexAddress } from '../../../../../../shared/modules/hexstring-utils'; import { useI18nContext } from '../../../../../hooks/useI18nContext'; import useAddressDetails from '../../../../../hooks/useAddressDetails'; -import { getIpfsGateway } from '../../../../../selectors'; +import { getIpfsGateway, txDataSelector } from '../../../../../selectors'; import Identicon from '../../../../ui/identicon'; import InfoTooltip from '../../../../ui/info-tooltip'; @@ -25,7 +25,6 @@ const ConfirmPageContainerSummary = (props) => { subtitleComponent, className, tokenAddress, - toAddress, nonce, origin, image, @@ -36,6 +35,10 @@ const ConfirmPageContainerSummary = (props) => { const t = useI18nContext(); const ipfsGateway = useSelector(getIpfsGateway); + const txData = useSelector(txDataSelector); + const { txParams = {} } = txData; + const { to: txParamsToAddress } = txParams; + const contractInitiatedTransactionType = [ TransactionType.contractInteraction, TransactionType.tokenMethodTransfer, @@ -48,14 +51,15 @@ const ConfirmPageContainerSummary = (props) => { if (isContractTypeTransaction) { // If the transaction is TOKEN_METHOD_TRANSFER or TOKEN_METHOD_TRANSFER_FROM // the contract address is passed down as tokenAddress, if it is anyother - // type of contract interaction it is passed as toAddress + // type of contract interaction it is "to" from txParams + contractAddress = transactionType === TransactionType.tokenMethodTransfer || transactionType === TransactionType.tokenMethodTransferFrom || transactionType === TransactionType.tokenMethodSafeTransferFrom || transactionType === TransactionType.tokenMethodSetApprovalForAll ? tokenAddress - : toAddress; + : txParamsToAddress; } const { toName, isTrusted } = useAddressDetails(contractAddress); @@ -146,7 +150,6 @@ ConfirmPageContainerSummary.propTypes = { subtitleComponent: PropTypes.node, className: PropTypes.string, tokenAddress: PropTypes.string, - toAddress: PropTypes.string, nonce: PropTypes.string, origin: PropTypes.string.isRequired, transactionType: PropTypes.string,