Skip to content

Commit

Permalink
Merge branch 'develop' into 17191/onboarding-unit-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tmashuang authored Jan 25, 2023
2 parents a06c302 + 16ea4a8 commit 4289c60
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
20 changes: 18 additions & 2 deletions app/scripts/metamask-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -642,8 +642,9 @@ export default class MetamaskController extends EventEmitter {
await opts.openPopup();
});

let additionalKeyrings = [];
if (!isManifestV3) {
let additionalKeyrings = [keyringBuilderFactory(QRHardwareKeyring)];

if (this.canUseHardwareWallets()) {
const additionalKeyringTypes = [
TrezorKeyring,
LedgerBridgeKeyring,
Expand All @@ -661,6 +662,7 @@ export default class MetamaskController extends EventEmitter {
encryptor: opts.encryptor || undefined,
cacheEncryptionKey: isManifestV3,
});

this.keyringController.memStore.subscribe((state) =>
this._onKeyringControllerUpdate(state),
);
Expand Down Expand Up @@ -1330,6 +1332,10 @@ export default class MetamaskController extends EventEmitter {
}
}

canUseHardwareWallets() {
return !isManifestV3 || process.env.CONF?.HARDWARE_WALLETS_MV3;
}

resetStates(resetMethods) {
resetMethods.forEach((resetMethod) => {
try {
Expand Down Expand Up @@ -2588,6 +2594,12 @@ export default class MetamaskController extends EventEmitter {

async getKeyringForDevice(deviceName, hdPath = null) {
let keyringName = null;
if (
deviceName !== HardwareDeviceNames.QR &&
!this.canUseHardwareWallets()
) {
throw new Error('Hardware wallets are not supported on this version.');
}
switch (deviceName) {
case HardwareDeviceNames.trezor:
keyringName = TrezorKeyring.type;
Expand Down Expand Up @@ -4405,6 +4417,10 @@ export default class MetamaskController extends EventEmitter {
* @param {string} transportType - The Ledger transport type.
*/
async setLedgerTransportPreference(transportType) {
if (!this.canUseHardwareWallets()) {
return undefined;
}

const currentValue =
this.preferencesController.getLedgerTransportPreference();
const newValue =
Expand Down
12 changes: 9 additions & 3 deletions ui/pages/create-account/connect-hardware/select-hardware.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
} from '../../../../shared/constants/hardware-wallets';
import ZENDESK_URLS from '../../../helpers/constants/zendesk-url';
import { EVENT } from '../../../../shared/constants/metametrics';
import { isManifestV3 } from '../../../../shared/modules/mv3.utils';

export default class SelectHardware extends Component {
static contextTypes = {
Expand All @@ -32,6 +33,10 @@ export default class SelectHardware extends Component {
selectedDevice: null,
};

shouldShowConnectButton() {
return !isManifestV3 || process.env.CONF?.HARDWARE_WALLETS_MV3;
}

connect = () => {
if (this.state.selectedDevice) {
this.props.connectToHardwareWallet(this.state.selectedDevice);
Expand Down Expand Up @@ -103,14 +108,15 @@ export default class SelectHardware extends Component {
return (
<>
<div className="hw-connect__btn-wrapper">
{this.renderConnectToLedgerButton()}
{this.renderConnectToTrezorButton()}
{this.shouldShowConnectButton() && this.renderConnectToLedgerButton()}
{this.shouldShowConnectButton() && this.renderConnectToTrezorButton()}
</div>
<div
className="hw-connect__btn-wrapper"
style={{ margin: '10px 0 0 0' }}
>
{this.renderConnectToLatticeButton()}
{this.shouldShowConnectButton() &&
this.renderConnectToLatticeButton()}
{this.renderConnectToQRButton()}
</div>
</>
Expand Down

0 comments on commit 4289c60

Please sign in to comment.