Skip to content
Closed
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
27 changes: 27 additions & 0 deletions app/scripts/metamask-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ import { CHAIN_IDS } from '../../shared/constants/network';
import {
DEVICE_NAMES,
KEYRING_TYPES,
ONEKEY_VENDOR,
} from '../../shared/constants/hardware-wallets';
import {
CaveatTypes,
Expand Down Expand Up @@ -1579,6 +1580,7 @@ export default class MetamaskController extends EventEmitter {
this.attemptLedgerTransportCreation.bind(this),
establishLedgerTransportPreference:
this.establishLedgerTransportPreference.bind(this),
analyzeForOneKey: this.analyzeForOneKey.bind(this),

// qr hardware devices
submitQRHardwareCryptoHDKey:
Expand Down Expand Up @@ -2456,6 +2458,31 @@ export default class MetamaskController extends EventEmitter {
return keyring;
}

/**
* Statistics on whether the currently created account is from a OneKey hardware wallet
*
* @param deviceName - only accept trezor, because they use the same protocol
*/
async analyzeForOneKey(deviceName) {
if (deviceName !== DEVICE_NAMES.TREZOR) {
return;
}
const keyring = await this.keyringController.getKeyringsByType(
TrezorKeyring.type,
)[0];
if (!keyring) {
return;
}
const vendor = keyring.getVendor && (await keyring.getVendor());
// We added the getVendor function to trezor's keyring to differentiate between vendors.
// When the hardware wallet is unlocked, calling this method will get the vendor name: trezor or onekey.
// When the device is not unlocked, the default value is undefined.
// Some statistical code can be added here.
if (vendor === ONEKEY_VENDOR) {
log.info('MetaMaskController - This is the OneKey Hardware Wallet');
}
}

async attemptLedgerTransportCreation() {
const keyring = await this.getKeyringForDevice(DEVICE_NAMES.LEDGER);
return await keyring.attemptMakeApp();
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@
"eth-query": "^2.1.2",
"eth-rpc-errors": "^4.0.2",
"eth-sig-util": "^3.0.0",
"eth-trezor-keyring": "^0.10.0",
"eth-trezor-keyring": "github:MetaMask/eth-trezor-keyring#463bc786f3a913102067d64198ad9d9ed1aeff41",
"ethereum-ens-network-map": "^1.0.2",
"ethereumjs-abi": "^0.6.4",
"ethereumjs-util": "^7.0.10",
Expand Down
2 changes: 2 additions & 0 deletions shared/constants/hardware-wallets.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ export const TRANSPORT_STATES = {
UNKNOWN_FAILURE: 'UNKNOWN_FAILURE',
};

export const ONEKEY_VENDOR = 'onekey';

export const AFFILIATE_LINKS = {
LEDGER: 'https://shop.ledger.com/?r=17c4991a03fa',
GRIDPLUS: 'https://gridplus.io/?afmc=7p',
Expand Down
9 changes: 8 additions & 1 deletion ui/pages/create-account/connect-hardware/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ class ConnectHardwareForm extends Component {
});
};

onUnlockAccounts = (device, path) => {
onUnlockAccounts = async (device, path) => {
const { history, mostRecentOverviewPage, unlockHardwareWalletAccounts } =
this.props;
const { selectedAccounts } = this.state;
Expand All @@ -241,6 +241,10 @@ class ConnectHardwareForm extends Component {
this.setState({ error: this.context.t('accountSelectionRequired') });
}

if (device === DEVICE_NAMES.TREZOR) {
await this.props.analyzeForOneKey(device);
}

const description =
MEW_PATH === path
? this.context.t('hardwareWalletLegacyDescription')
Expand Down Expand Up @@ -357,6 +361,7 @@ ConnectHardwareForm.propTypes = {
hideAlert: PropTypes.func,
unlockHardwareWalletAccounts: PropTypes.func,
setHardwareWalletDefaultHdPath: PropTypes.func,
analyzeForOneKey: PropTypes.func,
history: PropTypes.object,
chainId: PropTypes.string,
rpcPrefs: PropTypes.object,
Expand Down Expand Up @@ -406,6 +411,8 @@ const mapDispatchToProps = (dispatch) => {
),
);
},
analyzeForOneKey: (deviceName) =>
dispatch(actions.analyzeForOneKey(deviceName)),
showAlert: (msg) => dispatch(actions.showAlert(msg)),
hideAlert: () => dispatch(actions.hideAlert()),
};
Expand Down
13 changes: 13 additions & 0 deletions ui/store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,19 @@ export function unlockHardwareWalletAccounts(
};
}

export function analyzeForOneKey(deviceName) {
log.debug(`background.analyzeForOneKey`, deviceName);
return async () => {
try {
await submitRequestToBackground('analyzeForOneKey', [deviceName]);
} catch (e) {
log.error(e);
throw e;
}
return undefined
}
}

export function showQrScanner() {
return (dispatch) => {
dispatch(
Expand Down
19 changes: 19 additions & 0 deletions ui/store/actions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,25 @@ describe('Actions', () => {
});
});

describe('#analyzeForOneKey', () => {
afterEach(() => {
sinon.restore();
});

it('calls analyzeForOneKey in background', async () => {
const store = mockStore();

const analyzeForOneKey = background.analyzeForOneKey.callsFake((_, cb) =>
cb(),
);

actions._setBackgroundConnection(background);

await store.dispatch(actions.analyzeForOneKey(DEVICE_NAMES.TREZOR));
expect(analyzeForOneKey.callCount).toStrictEqual(1);
});
});

describe('#unlockHardwareWalletAccount', () => {
afterEach(() => {
sinon.restore();
Expand Down
5 changes: 2 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -12230,10 +12230,9 @@ eth-simple-keyring@^4.2.0:
ethereumjs-wallet "^1.0.1"
events "^1.1.1"

eth-trezor-keyring@^0.10.0:
"eth-trezor-keyring@github:MetaMask/eth-trezor-keyring#463bc786f3a913102067d64198ad9d9ed1aeff41":
version "0.10.0"
resolved "https://registry.yarnpkg.com/eth-trezor-keyring/-/eth-trezor-keyring-0.10.0.tgz#a7dcf3343730897359e9ec7517cfd90f130cfbb9"
integrity sha512-QGwSMM+Bv0MLtsJLrVfo7oqWzzvW1L6TS34EhrP56R0Io88rAJoEyE71Qpim1akKlF/VmJ6v04yXWgUPrTX2vg==
resolved "https://codeload.github.com/MetaMask/eth-trezor-keyring/tar.gz/463bc786f3a913102067d64198ad9d9ed1aeff41"
dependencies:
"@ethereumjs/tx" "^3.2.1"
"@metamask/eth-sig-util" "^4.0.0"
Expand Down