From d0bea6ccd521e47221d7b577e21f37b061325d1c Mon Sep 17 00:00:00 2001 From: ryanml Date: Thu, 2 Mar 2023 05:40:07 -0700 Subject: [PATCH] Fix incorrect balance in signature request header (#17829) * Fix incorrect balance in signature request header * Fix unit tests * Fix tests and increase unit test coverage * actually fix unit tests --------- Co-authored-by: Dan Miller --- .../signature-request.component.test.js.snap | 775 +++++++++++++++++- .../signature-request.component.js | 9 +- .../signature-request.component.test.js | 36 +- .../signature-request.container.js | 9 + .../signature-request.container.test.js | 3 + .../confirm-signature-request/index.test.js | 1 + 6 files changed, 830 insertions(+), 3 deletions(-) diff --git a/ui/components/app/signature-request/__snapshots__/signature-request.component.test.js.snap b/ui/components/app/signature-request/__snapshots__/signature-request.component.test.js.snap index 3b6d02fa5..df3631f5b 100644 --- a/ui/components/app/signature-request/__snapshots__/signature-request.component.test.js.snap +++ b/ui/components/app/signature-request/__snapshots__/signature-request.component.test.js.snap @@ -1,6 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`Signature Request Component render should match snapshot 1`] = ` +exports[`Signature Request Component render should match snapshot when useNativeCurrencyAsPrimaryCurrency is false 1`] = `
0 + DEF + +
+
+ +
+
+
+
+
+
+ + T + +
+
+ + test + +
+
+
+

+ Signature request +

+
+ Only sign this message if you fully understand the content and trust the requesting site. +
+
+ +
+ Verify contract details +
+
+
+
+
+
+

+ Mail +

+
+
+ + Contents + : + + + + Hello, Bob! + +
+
+ + From + : + + +
+
+ + Name + : + + + + Cow + +
+
+ + Wallets + : + + +
+
+ + 0 + : + + + +
+
+
+
+
+
+ + + + + +
+
+
+
+
+ 0xCD2...D826 +
+
+
+
+
+
+ + 1 + : + + + +
+
+
+
+
+
+ + + + + +
+
+
+
+
+ 0xDea...beeF +
+
+
+
+
+
+
+
+
+
+ + To + : + + +
+
+ + 0 + : + + +
+
+ + Name + : + + + + Bob + +
+
+ + Wallets + : + + +
+
+ + 0 + : + + + +
+
+
+
+
+
+ + + + + +
+
+
+
+
+ 0xbBb...BBbB +
+
+
+
+
+
+ + 1 + : + + + +
+
+
+
+
+
+ + + + + +
+
+
+
+
+ 0xB0B...Ea57 +
+
+
+
+
+
+ + 2 + : + + + +
+
+
+
+
+
+ + + + + +
+
+
+
+
+ 0xB0B...0000 +
+
+
+
+
+
+
+
+
+
+
+
+
+
+ + + +`; + +exports[`Signature Request Component render should match snapshot when useNativeCurrencyAsPrimaryCurrency is true 1`] = ` +
+
+ + diff --git a/ui/components/app/signature-request/signature-request.component.test.js b/ui/components/app/signature-request/signature-request.component.test.js index 5a26ba073..8c21d71e7 100644 --- a/ui/components/app/signature-request/signature-request.component.test.js +++ b/ui/components/app/signature-request/signature-request.component.test.js @@ -62,7 +62,7 @@ describe('Signature Request Component', () => { }; }); - it('should match snapshot', () => { + it('should match snapshot when useNativeCurrencyAsPrimaryCurrency is false', () => { const msgParams = { data: JSON.stringify(messageData), version: 'V4', @@ -83,6 +83,40 @@ describe('Signature Request Component', () => { }} fromAccount={{ address: fromAddress }} provider={{ type: 'rpc' }} + useNativeCurrencyAsPrimaryCurrency={false} + nativeCurrency="ABC" + currentCurrency="DEF" + />, + store, + ); + + expect(container).toMatchSnapshot(); + }); + + it('should match snapshot when useNativeCurrencyAsPrimaryCurrency is true', () => { + const msgParams = { + data: JSON.stringify(messageData), + version: 'V4', + origin: 'test', + }; + const { container } = renderWithProvider( + undefined} + cancel={() => undefined} + cancelAll={() => undefined} + mostRecentOverviewPage="/" + showRejectTransactionsConfirmationModal={() => undefined} + history={{ push: '/' }} + sign={() => undefined} + txData={{ + msgParams, + }} + fromAccount={{ address: fromAddress }} + provider={{ type: 'rpc' }} + useNativeCurrencyAsPrimaryCurrency + nativeCurrency="ABC" + currentCurrency="DEF" />, store, ); diff --git a/ui/components/app/signature-request/signature-request.container.js b/ui/components/app/signature-request/signature-request.container.js index 52a67c1ec..ac3bd2d38 100644 --- a/ui/components/app/signature-request/signature-request.container.js +++ b/ui/components/app/signature-request/signature-request.container.js @@ -8,6 +8,8 @@ import { getSubjectMetadata, unconfirmedMessagesHashSelector, getTotalUnapprovedMessagesCount, + getCurrentCurrency, + getPreferences, } from '../../../selectors'; import { isAddressLedger, @@ -35,6 +37,7 @@ function mapStateToProps(state, ownProps) { const subjectMetadata = getSubjectMetadata(state); const unconfirmedMessagesList = unconfirmedMessagesHashSelector(state); const unapprovedMessagesCount = getTotalUnapprovedMessagesCount(state); + const { useNativeCurrencyAsPrimaryCurrency } = getPreferences(state); const { iconUrl: siteImage = '' } = subjectMetadata[txData.msgParams.origin] || {}; @@ -51,6 +54,8 @@ function mapStateToProps(state, ownProps) { mostRecentOverviewPage: getMostRecentOverviewPage(state), conversionRate: conversionRateSelector(state), nativeCurrency: getNativeCurrency(state), + currentCurrency: getCurrentCurrency(state), + useNativeCurrencyAsPrimaryCurrency, subjectMetadata: getSubjectMetadata(state), // not forwarded to component allAccounts: accountsWithSendEtherInfoSelector(state), @@ -88,6 +93,8 @@ function mergeProps(stateProps, dispatchProps, ownProps) { siteImage, conversionRate, nativeCurrency, + currentCurrency, + useNativeCurrencyAsPrimaryCurrency, provider, subjectMetadata, unconfirmedMessagesList, @@ -141,6 +148,8 @@ function mergeProps(stateProps, dispatchProps, ownProps) { siteImage, conversionRate, nativeCurrency, + currentCurrency, + useNativeCurrencyAsPrimaryCurrency, provider, subjectMetadata, unapprovedMessagesCount, diff --git a/ui/components/app/signature-request/signature-request.container.test.js b/ui/components/app/signature-request/signature-request.container.test.js index e8c4a1e1e..8e3411b86 100644 --- a/ui/components/app/signature-request/signature-request.container.test.js +++ b/ui/components/app/signature-request/signature-request.container.test.js @@ -51,6 +51,9 @@ describe('Signature Request', () => { provider: { type: 'rpc', }, + preferences: { + useNativeCurrencyAsPrimaryCurrency: true, + }, accounts: { '0xd8f6a2ffb0fc5952d16c9768b71cfd35b6399aa5': { address: '0xd8f6a2ffb0fc5952d16c9768b71cfd35b6399aa5', diff --git a/ui/pages/confirm-signature-request/index.test.js b/ui/pages/confirm-signature-request/index.test.js index 93c80b53a..417437a97 100644 --- a/ui/pages/confirm-signature-request/index.test.js +++ b/ui/pages/confirm-signature-request/index.test.js @@ -47,6 +47,7 @@ const mockState = { selectedAddress: '0x8eeee1781fd885ff5ddef7789486676961873d12', addressBook: {}, tokenList: {}, + preferences: {}, }, appState: { warning: null,