Skip to content

Commit 5af1b52

Browse files
authored
Merge branch 'main' into sidepanel-icon
2 parents 3cd6ad5 + 76c67d6 commit 5af1b52

File tree

14 files changed

+161
-140
lines changed

14 files changed

+161
-140
lines changed

app/scripts/controller-init/messengers/accounts/snap-keyring-builder-messenger.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ export function getSnapKeyringBuilderMessenger(
4949
'SnapController:get',
5050
'SnapController:isMinimumPlatformVersion',
5151
'PreferencesController:getState',
52+
'RemoteFeatureFlagController:getState',
5253
],
5354
});
5455
return keyringMessenger;

app/scripts/lib/snap-keyring/snap-keyring.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
} from '@metamask/keyring-api';
77
import { InternalAccount } from '@metamask/keyring-internal-api';
88
import { SnapId } from '@metamask/snaps-sdk';
9+
import { RemoteFeatureFlagControllerState } from '@metamask/remote-feature-flag-controller';
910
import { getRootMessenger } from '../messenger';
1011
import { SNAP_MANAGE_ACCOUNTS_CONFIRMATION_TYPES } from '../../../../shared/constants/app';
1112
import {
@@ -43,6 +44,7 @@ const mockLocale = 'en';
4344
const mockPreferencesControllerGetState = jest.fn();
4445
const mockSnapControllerGet = jest.fn();
4546
const mockSnapControllerHandleRequest = jest.fn();
47+
const mockRemoteFeatureFlagsGetStateRequest = jest.fn();
4648

4749
const mockFlowId = '123';
4850
const address = '0x2a4d4b667D5f12C3F9Bf8F14a7B9f8D8d9b8c8fA';
@@ -114,6 +116,7 @@ const createControllerMessenger = ({
114116
'PreferencesController:getState',
115117
'SnapController:get',
116118
'SnapController:handleRequest',
119+
'RemoteFeatureFlagController:getState',
117120
],
118121
});
119122

@@ -171,6 +174,9 @@ const createControllerMessenger = ({
171174
case 'SnapController:handleRequest':
172175
return mockSnapControllerHandleRequest(params);
173176

177+
case 'RemoteFeatureFlagController:getState':
178+
return mockRemoteFeatureFlagsGetStateRequest(params);
179+
174180
default:
175181
throw new Error(
176182
`MOCK_FAIL - unsupported messenger call: ${actionType}`,
@@ -191,6 +197,11 @@ const createSnapKeyringBuilder = ({
191197
jest.mocked(isSnapPreinstalled).mockReturnValue(snapPreinstalled);
192198
jest.mocked(getSnapName).mockReturnValue(snapName);
193199

200+
// Needed now to know if state 2 is enabled or not.
201+
mockRemoteFeatureFlagsGetStateRequest.mockReturnValue({
202+
remoteFeatureFlags: {},
203+
} as RemoteFeatureFlagControllerState);
204+
194205
return snapKeyringBuilder(createControllerMessenger(), {
195206
persistKeyringHelper: mockPersistKeyringHelper,
196207
removeAccountHelper: mockRemoveAccountHelper,

app/scripts/lib/snap-keyring/snap-keyring.ts

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ import MetaMetricsController from '../../controllers/metametrics-controller';
2121
import { getUniqueAccountName } from '../../../../shared/lib/accounts';
2222
import { isSnapPreinstalled } from '../../../../shared/lib/snaps/snaps';
2323
import { getSnapName } from '../../../../shared/lib/accounts/snaps';
24+
import {
25+
FEATURE_VERSION_2,
26+
isMultichainAccountsFeatureEnabled,
27+
MultichainAccountsFeatureFlag,
28+
} from '../../../../shared/lib/multichain-accounts/remote-feature-flag';
2429
import { SnapKeyringBuilderMessenger } from './types';
2530
import { isBlockedUrl } from './utils/isBlockedUrl';
2631
import { showError, showSuccess } from './utils/showResult';
@@ -299,14 +304,24 @@ class SnapKeyringImpl implements SnapKeyringCallbacks {
299304
});
300305
}
301306

307+
#isMultichainAccountsFeatureState2Enabled() {
308+
const state = this.#messenger.call('RemoteFeatureFlagController:getState');
309+
310+
const featureFlag = state?.remoteFeatureFlags
311+
?.enableMultichainAccountsState2 as
312+
| MultichainAccountsFeatureFlag
313+
| undefined;
314+
return isMultichainAccountsFeatureEnabled(featureFlag, FEATURE_VERSION_2);
315+
}
316+
302317
async #addAccountFinalize({
303318
address,
304319
snapId,
305320
skipConfirmationDialog,
306321
skipSetSelectedAccountStep,
307322
skipApprovalFlow,
308-
accountName,
309323
onceSaved,
324+
accountName,
310325
defaultAccountNameChosen,
311326
}: {
312327
address: string;
@@ -364,12 +379,19 @@ class SnapKeyringImpl implements SnapKeyringCallbacks {
364379
);
365380
}
366381

367-
if (accountName) {
368-
this.#messenger.call(
369-
'AccountsController:setAccountName',
370-
accountId,
371-
accountName,
372-
);
382+
// HACK: In state 2, account creations can run in parallel, thus, `accountName`
383+
// sometimes conflict with other concurrent renaming. Since we don't rely on those
384+
// account names anymore, we just omit this part and make this race-free.
385+
// FIXME: We still rely on the old behavior in some e2e, so we cannot remove this
386+
// entirely.
387+
if (!this.#isMultichainAccountsFeatureState2Enabled()) {
388+
if (accountName) {
389+
this.#messenger.call(
390+
'AccountsController:setAccountName',
391+
accountId,
392+
accountName,
393+
);
394+
}
373395
}
374396

375397
if (!skipConfirmationDialog) {

app/scripts/lib/snap-keyring/types.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
IsMinimumPlatformVersion,
2424
} from '@metamask/snaps-controllers';
2525
import { SnapKeyring } from '@metamask/eth-snap-keyring';
26+
import { RemoteFeatureFlagControllerGetStateAction } from '@metamask/remote-feature-flag-controller';
2627
import { PreferencesControllerGetStateAction } from '../../controllers/preferences-controller';
2728

2829
export type SnapKeyringBuilderAllowActions =
@@ -44,7 +45,8 @@ export type SnapKeyringBuilderAllowActions =
4445
| HandleSnapRequest
4546
| GetSnap
4647
| PreferencesControllerGetStateAction
47-
| IsMinimumPlatformVersion;
48+
| IsMinimumPlatformVersion
49+
| RemoteFeatureFlagControllerGetStateAction;
4850

4951
export type SnapKeyringBuilderMessenger = Messenger<
5052
'SnapKeyring',

app/scripts/metamask-controller.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5215,6 +5215,15 @@ export default class MetamaskController extends EventEmitter {
52155215
await this.getSnapKeyring(),
52165216
this.accountTreeController.getSelectedAccountGroup(),
52175217
);
5218+
5219+
if (this.isMultichainAccountsFeatureState2Enabled()) {
5220+
// This allows to create missing accounts if new account providers have been added.
5221+
// FIXME: We might wanna run discovery + alignment asynchronously here, like we do
5222+
// for mobile, but for now, this easy fix should cover new provider accounts.
5223+
// NOTE: We run this asynchronously on purpose, see FIXME^.
5224+
// eslint-disable-next-line no-void
5225+
void this.multichainAccountService.alignWallets();
5226+
}
52185227
}
52195228

52205229
async _loginUser(password) {

test/e2e/mock-e2e-allowlist.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,6 @@ const ALLOWLISTED_URLS = [
44
// Snaps
55
'https://acl.execution.metamask.io/latest/registry.json',
66
'https://acl.execution.metamask.io/latest/signature.json',
7-
'https://metamask.github.io/eth-ledger-bridge-keyring',
8-
'https://metamask.github.io/eth-ledger-bridge-keyring/',
9-
'https://metamask.github.io/eth-ledger-bridge-keyring/bundle.js',
10-
'https://metamask.github.io/ledger-iframe-bridge/8.0.3/',
11-
'https://metamask.github.io/ledger-iframe-bridge/8.0.3/assets/index-j_SGnqki.js',
12-
'https://metamask.github.io/ledger-iframe-bridge/8.0.3/assets/vendor-BlXVsT1S.js',
137
// Vault Decryptor
148
'https://metamask.github.io/vault-decryptor',
159
'https://metamask.github.io/vault-decryptor/',

ui/components/app/tab-bar/index.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@
2626
opacity: 1;
2727
}
2828

29+
@include design-system.screen-sm-min {
30+
max-height: 50px;
31+
}
32+
2933
&__selected-indicator {
3034
width: 4px;
3135
height: calc(100% - 8px);

ui/pages/settings/index.scss

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -248,18 +248,6 @@
248248
flex: 0 0 40%;
249249
max-width: 197px;
250250
}
251-
252-
.tab-bar__tab {
253-
@include design-system.screen-sm-min {
254-
max-height: 50px;
255-
}
256-
257-
&__caret {
258-
@include design-system.screen-sm-min {
259-
display: none;
260-
}
261-
}
262-
}
263251
}
264252

265253
&__modules {
@@ -507,9 +495,33 @@
507495
flex: 1 1 auto;
508496

509497
.tab-bar__tab {
498+
@include design-system.screen-sm-min {
499+
@include design-system.H4;
500+
501+
max-height: none;
502+
}
503+
504+
&__selected-indicator {
505+
display: none;
506+
}
507+
510508
&__caret {
511509
display: block;
512510
}
511+
512+
&__content {
513+
&__title {
514+
@include design-system.screen-sm-min {
515+
@include design-system.H4;
516+
}
517+
}
518+
}
519+
520+
&--active {
521+
@include design-system.screen-sm-min {
522+
background-color: unset;
523+
}
524+
}
513525
}
514526
}
515527

ui/pages/settings/settings.component.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -194,11 +194,7 @@ class SettingsPage extends PureComponent {
194194
/>
195195
)}
196196
{isSeedlessPasswordOutdated && <PasswordOutdatedModal />}
197-
<Box
198-
className="settings-page__header"
199-
padding={4}
200-
paddingBottom={[2, 4]}
201-
>
197+
<Box className="settings-page__header" padding={4} paddingBottom={2}>
202198
<div
203199
className={classnames('settings-page__header__title-container', {
204200
'settings-page__header__title-container--hide-search':

ui/pages/shield-plan/shield-plan.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,14 @@ const ShieldPlan = () => {
148148
const hasAvailableToken = availableTokenBalances.length > 0;
149149
const [selectedPaymentMethod, setSelectedPaymentMethod] =
150150
useState<PaymentType>(() => {
151+
// always default to card if no token is available
152+
if (!hasAvailableToken) {
153+
return PAYMENT_TYPES.byCard;
154+
}
151155
if (lastUsedPaymentDetails?.type) {
152156
return lastUsedPaymentDetails.type;
153157
}
154-
return hasAvailableToken ? PAYMENT_TYPES.byCrypto : PAYMENT_TYPES.byCard;
158+
return PAYMENT_TYPES.byCrypto;
155159
});
156160
// default options for the new subscription request
157161
const defaultOptions = useMemo(() => {
@@ -216,10 +220,12 @@ const ShieldPlan = () => {
216220

217221
// set default selected payment method to crypto if selected token available
218222
useEffect(() => {
219-
if (selectedToken) {
223+
const lastUsedPaymentMethod = lastUsedPaymentDetails?.type;
224+
// if the last used payment method is not crypto, don't set default method
225+
if (selectedToken && lastUsedPaymentMethod !== PAYMENT_TYPES.byCard) {
220226
setSelectedPaymentMethod(PAYMENT_TYPES.byCrypto);
221227
}
222-
}, [selectedToken, setSelectedPaymentMethod]);
228+
}, [selectedToken, setSelectedPaymentMethod, lastUsedPaymentDetails]);
223229

224230
const tokensSupported = useMemo(() => {
225231
const chainsAndTokensSupported = cryptoPaymentMethod?.chains ?? [];

0 commit comments

Comments
 (0)