mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-21 17:37:01 +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(
|
||||
async () => await this.keyringController.addNewAccount(keyring),
|
||||
);
|
||||
for (let i = 0; i < newAccounts.length; i++) {
|
||||
await this.keyringController.addNewAccount(keyring);
|
||||
}
|
||||
|
||||
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()))),
|
||||
];
|
||||
|
||||
// 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) => {
|
||||
if (!oldAccounts.includes(address.toLowerCase())) {
|
||||
const label = newAccounts
|
||||
.filter((item) => item.toLowerCase() === address)
|
||||
.map((item) => accounts[item].name)[0];
|
||||
this.preferencesController.setAccountLabel(address, label);
|
||||
// Convert the address to lowercase for consistent comparisons
|
||||
const lowercasedAddress = address.toLowerCase();
|
||||
|
||||
// If the address is not in oldAccounts
|
||||
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