ApprovalController Actions
17 actions registered.
ApprovalController:acceptRequest
Package: @metamask/approval-controller
Resolves the promise of the approval with the given id, and deletes the approval. Throws an error if no such approval exists.
Parameters:
| Name | Description |
|---|---|
id | The id of the approval request. |
value | The value to resolve the approval promise with. |
options | Options bag. |
Returns: A promise that either resolves once a result is provided by the creator of the approval request, or immediately if options.waitForResult is false or undefined.
Handler signature:
(id: string, value?: unknown, options?: AcceptOptions) => Promise<AcceptResult>
ApprovalController:add
Package: @metamask/approval-controller
Adds an approval request per the given arguments and returns the approval promise resolving to an AddResult object.
There can only be one approval per origin and type. An error is thrown if attempting to add an invalid or duplicate request.
Parameters:
| Name | Description |
|---|---|
opts | Options bag. |
opts.id | The id of the approval request. A random id will be generated if none is provided. |
opts.origin | The origin of the approval request. |
opts.type | The type associated with the approval request. |
opts.requestData | Additional data associated with the request, if any. |
Returns: The approval promise resolving to an AddResult object.
Handler signature:
(opts: AddApprovalOptions & {
expectsResult: true;
}) => Promise<AddResult>
ApprovalController:addAndShowApprovalRequest
Package: @metamask/approval-controller
Adds an approval request per the given arguments, calls the show approval request function, and returns the associated approval promise resolving to an AddResult object.
There can only be one approval per origin and type. An error is thrown if attempting to add an invalid or duplicate request.
Parameters:
| Name | Description |
|---|---|
opts | Options bag. |
opts.id | The id of the approval request. A random id will be generated if none is provided. |
opts.origin | The origin of the approval request. |
opts.type | The type associated with the approval request. |
opts.requestData | Additional data associated with the request, |
opts.requestState | Additional state associated with the request, if any. |
Returns: The approval promise resolving to an AddResult object.
Handler signature:
(opts: AddApprovalOptions & {
expectsResult: true;
}) => Promise<AddResult>
ApprovalController:addRequest
Package: @metamask/approval-controller
Adds an approval request per the given arguments, optionally showing the approval request to the user.
Parameters:
| Name | Description |
|---|---|
opts | Options bag. |
opts.id | The id of the approval request. A random id will be generated if none is provided. |
opts.origin | The origin of the approval request. |
opts.type | The type associated with the approval request. |
opts.requestData | Additional data associated with the request, if any. |
opts.requestState | Additional state associated with the request, if any. |
shouldShowRequest | Whether to show the approval request to the user. |
Returns: The approval promise.
Handler signature:
(opts: AddApprovalOptions, shouldShowRequest: boolean) => Promise<unknown>
ApprovalController:clearRequests
Package: @metamask/approval-controller
Rejects and deletes all approval requests.
Parameters:
| Name | Description |
|---|---|
rejectionError | The JsonRpcError to reject the approval requests with. |
Handler signature:
(rejectionError: JsonRpcError<DataWithOptionalCause>) => void
ApprovalController:endFlow
Package: @metamask/approval-controller
Ends the current approval flow.
Parameters:
| Name | Description |
|---|---|
opts | Options bag. |
opts.id | The id of the approval flow that will be finished. |
Handler signature:
({ id }: EndFlowOptions) => void
ApprovalController:get
Package: @metamask/approval-controller
Gets the info for the approval request with the given id.
Parameters:
| Name | Description |
|---|---|
id | The id of the approval request. |
Returns: The approval request data associated with the id.
Handler signature:
(id: string) => ApprovalRequest<ApprovalRequestData> | undefined
ApprovalController:getApprovalCount
Package: @metamask/approval-controller
Gets the number of pending approvals, by origin and/or type.
If only origin is specified, all approvals for that origin will be
counted, regardless of type.
If only type is specified, all approvals for that type will be counted,
regardless of origin.
If both origin and type are specified, 0 or 1 will be returned.
Parameters:
| Name | Description |
|---|---|
opts | The approval count options. |
opts.origin | An approval origin. |
opts.type | The type of the approval request. |
Returns: The current approval request count for the given origin and/or type.
Handler signature:
(opts?: {
origin?: string;
type?: string;
}) => number
ApprovalController:getState
Package: @metamask/approval-controller
Handler signature:
() => ApprovalControllerState
ApprovalController:getTotalApprovalCount
Package: @metamask/approval-controller
Get the total count of all pending approval requests for all origins.
Returns: The total pending approval request count.
Handler signature:
() => number
ApprovalController:hasRequest
Package: @metamask/approval-controller
Checks if there's a pending approval request per the given parameters. At least one parameter must be specified. An error will be thrown if the parameters are invalid.
If id is specified, all other parameters will be ignored.
If id is not specified, the method will check for requests that match
all of the specified parameters.
Parameters:
| Name | Description |
|---|---|
opts | Options bag. |
opts.id | The ID to check for. |
opts.origin | The origin to check for. |
opts.type | The type to check for. |
Returns: true if a matching approval is found, and false otherwise.
Handler signature:
(opts?: {
id?: string;
origin?: string;
type?: string;
}) => boolean
ApprovalController:rejectRequest
Package: @metamask/approval-controller
Rejects the promise of the approval with the given id, and deletes the approval. Throws an error if no such approval exists.
Parameters:
| Name | Description |
|---|---|
id | The id of the approval request. |
error | The error to reject the approval promise with. |
Handler signature:
(id: string, error: unknown) => void
ApprovalController:setFlowLoadingText
Package: @metamask/approval-controller
Sets the loading text for the approval flow.
Parameters:
| Name | Description |
|---|---|
opts | Options bag. |
opts.id | The approval flow loading text that will be displayed. |
opts.loadingText | The loading text that will be associated to the approval flow. |
Handler signature:
({ id, loadingText }: SetFlowLoadingTextOptions) => void
ApprovalController:showError
Package: @metamask/approval-controller
Show an error page.
Parameters:
| Name | Description |
|---|---|
opts | Options bag. |
opts.message | The message text or components to display in the page. |
opts.header | The text or components to display in the header of the page. |
opts.flowToEnd | The ID of the approval flow to end once the error page is approved. |
opts.title | The title to display above the message. Shown by default but can be hidden with null. |
opts.icon | The icon to display in the page. Shown by default but can be hidden with null. |
Returns: Empty object to support future additions.
Handler signature:
(opts?: ErrorOptions) => Promise<ErrorResult>
ApprovalController:showSuccess
Package: @metamask/approval-controller
Show a success page.
Parameters:
| Name | Description |
|---|---|
opts | Options bag. |
opts.message | The message text or components to display in the page. |
opts.header | The text or components to display in the header of the page. |
opts.flowToEnd | The ID of the approval flow to end once the success page is approved. |
opts.title | The title to display above the message. Shown by default but can be hidden with null. |
opts.icon | The icon to display in the page. Shown by default but can be hidden with null. |
Returns: Empty object to support future additions.
Handler signature:
(opts?: SuccessOptions) => Promise<SuccessResult>
ApprovalController:startFlow
Package: @metamask/approval-controller
Starts a new approval flow.
Parameters:
| Name | Description |
|---|---|
opts | Options bag. |
opts.id | The id of the approval flow. |
opts.loadingText | The loading text that will be associated to the approval flow. |
opts.show | A flag to determine whether the approval should show to the user. |
Returns: The object containing the approval flow id.
Handler signature:
(opts?: StartFlowOptions) => ApprovalFlowStartResult
ApprovalController:updateRequestState
Package: @metamask/approval-controller
Updates the request state of the approval with the given id.
Parameters:
| Name | Description |
|---|---|
opts | Options bag. |
opts.id | The id of the approval request. |
opts.requestState | Additional data associated with the request |
Handler signature:
(opts: UpdateRequestStateOptions) => void