mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-22 01:47:00 +01:00
Fixed bug that was causing to not show the correct account name and instead was displaying the default "Account x" one (#20555)
This commit is contained in:
parent
e6cd452506
commit
787fc13f19
@ -292,9 +292,9 @@ export default class MMIController extends EventEmitter {
|
|||||||
})),
|
})),
|
||||||
);
|
);
|
||||||
|
|
||||||
newAccounts.forEach(
|
for (let i = 0; i < newAccounts.length; i++) {
|
||||||
async () => await this.keyringController.addNewAccount(keyring),
|
await this.keyringController.addNewAccount(keyring);
|
||||||
);
|
}
|
||||||
|
|
||||||
const allAccounts = await this.keyringController.getAccounts();
|
const allAccounts = await this.keyringController.getAccounts();
|
||||||
|
|
||||||
@ -303,12 +303,33 @@ export default class MMIController extends EventEmitter {
|
|||||||
...new Set(oldAccounts.concat(allAccounts.map((a) => a.toLowerCase()))),
|
...new Set(oldAccounts.concat(allAccounts.map((a) => a.toLowerCase()))),
|
||||||
];
|
];
|
||||||
|
|
||||||
|
// Create a Set of lowercased addresses from oldAccounts for efficient existence checks
|
||||||
|
const oldAccountsSet = new Set(
|
||||||
|
oldAccounts.map((address) => address.toLowerCase()),
|
||||||
|
);
|
||||||
|
|
||||||
|
// Create a map of lowercased addresses to names from newAccounts for efficient lookups
|
||||||
|
const accountNameMap = newAccounts.reduce((acc, item) => {
|
||||||
|
// For each account in newAccounts, add an entry to the map with the lowercased address as the key and the name as the value
|
||||||
|
acc[item.toLowerCase()] = accounts[item].name;
|
||||||
|
return acc;
|
||||||
|
}, {});
|
||||||
|
|
||||||
|
// Iterate over all accounts
|
||||||
allAccounts.forEach((address) => {
|
allAccounts.forEach((address) => {
|
||||||
if (!oldAccounts.includes(address.toLowerCase())) {
|
// Convert the address to lowercase for consistent comparisons
|
||||||
const label = newAccounts
|
const lowercasedAddress = address.toLowerCase();
|
||||||
.filter((item) => item.toLowerCase() === address)
|
|
||||||
.map((item) => accounts[item].name)[0];
|
// If the address is not in oldAccounts
|
||||||
this.preferencesController.setAccountLabel(address, label);
|
if (!oldAccountsSet.has(lowercasedAddress)) {
|
||||||
|
// Look up the label in the map
|
||||||
|
const label = accountNameMap[lowercasedAddress];
|
||||||
|
|
||||||
|
// If the label is defined
|
||||||
|
if (label) {
|
||||||
|
// Set the label for the address
|
||||||
|
this.preferencesController.setAccountLabel(address, label);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user