Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

feat: account tag enhancement & uppercase for OneKey labels #29999

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all 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
19 changes: 13 additions & 6 deletions app/scripts/metamask-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import { JsonRpcError, providerErrors } from '@metamask/rpc-errors';
import { Mutex } from 'await-semaphore';
import log from 'loglevel';
import {
OneKeyKeyring,
TrezorConnectBridge,
TrezorKeyring,
} from '@metamask/eth-trezor-keyring';
Expand Down Expand Up @@ -1099,6 +1100,10 @@ export default class MetamaskController extends EventEmitter {
keyring: keyringOverrides?.trezor || TrezorKeyring,
bridge: keyringOverrides?.trezorBridge || TrezorConnectBridge,
},
{
keyring: keyringOverrides?.oneKey || OneKeyKeyring,
bridge: keyringOverrides?.oneKeyBridge || TrezorConnectBridge,
},
{
keyring: keyringOverrides?.ledger || LedgerKeyring,
bridge: keyringOverrides?.ledgerBridge || LedgerIframeBridge,
Expand All @@ -1123,6 +1128,10 @@ export default class MetamaskController extends EventEmitter {
TrezorKeyring,
keyringOverrides?.trezorBridge || TrezorOffscreenBridge,
),
hardwareKeyringBuilderFactory(
OneKeyKeyring,
keyringOverrides?.oneKey || TrezorOffscreenBridge,
),
hardwareKeyringBuilderFactory(
LedgerKeyring,
keyringOverrides?.ledgerBridge || LedgerOffscreenBridge,
Expand Down Expand Up @@ -4900,11 +4909,7 @@ export default class MetamaskController extends EventEmitter {
// The `getKeyringForAccount` is now deprecated, so we just use `withKeyring` instead to access our keyring.
return await this.keyringController.withKeyring(
{ address },
({ type: keyringType, bridge: keyringBridge }) =>
// Specific case for OneKey devices, see `ONE_KEY_VIA_TREZOR_MINOR_VERSION` for further details.
keyringBridge?.minorVersion === ONE_KEY_VIA_TREZOR_MINOR_VERSION
? HardwareKeyringType.oneKey
: HardwareKeyringType[keyringType],
({ type }) => HardwareKeyringType[type],
);
}

Expand Down Expand Up @@ -7703,9 +7708,11 @@ export default class MetamaskController extends EventEmitter {
let keyringType = null;
switch (options.name) {
case HardwareDeviceNames.trezor:
case HardwareDeviceNames.oneKey:
keyringType = keyringOverrides?.trezor?.type || TrezorKeyring.type;
break;
case HardwareDeviceNames.oneKey:
keyringType = keyringOverrides?.oneKey?.type || OneKeyKeyring?.type;
break;
case HardwareDeviceNames.ledger:
keyringType = keyringOverrides?.ledger?.type || LedgerKeyring.type;
break;
Expand Down
8 changes: 8 additions & 0 deletions lavamoat/build-system/policy.json
Original file line number Diff line number Diff line change
Expand Up @@ -1795,6 +1795,7 @@
"chokidar>anymatch": true,
"chokidar>braces": true,
"chokidar>fsevents": true,
"tsx>fsevents": true,
"eslint>glob-parent": true,
"chokidar>is-binary-path": true,
"del>is-glob": true,
Expand Down Expand Up @@ -3364,6 +3365,13 @@
"gulp-watch>chokidar>fsevents>node-pre-gyp": true
}
},
"tsx>fsevents": {
"globals": {
"console.assert": true,
"process.platform": true
},
"native": true
},
"@lavamoat/allow-scripts>@npmcli/run-script>node-gyp>npmlog>gauge": {
"builtin": {
"util.format": true
Expand Down
11 changes: 9 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,10 @@
"tslib@npm:^2.3.1": "~2.6.0",
"tslib@npm:^2.4.0": "~2.6.0",
"tslib@npm:^2.6.2": "~2.6.0",
"undici@npm:5.28.4": "5.28.5"
"undici@npm:5.28.4": "5.28.5",
"@metamask/eth-trezor-keyring": "file:/Users/sebastienvaneyck/Documents/consensys/metamask/accounts/packages/keyring-eth-trezor",
"@metamask/keyring-controller": "file:/Users/sebastienvaneyck/Documents/consensys/metamask/core/packages/keyring-controller",
"@metamask/accounts-controller": "file:/Users/sebastienvaneyck/Documents/consensys/metamask/core/packages/accounts-controller"
},
"dependencies": {
"@babel/runtime": "patch:@babel/runtime@npm%3A7.25.9#~/.yarn/patches/@babel-runtime-npm-7.25.9-fe8c62510a.patch",
Expand Down Expand Up @@ -764,7 +767,11 @@
"level>classic-level": false,
"jest-preview": false,
"@metamask/solana-wallet-snap>@solana/web3.js>bigint-buffer": false,
"@lavamoat/allow-scripts>@lavamoat/preinstall-always-fail": false
"@lavamoat/allow-scripts>@lavamoat/preinstall-always-fail": false,
"@metamask/eth-trezor-keyring>@trezor/connect-web>@trezor/connect>@trezor/transport>protobufjs": false,
"@metamask/eth-trezor-keyring>@trezor/connect-web>@trezor/connect>@trezor/transport>usb": false,
"@trezor/connect-web>@trezor/connect>@trezor/blockchain-link>@solana/web3.js>rpc-websockets>bufferutil": false,
"@trezor/connect-web>@trezor/connect>@trezor/blockchain-link>@solana/web3.js>rpc-websockets>utf-8-validate": false
}
},
"packageManager": "[email protected]"
Expand Down
3 changes: 2 additions & 1 deletion shared/constants/hardware-wallets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@ export enum HardwareKeyringType {
export enum HardwareKeyringNames {
ledger = 'Ledger',
trezor = 'Trezor',
oneKey = 'OneKey',
lattice = 'Lattice1',
qr = 'QR',
}

export enum HardwareDeviceNames {
ledger = 'ledger',
trezor = 'trezor',
oneKey = 'onekey',
oneKey = 'oneKey',
lattice = 'lattice',
qr = 'QR Hardware',
}
Expand Down
2 changes: 1 addition & 1 deletion ui/ducks/app/app.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ describe('App State', () => {
it('sets hardware wallet default hd path', () => {
const hdPaths = {
trezor: "m/44'/60'/0'/0",
onekey: "m/44'/60'/0'/0",
oneKey: "m/44'/60'/0'/0",
ledger: "m/44'/60'/0'",
lattice: "m/44'/60'/0'/0",
};
Expand Down
4 changes: 2 additions & 2 deletions ui/ducks/app/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ type AppState = {
buyView: Record<string, any>;
defaultHdPaths: {
trezor: string;
onekey: string;
oneKey: string;
ledger: string;
lattice: string;
};
Expand Down Expand Up @@ -178,7 +178,7 @@ const initialState: AppState = {
buyView: {},
defaultHdPaths: {
trezor: `m/44'/60'/0'/0`,
onekey: `m/44'/60'/0'/0`,
oneKey: `m/44'/60'/0'/0`,
ledger: `m/44'/60'/0'/0/0`,
lattice: `m/44'/60'/0'/0`,
},
Expand Down
2 changes: 2 additions & 0 deletions ui/helpers/utils/accounts.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ export function getAccountLabel(
return HardwareKeyringNames.qr;
case KeyringType.trezor:
return HardwareKeyringNames.trezor;
case KeyringType.oneKey:
return HardwareKeyringNames.oneKey;
case KeyringType.ledger:
return HardwareKeyringNames.ledger;
case KeyringType.lattice:
Expand Down
7 changes: 7 additions & 0 deletions ui/helpers/utils/accounts.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,13 @@ describe('Accounts', () => {
);
});

it('should return the correct label for OneKey hardware wallet', () => {
mockAccount.metadata.keyring.type = KeyringType.oneKey;
expect(getAccountLabel(KeyringType.oneKey, mockAccount)).toBe(
HardwareKeyringNames.oneKey,
);
});

it('should return the correct label for Ledger hardware wallet', () => {
mockAccount.metadata.keyring.type = KeyringType.ledger;
expect(getAccountLabel(KeyringType.ledger, mockAccount)).toBe(
Expand Down
6 changes: 4 additions & 2 deletions ui/pages/create-account/connect-hardware/account-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class AccountList extends Component {
<div className="hw-connect__hdPath">
<Dropdown
className="hw-connect__hdPath__select"
options={hdPaths[device.toLowerCase()]}
options={hdPaths[device]}
selectedOption={pathValue || selectedPath}
onChange={(value) => {
this.setPath(value);
Expand All @@ -73,7 +73,9 @@ class AccountList extends Component {
HardwareDeviceNames.lattice,
HardwareDeviceNames.trezor,
HardwareDeviceNames.oneKey,
].includes(device.toLowerCase());
]
.map((name) => name.toLowerCase())
.includes(device.toLowerCase());
return (
<div className="hw-connect">
<h3 className="hw-connect__unlock-title">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ const render = () => {
ledger: LEDGER_HD_PATHS,
lattice: LATTICE_HD_PATHS,
trezor: TREZOR_HD_PATHS,
onekey: TREZOR_HD_PATHS,
oneKey: TREZOR_HD_PATHS,
},
onPathChange: jest.fn(),
onAccountChange: jest.fn(),
Expand Down
2 changes: 1 addition & 1 deletion ui/pages/create-account/connect-hardware/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ const HD_PATHS = {
ledger: LEDGER_HD_PATHS,
lattice: LATTICE_HD_PATHS,
trezor: TREZOR_HD_PATHS,
onekey: TREZOR_HD_PATHS,
oneKey: TREZOR_HD_PATHS,
};

const getErrorMessage = (errorCode, t) => {
Expand Down
1 change: 1 addition & 0 deletions ui/selectors/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,7 @@ export function getAccountTypeForKeyring(keyring) {

switch (type) {
case KeyringType.trezor:
case KeyringType.oneKey:
case KeyringType.ledger:
case KeyringType.lattice:
case KeyringType.qr:
Expand Down
Loading
Loading