@metamask/approval-controller
Advanced tools
Comparing version 1.0.1 to 1.1.0
@@ -9,5 +9,13 @@ # Changelog | ||
## [1.1.0] | ||
### Added | ||
- Add `updateRequestState` action to `ApprovalController` ([#1059](https://github.com/MetaMask/controllers/pull/1059)) | ||
### Changed | ||
- Rename this repository to `core` ([#1031](https://github.com/MetaMask/controllers/pull/1031)) | ||
- Update `@metamask/controller-utils` package ([#1041](https://github.com/MetaMask/controllers/pull/1041)) | ||
## [1.0.1] | ||
### Changed | ||
- Relax dependencies on `@metamask/base-controller` and `@metamask/controller-utils` (use `^` instead of `~`) ([#998](https://github.com/MetaMask/controllers/pull/998)) | ||
- Relax dependencies on `@metamask/base-controller` and `@metamask/controller-utils` (use `^` instead of `~`) ([#998](https://github.com/MetaMask/core/pull/998)) | ||
@@ -17,3 +25,3 @@ ## [1.0.0] | ||
- Initial release | ||
- As a result of converting our shared controllers repo into a monorepo ([#831](https://github.com/MetaMask/controllers/pull/831)), we've created this package from select parts of [`@metamask/controllers` v33.0.0](https://github.com/MetaMask/controllers/tree/v33.0.0), namely: | ||
- As a result of converting our shared controllers repo into a monorepo ([#831](https://github.com/MetaMask/core/pull/831)), we've created this package from select parts of [`@metamask/controllers` v33.0.0](https://github.com/MetaMask/core/tree/v33.0.0), namely: | ||
- Everything in `src/approval` | ||
@@ -23,4 +31,5 @@ | ||
[Unreleased]: https://github.com/MetaMask/controllers/compare/@metamask/approval-controller@1.0.1...HEAD | ||
[1.0.1]: https://github.com/MetaMask/controllers/compare/@metamask/approval-controller@1.0.0...@metamask/approval-controller@1.0.1 | ||
[1.0.0]: https://github.com/MetaMask/controllers/releases/tag/@metamask/approval-controller@1.0.0 | ||
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/approval-controller@1.1.0...HEAD | ||
[1.1.0]: https://github.com/MetaMask/core/compare/@metamask/approval-controller@1.0.1...@metamask/approval-controller@1.1.0 | ||
[1.0.1]: https://github.com/MetaMask/core/compare/@metamask/approval-controller@1.0.0...@metamask/approval-controller@1.0.1 | ||
[1.0.0]: https://github.com/MetaMask/core/releases/tag/@metamask/approval-controller@1.0.0 |
@@ -7,2 +7,3 @@ import type { Patch } from 'immer'; | ||
declare type ApprovalRequestData = Record<string, Json> | null; | ||
declare type ApprovalRequestState = Record<string, Json> | null; | ||
export declare type ApprovalRequest<RequestData extends ApprovalRequestData> = { | ||
@@ -30,2 +31,6 @@ /** | ||
requestData: RequestData; | ||
/** | ||
* Additional mutable state associated with the request | ||
*/ | ||
requestState: ApprovalRequestState; | ||
}; | ||
@@ -50,2 +55,3 @@ declare type ShowApprovalRequest = () => void | Promise<void>; | ||
requestData?: Record<string, Json>; | ||
requestState?: Record<string, Json>; | ||
}; | ||
@@ -68,3 +74,11 @@ export declare type AddApprovalRequest = { | ||
}; | ||
export declare type ApprovalControllerActions = GetApprovalsState | ClearApprovalRequests | AddApprovalRequest | HasApprovalRequest | AcceptRequest | RejectRequest; | ||
declare type UpdateRequestStateOptions = { | ||
id: string; | ||
requestState: Record<string, Json>; | ||
}; | ||
export declare type UpdateRequestState = { | ||
type: `${typeof controllerName}:updateRequestState`; | ||
handler: ApprovalController['updateRequestState']; | ||
}; | ||
export declare type ApprovalControllerActions = GetApprovalsState | ClearApprovalRequests | AddApprovalRequest | HasApprovalRequest | AcceptRequest | RejectRequest | UpdateRequestState; | ||
export declare type ApprovalStateChange = { | ||
@@ -122,2 +136,3 @@ type: `${typeof controllerName}:stateChange`; | ||
* @param opts.requestData - Additional data associated with the request, | ||
* @param opts.requestState - Additional state associated with the request, | ||
* if any. | ||
@@ -220,2 +235,10 @@ * @returns The approval promise. | ||
/** | ||
* Updates the request state of the approval with the given id. | ||
* | ||
* @param opts - Options bag. | ||
* @param opts.id - The id of the approval request. | ||
* @param opts.requestState - Additional data associated with the request | ||
*/ | ||
updateRequestState(opts: UpdateRequestStateOptions): void; | ||
/** | ||
* Implementation of add operation. | ||
@@ -227,2 +250,3 @@ * | ||
* @param requestData - The request data associated with the approval request. | ||
* @param requestState - The request state associated with the approval request. | ||
* @returns The approval promise. | ||
@@ -238,2 +262,3 @@ */ | ||
* @param requestData - The request data associated with the approval request. | ||
* @param requestState - The request state associated with the approval request. | ||
*/ | ||
@@ -257,2 +282,3 @@ private _validateAddParams; | ||
* @param requestData - The request data associated with the approval request. | ||
* @param requestState - The request state associated with the approval request. | ||
*/ | ||
@@ -259,0 +285,0 @@ private _addToStore; |
@@ -66,2 +66,3 @@ "use strict"; | ||
this.messagingSystem.registerActionHandler(`${controllerName}:rejectRequest`, this.reject.bind(this)); | ||
this.messagingSystem.registerActionHandler(`${controllerName}:updateRequestState`, this.updateRequestState.bind(this)); | ||
} | ||
@@ -81,2 +82,3 @@ /** | ||
* @param opts.requestData - Additional data associated with the request, | ||
* @param opts.requestState - Additional state associated with the request, | ||
* if any. | ||
@@ -86,3 +88,3 @@ * @returns The approval promise. | ||
addAndShowApprovalRequest(opts) { | ||
const promise = this._add(opts.origin, opts.type, opts.id, opts.requestData); | ||
const promise = this._add(opts.origin, opts.type, opts.id, opts.requestData, opts.requestState); | ||
this._showApprovalRequest(); | ||
@@ -108,3 +110,3 @@ return promise; | ||
add(opts) { | ||
return this._add(opts.origin, opts.type, opts.id, opts.requestData); | ||
return this._add(opts.origin, opts.type, opts.id, opts.requestData, opts.requestState); | ||
} | ||
@@ -245,2 +247,19 @@ /** | ||
/** | ||
* Updates the request state of the approval with the given id. | ||
* | ||
* @param opts - Options bag. | ||
* @param opts.id - The id of the approval request. | ||
* @param opts.requestState - Additional data associated with the request | ||
*/ | ||
updateRequestState(opts) { | ||
if (!this.state.pendingApprovals[opts.id]) { | ||
throw new errors_1.ApprovalRequestNotFoundError(opts.id); | ||
} | ||
this.update((draftState) => { | ||
// Typecast: ts(2589) | ||
draftState.pendingApprovals[opts.id].requestState = | ||
opts.requestState; | ||
}); | ||
} | ||
/** | ||
* Implementation of add operation. | ||
@@ -252,7 +271,8 @@ * | ||
* @param requestData - The request data associated with the approval request. | ||
* @param requestState - The request state associated with the approval request. | ||
* @returns The approval promise. | ||
*/ | ||
_add(origin, type, id = (0, nanoid_1.nanoid)(), requestData) { | ||
_add(origin, type, id = (0, nanoid_1.nanoid)(), requestData, requestState) { | ||
var _a; | ||
this._validateAddParams(id, origin, type, requestData); | ||
this._validateAddParams(id, origin, type, requestData, requestState); | ||
if ((_a = this._origins.get(origin)) === null || _a === void 0 ? void 0 : _a.has(type)) { | ||
@@ -265,3 +285,3 @@ throw eth_rpc_errors_1.ethErrors.rpc.resourceUnavailable(getAlreadyPendingMessage(origin, type)); | ||
this._addPendingApprovalOrigin(origin, type); | ||
this._addToStore(id, origin, type, requestData); | ||
this._addToStore(id, origin, type, requestData, requestState); | ||
}); | ||
@@ -276,4 +296,5 @@ } | ||
* @param requestData - The request data associated with the approval request. | ||
* @param requestState - The request state associated with the approval request. | ||
*/ | ||
_validateAddParams(id, origin, type, requestData) { | ||
_validateAddParams(id, origin, type, requestData, requestState) { | ||
let errorMessage = null; | ||
@@ -296,2 +317,6 @@ if (!id || typeof id !== 'string') { | ||
} | ||
else if (requestState && | ||
(typeof requestState !== 'object' || Array.isArray(requestState))) { | ||
errorMessage = 'Request state must be a plain object if specified.'; | ||
} | ||
if (errorMessage) { | ||
@@ -323,4 +348,5 @@ throw eth_rpc_errors_1.ethErrors.rpc.internal(errorMessage); | ||
* @param requestData - The request data associated with the approval request. | ||
* @param requestState - The request state associated with the approval request. | ||
*/ | ||
_addToStore(id, origin, type, requestData) { | ||
_addToStore(id, origin, type, requestData, requestState) { | ||
const approval = { | ||
@@ -332,2 +358,3 @@ id, | ||
requestData: requestData || null, | ||
requestState: requestState || null, | ||
}; | ||
@@ -334,0 +361,0 @@ this.update((draftState) => { |
{ | ||
"name": "@metamask/approval-controller", | ||
"version": "1.0.1", | ||
"version": "1.1.0", | ||
"description": "Manages requests that require user approval", | ||
@@ -9,9 +9,9 @@ "keywords": [ | ||
], | ||
"homepage": "https://github.com/MetaMask/controllers/tree/main/packages/approval-controller#readme", | ||
"homepage": "https://github.com/MetaMask/core/tree/main/packages/approval-controller#readme", | ||
"bugs": { | ||
"url": "https://github.com/MetaMask/controllers/issues" | ||
"url": "https://github.com/MetaMask/core/issues" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/MetaMask/controllers.git" | ||
"url": "https://github.com/MetaMask/core.git" | ||
}, | ||
@@ -33,4 +33,4 @@ "license": "MIT", | ||
"dependencies": { | ||
"@metamask/base-controller": "^1.1.1", | ||
"@metamask/controller-utils": "^1.0.0", | ||
"@metamask/base-controller": "^1.1.2", | ||
"@metamask/controller-utils": "^2.0.0", | ||
"eth-rpc-errors": "^4.0.0", | ||
@@ -37,0 +37,0 @@ "immer": "^9.0.6", |
@@ -15,2 +15,2 @@ # `@metamask/approval-controller` | ||
This package is part of a monorepo. Instructions for contributing can be found in the [monorepo README](https://github.com/MetaMask/controllers#readme). | ||
This package is part of a monorepo. Instructions for contributing can be found in the [monorepo README](https://github.com/MetaMask/core#readme). |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
63732
744
- Removed@metamask/controller-utils@1.0.0(transitive)