diff --git a/.yarn/patches/@metamask-snaps-utils-npm-8.1.1-7d5dd6a26a.patch b/.yarn/patches/@metamask-snaps-utils-npm-8.1.1-7d5dd6a26a.patch new file mode 100644 index 000000000000..3361025d4860 --- /dev/null +++ b/.yarn/patches/@metamask-snaps-utils-npm-8.1.1-7d5dd6a26a.patch @@ -0,0 +1,120 @@ +diff --git a/dist/ui.cjs b/dist/ui.cjs +index 300fe9e97bba85945e3c2d200e736987453f8268..d6fa322e2b3629f41d653b91db52c3db85064276 100644 +--- a/dist/ui.cjs ++++ b/dist/ui.cjs +@@ -200,13 +200,23 @@ function getMarkdownLinks(text) { + * @param link - The link to validate. + * @param isOnPhishingList - The function that checks the link against the + * phishing list. ++ * @throws If the link is invalid. + */ + function validateLink(link, isOnPhishingList) { + try { + const url = new URL(link); + (0, utils_1.assert)(ALLOWED_PROTOCOLS.includes(url.protocol), `Protocol must be one of: ${ALLOWED_PROTOCOLS.join(', ')}.`); +- const hostname = url.protocol === 'mailto:' ? url.pathname.split('@')[1] : url.hostname; +- (0, utils_1.assert)(!isOnPhishingList(hostname), 'The specified URL is not allowed.'); ++ if (url.protocol === 'mailto:') { ++ const emails = url.pathname.split(','); ++ for (const email of emails) { ++ const hostname = email.split('@')[1]; ++ (0, utils_1.assert)(!hostname.includes(':')); ++ const href = `https://${hostname}`; ++ (0, utils_1.assert)(!isOnPhishingList(href), 'The specified URL is not allowed.'); ++ } ++ return; ++ } ++ (0, utils_1.assert)(!isOnPhishingList(url.href), 'The specified URL is not allowed.'); + } + catch (error) { + throw new Error(`Invalid URL: ${error?.code === 'ERR_ASSERTION' ? error.message : 'Unable to parse URL.'}`); +diff --git a/dist/ui.cjs.map b/dist/ui.cjs.map +index 71b5ecb9eb8bc8bdf919daccf24b25737ee69819..6d6e56cd7fea85e4d477c0399506a03d465ca740 100644 +--- a/dist/ui.cjs.map ++++ b/dist/ui.cjs.map +@@ -1 +1 @@ +-{"version":3,"file":"ui.cjs","sourceRoot":"","sources":["../src/ui.t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sdk';\nimport { NodeType } from '@metamask/snaps-sdk';\nimport type {\n BoldChildren,\n GenericSnapElement,\n ItalicChildren,\n JSXElement,\n LinkElement,\n Nestable,\n RowChildren,\n SnapNode,\n StandardFormattingElement,\n TextChildren,\n} from '@metamask/snaps-sdk/jsx';\nimport {\n Italic,\n Link,\n Bold,\n Row,\n Text,\n Field,\n Image,\n Input,\n Heading,\n Form,\n Divider,\n Spinner,\n Copyable,\n Box,\n Button,\n Address,\n} from '@metamask/snaps-sdk/jsx';\nimport {\n assert,\n assertExhaustive,\n hasProperty,\n isPlainObject,\n} from '@metamask/utils';\nimport { lexer, walkTokens } from 'marked';\nimport type { Token, Tokens } from 'marked';\n\nconst MAX_TEXT_LENGTH = 50_000; // 50 kb\nconst ALLOWED_PROTOCOLS = ['https:', 'mailto:'];\n\n/**\n * Get the button variant from a legacy button component variant.\n *\n * @param variant - The legacy button component variant.\n * @returns The button variant.\n */\nfunction getButtonVariant(variant?: 'primary' | 'secondary' | undefined) {\n switch (variant) {\n case 'primary':\n return 'primary';\n case 'secondary':\n return 'destructive';\n default:\n return undefined;\n }\n}\n\n/**\n * Get the children of a JSX element. If there is only one child, the child is\n * returned directly. Otherwise, the children are returned as an array.\n *\n * @param elements - The JSX elements.\n * @returns The child or children.\n */\nfunction getChildren(elements: Type[]) {\n if (elements.length === 1) {\n return elements[0];\n }\n\n return elements;\n}\n\n/**\n * Get the text of a link token.\n *\n * @param token - The link token.\n * @returns The text of the link token.\n */\nfunction getLinkText(token: Tokens.Link | Tokens.Generic) {\n if (token.tokens && token.tokens.length > 0) {\n return getChildren(token.tokens.flatMap(getTextChildFromToken));\n }\n\n return token.href;\n}\n\n/**\n * Get the text child from a list of markdown tokens.\n *\n * @param tokens - The markdown tokens.\n * @returns The text child.\n */\nfunction getTextChildFromTokens(tokens: Token[]) {\n return getChildren(tokens.flatMap(getTextChildFromToken));\n}\n\n/**\n * Get the text child from a markdown token.\n *\n * @param token - The markdown token.\n * @returns The text child.\n */\nfunction getTextChildFromToken(token: Token): TextChildren {\n switch (token.type) {\n case 'link': {\n return ;\n }\n\n case 'text':\n return token.text;\n\n case 'strong':\n return (\n \n {\n getTextChildFromTokens(\n // Due to the way `marked` is typed, `token.tokens` can be\n // `undefined`, but it's a required field of `Tokens.Bold`, so we\n // can safely cast it to `Token[]`.\n token.tokens as Token[],\n ) as BoldChildren\n }\n \n );\n\n case 'em':\n return (\n \n {\n getTextChildFromTokens(\n // Due to the way `marked` is typed, `token.tokens` can be\n // `undefined`, but it's a required field of `Tokens.Bold`, so we\n // can safely cast it to `Token[]`.\n token.tokens as Token[],\n ) as ItalicChildren\n }\n \n );\n\n default:\n return null;\n }\n}\n\n/**\n * Get all text children from a markdown string.\n *\n * @param value - The markdown string.\n * @returns The text children.\n */\nexport function getTextChildren(\n value: string,\n): (string | StandardFormattingElement | LinkElement)[] {\n const rootTokens = lexer(value, { gfm: false });\n const children: (string | StandardFormattingElement | LinkElement | null)[] =\n [];\n\n walkTokens(rootTokens, (token) => {\n if (token.type === 'paragraph') {\n if (children.length > 0) {\n children.push('\\n\\n');\n }\n\n const { tokens } = token as Tokens.Paragraph;\n // We do not need to consider nesting deeper than 1 level here and we can therefore cast.\n children.push(\n ...(tokens.flatMap(getTextChildFromToken) as (\n | string\n | StandardFormattingElement\n | LinkElement\n | null\n )[]),\n );\n }\n });\n\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion\n return children.filter((child) => child !== null) as (\n | string\n | StandardFormattingElement\n | LinkElement\n )[];\n}\n\n/**\n * Validate the text size of a component. The text size is the total length of\n * all text in the component.\n *\n * @param component - The component to validate.\n * @throws An error if the text size exceeds the maximum allowed size.\n */\nfunction validateComponentTextSize(component: Component) {\n const textSize = getTotalTextLength(component);\n assert(\n textSize <= MAX_TEXT_LENGTH,\n `The text in a Snap UI may not be larger than ${\n MAX_TEXT_LENGTH / 1000\n } kB.`,\n );\n}\n\n/**\n * Get a JSX element from a legacy UI component. This supports all legacy UI\n * components, and maps them to their JSX equivalents where possible.\n *\n * This function validates the text size of the component, but does not validate\n * the total size. The total size of the component should be validated before\n * calling this function.\n *\n * @param legacyComponent - The legacy UI component.\n * @returns The JSX element.\n */\nexport function getJsxElementFromComponent(\n legacyComponent: Component,\n): JSXElement {\n validateComponentTextSize(legacyComponent);\n\n /**\n * Get the JSX element for a component. This function is recursive and will\n * call itself for child components.\n *\n * @param component - The component to convert to a JSX element.\n * @returns The JSX element.\n */\n function getElement(component: Component) {\n switch (component.type) {\n case NodeType.Address:\n return
;\n\n case NodeType.Button:\n return (\n \n {component.value}\n \n );\n\n case NodeType.Copyable:\n return (\n \n );\n\n case NodeType.Divider:\n return ;\n\n case NodeType.Form:\n return (\n
\n {getChildren(component.children.map(getElement))}\n
\n );\n\n case NodeType.Heading:\n return ;\n\n case NodeType.Image:\n // `Image` supports `alt`, but the legacy `Image` component does not.\n return ;\n\n case NodeType.Input:\n return (\n \n \n \n );\n\n case NodeType.Panel:\n // `Panel` is renamed to `Box` in JSX.\n return (\n \n );\n\n case NodeType.Row:\n return (\n \n {getElement(component.value) as RowChildren}\n \n );\n\n case NodeType.Spinner:\n return ;\n\n case NodeType.Text:\n return {getChildren(getTextChildren(component.value))};\n\n /* istanbul ignore next 2 */\n default:\n return assertExhaustive(component);\n }\n }\n\n return getElement(legacyComponent);\n}\n\n/**\n * Extract all links from a Markdown text string using the `marked` lexer.\n *\n * @param text - The markdown text string.\n * @returns A list of URLs linked to in the string.\n */\nfunction getMarkdownLinks(text: string) {\n const tokens = lexer(text, { gfm: false });\n const links: Tokens.Link[] = [];\n\n // Walk the lexed tokens and collect all link tokens\n walkTokens(tokens, (token) => {\n if (token.type === 'link') {\n links.push(token as Tokens.Link);\n }\n });\n\n return links;\n}\n\n/**\n * Validate a link against the phishing list.\n *\n * @param link - The link to validate.\n * @param isOnPhishingList - The function that checks the link against the\n * phishing list.\n */\nexport function validateLink(\n link: string,\n isOnPhishingList: (url: string) => boolean,\n) {\n try {\n const url = new URL(link);\n assert(\n ALLOWED_PROTOCOLS.includes(url.protocol),\n `Protocol must be one of: ${ALLOWED_PROTOCOLS.join(', ')}.`,\n );\n\n const hostname =\n url.protocol === 'mailto:' ? url.pathname.split('@')[1] : url.hostname;\n\n assert(!isOnPhishingList(hostname), 'The specified URL is not allowed.');\n } catch (error) {\n throw new Error(\n `Invalid URL: ${\n error?.code === 'ERR_ASSERTION' ? error.message : 'Unable to parse URL.'\n }`,\n );\n }\n}\n\n/**\n * Search for Markdown links in a string and checks them against the phishing\n * list.\n *\n * @param text - The text to verify.\n * @param isOnPhishingList - The function that checks the link against the\n * phishing list.\n * @throws If the text contains a link that is not allowed.\n */\nexport function validateTextLinks(\n text: string,\n isOnPhishingList: (url: string) => boolean,\n) {\n const links = getMarkdownLinks(text);\n\n for (const link of links) {\n validateLink(link.href, isOnPhishingList);\n }\n}\n\n/**\n * Walk a JSX tree and validate each {@link LinkElement} node against the\n * phishing list.\n *\n * @param node - The JSX node to walk.\n * @param isOnPhishingList - The function that checks the link against the\n * phishing list.\n */\nexport function validateJsxLinks(\n node: JSXElement,\n isOnPhishingList: (url: string) => boolean,\n) {\n walkJsx(node, (childNode) => {\n if (childNode.type !== 'Link') {\n return;\n }\n\n validateLink(childNode.props.href, isOnPhishingList);\n });\n}\n\n/**\n * Calculate the total length of all text in the component.\n *\n * @param component - A custom UI component.\n * @returns The total length of all text components in the component.\n */\nexport function getTotalTextLength(component: Component): number {\n const { type } = component;\n\n switch (type) {\n case NodeType.Panel:\n return component.children.reduce(\n // This is a bug in TypeScript: https://github.com/microsoft/TypeScript/issues/48313\n // eslint-disable-next-line @typescript-eslint/restrict-plus-operands\n (sum, node) => sum + getTotalTextLength(node),\n 0,\n );\n\n case NodeType.Row:\n return getTotalTextLength(component.value);\n\n case NodeType.Text:\n return component.value.length;\n\n default:\n return 0;\n }\n}\n\n/**\n * Check if a JSX element has children.\n *\n * @param element - A JSX element.\n * @returns `true` if the element has children, `false` otherwise.\n */\nexport function hasChildren(\n element: Element,\n): element is Element & {\n props: { children: Nestable };\n} {\n return hasProperty(element.props, 'children');\n}\n\n/**\n * Filter a JSX child to remove `null`, `undefined`, plain booleans, and empty\n * strings.\n *\n * @param child - The JSX child to filter.\n * @returns `true` if the child is not `null`, `undefined`, a plain boolean, or\n * an empty string, `false` otherwise.\n */\nfunction filterJsxChild(child: JSXElement | string | boolean | null): boolean {\n return Boolean(child) && child !== true;\n}\n\n/**\n * Get the children of a JSX element as an array. If the element has only one\n * child, the child is returned as an array.\n *\n * @param element - A JSX element.\n * @returns The children of the element.\n */\nexport function getJsxChildren(element: JSXElement): (JSXElement | string)[] {\n if (hasChildren(element)) {\n if (Array.isArray(element.props.children)) {\n // @ts-expect-error - Each member of the union type has signatures, but\n // none of those signatures are compatible with each other.\n return element.props.children.filter(filterJsxChild).flat(Infinity);\n }\n\n if (element.props.children) {\n return [element.props.children];\n }\n }\n\n return [];\n}\n\n/**\n * Walk a JSX tree and call a callback on each node.\n *\n * @param node - The JSX node to walk.\n * @param callback - The callback to call on each node.\n * @param depth - The current depth in the JSX tree for a walk.\n * @returns The result of the callback, if any.\n */\nexport function walkJsx(\n node: JSXElement | JSXElement[],\n callback: (node: JSXElement, depth: number) => Value | undefined,\n depth = 0,\n): Value | undefined {\n if (Array.isArray(node)) {\n for (const child of node) {\n const childResult = walkJsx(child as JSXElement, callback, depth);\n if (childResult !== undefined) {\n return childResult;\n }\n }\n\n return undefined;\n }\n\n const result = callback(node, depth);\n if (result !== undefined) {\n return result;\n }\n\n if (\n hasProperty(node, 'props') &&\n isPlainObject(node.props) &&\n hasProperty(node.props, 'children')\n ) {\n const children = getJsxChildren(node);\n for (const child of children) {\n if (isPlainObject(child)) {\n const childResult = walkJsx(child, callback, depth + 1);\n if (childResult !== undefined) {\n return childResult;\n }\n }\n }\n }\n\n return undefined;\n}\n\n/**\n * Serialise a JSX prop to a string.\n *\n * @param prop - The JSX prop.\n * @returns The serialised JSX prop.\n */\nfunction serialiseProp(prop: unknown): string {\n if (typeof prop === 'string') {\n return `\"${prop}\"`;\n }\n\n return `{${JSON.stringify(prop)}}`;\n}\n\n/**\n * Serialise JSX props to a string.\n *\n * @param props - The JSX props.\n * @returns The serialised JSX props.\n */\nfunction serialiseProps(props: Record): string {\n return Object.entries(props)\n .filter(([key]) => key !== 'children')\n .sort(([a], [b]) => a.localeCompare(b))\n .map(([key, value]) => ` ${key}=${serialiseProp(value)}`)\n .join('');\n}\n\n/**\n * Serialise a JSX node to a string.\n *\n * @param node - The JSX node.\n * @param indentation - The indentation level. Defaults to `0`. This should not\n * be set by the caller, as it is used for recursion.\n * @returns The serialised JSX node.\n */\nexport function serialiseJsx(node: SnapNode, indentation = 0): string {\n if (Array.isArray(node)) {\n return node.map((child) => serialiseJsx(child, indentation)).join('');\n }\n\n const indent = ' '.repeat(indentation);\n if (typeof node === 'string') {\n return `${indent}${node}\\n`;\n }\n\n if (!node) {\n return '';\n }\n\n const { type, props } = node as GenericSnapElement;\n const trailingNewline = indentation > 0 ? '\\n' : '';\n\n if (hasProperty(props, 'children')) {\n const children = serialiseJsx(props.children as SnapNode, indentation + 1);\n return `${indent}<${type}${serialiseProps(\n props,\n )}>\\n${children}${indent}${trailingNewline}`;\n }\n\n return `${indent}<${type}${serialiseProps(props)} />${trailingNewline}`;\n}\n"]} +\ No newline at end of file ++{"version":3,"file":"ui.cjs","sourceRoot":"","sources":["../src/ui.tsx"],"names":[],"mappings":";;;;AACA,mDAA+C;AAa/C,iDAiBiC;AACjC,2CAKyB;AACzB,mCAA2C;AAG3C,MAAM,eAAe,GAAG,KAAM,CAAC,CAAC,QAAQ;AACxC,MAAM,iBAAiB,GAAG,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC;AAEhD;;;;;GAKG;AACH,SAAS,gBAAgB,CAAC,OAA6C;IACrE,QAAQ,OAAO,EAAE,CAAC;QAChB,KAAK,SAAS;YACZ,OAAO,SAAS,CAAC;QACnB,KAAK,WAAW;YACd,OAAO,aAAa,CAAC;QACvB;YACE,OAAO,SAA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';\nimport type {\n BoldChildren,\n GenericSnapElement,\n ItalicChildren,\n JSXElement,\n LinkElement,\n Nestable,\n RowChildren,\n SnapNode,\n StandardFormattingElement,\n TextChildren,\n} from '@metamask/snaps-sdk/jsx';\nimport {\n Italic,\n Link,\n Bold,\n Row,\n Text,\n Field,\n Image,\n Input,\n Heading,\n Form,\n Divider,\n Spinner,\n Copyable,\n Box,\n Button,\n Address,\n} from '@metamask/snaps-sdk/jsx';\nimport {\n assert,\n assertExhaustive,\n hasProperty,\n isPlainObject,\n} from '@metamask/utils';\nimport { lexer, walkTokens } from 'marked';\nimport type { Token, Tokens } from 'marked';\n\nconst MAX_TEXT_LENGTH = 50_000; // 50 kb\nconst ALLOWED_PROTOCOLS = ['https:', 'mailto:'];\n\n/**\n * Get the button variant from a legacy button component variant.\n *\n * @param variant - The legacy button component variant.\n * @returns The button variant.\n */\nfunction getButtonVariant(variant?: 'primary' | 'secondary' | undefined) {\n switch (variant) {\n case 'primary':\n return 'primary';\n case 'secondary':\n return 'destructive';\n default:\n return undefined;\n }\n}\n\n/**\n * Get the children of a JSX element. If there is only one child, the child is\n * returned directly. Otherwise, the children are returned as an array.\n *\n * @param elements - The JSX elements.\n * @returns The child or children.\n */\nfunction getChildren(elements: Type[]) {\n if (elements.length === 1) {\n return elements[0];\n }\n\n return elements;\n}\n\n/**\n * Get the text of a link token.\n *\n * @param token - The link token.\n * @returns The text of the link token.\n */\nfunction getLinkText(token: Tokens.Link | Tokens.Generic) {\n if (token.tokens && token.tokens.length > 0) {\n return getChildren(token.tokens.flatMap(getTextChildFromToken));\n }\n\n return token.href;\n}\n\n/**\n * Get the text child from a list of markdown tokens.\n *\n * @param tokens - The markdown tokens.\n * @returns The text child.\n */\nfunction getTextChildFromTokens(tokens: Token[]) {\n return getChildren(tokens.flatMap(getTextChildFromToken));\n}\n\n/**\n * Get the text child from a markdown token.\n *\n * @param token - The markdown token.\n * @returns The text child.\n */\nfunction getTextChildFromToken(token: Token): TextChildren {\n switch (token.type) {\n case 'link': {\n return ;\n }\n\n case 'text':\n return token.text;\n\n case 'strong':\n return (\n \n {\n getTextChildFromTokens(\n // Due to the way `marked` is typed, `token.tokens` can be\n // `undefined`, but it's a required field of `Tokens.Bold`, so we\n // can safely cast it to `Token[]`.\n token.tokens as Token[],\n ) as BoldChildren\n }\n \n );\n\n case 'em':\n return (\n \n {\n getTextChildFromTokens(\n // Due to the way `marked` is typed, `token.tokens` can be\n // `undefined`, but it's a required field of `Tokens.Bold`, so we\n // can safely cast it to `Token[]`.\n token.tokens as Token[],\n ) as ItalicChildren\n }\n \n );\n\n default:\n return null;\n }\n}\n\n/**\n * Get all text children from a markdown string.\n *\n * @param value - The markdown string.\n * @returns The text children.\n */\nexport function getTextChildren(\n value: string,\n): (string | StandardFormattingElement | LinkElement)[] {\n const rootTokens = lexer(value, { gfm: false });\n const children: (string | StandardFormattingElement | LinkElement | null)[] =\n [];\n\n walkTokens(rootTokens, (token) => {\n if (token.type === 'paragraph') {\n if (children.length > 0) {\n children.push('\\n\\n');\n }\n\n const { tokens } = token as Tokens.Paragraph;\n // We do not need to consider nesting deeper than 1 level here and we can therefore cast.\n children.push(\n ...(tokens.flatMap(getTextChildFromToken) as (\n | string\n | StandardFormattingElement\n | LinkElement\n | null\n )[]),\n );\n }\n });\n\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion\n return children.filter((child) => child !== null) as (\n | string\n | StandardFormattingElement\n | LinkElement\n )[];\n}\n\n/**\n * Validate the text size of a component. The text size is the total length of\n * all text in the component.\n *\n * @param component - The component to validate.\n * @throws An error if the text size exceeds the maximum allowed size.\n */\nfunction validateComponentTextSize(component: Component) {\n const textSize = getTotalTextLength(component);\n assert(\n textSize <= MAX_TEXT_LENGTH,\n `The text in a Snap UI may not be larger than ${\n MAX_TEXT_LENGTH / 1000\n } kB.`,\n );\n}\n\n/**\n * Get a JSX element from a legacy UI component. This supports all legacy UI\n * components, and maps them to their JSX equivalents where possible.\n *\n * This function validates the text size of the component, but does not validate\n * the total size. The total size of the component should be validated before\n * calling this function.\n *\n * @param legacyComponent - The legacy UI component.\n * @returns The JSX element.\n */\nexport function getJsxElementFromComponent(\n legacyComponent: Component,\n): JSXElement {\n validateComponentTextSize(legacyComponent);\n\n /**\n * Get the JSX element for a component. This function is recursive and will\n * call itself for child components.\n *\n * @param component - The component to convert to a JSX element.\n * @returns The JSX element.\n */\n function getElement(component: Component) {\n switch (component.type) {\n case NodeType.Address:\n return
;\n\n case NodeType.Button:\n return (\n \n {component.value}\n \n );\n\n case NodeType.Copyable:\n return (\n \n );\n\n case NodeType.Divider:\n return ;\n\n case NodeType.Form:\n return (\n
\n {getChildren(component.children.map(getElement))}\n
\n );\n\n case NodeType.Heading:\n return ;\n\n case NodeType.Image:\n // `Image` supports `alt`, but the legacy `Image` component does not.\n return ;\n\n case NodeType.Input:\n return (\n \n \n \n );\n\n case NodeType.Panel:\n // `Panel` is renamed to `Box` in JSX.\n return (\n \n );\n\n case NodeType.Row:\n return (\n \n {getElement(component.value) as RowChildren}\n \n );\n\n case NodeType.Spinner:\n return ;\n\n case NodeType.Text:\n return {getChildren(getTextChildren(component.value))};\n\n /* istanbul ignore next 2 */\n default:\n return assertExhaustive(component);\n }\n }\n\n return getElement(legacyComponent);\n}\n\n/**\n * Extract all links from a Markdown text string using the `marked` lexer.\n *\n * @param text - The markdown text string.\n * @returns A list of URLs linked to in the string.\n */\nfunction getMarkdownLinks(text: string) {\n const tokens = lexer(text, { gfm: false });\n const links: Tokens.Link[] = [];\n\n // Walk the lexed tokens and collect all link tokens\n walkTokens(tokens, (token) => {\n if (token.type === 'link') {\n links.push(token as Tokens.Link);\n }\n });\n\n return links;\n}\n\n/**\n * Validate a link against the phishing list.\n *\n * @param link - The link to validate.\n * @param isOnPhishingList - The function that checks the link against the\n * phishing list.\n * @throws If the link is invalid.\n */\nexport function validateLink(\n link: string,\n isOnPhishingList: (url: string) => boolean,\n) {\n try {\n const url = new URL(link);\n assert(\n ALLOWED_PROTOCOLS.includes(url.protocol),\n `Protocol must be one of: ${ALLOWED_PROTOCOLS.join(', ')}.`,\n );\n\n if (url.protocol === 'mailto:') {\n const emails = url.pathname.split(',');\n for (const email of emails) {\n const hostname = email.split('@')[1];\n assert(!hostname.includes(':'));\n const href = `https://${hostname}`;\n assert(!isOnPhishingList(href), 'The specified URL is not allowed.');\n }\n\n return;\n }\n\n assert(!isOnPhishingList(url.href), 'The specified URL is not allowed.');\n } catch (error) {\n throw new Error(\n `Invalid URL: ${\n error?.code === 'ERR_ASSERTION' ? error.message : 'Unable to parse URL.'\n }`,\n );\n }\n}\n\n/**\n * Search for Markdown links in a string and checks them against the phishing\n * list.\n *\n * @param text - The text to verify.\n * @param isOnPhishingList - The function that checks the link against the\n * phishing list.\n * @throws If the text contains a link that is not allowed.\n */\nexport function validateTextLinks(\n text: string,\n isOnPhishingList: (url: string) => boolean,\n) {\n const links = getMarkdownLinks(text);\n\n for (const link of links) {\n validateLink(link.href, isOnPhishingList);\n }\n}\n\n/**\n * Walk a JSX tree and validate each {@link LinkElement} node against the\n * phishing list.\n *\n * @param node - The JSX node to walk.\n * @param isOnPhishingList - The function that checks the link against the\n * phishing list.\n */\nexport function validateJsxLinks(\n node: JSXElement,\n isOnPhishingList: (url: string) => boolean,\n) {\n walkJsx(node, (childNode) => {\n if (childNode.type !== 'Link') {\n return;\n }\n\n validateLink(childNode.props.href, isOnPhishingList);\n });\n}\n\n/**\n * Calculate the total length of all text in the component.\n *\n * @param component - A custom UI component.\n * @returns The total length of all text components in the component.\n */\nexport function getTotalTextLength(component: Component): number {\n const { type } = component;\n\n switch (type) {\n case NodeType.Panel:\n return component.children.reduce(\n // This is a bug in TypeScript: https://github.com/microsoft/TypeScript/issues/48313\n // eslint-disable-next-line @typescript-eslint/restrict-plus-operands\n (sum, node) => sum + getTotalTextLength(node),\n 0,\n );\n\n case NodeType.Row:\n return getTotalTextLength(component.value);\n\n case NodeType.Text:\n return component.value.length;\n\n default:\n return 0;\n }\n}\n\n/**\n * Check if a JSX element has children.\n *\n * @param element - A JSX element.\n * @returns `true` if the element has children, `false` otherwise.\n */\nexport function hasChildren(\n element: Element,\n): element is Element & {\n props: { children: Nestable };\n} {\n return hasProperty(element.props, 'children');\n}\n\n/**\n * Filter a JSX child to remove `null`, `undefined`, plain booleans, and empty\n * strings.\n *\n * @param child - The JSX child to filter.\n * @returns `true` if the child is not `null`, `undefined`, a plain boolean, or\n * an empty string, `false` otherwise.\n */\nfunction filterJsxChild(child: JSXElement | string | boolean | null): boolean {\n return Boolean(child) && child !== true;\n}\n\n/**\n * Get the children of a JSX element as an array. If the element has only one\n * child, the child is returned as an array.\n *\n * @param element - A JSX element.\n * @returns The children of the element.\n */\nexport function getJsxChildren(element: JSXElement): (JSXElement | string)[] {\n if (hasChildren(element)) {\n if (Array.isArray(element.props.children)) {\n // @ts-expect-error - Each member of the union type has signatures, but\n // none of those signatures are compatible with each other.\n return element.props.children.filter(filterJsxChild).flat(Infinity);\n }\n\n if (element.props.children) {\n return [element.props.children];\n }\n }\n\n return [];\n}\n\n/**\n * Walk a JSX tree and call a callback on each node.\n *\n * @param node - The JSX node to walk.\n * @param callback - The callback to call on each node.\n * @param depth - The current depth in the JSX tree for a walk.\n * @returns The result of the callback, if any.\n */\nexport function walkJsx(\n node: JSXElement | JSXElement[],\n callback: (node: JSXElement, depth: number) => Value | undefined,\n depth = 0,\n): Value | undefined {\n if (Array.isArray(node)) {\n for (const child of node) {\n const childResult = walkJsx(child as JSXElement, callback, depth);\n if (childResult !== undefined) {\n return childResult;\n }\n }\n\n return undefined;\n }\n\n const result = callback(node, depth);\n if (result !== undefined) {\n return result;\n }\n\n if (\n hasProperty(node, 'props') &&\n isPlainObject(node.props) &&\n hasProperty(node.props, 'children')\n ) {\n const children = getJsxChildren(node);\n for (const child of children) {\n if (isPlainObject(child)) {\n const childResult = walkJsx(child, callback, depth + 1);\n if (childResult !== undefined) {\n return childResult;\n }\n }\n }\n }\n\n return undefined;\n}\n\n/**\n * Serialise a JSX prop to a string.\n *\n * @param prop - The JSX prop.\n * @returns The serialised JSX prop.\n */\nfunction serialiseProp(prop: unknown): string {\n if (typeof prop === 'string') {\n return `\"${prop}\"`;\n }\n\n return `{${JSON.stringify(prop)}}`;\n}\n\n/**\n * Serialise JSX props to a string.\n *\n * @param props - The JSX props.\n * @returns The serialised JSX props.\n */\nfunction serialiseProps(props: Record): string {\n return Object.entries(props)\n .filter(([key]) => key !== 'children')\n .sort(([a], [b]) => a.localeCompare(b))\n .map(([key, value]) => ` ${key}=${serialiseProp(value)}`)\n .join('');\n}\n\n/**\n * Serialise a JSX node to a string.\n *\n * @param node - The JSX node.\n * @param indentation - The indentation level. Defaults to `0`. This should not\n * be set by the caller, as it is used for recursion.\n * @returns The serialised JSX node.\n */\nexport function serialiseJsx(node: SnapNode, indentation = 0): string {\n if (Array.isArray(node)) {\n return node.map((child) => serialiseJsx(child, indentation)).join('');\n }\n\n const indent = ' '.repeat(indentation);\n if (typeof node === 'string') {\n return `${indent}${node}\\n`;\n }\n\n if (!node) {\n return '';\n }\n\n const { type, props } = node as GenericSnapElement;\n const trailingNewline = indentation > 0 ? '\\n' : '';\n\n if (hasProperty(props, 'children')) {\n const children = serialiseJsx(props.children as SnapNode, indentation + 1);\n return `${indent}<${type}${serialiseProps(\n props,\n )}>\\n${children}${indent}${trailingNewline}`;\n }\n\n return `${indent}<${type}${serialiseProps(props)} />${trailingNewline}`;\n}\n"]} +\ No newline at end of file +diff --git a/dist/ui.d.cts b/dist/ui.d.cts +index c9bd215bf861b83df1d9b63acd586d71a37d896f..b7e6a58104694f96ac1f1608492fe71182a1c15f 100644 +--- a/dist/ui.d.cts ++++ b/dist/ui.d.cts +@@ -25,6 +25,7 @@ export declare function getJsxElementFromComponent(legacyComponent: Component): + * @param link - The link to validate. + * @param isOnPhishingList - The function that checks the link against the + * phishing list. ++ * @throws If the link is invalid. + */ + export declare function validateLink(link: string, isOnPhishingList: (url: string) => boolean): void; + /** +diff --git a/dist/ui.d.cts.map b/dist/ui.d.cts.map +index 7c6a6f95c8aa97d0e048e32d4f76c46a0cd7bd15..66fa95b636d7dc2e8d467e129dccc410b9b27b8a 100644 +--- a/dist/ui.d.cts.map ++++ b/dist/ui.d.cts.map +@@ -1 +1 @@ +-{"version":3,"file":"ui.d.cts","sourceRoot":"","sources":["../src/ui.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AAErD,OAAO,KAAK,EAIV,UAAU,EACV,WAAW,EACX,QAAQ,EAER,QAAQ,EACR,yBAAyB,EAE1B,gCAAgC;AAuIjC;;;;;GAKG;AACH,wBAAgB,eAAe,CAC7B,KAAK,EAAE,MAAM,GACZ,CAAC,MAAM,GAAG,yBAAyB,GAAG,WAAW,CAAC,EAAE,CA8BtD;AAmBD;;;;;;;;;;GAUG;AACH,wBAAgB,0BAA0B,CACxC,eAAe,EAAE,SAAS,GACzB,UAAU,CAsFZ;AAsBD;;;;;;GAMG;AACH,wBAAgB,YAAY,CAC1B,IAAI,EAAE,MAAM,EACZ,gBAAgB,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,QAoB3C;AAED;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,MAAM,EACZ,gBAAgB,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,QAO3C;AAED;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAC9B,IAAI,EAAE,UAAU,EAChB,gBAAgB,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,QAS3C;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,SAAS,GAAG,MAAM,CAqB/D;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,OAAO,SAAS,UAAU,EACpD,OAAO,EAAE,OAAO,GACf,OAAO,IAAI,OAAO,GAAG;IACtB,KAAK,EAAE;QAAE,QAAQ,EAAE,QAAQ,CAAC,UAAU,GAAG,MAAM,CA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EAAE,UAAU,EAChB,gBAAgB,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,QAS3C;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,SAAS,GAAG,MAAM,CAqB/D;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,OAAO,SAAS,UAAU,EACpD,OAAO,EAAE,OAAO,GACf,OAAO,IAAI,OAAO,GAAG;IACtB,KAAK,EAAE;QAAE,QAAQ,EAAE,QAAQ,CAAC,UAAU,GAAG,MAAM,CAAC,CAAA;KAAE,CAAC;CACpD,CAEA;AAcD;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,UAAU,GAAG,CAAC,UAAU,GAAG,MAAM,CAAC,EAAE,CAc3E;AAED;;;;;;;GAOG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAC3B,IAAI,EAAE,UAAU,GAAG,UAAU,EAAE,EAC/B,QAAQ,EAAE,CAAC,IAAI,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,KAAK,KAAK,GAAG,SAAS,EAChE,KAAK,SAAI,GACR,KAAK,GAAG,SAAS,CAkCnB;AA8BD;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,QAAQ,EAAE,WAAW,SAAI,GAAG,MAAM,CAyBpE"} +\ No newline at end of file +diff --git a/dist/ui.d.mts b/dist/ui.d.mts +index 9047d932564925a86e7b82a09b17c72aee1273fe..a34aa56c5cdd8fcb7022cebbb036665a180c3d05 100644 +--- a/dist/ui.d.mts ++++ b/dist/ui.d.mts +@@ -25,6 +25,7 @@ export declare function getJsxElementFromComponent(legacyComponent: Component): + * @param link - The link to validate. + * @param isOnPhishingList - The function that checks the link against the + * phishing list. ++ * @throws If the link is invalid. + */ + export declare function validateLink(link: string, isOnPhishingList: (url: string) => boolean): void; + /** +diff --git a/dist/ui.d.mts.map b/dist/ui.d.mts.map +index e2a961017b4f1cf120155b371776653e1a1d9d0b..d551ff82192402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C;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,SAAS,GAAG,MAAM,CAqB/D;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,OAAO,SAAS,UAAU,EACpD,OAAO,EAAE,OAAO,GACf,OAAO,IAAI,OAAO,GAAG;IACtB,KAAK,EAAE;QAAE,QAAQ,EAAE,QAAQ,CAAC,UAAU,GAAG,MAAM,CAAC,CAAA;KAAE,CAAC;CACpD,CAEA;AAcD;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,UAAU,GAAG,CAAC,UAAU,GAAG,MAAM,CAAC,EAAE,CAc3E;AAED;;;;;;;GAOG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAC3B,IAAI,EAAE,UAAU,GAAG,UAAU,EAAE,EAC/B,QAAQ,EAAE,CAAC,IAAI,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,KAAK,KAAK,GAAG,SAAS,EAChE,KAAK,SAAI,GACR,KAAK,GAAG,SAAS,CAkCnB;AA8BD;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,QAAQ,EAAE,WAAW,SAAI,GAAG,MAAM,CAyBpE"} +\ No newline at end of file +diff --git a/dist/ui.mjs b/dist/ui.mjs +index 11b2b5625df002c0962216a06f258869ba65e06b..7499feea1cd9df0d90d2756741bc8e035200506f 100644 +--- a/dist/ui.mjs ++++ b/dist/ui.mjs +@@ -195,13 +195,23 @@ function getMarkdownLinks(text) { + * @param link - The link to validate. + * @param isOnPhishingList - The function that checks the link against the + * phishing list. ++ * @throws If the link is invalid. + */ + export function validateLink(link, isOnPhishingList) { + try { + const url = new URL(link); + assert(ALLOWED_PROTOCOLS.includes(url.protocol), `Protocol must be one of: ${ALLOWED_PROTOCOLS.join(', ')}.`); +- const hostname = url.protocol === 'mailto:' ? url.pathname.split('@')[1] : url.hostname; +- assert(!isOnPhishingList(hostname), 'The specified URL is not allowed.'); ++ if (url.protocol === 'mailto:') { ++ const emails = url.pathname.split(','); ++ for (const email of emails) { ++ const hostname = email.split('@')[1]; ++ assert(!hostname.includes(':')); ++ const href = `https://${hostname}`; ++ assert(!isOnPhishingList(href), 'The specified URL is not allowed.'); ++ } ++ return; ++ } ++ assert(!isOnPhishingList(url.href), 'The specified URL is not allowed.'); + } + catch (error) { + throw new Error(`Invalid URL: ${error?.code === 'ERR_ASSERTION' ? error.message : 'Unable to parse URL.'}`); +diff --git a/dist/ui.mjs.map b/dist/ui.mjs.map +index 1600ced3d6bfc87a5b75328b776dc93e54402201..0d1ffdd50173f534e9dc2ce041ca83e7926750b0 100644 +--- a/dist/ui.mjs.map ++++ b/dist/ui.mjs.map +@@ -1 +1 @@ +-{"version":3,"file":"ui.mjs","sourceRoot":"","sources":["../src/ui.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,QAAQ,EAAE,4BAA4B;AAa/C,OAAO,EACL,MAAM,EACN,IAAI,EACJ,IAAI,EACJ,GAAG,EACH,IAAI,EACJ,KAAK,EACL,KAAK,EACL,KAAK,EACL,OAAO,EACP,IAAI,EACJ,OAAO,EACP,OAAO,EACP,QAAQ,EACR,GAAG,EACH,MAAM,EACN,OAAO,EACR,gCAAgC;AACjC,OAAO,EACL,MAAM,EACN,gBAAgB,EAChB,WAAW,EACX,aAAa,EACd,wBAAwB;AACzB,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,eAAe;AAG3C,MAAM,eAAe,GAAG,KAAM,CAAC,CAAC,QAAQ;AACxC,MAAM,iBAAiB,GAAG,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC;AAEhD;;;;;GAKG;AACH,SAAS,gBAAgB,CAAC,OAA6C;IACrE,QAAQ,OAAO,EAAE,CAAC;QAChB,KAAK,SAAS;YACZ,OAAO,SAAS,CAAC;QACnB,KAAK,WAAW;YACd,OAAO,aAAa,CAAC;QACvB;YACE,OAAO,SAAS,CAAC;IACrB,CAAC;AACH,CAAC;AAED;;;;;;GAMG;AACH,SAAS,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E,IAAI,EAAE,KAAK,EAAE,GAAG,IAA0B,CAAC;IACnD,MAAM,eAAe,GAAG,WAAW,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;IAEpD,IAAI,WAAW,CAAC,KAAK,EAAE,UAAU,CAAC,EAAE,CAAC;QACnC,MAAM,QAAQ,GAAG,YAAY,CAAC,KAAK,CAAC,QAAoB,EAAE,WAAW,GAAG,CAAC,CAAC,CAAC;QAC3E,OAAO,GAAG,MAAM,IAAI,IAAI,GAAG,cAAc,CACvC,KAAK,CACN,MAAM,QAAQ,GAAG,MAAM,KAAK,IAAI,IAAI,eAAe,EAAE,CAAC;IACzD,CAAC;IAED,OAAO,GAAG,MAAM,IAAI,IAAI,GAAG,cAAc,CAAC,KAAK,CAAC,MAAM,eAAe,EAAE,CAAC;AAC1E,CAAC","sourcesContent":["import type { Component } from '@metamask/snaps-sdk';\nimport { NodeType } from '@metamask/snaps-sdk';\nimport type {\n BoldChildren,\n GenericSnapElement,\n ItalicChildren,\n JSXElement,\n LinkElement,\n Nestable,\n RowChildren,\n SnapNode,\n StandardFormattingElement,\n TextChildren,\n} from '@metamask/snaps-sdk/jsx';\nimport {\n Italic,\n Link,\n Bold,\n Row,\n Text,\n Field,\n Image,\n Input,\n Heading,\n Form,\n Divider,\n Spinner,\n Copyable,\n Box,\n Button,\n Address,\n} from '@metamask/snaps-sdk/jsx';\nimport {\n assert,\n assertExhaustive,\n hasProperty,\n isPlainObject,\n} from '@metamask/utils';\nimport { lexer, walkTokens } from 'marked';\nimport type { Token, Tokens } from 'marked';\n\nconst MAX_TEXT_LENGTH = 50_000; // 50 kb\nconst ALLOWED_PROTOCOLS = ['https:', 'mailto:'];\n\n/**\n * Get the button variant from a legacy button component variant.\n *\n * @param variant - The legacy button component variant.\n * @returns The button variant.\n */\nfunction getButtonVariant(variant?: 'primary' | 'secondary' | undefined) {\n switch (variant) {\n case 'primary':\n return 'primary';\n case 'secondary':\n return 'destructive';\n default:\n return undefined;\n }\n}\n\n/**\n * Get the children of a JSX element. If there is only one child, the child is\n * returned directly. Otherwise, the children are returned as an array.\n *\n * @param elements - The JSX elements.\n * @returns The child or children.\n */\nfunction getChildren(elements: Type[]) {\n if (elements.length === 1) {\n return elements[0];\n }\n\n return elements;\n}\n\n/**\n * Get the text of a link token.\n *\n * @param token - The link token.\n * @returns The text of the link token.\n */\nfunction getLinkText(token: Tokens.Link | Tokens.Generic) {\n if (token.tokens && token.tokens.length > 0) {\n return getChildren(token.tokens.flatMap(getTextChildFromToken));\n }\n\n return token.href;\n}\n\n/**\n * Get the text child from a list of markdown tokens.\n *\n * @param tokens - The markdown tokens.\n * @returns The text child.\n */\nfunction getTextChildFromTokens(tokens: Token[]) {\n return getChildren(tokens.flatMap(getTextChildFromToken));\n}\n\n/**\n * Get the text child from a markdown token.\n *\n * @param token - The markdown token.\n * @returns The text child.\n */\nfunction getTextChildFromToken(token: Token): TextChildren {\n switch (token.type) {\n case 'link': {\n return ;\n }\n\n case 'text':\n return token.text;\n\n case 'strong':\n return (\n \n {\n getTextChildFromTokens(\n // Due to the way `marked` is typed, `token.tokens` can be\n // `undefined`, but it's a required field of `Tokens.Bold`, so we\n // can safely cast it to `Token[]`.\n token.tokens as Token[],\n ) as BoldChildren\n }\n \n );\n\n case 'em':\n return (\n \n {\n getTextChildFromTokens(\n // Due to the way `marked` is typed, `token.tokens` can be\n // `undefined`, but it's a required field of `Tokens.Bold`, so we\n // can safely cast it to `Token[]`.\n token.tokens as Token[],\n ) as ItalicChildren\n }\n \n );\n\n default:\n return null;\n }\n}\n\n/**\n * Get all text children from a markdown string.\n *\n * @param value - The markdown string.\n * @returns The text children.\n */\nexport function getTextChildren(\n value: string,\n): (string | StandardFormattingElement | LinkElement)[] {\n const rootTokens = lexer(value, { gfm: false });\n const children: (string | StandardFormattingElement | LinkElement | null)[] =\n [];\n\n walkTokens(rootTokens, (token) => {\n if (token.type === 'paragraph') {\n if (children.length > 0) {\n children.push('\\n\\n');\n }\n\n const { tokens } = token as Tokens.Paragraph;\n // We do not need to consider nesting deeper than 1 level here and we can therefore cast.\n children.push(\n ...(tokens.flatMap(getTextChildFromToken) as (\n | string\n | StandardFormattingElement\n | LinkElement\n | null\n )[]),\n );\n }\n });\n\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion\n return children.filter((child) => child !== null) as (\n | string\n | StandardFormattingElement\n | LinkElement\n )[];\n}\n\n/**\n * Validate the text size of a component. The text size is the total length of\n * all text in the component.\n *\n * @param component - The component to validate.\n * @throws An error if the text size exceeds the maximum allowed size.\n */\nfunction validateComponentTextSize(component: Component) {\n const textSize = getTotalTextLength(component);\n assert(\n textSize <= MAX_TEXT_LENGTH,\n `The text in a Snap UI may not be larger than ${\n MAX_TEXT_LENGTH / 1000\n } kB.`,\n );\n}\n\n/**\n * Get a JSX element from a legacy UI component. This supports all legacy UI\n * components, and maps them to their JSX equivalents where possible.\n *\n * This function validates the text size of the component, but does not validate\n * the total size. The total size of the component should be validated before\n * calling this function.\n *\n * @param legacyComponent - The legacy UI component.\n * @returns The JSX element.\n */\nexport function getJsxElementFromComponent(\n legacyComponent: Component,\n): JSXElement {\n validateComponentTextSize(legacyComponent);\n\n /**\n * Get the JSX element for a component. This function is recursive and will\n * call itself for child components.\n *\n * @param component - The component to convert to a JSX element.\n * @returns The JSX element.\n */\n function getElement(component: Component) {\n switch (component.type) {\n case NodeType.Address:\n return
;\n\n case NodeType.Button:\n return (\n \n {component.value}\n \n );\n\n case NodeType.Copyable:\n return (\n \n );\n\n case NodeType.Divider:\n return ;\n\n case NodeType.Form:\n return (\n
\n {getChildren(component.children.map(getElement))}\n
\n );\n\n case NodeType.Heading:\n return ;\n\n case NodeType.Image:\n // `Image` supports `alt`, but the legacy `Image` component does not.\n return ;\n\n case NodeType.Input:\n return (\n \n \n \n );\n\n case NodeType.Panel:\n // `Panel` is renamed to `Box` in JSX.\n return (\n \n );\n\n case NodeType.Row:\n return (\n \n {getElement(component.value) as RowChildren}\n \n );\n\n case NodeType.Spinner:\n return ;\n\n case NodeType.Text:\n return {getChildren(getTextChildren(component.value))};\n\n /* istanbul ignore next 2 */\n default:\n return assertExhaustive(component);\n }\n }\n\n return getElement(legacyComponent);\n}\n\n/**\n * Extract all links from a Markdown text string using the `marked` lexer.\n *\n * @param text - The markdown text string.\n * @returns A list of URLs linked to in the string.\n */\nfunction getMarkdownLinks(text: string) {\n const tokens = lexer(text, { gfm: false });\n const links: Tokens.Link[] = [];\n\n // Walk the lexed tokens and collect all link tokens\n walkTokens(tokens, (token) => {\n if (token.type === 'link') {\n links.push(token as Tokens.Link);\n }\n });\n\n return links;\n}\n\n/**\n * Validate a link against the phishing list.\n *\n * @param link - The link to validate.\n * @param isOnPhishingList - The function that checks the link against the\n * phishing list.\n */\nexport function validateLink(\n link: string,\n isOnPhishingList: (url: string) => boolean,\n) {\n try {\n const url = new URL(link);\n assert(\n ALLOWED_PROTOCOLS.includes(url.protocol),\n `Protocol must be one of: ${ALLOWED_PROTOCOLS.join(', ')}.`,\n );\n\n const hostname =\n url.protocol === 'mailto:' ? url.pathname.split('@')[1] : url.hostname;\n\n assert(!isOnPhishingList(hostname), 'The specified URL is not allowed.');\n } catch (error) {\n throw new Error(\n `Invalid URL: ${\n error?.code === 'ERR_ASSERTION' ? error.message : 'Unable to parse URL.'\n }`,\n );\n }\n}\n\n/**\n * Search for Markdown links in a string and checks them against the phishing\n * list.\n *\n * @param text - The text to verify.\n * @param isOnPhishingList - The function that checks the link against the\n * phishing list.\n * @throws If the text contains a link that is not allowed.\n */\nexport function validateTextLinks(\n text: string,\n isOnPhishingList: (url: string) => boolean,\n) {\n const links = getMarkdownLinks(text);\n\n for (const link of links) {\n validateLink(link.href, isOnPhishingList);\n }\n}\n\n/**\n * Walk a JSX tree and validate each {@link LinkElement} node against the\n * phishing list.\n *\n * @param node - The JSX node to walk.\n * @param isOnPhishingList - The function that checks the link against the\n * phishing list.\n */\nexport function validateJsxLinks(\n node: JSXElement,\n isOnPhishingList: (url: string) => boolean,\n) {\n walkJsx(node, (childNode) => {\n if (childNode.type !== 'Link') {\n return;\n }\n\n validateLink(childNode.props.href, isOnPhishingList);\n });\n}\n\n/**\n * Calculate the total length of all text in the component.\n *\n * @param component - A custom UI component.\n * @returns The total length of all text components in the component.\n */\nexport function getTotalTextLength(component: Component): number {\n const { type } = component;\n\n switch (type) {\n case NodeType.Panel:\n return component.children.reduce(\n // This is a bug in TypeScript: https://github.com/microsoft/TypeScript/issues/48313\n // eslint-disable-next-line @typescript-eslint/restrict-plus-operands\n (sum, node) => sum + getTotalTextLength(node),\n 0,\n );\n\n case NodeType.Row:\n return getTotalTextLength(component.value);\n\n case NodeType.Text:\n return component.value.length;\n\n default:\n return 0;\n }\n}\n\n/**\n * Check if a JSX element has children.\n *\n * @param element - A JSX element.\n * @returns `true` if the element has children, `false` otherwise.\n */\nexport function hasChildren(\n element: Element,\n): element is Element & {\n props: { children: Nestable };\n} {\n return hasProperty(element.props, 'children');\n}\n\n/**\n * Filter a JSX child to remove `null`, `undefined`, plain booleans, and empty\n * strings.\n *\n * @param child - The JSX child to filter.\n * @returns `true` if the child is not `null`, `undefined`, a plain boolean, or\n * an empty string, `false` otherwise.\n */\nfunction filterJsxChild(child: JSXElement | string | boolean | null): boolean {\n return Boolean(child) && child !== true;\n}\n\n/**\n * Get the children of a JSX element as an array. If the element has only one\n * child, the child is returned as an array.\n *\n * @param element - A JSX element.\n * @returns The children of the element.\n */\nexport function getJsxChildren(element: JSXElement): (JSXElement | string)[] {\n if (hasChildren(element)) {\n if (Array.isArray(element.props.children)) {\n // @ts-expect-error - Each member of the union type has signatures, but\n // none of those signatures are compatible with each other.\n return element.props.children.filter(filterJsxChild).flat(Infinity);\n }\n\n if (element.props.children) {\n return [element.props.children];\n }\n }\n\n return [];\n}\n\n/**\n * Walk a JSX tree and call a callback on each node.\n *\n * @param node - The JSX node to walk.\n * @param callback - The callback to call on each node.\n * @param depth - The current depth in the JSX tree for a walk.\n * @returns The result of the callback, if any.\n */\nexport function walkJsx(\n node: JSXElement | JSXElement[],\n callback: (node: JSXElement, depth: number) => Value | undefined,\n depth = 0,\n): Value | undefined {\n if (Array.isArray(node)) {\n for (const child of node) {\n const childResult = walkJsx(child as JSXElement, callback, depth);\n if (childResult !== undefined) {\n return childResult;\n }\n }\n\n return undefined;\n }\n\n const result = callback(node, depth);\n if (result !== undefined) {\n return result;\n }\n\n if (\n hasProperty(node, 'props') &&\n isPlainObject(node.props) &&\n hasProperty(node.props, 'children')\n ) {\n const children = getJsxChildren(node);\n for (const child of children) {\n if (isPlainObject(child)) {\n const childResult = walkJsx(child, callback, depth + 1);\n if (childResult !== undefined) {\n return childResult;\n }\n }\n }\n }\n\n return undefined;\n}\n\n/**\n * Serialise a JSX prop to a string.\n *\n * @param prop - The JSX prop.\n * @returns The serialised JSX prop.\n */\nfunction serialiseProp(prop: unknown): string {\n if (typeof prop === 'string') {\n return `\"${prop}\"`;\n }\n\n return `{${JSON.stringify(prop)}}`;\n}\n\n/**\n * Serialise JSX props to a string.\n *\n * @param props - The JSX props.\n * @returns The serialised JSX props.\n */\nfunction serialiseProps(props: Record): string {\n return Object.entries(props)\n .filter(([key]) => key !== 'children')\n .sort(([a], [b]) => a.localeCompare(b))\n .map(([key, value]) => ` ${key}=${serialiseProp(value)}`)\n .join('');\n}\n\n/**\n * Serialise a JSX node to a string.\n *\n * @param node - The JSX node.\n * @param indentation - The indentation level. Defaults to `0`. This should not\n * be set by the caller, as it is used for recursion.\n * @returns The serialised JSX node.\n */\nexport function serialiseJsx(node: SnapNode, indentation = 0): string {\n if (Array.isArray(node)) {\n return node.map((child) => serialiseJsx(child, indentation)).join('');\n }\n\n const indent = ' '.repeat(indentation);\n if (typeof node === 'string') {\n return `${indent}${node}\\n`;\n }\n\n if (!node) {\n return '';\n }\n\n const { type, props } = node as GenericSnapElement;\n const trailingNewline = indentation > 0 ? '\\n' : '';\n\n if (hasProperty(props, 'children')) {\n const children = serialiseJsx(props.children as SnapNode, indentation + 1);\n return `${indent}<${type}${serialiseProps(\n props,\n )}>\\n${children}${indent}${trailingNewline}`;\n }\n\n return `${indent}<${type}${serialiseProps(props)} />${trailingNewline}`;\n}\n"]} +\ No newline at end of file ++{"version":3,"file":"ui.mjs","sourceRoot":"","sources":["../src/ui.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,QAAQ,EAAE,4BAA4B;AAa/C,OAAO,EACL,MAAM,EACN,IAAI,EACJ,IAAI,EACJ,GAAG,EACH,IAAI,EACJ,KAAK,EACL,KAAK,EACL,KAAK,EACL,OAAO,EACP,IAAI,EACJ,OAAO,EACP,OAAO,EACP,QAAQ,EACR,GAAG,EACH,MAAM,EACN,OAAO,EACR,gCAAgC;AACjC,OAAO,EACL,MAAM,EACN,gBAAgB,EAChB,WAAW,EACX,aAAa,EACd,wBAAwB;AACzB,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,eAAe;AAG3C,MAAM,eAAe,GAAG,KAAM,CAAC,CAAC,QAAQ;AACxC,MAAM,iBAAiB,GAAG,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC;AAEhD;;;;;GAKG;AACH,SAAS,gBAAgB,CAAC,OAA6C;IACrE,QAAQ,OAAO,EAAE,CAAC;QAChB,KAAK,SAAS;YACZ,OAAO,SAAS,CAAC;QACnB,KAAK,WAAW;YACd,OAAO,aAAa,CAAC;QACvB;YACE,OAAO,SAAS,CAAC;IACrB,CAAC;AACH,CAAC;AAED;;;;;;GAMG;AACH,SAAS,WAAW,CAAO,QAAgB;IACzC,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC1B,OAAO,QAAQ,CAAC,CAAC,CAAC,CAAC;IACrB,CAAC;IAED,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED;;;;;GAKG;AACH,SAAS,WAAW,CAAC,KAAmC;IACtD,IAAI,KAAK,CAAC,MAAM,IAAI,KAAK,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;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AAC;IACZ,CAAC;IAED,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,IAA0B,CAAC;IACnD,MAAM,eAAe,GAAG,WAAW,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;IAEpD,IAAI,WAAW,CAAC,KAAK,EAAE,UAAU,CAAC,EAAE,CAAC;QACnC,MAAM,QAAQ,GAAG,YAAY,CAAC,KAAK,CAAC,QAAoB,EAAE,WAAW,GAAG,CAAC,CAAC,CAAC;QAC3E,OAAO,GAAG,MAAM,IAAI,IAAI,GAAG,cAAc,CACvC,KAAK,CACN,MAAM,QAAQ,GAAG,MAAM,KAAK,IAAI,IAAI,eAAe,EAAE,CAAC;IACzD,CAAC;IAED,OAAO,GAAG,MAAM,IAAI,IAAI,GAAG,cAAc,CAAC,KAAK,CAAC,MAAM,eAAe,EAAE,CAAC;AAC1E,CAAC","sourcesContent":["import type { Component } from '@metamask/snaps-sdk';\nimport { NodeType } from '@metamask/snaps-sdk';\nimport type {\n BoldChildren,\n GenericSnapElement,\n ItalicChildren,\n JSXElement,\n LinkElement,\n Nestable,\n RowChildren,\n SnapNode,\n StandardFormattingElement,\n TextChildren,\n} from '@metamask/snaps-sdk/jsx';\nimport {\n Italic,\n Link,\n Bold,\n Row,\n Text,\n Field,\n Image,\n Input,\n Heading,\n Form,\n Divider,\n Spinner,\n Copyable,\n Box,\n Button,\n Address,\n} from '@metamask/snaps-sdk/jsx';\nimport {\n assert,\n assertExhaustive,\n hasProperty,\n isPlainObject,\n} from '@metamask/utils';\nimport { lexer, walkTokens } from 'marked';\nimport type { Token, Tokens } from 'marked';\n\nconst MAX_TEXT_LENGTH = 50_000; // 50 kb\nconst ALLOWED_PROTOCOLS = ['https:', 'mailto:'];\n\n/**\n * Get the button variant from a legacy button component variant.\n *\n * @param variant - The legacy button component variant.\n * @returns The button variant.\n */\nfunction getButtonVariant(variant?: 'primary' | 'secondary' | undefined) {\n switch (variant) {\n case 'primary':\n return 'primary';\n case 'secondary':\n return 'destructive';\n default:\n return undefined;\n }\n}\n\n/**\n * Get the children of a JSX element. If there is only one child, the child is\n * returned directly. Otherwise, the children are returned as an array.\n *\n * @param elements - The JSX elements.\n * @returns The child or children.\n */\nfunction getChildren(elements: Type[]) {\n if (elements.length === 1) {\n return elements[0];\n }\n\n return elements;\n}\n\n/**\n * Get the text of a link token.\n *\n * @param token - The link token.\n * @returns The text of the link token.\n */\nfunction getLinkText(token: Tokens.Link | Tokens.Generic) {\n if (token.tokens && token.tokens.length > 0) {\n return getChildren(token.tokens.flatMap(getTextChildFromToken));\n }\n\n return token.href;\n}\n\n/**\n * Get the text child from a list of markdown tokens.\n *\n * @param tokens - The markdown tokens.\n * @returns The text child.\n */\nfunction getTextChildFromTokens(tokens: Token[]) {\n return getChildren(tokens.flatMap(getTextChildFromToken));\n}\n\n/**\n * Get the text child from a markdown token.\n *\n * @param token - The markdown token.\n * @returns The text child.\n */\nfunction getTextChildFromToken(token: Token): TextChildren {\n switch (token.type) {\n case 'link': {\n return ;\n }\n\n case 'text':\n return token.text;\n\n case 'strong':\n return (\n \n {\n getTextChildFromTokens(\n // Due to the way `marked` is typed, `token.tokens` can be\n // `undefined`, but it's a required field of `Tokens.Bold`, so we\n // can safely cast it to `Token[]`.\n token.tokens as Token[],\n ) as BoldChildren\n }\n \n );\n\n case 'em':\n return (\n \n {\n getTextChildFromTokens(\n // Due to the way `marked` is typed, `token.tokens` can be\n // `undefined`, but it's a required field of `Tokens.Bold`, so we\n // can safely cast it to `Token[]`.\n token.tokens as Token[],\n ) as ItalicChildren\n }\n \n );\n\n default:\n return null;\n }\n}\n\n/**\n * Get all text children from a markdown string.\n *\n * @param value - The markdown string.\n * @returns The text children.\n */\nexport function getTextChildren(\n value: string,\n): (string | StandardFormattingElement | LinkElement)[] {\n const rootTokens = lexer(value, { gfm: false });\n const children: (string | StandardFormattingElement | LinkElement | null)[] =\n [];\n\n walkTokens(rootTokens, (token) => {\n if (token.type === 'paragraph') {\n if (children.length > 0) {\n children.push('\\n\\n');\n }\n\n const { tokens } = token as Tokens.Paragraph;\n // We do not need to consider nesting deeper than 1 level here and we can therefore cast.\n children.push(\n ...(tokens.flatMap(getTextChildFromToken) as (\n | string\n | StandardFormattingElement\n | LinkElement\n | null\n )[]),\n );\n }\n });\n\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion\n return children.filter((child) => child !== null) as (\n | string\n | StandardFormattingElement\n | LinkElement\n )[];\n}\n\n/**\n * Validate the text size of a component. The text size is the total length of\n * all text in the component.\n *\n * @param component - The component to validate.\n * @throws An error if the text size exceeds the maximum allowed size.\n */\nfunction validateComponentTextSize(component: Component) {\n const textSize = getTotalTextLength(component);\n assert(\n textSize <= MAX_TEXT_LENGTH,\n `The text in a Snap UI may not be larger than ${\n MAX_TEXT_LENGTH / 1000\n } kB.`,\n );\n}\n\n/**\n * Get a JSX element from a legacy UI component. This supports all legacy UI\n * components, and maps them to their JSX equivalents where possible.\n *\n * This function validates the text size of the component, but does not validate\n * the total size. The total size of the component should be validated before\n * calling this function.\n *\n * @param legacyComponent - The legacy UI component.\n * @returns The JSX element.\n */\nexport function getJsxElementFromComponent(\n legacyComponent: Component,\n): JSXElement {\n validateComponentTextSize(legacyComponent);\n\n /**\n * Get the JSX element for a component. This function is recursive and will\n * call itself for child components.\n *\n * @param component - The component to convert to a JSX element.\n * @returns The JSX element.\n */\n function getElement(component: Component) {\n switch (component.type) {\n case NodeType.Address:\n return
;\n\n case NodeType.Button:\n return (\n \n {component.value}\n \n );\n\n case NodeType.Copyable:\n return (\n \n );\n\n case NodeType.Divider:\n return ;\n\n case NodeType.Form:\n return (\n
\n {getChildren(component.children.map(getElement))}\n
\n );\n\n case NodeType.Heading:\n return ;\n\n case NodeType.Image:\n // `Image` supports `alt`, but the legacy `Image` component does not.\n return ;\n\n case NodeType.Input:\n return (\n \n \n \n );\n\n case NodeType.Panel:\n // `Panel` is renamed to `Box` in JSX.\n return (\n \n );\n\n case NodeType.Row:\n return (\n \n {getElement(component.value) as RowChildren}\n \n );\n\n case NodeType.Spinner:\n return ;\n\n case NodeType.Text:\n return {getChildren(getTextChildren(component.value))};\n\n /* istanbul ignore next 2 */\n default:\n return assertExhaustive(component);\n }\n }\n\n return getElement(legacyComponent);\n}\n\n/**\n * Extract all links from a Markdown text string using the `marked` lexer.\n *\n * @param text - The markdown text string.\n * @returns A list of URLs linked to in the string.\n */\nfunction getMarkdownLinks(text: string) {\n const tokens = lexer(text, { gfm: false });\n const links: Tokens.Link[] = [];\n\n // Walk the lexed tokens and collect all link tokens\n walkTokens(tokens, (token) => {\n if (token.type === 'link') {\n links.push(token as Tokens.Link);\n }\n });\n\n return links;\n}\n\n/**\n * Validate a link against the phishing list.\n *\n * @param link - The link to validate.\n * @param isOnPhishingList - The function that checks the link against the\n * phishing list.\n * @throws If the link is invalid.\n */\nexport function validateLink(\n link: string,\n isOnPhishingList: (url: string) => boolean,\n) {\n try {\n const url = new URL(link);\n assert(\n ALLOWED_PROTOCOLS.includes(url.protocol),\n `Protocol must be one of: ${ALLOWED_PROTOCOLS.join(', ')}.`,\n );\n\n if (url.protocol === 'mailto:') {\n const emails = url.pathname.split(',');\n for (const email of emails) {\n const hostname = email.split('@')[1];\n assert(!hostname.includes(':'));\n const href = `https://${hostname}`;\n assert(!isOnPhishingList(href), 'The specified URL is not allowed.');\n }\n\n return;\n }\n\n assert(!isOnPhishingList(url.href), 'The specified URL is not allowed.');\n } catch (error) {\n throw new Error(\n `Invalid URL: ${\n error?.code === 'ERR_ASSERTION' ? error.message : 'Unable to parse URL.'\n }`,\n );\n }\n}\n\n/**\n * Search for Markdown links in a string and checks them against the phishing\n * list.\n *\n * @param text - The text to verify.\n * @param isOnPhishingList - The function that checks the link against the\n * phishing list.\n * @throws If the text contains a link that is not allowed.\n */\nexport function validateTextLinks(\n text: string,\n isOnPhishingList: (url: string) => boolean,\n) {\n const links = getMarkdownLinks(text);\n\n for (const link of links) {\n validateLink(link.href, isOnPhishingList);\n }\n}\n\n/**\n * Walk a JSX tree and validate each {@link LinkElement} node against the\n * phishing list.\n *\n * @param node - The JSX node to walk.\n * @param isOnPhishingList - The function that checks the link against the\n * phishing list.\n */\nexport function validateJsxLinks(\n node: JSXElement,\n isOnPhishingList: (url: string) => boolean,\n) {\n walkJsx(node, (childNode) => {\n if (childNode.type !== 'Link') {\n return;\n }\n\n validateLink(childNode.props.href, isOnPhishingList);\n });\n}\n\n/**\n * Calculate the total length of all text in the component.\n *\n * @param component - A custom UI component.\n * @returns The total length of all text components in the component.\n */\nexport function getTotalTextLength(component: Component): number {\n const { type } = component;\n\n switch (type) {\n case NodeType.Panel:\n return component.children.reduce(\n // This is a bug in TypeScript: https://github.com/microsoft/TypeScript/issues/48313\n // eslint-disable-next-line @typescript-eslint/restrict-plus-operands\n (sum, node) => sum + getTotalTextLength(node),\n 0,\n );\n\n case NodeType.Row:\n return getTotalTextLength(component.value);\n\n case NodeType.Text:\n return component.value.length;\n\n default:\n return 0;\n }\n}\n\n/**\n * Check if a JSX element has children.\n *\n * @param element - A JSX element.\n * @returns `true` if the element has children, `false` otherwise.\n */\nexport function hasChildren(\n element: Element,\n): element is Element & {\n props: { children: Nestable };\n} {\n return hasProperty(element.props, 'children');\n}\n\n/**\n * Filter a JSX child to remove `null`, `undefined`, plain booleans, and empty\n * strings.\n *\n * @param child - The JSX child to filter.\n * @returns `true` if the child is not `null`, `undefined`, a plain boolean, or\n * an empty string, `false` otherwise.\n */\nfunction filterJsxChild(child: JSXElement | string | boolean | null): boolean {\n return Boolean(child) && child !== true;\n}\n\n/**\n * Get the children of a JSX element as an array. If the element has only one\n * child, the child is returned as an array.\n *\n * @param element - A JSX element.\n * @returns The children of the element.\n */\nexport function getJsxChildren(element: JSXElement): (JSXElement | string)[] {\n if (hasChildren(element)) {\n if (Array.isArray(element.props.children)) {\n // @ts-expect-error - Each member of the union type has signatures, but\n // none of those signatures are compatible with each other.\n return element.props.children.filter(filterJsxChild).flat(Infinity);\n }\n\n if (element.props.children) {\n return [element.props.children];\n }\n }\n\n return [];\n}\n\n/**\n * Walk a JSX tree and call a callback on each node.\n *\n * @param node - The JSX node to walk.\n * @param callback - The callback to call on each node.\n * @param depth - The current depth in the JSX tree for a walk.\n * @returns The result of the callback, if any.\n */\nexport function walkJsx(\n node: JSXElement | JSXElement[],\n callback: (node: JSXElement, depth: number) => Value | undefined,\n depth = 0,\n): Value | undefined {\n if (Array.isArray(node)) {\n for (const child of node) {\n const childResult = walkJsx(child as JSXElement, callback, depth);\n if (childResult !== undefined) {\n return childResult;\n }\n }\n\n return undefined;\n }\n\n const result = callback(node, depth);\n if (result !== undefined) {\n return result;\n }\n\n if (\n hasProperty(node, 'props') &&\n isPlainObject(node.props) &&\n hasProperty(node.props, 'children')\n ) {\n const children = getJsxChildren(node);\n for (const child of children) {\n if (isPlainObject(child)) {\n const childResult = walkJsx(child, callback, depth + 1);\n if (childResult !== undefined) {\n return childResult;\n }\n }\n }\n }\n\n return undefined;\n}\n\n/**\n * Serialise a JSX prop to a string.\n *\n * @param prop - The JSX prop.\n * @returns The serialised JSX prop.\n */\nfunction serialiseProp(prop: unknown): string {\n if (typeof prop === 'string') {\n return `\"${prop}\"`;\n }\n\n return `{${JSON.stringify(prop)}}`;\n}\n\n/**\n * Serialise JSX props to a string.\n *\n * @param props - The JSX props.\n * @returns The serialised JSX props.\n */\nfunction serialiseProps(props: Record): string {\n return Object.entries(props)\n .filter(([key]) => key !== 'children')\n .sort(([a], [b]) => a.localeCompare(b))\n .map(([key, value]) => ` ${key}=${serialiseProp(value)}`)\n .join('');\n}\n\n/**\n * Serialise a JSX node to a string.\n *\n * @param node - The JSX node.\n * @param indentation - The indentation level. Defaults to `0`. This should not\n * be set by the caller, as it is used for recursion.\n * @returns The serialised JSX node.\n */\nexport function serialiseJsx(node: SnapNode, indentation = 0): string {\n if (Array.isArray(node)) {\n return node.map((child) => serialiseJsx(child, indentation)).join('');\n }\n\n const indent = ' '.repeat(indentation);\n if (typeof node === 'string') {\n return `${indent}${node}\\n`;\n }\n\n if (!node) {\n return '';\n }\n\n const { type, props } = node as GenericSnapElement;\n const trailingNewline = indentation > 0 ? '\\n' : '';\n\n if (hasProperty(props, 'children')) {\n const children = serialiseJsx(props.children as SnapNode, indentation + 1);\n return `${indent}<${type}${serialiseProps(\n props,\n )}>\\n${children}${indent}${trailingNewline}`;\n }\n\n return `${indent}<${type}${serialiseProps(props)} />${trailingNewline}`;\n}\n"]} +\ No newline at end of file diff --git a/.yarnrc.yml b/.yarnrc.yml index 252333917781..fb335f532861 100644 --- a/.yarnrc.yml +++ b/.yarnrc.yml @@ -43,6 +43,12 @@ npmAuditIgnoreAdvisories: # not appear to be used. - 1092461 + # Issue: Sentry SDK Prototype Pollution gadget in JavaScript SDKs + # URL: https://github.com/advisories/GHSA-593m-55hh-j8gv + # Not easily fixed in this version, will be fixed in v12.5.0 + # Minimally effects the extension due to usage of LavaMoat + SES lockdown. + - 1099839 + # Temp fix for https://github.com/MetaMask/metamask-extension/pull/16920 for the sake of 11.7.1 hotfix # This will be removed in this ticket https://github.com/MetaMask/metamask-extension/issues/22299 - 'ts-custom-error (deprecation)' @@ -114,15 +120,9 @@ npmAuditIgnoreAdvisories: # upon old versions of ethereumjs-utils. - 'ethereum-cryptography (deprecation)' - # Currently only dependent on deprecated @metamask/types as it is brought in - # by @metamask/keyring-api. Updating the dependency in keyring-api will - # remove this. - - '@metamask/types (deprecation)' - - # @metamask/keyring-api also depends on @metamask/snaps-ui which is - # deprecated. Replacing that dependency with @metamask/snaps-sdk will remove - # this. - - '@metamask/snaps-ui (deprecation)' + # Currently in use for the network list drag and drop functionality. + # Maintenance has stopped and the project will be archived in 2025. + - 'react-beautiful-dnd (deprecation)' npmRegistries: 'https://npm.pkg.github.com': diff --git a/CHANGELOG.md b/CHANGELOG.md index fc39b4e78a55..f9015334eb45 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,376 +7,44 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] ## [12.6.0] -### Uncategorized -- fix: Max approval and array value spending cap bugs ([#27573](https://github.com/MetaMask/metamask-extension/pull/27573)) -- feat: add power users survey support ([#27361](https://github.com/MetaMask/metamask-extension/pull/27361)) -- fix: Recreate offscreen document if it already exists ([#27596](https://github.com/MetaMask/metamask-extension/pull/27596)) -- fix: flaky test `Block Explorer links to the token tracker in the explorer` ([#27599](https://github.com/MetaMask/metamask-extension/pull/27599)) -- fix(snaps): `Copyable` more button color ([#27600](https://github.com/MetaMask/metamask-extension/pull/27600)) -- fix: flaky test `Import flow allows importing multiple tokens from search` ([#27567](https://github.com/MetaMask/metamask-extension/pull/27567)) -- fix(27428): fix if we type enter anything followed by a \ in settings search ([#27432](https://github.com/MetaMask/metamask-extension/pull/27432)) -- fix: flaky test `Address Book Edit entry in address book` due to race condition with mmi menu ([#27557](https://github.com/MetaMask/metamask-extension/pull/27557)) -- refactor: Typescript conversion of get-provider-state.js ([#23635](https://github.com/MetaMask/metamask-extension/pull/23635)) -- chore: Use "gas_included" event prop ([#27559](https://github.com/MetaMask/metamask-extension/pull/27559)) -- fix: mock locale in unit test ([#27574](https://github.com/MetaMask/metamask-extension/pull/27574)) -- feat: codefence Account Watcher for flask ([#27543](https://github.com/MetaMask/metamask-extension/pull/27543)) -- chore: start upgrade to React Router v6 ([#27185](https://github.com/MetaMask/metamask-extension/pull/27185)) -- fix: AmonHenV2 connection flow incremental permitted chain approval and account address case comparison ([#27518](https://github.com/MetaMask/metamask-extension/pull/27518)) -- fix: flaky test `Backup and Restore should backup the account settings` ([#27565](https://github.com/MetaMask/metamask-extension/pull/27565)) -- fix: Apply flex to Snaps buttons only when containing images and icons ([#27564](https://github.com/MetaMask/metamask-extension/pull/27564)) -- feat: aggregated balance feature ([#27097](https://github.com/MetaMask/metamask-extension/pull/27097)) -- feat: Add redesign integration tests ([#27259](https://github.com/MetaMask/metamask-extension/pull/27259)) -- fix: flaky test `4byte setting does not try to get contract method name from 4byte when the setting is off` ([#27560](https://github.com/MetaMask/metamask-extension/pull/27560)) -- feat: add merge queue ([#26871](https://github.com/MetaMask/metamask-extension/pull/26871)) -- feat: remove squiggle animation from swaps smart transactions ([#27264](https://github.com/MetaMask/metamask-extension/pull/27264)) -- feat: Enable gas included swaps ([#27427](https://github.com/MetaMask/metamask-extension/pull/27427)) -- fix(snaps): Fix custom UI buttons submitting forms ([#27531](https://github.com/MetaMask/metamask-extension/pull/27531)) -- chore: Master sync following v12.3.1 ([#27538](https://github.com/MetaMask/metamask-extension/pull/27538)) -- Merge origin/develop into master-sync -- fix(NOTIFY-1171): account syncing performance and bug fixes ([#27529](https://github.com/MetaMask/metamask-extension/pull/27529)) -- fix: genUnapprovedApproveConfirmation import path ([#27530](https://github.com/MetaMask/metamask-extension/pull/27530)) -- fix(snaps): Keep focus on input if interface re-renders ([#27429](https://github.com/MetaMask/metamask-extension/pull/27429)) -- fix: Allow state updates in Snaps interfaces to state values that are falsy ([#27488](https://github.com/MetaMask/metamask-extension/pull/27488)) -- fix: updated ui for connect and review page ([#27478](https://github.com/MetaMask/metamask-extension/pull/27478)) -- feat: Custom header for wallet initiated confirmations ([#27391](https://github.com/MetaMask/metamask-extension/pull/27391)) -- feat: convert account tracker to typescript ([#27231](https://github.com/MetaMask/metamask-extension/pull/27231)) -- fix: Fix snaps permission connection for `CHAIN_PERMISSIONS` feature flag ([#27459](https://github.com/MetaMask/metamask-extension/pull/27459)) -- fix: flaky test `Navigation Signature - Different signature types initiates multiple signatures and rejects all` ([#27481](https://github.com/MetaMask/metamask-extension/pull/27481)) -- feat: Double Sentry performance trace sample rate ([#27468](https://github.com/MetaMask/metamask-extension/pull/27468)) -- ci: Expand github bot policy update comment to be more actionable ([#27242](https://github.com/MetaMask/metamask-extension/pull/27242)) -- chore: Add `useLedgerConnection` unit tests ([#27358](https://github.com/MetaMask/metamask-extension/pull/27358)) -- ci: Sentry reporting only on develop branch, with Git message overrides ([#27412](https://github.com/MetaMask/metamask-extension/pull/27412)) -- test: Fix flaky permit test ([#27450](https://github.com/MetaMask/metamask-extension/pull/27450)) -- fix: removed closeMenu for ConnectedAccountsMenu ([#27460](https://github.com/MetaMask/metamask-extension/pull/27460)) -- fix(snaps): Set proper text color for secondary button ([#27335](https://github.com/MetaMask/metamask-extension/pull/27335)) -- chore: set bridge selected tokens and amount ([#26212](https://github.com/MetaMask/metamask-extension/pull/26212)) -- fix: flaky test `Add account should not affect public address when using secret recovery phrase to recover account with non-zero balance @no-mmi`aded ([#27420](https://github.com/MetaMask/metamask-extension/pull/27420)) -- fix: flaky test `Responsive UI Send Transaction from responsive window` ([#27417](https://github.com/MetaMask/metamask-extension/pull/27417)) -- fix: flaky test `Request Queuing Dapp 1, Switch Tx -> Dapp 2 Send Tx should queue send tx after switch network confirmation and transaction should target the correct network after switch is confirmed` ([#27352](https://github.com/MetaMask/metamask-extension/pull/27352)) -- fix: Change speed key color ([#27416](https://github.com/MetaMask/metamask-extension/pull/27416)) -- feat: Display setApprovalForAll and revoke setApprovalForAll to users… ([#27401](https://github.com/MetaMask/metamask-extension/pull/27401)) -- fix: "Warning: Invalid argument supplied to oneOfType" ([#27267](https://github.com/MetaMask/metamask-extension/pull/27267)) -- feat: Editing flow ([#26635](https://github.com/MetaMask/metamask-extension/pull/26635)) -- chore: bump profile-sync-controller to 0.9.3 ([#27415](https://github.com/MetaMask/metamask-extension/pull/27415)) -- fix: Remove duplication ([#27421](https://github.com/MetaMask/metamask-extension/pull/27421)) -- fix: Confirm Page test failing in CI/CD ([#27423](https://github.com/MetaMask/metamask-extension/pull/27423)) -- feat: Display approve, increaseAllowance and revoke approval to users… ([#26985](https://github.com/MetaMask/metamask-extension/pull/26985)) -- feat: Add performance metrics for signature requests ([#26967](https://github.com/MetaMask/metamask-extension/pull/26967)) -- fix: Permit DataTree token decimals ([#27328](https://github.com/MetaMask/metamask-extension/pull/27328)) -- fix: alert system and refine SIWE and contract interaction alerts ([#27205](https://github.com/MetaMask/metamask-extension/pull/27205)) -- fix(NOTIFY-1166): rename account sync event names ([#27413](https://github.com/MetaMask/metamask-extension/pull/27413)) -- feat: ERC20 Revoke Allowance ([#26906](https://github.com/MetaMask/metamask-extension/pull/26906)) -- chore: Master sync following v12.3.0 ([#27410](https://github.com/MetaMask/metamask-extension/pull/27410)) -- Merge origin/develop into master-sync -- fix(snaps): Fix gaps for custom UI Boxes ([#27405](https://github.com/MetaMask/metamask-extension/pull/27405)) -- refactor: replace Typography with Text component in gas-timing.component.js ([#27053](https://github.com/MetaMask/metamask-extension/pull/27053)) -- fix: flaky test `Request-queue UI changes should gracefully handle deleted network @no-mmi.` ([#27393](https://github.com/MetaMask/metamask-extension/pull/27393)) -- fix: issue with default nonce value being wrong when switching networks between transactions ([#27297](https://github.com/MetaMask/metamask-extension/pull/27297)) -- fix: flaky test `Token Allowance increases token spending cap to allow other accounts to transfer tokens` ([#27389](https://github.com/MetaMask/metamask-extension/pull/27389)) -- test: [POM] Migrate Snap Account Settings to page object model ([#27302](https://github.com/MetaMask/metamask-extension/pull/27302)) -- fix: incorrect method name parsed from transaction data ([#27363](https://github.com/MetaMask/metamask-extension/pull/27363)) -- feat: Redesigned Revoke setApprovalForAll confirmation ([#27111](https://github.com/MetaMask/metamask-extension/pull/27111)) -- chore: update snow dep version ([#27386](https://github.com/MetaMask/metamask-extension/pull/27386)) -- feat: improve account syncing performance ([#27330](https://github.com/MetaMask/metamask-extension/pull/27330)) -- fix: Update scam token warning ([#26994](https://github.com/MetaMask/metamask-extension/pull/26994)) -- test: remove test after smart tx toggle moved into settings ([#27378](https://github.com/MetaMask/metamask-extension/pull/27378)) -- feat: Update Redesign Signature subtitles ([#27359](https://github.com/MetaMask/metamask-extension/pull/27359)) -- fix: remove methods from array used to determine which requests should be enqueued because they can be safely passed through ([#27315](https://github.com/MetaMask/metamask-extension/pull/27315)) -- test: add trezor sign typed v4 spec ([#26988](https://github.com/MetaMask/metamask-extension/pull/26988)) -- chore(snaps): Remove debouncing/throttling of interfaces actions ([#27273](https://github.com/MetaMask/metamask-extension/pull/27273)) -- fix: "Update Network: should delete added rpc url for exis..." flaky test ([#27350](https://github.com/MetaMask/metamask-extension/pull/27350)) -- fix: Consistent confirmation navigation ([#27326](https://github.com/MetaMask/metamask-extension/pull/27326)) -- fix: Update snapshot tests ([#27355](https://github.com/MetaMask/metamask-extension/pull/27355)) -- chore: prevent importing between UI and background ([#27329](https://github.com/MetaMask/metamask-extension/pull/27329)) -- feat: Redesigned setApprovalForAll confirmations ([#27061](https://github.com/MetaMask/metamask-extension/pull/27061)) -- fix: disable the confirm button when there is a blocking alert ([#27347](https://github.com/MetaMask/metamask-extension/pull/27347)) -- fix: fix bug spending cap label alignment ([#27338](https://github.com/MetaMask/metamask-extension/pull/27338)) -- fix: Don't show third party notice for preinstalled Snaps ([#27319](https://github.com/MetaMask/metamask-extension/pull/27319)) -- refactor: Typescript conversion of eth-accounts.js ([#23504](https://github.com/MetaMask/metamask-extension/pull/23504)) -- feat: add user-storage to privacy snapshot and update user-storage mocks ([#27292](https://github.com/MetaMask/metamask-extension/pull/27292)) -- chore(26921): bump `@metamask/address-book-controller` to 6.0.0 ([#27107](https://github.com/MetaMask/metamask-extension/pull/27107)) -- fix: Update Q Mainnet symbol #26888 ([#27134](https://github.com/MetaMask/metamask-extension/pull/27134)) -- test: add `Trezor unlocks and remove account` and `Trezor unlock multiple accounts` specs ([#27325](https://github.com/MetaMask/metamask-extension/pull/27325)) -- chore: fix lint on develop branch ([#27345](https://github.com/MetaMask/metamask-extension/pull/27345)) -- test: [POM] migrate Account Custom Name to page object model ([#27283](https://github.com/MetaMask/metamask-extension/pull/27283)) -- fix: Contract interactions cannot confirm a contract interaction with `Ledger` with the new redesign ([#27331](https://github.com/MetaMask/metamask-extension/pull/27331)) -- feat: Add anonymized signature metrics ([#27298](https://github.com/MetaMask/metamask-extension/pull/27298)) -- test: add Contract interaction Redesign with Trezor account ([#27323](https://github.com/MetaMask/metamask-extension/pull/27323)) -- chore: removes portfolio button & fixes code fence of receive modal ([#27286](https://github.com/MetaMask/metamask-extension/pull/27286)) -- chore: MMI adds note to trader support to the new Tx confirmation view ([#27214](https://github.com/MetaMask/metamask-extension/pull/27214)) -- feat: integrate NFT api to display names for nfts within simulations for `ERC721`s ([#25692](https://github.com/MetaMask/metamask-extension/pull/25692)) -- feat: update tooltip for swap flow ([#27261](https://github.com/MetaMask/metamask-extension/pull/27261)) -- fix: add E2E Tests for Multi-RPC Migration and Selection ([#26851](https://github.com/MetaMask/metamask-extension/pull/26851)) -- test: network menu snaphots ([#27311](https://github.com/MetaMask/metamask-extension/pull/27311)) -- chore: Update Ethereum logo to purple ([#27295](https://github.com/MetaMask/metamask-extension/pull/27295)) -- fix(snap): Use default buttons when `hideSnapsBranding` is `true` ([#27303](https://github.com/MetaMask/metamask-extension/pull/27303)) -- chore: Add preinstalled example Snap ([#27271](https://github.com/MetaMask/metamask-extension/pull/27271)) -- fix: Redesign Signature Message date values ([#27249](https://github.com/MetaMask/metamask-extension/pull/27249)) -- fix: Fix ERC20 approve copy ([#27222](https://github.com/MetaMask/metamask-extension/pull/27222)) -- feat: network controller upgrade + network editing UI ([#26433](https://github.com/MetaMask/metamask-extension/pull/26433)) -- test: [POM] create ResetPasswordPage for e2e tests and migrate 2 test files to POM ([#27244](https://github.com/MetaMask/metamask-extension/pull/27244)) -- chore: Changed the order of the report ([#27260](https://github.com/MetaMask/metamask-extension/pull/27260)) -- fix: :sparkles: move notifications activated event ([#27290](https://github.com/MetaMask/metamask-extension/pull/27290)) -- chore: Make sonarcloud failures non-blocking ([#27289](https://github.com/MetaMask/metamask-extension/pull/27289)) -- feat: use networkClientId to resolve chainId in PPOM Middleware ([#27263](https://github.com/MetaMask/metamask-extension/pull/27263)) -- feat: quality gate test coverage fix ([#27282](https://github.com/MetaMask/metamask-extension/pull/27282)) -- fix: re-designed confirmation storybooks ([#27281](https://github.com/MetaMask/metamask-extension/pull/27281)) -- perf: finish getting rid of uses of the Roboto font ([#26552](https://github.com/MetaMask/metamask-extension/pull/26552)) -- perf: use redux state patches ([#26738](https://github.com/MetaMask/metamask-extension/pull/26738)) -- feat(NOTIFY-866): add account syncing ([#27060](https://github.com/MetaMask/metamask-extension/pull/27060)) -- fix: no sentry DSN ([#27272](https://github.com/MetaMask/metamask-extension/pull/27272)) -- chore: Bump Snaps packages ([#27057](https://github.com/MetaMask/metamask-extension/pull/27057)) -- fix: custom tracing in production builds ([#27124](https://github.com/MetaMask/metamask-extension/pull/27124)) -- feat: create useSignatureEvent fragment hook and fix expected updateEventFragment type ([#27043](https://github.com/MetaMask/metamask-extension/pull/27043)) -- refactor: memoize fetchErc20Decimals, relocate to utils/token, and apply to other instances ([#27088](https://github.com/MetaMask/metamask-extension/pull/27088)) -- perf: preload `_locales/en/messages.json` so we don't have to wait as long for our JS to dynamically load it ([#26556](https://github.com/MetaMask/metamask-extension/pull/26556)) -- feat: Create a quality gate for unit test coverage ([#27123](https://github.com/MetaMask/metamask-extension/pull/27123)) -- fix: updating close icon svg ([#27235](https://github.com/MetaMask/metamask-extension/pull/27235)) -- chore: add wallet state injection and `yarn start:with-state` script ([#26222](https://github.com/MetaMask/metamask-extension/pull/26222)) -- chore: bump assets-controllers to v37 ([#26984](https://github.com/MetaMask/metamask-extension/pull/26984)) -- feat: always use snaps to resolve domains; include preinstalled ENS resolver snap ([#26242](https://github.com/MetaMask/metamask-extension/pull/26242)) -- ci: dynamic e2e timeout ([#27146](https://github.com/MetaMask/metamask-extension/pull/27146)) -- fix: fix percentage change for non standard currencies ([#27239](https://github.com/MetaMask/metamask-extension/pull/27239)) -- fix: Estimated fee in redesigned screens ([#27247](https://github.com/MetaMask/metamask-extension/pull/27247)) -- chore: smart-transactions code domain ([#26948](https://github.com/MetaMask/metamask-extension/pull/26948)) -- fix: UI transaction integration tests ([#27130](https://github.com/MetaMask/metamask-extension/pull/27130)) -- fix: :pencil2: fix event property typo ([#27228](https://github.com/MetaMask/metamask-extension/pull/27228)) -- chore: Add currency conversion telemetry ([#26876](https://github.com/MetaMask/metamask-extension/pull/26876)) -- feat: upgrade notification controllers ([#27224](https://github.com/MetaMask/metamask-extension/pull/27224)) -- chore: remove dead code ([#27211](https://github.com/MetaMask/metamask-extension/pull/27211)) -- fix: Fixed flaky test for custom screen size ([#27067](https://github.com/MetaMask/metamask-extension/pull/27067)) -- chore(3210): deprecated `Application open` metric event ([#27102](https://github.com/MetaMask/metamask-extension/pull/27102)) -- test: [POM] create AccountListPage for e2e tests and migrate 4 test files to POM and TS ([#27201](https://github.com/MetaMask/metamask-extension/pull/27201)) -- fix: Update max gas limit with value returned from eth_estimateGas api if present ([#27165](https://github.com/MetaMask/metamask-extension/pull/27165)) -- fix: add memoization to confirm context ([#27208](https://github.com/MetaMask/metamask-extension/pull/27208)) -- fix: incomplete transactions on startup ([#26963](https://github.com/MetaMask/metamask-extension/pull/26963)) -- fix: permit UI integration tests ([#26365](https://github.com/MetaMask/metamask-extension/pull/26365)) -- chore: Update package @blockaid/ppom_release to version 1.5.3 ([#27170](https://github.com/MetaMask/metamask-extension/pull/27170)) -- chore: update @metamask/bitcoin-wallet-snap to 0.6.0 ([#27141](https://github.com/MetaMask/metamask-extension/pull/27141)) -- chore(2916): refactor stream handler for phishing warning and provider stream ([#26526](https://github.com/MetaMask/metamask-extension/pull/26526)) -- refactor: convert `jazzicon.component.js` to typescript ([#23824](https://github.com/MetaMask/metamask-extension/pull/23824)) -- fix(action): add a workaround for known bots ([#27019](https://github.com/MetaMask/metamask-extension/pull/27019)) -- feat: Adding a new controller for Metametrics Data Deletion ([#24503](https://github.com/MetaMask/metamask-extension/pull/24503)) -- feat: migrate OnboardingController to BaseController v2 ([#26880](https://github.com/MetaMask/metamask-extension/pull/26880)) -- fix: change asset picker button to buttonbase to fix text theming ([#27127](https://github.com/MetaMask/metamask-extension/pull/27127)) -- chore: Update `asset-list` to Typescript, remove PropTypes ([#26952](https://github.com/MetaMask/metamask-extension/pull/26952)) -- fix: flaky test `Simulation Details displays generic error message` ([#27156](https://github.com/MetaMask/metamask-extension/pull/27156)) -- fix: fix fiat values in testnet visibility ([#26273](https://github.com/MetaMask/metamask-extension/pull/26273)) -- fix: sentry sessions in production builds ([#27016](https://github.com/MetaMask/metamask-extension/pull/27016)) -- fix: flaky test `Swaps - notifications @no-mmi tests a notification for not enough balance` ([#27160](https://github.com/MetaMask/metamask-extension/pull/27160)) -- feat: Adding "cookie id" to metrics event ([#26697](https://github.com/MetaMask/metamask-extension/pull/26697)) -- chore: bump `@metamask/accounts-controller` to 18.2.0 ([#27142](https://github.com/MetaMask/metamask-extension/pull/27142)) -- feat: add tracking event to Receive button ([#26958](https://github.com/MetaMask/metamask-extension/pull/26958)) -- feat: converted PreferencesController to typescript ([#26710](https://github.com/MetaMask/metamask-extension/pull/26710)) -- fix: storybook theme package not working ([#27086](https://github.com/MetaMask/metamask-extension/pull/27086)) -- feat: Edit spending cap for ERC20 `approve` and `increaseAllowance` ([#26845](https://github.com/MetaMask/metamask-extension/pull/26845)) -- chore(26919): bump `@metamask/signature-controller` to 19.0.0 and `@metamask/logging-controller` to 6.0.0 ([#27082](https://github.com/MetaMask/metamask-extension/pull/27082)) -- fix: display of network name in network switch toast on confirmation pages ([#27100](https://github.com/MetaMask/metamask-extension/pull/27100)) -- chore: Master sync post 12.2.2 merge ([#27094](https://github.com/MetaMask/metamask-extension/pull/27094)) -- fix: notification services add new allowed events ([#26987](https://github.com/MetaMask/metamask-extension/pull/26987)) -- fix: Resolve path-to-regexp to v1.9.0 to resolve GHSA-9wv6-86v2-598j ([#27113](https://github.com/MetaMask/metamask-extension/pull/27113)) -- feat: funding method modal ([#26426](https://github.com/MetaMask/metamask-extension/pull/26426)) -- chore: fix issue 27079 incorrect 0 balance ([#27083](https://github.com/MetaMask/metamask-extension/pull/27083)) -- fix: change default currency decimals for issue 26646 ([#27074](https://github.com/MetaMask/metamask-extension/pull/27074)) -- fix: Issue 26751 QR barcode scanner ([#27002](https://github.com/MetaMask/metamask-extension/pull/27002)) -- feat: new components for network UI ([#27085](https://github.com/MetaMask/metamask-extension/pull/27085)) -- fix: flaky test `Snap Account - Swap swaps ETH for DAI using a snap a...` ([#27087](https://github.com/MetaMask/metamask-extension/pull/27087)) -- chore: Enable import attributes in Webpack build ([#27080](https://github.com/MetaMask/metamask-extension/pull/27080)) -- fix: edit button on confirmation page for send ERC-1155 token ([#27004](https://github.com/MetaMask/metamask-extension/pull/27004)) -- chore: Move scroll to bottom related state on re-designed confirmation pages to confirmContext ([#27064](https://github.com/MetaMask/metamask-extension/pull/27064)) -- fix: flaky test `Request Queuing for Multiple Dapps and Txs on different networks should batch confirmation txs for different dapps on different networks.` ([#27095](https://github.com/MetaMask/metamask-extension/pull/27095)) -- Merge branch 'develop' into master-sync -- fix: Update id for ignoring path-to-regexp ([#27093](https://github.com/MetaMask/metamask-extension/pull/27093)) -- Merge origin/develop into master-sync -- refactor: Send signature metrics as event fragments in middleware & feat: Add signature alert metrics to events ([#26597](https://github.com/MetaMask/metamask-extension/pull/26597)) -- fix: flaky test `Navigate transactions should reject and remove all unapproved transactions` ([#27028](https://github.com/MetaMask/metamask-extension/pull/27028)) -- fix(windows): cannot use double-quotes in filenames on Windows ([#27071](https://github.com/MetaMask/metamask-extension/pull/27071)) -- perf: add Sentry tracing to CircleCI runs ([#26588](https://github.com/MetaMask/metamask-extension/pull/26588)) -- fix: Data collection does not appear on Settings search ([#26953](https://github.com/MetaMask/metamask-extension/pull/26953)) -- fix: flaky test `Swap Eth for another Token @no-mmi Completes a Swap between ETH and DAI after changing initial rate` ([#27022](https://github.com/MetaMask/metamask-extension/pull/27022)) -- docs: Privacy settings manual scenarios ([#26764](https://github.com/MetaMask/metamask-extension/pull/26764)) -- fix: Adding patch on eth-json-rpc-middleware to disable verifyContract field validation for cosmos ([#27021](https://github.com/MetaMask/metamask-extension/pull/27021)) -- chore: bump @metamask/base-controller to ^7.0.0 ([#27032](https://github.com/MetaMask/metamask-extension/pull/27032)) -- fix: check if the notifications started flow is running ([#27038](https://github.com/MetaMask/metamask-extension/pull/27038)) -- fix: update `network is busy` threshold 0.9 ([#26983](https://github.com/MetaMask/metamask-extension/pull/26983)) -- fix: Update id for ignoring path-to-regexp advisory ([#27044](https://github.com/MetaMask/metamask-extension/pull/27044)) -- fix: Add a second id to ignore for the GHSA-9wv6-86v2-598j ([#27041](https://github.com/MetaMask/metamask-extension/pull/27041)) -- chore: Create a story for AddNetworkModal component ([#27003](https://github.com/MetaMask/metamask-extension/pull/27003)) -- chore: Create Storybook story for ImportSRP component ([#27000](https://github.com/MetaMask/metamask-extension/pull/27000)) -- fix(AssetPrice): change `stroke-linecap` and `stroke-linejoin` properties to valid JS syntax ([#26488](https://github.com/MetaMask/metamask-extension/pull/26488)) -- fix: Ignore yarn audit warning for GHSA-9wv6-86v2-598j ([#27024](https://github.com/MetaMask/metamask-extension/pull/27024)) -- feat: Add updates to Snaps custom UI ([#26639](https://github.com/MetaMask/metamask-extension/pull/26639)) -- test: Add integration test for low gas fees alert ([#27015](https://github.com/MetaMask/metamask-extension/pull/27015)) -- fix: flaky test `BTC Account - Overview has portfolio button enabled for BTC accounts` ([#27017](https://github.com/MetaMask/metamask-extension/pull/27017)) -- fix: flaky test `'Import NFT should continue to display an imported NFT after importing, adding a new account, and switching back` ([#27006](https://github.com/MetaMask/metamask-extension/pull/27006)) -- refactor: remove UI initialisation callbacks ([#26969](https://github.com/MetaMask/metamask-extension/pull/26969)) -- fix: flaky test `Test Snap Signature Insights tests Signature Insights functionality (Legacy)` ([#27007](https://github.com/MetaMask/metamask-extension/pull/27007)) -- fix: :bug: fix typo ([#27010](https://github.com/MetaMask/metamask-extension/pull/27010)) -- refactor: replace Typography with Text component in convert-token-to-nft-modal.js ([#26997](https://github.com/MetaMask/metamask-extension/pull/26997)) -- fix: Fix flakey E2E Request Queue Switch Send Tests ([#26995](https://github.com/MetaMask/metamask-extension/pull/26995)) -- ci: Ensure get-changed-files-with-git-diff scripts does not run on the master branch ([#26992](https://github.com/MetaMask/metamask-extension/pull/26992)) -- fix(2946): rename back up your data to export your data ([#26322](https://github.com/MetaMask/metamask-extension/pull/26322)) -- fix: Don't show AccountListMenu back button by default ([#26940](https://github.com/MetaMask/metamask-extension/pull/26940)) -- chore: Adding generic type to useConfirmContext hook ([#26990](https://github.com/MetaMask/metamask-extension/pull/26990)) -- chore: bump `eth-ledger-bridge-keyring` to `^3.0.1` ([#26498](https://github.com/MetaMask/metamask-extension/pull/26498)) -- chore: bump `@metamask/smart-transactions-controller` to `^13.0.0` ([#26857](https://github.com/MetaMask/metamask-extension/pull/26857)) -- test: add integration test for pending transaction alert and fix bug … ([#26986](https://github.com/MetaMask/metamask-extension/pull/26986)) -- feat: Added UI for switching via dapp for custom chain id ([#26905](https://github.com/MetaMask/metamask-extension/pull/26905)) -- test: add Send eth with a Trezor account spec ([#26530](https://github.com/MetaMask/metamask-extension/pull/26530)) -- feat: update button primary to use light theme on dark mode ([#26879](https://github.com/MetaMask/metamask-extension/pull/26879)) -- chore: Create a story for NftsItems component ([#26956](https://github.com/MetaMask/metamask-extension/pull/26956)) -- fix: update input raw locator in account watcher e2e to use element ID ([#26950](https://github.com/MetaMask/metamask-extension/pull/26950)) -- test(btc): mock ramps endpoints ([#26941](https://github.com/MetaMask/metamask-extension/pull/26941)) -- feat: use new `SnapAuthorshipPill` component to show snap origin in confirmation flow ([#26881](https://github.com/MetaMask/metamask-extension/pull/26881)) -- feat: multichain support in PPOMController ([#26966](https://github.com/MetaMask/metamask-extension/pull/26966)) -- feat: Do not require scroll-to-bottom for SIWE or Signatures with simulations before enabling Confirm footer ([#26887](https://github.com/MetaMask/metamask-extension/pull/26887)) -- fix: confirmation screen with in expanded extension view ([#26965](https://github.com/MetaMask/metamask-extension/pull/26965)) -- fix: add isUnlocked Check for Metamask Notifications ([#26960](https://github.com/MetaMask/metamask-extension/pull/26960)) -- test: [Snaps E2E] Create and update snap multi-install test ([#26949](https://github.com/MetaMask/metamask-extension/pull/26949)) -- chore: Remove Snaps from LavaMoat policy CODEOWNERS ([#26962](https://github.com/MetaMask/metamask-extension/pull/26962)) -- build: bump @metamask/message-manager → "^10.1.0" & @metamask/controller-utils → "^11.2.0" ([#26947](https://github.com/MetaMask/metamask-extension/pull/26947)) -- fix: Code cleanup on quoted attributes ([#25783](https://github.com/MetaMask/metamask-extension/pull/25783)) -- fix: Add Basic Functionality to Settings Search ([#25185](https://github.com/MetaMask/metamask-extension/pull/25185)) -- chore: Add basic UX and Assets team CODEOWNER rules ([#25840](https://github.com/MetaMask/metamask-extension/pull/25840)) -- test: [Snaps E2E] Fix deprecations and add radio button and checkbox tests to snaps interactive ui test ([#26927](https://github.com/MetaMask/metamask-extension/pull/26927)) -- fix: issue where `wallet_addEtherumChain` was incorrectly enforcing inclusion of a blockExplorerUrls property which is not required ([#26938](https://github.com/MetaMask/metamask-extension/pull/26938)) -- fix: Bug in calculating token value when number of decimals in token is large ([#26931](https://github.com/MetaMask/metamask-extension/pull/26931)) -- feat: Adding context to get current confirmation PR-7 ([#26689](https://github.com/MetaMask/metamask-extension/pull/26689)) -- fix: Show correct origins when snaps use `wallet_requestSnaps` ([#26715](https://github.com/MetaMask/metamask-extension/pull/26715)) -- fix(btc): fix account overview e2e test ([#26929](https://github.com/MetaMask/metamask-extension/pull/26929)) -- feat: Adding context to get current confirmation PR-6 ([#26685](https://github.com/MetaMask/metamask-extension/pull/26685)) -- feat: add brand evo font files ([#26672](https://github.com/MetaMask/metamask-extension/pull/26672)) -- feat: Icon Button to use light theme in dark mode ([#26884](https://github.com/MetaMask/metamask-extension/pull/26884)) -- New Crowdin translations by Github Action ([#26235](https://github.com/MetaMask/metamask-extension/pull/26235)) -- chore(deps): Bump `@metamask/utils` from `^8.2.1` to `^9.1.0` ([#26551](https://github.com/MetaMask/metamask-extension/pull/26551)) -- feat: Make footers and headers sticky in confirmation popups ([#26853](https://github.com/MetaMask/metamask-extension/pull/26853)) -- chore: Update `develop` with changes from v12.1.2 ([#26896](https://github.com/MetaMask/metamask-extension/pull/26896)) -- Merge remote-tracking branch 'origin/master' into v12.2.0-master-sync -- fix: flaky test "Request Queuing Dapp 1 Send Tx -> Dapp 2 Request Acc..." ([#26872](https://github.com/MetaMask/metamask-extension/pull/26872)) -- fix: update notifications events ([#26807](https://github.com/MetaMask/metamask-extension/pull/26807)) -- fix: move porfolio button next to price amount ([#26867](https://github.com/MetaMask/metamask-extension/pull/26867)) -- feat: new basic functionality event ([#26837](https://github.com/MetaMask/metamask-extension/pull/26837)) -- feat: Adding context to get current confirmation PR-5 ([#26673](https://github.com/MetaMask/metamask-extension/pull/26673)) -- feat: Change copy from estimated to network fee ([#26859](https://github.com/MetaMask/metamask-extension/pull/26859)) -- test: add integration test for no gas price alert ([#26838](https://github.com/MetaMask/metamask-extension/pull/26838)) -- fix: PermitSingle, PermitBatch, PermitTransferFrom, PermitBatchTransferFrom simulation "Spending cap" ([#26684](https://github.com/MetaMask/metamask-extension/pull/26684)) -- docs: Manual scenario for "Import account with private key" feature ([#26756](https://github.com/MetaMask/metamask-extension/pull/26756)) -- feat: Adding context to get current confirmation PR-4 ([#26649](https://github.com/MetaMask/metamask-extension/pull/26649)) -- ci: Prevent E2E timeouts on release changes ([#26846](https://github.com/MetaMask/metamask-extension/pull/26846)) -- fix: Apply padding to Snaps UI root element no matter the type ([#26850](https://github.com/MetaMask/metamask-extension/pull/26850)) -- fix: nonce increment/decrement functionality using arrow buttons ([#26569](https://github.com/MetaMask/metamask-extension/pull/26569)) -- chore: urls update for MMI support page ([#26839](https://github.com/MetaMask/metamask-extension/pull/26839)) -- chore: MMI adds mmi flow to new transactions confirmations view ([#26817](https://github.com/MetaMask/metamask-extension/pull/26817)) -- feat: Adding context to get current confirmation PR-3 ([#26645](https://github.com/MetaMask/metamask-extension/pull/26645)) -- feat: added edit accounts modal ([#26413](https://github.com/MetaMask/metamask-extension/pull/26413)) -- chore: Update `develop` with changes from `v12.1.1` ([#26829](https://github.com/MetaMask/metamask-extension/pull/26829)) -- test: add spec Vault decrypt - paste encrypted vault into field ([#26678](https://github.com/MetaMask/metamask-extension/pull/26678)) -- fix: wait for ledger offscreen iframe load ([#26225](https://github.com/MetaMask/metamask-extension/pull/26225)) -- feat: Adding context to get current confirmation PR-2 ([#26619](https://github.com/MetaMask/metamask-extension/pull/26619)) -- feat: Add redesigned ERC20 Approve confirmation and SpendingCap section ([#26606](https://github.com/MetaMask/metamask-extension/pull/26606)) -- Merge remote-tracking branch 'origin/master' into sync-develop-v12.1.1 -- fix: Update Swaps symbol from matic to pol ([#26826](https://github.com/MetaMask/metamask-extension/pull/26826)) -- fix(bug report): the description of bug report issue wasn't up-to-date anymore ([#26777](https://github.com/MetaMask/metamask-extension/pull/26777)) -- ci: enable VNC over ssh ([#26106](https://github.com/MetaMask/metamask-extension/pull/26106)) -- fix: "Phishing Detection Via Iframe should redirect users ..." flaky test ([#26779](https://github.com/MetaMask/metamask-extension/pull/26779)) -- build: celebratory update of yarn to v4.4.1 ([#26775](https://github.com/MetaMask/metamask-extension/pull/26775)) -- fix: flaky test `Request Queuing Dapp 1, Switch Tx -> Dapp 2 Send Tx should queue signTypedData tx after eth_sendTransaction confirmation and signTypedData confirmation should target the correct network after eth_sendTransaction is confirmed @no-mmi` ([#26794](https://github.com/MetaMask/metamask-extension/pull/26794)) -- chore: Upgrade core packages to release 159.0.0 ([#26138](https://github.com/MetaMask/metamask-extension/pull/26138)) -- test: Fix flaky e2e signature tests ([#26771](https://github.com/MetaMask/metamask-extension/pull/26771)) -- fix: flaky test `Test Snap Interactive UI test interactive ui elements` ([#26792](https://github.com/MetaMask/metamask-extension/pull/26792)) -- feat: implement client side malicious network request detection ([#25839](https://github.com/MetaMask/metamask-extension/pull/25839)) -- chore: Bump Snaps dependencies ([#26675](https://github.com/MetaMask/metamask-extension/pull/26675)) -- refactor: extract Send-specific functionality out of AssetPicker ([#26558](https://github.com/MetaMask/metamask-extension/pull/26558)) -- chore: Bump `storybook`, `@storybook/*` to `^7.6.20`, `storybook-dark-mode` from `^3.0.3` to `^4.0.2` ([#26703](https://github.com/MetaMask/metamask-extension/pull/26703)) -- fix: Sentry app state null data to show null as value. ([#26522](https://github.com/MetaMask/metamask-extension/pull/26522)) -- chore: Master sync ([#26737](https://github.com/MetaMask/metamask-extension/pull/26737)) -- fix: Stop using a hardcoded Snap ID for notifications ([#26739](https://github.com/MetaMask/metamask-extension/pull/26739)) -- chore: MMI Fixes passing the state to route using history.push ([#26722](https://github.com/MetaMask/metamask-extension/pull/26722)) -- Merge origin/develop into master-sync -- test: Add integration test for insufficient gas ([#26711](https://github.com/MetaMask/metamask-extension/pull/26711)) -- test: [Snaps E2E] Add changes to fix flakiness in Snaps UI Images test ([#26725](https://github.com/MetaMask/metamask-extension/pull/26725)) -- test: Add integration test for gas estimate failed alert ([#26681](https://github.com/MetaMask/metamask-extension/pull/26681)) -- fix: flaky test `Click bridge button @no-mmi loads portfolio tab from asset overview when flag is turned off` ([#26654](https://github.com/MetaMask/metamask-extension/pull/26654)) -- fix: flaky test `Navigation Signature - Different signature types initiates and queues multiple signatures and confirms` ([#26707](https://github.com/MetaMask/metamask-extension/pull/26707)) -- feat: adding context to get current confirmation in re-designed confirmation pages PR-1 ([#26587](https://github.com/MetaMask/metamask-extension/pull/26587)) -- fix: Add IOTX icon ([#26723](https://github.com/MetaMask/metamask-extension/pull/26723)) -- test: Add integration tests for network busy alert ([#26679](https://github.com/MetaMask/metamask-extension/pull/26679)) -- feat: Temporarily hide Approve redesigned pages ([#26676](https://github.com/MetaMask/metamask-extension/pull/26676)) -- perf: use an interstitial page to load `popup.html`; load scripts using `defer`ed script tags ([#26555](https://github.com/MetaMask/metamask-extension/pull/26555)) -- feat: Add metrics to track where signature rejection occurred ([#26469](https://github.com/MetaMask/metamask-extension/pull/26469)) -- chore: update @metamask/bitcoin-wallet-snap to 0.5.0 ([#26701](https://github.com/MetaMask/metamask-extension/pull/26701)) -- fix: adding missing token images ([#26708](https://github.com/MetaMask/metamask-extension/pull/26708)) -- feat: Added Edit networks screen modal ([#26097](https://github.com/MetaMask/metamask-extension/pull/26097)) -- perf: add trace for UI startup ([#26636](https://github.com/MetaMask/metamask-extension/pull/26636)) -- fix: Address design review on contract interaction and deployment red… ([#26659](https://github.com/MetaMask/metamask-extension/pull/26659)) -- test: [Snaps E2E] Add test cases for signature confirmations redesign to signature insights snaps test ([#26691](https://github.com/MetaMask/metamask-extension/pull/26691)) -- feat: updated ui for adding chain id screen ([#25777](https://github.com/MetaMask/metamask-extension/pull/25777)) -- fix: update moonbeam and moonriver network and token logos ([#26677](https://github.com/MetaMask/metamask-extension/pull/26677)) -- chore: MMI adds back the current Tx confirmation view to MMI ([#26539](https://github.com/MetaMask/metamask-extension/pull/26539)) -- fix(snaps): Use ApprovalType instead DIALOG_APPROVAL_TYPES in confirmation page ([#26655](https://github.com/MetaMask/metamask-extension/pull/26655)) -- fix: catch error for getTokenStandardAndDetails ([#26269](https://github.com/MetaMask/metamask-extension/pull/26269)) -- chore: Master sync ([#26641](https://github.com/MetaMask/metamask-extension/pull/26641)) -- chore: update gitignore ([#26642](https://github.com/MetaMask/metamask-extension/pull/26642)) -- fix: flaky test `Phishing Detection should navigate the user to PhishFort to dispute a Phishfort Block` ([#26651](https://github.com/MetaMask/metamask-extension/pull/26651)) -- fix: flaky tests `Sentry errors before initialization, after opting into metrics @no-mmi should capture UI application state`... ([#26648](https://github.com/MetaMask/metamask-extension/pull/26648)) -- fix: flaky test `Vault Decryptor Page is able to decrypt the vault us..` due to empty file load ([#26612](https://github.com/MetaMask/metamask-extension/pull/26612)) -- Merge branch 'develop' into master-sync -- fix: flaky test `Increase Token Allowance increases token spending ca..` ([#26640](https://github.com/MetaMask/metamask-extension/pull/26640)) -- chore: bump smart transactions controller ([#26644](https://github.com/MetaMask/metamask-extension/pull/26644)) -- chore: Polish multichain token list styles ([#26300](https://github.com/MetaMask/metamask-extension/pull/26300)) -- Merge origin/develop into master-sync -- feat: upgrade network controller to v20 ([#26150](https://github.com/MetaMask/metamask-extension/pull/26150)) -- docs: Add publish a release to Sentry flow steps ([#26605](https://github.com/MetaMask/metamask-extension/pull/26605)) -- chore: set bridge network allowlists from feature flags ([#26147](https://github.com/MetaMask/metamask-extension/pull/26147)) -- chore: anonymize send analytic properties #26627 ([#26628](https://github.com/MetaMask/metamask-extension/pull/26628)) -- chore: add user IDs to send page analytics ([#26600](https://github.com/MetaMask/metamask-extension/pull/26600)) -- feat: Integrate Snaps into the redesigned confirmations ([#26435](https://github.com/MetaMask/metamask-extension/pull/26435)) -- refactor: Replace usages of the deprecated `setProviderType` ([#22619](https://github.com/MetaMask/metamask-extension/pull/22619)) -- refactor: Use generic helper function to initiate signatures ([#26584](https://github.com/MetaMask/metamask-extension/pull/26584)) -- test: [Snaps E2E] Update snaps dialog test to include Custom dialog type ([#26598](https://github.com/MetaMask/metamask-extension/pull/26598)) -- feat: new receive flow ([#26148](https://github.com/MetaMask/metamask-extension/pull/26148)) -- fix: remove speed up and cancel controller validation ([#26492](https://github.com/MetaMask/metamask-extension/pull/26492)) -- fix: flaky test `Test Snap Name Lookup tests name-lookup functionalit...` ([#26583](https://github.com/MetaMask/metamask-extension/pull/26583)) -- feat: Add contract deployment redesigned transaction screen ([#26382](https://github.com/MetaMask/metamask-extension/pull/26382)) -- feat: add transaction performance metrics ([#26332](https://github.com/MetaMask/metamask-extension/pull/26332)) -- test: add tests for insufficient funds alert ([#26512](https://github.com/MetaMask/metamask-extension/pull/26512)) -- feat: account watcher e2e ([#26524](https://github.com/MetaMask/metamask-extension/pull/26524)) -- feat: update add team label workflow ([#26548](https://github.com/MetaMask/metamask-extension/pull/26548)) -- feat: Add approval static simulation ([#26514](https://github.com/MetaMask/metamask-extension/pull/26514)) -- fix: Snapshot unit tests ([#26585](https://github.com/MetaMask/metamask-extension/pull/26585)) -- chore: Rename `permittedChains` permission to `endowment:permitted-chains` ([#26534](https://github.com/MetaMask/metamask-extension/pull/26534)) -- feat: Redesign Approve confirmation ([#26464](https://github.com/MetaMask/metamask-extension/pull/26464)) -- feat: Enable hardware wallets for smart transactions, sign a transaction only once ([#26251](https://github.com/MetaMask/metamask-extension/pull/26251)) -- fix: Allowlist Snap UI card component ([#26565](https://github.com/MetaMask/metamask-extension/pull/26565)) -- fix: adding warning for origin on redesigned pages ([#26306](https://github.com/MetaMask/metamask-extension/pull/26306)) -- fix: track `swapAndSend` transaction type ([#26535](https://github.com/MetaMask/metamask-extension/pull/26535)) -- feat: added AccountWatcher as preinstalled snap and added to menu list ([#26402](https://github.com/MetaMask/metamask-extension/pull/26402)) -- fix: stick add team label version to commit hash ([#26540](https://github.com/MetaMask/metamask-extension/pull/26540)) -- fix: correct duplicate notifications event tracking in global menu ([#26525](https://github.com/MetaMask/metamask-extension/pull/26525)) -- feat: migrate protect intrinsics test to e2e ([#26197](https://github.com/MetaMask/metamask-extension/pull/26197)) -- fix: NetworkChangeToast width in wide screen mode ([#26532](https://github.com/MetaMask/metamask-extension/pull/26532)) -- fix: missing deadline in swaps stx status screen ([#25779](https://github.com/MetaMask/metamask-extension/pull/25779)) -- fix: Snap Address component UI/UX (Snaps custom UI) ([#26477](https://github.com/MetaMask/metamask-extension/pull/26477)) -- feat(snaps): Removed Snaps name-lookup permission code fences ([#26393](https://github.com/MetaMask/metamask-extension/pull/26393)) -- docs: Include MV2 build commands in README ([#26486](https://github.com/MetaMask/metamask-extension/pull/26486)) -- test: add `driver.clickElementAndWaitForWindowToClose` helper method ([#26449](https://github.com/MetaMask/metamask-extension/pull/26449)) -- chore: Integrate SnapInsightsController ([#26411](https://github.com/MetaMask/metamask-extension/pull/26411)) -- feat: Update @blockaid/ppom_release to release 1.5.2 ([#26494](https://github.com/MetaMask/metamask-extension/pull/26494)) -- chore: Master sync ([#26497](https://github.com/MetaMask/metamask-extension/pull/26497)) -- Merge origin/develop into master-sync -- feat(notifications): use shared libraries NotificationServicesController ([#26480](https://github.com/MetaMask/metamask-extension/pull/26480)) -- perf: add parallel fetching for the network fee dropdown ([#26489](https://github.com/MetaMask/metamask-extension/pull/26489)) -- chore: Add Near Icon ([#26459](https://github.com/MetaMask/metamask-extension/pull/26459)) -- fix: Restore `responsive` e2e driver option ([#25932](https://github.com/MetaMask/metamask-extension/pull/25932)) -- chore: downgrade prettier-eslint to match prettier version ([#26145](https://github.com/MetaMask/metamask-extension/pull/26145)) -- test: Add manual scenario for upgrade testing ([#26317](https://github.com/MetaMask/metamask-extension/pull/26317)) -- build(chore): switch to `defer` since it guarantees execution order once chunked ([#26425](https://github.com/MetaMask/metamask-extension/pull/26425)) -- fix: Update send transactions with custom nonce.csv ([#26451](https://github.com/MetaMask/metamask-extension/pull/26451)) -- fix: `rpcIdentifierUtility` client side grouping before emitting CustomRPC event ([#26266](https://github.com/MetaMask/metamask-extension/pull/26266)) -- feat(notifications): use notification services push controller ([#26448](https://github.com/MetaMask/metamask-extension/pull/26448)) -- feat: Add footers to Snap home pages ([#26463](https://github.com/MetaMask/metamask-extension/pull/26463)) -- fix: Remove double padding on Snap home page ([#26462](https://github.com/MetaMask/metamask-extension/pull/26462)) -- chore(webpack): update `html-bundler-webpack-plugin` from `v3.6.5` to `v3.17.3` ([#26371](https://github.com/MetaMask/metamask-extension/pull/26371)) + +## [12.5.0] + +## [12.4.2] +### Fixed +- Fix a problem where certain name lookup Snaps would not be triggered ([#27880](https://github.com/MetaMask/metamask-extension/pull/27880)) + +## [12.4.1] +### Fixed +- Fix crash on swaps review page ([#27708](https://github.com/MetaMask/metamask-extension/pull/27708)) +- Fix bug that could prevent the phishing detection feature from having the most up to date info on which web pages to block ([#27743](https://github.com/MetaMask/metamask-extension/pull/27743)) + +## [12.4.0] +### Added +- Added a receive button to the home screen, allowing users to easily get their address or QR-code for receiving cryptocurrency ([#26148](https://github.com/MetaMask/metamask-extension/pull/26148)) +- Added smart transactions functionality for hardware wallet users ([#26251](https://github.com/MetaMask/metamask-extension/pull/26251)) +- Added new custom UI components for Snaps developers ([#26675](https://github.com/MetaMask/metamask-extension/pull/26675)) +- Add support for footers to Snap home pages ([#26463](https://github.com/MetaMask/metamask-extension/pull/26463)) +- [FLASK] Added Account Watcher as a preinstalled snap and added it to the menu list ([#26402](https://github.com/MetaMask/metamask-extension/pull/26402)) +- [FLASK] Added footers to Snap home pages ([#26463](https://github.com/MetaMask/metamask-extension/pull/26463)) +- Added icons for IoTeX network ([#26723](https://github.com/MetaMask/metamask-extension/pull/26723)) +- Added NEAR icon for chainId 397 and 398 ([#26459](https://github.com/MetaMask/metamask-extension/pull/26459)) + + +### Changed +- Redesign contract deployment transaction screen ([#26382](https://github.com/MetaMask/metamask-extension/pull/26382)) +- Improve performance, reliability and coverage of the phishing detection feature ([#25839](https://github.com/MetaMask/metamask-extension/pull/25839)) +- Updated Moonbeam and Moonriver network and token logos ([#26677](https://github.com/MetaMask/metamask-extension/pull/26677)) +- Updated UI for add network notification window ([#25777](https://github.com/MetaMask/metamask-extension/pull/25777)) +- Update visual styling of token lists ([#26300](https://github.com/MetaMask/metamask-extension/pull/26300)) +- Update spacing on Snap home page ([#26462](https://github.com/MetaMask/metamask-extension/pull/26462)) +- [FLASK] Integrated Snaps into the redesigned confirmation pages ([#26435](https://github.com/MetaMask/metamask-extension/pull/26435)) + +### Fixed +- Fixed network change toast width in wide screen mode ([#26532](https://github.com/MetaMask/metamask-extension/pull/26532)) +- Fixed missing deadline in swaps smart transaction status screen ([#25779](https://github.com/MetaMask/metamask-extension/pull/25779)) +- Improved Snap Address component UI/UX; stop using petnames in custom Snaps UIs ([#26477](https://github.com/MetaMask/metamask-extension/pull/26477)) +- Fixed bug that could prevent the Import NFT modal from closing after importing some tokens ([#26269](https://github.com/MetaMask/metamask-extension/pull/26269)) ## [12.3.1] ### Fixed @@ -1876,7 +1544,7 @@ Update styles and spacing on the critical error page ([#20350](https://github.c - Avoid blob url for files downloads ([#17986](https://github.com/MetaMask/metamask-extension/pull/17986)) - Upgrading the Import Account modal ([#17763](https://github.com/MetaMask/metamask-extension/pull/17763)) - identify desktop is paired in the metrics event ([#17892](https://github.com/MetaMask/metamask-extension/pull/17892)) -- [MMI] Conditional change title in home if buildType is MMI ([#17898](https://github.com/MetaMask/metamask-extension/pull/17898)) +- [MMI] Conditional change title in home if buildType is MMI ([#17898](https://github.com/MetaMask/metamask-extension/pull/17898)) - [MMI] Prevent multiple instances of MM at the same browser ([#17856](https://github.com/MetaMask/metamask-extension/pull/17856)) - Buy crypto by redirecting to onramp experience on pdapp instead of deposit popover ([#17689](https://github.com/MetaMask/metamask-extension/pull/17689)) - Update snaps locale messages for casing and content ([#17915](https://github.com/MetaMask/metamask-extension/pull/17915)) @@ -5485,7 +5153,11 @@ Update styles and spacing on the critical error page ([#20350](https://github.c [Unreleased]: https://github.com/MetaMask/metamask-extension/compare/v12.6.0...HEAD -[12.6.0]: https://github.com/MetaMask/metamask-extension/compare/v12.3.1...v12.6.0 +[12.6.0]: https://github.com/MetaMask/metamask-extension/compare/v12.5.0...v12.6.0 +[12.5.0]: https://github.com/MetaMask/metamask-extension/compare/v12.4.2...v12.5.0 +[12.4.2]: https://github.com/MetaMask/metamask-extension/compare/v12.4.1...v12.4.2 +[12.4.1]: https://github.com/MetaMask/metamask-extension/compare/v12.4.0...v12.4.1 +[12.4.0]: https://github.com/MetaMask/metamask-extension/compare/v12.3.1...v12.4.0 [12.3.1]: https://github.com/MetaMask/metamask-extension/compare/v12.3.0...v12.3.1 [12.3.0]: https://github.com/MetaMask/metamask-extension/compare/v12.2.4...v12.3.0 [12.2.4]: https://github.com/MetaMask/metamask-extension/compare/v12.2.3...v12.2.4 diff --git a/app/scripts/controllers/swaps/swaps.test.ts b/app/scripts/controllers/swaps/swaps.test.ts index 4ed1b545f170..c3ac811adcaa 100644 --- a/app/scripts/controllers/swaps/swaps.test.ts +++ b/app/scripts/controllers/swaps/swaps.test.ts @@ -1097,7 +1097,6 @@ describe('SwapsController', function () { oldState.swapsState.swapsStxGetTransactionsRefreshTime, swapsStxBatchStatusRefreshTime: oldState.swapsState.swapsStxBatchStatusRefreshTime, - swapsStxStatusDeadline: oldState.swapsState.swapsStxStatusDeadline, }); }); @@ -1175,6 +1174,7 @@ describe('SwapsController', function () { const swapsStxBatchStatusRefreshTime = 0; const swapsStxGetTransactionsRefreshTime = 0; const swapsStxStatusDeadline = 0; + swapsController.__test__updateState({ swapsState: { ...swapsController.state.swapsState, diff --git a/app/scripts/lib/ppom/ppom-middleware.test.ts b/app/scripts/lib/ppom/ppom-middleware.test.ts index aafde70f2072..f46aa8036d03 100644 --- a/app/scripts/lib/ppom/ppom-middleware.test.ts +++ b/app/scripts/lib/ppom/ppom-middleware.test.ts @@ -1,6 +1,5 @@ import { type Hex, JsonRpcResponseStruct } from '@metamask/utils'; import { detectSIWE, SIWEMessage } from '@metamask/controller-utils'; - import { CHAIN_IDS } from '../../../../shared/constants/network'; import { @@ -8,6 +7,7 @@ import { BlockaidResultType, } from '../../../../shared/constants/security-provider'; import { flushPromises } from '../../../../test/lib/timer-helpers'; +import { mockNetworkState } from '../../../../test/stub/networks'; import { createPPOMMiddleware, PPOMMiddlewareRequest } from './ppom-middleware'; import { generateSecurityAlertId, @@ -36,18 +36,22 @@ const REQUEST_MOCK = { params: [], id: '', jsonrpc: '2.0' as const, - origin: 'test.com', - networkClientId: 'networkClientId', }; const createMiddleware = ( options: { - chainId?: Hex; + chainId?: Hex | null; error?: Error; securityAlertsEnabled?: boolean; - } = {}, + // TODO: Replace `any` with type + // eslint-disable-next-line @typescript-eslint/no-explicit-any + updateSecurityAlertResponse?: any; + } = { + updateSecurityAlertResponse: () => undefined, + }, ) => { - const { chainId, error, securityAlertsEnabled } = options; + const { chainId, error, securityAlertsEnabled, updateSecurityAlertResponse } = + options; const ppomController = {}; @@ -66,9 +70,10 @@ const createMiddleware = ( } const networkController = { - getNetworkConfigurationByNetworkClientId: jest - .fn() - .mockReturnValue({ chainId: chainId || CHAIN_IDS.MAINNET }), + state: { + ...mockNetworkState({ chainId: chainId || CHAIN_IDS.MAINNET }), + ...(chainId === null ? { providerConfig: {} } : undefined), + }, }; const appStateController = { @@ -79,9 +84,7 @@ const createMiddleware = ( listAccounts: () => [{ address: INTERNAL_ACCOUNT_ADDRESS }], }; - const updateSecurityAlertResponse = jest.fn(); - - const middleware = createPPOMMiddleware( + return createPPOMMiddleware( // TODO: Replace `any` with type // eslint-disable-next-line @typescript-eslint/no-explicit-any ppomController as any, @@ -98,16 +101,6 @@ const createMiddleware = ( accountsController as any, updateSecurityAlertResponse, ); - - return { - middleware, - ppomController, - preferenceController, - networkController, - appStateController, - accountsController, - updateSecurityAlertResponse, - }; }; describe('PPOMMiddleware', () => { @@ -135,29 +128,12 @@ describe('PPOMMiddleware', () => { }; }); - it('gets the network configuration for the request networkClientId', async () => { - const { middleware, networkController } = createMiddleware(); - - const req = { - ...REQUEST_MOCK, - method: 'eth_sendTransaction', - securityAlertResponse: undefined, - }; - - await middleware(req, { ...JsonRpcResponseStruct.TYPE }, () => undefined); - - await flushPromises(); - - expect( - networkController.getNetworkConfigurationByNetworkClientId, - ).toHaveBeenCalledTimes(1); - expect( - networkController.getNetworkConfigurationByNetworkClientId, - ).toHaveBeenCalledWith('networkClientId'); - }); - it('updates alert response after validating request', async () => { - const { middleware, updateSecurityAlertResponse } = createMiddleware(); + const updateSecurityAlertResponse = jest.fn(); + + const middlewareFunction = createMiddleware({ + updateSecurityAlertResponse, + }); const req = { ...REQUEST_MOCK, @@ -165,7 +141,11 @@ describe('PPOMMiddleware', () => { securityAlertResponse: undefined, }; - await middleware(req, { ...JsonRpcResponseStruct.TYPE }, () => undefined); + await middlewareFunction( + req, + { ...JsonRpcResponseStruct.TYPE }, + () => undefined, + ); await flushPromises(); @@ -178,7 +158,7 @@ describe('PPOMMiddleware', () => { }); it('adds loading response to confirmation requests while validation is in progress', async () => { - const { middleware } = createMiddleware(); + const middlewareFunction = createMiddleware(); const req: PPOMMiddlewareRequest<(string | { to: string })[]> = { ...REQUEST_MOCK, @@ -186,7 +166,11 @@ describe('PPOMMiddleware', () => { securityAlertResponse: undefined, }; - await middleware(req, { ...JsonRpcResponseStruct.TYPE }, () => undefined); + await middlewareFunction( + req, + { ...JsonRpcResponseStruct.TYPE }, + () => undefined, + ); expect(req.securityAlertResponse?.reason).toBe(BlockaidReason.inProgress); expect(req.securityAlertResponse?.result_type).toBe( @@ -195,7 +179,7 @@ describe('PPOMMiddleware', () => { }); it('does not do validation if the user has not enabled the preference', async () => { - const { middleware } = createMiddleware({ + const middlewareFunction = createMiddleware({ securityAlertsEnabled: false, }); @@ -206,7 +190,29 @@ describe('PPOMMiddleware', () => { }; // @ts-expect-error Passing in invalid input for testing purposes - await middleware(req, undefined, () => undefined); + await middlewareFunction(req, undefined, () => undefined); + + expect(req.securityAlertResponse).toBeUndefined(); + expect(validateRequestWithPPOM).not.toHaveBeenCalled(); + }); + + it('does not do validation if unable to get the chainId from the network provider config', async () => { + isChainSupportedMock.mockResolvedValue(false); + const middlewareFunction = createMiddleware({ + chainId: null, + }); + + const req = { + ...REQUEST_MOCK, + method: 'eth_sendTransaction', + securityAlertResponse: undefined, + }; + + await middlewareFunction( + req, + { ...JsonRpcResponseStruct.TYPE }, + () => undefined, + ); expect(req.securityAlertResponse).toBeUndefined(); expect(validateRequestWithPPOM).not.toHaveBeenCalled(); @@ -214,7 +220,7 @@ describe('PPOMMiddleware', () => { it('does not do validation if user is not on a supported network', async () => { isChainSupportedMock.mockResolvedValue(false); - const { middleware } = createMiddleware({ + const middlewareFunction = createMiddleware({ chainId: '0x2', }); @@ -224,14 +230,18 @@ describe('PPOMMiddleware', () => { securityAlertResponse: undefined, }; - await middleware(req, { ...JsonRpcResponseStruct.TYPE }, () => undefined); + await middlewareFunction( + req, + { ...JsonRpcResponseStruct.TYPE }, + () => undefined, + ); expect(req.securityAlertResponse).toBeUndefined(); expect(validateRequestWithPPOM).not.toHaveBeenCalled(); }); it('does not do validation when request is not for confirmation method', async () => { - const { middleware } = createMiddleware(); + const middlewareFunction = createMiddleware(); const req = { ...REQUEST_MOCK, @@ -239,14 +249,18 @@ describe('PPOMMiddleware', () => { securityAlertResponse: undefined, }; - await middleware(req, { ...JsonRpcResponseStruct.TYPE }, () => undefined); + await middlewareFunction( + req, + { ...JsonRpcResponseStruct.TYPE }, + () => undefined, + ); expect(req.securityAlertResponse).toBeUndefined(); expect(validateRequestWithPPOM).not.toHaveBeenCalled(); }); it('does not do validation when request is send to users own account', async () => { - const { middleware } = createMiddleware(); + const middlewareFunction = createMiddleware(); const req = { ...REQUEST_MOCK, @@ -255,14 +269,18 @@ describe('PPOMMiddleware', () => { securityAlertResponse: undefined, }; - await middleware(req, { ...JsonRpcResponseStruct.TYPE }, () => undefined); + await middlewareFunction( + req, + { ...JsonRpcResponseStruct.TYPE }, + () => undefined, + ); expect(req.securityAlertResponse).toBeUndefined(); expect(validateRequestWithPPOM).not.toHaveBeenCalled(); }); it('does not do validation for SIWE signature', async () => { - const { middleware } = createMiddleware({ + const middlewareFunction = createMiddleware({ securityAlertsEnabled: true, }); @@ -283,17 +301,17 @@ describe('PPOMMiddleware', () => { detectSIWEMock.mockReturnValue({ isSIWEMessage: true } as SIWEMessage); // @ts-expect-error Passing invalid input for testing purposes - await middleware(req, undefined, () => undefined); + await middlewareFunction(req, undefined, () => undefined); expect(req.securityAlertResponse).toBeUndefined(); expect(validateRequestWithPPOM).not.toHaveBeenCalled(); }); it('calls next method', async () => { - const { middleware } = createMiddleware(); + const middlewareFunction = createMiddleware(); const nextMock = jest.fn(); - await middleware( + await middlewareFunction( { ...REQUEST_MOCK, method: 'eth_sendTransaction' }, { ...JsonRpcResponseStruct.TYPE }, nextMock, @@ -308,7 +326,7 @@ describe('PPOMMiddleware', () => { const nextMock = jest.fn(); - const { middleware } = createMiddleware({ error }); + const middlewareFunction = createMiddleware({ error }); const req = { ...REQUEST_MOCK, @@ -316,7 +334,7 @@ describe('PPOMMiddleware', () => { securityAlertResponse: undefined, }; - await middleware(req, { ...JsonRpcResponseStruct.TYPE }, nextMock); + await middlewareFunction(req, { ...JsonRpcResponseStruct.TYPE }, nextMock); expect(req.securityAlertResponse).toStrictEqual( SECURITY_ALERT_RESPONSE_MOCK, diff --git a/app/scripts/lib/ppom/ppom-middleware.ts b/app/scripts/lib/ppom/ppom-middleware.ts index 5b9107337a05..1bad576e3881 100644 --- a/app/scripts/lib/ppom/ppom-middleware.ts +++ b/app/scripts/lib/ppom/ppom-middleware.ts @@ -1,9 +1,6 @@ import { AccountsController } from '@metamask/accounts-controller'; import { PPOMController } from '@metamask/ppom-validator'; -import { - NetworkClientId, - NetworkController, -} from '@metamask/network-controller'; +import { NetworkController } from '@metamask/network-controller'; import { Json, JsonRpcParams, @@ -17,6 +14,8 @@ import { SIGNING_METHODS } from '../../../../shared/constants/transaction'; import PreferencesController from '../../controllers/preferences-controller'; import { AppStateController } from '../../controllers/app-state'; import { LOADING_SECURITY_ALERT_RESPONSE } from '../../../../shared/constants/security-provider'; +// eslint-disable-next-line import/no-restricted-paths +import { getProviderConfig } from '../../../../ui/ducks/metamask/metamask'; import { trace, TraceContext, TraceName } from '../../../../shared/lib/trace'; import { generateSecurityAlertId, @@ -35,7 +34,6 @@ const CONFIRMATION_METHODS = Object.freeze([ export type PPOMMiddlewareRequest< Params extends JsonRpcParams = JsonRpcParams, > = Required> & { - networkClientId: NetworkClientId; securityAlertResponse?: SecurityAlertResponse | undefined; traceContext?: TraceContext; }; @@ -81,13 +79,14 @@ export function createPPOMMiddleware< const securityAlertsEnabled = preferencesController.store.getState()?.securityAlertsEnabled; - // This will always exist as the SelectedNetworkMiddleware - // adds networkClientId to the request before this middleware runs const { chainId } = - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - networkController.getNetworkConfigurationByNetworkClientId( - req.networkClientId, - )!; + getProviderConfig({ + metamask: networkController.state, + }) ?? {}; + if (!chainId) { + return; + } + const isSupportedChain = await isChainSupported(chainId); if ( diff --git a/app/scripts/lib/setupSentry.js b/app/scripts/lib/setupSentry.js index 14e3bc0934d8..13b4728a4423 100644 --- a/app/scripts/lib/setupSentry.js +++ b/app/scripts/lib/setupSentry.js @@ -302,7 +302,7 @@ async function getMetaMetricsEnabled() { function setSentryClient() { const clientOptions = getClientOptions(); - const { dsn, environment, release } = clientOptions; + const { dsn, environment, release, tracesSampleRate } = clientOptions; /** * Sentry throws on initialization as it wants to avoid polluting the global namespace and @@ -322,6 +322,7 @@ function setSentryClient() { environment, dsn, release, + tracesSampleRate, }); Sentry.registerSpanErrorInstrumentation(); @@ -425,6 +426,7 @@ export function rewriteReport(report) { } report.extra.appState = appState; + if (browser.runtime && browser.runtime.id) { report.extra.extensionId = browser.runtime.id; } diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js index a5445e16875a..38cd08914dd6 100644 --- a/app/scripts/metamask-controller.js +++ b/app/scripts/metamask-controller.js @@ -2768,7 +2768,7 @@ export default class MetamaskController extends EventEmitter { 'PhishingController:maybeUpdateState', ); }, - isOnPhishingList: (sender) => { + isOnPhishingList: (url) => { const { usePhishDetect } = this.preferencesController.store.getState(); @@ -2778,7 +2778,7 @@ export default class MetamaskController extends EventEmitter { return this.controllerMessenger.call( 'PhishingController:testOrigin', - sender.url, + url, ).result; }, createInterface: this.controllerMessenger.call.bind( @@ -5595,7 +5595,6 @@ export default class MetamaskController extends EventEmitter { engine.push(createTracingMiddleware()); - // PPOMMiddleware come after the SelectedNetworkMiddleware engine.push( createPPOMMiddleware( this.ppomController, diff --git a/app/scripts/migrations/126.1.test.ts b/app/scripts/migrations/126.1.test.ts new file mode 100644 index 000000000000..0d21a675ebcc --- /dev/null +++ b/app/scripts/migrations/126.1.test.ts @@ -0,0 +1,142 @@ +import { migrate, version } from './126.1'; + +const oldVersion = 126.1; + +const mockPhishingListMetaMask = { + allowlist: [], + blocklist: ['malicious1.com'], + c2DomainBlocklist: ['malicious2.com'], + fuzzylist: [], + tolerance: 0, + version: 1, + lastUpdated: Date.now(), + name: 'MetaMask', +}; + +const mockPhishingListPhishfort = { + allowlist: [], + blocklist: ['phishfort1.com'], + c2DomainBlocklist: ['phishfort2.com'], + fuzzylist: [], + tolerance: 0, + version: 1, + lastUpdated: Date.now(), + name: 'Phishfort', +}; + +describe(`migration #${version}`, () => { + it('updates the version metadata', async () => { + const oldStorage = { + meta: { version: oldVersion }, + data: {}, + }; + + const newStorage = await migrate(oldStorage); + + expect(newStorage.meta).toStrictEqual({ version }); + }); + + it('keeps only the MetaMask phishing list in PhishingControllerState', async () => { + const oldState = { + PhishingController: { + phishingLists: [mockPhishingListMetaMask, mockPhishingListPhishfort], + whitelist: [], + hotlistLastFetched: 0, + stalelistLastFetched: 0, + c2DomainBlocklistLastFetched: 0, + }, + }; + + const transformedState = await migrate({ + meta: { version: oldVersion }, + data: oldState, + }); + + const updatedPhishingController = transformedState.data + .PhishingController as Record; + + expect(updatedPhishingController.phishingLists).toStrictEqual([ + mockPhishingListMetaMask, + ]); + }); + + it('removes all phishing lists if MetaMask is not present', async () => { + const oldState = { + PhishingController: { + phishingLists: [mockPhishingListPhishfort], + whitelist: [], + hotlistLastFetched: 0, + stalelistLastFetched: 0, + c2DomainBlocklistLastFetched: 0, + }, + }; + + const transformedState = await migrate({ + meta: { version: oldVersion }, + data: oldState, + }); + + const updatedPhishingController = transformedState.data + .PhishingController as Record; + + expect(updatedPhishingController.phishingLists).toStrictEqual([]); + }); + + it('does nothing if PhishingControllerState is empty', async () => { + const oldState = { + PhishingController: { + phishingLists: [], + whitelist: [], + hotlistLastFetched: 0, + stalelistLastFetched: 0, + c2DomainBlocklistLastFetched: 0, + }, + }; + + const transformedState = await migrate({ + meta: { version: oldVersion }, + data: oldState, + }); + + const updatedPhishingController = transformedState.data + .PhishingController as Record; + + expect(updatedPhishingController.phishingLists).toStrictEqual([]); + }); + + it('does nothing if PhishingController is not in the state', async () => { + const oldState = { + NetworkController: { + providerConfig: { + chainId: '0x1', + }, + }, + }; + + const transformedState = await migrate({ + meta: { version: oldVersion }, + data: oldState, + }); + + expect(transformedState.data).toStrictEqual(oldState); + }); + + it('does nothing if phishingLists is not an array (null)', async () => { + const oldState: Record = { + PhishingController: { + phishingLists: null, + whitelist: [], + hotlistLastFetched: 0, + stalelistLastFetched: 0, + c2DomainBlocklistLastFetched: 0, + }, + }; + + const transformedState = await migrate({ + meta: { version: oldVersion }, + data: oldState, + }); + + expect(transformedState.data).toStrictEqual(oldState); + }); +}); diff --git a/app/scripts/migrations/126.1.ts b/app/scripts/migrations/126.1.ts new file mode 100644 index 000000000000..81e609e672f1 --- /dev/null +++ b/app/scripts/migrations/126.1.ts @@ -0,0 +1,54 @@ +import { hasProperty, isObject } from '@metamask/utils'; +import { cloneDeep } from 'lodash'; + +type VersionedData = { + meta: { version: number }; + data: Record; +}; + +export const version = 126.1; + +/** + * This migration removes `providerConfig` from the network controller state. + * + * @param originalVersionedData - Versioned MetaMask extension state, exactly what we persist to dist. + * @param originalVersionedData.meta - State metadata. + * @param originalVersionedData.meta.version - The current state version. + * @param originalVersionedData.data - The persisted MetaMask state, keyed by controller. + * @returns Updated versioned MetaMask extension state. + */ +export async function migrate( + originalVersionedData: VersionedData, +): Promise { + const versionedData = cloneDeep(originalVersionedData); + versionedData.meta.version = version; + transformState(versionedData.data); + return versionedData; +} + +function transformState( + state: Record, +): Record { + if ( + hasProperty(state, 'PhishingController') && + isObject(state.PhishingController) && + hasProperty(state.PhishingController, 'phishingLists') + ) { + const phishingController = state.PhishingController; + + if (!Array.isArray(phishingController.phishingLists)) { + console.error( + `Migration ${version}: Invalid PhishingController.phishingLists state`, + ); + return state; + } + + phishingController.phishingLists = phishingController.phishingLists.filter( + (list) => list.name === 'MetaMask', + ); + + state.PhishingController = phishingController; + } + + return state; +} diff --git a/app/scripts/migrations/index.js b/app/scripts/migrations/index.js index 296ff8077613..883d3081ef46 100644 --- a/app/scripts/migrations/index.js +++ b/app/scripts/migrations/index.js @@ -146,6 +146,7 @@ const migrations = [ require('./125'), require('./125.1'), require('./126'), + require('./126.1'), require('./127'), require('./128'), require('./129'), diff --git a/lavamoat/browserify/beta/policy.json b/lavamoat/browserify/beta/policy.json index 380e38cd7a63..81dbe331237d 100644 --- a/lavamoat/browserify/beta/policy.json +++ b/lavamoat/browserify/beta/policy.json @@ -2036,6 +2036,7 @@ "Event": true, "Headers": true, "TextDecoder": true, + "TextEncoder": true, "URL": true, "URLSearchParams": true, "addEventListener": true, @@ -2946,7 +2947,7 @@ }, "@sentry/browser": { "globals": { - "PerformanceObserver.supportedEntryTypes.includes": true, + "PerformanceObserver.supportedEntryTypes": true, "Request": true, "URL": true, "XMLHttpRequest.prototype": true, @@ -3043,7 +3044,8 @@ "innerWidth": true, "location.href": true, "location.origin": true, - "parent": true + "parent": true, + "setTimeout": true }, "packages": { "@sentry/browser>@sentry-internal/browser-utils": true, diff --git a/lavamoat/browserify/flask/policy.json b/lavamoat/browserify/flask/policy.json index 380e38cd7a63..81dbe331237d 100644 --- a/lavamoat/browserify/flask/policy.json +++ b/lavamoat/browserify/flask/policy.json @@ -2036,6 +2036,7 @@ "Event": true, "Headers": true, "TextDecoder": true, + "TextEncoder": true, "URL": true, "URLSearchParams": true, "addEventListener": true, @@ -2946,7 +2947,7 @@ }, "@sentry/browser": { "globals": { - "PerformanceObserver.supportedEntryTypes.includes": true, + "PerformanceObserver.supportedEntryTypes": true, "Request": true, "URL": true, "XMLHttpRequest.prototype": true, @@ -3043,7 +3044,8 @@ "innerWidth": true, "location.href": true, "location.origin": true, - "parent": true + "parent": true, + "setTimeout": true }, "packages": { "@sentry/browser>@sentry-internal/browser-utils": true, diff --git a/lavamoat/browserify/main/policy.json b/lavamoat/browserify/main/policy.json index 380e38cd7a63..81dbe331237d 100644 --- a/lavamoat/browserify/main/policy.json +++ b/lavamoat/browserify/main/policy.json @@ -2036,6 +2036,7 @@ "Event": true, "Headers": true, "TextDecoder": true, + "TextEncoder": true, "URL": true, "URLSearchParams": true, "addEventListener": true, @@ -2946,7 +2947,7 @@ }, "@sentry/browser": { "globals": { - "PerformanceObserver.supportedEntryTypes.includes": true, + "PerformanceObserver.supportedEntryTypes": true, "Request": true, "URL": true, "XMLHttpRequest.prototype": true, @@ -3043,7 +3044,8 @@ "innerWidth": true, "location.href": true, "location.origin": true, - "parent": true + "parent": true, + "setTimeout": true }, "packages": { "@sentry/browser>@sentry-internal/browser-utils": true, diff --git a/lavamoat/browserify/mmi/policy.json b/lavamoat/browserify/mmi/policy.json index 576041b08cfb..672413e581ed 100644 --- a/lavamoat/browserify/mmi/policy.json +++ b/lavamoat/browserify/mmi/policy.json @@ -2128,6 +2128,7 @@ "Event": true, "Headers": true, "TextDecoder": true, + "TextEncoder": true, "URL": true, "URLSearchParams": true, "addEventListener": true, @@ -3038,7 +3039,7 @@ }, "@sentry/browser": { "globals": { - "PerformanceObserver.supportedEntryTypes.includes": true, + "PerformanceObserver.supportedEntryTypes": true, "Request": true, "URL": true, "XMLHttpRequest.prototype": true, @@ -3135,7 +3136,8 @@ "innerWidth": true, "location.href": true, "location.origin": true, - "parent": true + "parent": true, + "setTimeout": true }, "packages": { "@sentry/browser>@sentry-internal/browser-utils": true, diff --git a/package.json b/package.json index c3f3867bf3c3..ce85b9d31f6b 100644 --- a/package.json +++ b/package.json @@ -266,7 +266,8 @@ "@metamask/network-controller@npm:^17.0.0": "patch:@metamask/network-controller@npm%3A21.0.0#~/.yarn/patches/@metamask-network-controller-npm-21.0.0-559aa8e395.patch", "@metamask/network-controller@npm:^19.0.0": "patch:@metamask/network-controller@npm%3A21.0.0#~/.yarn/patches/@metamask-network-controller-npm-21.0.0-559aa8e395.patch", "@metamask/network-controller@npm:^20.0.0": "patch:@metamask/network-controller@npm%3A21.0.0#~/.yarn/patches/@metamask-network-controller-npm-21.0.0-559aa8e395.patch", - "path-to-regexp": "1.9.0" + "path-to-regexp": "1.9.0", + "@metamask/snaps-utils@npm:^8.1.1": "patch:@metamask/snaps-utils@npm%3A8.1.1#~/.yarn/patches/@metamask-snaps-utils-npm-8.1.1-7d5dd6a26a.patch" }, "dependencies": { "@babel/runtime": "patch:@babel/runtime@npm%3A7.24.0#~/.yarn/patches/@babel-runtime-npm-7.24.0-7eb1dd11a2.patch", @@ -344,7 +345,7 @@ "@metamask/post-message-stream": "^8.0.0", "@metamask/ppom-validator": "0.34.0", "@metamask/preinstalled-example-snap": "^0.1.0", - "@metamask/profile-sync-controller": "^0.9.4", + "@metamask/profile-sync-controller": "^0.9.7", "@metamask/providers": "^14.0.2", "@metamask/queued-request-controller": "^2.0.0", "@metamask/rate-limit-controller": "^6.0.0", @@ -358,7 +359,7 @@ "@metamask/snaps-execution-environments": "^6.7.2", "@metamask/snaps-rpc-methods": "^11.1.1", "@metamask/snaps-sdk": "^6.5.1", - "@metamask/snaps-utils": "^8.1.1", + "@metamask/snaps-utils": "patch:@metamask/snaps-utils@npm%3A8.1.1#~/.yarn/patches/@metamask-snaps-utils-npm-8.1.1-7d5dd6a26a.patch", "@metamask/transaction-controller": "^37.0.0", "@metamask/user-operation-controller": "^13.0.0", "@metamask/utils": "^9.1.0", @@ -367,9 +368,9 @@ "@popperjs/core": "^2.4.0", "@reduxjs/toolkit": "patch:@reduxjs/toolkit@npm%3A1.9.7#~/.yarn/patches/@reduxjs-toolkit-npm-1.9.7-b14925495c.patch", "@segment/loosely-validate-event": "^2.0.0", - "@sentry/browser": "^8.19.0", - "@sentry/types": "^8.19.0", - "@sentry/utils": "^8.19.0", + "@sentry/browser": "^8.33.1", + "@sentry/types": "^8.33.1", + "@sentry/utils": "^8.33.1", "@swc/core": "1.4.11", "@trezor/connect-web": "patch:@trezor/connect-web@npm%3A9.3.0#~/.yarn/patches/@trezor-connect-web-npm-9.3.0-040ab10d9a.patch", "@zxing/browser": "^0.1.4", diff --git a/shared/lib/trace.test.ts b/shared/lib/trace.test.ts index 5154a930b7f9..7cd39eba03d1 100644 --- a/shared/lib/trace.test.ts +++ b/shared/lib/trace.test.ts @@ -1,4 +1,5 @@ import { + setMeasurement, Span, startSpan, startSpanManual, @@ -10,6 +11,7 @@ jest.mock('@sentry/browser', () => ({ withIsolationScope: jest.fn(), startSpan: jest.fn(), startSpanManual: jest.fn(), + setMeasurement: jest.fn(), })); const NAME_MOCK = TraceName.Transaction; @@ -32,7 +34,8 @@ describe('Trace', () => { const startSpanMock = jest.mocked(startSpan); const startSpanManualMock = jest.mocked(startSpanManual); const withIsolationScopeMock = jest.mocked(withIsolationScope); - const setTagsMock = jest.fn(); + const setMeasurementMock = jest.mocked(setMeasurement); + const setTagMock = jest.fn(); beforeEach(() => { jest.resetAllMocks(); @@ -41,13 +44,20 @@ describe('Trace', () => { startSpan: startSpanMock, startSpanManual: startSpanManualMock, withIsolationScope: withIsolationScopeMock, + setMeasurement: setMeasurementMock, }; startSpanMock.mockImplementation((_, fn) => fn({} as Span)); + startSpanManualMock.mockImplementation((_, fn) => + fn({} as Span, () => { + // Intentionally empty + }), + ); + // eslint-disable-next-line @typescript-eslint/no-explicit-any withIsolationScopeMock.mockImplementation((fn: any) => - fn({ setTags: setTagsMock }), + fn({ setTag: setTagMock }), ); }); @@ -91,8 +101,12 @@ describe('Trace', () => { expect.any(Function), ); - expect(setTagsMock).toHaveBeenCalledTimes(1); - expect(setTagsMock).toHaveBeenCalledWith(TAGS_MOCK); + expect(setTagMock).toHaveBeenCalledTimes(2); + expect(setTagMock).toHaveBeenCalledWith('tag1', 'value1'); + expect(setTagMock).toHaveBeenCalledWith('tag2', true); + + expect(setMeasurementMock).toHaveBeenCalledTimes(1); + expect(setMeasurementMock).toHaveBeenCalledWith('tag3', 123, 'none'); }); it('invokes Sentry if no callback provided', () => { @@ -117,8 +131,12 @@ describe('Trace', () => { expect.any(Function), ); - expect(setTagsMock).toHaveBeenCalledTimes(1); - expect(setTagsMock).toHaveBeenCalledWith(TAGS_MOCK); + expect(setTagMock).toHaveBeenCalledTimes(2); + expect(setTagMock).toHaveBeenCalledWith('tag1', 'value1'); + expect(setTagMock).toHaveBeenCalledWith('tag2', true); + + expect(setMeasurementMock).toHaveBeenCalledTimes(1); + expect(setMeasurementMock).toHaveBeenCalledWith('tag3', 123, 'none'); }); it('invokes Sentry if no callback provided with custom start time', () => { @@ -145,8 +163,12 @@ describe('Trace', () => { expect.any(Function), ); - expect(setTagsMock).toHaveBeenCalledTimes(1); - expect(setTagsMock).toHaveBeenCalledWith(TAGS_MOCK); + expect(setTagMock).toHaveBeenCalledTimes(2); + expect(setTagMock).toHaveBeenCalledWith('tag1', 'value1'); + expect(setTagMock).toHaveBeenCalledWith('tag2', true); + + expect(setMeasurementMock).toHaveBeenCalledTimes(1); + expect(setMeasurementMock).toHaveBeenCalledWith('tag3', 123, 'none'); }); }); diff --git a/shared/lib/trace.ts b/shared/lib/trace.ts index 0c667a346235..5ca256371502 100644 --- a/shared/lib/trace.ts +++ b/shared/lib/trace.ts @@ -1,10 +1,13 @@ import * as Sentry from '@sentry/browser'; -import { Primitive, StartSpanOptions } from '@sentry/types'; +import { MeasurementUnit, StartSpanOptions } from '@sentry/types'; import { createModuleLogger } from '@metamask/utils'; // TODO: Remove restricted import // eslint-disable-next-line import/no-restricted-paths import { log as sentryLogger } from '../../app/scripts/lib/setupSentry'; +/** + * The supported trace names. + */ export enum TraceName { BackgroundConnect = 'Background Connect', DeveloperTest = 'Developer Test', @@ -36,22 +39,71 @@ type PendingTrace = { startTime: number; }; +/** + * A context object to associate traces with each other and generate nested traces. + */ export type TraceContext = unknown; +/** + * A callback function that can be traced. + */ export type TraceCallback = (context?: TraceContext) => T; +/** + * A request to create a new trace. + */ export type TraceRequest = { + /** + * Custom data to associate with the trace. + */ data?: Record; + + /** + * A unique identifier when not tracing a callback. + * Defaults to 'default' if not provided. + */ id?: string; + + /** + * The name of the trace. + */ name: TraceName; + + /** + * The parent context of the trace. + * If provided, the trace will be nested under the parent trace. + */ parentContext?: TraceContext; + + /** + * Override the start time of the trace. + */ startTime?: number; + + /** + * Custom tags to associate with the trace. + */ tags?: Record; }; +/** + * A request to end a pending trace. + */ export type EndTraceRequest = { + /** + * The unique identifier of the trace. + * Defaults to 'default' if not provided. + */ id?: string; + + /** + * The name of the trace. + */ name: TraceName; + + /** + * Override the end time of the trace. + */ timestamp?: number; }; @@ -59,6 +111,16 @@ export function trace(request: TraceRequest, fn: TraceCallback): T; export function trace(request: TraceRequest): TraceContext; +/** + * Create a Sentry transaction to analyse the duration of a code flow. + * If a callback is provided, the transaction will be automatically ended when the callback completes. + * If the callback returns a promise, the transaction will be ended when the promise resolves or rejects. + * If no callback is provided, the transaction must be manually ended using `endTrace`. + * + * @param request - The data associated with the trace, such as the name and tags. + * @param fn - The optional callback to record the duration of. + * @returns The context of the trace, or the result of the callback if provided. + */ export function trace( request: TraceRequest, fn?: TraceCallback, @@ -70,6 +132,12 @@ export function trace( return traceCallback(request, fn); } +/** + * End a pending trace that was started without a callback. + * Does nothing if the pending trace cannot be found. + * + * @param request - The data necessary to identify and end the pending trace. + */ export function endTrace(request: EndTraceRequest) { const { name, timestamp } = request; const id = getTraceId(request); @@ -101,6 +169,10 @@ function traceCallback(request: TraceRequest, fn: TraceCallback): T { const start = Date.now(); let error: unknown; + if (span) { + initSpan(span, request); + } + return tryCatchMaybePromise( () => fn(span), (currentError) => { @@ -131,6 +203,10 @@ function startTrace(request: TraceRequest): TraceContext { span?.end(timestamp); }; + if (span) { + initSpan(span, request); + } + const pendingTrace = { end, request, startTime }; const key = getTraceKey(request); tracesByKey.set(key, pendingTrace); @@ -149,7 +225,7 @@ function startSpan( request: TraceRequest, callback: (spanOptions: StartSpanOptions) => T, ) { - const { data: attributes, name, parentContext, startTime, tags } = request; + const { data: attributes, name, parentContext, startTime } = request; const parentSpan = (parentContext ?? null) as Sentry.Span | null; const spanOptions: StartSpanOptions = { @@ -161,8 +237,7 @@ function startSpan( }; return sentryWithIsolationScope((scope: Sentry.Scope) => { - scope.setTags(tags as Record); - + initScope(scope, request); return callback(spanOptions); }); } @@ -182,6 +257,40 @@ function getPerformanceTimestamp(): number { return performance.timeOrigin + performance.now(); } +/** + * Initialise the isolated Sentry scope created for each trace. + * Includes setting all non-numeric tags. + * + * @param scope - The Sentry scope to initialise. + * @param request - The trace request. + */ +function initScope(scope: Sentry.Scope, request: TraceRequest) { + const tags = request.tags ?? {}; + + for (const [key, value] of Object.entries(tags)) { + if (typeof value !== 'number') { + scope.setTag(key, value); + } + } +} + +/** + * Initialise the Sentry span created for each trace. + * Includes setting all numeric tags as measurements so they can be queried numerically in Sentry. + * + * @param _span - The Sentry span to initialise. + * @param request - The trace request. + */ +function initSpan(_span: Sentry.Span, request: TraceRequest) { + const tags = request.tags ?? {}; + + for (const [key, value] of Object.entries(tags)) { + if (typeof value === 'number') { + sentrySetMeasurement(key, value, 'none'); + } + } +} + function tryCatchMaybePromise( tryFn: () => T, catchFn: (error: unknown) => void, @@ -243,7 +352,7 @@ function sentryWithIsolationScope(callback: (scope: Sentry.Scope) => T): T { if (!actual) { const scope = { // eslint-disable-next-line no-empty-function - setTags: () => {}, + setTag: () => {}, } as unknown as Sentry.Scope; return callback(scope); @@ -251,3 +360,17 @@ function sentryWithIsolationScope(callback: (scope: Sentry.Scope) => T): T { return actual(callback); } + +function sentrySetMeasurement( + key: string, + value: number, + unit: MeasurementUnit, +) { + const actual = globalThis.sentry?.setMeasurement; + + if (!actual) { + return; + } + + actual(key, value, unit); +} diff --git a/shared/modules/hexstring-utils.test.js b/shared/modules/hexstring-utils.test.js index 5fe876428bcc..9bfeac1978e1 100644 --- a/shared/modules/hexstring-utils.test.js +++ b/shared/modules/hexstring-utils.test.js @@ -1,5 +1,5 @@ import { toChecksumAddress } from 'ethereumjs-util'; -import { isPossibleAddress, isValidHexAddress } from './hexstring-utils'; +import { isValidHexAddress, isPossibleAddress } from './hexstring-utils'; describe('hexstring utils', function () { describe('isPossibleAddress', function () { diff --git a/test/data/confirmations/contract-interaction.ts b/test/data/confirmations/contract-interaction.ts index 507a27a48dc3..49a6e1aad1ab 100644 --- a/test/data/confirmations/contract-interaction.ts +++ b/test/data/confirmations/contract-interaction.ts @@ -1,4 +1,6 @@ import { + SimulationData, + TransactionMeta, TransactionStatus, TransactionType, } from '@metamask/transaction-controller'; @@ -22,12 +24,14 @@ export const genUnapprovedContractInteractionConfirmation = ({ address = CONTRACT_INTERACTION_SENDER_ADDRESS, txData = DEPOSIT_METHOD_DATA, chainId = CHAIN_ID, + simulationData, }: { address?: Hex; txData?: Hex; chainId?: string; -} = {}): Confirmation => - ({ + simulationData?: SimulationData; +} = {}): Confirmation => { + const confirmation: Confirmation = { actionId: String(400855682), chainId, dappSuggestedGasFees: { @@ -160,4 +164,12 @@ export const genUnapprovedContractInteractionConfirmation = ({ userEditedGasLimit: false, userFeeLevel: 'medium', verifiedOnBlockchain: false, - } as SignatureRequestType); + } as SignatureRequestType; + + // Overwrite simulation data if provided + if (simulationData) { + (confirmation as TransactionMeta).simulationData = simulationData; + } + + return confirmation; +}; diff --git a/test/e2e/tests/transaction/send-edit.spec.js b/test/e2e/tests/transaction/send-edit.spec.js index 953f2ebf3569..e5a74798d8fd 100644 --- a/test/e2e/tests/transaction/send-edit.spec.js +++ b/test/e2e/tests/transaction/send-edit.spec.js @@ -1,4 +1,5 @@ const { strict: assert } = require('assert'); + const { createInternalTransaction, } = require('../../page-objects/flows/transaction'); diff --git a/ui/components/app/snaps/snap-ui-renderer/index.scss b/ui/components/app/snaps/snap-ui-renderer/index.scss index b1bc569af333..7e18e72c917f 100644 --- a/ui/components/app/snaps/snap-ui-renderer/index.scss +++ b/ui/components/app/snaps/snap-ui-renderer/index.scss @@ -1,4 +1,10 @@ +@use "design-system"; + .snap-ui-renderer { + $width-screen-sm-min: 85vw; + $width-screen-md-min: 80vw; + $width-screen-lg-min: 62vw; + &__content { margin-bottom: 0 !important; } @@ -69,5 +75,17 @@ &__footer { margin-top: auto; + + @include design-system.screen-sm-min { + max-width: $width-screen-sm-min; + } + + @include design-system.screen-md-min { + max-width: $width-screen-md-min; + } + + @include design-system.screen-lg-min { + max-width: $width-screen-lg-min; + } } } diff --git a/ui/components/multichain/asset-picker-amount/asset-picker-modal/asset-picker-modal.tsx b/ui/components/multichain/asset-picker-amount/asset-picker-modal/asset-picker-modal.tsx index 0d9e01627878..ac6f658f33a0 100644 --- a/ui/components/multichain/asset-picker-amount/asset-picker-modal/asset-picker-modal.tsx +++ b/ui/components/multichain/asset-picker-amount/asset-picker-modal/asset-picker-modal.tsx @@ -59,6 +59,7 @@ import { } from './types'; import { AssetPickerModalTabs, TabName } from './asset-picker-modal-tabs'; import { AssetPickerModalNftTab } from './asset-picker-modal-nft-tab'; + import AssetList from './AssetList'; import { Search } from './asset-picker-modal-search'; diff --git a/ui/components/multichain/asset-picker-amount/asset-picker/asset-picker.tsx b/ui/components/multichain/asset-picker-amount/asset-picker/asset-picker.tsx index 3b1526e4af62..f8ea081db21a 100644 --- a/ui/components/multichain/asset-picker-amount/asset-picker/asset-picker.tsx +++ b/ui/components/multichain/asset-picker-amount/asset-picker/asset-picker.tsx @@ -33,6 +33,7 @@ import { LARGE_SYMBOL_LENGTH } from '../constants'; ///: BEGIN:ONLY_INCLUDE_IF(build-main,build-beta,build-flask) import { useI18nContext } from '../../../../hooks/useI18nContext'; ///: END:ONLY_INCLUDE_IF + import { ellipsify } from '../../../../pages/confirmations/send/send.utils'; import { AssetWithDisplayData, diff --git a/ui/ducks/swaps/swaps.js b/ui/ducks/swaps/swaps.js index 97daa88726d3..91521801119b 100644 --- a/ui/ducks/swaps/swaps.js +++ b/ui/ducks/swaps/swaps.js @@ -5,6 +5,7 @@ import log from 'loglevel'; import { captureMessage } from '@sentry/browser'; import { TransactionType } from '@metamask/transaction-controller'; +import { CHAIN_IDS } from '../../../shared/constants/network'; import { addToken, addTransactionAndWaitForPublish, @@ -1257,6 +1258,21 @@ export const signAndSendTransactions = ( }, }, ); + if ( + [ + CHAIN_IDS.LINEA_MAINNET, + CHAIN_IDS.LINEA_GOERLI, + CHAIN_IDS.LINEA_SEPOLIA, + ].includes(chainId) + ) { + log.debug( + 'Delaying submitting trade tx to make Linea confirmation more likely', + ); + const waitPromise = new Promise((resolve) => + setTimeout(resolve, 5000), + ); + await waitPromise; + } } catch (e) { await dispatch(setSwapsErrorKey(SWAP_FAILED_ERROR)); history.push(SWAPS_ERROR_ROUTE); diff --git a/ui/helpers/utils/tags.test.ts b/ui/helpers/utils/tags.test.ts new file mode 100644 index 000000000000..eae5e90f9ea1 --- /dev/null +++ b/ui/helpers/utils/tags.test.ts @@ -0,0 +1,206 @@ +// TODO: Remove restricted import +// eslint-disable-next-line import/no-restricted-paths +import { getEnvironmentType } from '../../../app/scripts/lib/util'; +import { ENVIRONMENT_TYPE_FULLSCREEN } from '../../../shared/constants/app'; +import { MetaMaskReduxState } from '../../store/store'; +import { getStartupTraceTags } from './tags'; + +jest.mock('../../../app/scripts/lib/util', () => ({ + ...jest.requireActual('../../../app/scripts/lib/util'), + getEnvironmentType: jest.fn(), +})); + +const STATE_EMPTY_MOCK = { + metamask: { + allTokens: {}, + internalAccounts: { + accounts: {}, + }, + metamaskNotificationsList: [], + }, +} as unknown as MetaMaskReduxState; + +function createMockState( + metamaskState: Partial, +): MetaMaskReduxState { + return { + ...STATE_EMPTY_MOCK, + metamask: { + ...STATE_EMPTY_MOCK.metamask, + ...metamaskState, + }, + }; +} + +describe('Tags Utils', () => { + const getEnvironmentTypeMock = jest.mocked(getEnvironmentType); + + beforeEach(() => { + jest.resetAllMocks(); + }); + + describe('getStartupTraceTags', () => { + it('includes UI type', () => { + getEnvironmentTypeMock.mockReturnValue(ENVIRONMENT_TYPE_FULLSCREEN); + + const tags = getStartupTraceTags(STATE_EMPTY_MOCK); + + expect(tags['wallet.ui_type']).toStrictEqual(ENVIRONMENT_TYPE_FULLSCREEN); + }); + + it('includes if unlocked', () => { + const state = createMockState({ isUnlocked: true }); + const tags = getStartupTraceTags(state); + + expect(tags['wallet.unlocked']).toStrictEqual(true); + }); + + it('includes if not unlocked', () => { + const state = createMockState({ isUnlocked: false }); + const tags = getStartupTraceTags(state); + + expect(tags['wallet.unlocked']).toStrictEqual(false); + }); + + it('includes pending approval type', () => { + const state = createMockState({ + pendingApprovals: { + 1: { + type: 'eth_sendTransaction', + }, + } as unknown as MetaMaskReduxState['metamask']['pendingApprovals'], + }); + + const tags = getStartupTraceTags(state); + + expect(tags['wallet.pending_approval']).toStrictEqual( + 'eth_sendTransaction', + ); + }); + + it('includes first pending approval type if multiple', () => { + const state = createMockState({ + pendingApprovals: { + 1: { + type: 'eth_sendTransaction', + }, + 2: { + type: 'personal_sign', + }, + } as unknown as MetaMaskReduxState['metamask']['pendingApprovals'], + }); + + const tags = getStartupTraceTags(state); + + expect(tags['wallet.pending_approval']).toStrictEqual( + 'eth_sendTransaction', + ); + }); + + it('includes account count', () => { + const state = createMockState({ + internalAccounts: { + accounts: { + '0x1234': {}, + '0x4321': {}, + }, + } as unknown as MetaMaskReduxState['metamask']['internalAccounts'], + }); + + const tags = getStartupTraceTags(state); + + expect(tags['wallet.account_count']).toStrictEqual(2); + }); + + it('includes nft count', () => { + const state = createMockState({ + allNfts: { + '0x1234': { + '0x1': [ + { + tokenId: '1', + }, + { + tokenId: '2', + }, + ], + '0x2': [ + { + tokenId: '3', + }, + { + tokenId: '4', + }, + ], + }, + '0x4321': { + '0x3': [ + { + tokenId: '5', + }, + ], + }, + } as unknown as MetaMaskReduxState['metamask']['allNfts'], + }); + + const tags = getStartupTraceTags(state); + + expect(tags['wallet.nft_count']).toStrictEqual(5); + }); + + it('includes notification count', () => { + const state = createMockState({ + metamaskNotificationsList: [ + {}, + {}, + {}, + ] as unknown as MetaMaskReduxState['metamask']['metamaskNotificationsList'], + }); + + const tags = getStartupTraceTags(state); + + expect(tags['wallet.notification_count']).toStrictEqual(3); + }); + + it('includes token count', () => { + const state = createMockState({ + allTokens: { + '0x1': { + '0x1234': [{}, {}], + '0x4321': [{}], + }, + '0x2': { + '0x5678': [{}], + }, + } as unknown as MetaMaskReduxState['metamask']['allTokens'], + }); + + const tags = getStartupTraceTags(state); + + expect(tags['wallet.token_count']).toStrictEqual(4); + }); + + it('includes transaction count', () => { + const state = createMockState({ + transactions: [ + { + id: 1, + chainId: '0x1', + }, + { + id: 2, + chainId: '0x1', + }, + { + id: 3, + chainId: '0x2', + }, + ] as unknown as MetaMaskReduxState['metamask']['transactions'], + }); + + const tags = getStartupTraceTags(state); + + expect(tags['wallet.transaction_count']).toStrictEqual(3); + }); + }); +}); diff --git a/ui/helpers/utils/tags.ts b/ui/helpers/utils/tags.ts new file mode 100644 index 000000000000..4a253e214d82 --- /dev/null +++ b/ui/helpers/utils/tags.ts @@ -0,0 +1,42 @@ +// TODO: Remove restricted import +// eslint-disable-next-line import/no-restricted-paths +import { getEnvironmentType } from '../../../app/scripts/lib/util'; +import { getIsUnlocked } from '../../ducks/metamask/metamask'; +import { + getInternalAccounts, + getPendingApprovals, + getTransactions, + selectAllTokensFlat, +} from '../../selectors'; +import { getMetamaskNotifications } from '../../selectors/metamask-notifications/metamask-notifications'; +import { selectAllNftsFlat } from '../../selectors/nft'; +import { MetaMaskReduxState } from '../../store/store'; + +/** + * Generate the required tags for the UI startup trace. + * + * @param state - The current flattened UI state. + * @returns The tags for the startup trace. + */ +export function getStartupTraceTags(state: MetaMaskReduxState) { + const uiType = getEnvironmentType(); + const unlocked = getIsUnlocked(state) as boolean; + const accountCount = getInternalAccounts(state).length; + const nftCount = selectAllNftsFlat(state).length; + const notificationCount = getMetamaskNotifications(state).length; + const tokenCount = selectAllTokensFlat(state).length as number; + const transactionCount = getTransactions(state).length; + const pendingApprovals = getPendingApprovals(state); + const firstApprovalType = pendingApprovals?.[0]?.type; + + return { + 'wallet.account_count': accountCount, + 'wallet.nft_count': nftCount, + 'wallet.notification_count': notificationCount, + 'wallet.pending_approval': firstApprovalType, + 'wallet.token_count': tokenCount, + 'wallet.transaction_count': transactionCount, + 'wallet.unlocked': unlocked, + 'wallet.ui_type': uiType, + }; +} diff --git a/ui/index.js b/ui/index.js index fec0321164dd..bc427addb55e 100644 --- a/ui/index.js +++ b/ui/index.js @@ -39,6 +39,7 @@ import { import Root from './pages'; import txHelper from './helpers/utils/tx-helper'; import { setBackgroundConnection } from './store/background-connection'; +import { getStartupTraceTags } from './helpers/utils/tags'; log.setLevel(global.METAMASK_DEBUG ? 'debug' : 'warn', false); @@ -182,8 +183,14 @@ export async function setupInitialStore( async function startApp(metamaskState, backgroundConnection, opts) { const { traceContext } = opts; + const tags = getStartupTraceTags({ metamask: metamaskState }); + const store = await trace( - { name: TraceName.SetupStore, parentContext: traceContext }, + { + name: TraceName.SetupStore, + parentContext: traceContext, + tags, + }, () => setupInitialStore(metamaskState, backgroundConnection, opts.activeTab), ); diff --git a/ui/pages/confirmations/components/confirm/info/hooks/useDecodedTransactionData.test.ts b/ui/pages/confirmations/components/confirm/info/hooks/useDecodedTransactionData.test.ts index 35f2f42c4792..b96f149f0bdd 100644 --- a/ui/pages/confirmations/components/confirm/info/hooks/useDecodedTransactionData.test.ts +++ b/ui/pages/confirmations/components/confirm/info/hooks/useDecodedTransactionData.test.ts @@ -59,6 +59,20 @@ describe('useDecodedTransactionData', () => { }, ); + it('returns undefined if no transaction to', async () => { + const result = await runHook({ + currentConfirmation: { + chainId: CHAIN_ID_MOCK, + txParams: { + data: TRANSACTION_DATA_UNISWAP, + to: undefined, + } as TransactionParams, + }, + }); + + expect(result).toStrictEqual({ pending: false, value: undefined }); + }); + it('returns the decoded data', async () => { decodeTransactionDataMock.mockResolvedValue(TRANSACTION_DECODE_SOURCIFY); diff --git a/ui/pages/confirmations/components/confirm/info/hooks/useDecodedTransactionData.ts b/ui/pages/confirmations/components/confirm/info/hooks/useDecodedTransactionData.ts index b2d69df413d4..6934f893378d 100644 --- a/ui/pages/confirmations/components/confirm/info/hooks/useDecodedTransactionData.ts +++ b/ui/pages/confirmations/components/confirm/info/hooks/useDecodedTransactionData.ts @@ -18,9 +18,10 @@ export function useDecodedTransactionData(): AsyncResult< const chainId = currentConfirmation?.chainId as Hex; const contractAddress = currentConfirmation?.txParams?.to as Hex; const transactionData = currentConfirmation?.txParams?.data as Hex; + const transactionTo = currentConfirmation?.txParams?.to as Hex; return useAsyncResult(async () => { - if (!hasTransactionData(transactionData)) { + if (!hasTransactionData(transactionData) || !transactionTo) { return undefined; } @@ -29,5 +30,5 @@ export function useDecodedTransactionData(): AsyncResult< chainId, contractAddress, }); - }, [transactionData, chainId, contractAddress]); + }, [transactionData, transactionTo, chainId, contractAddress]); } diff --git a/ui/pages/confirmations/components/confirm/info/hooks/useFourByte.test.ts b/ui/pages/confirmations/components/confirm/info/hooks/useFourByte.test.ts index 5d4a023c82bb..9f1a848a96cd 100644 --- a/ui/pages/confirmations/components/confirm/info/hooks/useFourByte.test.ts +++ b/ui/pages/confirmations/components/confirm/info/hooks/useFourByte.test.ts @@ -34,7 +34,7 @@ describe('useFourByte', () => { expect(result.current.params).toEqual([]); }); - it('returns empty object if resolution is turned off', () => { + it('returns null if resolution disabled', () => { const currentConfirmation = genUnapprovedContractInteractionConfirmation({ address: CONTRACT_INTERACTION_SENDER_ADDRESS, txData: depositHexData, @@ -57,7 +57,7 @@ describe('useFourByte', () => { expect(result.current).toBeNull(); }); - it("returns undefined if it's not known even if resolution is enabled", () => { + it('returns null if not known even if resolution enabled', () => { const currentConfirmation = genUnapprovedContractInteractionConfirmation({ address: CONTRACT_INTERACTION_SENDER_ADDRESS, txData: depositHexData, @@ -77,4 +77,29 @@ describe('useFourByte', () => { expect(result.current).toBeNull(); }); + + it('returns null if no transaction to', () => { + const currentConfirmation = genUnapprovedContractInteractionConfirmation({ + address: CONTRACT_INTERACTION_SENDER_ADDRESS, + txData: depositHexData, + }) as TransactionMeta; + + currentConfirmation.txParams.to = undefined; + + const { result } = renderHookWithProvider( + () => useFourByte(currentConfirmation), + { + ...mockState, + metamask: { + ...mockState.metamask, + use4ByteResolution: true, + knownMethodData: { + [depositHexData]: { name: 'Deposit', params: [] }, + }, + }, + }, + ); + + expect(result.current).toBeNull(); + }); }); diff --git a/ui/pages/confirmations/components/confirm/info/hooks/useFourByte.ts b/ui/pages/confirmations/components/confirm/info/hooks/useFourByte.ts index 7e2b81b443bd..7fece13fb417 100644 --- a/ui/pages/confirmations/components/confirm/info/hooks/useFourByte.ts +++ b/ui/pages/confirmations/components/confirm/info/hooks/useFourByte.ts @@ -1,28 +1,41 @@ import { TransactionMeta } from '@metamask/transaction-controller'; import { useDispatch, useSelector } from 'react-redux'; import { useEffect } from 'react'; +import { Hex } from '@metamask/utils'; import { getKnownMethodData, use4ByteResolutionSelector, } from '../../../../../../selectors'; import { getContractMethodData } from '../../../../../../store/actions'; +import { hasTransactionData } from '../../../../../../../shared/modules/transaction.utils'; export const useFourByte = (currentConfirmation: TransactionMeta) => { const dispatch = useDispatch(); const isFourByteEnabled = useSelector(use4ByteResolutionSelector); - const transactionData = currentConfirmation?.txParams?.data; + const transactionTo = currentConfirmation?.txParams?.to; + const transactionData = currentConfirmation?.txParams?.data as + | Hex + | undefined; useEffect(() => { - if (!isFourByteEnabled || !transactionData) { + if ( + !isFourByteEnabled || + !hasTransactionData(transactionData) || + !transactionTo + ) { return; } dispatch(getContractMethodData(transactionData)); - }, [isFourByteEnabled, transactionData, dispatch]); + }, [isFourByteEnabled, transactionData, transactionTo, dispatch]); const methodData = useSelector((state) => getKnownMethodData(state, transactionData), ); + if (!transactionTo) { + return null; + } + return methodData; }; diff --git a/ui/pages/confirmations/components/confirm/info/shared/transaction-data/transaction-data.test.tsx b/ui/pages/confirmations/components/confirm/info/shared/transaction-data/transaction-data.test.tsx index 5a793508c744..33037e75850b 100644 --- a/ui/pages/confirmations/components/confirm/info/shared/transaction-data/transaction-data.test.tsx +++ b/ui/pages/confirmations/components/confirm/info/shared/transaction-data/transaction-data.test.tsx @@ -31,6 +31,7 @@ async function renderTransactionData(transactionData: string) { type: TransactionType.contractInteraction, status: TransactionStatus.unapproved, txParams: { + to: '0x1234', data: transactionData, }, } as Confirmation); diff --git a/ui/pages/confirmations/components/confirm/info/shared/transaction-details/transaction-details.test.tsx b/ui/pages/confirmations/components/confirm/info/shared/transaction-details/transaction-details.test.tsx index 34da84540e9b..e8735c3ec2c4 100644 --- a/ui/pages/confirmations/components/confirm/info/shared/transaction-details/transaction-details.test.tsx +++ b/ui/pages/confirmations/components/confirm/info/shared/transaction-details/transaction-details.test.tsx @@ -1,10 +1,14 @@ import React from 'react'; import configureMockStore from 'redux-mock-store'; import thunk from 'redux-thunk'; +import { SimulationErrorCode } from '@metamask/transaction-controller'; import { getMockConfirmState, + getMockConfirmStateForTransaction, getMockContractInteractionConfirmState, } from '../../../../../../../../test/data/confirmations/helper'; +import { genUnapprovedContractInteractionConfirmation } from '../../../../../../../../test/data/confirmations/contract-interaction'; +import { CHAIN_IDS } from '../../../../../../../../shared/constants/network'; import { renderWithConfirmContextProvider } from '../../../../../../../../test/lib/confirmations/render-helpers'; import { TransactionDetails } from './transaction-details'; @@ -39,4 +43,22 @@ describe('', () => { ); expect(container).toMatchSnapshot(); }); + + it('renders component for transaction details with amount', () => { + const simulationDataMock = { + error: { code: SimulationErrorCode.Disabled }, + tokenBalanceChanges: [], + }; + const contractInteraction = genUnapprovedContractInteractionConfirmation({ + simulationData: simulationDataMock, + chainId: CHAIN_IDS.GOERLI, + }); + const state = getMockConfirmStateForTransaction(contractInteraction); + const mockStore = configureMockStore(middleware)(state); + const { getByTestId } = renderWithConfirmContextProvider( + , + mockStore, + ); + expect(getByTestId('transaction-details-amount-row')).toBeInTheDocument(); + }); }); diff --git a/ui/pages/confirmations/components/confirm/info/shared/transaction-details/transaction-details.tsx b/ui/pages/confirmations/components/confirm/info/shared/transaction-details/transaction-details.tsx index e53387af325a..706729a8cc0a 100644 --- a/ui/pages/confirmations/components/confirm/info/shared/transaction-details/transaction-details.tsx +++ b/ui/pages/confirmations/components/confirm/info/shared/transaction-details/transaction-details.tsx @@ -16,6 +16,10 @@ import { selectPaymasterAddress } from '../../../../../../../selectors/account-a import { selectConfirmationAdvancedDetailsOpen } from '../../../../../selectors/preferences'; import { useConfirmContext } from '../../../../../context/confirm'; import { useFourByte } from '../../hooks/useFourByte'; +import { ConfirmInfoRowCurrency } from '../../../../../../../components/app/confirm/info/row/currency'; +import { PRIMARY } from '../../../../../../../helpers/constants/common'; +import { useUserPreferencedCurrency } from '../../../../../../../hooks/useUserPreferencedCurrency'; +import { HEX_ZERO } from '../constants'; export const OriginRow = () => { const t = useI18nContext(); @@ -83,6 +87,30 @@ export const MethodDataRow = () => { ); }; +const AmountRow = () => { + const t = useI18nContext(); + const { currentConfirmation } = useConfirmContext(); + const { currency } = useUserPreferencedCurrency(PRIMARY); + + const value = currentConfirmation?.txParams?.value; + const simulationData = currentConfirmation?.simulationData; + + if (!value || value === HEX_ZERO || !simulationData?.error) { + return null; + } + + return ( + + + + + + ); +}; + const PaymasterRow = () => { const t = useI18nContext(); const { currentConfirmation } = useConfirmContext(); @@ -124,6 +152,7 @@ export const TransactionDetails = () => { {showAdvancedDetails && } + ); diff --git a/ui/pages/confirmations/components/confirm/info/typed-sign/permit-simulation/permit-simulation.test.tsx b/ui/pages/confirmations/components/confirm/info/typed-sign/permit-simulation/permit-simulation.test.tsx index 1be34109a637..66125d9def17 100644 --- a/ui/pages/confirmations/components/confirm/info/typed-sign/permit-simulation/permit-simulation.test.tsx +++ b/ui/pages/confirmations/components/confirm/info/typed-sign/permit-simulation/permit-simulation.test.tsx @@ -5,6 +5,7 @@ import { act } from 'react-dom/test-utils'; import { getMockTypedSignConfirmStateForRequest } from '../../../../../../../../test/data/confirmations/helper'; import { renderWithConfirmContextProvider } from '../../../../../../../../test/lib/confirmations/render-helpers'; import { permitSignatureMsg } from '../../../../../../../../test/data/confirmations/typed_sign'; + import PermitSimulation from './permit-simulation'; jest.mock('../../../../../../../store/actions', () => { diff --git a/ui/pages/confirmations/confirm-transaction-base/confirm-transaction-base.component.js b/ui/pages/confirmations/confirm-transaction-base/confirm-transaction-base.component.js index 96fd5315e317..b4d2d6a8def5 100644 --- a/ui/pages/confirmations/confirm-transaction-base/confirm-transaction-base.component.js +++ b/ui/pages/confirmations/confirm-transaction-base/confirm-transaction-base.component.js @@ -215,6 +215,8 @@ export default class ConfirmTransactionBase extends Component { useMaxValue, hasPriorityApprovalRequest, mostRecentOverviewPage, + txData, + getNextNonce, } = this.props; const { @@ -225,6 +227,7 @@ export default class ConfirmTransactionBase extends Component { isEthGasPriceFetched: prevIsEthGasPriceFetched, hexMaximumTransactionFee: prevHexMaximumTransactionFee, hasPriorityApprovalRequest: prevHasPriorityApprovalRequest, + txData: prevTxData, } = prevProps; const statusUpdated = transactionStatus !== prevTxStatus; @@ -232,6 +235,10 @@ export default class ConfirmTransactionBase extends Component { transactionStatus === TransactionStatus.dropped || transactionStatus === TransactionStatus.confirmed; + if (txData.id !== prevTxData.id) { + getNextNonce(); + } + if ( nextNonce !== prevNextNonce || customNonceValue !== prevCustomNonceValue diff --git a/ui/pages/swaps/awaiting-swap/awaiting-swap.js b/ui/pages/swaps/awaiting-swap/awaiting-swap.js index e7f47bc3f006..660f7ef4fcae 100644 --- a/ui/pages/swaps/awaiting-swap/awaiting-swap.js +++ b/ui/pages/swaps/awaiting-swap/awaiting-swap.js @@ -97,6 +97,9 @@ export default function AwaitingSwap({ const [trackedQuotesExpiredEvent, setTrackedQuotesExpiredEvent] = useState(false); + const destinationTokenSymbol = + usedQuote?.destinationTokenInfo?.symbol || swapMetaData?.token_to; + let feeinUnformattedFiat; if (usedQuote && swapsGasPrice) { @@ -107,7 +110,7 @@ export default function AwaitingSwap({ currentCurrency, conversionRate: usdConversionRate, tradeValue: usedQuote?.trade?.value, - sourceSymbol: swapMetaData?.token_from, + sourceSymbol: usedQuote?.sourceTokenInfo?.symbol, sourceAmount: usedQuote.sourceAmount, chainId, }); @@ -123,13 +126,14 @@ export default function AwaitingSwap({ const currentSmartTransactionsEnabled = useSelector( getCurrentSmartTransactionsEnabled, ); + const swapSlippage = swapMetaData?.slippage || usedQuote?.slippage; const sensitiveProperties = { - token_from: swapMetaData?.token_from, + token_from: swapMetaData?.token_from || usedQuote?.sourceTokenInfo?.symbol, token_from_amount: swapMetaData?.token_from_amount, - token_to: swapMetaData?.token_to, + token_to: destinationTokenSymbol, request_type: fetchParams?.balanceError ? 'Quote' : 'Order', - slippage: swapMetaData?.slippage, - custom_slippage: swapMetaData?.slippage === 2, + slippage: swapSlippage, + custom_slippage: swapSlippage === 2, gas_fees: feeinUnformattedFiat, is_hardware_wallet: hardwareWalletUsed, hardware_wallet_type: hardwareWalletType, @@ -137,7 +141,6 @@ export default function AwaitingSwap({ current_stx_enabled: currentSmartTransactionsEnabled, stx_user_opt_in: smartTransactionsOptInStatus, }; - const baseNetworkUrl = rpcPrefs.blockExplorerUrl ?? SWAPS_CHAINID_DEFAULT_BLOCK_EXPLORER_URL_MAP[chainId] ?? @@ -234,7 +237,7 @@ export default function AwaitingSwap({ className="awaiting-swap__amount-and-symbol" data-testid="awaiting-swap-amount-and-symbol" > - {swapMetaData?.token_to} + {destinationTokenSymbol} , ]); content = blockExplorerUrl && ( @@ -252,7 +255,7 @@ export default function AwaitingSwap({ key="swapTokenAvailable-2" className="awaiting-swap__amount-and-symbol" > - {`${tokensReceived || ''} ${swapMetaData?.token_to}`} + {`${tokensReceived || ''} ${destinationTokenSymbol}`} , ]); content = blockExplorerUrl && ( @@ -317,7 +320,7 @@ export default function AwaitingSwap({ } else if (errorKey) { await dispatch(navigateBackToBuildQuote(history)); } else if ( - isSwapsDefaultTokenSymbol(swapMetaData?.token_to, chainId) || + isSwapsDefaultTokenSymbol(destinationTokenSymbol, chainId) || swapComplete ) { history.push(DEFAULT_ROUTE); diff --git a/ui/pages/swaps/prepare-swap-page/prepare-swap-page.js b/ui/pages/swaps/prepare-swap-page/prepare-swap-page.js index 7ea900c5eb59..72050df4aca9 100644 --- a/ui/pages/swaps/prepare-swap-page/prepare-swap-page.js +++ b/ui/pages/swaps/prepare-swap-page/prepare-swap-page.js @@ -52,6 +52,7 @@ import { getTransactionSettingsOpened, setTransactionSettingsOpened, getLatestAddedTokenTo, + getUsedQuote, } from '../../../ducks/swaps/swaps'; import { getSwapsDefaultToken, @@ -190,9 +191,10 @@ export default function PrepareSwapPage({ const rpcPrefs = useSelector(getRpcPrefsForCurrentProvider, shallowEqual); const tokenList = useSelector(getTokenList, isEqual); const quotes = useSelector(getQuotes, isEqual); + const usedQuote = useSelector(getUsedQuote, isEqual); const latestAddedTokenTo = useSelector(getLatestAddedTokenTo, isEqual); const numberOfQuotes = Object.keys(quotes).length; - const areQuotesPresent = numberOfQuotes > 0; + const areQuotesPresent = numberOfQuotes > 0 && usedQuote; const swapsErrorKey = useSelector(getSwapsErrorKey); const aggregatorMetadata = useSelector(getAggregatorMetadata, shallowEqual); const transactionSettingsOpened = useSelector( diff --git a/ui/selectors/accounts.test.ts b/ui/selectors/accounts.test.ts index 61a0059989ba..22fd6f610b12 100644 --- a/ui/selectors/accounts.test.ts +++ b/ui/selectors/accounts.test.ts @@ -147,4 +147,42 @@ describe('Accounts Selectors', () => { expect(isSelectedInternalAccountBtc(state)).toBe(false); }); }); + + describe('hasCreatedBtcTestnetAccount', () => { + it('returns true if the BTC testnet account has been created', () => { + const state: AccountsState = { + metamask: { + // No-op for this test, but might be required in the future: + ...MOCK_STATE.metamask, + internalAccounts: { + selectedAccount: MOCK_ACCOUNT_BIP122_P2WPKH.id, + accounts: { + mock_account_bip122_pwpkh: MOCK_ACCOUNT_BIP122_P2WPKH, + mock_account_bip122_p2wpkh_testnet: + MOCK_ACCOUNT_BIP122_P2WPKH_TESTNET, + }, + }, + }, + }; + + expect(hasCreatedBtcTestnetAccount(state)).toBe(true); + }); + + it('returns false if the BTC testnet account has not been created yet', () => { + const state: AccountsState = { + metamask: { + // No-op for this test, but might be required in the future: + ...MOCK_STATE.metamask, + internalAccounts: { + selectedAccount: MOCK_ACCOUNT_BIP122_P2WPKH.id, + accounts: { + mock_account_bip122_p2wpkh: MOCK_ACCOUNT_BIP122_P2WPKH, + }, + }, + }, + }; + + expect(isSelectedInternalAccountBtc(state)).toBe(false); + }); + }); }); diff --git a/ui/selectors/nft.test.ts b/ui/selectors/nft.test.ts index 101eb4aae181..d6f4d956f020 100644 --- a/ui/selectors/nft.test.ts +++ b/ui/selectors/nft.test.ts @@ -38,6 +38,7 @@ describe('NFT Selectors', () => { [chainIdMock2]: [contractMock5], }, }, + allNfts: {}, }, }; @@ -80,6 +81,7 @@ describe('NFT Selectors', () => { [chainIdMock2]: [contractMock5], }, }, + allNfts: {}, }, }; diff --git a/ui/selectors/nft.ts b/ui/selectors/nft.ts index 8320c6258b1c..ab3836714923 100644 --- a/ui/selectors/nft.ts +++ b/ui/selectors/nft.ts @@ -1,14 +1,19 @@ -import { NftContract } from '@metamask/assets-controllers'; +import { Nft, NftContract } from '@metamask/assets-controllers'; import { createSelector } from 'reselect'; import { getMemoizedCurrentChainId } from './selectors'; -type NftState = { +export type NftState = { metamask: { allNftContracts: { [account: string]: { [chainId: string]: NftContract[]; }; }; + allNfts: { + [account: string]: { + [chainId: string]: Nft[]; + }; + }; }; }; @@ -16,6 +21,16 @@ function getNftContractsByChainByAccount(state: NftState) { return state.metamask.allNftContracts ?? {}; } +/** + * Get all NFTs owned by the user. + * + * @param state - Metamask state. + * @returns All NFTs owned by the user, keyed by chain ID then account address. + */ +function getNftsByChainByAccount(state: NftState) { + return state.metamask.allNfts ?? {}; +} + export const getNftContractsByAddressByChain = createSelector( getNftContractsByChainByAccount, (nftContractsByChainByAccount) => { @@ -53,3 +68,21 @@ export const getNftContractsByAddressOnCurrentChain = createSelector( return nftContractsByAddressByChain[currentChainId] ?? {}; }, ); + +/** + * Get a flattened list of all NFTs owned by the user. + * Includes all NFTs from all chains and accounts. + * + * @param state - Metamask state. + * @returns All NFTs owned by the user in a single array. + */ +export const selectAllNftsFlat = createSelector( + getNftsByChainByAccount, + (nftsByChainByAccount) => { + const nftsByChainArray = Object.values(nftsByChainByAccount); + return nftsByChainArray.reduce((acc, nftsByChain) => { + const nftsArrays = Object.values(nftsByChain); + return acc.concat(...nftsArrays); + }, []); + }, +); diff --git a/ui/selectors/selectors.js b/ui/selectors/selectors.js index fac2f9f52c31..3b2c2f18dadd 100644 --- a/ui/selectors/selectors.js +++ b/ui/selectors/selectors.js @@ -490,6 +490,24 @@ export function getAllTokens(state) { return state.metamask.allTokens; } +/** + * Get a flattened list of all ERC-20 tokens owned by the user. + * Includes all tokens from all chains and accounts. + * + * @returns {object[]} All ERC-20 tokens owned by the user in a flat array. + */ +export const selectAllTokensFlat = createSelector( + getAllTokens, + (tokensByAccountByChain) => { + const tokensByAccountArray = Object.values(tokensByAccountByChain); + + return tokensByAccountArray.reduce((acc, tokensByAccount) => { + const tokensArray = Object.values(tokensByAccount); + return acc.concat(...tokensArray); + }, []); + }, +); + /** * Selector to return an origin to network ID map * diff --git a/ui/store/store.ts b/ui/store/store.ts index 6e580c137bdc..8433511380e7 100644 --- a/ui/store/store.ts +++ b/ui/store/store.ts @@ -5,6 +5,11 @@ import { ApprovalControllerState } from '@metamask/approval-controller'; import { GasEstimateType, GasFeeEstimates } from '@metamask/gas-fee-controller'; import { TransactionMeta } from '@metamask/transaction-controller'; import { InternalAccount } from '@metamask/keyring-api'; +import { + NftControllerState, + TokensControllerState, +} from '@metamask/assets-controllers'; +import { NotificationServicesControllerState } from '@metamask/notification-services-controller/notification-services'; import rootReducer from '../ducks'; import { LedgerTransportTypes } from '../../shared/constants/hardware-wallets'; import type { NetworkStatus } from '../../shared/constants/network'; @@ -45,48 +50,50 @@ export type MessagesIndexedById = { * state received from the background takes precedence over anything in the * metamask reducer. */ -type TemporaryBackgroundState = { - addressBook: { - [chainId: string]: { - name: string; - }[]; - }; - // todo: can this be deleted post network controller v20 - providerConfig: { - chainId: string; - }; - transactions: TransactionMeta[]; - ledgerTransportType: LedgerTransportTypes; - unapprovedDecryptMsgs: MessagesIndexedById; - unapprovedPersonalMsgs: MessagesIndexedById; - unapprovedTypedMessages: MessagesIndexedById; - networksMetadata: { - [NetworkClientId: string]: { - EIPS: { [eip: string]: boolean }; - status: NetworkStatus; +type TemporaryBackgroundState = NftControllerState & + NotificationServicesControllerState & + TokensControllerState & { + addressBook: { + [chainId: string]: { + name: string; + }[]; }; - }; - selectedNetworkClientId: string; - pendingApprovals: ApprovalControllerState['pendingApprovals']; - approvalFlows: ApprovalControllerState['approvalFlows']; - knownMethodData?: { - [fourBytePrefix: string]: Record; - }; - gasFeeEstimates: GasFeeEstimates; - gasEstimateType: GasEstimateType; - ///: BEGIN:ONLY_INCLUDE_IF(build-mmi) - // TODO: Replace `any` with type - // eslint-disable-next-line @typescript-eslint/no-explicit-any - custodyAccountDetails?: { [key: string]: any }; - ///: END:ONLY_INCLUDE_IF - internalAccounts: { - accounts: { - [key: string]: InternalAccount; + // todo: can this be deleted post network controller v20 + providerConfig: { + chainId: string; + }; + transactions: TransactionMeta[]; + ledgerTransportType: LedgerTransportTypes; + unapprovedDecryptMsgs: MessagesIndexedById; + unapprovedPersonalMsgs: MessagesIndexedById; + unapprovedTypedMessages: MessagesIndexedById; + networksMetadata: { + [NetworkClientId: string]: { + EIPS: { [eip: string]: boolean }; + status: NetworkStatus; + }; + }; + selectedNetworkClientId: string; + pendingApprovals: ApprovalControllerState['pendingApprovals']; + approvalFlows: ApprovalControllerState['approvalFlows']; + knownMethodData?: { + [fourBytePrefix: string]: Record; }; - selectedAccount: string; + gasFeeEstimates: GasFeeEstimates; + gasEstimateType: GasEstimateType; + ///: BEGIN:ONLY_INCLUDE_IF(build-mmi) + // TODO: Replace `any` with type + // eslint-disable-next-line @typescript-eslint/no-explicit-any + custodyAccountDetails?: { [key: string]: any }; + ///: END:ONLY_INCLUDE_IF + internalAccounts: { + accounts: { + [key: string]: InternalAccount; + }; + selectedAccount: string; + }; + keyrings: { type: string; accounts: string[] }[]; }; - keyrings: { type: string; accounts: string[] }[]; -}; type RootReducerReturnType = ReturnType; diff --git a/yarn.lock b/yarn.lock index cdde2e6fce0c..9e22d7e4a7e0 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6053,9 +6053,9 @@ __metadata: languageName: node linkType: hard -"@metamask/profile-sync-controller@npm:^0.9.4": - version: 0.9.4 - resolution: "@metamask/profile-sync-controller@npm:0.9.4" +"@metamask/profile-sync-controller@npm:^0.9.7": + version: 0.9.7 + resolution: "@metamask/profile-sync-controller@npm:0.9.7" dependencies: "@metamask/base-controller": "npm:^7.0.1" "@metamask/keyring-api": "npm:^8.1.3" @@ -6071,7 +6071,7 @@ __metadata: "@metamask/accounts-controller": ^18.1.1 "@metamask/keyring-controller": ^17.2.0 "@metamask/snaps-controllers": ^9.7.0 - checksum: 10/86079da552eed316f2754bd899047de1d8d9d15d390c9cdee0aef66b95bea708b5c7929a8d8d946210cc0e4c52347fee971a5cf5130149d0ca60abdc85f47774 + checksum: 10/e53888533b2aae937bbe4e385dca2617c324b34e3e60af218cd98c26d514fb725f4c67b649f126e055f6a50a554817b229d37488115b98d70e8aee7b3a910bde languageName: node linkType: hard @@ -6364,6 +6364,37 @@ __metadata: languageName: node linkType: hard +"@metamask/snaps-utils@npm:8.1.1": + version: 8.1.1 + resolution: "@metamask/snaps-utils@npm:8.1.1" + dependencies: + "@babel/core": "npm:^7.23.2" + "@babel/types": "npm:^7.23.0" + "@metamask/base-controller": "npm:^6.0.2" + "@metamask/key-tree": "npm:^9.1.2" + "@metamask/permission-controller": "npm:^11.0.0" + "@metamask/rpc-errors": "npm:^6.3.1" + "@metamask/slip44": "npm:^4.0.0" + "@metamask/snaps-registry": "npm:^3.2.1" + "@metamask/snaps-sdk": "npm:^6.5.0" + "@metamask/superstruct": "npm:^3.1.0" + "@metamask/utils": "npm:^9.2.1" + "@noble/hashes": "npm:^1.3.1" + "@scure/base": "npm:^1.1.1" + chalk: "npm:^4.1.2" + cron-parser: "npm:^4.5.0" + fast-deep-equal: "npm:^3.1.3" + fast-json-stable-stringify: "npm:^2.1.0" + fast-xml-parser: "npm:^4.4.1" + marked: "npm:^12.0.1" + rfdc: "npm:^1.3.0" + semver: "npm:^7.5.4" + ses: "npm:^1.1.0" + validate-npm-package-name: "npm:^5.0.0" + checksum: 10/f4ceb52a1f9578993c88c82a67f4f041309af51c83ff5caa3fed080f36b54d14ea7da807ce1cf19a13600dd0e77c51af70398e8c7bb78f0ba99a037f4d22610f + languageName: node + linkType: hard + "@metamask/snaps-utils@npm:^7.4.0, @metamask/snaps-utils@npm:^7.8.0": version: 7.8.1 resolution: "@metamask/snaps-utils@npm:7.8.1" @@ -6395,9 +6426,9 @@ __metadata: languageName: node linkType: hard -"@metamask/snaps-utils@npm:^8.1.1": +"@metamask/snaps-utils@patch:@metamask/snaps-utils@npm%3A8.1.1#~/.yarn/patches/@metamask-snaps-utils-npm-8.1.1-7d5dd6a26a.patch": version: 8.1.1 - resolution: "@metamask/snaps-utils@npm:8.1.1" + resolution: "@metamask/snaps-utils@patch:@metamask/snaps-utils@npm%3A8.1.1#~/.yarn/patches/@metamask-snaps-utils-npm-8.1.1-7d5dd6a26a.patch::version=8.1.1&hash=d09097" dependencies: "@babel/core": "npm:^7.23.2" "@babel/types": "npm:^7.23.0" @@ -6422,7 +6453,7 @@ __metadata: semver: "npm:^7.5.4" ses: "npm:^1.1.0" validate-npm-package-name: "npm:^5.0.0" - checksum: 10/f4ceb52a1f9578993c88c82a67f4f041309af51c83ff5caa3fed080f36b54d14ea7da807ce1cf19a13600dd0e77c51af70398e8c7bb78f0ba99a037f4d22610f + checksum: 10/6b1d3d70c5ebee684d5b76bf911c66ebd122a0607cefcfc9fffd4bf6882a7acfca655d97be87c0f7f47e59a981b58234578ed8a123e554a36e6c48ff87492655 languageName: node linkType: hard @@ -7896,64 +7927,64 @@ __metadata: languageName: node linkType: hard -"@sentry-internal/browser-utils@npm:8.19.0": - version: 8.19.0 - resolution: "@sentry-internal/browser-utils@npm:8.19.0" +"@sentry-internal/browser-utils@npm:8.33.1": + version: 8.33.1 + resolution: "@sentry-internal/browser-utils@npm:8.33.1" dependencies: - "@sentry/core": "npm:8.19.0" - "@sentry/types": "npm:8.19.0" - "@sentry/utils": "npm:8.19.0" - checksum: 10/d6df6cb6edc6b2ddb7362daee39770a51b255d343b3dcb80dc98f77dc43a7cc66f29076e14d1a0ac162a51a4f620b876493a04c23a530f57170009364b6464ea + "@sentry/core": "npm:8.33.1" + "@sentry/types": "npm:8.33.1" + "@sentry/utils": "npm:8.33.1" + checksum: 10/aed6ec58a2dea3613011c24c1e1f14899eaba721d4523ca7da281cbf70e1d48e5ab2bd50da17de76e8cc8052b983840d937e167ea980c6a07e4d32f0e374903c languageName: node linkType: hard -"@sentry-internal/feedback@npm:8.19.0": - version: 8.19.0 - resolution: "@sentry-internal/feedback@npm:8.19.0" +"@sentry-internal/feedback@npm:8.33.1": + version: 8.33.1 + resolution: "@sentry-internal/feedback@npm:8.33.1" dependencies: - "@sentry/core": "npm:8.19.0" - "@sentry/types": "npm:8.19.0" - "@sentry/utils": "npm:8.19.0" - checksum: 10/e10cf1f63d49a41072aaa1b7b007241a273bd4bfa6d2c628e50d621c8cde836e6743bdefbf9ba7e96684b6dd18ad49e17841f4420fc33757e7c119ec88b4ac15 + "@sentry/core": "npm:8.33.1" + "@sentry/types": "npm:8.33.1" + "@sentry/utils": "npm:8.33.1" + checksum: 10/2cb3f4c4b71f8cdf8bcab9251216b15e0caaae257bbce49fffcf053716fab60d61793898c221457e518b109e6319faf8190c2d0e57fcea8b91f28e5815f4e643 languageName: node linkType: hard -"@sentry-internal/replay-canvas@npm:8.19.0": - version: 8.19.0 - resolution: "@sentry-internal/replay-canvas@npm:8.19.0" +"@sentry-internal/replay-canvas@npm:8.33.1": + version: 8.33.1 + resolution: "@sentry-internal/replay-canvas@npm:8.33.1" dependencies: - "@sentry-internal/replay": "npm:8.19.0" - "@sentry/core": "npm:8.19.0" - "@sentry/types": "npm:8.19.0" - "@sentry/utils": "npm:8.19.0" - checksum: 10/1f379c141884b448c56fcd663b8acc0ff1c12d50a2b9db37f9552eb2bc8c99a970114f80e58c8c4fcd61f933f9a15f58dc6cbe6f4297bb574d6772be8f41c5bf + "@sentry-internal/replay": "npm:8.33.1" + "@sentry/core": "npm:8.33.1" + "@sentry/types": "npm:8.33.1" + "@sentry/utils": "npm:8.33.1" + checksum: 10/75432f627a73bad2e09ad2a7b7200c1ea4fe9d9e797458615850689dd7b017f38c876f4435ea548da9ae7653f55be90d58fc115897febacc53b69e6593867afb languageName: node linkType: hard -"@sentry-internal/replay@npm:8.19.0": - version: 8.19.0 - resolution: "@sentry-internal/replay@npm:8.19.0" +"@sentry-internal/replay@npm:8.33.1": + version: 8.33.1 + resolution: "@sentry-internal/replay@npm:8.33.1" dependencies: - "@sentry-internal/browser-utils": "npm:8.19.0" - "@sentry/core": "npm:8.19.0" - "@sentry/types": "npm:8.19.0" - "@sentry/utils": "npm:8.19.0" - checksum: 10/dc9bef6997d1f40fb0402f52c9d14f72cf050ec140fda27e00057c59ddd1a6144e78e40aeb5e0223dd48651bf02f809db26cf6e866dd5c8ec5c6bbbf76c6f1aa + "@sentry-internal/browser-utils": "npm:8.33.1" + "@sentry/core": "npm:8.33.1" + "@sentry/types": "npm:8.33.1" + "@sentry/utils": "npm:8.33.1" + checksum: 10/05cdb361ccde5039c7353877a95eb15e4d630d5edbb874cd55ac190ee8256a1456e1c6cae37636df55bff10fcde6ff1232d8ca290467d43393bb18d9e4efe99f languageName: node linkType: hard -"@sentry/browser@npm:^8.19.0": - version: 8.19.0 - resolution: "@sentry/browser@npm:8.19.0" +"@sentry/browser@npm:^8.33.1": + version: 8.33.1 + resolution: "@sentry/browser@npm:8.33.1" dependencies: - "@sentry-internal/browser-utils": "npm:8.19.0" - "@sentry-internal/feedback": "npm:8.19.0" - "@sentry-internal/replay": "npm:8.19.0" - "@sentry-internal/replay-canvas": "npm:8.19.0" - "@sentry/core": "npm:8.19.0" - "@sentry/types": "npm:8.19.0" - "@sentry/utils": "npm:8.19.0" - checksum: 10/2412e938454bd5cc505bbbe7092a17bf5fde4b222ecfedaf3d54fb963a6c875c78661921d8f6e998498c85a9a52e616db75fd706867f76d38bf3f95714775aa6 + "@sentry-internal/browser-utils": "npm:8.33.1" + "@sentry-internal/feedback": "npm:8.33.1" + "@sentry-internal/replay": "npm:8.33.1" + "@sentry-internal/replay-canvas": "npm:8.33.1" + "@sentry/core": "npm:8.33.1" + "@sentry/types": "npm:8.33.1" + "@sentry/utils": "npm:8.33.1" + checksum: 10/085717b19c89184fad0c9e17dee679401ff87616678f952d91afff574ebcc56114845c216bbbd7b81c93d54c2a42b3db4232af1c707843424cdd6800a99030a5 languageName: node linkType: hard @@ -7972,36 +8003,29 @@ __metadata: languageName: node linkType: hard -"@sentry/core@npm:8.19.0": - version: 8.19.0 - resolution: "@sentry/core@npm:8.19.0" +"@sentry/core@npm:8.33.1": + version: 8.33.1 + resolution: "@sentry/core@npm:8.33.1" dependencies: - "@sentry/types": "npm:8.19.0" - "@sentry/utils": "npm:8.19.0" - checksum: 10/708ef5abd81a9ab5288a4b258411e78591a7fec4854fc582c34f087fce62f5cd74e1086fbbc27a9f55da77d113dde137fbf9649f5b7df3d1a22886850702adbd + "@sentry/types": "npm:8.33.1" + "@sentry/utils": "npm:8.33.1" + checksum: 10/dbd781777f5dc003e21680919d37e308a64320776c54a5712163f72d4c0c4d5d25d7f07b83123e517c333fcdefb92ac5a0f15cb4dbbc79f3cc7309038cb0fcbb languageName: node linkType: hard -"@sentry/types@npm:8.19.0": - version: 8.19.0 - resolution: "@sentry/types@npm:8.19.0" - checksum: 10/8812f7394c6c031197abc04d80e5b5b3693742dc065b877c535a9ceb538aabd60ee27fc2b13824e2b8fc264819868109bbd4de3642fd1c7bf30d304fb0c21aa9 +"@sentry/types@npm:8.33.1, @sentry/types@npm:^8.33.1": + version: 8.33.1 + resolution: "@sentry/types@npm:8.33.1" + checksum: 10/bcd7f80e84a23cb810fa5819dc85f45bd62d52b01b1f64a1b31297df21e9d1f4de8f7ea91835c5d6a7010d7dbfc8b09cd708d057d345a6ff685b7f12db41ae57 languageName: node linkType: hard -"@sentry/types@npm:^8.19.0": - version: 8.20.0 - resolution: "@sentry/types@npm:8.20.0" - checksum: 10/c7d7ed17975f0fc0b4bf5aece58084953c2a76e8f417923a476fe1fd42a2c9339c548d701edbc4b938c9252cf680d3eff4c6c2a986bc7ac62649aebf656c5b64 - languageName: node - linkType: hard - -"@sentry/utils@npm:8.19.0, @sentry/utils@npm:^8.19.0": - version: 8.19.0 - resolution: "@sentry/utils@npm:8.19.0" +"@sentry/utils@npm:8.33.1, @sentry/utils@npm:^8.33.1": + version: 8.33.1 + resolution: "@sentry/utils@npm:8.33.1" dependencies: - "@sentry/types": "npm:8.19.0" - checksum: 10/abd507e5b37c7753534865f74a1a622fdbe2d71cfa61fd009703f4c9c90634fb6d26e3b2f8e09904631d4692e3735de451ed914c505c31700a6f5504a61e649e + "@sentry/types": "npm:8.33.1" + checksum: 10/79426deba11c043f0410b4b5d635367147d7e41bb90526168f180ae05598768348de39a82f89a92a4f0365f5ece5f62950ba6eab0b7300faefea7a9bb0889df3 languageName: node linkType: hard @@ -26138,7 +26162,7 @@ __metadata: "@metamask/post-message-stream": "npm:^8.0.0" "@metamask/ppom-validator": "npm:0.34.0" "@metamask/preinstalled-example-snap": "npm:^0.1.0" - "@metamask/profile-sync-controller": "npm:^0.9.4" + "@metamask/profile-sync-controller": "npm:^0.9.7" "@metamask/providers": "npm:^14.0.2" "@metamask/queued-request-controller": "npm:^2.0.0" "@metamask/rate-limit-controller": "npm:^6.0.0" @@ -26152,7 +26176,7 @@ __metadata: "@metamask/snaps-execution-environments": "npm:^6.7.2" "@metamask/snaps-rpc-methods": "npm:^11.1.1" "@metamask/snaps-sdk": "npm:^6.5.1" - "@metamask/snaps-utils": "npm:^8.1.1" + "@metamask/snaps-utils": "patch:@metamask/snaps-utils@npm%3A8.1.1#~/.yarn/patches/@metamask-snaps-utils-npm-8.1.1-7d5dd6a26a.patch" "@metamask/test-bundler": "npm:^1.0.0" "@metamask/test-dapp": "npm:^8.4.0" "@metamask/transaction-controller": "npm:^37.0.0" @@ -26170,10 +26194,10 @@ __metadata: "@popperjs/core": "npm:^2.4.0" "@reduxjs/toolkit": "patch:@reduxjs/toolkit@npm%3A1.9.7#~/.yarn/patches/@reduxjs-toolkit-npm-1.9.7-b14925495c.patch" "@segment/loosely-validate-event": "npm:^2.0.0" - "@sentry/browser": "npm:^8.19.0" + "@sentry/browser": "npm:^8.33.1" "@sentry/cli": "npm:^2.19.4" - "@sentry/types": "npm:^8.19.0" - "@sentry/utils": "npm:^8.19.0" + "@sentry/types": "npm:^8.33.1" + "@sentry/utils": "npm:^8.33.1" "@storybook/addon-a11y": "npm:^7.6.20" "@storybook/addon-actions": "npm:^7.6.20" "@storybook/addon-designs": "npm:^7.0.9"