Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
adonesky1 committed Feb 7, 2024
1 parent d3861d0 commit 1067774
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { RestrictedControllerMessenger } from '@metamask/base-controller';
import { BaseController } from '@metamask/base-controller';
import
import type {

Check failure on line 4 in packages/selected-network-controller/src/SelectedNetworkController.ts

View workflow job for this annotation

GitHub Actions / Lint, build, and test / Build (20.x)

Expression expected.
BlockTrackerProxy,
NetworkClientId,
Expand All @@ -24,7 +25,7 @@ const getDefaultState = () => ({

type Domain = string;

const METAMASK_DOMAIN = 'metamask' as const;
export const METAMASK_DOMAIN = 'metamask' as const;

export const SelectedNetworkControllerActionTypes = {
getState: `${controllerName}:getState` as const,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ import type {
SelectedNetworkControllerGetNetworkClientIdForDomainAction,
SelectedNetworkControllerSetNetworkClientIdForDomainAction,
} from './SelectedNetworkController';

Check failure on line 13 in packages/selected-network-controller/src/SelectedNetworkMiddleware.ts

View workflow job for this annotation

GitHub Actions / Lint, build, and test / Lint (20.x)

Parse errors in imported module './SelectedNetworkController': Expression expected. (4:0)
import { SelectedNetworkControllerActionTypes } from './SelectedNetworkController';
import {
METAMASK_DOMAIN,
SelectedNetworkControllerActionTypes,
} from './SelectedNetworkController';

Check failure on line 17 in packages/selected-network-controller/src/SelectedNetworkMiddleware.ts

View workflow job for this annotation

GitHub Actions / Lint, build, and test / Lint (20.x)

Parse errors in imported module './SelectedNetworkController': Expression expected. (4:0)

export type MiddlewareAllowedActions = NetworkControllerGetStateAction;
export type MiddlewareAllowedEvents = NetworkControllerStateChangeEvent;
Expand All @@ -37,29 +40,32 @@ export const createSelectedNetworkMiddleware = (
origin,
);

const setNetworkClientIdForDomain = (
origin: string,
networkClientId: NetworkClientId,
) =>
messenger.call(
SelectedNetworkControllerActionTypes.setNetworkClientIdForDomain,
origin,
networkClientId,
);
// const setNetworkClientIdForDomain = (
// origin: string,
// networkClientId: NetworkClientId,
// ) =>
// messenger.call(
// SelectedNetworkControllerActionTypes.setNetworkClientIdForDomain,
// origin,
// networkClientId,
// );

const getDefaultNetworkClientId = () =>
messenger.call('NetworkController:getState').selectedNetworkClientId;
// const getDefaultNetworkClientId = () =>
// messenger.call('NetworkController:getState').selectedNetworkClientId;

return (req: SelectedNetworkMiddlewareJsonRpcRequest, _, next) => {
if (!req.origin) {
throw new Error("Request object is lacking an 'origin'");
}

if (getNetworkClientIdForDomain(req.origin) === undefined) {
setNetworkClientIdForDomain(req.origin, getDefaultNetworkClientId());
}
// if (getNetworkClientIdForDomain(req.origin) === undefined) {
// setNetworkClientIdForDomain(req.origin, getDefaultNetworkClientId());
// }

req.networkClientId = getNetworkClientIdForDomain(req.origin);
req.networkClientId =
getNetworkClientIdForDomain(req.origin) ??
// TODO once this PR (https://github.com/MetaMask/core/pull/3884) is merged this will be removed
getNetworkClientIdForDomain(METAMASK_DOMAIN);
return next();
};
};

0 comments on commit 1067774

Please sign in to comment.