Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add domain binding SIWE redesign alert row #25281

Merged
merged 55 commits into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
04318ca
refactor: update SignatureRequestType siwe type to SIWEMessage
digiwand Jun 13, 2024
1fda0b5
TEMP: prep to add domain binding alert in sign redesign SIWE
digiwand Jun 13, 2024
68e8b29
Merge branch 'develop' into feat-sign-refactor-alerts
digiwand Jun 14, 2024
979ad8f
feat: add domain binding SIWE alert
digiwand Jun 14, 2024
661de18
fix: isSIWESignatureRequest request?
digiwand Jun 14, 2024
2a9dbeb
refactor: revert msgParams destruct
digiwand Jun 14, 2024
35efdfc
chore: rm unused comment
digiwand Jun 14, 2024
2f58e32
fix: msgParams destruct and alert title/reason
digiwand Jun 18, 2024
fbcf497
fix: lint useSignatureAlerts
digiwand Jun 19, 2024
f1c0ac7
Merge branch 'develop' into feat-sign-refactor-alerts
digiwand Jun 19, 2024
dfa35a1
refactor: useSignatureAlerts -> useDomainMismatchAlerts
digiwand Jun 20, 2024
5e8fb5b
refactor: useDomainMismatchAlerts -> useDomainMismatchAlert
digiwand Jun 20, 2024
9ed03d9
fix: disable SIWE redesign
digiwand Jun 20, 2024
78363ec
refactor: useDomainMismatchAlert rm useMemo and directly return
digiwand Jun 20, 2024
ca059ab
style: export default function useDomainMismatchAlerts
digiwand Jun 20, 2024
44bd4e8
style: rn isSIWEDomainValid -> isValidDomain
digiwand Jun 20, 2024
8bb125b
refactor: use currentConfirmationSelector instead of useCurrentConfir…
digiwand Jun 20, 2024
c21feb2
refactor: use currentConfirmationSelector instead of useCurrentConfir…
digiwand Jun 20, 2024
f779176
refactor: force return boolean isSIWESignatureRequest
digiwand Jun 20, 2024
07b8a97
refactor: mv useDomainMismatchAlert and update useConfirmationAlerts …
digiwand Jun 20, 2024
abc8365
style: rn confirmAlertModalTitleSignIn -> alertReasonSignIn
digiwand Jun 21, 2024
7825774
style: rn -> alertMessageSignInDomainMismatch
digiwand Jun 21, 2024
8fcaec9
refactor: restore useDomainMismatchAlert useMemo
digiwand Jun 21, 2024
60a6493
yarn lint:fix
digiwand Jun 21, 2024
30f7405
fix: should return alert if !isValidDomain
digiwand Jun 21, 2024
a07296d
test: add useDomainMismatchAlert tests
digiwand Jun 21, 2024
1f18f72
yarn lint:fix
digiwand Jun 21, 2024
c195dde
test: split useDomainMismatchAlert msgParams and SIWE tests
digiwand Jun 21, 2024
1069915
test: update useDomainMismatchAlert mock states
digiwand Jun 21, 2024
f8ddcbb
yarn lint:fix
digiwand Jun 21, 2024
245c5c6
Merge branch 'develop' into feat-sign-refactor-alerts
digiwand Jun 21, 2024
c45f50e
fix: lint PersonalInfo SIWESign statement null
digiwand Jun 21, 2024
3763396
fix: no early return with useMemo
digiwand Jun 21, 2024
a467e42
Merge branch 'develop' into feat-sign-refactor-alerts
digiwand Jun 21, 2024
4ecafc7
fix: rm superfluous msgParams check
digiwand Jun 21, 2024
5ae550d
fix: useDomainMismatchAlert useMemo logic
digiwand Jun 21, 2024
f87de03
refactor: update useDomainMismatchAlert useMemo logic
digiwand Jun 21, 2024
9d22e20
fix: mock personal_sign parsedMessage
digiwand Jun 21, 2024
be02ff6
Merge branch 'develop' into feat-sign-refactor-alerts
digiwand Jun 21, 2024
323f1f8
fix: use {} in case !currentConfirmation
digiwand Jun 21, 2024
8397115
fix: useDomainMismatchAlerts tests
digiwand Jun 21, 2024
ea6aeda
style: readd a comment to address SIWE redesign
digiwand Jun 21, 2024
bd39c5b
yarn lint:fix
digiwand Jun 21, 2024
780f5b7
fix: update: test
digiwand Jun 23, 2024
834f68a
Merge branch 'develop' into feat-sign-refactor-alerts
digiwand Jun 23, 2024
3771748
refactor: reduce useDomainMismatchAlert dep
digiwand Jun 25, 2024
ffda4d1
style: update conditional
digiwand Jun 25, 2024
a98fbcd
fix: lint newline
digiwand Jun 25, 2024
e817fec
yarn lint:fix
digiwand Jun 25, 2024
51df149
Merge branch 'develop' into feat-sign-refactor-alerts
digiwand Jun 26, 2024
c2e8a8c
Merge branch 'develop' into feat-sign-refactor-alerts
digiwand Jun 26, 2024
e78bdd0
chore: mv useDomainMismatchAlert
digiwand Jun 26, 2024
95f28be
chore: pluarlize useDomainMismatchAlerts filepath
digiwand Jun 26, 2024
ec7f458
Merge branch 'develop' into feat-sign-refactor-alerts
digiwand Jun 26, 2024
52502c2
Merge branch 'develop' into feat-sign-refactor-alerts
digiwand Jun 27, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions app/_locales/en/messages.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

46 changes: 46 additions & 0 deletions ui/pages/confirmations/hooks/alerts/useSignatureAlerts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { useMemo } from 'react';
import {
isValidSIWEOrigin,
WrappedSIWERequest
} from '@metamask/controller-utils';

import { Alert } from '../../../../ducks/confirm-alerts/confirm-alerts';
import { Severity } from '../../../../helpers/constants/design-system';
import { useI18nContext } from '../../../../hooks/useI18nContext';
import { SignatureRequestType } from '../../types/confirm';
import { isSIWESignatureRequest } from '../../utils';
import useCurrentConfirmation from '../useCurrentConfirmation';

const useSignatureAlerts = (): Alert[] => {
const { currentConfirmation } = useCurrentConfirmation();
const t = useI18nContext();

const alerts = useMemo<Alert[]>(() => {
const isSIWE = isSIWESignatureRequest(
currentConfirmation as SignatureRequestType
);
if (!isSIWE || !currentConfirmation?.msgParams) {
return [];
}

const { msgParams } = currentConfirmation;
const isSIWEDomainValid = isValidSIWEOrigin(msgParams as WrappedSIWERequest);
if (isSIWEDomainValid) {
return [];
}

const alert = {
field: 'requestFrom',
key: 'requestFrom',
message: t('confirmAlertModalMessageDomainMismatch'),
reason: t('confirmAlertModalTitleSignIn'),
severity: Severity.Danger,
} as Alert;

return [alert];
}, [currentConfirmation?.id, currentConfirmation?.msgParams, t]);

return alerts;
};

export default useSignatureAlerts;
digiwand marked this conversation as resolved.
Show resolved Hide resolved
7 changes: 6 additions & 1 deletion ui/pages/confirmations/hooks/useConfirmationAlerts.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import { useMemo } from 'react';
import useBlockaidAlerts from './alerts/useBlockaidAlert';
import useSignatureAlerts from './alerts/useSignatureAlerts';

const useConfirmationAlerts = () => {
const blockaidAlerts = useBlockaidAlerts();
const signatureAlerts = useSignatureAlerts();

return useMemo(() => [...blockaidAlerts], [blockaidAlerts]);
return useMemo(
() => [...blockaidAlerts, ...signatureAlerts],
[blockaidAlerts, signatureAlerts],
);
};

export default useConfirmationAlerts;
18 changes: 3 additions & 15 deletions ui/pages/confirmations/types/confirm.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { ApprovalControllerState } from '@metamask/approval-controller';
import { SIWEMessage } from '@metamask/controller-utils';

import {
TransactionMeta,
TransactionType,
Expand Down Expand Up @@ -26,21 +28,7 @@ export type SignatureRequestType = {
origin: string;
data: string | TypedSignDataV1Type;
version?: string;
siwe?: {
isSIWEMessage: boolean;
parsedMessage: null | {
domain: string;
address: string;
statement: string;
uri: string;
version: string;
chainId: number;
nonce: string;
issuedAt: string;
requestId?: string;
resources?: string[];
};
};
siwe?: SIWEMessage;
};
type: TransactionType;
custodyId?: string;
Expand Down
2 changes: 1 addition & 1 deletion ui/pages/confirmations/utils/confirm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export const parseSanitizeTypedDataMessage = (dataToParse: string) => {
};

export const isSIWESignatureRequest = (request: SignatureRequestType) =>
request.msgParams?.siwe?.isSIWEMessage;
request?.msgParams?.siwe?.isSIWEMessage;
digiwand marked this conversation as resolved.
Show resolved Hide resolved

export const isPermitSignatureRequest = (request: SignatureRequestType) => {
if (
Expand Down