Skip to content

Commit 695184d

Browse files
FrederikBoldingGuillaumeRxhmalik88
authored
chore: Bump Snaps dependencies (#31270)
<!-- Please submit this PR as a draft initially. Do not mark it as "Ready for review" until the template has been completely filled out, and PR status checks have passed at least once. --> ## **Description** Bump Snaps packages and handle any required changes. Summary of Snaps changes: - Add `AssetSelector` component - Add `AddressInput` component - Add mutex to `getSnapState` to prevent concurrent decryption - Increase Snap interface context size limit slightly - Bump dependencies [![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/31270?quickstart=1) ## **Related issues** Closes: MetaMask/snaps#2811 --------- Co-authored-by: Guillaume Roux <[email protected]> Co-authored-by: Hassan Malik <[email protected]> Co-authored-by: Guillaume Roux <[email protected]>
1 parent a52bf03 commit 695184d

File tree

30 files changed

+1342
-77
lines changed

30 files changed

+1342
-77
lines changed

app/_locales/en/messages.json

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/_locales/en_GB/messages.json

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/scripts/controller-init/messengers/snaps/snap-interface-controller-messenger.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,17 @@ import {
66
} from '@metamask/approval-controller';
77
import { MaybeUpdateState, TestOrigin } from '@metamask/phishing-controller';
88
import { NotificationListUpdatedEvent } from '@metamask/notification-services-controller/notification-services';
9+
import { AccountsControllerGetAccountByAddressAction } from '@metamask/accounts-controller';
10+
import { MultichainAssetsControllerGetStateAction } from '@metamask/assets-controllers';
911

1012
type Actions =
1113
| MaybeUpdateState
1214
| TestOrigin
1315
| HasApprovalRequest
1416
| AcceptRequest
15-
| GetSnap;
17+
| GetSnap
18+
| AccountsControllerGetAccountByAddressAction
19+
| MultichainAssetsControllerGetStateAction;
1620

1721
type Events = NotificationListUpdatedEvent;
1822

@@ -39,6 +43,8 @@ export function getSnapInterfaceControllerMessenger(
3943
`ApprovalController:hasRequest`,
4044
`ApprovalController:acceptRequest`,
4145
`SnapController:get`,
46+
'AccountsController:getAccountByAddress',
47+
'MultichainAssetsController:getState',
4248
],
4349
allowedEvents: ['NotificationServicesController:notificationsListUpdated'],
4450
});

app/scripts/controller-init/snaps/snap-interface-controller-init.ts

+3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ export const SnapInterfaceControllerInit: ControllerInitFunction<
1919
// with the expected type.
2020
// TODO: Look into the type mismatch.
2121
state: persistedState.SnapInterfaceController,
22+
// @ts-expect-error: `controllerMessenger` is not compatible with the
23+
// expected type.
24+
// TODO: Look into the type mismatch.
2225
messenger: controllerMessenger,
2326
});
2427

builds.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ buildTypes:
2727
- ALLOW_LOCAL_SNAPS: false
2828
- REQUIRE_SNAPS_ALLOWLIST: true
2929
- REJECT_INVALID_SNAPS_PLATFORM_VERSION: true
30-
- IFRAME_EXECUTION_ENVIRONMENT_URL: https://execution.metamask.io/iframe/7.0.0/index.html
30+
- IFRAME_EXECUTION_ENVIRONMENT_URL: https://execution.metamask.io/iframe/7.1.0/index.html
3131
- ACCOUNT_SNAPS_DIRECTORY_URL: https://snaps.metamask.io/account-management
3232
- EVM_MULTICHAIN_ENABLED: false
3333
# Main build uses the default browser manifest
@@ -55,7 +55,7 @@ buildTypes:
5555
- ALLOW_LOCAL_SNAPS: false
5656
- REQUIRE_SNAPS_ALLOWLIST: true
5757
- REJECT_INVALID_SNAPS_PLATFORM_VERSION: true
58-
- IFRAME_EXECUTION_ENVIRONMENT_URL: https://execution.metamask.io/iframe/7.0.0/index.html
58+
- IFRAME_EXECUTION_ENVIRONMENT_URL: https://execution.metamask.io/iframe/7.1.0/index.html
5959
- ACCOUNT_SNAPS_DIRECTORY_URL: https://snaps.metamask.io/account-management
6060
- EVM_MULTICHAIN_ENABLED: false
6161
# Modifies how the version is displayed.
@@ -83,7 +83,7 @@ buildTypes:
8383
- ALLOW_LOCAL_SNAPS: true
8484
- REQUIRE_SNAPS_ALLOWLIST: false
8585
- REJECT_INVALID_SNAPS_PLATFORM_VERSION: false
86-
- IFRAME_EXECUTION_ENVIRONMENT_URL: https://execution.metamask.io/iframe/7.0.0/index.html
86+
- IFRAME_EXECUTION_ENVIRONMENT_URL: https://execution.metamask.io/iframe/7.1.0/index.html
8787
- SUPPORT_LINK: https://support.metamask.io/
8888
- SUPPORT_REQUEST_LINK: https://support.metamask.io/
8989
- INFURA_ENV_KEY_REF: INFURA_FLASK_PROJECT_ID
@@ -109,7 +109,7 @@ buildTypes:
109109
- ALLOW_LOCAL_SNAPS: false
110110
- REQUIRE_SNAPS_ALLOWLIST: true
111111
- REJECT_INVALID_SNAPS_PLATFORM_VERSION: true
112-
- IFRAME_EXECUTION_ENVIRONMENT_URL: https://execution.metamask.io/iframe/7.0.0/index.html
112+
- IFRAME_EXECUTION_ENVIRONMENT_URL: https://execution.metamask.io/iframe/7.1.0/index.html
113113
- MMI_CONFIGURATION_SERVICE_URL: https://configuration.metamask-institutional.io/v2/configuration/default
114114
- SUPPORT_LINK: https://support.metamask-institutional.io
115115
- SUPPORT_REQUEST_LINK: https://support.metamask-institutional.io

package.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@
191191
"[email protected]": "^7.5.4",
192192
"[email protected]": "^7.5.4",
193193
"lavamoat-core@npm:^16.2.2": "patch:lavamoat-core@npm%3A16.2.2#~/.yarn/patches/lavamoat-core-npm-16.2.2-e361ff1f8a.patch",
194-
"@metamask/snaps-sdk": "^6.19.0",
194+
"@metamask/snaps-sdk": "^6.21.0",
195195
"@swc/[email protected]": "^0.1.6",
196196
"@babel/core": "patch:@babel/core@npm%3A7.25.9#~/.yarn/patches/@babel-core-npm-7.25.9-4ae3bff7f3.patch",
197197
"@babel/runtime": "patch:@babel/runtime@npm%3A7.25.9#~/.yarn/patches/@babel-runtime-npm-7.25.9-fe8c62510a.patch",
@@ -319,11 +319,11 @@
319319
"@metamask/selected-network-controller": "^19.0.0",
320320
"@metamask/signature-controller": "^26.0.0",
321321
"@metamask/smart-transactions-controller": "^16.2.0",
322-
"@metamask/snaps-controllers": "^11.0.0",
323-
"@metamask/snaps-execution-environments": "^7.0.0",
322+
"@metamask/snaps-controllers": "^11.1.0",
323+
"@metamask/snaps-execution-environments": "^7.1.0",
324324
"@metamask/snaps-rpc-methods": "^12.0.0",
325-
"@metamask/snaps-sdk": "^6.19.0",
326-
"@metamask/snaps-utils": "^9.0.1",
325+
"@metamask/snaps-sdk": "^6.21.0",
326+
"@metamask/snaps-utils": "^9.1.0",
327327
"@metamask/solana-wallet-snap": "^1.15.1",
328328
"@metamask/transaction-controller": "^52.2.0",
329329
"@metamask/user-operation-controller": "^24.0.1",

test/e2e/mock-e2e-allowlist.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ const ALLOWLISTED_URLS = [
4545
'https://d6tizftlrpuof.cloudfront.net/themes/production/consensys-button-8ad6c4bb549247e0276dd160e2d8e00d.png',
4646
'https://doesntexist.test/customRPC',
4747
'https://etherscan.io/favicon.ico',
48-
'https://execution.metamask.io/iframe/7.0.0/index.html',
49-
'https://execution.metamask.io/iframe/7.0.0/bundle.js',
48+
'https://execution.metamask.io/iframe/7.1.0/index.html',
49+
'https://execution.metamask.io/iframe/7.1.0/bundle.js',
5050
'https://gas.api.cx.metamask.io/networks/1/gasPrices',
5151
'https://gas.api.cx.metamask.io/networks/1/suggestedGasFees',
5252
'https://gas.api.cx.metamask.io/networks/1337/suggestedGasFees',

test/e2e/snaps/enums.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module.exports = {
2-
TEST_SNAPS_WEBSITE_URL: 'https://metamask.github.io/snaps/test-snaps/2.20.1',
2+
TEST_SNAPS_WEBSITE_URL: 'https://metamask.github.io/snaps/test-snaps/2.20.3',
33
};

ui/components/app/metamask-template-renderer/safe-component-list.js

+4
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,12 @@ import { SnapUIIcon } from '../snaps/snap-ui-icon';
4545
import { SnapUIImage } from '../snaps/snap-ui-image';
4646
import { SnapUIInput } from '../snaps/snap-ui-input';
4747
import { SnapUILink } from '../snaps/snap-ui-link';
48+
import { SnapUIAddressInput } from '../snaps/snap-ui-address-input';
4849
import { SnapUIMarkdown } from '../snaps/snap-ui-markdown';
4950
import { SnapUIRadioGroup } from '../snaps/snap-ui-radio-group';
5051
import { SnapUISelector } from '../snaps/snap-ui-selector';
5152
import { SnapUITooltip } from '../snaps/snap-ui-tooltip';
53+
import { SnapUIAssetSelector } from '../snaps/snap-ui-asset-selector';
5254
///: BEGIN:ONLY_INCLUDE_IF(keyring-snaps)
5355
import { SnapAccountErrorMessage } from '../../../pages/confirmations/components/snap-account-error-message';
5456
import { SnapAccountSuccessMessage } from '../../../pages/confirmations/components/snap-account-success-message';
@@ -102,11 +104,13 @@ export const safeComponentList = {
102104
SnapUIIcon,
103105
SnapUIImage,
104106
SnapUIInput,
107+
SnapUIAddressInput,
105108
SnapUILink,
106109
SnapUIMarkdown,
107110
SnapUIRadioGroup,
108111
SnapUISelector,
109112
SnapUITooltip,
113+
SnapUIAssetSelector,
110114
span: 'span',
111115
Spinner,
112116
Skeleton,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './snap-ui-address-input';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,203 @@
1+
import React, {
2+
ChangeEvent,
3+
FunctionComponent,
4+
useEffect,
5+
useRef,
6+
useState,
7+
} from 'react';
8+
import classnames from 'classnames';
9+
import {
10+
CaipAccountId,
11+
CaipChainId,
12+
parseCaipAccountId,
13+
parseCaipChainId,
14+
} from '@metamask/utils';
15+
import {
16+
Box,
17+
FormTextField,
18+
FormTextFieldProps,
19+
FormTextFieldSize,
20+
Icon,
21+
IconName,
22+
Label,
23+
Text,
24+
} from '../../../component-library';
25+
import { useSnapInterfaceContext } from '../../../../contexts/snaps';
26+
import {
27+
AlignItems,
28+
BackgroundColor,
29+
BorderColor,
30+
BorderRadius,
31+
Display,
32+
FlexDirection,
33+
FontWeight,
34+
IconColor,
35+
TextVariant,
36+
} from '../../../../helpers/constants/design-system';
37+
import { SnapUIAvatar } from '../snap-ui-avatar';
38+
import { useDisplayName } from '../../../../hooks/snaps/useDisplayName';
39+
40+
export type SnapUIAddressInputProps = {
41+
name: string;
42+
form?: string;
43+
label?: string;
44+
chainId: CaipChainId;
45+
displayAvatar?: boolean;
46+
};
47+
48+
export const SnapUIAddressInput: FunctionComponent<
49+
SnapUIAddressInputProps & FormTextFieldProps<'div'>
50+
> = ({ name, form, label, chainId, displayAvatar = true, error, ...props }) => {
51+
const { handleInputChange, getValue, focusedInput, setCurrentFocusedInput } =
52+
useSnapInterfaceContext();
53+
54+
const inputRef = useRef<HTMLDivElement>(null);
55+
const initialValue = getValue(name, form) as string;
56+
const { namespace, reference } = parseCaipChainId(chainId);
57+
58+
const [value, setValue] = useState(
59+
initialValue
60+
? parseCaipAccountId(initialValue as CaipAccountId).address
61+
: '',
62+
);
63+
64+
const displayName = useDisplayName({
65+
address: value,
66+
chain: {
67+
namespace,
68+
reference,
69+
},
70+
chainId,
71+
});
72+
73+
/*
74+
* Focus input if the last focused input was this input
75+
* This avoids losing the focus when the UI is re-rendered
76+
*/
77+
useEffect(() => {
78+
if (inputRef.current && name === focusedInput) {
79+
(inputRef.current.querySelector('input') as HTMLInputElement).focus();
80+
}
81+
}, [inputRef]);
82+
83+
const handleChange = (event: ChangeEvent<HTMLInputElement>) => {
84+
setValue(event.target.value);
85+
86+
const newValue = event.target.value
87+
? `${chainId}:${event.target.value}`
88+
: '';
89+
90+
handleInputChange(name, newValue, form);
91+
};
92+
93+
const handleFocus = () => setCurrentFocusedInput(name);
94+
const handleBlur = () => setCurrentFocusedInput(null);
95+
96+
const handleClear = () => {
97+
setValue('');
98+
handleInputChange(name, '', form);
99+
};
100+
101+
const MatchedAccountInfo = () => {
102+
return (
103+
<Box display={Display.Flex} flexDirection={FlexDirection.Column}>
104+
{label && (
105+
<Label className={classnames('mm-form-text-field__label')}>
106+
{label}
107+
</Label>
108+
)}
109+
<Box
110+
display={Display.Flex}
111+
backgroundColor={BackgroundColor.backgroundDefault}
112+
alignItems={AlignItems.center}
113+
borderWidth={1}
114+
borderRadius={BorderRadius.LG}
115+
borderColor={BorderColor.borderMuted}
116+
paddingLeft={4}
117+
paddingRight={4}
118+
gap={2}
119+
style={{
120+
height: '48px',
121+
}}
122+
>
123+
{displayAvatar && (
124+
<SnapUIAvatar address={`${chainId}:${value}`} size="sm" />
125+
)}
126+
<Box
127+
display={Display.Flex}
128+
alignItems={AlignItems.center}
129+
gap={2}
130+
style={{
131+
flex: 1,
132+
minWidth: 0,
133+
}}
134+
>
135+
<Box
136+
flexDirection={FlexDirection.Column}
137+
gap={2}
138+
style={{
139+
minWidth: 0,
140+
flex: 1,
141+
}}
142+
>
143+
<Text fontWeight={FontWeight.Medium}>{displayName}</Text>
144+
<Text variant={TextVariant.bodyXs} ellipsis>
145+
{value}
146+
</Text>
147+
</Box>
148+
</Box>
149+
<Icon
150+
onClick={handleClear}
151+
name={IconName.Close}
152+
color={IconColor.infoDefault}
153+
style={{
154+
cursor: 'pointer',
155+
flexShrink: 0,
156+
}}
157+
/>
158+
</Box>
159+
</Box>
160+
);
161+
};
162+
163+
if (displayName) {
164+
return <MatchedAccountInfo />;
165+
}
166+
167+
return (
168+
<FormTextField
169+
ref={inputRef}
170+
onFocus={handleFocus}
171+
onBlur={handleBlur}
172+
className={classnames('snap-ui-renderer__address-input', {
173+
'snap-ui-renderer__field': label !== undefined,
174+
})}
175+
id={name}
176+
value={value}
177+
onChange={handleChange}
178+
label={label}
179+
error={Boolean(error)}
180+
size={FormTextFieldSize.Lg}
181+
helpText={error}
182+
textFieldProps={{
183+
borderRadius: BorderRadius.LG,
184+
}}
185+
startAccessory={
186+
displayAvatar && value ? (
187+
<SnapUIAvatar address={`${chainId}:${value}`} size="sm" />
188+
) : null
189+
}
190+
endAccessory={
191+
value ? (
192+
<Icon
193+
onClick={handleClear}
194+
name={IconName.Close}
195+
color={IconColor.infoDefault}
196+
style={{ cursor: 'pointer' }}
197+
/>
198+
) : null
199+
}
200+
{...props}
201+
/>
202+
);
203+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './snap-ui-asset-selector';

0 commit comments

Comments
 (0)