mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Avoid using indexes to reference first item in array (#15732)
This commit is contained in:
parent
1295fabfb5
commit
a64f82e8a0
@ -263,7 +263,7 @@ export default class PreferencesController {
|
|||||||
// If the selected account is no longer valid,
|
// If the selected account is no longer valid,
|
||||||
// select an arbitrary other account:
|
// select an arbitrary other account:
|
||||||
if (address === this.getSelectedAddress()) {
|
if (address === this.getSelectedAddress()) {
|
||||||
const selected = Object.keys(identities)[0];
|
const [selected] = Object.keys(identities);
|
||||||
this.setSelectedAddress(selected);
|
this.setSelectedAddress(selected);
|
||||||
}
|
}
|
||||||
return address;
|
return address;
|
||||||
@ -326,7 +326,7 @@ export default class PreferencesController {
|
|||||||
// select an arbitrary other account:
|
// select an arbitrary other account:
|
||||||
let selected = this.getSelectedAddress();
|
let selected = this.getSelectedAddress();
|
||||||
if (!addresses.includes(selected)) {
|
if (!addresses.includes(selected)) {
|
||||||
selected = addresses[0];
|
[selected] = addresses;
|
||||||
this.setSelectedAddress(selected);
|
this.setSelectedAddress(selected);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2161,8 +2161,8 @@ export default class MetamaskController extends EventEmitter {
|
|||||||
ethQuery,
|
ethQuery,
|
||||||
);
|
);
|
||||||
|
|
||||||
const primaryKeyring =
|
const [primaryKeyring] =
|
||||||
keyringController.getKeyringsByType('HD Key Tree')[0];
|
keyringController.getKeyringsByType('HD Key Tree');
|
||||||
if (!primaryKeyring) {
|
if (!primaryKeyring) {
|
||||||
throw new Error('MetamaskController - No HD Key Tree found');
|
throw new Error('MetamaskController - No HD Key Tree found');
|
||||||
}
|
}
|
||||||
@ -2287,8 +2287,7 @@ export default class MetamaskController extends EventEmitter {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Accounts
|
// Accounts
|
||||||
const hdKeyring =
|
const [hdKeyring] = this.keyringController.getKeyringsByType('HD Key Tree');
|
||||||
this.keyringController.getKeyringsByType('HD Key Tree')[0];
|
|
||||||
const simpleKeyPairKeyrings =
|
const simpleKeyPairKeyrings =
|
||||||
this.keyringController.getKeyringsByType('Simple Key Pair');
|
this.keyringController.getKeyringsByType('Simple Key Pair');
|
||||||
const hdAccounts = await hdKeyring.getAccounts();
|
const hdAccounts = await hdKeyring.getAccounts();
|
||||||
@ -2394,7 +2393,7 @@ export default class MetamaskController extends EventEmitter {
|
|||||||
*/
|
*/
|
||||||
selectFirstIdentity() {
|
selectFirstIdentity() {
|
||||||
const { identities } = this.preferencesController.store.getState();
|
const { identities } = this.preferencesController.store.getState();
|
||||||
const address = Object.keys(identities)[0];
|
const [address] = Object.keys(identities);
|
||||||
this.preferencesController.setSelectedAddress(address);
|
this.preferencesController.setSelectedAddress(address);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2402,7 +2401,7 @@ export default class MetamaskController extends EventEmitter {
|
|||||||
* Gets the mnemonic of the user's primary keyring.
|
* Gets the mnemonic of the user's primary keyring.
|
||||||
*/
|
*/
|
||||||
getPrimaryKeyringMnemonic() {
|
getPrimaryKeyringMnemonic() {
|
||||||
const keyring = this.keyringController.getKeyringsByType('HD Key Tree')[0];
|
const [keyring] = this.keyringController.getKeyringsByType('HD Key Tree');
|
||||||
if (!keyring.mnemonic) {
|
if (!keyring.mnemonic) {
|
||||||
throw new Error('Primary keyring mnemonic unavailable.');
|
throw new Error('Primary keyring mnemonic unavailable.');
|
||||||
}
|
}
|
||||||
@ -2433,9 +2432,7 @@ export default class MetamaskController extends EventEmitter {
|
|||||||
'MetamaskController:getKeyringForDevice - Unknown device',
|
'MetamaskController:getKeyringForDevice - Unknown device',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
let keyring = await this.keyringController.getKeyringsByType(
|
let [keyring] = await this.keyringController.getKeyringsByType(keyringName);
|
||||||
keyringName,
|
|
||||||
)[0];
|
|
||||||
if (!keyring) {
|
if (!keyring) {
|
||||||
keyring = await this.keyringController.addNewKeyring(keyringName);
|
keyring = await this.keyringController.addNewKeyring(keyringName);
|
||||||
}
|
}
|
||||||
@ -2635,8 +2632,8 @@ export default class MetamaskController extends EventEmitter {
|
|||||||
* @returns {} keyState
|
* @returns {} keyState
|
||||||
*/
|
*/
|
||||||
async addNewAccount(accountCount) {
|
async addNewAccount(accountCount) {
|
||||||
const primaryKeyring =
|
const [primaryKeyring] =
|
||||||
this.keyringController.getKeyringsByType('HD Key Tree')[0];
|
this.keyringController.getKeyringsByType('HD Key Tree');
|
||||||
if (!primaryKeyring) {
|
if (!primaryKeyring) {
|
||||||
throw new Error('MetamaskController - No HD Key Tree found');
|
throw new Error('MetamaskController - No HD Key Tree found');
|
||||||
}
|
}
|
||||||
@ -2679,8 +2676,8 @@ export default class MetamaskController extends EventEmitter {
|
|||||||
* encoded as an array of UTF-8 bytes.
|
* encoded as an array of UTF-8 bytes.
|
||||||
*/
|
*/
|
||||||
async verifySeedPhrase() {
|
async verifySeedPhrase() {
|
||||||
const primaryKeyring =
|
const [primaryKeyring] =
|
||||||
this.keyringController.getKeyringsByType('HD Key Tree')[0];
|
this.keyringController.getKeyringsByType('HD Key Tree');
|
||||||
if (!primaryKeyring) {
|
if (!primaryKeyring) {
|
||||||
throw new Error('MetamaskController - No HD Key Tree found');
|
throw new Error('MetamaskController - No HD Key Tree found');
|
||||||
}
|
}
|
||||||
@ -2804,12 +2801,12 @@ export default class MetamaskController extends EventEmitter {
|
|||||||
'Simple Key Pair',
|
'Simple Key Pair',
|
||||||
[privateKey],
|
[privateKey],
|
||||||
);
|
);
|
||||||
const accounts = await keyring.getAccounts();
|
const [firstAccount] = await keyring.getAccounts();
|
||||||
// update accounts in preferences controller
|
// update accounts in preferences controller
|
||||||
const allAccounts = await this.keyringController.getAccounts();
|
const allAccounts = await this.keyringController.getAccounts();
|
||||||
this.preferencesController.setAddresses(allAccounts);
|
this.preferencesController.setAddresses(allAccounts);
|
||||||
// set new account as selected
|
// set new account as selected
|
||||||
await this.preferencesController.setSelectedAddress(accounts[0]);
|
await this.preferencesController.setSelectedAddress(firstAccount);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
@ -2875,7 +2872,7 @@ export default class MetamaskController extends EventEmitter {
|
|||||||
if (requestedAccount) {
|
if (requestedAccount) {
|
||||||
account = requestedAccount;
|
account = requestedAccount;
|
||||||
} else {
|
} else {
|
||||||
account = (await this.keyringController.getAccounts())[0];
|
[account] = await this.keyringController.getAccounts();
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.keyringController.exportAppKeyForAddress(account, subject);
|
return this.keyringController.exportAppKeyForAddress(account, subject);
|
||||||
|
Loading…
Reference in New Issue
Block a user