Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

chore(cherry-pick):759b92e to 12.1.1 #26802

Merged
merged 4 commits into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/scripts/migrations/105.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ function expectedInternalAccount(
type: 'HD Key Tree',
},
lastSelected: lastSelected ? expect.any(Number) : undefined,
importTime: 0,
},
options: {},
methods: ETH_EOA_METHODS,
Expand Down
1 change: 1 addition & 0 deletions app/scripts/migrations/105.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ function createInternalAccountsForAccountsController(
metadata: {
name: identity.name,
lastSelected: identity.lastSelected ?? undefined,
importTime: 0,
Gudahtt marked this conversation as resolved.
Show resolved Hide resolved
keyring: {
// This is default HD Key Tree type because the keyring is encrypted
// during migration, the type will get updated when the during the
Expand Down
37 changes: 33 additions & 4 deletions lavamoat/browserify/beta/policy.json
Original file line number Diff line number Diff line change
Expand Up @@ -797,11 +797,10 @@
"@ethereumjs/tx>@ethereumjs/util": true,
"@ethereumjs/tx>ethereum-cryptography": true,
"@metamask/accounts-controller>@metamask/base-controller": true,
"@metamask/accounts-controller>@metamask/utils": true,
"@metamask/eth-snap-keyring": true,
"@metamask/keyring-api": true,
"@metamask/keyring-controller": true,
"@metamask/snaps-utils": true,
"@metamask/utils": true,
"uuid": true
}
},
Expand All @@ -813,6 +812,21 @@
"immer": true
}
},
"@metamask/accounts-controller>@metamask/utils": {
"globals": {
"TextDecoder": true,
"TextEncoder": true
},
"packages": {
"@metamask/utils>@metamask/superstruct": true,
"@metamask/utils>@scure/base": true,
"@metamask/utils>pony-cause": true,
"@noble/hashes": true,
"browserify>buffer": true,
"nock>debug": true,
"semver": true
}
},
"@metamask/address-book-controller": {
"packages": {
"@metamask/address-book-controller>@metamask/controller-utils": true,
Expand Down Expand Up @@ -1592,10 +1606,25 @@
"URL": true
},
"packages": {
"@metamask/keyring-api>@metamask/utils": true,
"@metamask/keyring-api>bech32": true,
"@metamask/keyring-api>uuid": true,
"@metamask/utils": true,
"superstruct": true
"@metamask/utils>@metamask/superstruct": true
}
},
"@metamask/keyring-api>@metamask/utils": {
"globals": {
"TextDecoder": true,
"TextEncoder": true
},
"packages": {
"@metamask/utils>@metamask/superstruct": true,
"@metamask/utils>@scure/base": true,
"@metamask/utils>pony-cause": true,
"@noble/hashes": true,
"browserify>buffer": true,
"nock>debug": true,
"semver": true
}
},
"@metamask/keyring-api>uuid": {
Expand Down
37 changes: 33 additions & 4 deletions lavamoat/browserify/flask/policy.json
Original file line number Diff line number Diff line change
Expand Up @@ -797,11 +797,10 @@
"@ethereumjs/tx>@ethereumjs/util": true,
"@ethereumjs/tx>ethereum-cryptography": true,
"@metamask/accounts-controller>@metamask/base-controller": true,
"@metamask/accounts-controller>@metamask/utils": true,
"@metamask/eth-snap-keyring": true,
"@metamask/keyring-api": true,
"@metamask/keyring-controller": true,
"@metamask/snaps-utils": true,
"@metamask/utils": true,
"uuid": true
}
},
Expand All @@ -813,6 +812,21 @@
"immer": true
}
},
"@metamask/accounts-controller>@metamask/utils": {
"globals": {
"TextDecoder": true,
"TextEncoder": true
},
"packages": {
"@metamask/utils>@metamask/superstruct": true,
"@metamask/utils>@scure/base": true,
"@metamask/utils>pony-cause": true,
"@noble/hashes": true,
"browserify>buffer": true,
"nock>debug": true,
"semver": true
}
},
"@metamask/address-book-controller": {
"packages": {
"@metamask/address-book-controller>@metamask/controller-utils": true,
Expand Down Expand Up @@ -1592,10 +1606,25 @@
"URL": true
},
"packages": {
"@metamask/keyring-api>@metamask/utils": true,
"@metamask/keyring-api>bech32": true,
"@metamask/keyring-api>uuid": true,
"@metamask/utils": true,
"superstruct": true
"@metamask/utils>@metamask/superstruct": true
}
},
"@metamask/keyring-api>@metamask/utils": {
"globals": {
"TextDecoder": true,
"TextEncoder": true
},
"packages": {
"@metamask/utils>@metamask/superstruct": true,
"@metamask/utils>@scure/base": true,
"@metamask/utils>pony-cause": true,
"@noble/hashes": true,
"browserify>buffer": true,
"nock>debug": true,
"semver": true
}
},
"@metamask/keyring-api>uuid": {
Expand Down
37 changes: 33 additions & 4 deletions lavamoat/browserify/main/policy.json
Original file line number Diff line number Diff line change
Expand Up @@ -797,11 +797,10 @@
"@ethereumjs/tx>@ethereumjs/util": true,
"@ethereumjs/tx>ethereum-cryptography": true,
"@metamask/accounts-controller>@metamask/base-controller": true,
"@metamask/accounts-controller>@metamask/utils": true,
"@metamask/eth-snap-keyring": true,
"@metamask/keyring-api": true,
"@metamask/keyring-controller": true,
"@metamask/snaps-utils": true,
"@metamask/utils": true,
"uuid": true
}
},
Expand All @@ -813,6 +812,21 @@
"immer": true
}
},
"@metamask/accounts-controller>@metamask/utils": {
"globals": {
"TextDecoder": true,
"TextEncoder": true
},
"packages": {
"@metamask/utils>@metamask/superstruct": true,
"@metamask/utils>@scure/base": true,
"@metamask/utils>pony-cause": true,
"@noble/hashes": true,
"browserify>buffer": true,
"nock>debug": true,
"semver": true
}
},
"@metamask/address-book-controller": {
"packages": {
"@metamask/address-book-controller>@metamask/controller-utils": true,
Expand Down Expand Up @@ -1592,10 +1606,25 @@
"URL": true
},
"packages": {
"@metamask/keyring-api>@metamask/utils": true,
"@metamask/keyring-api>bech32": true,
"@metamask/keyring-api>uuid": true,
"@metamask/utils": true,
"superstruct": true
"@metamask/utils>@metamask/superstruct": true
}
},
"@metamask/keyring-api>@metamask/utils": {
"globals": {
"TextDecoder": true,
"TextEncoder": true
},
"packages": {
"@metamask/utils>@metamask/superstruct": true,
"@metamask/utils>@scure/base": true,
"@metamask/utils>pony-cause": true,
"@noble/hashes": true,
"browserify>buffer": true,
"nock>debug": true,
"semver": true
}
},
"@metamask/keyring-api>uuid": {
Expand Down
37 changes: 33 additions & 4 deletions lavamoat/browserify/mmi/policy.json
Original file line number Diff line number Diff line change
Expand Up @@ -889,11 +889,10 @@
"@ethereumjs/tx>@ethereumjs/util": true,
"@ethereumjs/tx>ethereum-cryptography": true,
"@metamask/accounts-controller>@metamask/base-controller": true,
"@metamask/accounts-controller>@metamask/utils": true,
"@metamask/eth-snap-keyring": true,
"@metamask/keyring-api": true,
"@metamask/keyring-controller": true,
"@metamask/snaps-utils": true,
"@metamask/utils": true,
"uuid": true
}
},
Expand All @@ -905,6 +904,21 @@
"immer": true
}
},
"@metamask/accounts-controller>@metamask/utils": {
"globals": {
"TextDecoder": true,
"TextEncoder": true
},
"packages": {
"@metamask/utils>@metamask/superstruct": true,
"@metamask/utils>@scure/base": true,
"@metamask/utils>pony-cause": true,
"@noble/hashes": true,
"browserify>buffer": true,
"nock>debug": true,
"semver": true
}
},
"@metamask/address-book-controller": {
"packages": {
"@metamask/address-book-controller>@metamask/controller-utils": true,
Expand Down Expand Up @@ -1684,10 +1698,25 @@
"URL": true
},
"packages": {
"@metamask/keyring-api>@metamask/utils": true,
"@metamask/keyring-api>bech32": true,
"@metamask/keyring-api>uuid": true,
"@metamask/utils": true,
"superstruct": true
"@metamask/utils>@metamask/superstruct": true
}
},
"@metamask/keyring-api>@metamask/utils": {
"globals": {
"TextDecoder": true,
"TextEncoder": true
},
"packages": {
"@metamask/utils>@metamask/superstruct": true,
"@metamask/utils>@scure/base": true,
"@metamask/utils>pony-cause": true,
"@noble/hashes": true,
"browserify>buffer": true,
"nock>debug": true,
"semver": true
}
},
"@metamask/keyring-api>uuid": {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@
"@metamask-institutional/sdk": "^0.1.30",
"@metamask-institutional/transaction-update": "^0.2.5",
"@metamask/abi-utils": "^2.0.2",
"@metamask/accounts-controller": "^17.0.0",
"@metamask/accounts-controller": "^18.1.0",
"@metamask/address-book-controller": "^4.0.1",
"@metamask/announcement-controller": "^6.1.0",
"@metamask/approval-controller": "^7.0.0",
Expand Down
35 changes: 22 additions & 13 deletions ui/components/multichain/pages/connections/connections.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,10 @@ export const Connections = () => {
);
const selectedAccount = useSelector(getSelectedAccount);
const internalAccounts = useSelector(getInternalAccounts);
const mergedAccounts = mergeAccounts(connectedAccounts, internalAccounts);
const mergedAccounts = mergeAccounts(
connectedAccounts,
internalAccounts,
) as AccountType[];
Copy link
Member

@Gudahtt Gudahtt Aug 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-blocking comment: This type assertion does not appear to be necessary, but at least it's not overriding any valid type errors. Easiest to leave this as-is for the cherry-pick, but please avoid the use of type assertions in the future. See here for details on why, and about alternatives: https://github.com/MetaMask/contributor-docs/blob/main/docs/typescript.md#type-assertions

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think linter was complaining when the pr was made. This type comes from this line

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, but that line is using the wrong type (it's using AccountType, but this is a MergedAccountType). If the type is corrected, the error goes away. TypeScript is correct here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general, we should never use type assertions like this. Even in the scenarios where TypeScript lacks the necessary type information and there is no good way to provide it, there are better ways to "override" the type (type guards, the satisfies operator, type annotations, etc.`). The linked document has plenty more details. I'd encourage you to review it, and follow up with any questions you have about it.

But in this specific scenario, I don't think any override is needed


const permittedAccountsByOrigin = useSelector(
getPermittedAccountsByOrigin,
Expand Down Expand Up @@ -174,16 +177,24 @@ export const Connections = () => {
index ===
mergedAccounts.reduce(
(
acc: string | number,
cur: { metadata: { lastSelected: number } },
indexOfAccountWIthHighestLastSelected: number,
currentAccountToCompare: AccountType,
// TODO: Replace `any` with type
// eslint-disable-next-line @typescript-eslint/no-explicit-any
i: any,
) =>
cur.metadata.lastSelected >
mergedAccounts[acc].metadata.lastSelected
) => {
const currentLastSelected =
currentAccountToCompare.metadata.lastSelected ?? 0;
const accountAtIndexLastSelected = mergedAccounts[
indexOfAccountWIthHighestLastSelected
].metadata.lastSelected
? i
: acc,
: indexOfAccountWIthHighestLastSelected;

return currentLastSelected > accountAtIndexLastSelected
? i
: indexOfAccountWIthHighestLastSelected;
},
0,
)
);
Expand Down Expand Up @@ -252,12 +263,10 @@ export const Connections = () => {
const isSelectedAccount =
selectedAccount.address === account.address;
// Match the index of latestSelected Account with the index of all the accounts and set the active status
let mergedAccountsProps;
if (index === latestSelected) {
mergedAccountsProps = { ...account, isAccountActive: true };
} else {
mergedAccountsProps = { ...account };
}
const mergedAccountsProps = {
...account,
isAccountActive: index === latestSelected,
};
return (
<AccountListItem
account={mergedAccountsProps}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from 'react';
import configureStore from 'redux-mock-store';
import { EthAccountType, EthMethod } from '@metamask/keyring-api';
import { fireEvent, renderWithProvider } from '../../../../test/jest';
import { ETH_EOA_METHODS } from '../../../../shared/constants/eth-methods';
import { PermissionDetailsModal } from '.';

describe('PermissionDetailsModal', () => {
Expand Down Expand Up @@ -34,6 +35,8 @@ describe('PermissionDetailsModal', () => {
id: 'cf8dace4-9439-4bd4-b3a8-88c821c8fcb3',
metadata: {
name: 'Really Long Name That Should Be Truncated',
importTime: 1724252448,
lastSelected: 1724252448,
keyring: {
type: 'HD Key Tree',
},
Expand All @@ -48,6 +51,7 @@ describe('PermissionDetailsModal', () => {
metadata: {
name: 'Account 1',
lastSelected: 1586359844192,
importTime: 1586359844192,
lastActive: 1586359844192,
keyring: {
type: 'HD Key Tree',
Expand Down Expand Up @@ -112,10 +116,14 @@ describe('PermissionDetailsModal', () => {
id: 'cf8dace4-9439-4bd4-b3a8-88c821c8fcb3',
metadata: {
name: 'mockName',
importTime: 1724256979,
keyring: {
type: 'HD Key Tree',
},
},
options: {},
methods: ETH_EOA_METHODS,
type: EthAccountType.Eoa,
label: '',
},
isOpen: true,
Expand Down
4 changes: 0 additions & 4 deletions ui/components/multichain/toast/toast.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ const mockInternalAccount = createMockInternalAccount();
const CHAOS_ACCOUNT: InternalAccount = {
...mockInternalAccount,
address: '0x64a845a5b02460acf8a3d84503b0d68d028b4bb4',
balance: '0x152387ad22c3f0',
keyring: {
type: 'HD Key Tree',
},
};

const onActionClick = jest.fn();
Expand Down
1 change: 1 addition & 0 deletions ui/hooks/useMultichainSelector.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ describe('useMultichainSelector', () => {
});

it('uses selectedAccount if account is not provided', () => {
// @ts-expect-error: intentionally testing without account
const { result } = renderUseMultichainHook(getMultichainIsEvm, null);

expect(result.current).toBe(true);
Expand Down
Loading