Skip to content

Commit

Permalink
feat: simplify permission log controller (#3662)
Browse files Browse the repository at this point in the history
## Explanation

Initially, I took the PermissionLogController from the extension and
converted it to TypeScript. During my work on this simplification task,
I realized that the primary functions in use are `createMiddleware`, for
logging permission activities and history, and `updateAccountsHistory`,
which is triggered on account changes. The controller also tracks two
state-level properties: `permissionHistory`, used on the extension's
permissions page, and `permissionActivityLog`, which is currently not in
use but retained for an upcoming feature. Additionally, the rest of the
functions in the PermissionLogController are private, serving as helper
functions.

## Changes

### Kept public
- `createMiddleware`.
- `updateAccountsHistory`.

### Changed to private
- `logRequest`: helper function only used within the controller.
- `logResponse`: helper function only used within the controller.
- `logPermissionsHistory`: helper function only used within the
controller.
- `commitNewHistory`: helper function only used within the controller.
- `getRequestedMethods`: helper function only used within the
controller.
- `getAccountsFromPermission`: helper function only used within the
controller.
- `getAccountToTimeMap`: included in the controller instead of outside
controller class as a private helper function.

### Removed
- `sinon` dependency: removed in favor of builtin jest fake timers.
- `getActivityLog`: originally returns the state of
permissionActivityLog, but now state can be accessed with state property
directly.
- `updateActivityLog`: originally updates the state for
permissionActivityLog, replaced by this.update already available on the
controller.
- `getHistory`: originally returns the state of PermissionHistory, but
now state can be accessed with state property directly
- `updateHistory`: originally updates the state for PermissionHistory,
replaced by this.update already available on the controller.


## References

* Fixes [#1824](#1824)

## Checklist

- [x] I've updated the test suite for new or updated code as appropriate
- [ ] I've updated documentation (JSDoc, Markdown, etc.) for new or
updated code as appropriate
- [ ] I've highlighted breaking changes using the "BREAKING" category
above as appropriate
  • Loading branch information
cryptodev-2s authored Dec 20, 2023
1 parent da6a302 commit 509e580
Show file tree
Hide file tree
Showing 4 changed files with 737 additions and 802 deletions.
1 change: 0 additions & 1 deletion packages/permission-log-controller/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
"deepmerge": "^4.2.2",
"jest": "^27.5.1",
"nanoid": "^3.1.31",
"sinon": "^9.2.4",
"ts-jest": "^27.1.4",
"typedoc": "^0.24.8",
"typedoc-plugin-missing-exports": "^2.0.0",
Expand Down
Loading

0 comments on commit 509e580

Please sign in to comment.