Skip to content

Commit

Permalink
fix: fix PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
salimtb committed Nov 21, 2024
1 parent ce44580 commit 180037e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
11 changes: 11 additions & 0 deletions app/scripts/metamask-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -2917,6 +2917,7 @@ export default class MetamaskController extends EventEmitter {
this.controllerMessenger.subscribe(
`${this.accountsController.name}:selectedAccountChange`,
async (account) => {
console.log('ACCOUNT CHANGED ....');
if (account.address && account.address !== lastSelectedAddress) {
lastSelectedAddress = account.address;
await this._onAccountChange(account.address);
Expand Down Expand Up @@ -4453,6 +4454,7 @@ export default class MetamaskController extends EventEmitter {

async _addAccountsWithBalance() {
try {
console.log('ADDING ACCOUNTS WITH BALANCE ....');
// Scan accounts until we find an empty one
const chainId = getCurrentChainId({
metamask: this.networkController.state,
Expand Down Expand Up @@ -6914,6 +6916,15 @@ export default class MetamaskController extends EventEmitter {
};

async _onAccountChange(newAddress) {
const networkConfigurations =
this.networkController.state.networkConfigurationsByChainId;

const chainIds = Object.keys(networkConfigurations);

await this.tokenDetectionController.detectTokens({
selectedAddress: newAddress,
chainIds,
});
const permittedAccountsMap = getPermittedAccountsByOrigin(
this.permissionController.state,
);
Expand Down
15 changes: 13 additions & 2 deletions ui/components/app/detected-token/detected-token.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
} from '../../../store/actions';
import {
getAllDetectedTokensForSelectedAddress,
getCurrentChainId,
getDetectedTokensInCurrentNetwork,
getNetworkConfigurationsByChainId,
getPreferences,
Expand Down Expand Up @@ -58,6 +59,7 @@ const DetectedToken = ({ setShowDetectedTokens }) => {
const detectedTokensMultichain = useSelector(
getAllDetectedTokensForSelectedAddress,
);
const currentChainId = useSelector(getCurrentChainId);
const { tokenNetworkFilter } = useSelector(getPreferences);
const allNetworksFilterShown = Object.keys(tokenNetworkFilter ?? {}).length;

Expand Down Expand Up @@ -91,13 +93,22 @@ const DetectedToken = ({ setShowDetectedTokens }) => {
}

return detectedTokens.reduce((tokenObj, token) => {
tokenObj[token.address] = { token, selected: true };
tokenObj[token.address] = {
token,
selected: tokensListDetected[token.address]?.selected ?? true,
chainId: currentChainId,
};
return tokenObj;
}, {});
};

setTokensListDetected(newTokensList());
}, [allNetworksFilterShown, detectedTokensMultichain, detectedTokens]);
}, [
allNetworksFilterShown,
detectedTokensMultichain,
detectedTokens,
currentChainId,
]);

const [showDetectedTokenIgnoredPopover, setShowDetectedTokenIgnoredPopover] =
useState(false);
Expand Down

0 comments on commit 180037e

Please sign in to comment.