Skip to content

Commit

Permalink
Merge branch 'extract-wrapper-type' into ts-send-metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
NiranjanaBinoy authored Apr 9, 2024
2 parents 1f7fd93 + 16cabb8 commit 2601cfa
Showing 1 changed file with 119 additions and 15 deletions.
134 changes: 119 additions & 15 deletions app/scripts/lib/rpc-method-middleware/handlers/handlers-helper.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,52 @@
import {
AddApprovalOptions,
ApprovalFlowStartResult,
EndFlowOptions,
StartFlowOptions,
} from '@metamask/approval-controller';
import {
NetworkClientId,
NetworkConfiguration,
ProviderConfig,
} from '@metamask/network-controller';
import type {
CaveatSpecificationConstraint,
ExtractCaveats,
ExtractPermission,
OriginString,
PermissionSpecificationConstraint,
PermissionSubjectMetadata,
RequestedPermissions,
SubjectPermissions,
SubjectType,
ValidPermission,
} from '@metamask/permission-controller';
import type { Json } from '@metamask/utils';
import type { Hex, Json } from '@metamask/utils';
import { InfuraNetworkType } from '@metamask/controller-utils';
import {
MetaMetricsEventPayload,
MetaMetricsPageOptions,
} from '../../../../../shared/constants/metametrics';

export type ExistingNetworkChainIds = '0x1' | '0xaa36a7' | '0xe704' | '0xe708';

export type HandlerWrapper = {
methodNames: [string];
hookNames: Record<string, boolean>;
};

export type NetworkConfigurations = Record<
string,
NetworkConfiguration & {
id: string;
}
>;

/**
* @typedef {object} ProviderStateHandlerResult
* @property {string} chainId - The current chain ID.
* @property {boolean} isUnlocked - Whether the extension is unlocked or not.
* @property {string} networkVersion - The current network ID.
* @property {string[]} accounts - List of permitted accounts for the specified origin.
* @property chainId - The current chain ID.
* @property isUnlocked - Whether the extension is unlocked or not.
* @property networkVersion - The current network ID.
* @property accounts - List of permitted accounts for the specified origin.
*/
export type ProviderStateHandlerResult = {
chainId: string;
Expand All @@ -30,16 +62,88 @@ export type SubjectMetadataToAdd = PermissionSubjectMetadata & {
iconUrl?: string | null;
} & Record<string, Json>;

export type UpsertNetworkConfigurationOptions = {
referrer: string;
source: string;
setActive?: boolean;
};

export type AddSubjectMetadata = (metadata: SubjectMetadataToAdd) => void;
export type EndApprovalFlow = ({ id }: EndFlowOptions) => void;
export type FindNetworkClientIdByChainId = (chainId: Hex) => NetworkClientId;
export type FindNetworkConfigurationBy = (
rpcInfo: Record<string, string>,
) => ProviderConfig | null;
export type HasPermission = (origin: OriginString) => boolean;
export type GetAccounts = () => Promise<string[]>;
export type GetCurrentChainId = () => Hex;
export type GetCurrentRpcUrl = () => string | undefined;
export type GetNetworkConfigurations = () => NetworkConfiguration;
export type GetPermissionsForOrigin<
ControllerCaveatSpecification extends CaveatSpecificationConstraint = CaveatSpecificationConstraint,
> = (
origin: OriginString,
) =>
| SubjectPermissions<
ValidPermission<string, ExtractCaveats<ControllerCaveatSpecification>>
>
| undefined;
export type GetProviderConfig = () => ProviderConfig;
export type GetProviderState = (
origin: string,
origin: OriginString,
) => Promise<ProviderStateHandlerResult>;
export type GetWeb3ShimUsageState = (origin: string) => undefined | 1 | 2;
export type HandleWatchAssetRequest = ({
asset,
type,
origin,
networkClientId,
}: Record<string, string>) => Promise<void>;
export type SetWeb3ShimUsageRecorded = (origin: string) => void;
export type GetUnlockPromise = (
shouldShowUnlockRequest: boolean,
) => Promise<void>;
export type GetWeb3ShimUsageState = (origin: OriginString) => undefined | 1 | 2;
export type HandleWatchAssetRequest = (
options: Record<string, string>,
) => Promise<void>;
export type RequestAccountsPermission<
ControllerPermissionSpecification extends PermissionSpecificationConstraint = PermissionSpecificationConstraint,
ControllerCaveatSpecification extends CaveatSpecificationConstraint = CaveatSpecificationConstraint,
> = (
subject?: PermissionSubjectMetadata,
requestedPermissions?: RequestedPermissions,
options?: {
id?: string;
preserveExistingPermissions?: boolean;
},
) => Promise<
[
SubjectPermissions<
ExtractPermission<
ControllerPermissionSpecification,
ControllerCaveatSpecification
>
>,
{
data?: Record<string, unknown>;
id: string;
origin: OriginString;
},
]
>;
export type RequestUserApproval = (
options?: AddApprovalOptions,
) => Promise<unknown>;
export type SendMetrics = (
payload: MetaMetricsEventPayload,
options?: MetaMetricsPageOptions,
) => void;
export type SetActiveNetwork = (
networkConfigurationIdOrType: string,
) => Promise<void>;
export type SetNetworkClientIdForDomain = (
domain: string,
networkClientId: NetworkClientId,
) => void;
export type SetProviderType = (type: InfuraNetworkType) => Promise<void>;
export type SetWeb3ShimUsageRecorded = (origin: OriginString) => void;
export type StartApprovalFlow = (
options?: StartFlowOptions,
) => ApprovalFlowStartResult;
export type UpsertNetworkConfiguration = (
networkConfiguration: NetworkConfiguration,
options?: UpsertNetworkConfigurationOptions,
) => Promise<string>;

0 comments on commit 2601cfa

Please sign in to comment.