Skip to content

Commit dbf544d

Browse files
committed
Adding mmi section to confirmation page
1 parent 68cc610 commit dbf544d

File tree

4 files changed

+103
-0
lines changed

4 files changed

+103
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default as MMISignatureMismatchBanner } from './mmi-signature-mismatch-banner';
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import React, { memo, useMemo } from 'react';
2+
import { useSelector } from 'react-redux';
3+
4+
import { MESSAGE_TYPE } from '../../../../../../shared/constants/app';
5+
import {
6+
BackgroundColor,
7+
BlockSize,
8+
Display,
9+
IconColor,
10+
TextColor,
11+
TextVariant,
12+
} from '../../../../../helpers/constants/design-system';
13+
import {
14+
getAccountByAddress,
15+
shortenAddress,
16+
} from '../../../../../helpers/utils/util';
17+
import { useI18nContext } from '../../../../../hooks/useI18nContext';
18+
import {
19+
accountsWithSendEtherInfoSelector,
20+
currentConfirmationSelector,
21+
getSelectedInternalAccount,
22+
} from '../../../../../selectors';
23+
import {
24+
Box,
25+
Icon,
26+
IconName,
27+
Text,
28+
} from '../../../../../components/component-library';
29+
30+
const MMISignatureMismatchBanner: React.FC = memo(() => {
31+
const t = useI18nContext();
32+
const currentConfirmation = useSelector(currentConfirmationSelector);
33+
const selectedAccount = useSelector(getSelectedInternalAccount);
34+
const allAccounts = useSelector(accountsWithSendEtherInfoSelector);
35+
36+
const fromAccount = useMemo(() => {
37+
if (
38+
!currentConfirmation ||
39+
currentConfirmation.type !== MESSAGE_TYPE.PERSONAL_SIGN ||
40+
!currentConfirmation.msgParams
41+
) {
42+
return null;
43+
}
44+
const {
45+
msgParams: { from },
46+
} = currentConfirmation;
47+
return getAccountByAddress(allAccounts, from);
48+
}, [currentConfirmation, allAccounts]);
49+
50+
if (
51+
selectedAccount &&
52+
fromAccount &&
53+
selectedAccount.address === fromAccount.address
54+
) {
55+
return null;
56+
}
57+
58+
return (
59+
<Box
60+
display={Display.Flex}
61+
width={BlockSize.Full}
62+
padding={4}
63+
marginBottom={4}
64+
backgroundColor={BackgroundColor.primaryMuted}
65+
>
66+
<Icon
67+
name={IconName.Info}
68+
color={IconColor.infoDefault}
69+
marginRight={2}
70+
/>
71+
<Text variant={TextVariant.bodyXs} color={TextColor.textDefault}>
72+
{t('mismatchAccount', [
73+
shortenAddress(selectedAccount?.address),
74+
shortenAddress(fromAccount?.address),
75+
])}
76+
</Text>
77+
</Box>
78+
);
79+
});
80+
81+
export default MMISignatureMismatchBanner;

ui/pages/confirmations/confirm/__snapshots__/confirm.test.tsx.snap

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,19 @@ exports[`Confirm should match snapshot for personal signature 1`] = `
7777
</p>
7878
</div>
7979
</div>
80+
<div
81+
class="mm-box mm-box--margin-bottom-4 mm-box--padding-4 mm-box--display-flex mm-box--width-full mm-box--background-color-primary-muted"
82+
>
83+
<span
84+
class="mm-box mm-icon mm-icon--size-md mm-box--margin-right-2 mm-box--display-inline-block mm-box--color-info-default"
85+
style="mask-image: url('./images/icons/info.svg');"
86+
/>
87+
<p
88+
class="mm-box mm-text mm-text--body-xs mm-box--color-text-default"
89+
>
90+
Your selected account (0x0dcd5...3e7bc) is different than the account trying to sign ()
91+
</p>
92+
</div>
8093
<div
8194
class="mm-box multichain-page-content mm-box--padding-4 mm-box--display-flex mm-box--flex-direction-column mm-box--width-full mm-box--height-full mm-box--background-color-background-alternative"
8295
>

ui/pages/confirmations/confirm/confirm.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ import { Content, Page } from '../../../components/multichain/pages/page';
44
import { BackgroundColor } from '../../../helpers/constants/design-system';
55
import { Footer } from '../components/confirm/footer';
66
import { Header } from '../components/confirm/header';
7+
///: BEGIN:ONLY_INCLUDE_IF(build-mmi)
8+
import { MMISignatureMismatchBanner } from '../components/confirm/mmi-signature-mismatch-banner';
9+
///: END:ONLY_INCLUDE_IF
710
import { Info } from '../components/confirm/info';
811
import { SignatureMessage } from '../components/confirm/signature-message';
912
import { Title } from '../components/confirm/title';
@@ -17,6 +20,11 @@ const Confirm = () => {
1720
return (
1821
<Page>
1922
<Header />
23+
{
24+
///: BEGIN:ONLY_INCLUDE_IF(build-mmi)
25+
<MMISignatureMismatchBanner />
26+
///: END:ONLY_INCLUDE_IF
27+
}
2028
<Content backgroundColor={BackgroundColor.backgroundAlternative}>
2129
<Title />
2230
<Info />

0 commit comments

Comments
 (0)