Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 27 additions & 5 deletions app/scripts/metamask-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ import {
hexToBytes,
bytesToHex,
KnownCaipNamespace,
isObject,
} from '@metamask/utils';
import { normalize } from '@metamask/eth-sig-util';

Expand Down Expand Up @@ -1010,6 +1011,9 @@ export default class MetamaskController extends EventEmitter {
this.networkController.getProviderAndBlockTracker().blockTracker;

this.on('update', (update) => {
if (!isObject(update)) {
return;
}
this.metaMetricsController.handleMetaMaskStateUpdate(update);
});

Expand Down Expand Up @@ -1336,7 +1340,12 @@ export default class MetamaskController extends EventEmitter {
});

// ensure isClientOpenAndUnlocked is updated when memState updates
this.on('update', (memState) => this._onStateUpdate(memState));
this.on('update', (memState) => {
if (!isObject(memState) || !('isUnlocked' in memState)) {
return;
}
this._onStateUpdate(memState);
});

/**
* All controllers in Memstore but not in store. They are not persisted.
Expand Down Expand Up @@ -2282,6 +2291,13 @@ export default class MetamaskController extends EventEmitter {
};

const updatePublicConfigStore = async (memState) => {
if (
!isObject(memState) ||
!('networksMetadata' in memState) ||
!('selectedNetworkId' in memState)
) {
return;
}
const networkStatus =
memState.networksMetadata[memState.selectedNetworkClientId]?.status;
if (networkStatus === NetworkStatus.Available) {
Expand Down Expand Up @@ -7753,12 +7769,18 @@ export default class MetamaskController extends EventEmitter {
// misc

/**
* A method for emitting the full MetaMask state to all registered listeners.
* A method for emitting either the full MetaMask state or pending patches to all registered listeners of the 'update' event.
* This method can be used to force UI updates in response to background actions or events e.g. state updates.
*
* @private
* @param sendFullState - If set to true, the full MetaMask state is sent. If set to false, only pending patches are sent.
* @see {@link {import('../../ui/store/actions.ts').forceUpdateMetamaskState}} also force-syncs UI state with background state, but in response to UI events or user actions.
*/
privateSendUpdate() {
this.emit('update', this.getState());
privateSendUpdate(sendFullState = true) {
if (sendFullState) {
this.emit('update', this.getState());
} else {
this.emit('update');
}
}

/**
Expand Down
Loading