Skip to content

Commit

Permalink
fixesss
Browse files Browse the repository at this point in the history
  • Loading branch information
adonesky1 committed Feb 9, 2024
1 parent 0454a69 commit 3905f51
Showing 1 changed file with 21 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export type SelectedNetworkControllerGetSelectedNetworkStateAction = {

export type SelectedNetworkControllerGetNetworkClientIdForDomainAction = {
type: typeof SelectedNetworkControllerActionTypes.getNetworkClientIdForDomain;
handler: (domain: string) => NetworkClientId;
handler: (domain: string) => NetworkClientId | undefined;
};

export type SelectedNetworkControllerSetNetworkClientIdForDomainAction = {
Expand Down Expand Up @@ -182,23 +182,13 @@ export class SelectedNetworkController extends BaseController<
const networkProxy = this.#proxies.get(domain);
if (networkProxy === undefined) {
this.#proxies.set(domain, {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore-next-line
provider: createEventEmitterProxy(networkClient.provider),

// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore-next-line
blockTracker: createEventEmitterProxy(networkClient.blockTracker, {
eventFilter: 'skipInternal',
}),
});
} else {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore-next-line
networkProxy.provider.setTarget(networkClient.provider);

// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore-next-line
networkProxy.blockTracker.setTarget(networkClient.blockTracker);
}

Expand Down Expand Up @@ -242,13 +232,24 @@ export class SelectedNetworkController extends BaseController<
this.#setNetworkClientIdForDomain(domain, networkClientId);
}

getNetworkClientIdForDomain(domain: Domain): NetworkClientId {
if (this.state.perDomainNetwork) {
return this.state.domains[domain] ?? this.state.domains[METAMASK_DOMAIN];
getNetworkClientIdForDomain(domain: Domain): NetworkClientId | undefined {
if (!this.state.perDomainNetwork) {
return undefined;
}
return this.state.domains[domain];
}

getNetworkClientIdForMetamask(): NetworkClientId {
return this.state.domains[METAMASK_DOMAIN];
}

#getNetworkClientIdForDomainOrMetamask(domain: Domain): NetworkClientId {
return (
this.getNetworkClientIdForDomain(domain) ??
this.getNetworkClientIdForMetamask()
);
}

/**
* Accesses the provider and block tracker for the currently selected network.
*
Expand All @@ -260,15 +261,10 @@ export class SelectedNetworkController extends BaseController<
if (networkProxy === undefined) {
const networkClient = this.messagingSystem.call(
'NetworkController:getNetworkClientById',
this.getNetworkClientIdForDomain(domain),
this.#getNetworkClientIdForDomainOrMetamask(domain),
);
networkProxy = {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore-next-line
provider: createEventEmitterProxy(networkClient.provider),

// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore-next-line
blockTracker: createEventEmitterProxy(networkClient.blockTracker, {
eventFilter: 'skipInternal',
}),
Expand All @@ -285,10 +281,13 @@ export class SelectedNetworkController extends BaseController<
return state;
});
Object.keys(this.state.domains).forEach((domain) => {
// when perDomainNetwork is false, getNetworkClientIdForDomain always returns the networkClientId for the domain 'metamask'
// when perDomainNetwork is false, getNetworkClientIdForDomainOrMetamask always returns the networkClientId for the domain 'metamask'
this.setNetworkClientIdForDomain(
domain,
this.getNetworkClientIdForDomain(domain),
// TODO cant we just use getNetworkClientIdForMetamask here?
// since when perDomainNetwork is false, the networkClientId for all domains is the same
// and when perDomainNetwork is true, the networkClientId for the domain 'metamask' is the same as the networkClientId for the domain 'metamask'
this.#getNetworkClientIdForDomainOrMetamask(domain),
);
});
}
Expand Down

0 comments on commit 3905f51

Please sign in to comment.