Skip to content

Commit

Permalink
fixup! add perm activity log ui
Browse files Browse the repository at this point in the history
  • Loading branch information
rekmarks committed Sep 12, 2019
1 parent 163c214 commit 879ee72
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 23 deletions.
2 changes: 1 addition & 1 deletion app/scripts/controllers/permissions/index.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
module.exports = require('./permissions')
module.exports = require('./permissions')
3 changes: 2 additions & 1 deletion app/scripts/controllers/permissions/loggerMiddleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const LOG_LIMIT = 100
* permissions-related methods.
*/
module.exports = function createLoggerMiddleware ({
walletPrefix, restrictedMethods, store, storeKey
walletPrefix, restrictedMethods, store, storeKey,
}) {
return (req, res, next, _end) => {

Expand All @@ -30,6 +30,7 @@ module.exports = function createLoggerMiddleware ({
const entry = {
method: request.method,
methodType: isInternal ? 'internal' : 'restricted',
origin: request.origin,
request: cloneObj(request),
requestTime: Date.now(),
response: null,
Expand Down
2 changes: 1 addition & 1 deletion app/scripts/controllers/permissions/permissions.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class PermissionsController {
restoredState = {}) {
this.store = new ObservableStore({
[METADATA_STORE_KEY]: { ...restoredState[METADATA_STORE_KEY] },
[LOG_STORE_KEY]: restoredState[LOG_STORE_KEY] || []
[LOG_STORE_KEY]: restoredState[LOG_STORE_KEY] || [],
})
this._openPopup = openPopup
this._closePopup = closePopup
Expand Down
4 changes: 2 additions & 2 deletions app/scripts/controllers/permissions/requestMiddleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const { errors: rpcErrors } = require('eth-json-rpc-errors')
* Create middleware for preprocessing permissions requests.
*/
module.exports = function createRequestMiddleware ({
internalPrefix, store, storeKey
internalPrefix, store, storeKey,
}) {
return createAsyncMiddleware(async (req, res, next) => {

Expand All @@ -22,7 +22,7 @@ module.exports = function createRequestMiddleware ({
req.siteMetadata &&
typeof req.siteMetadata.name === 'string'
) {
store.updateState({
store.updateState({
[storeKey]: {
...store.getState()[storeKey],
[req.origin]: req.siteMetadata,
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { default } from './permissions-activity.component'
export { default } from './permissions-activity.component'
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,23 @@ export default class PermissionsLog extends Component {
{
permissionsLog.map((e, i) => {
const date = new Date(e.requestTime)
const dateString = date.toLocaleDateString()
const timeString = date.toLocaleTimeString(
[], {hour: '2-digit', minute: '2-digit'}
)
const methodName = (
e.method.startsWith('wallet_')
? e.method.split('wallet_')[1]
: e.method
)
return (
<li key={i}>
<details className="settings-page__content-list-details">
<summary>
{`${date.toLocaleDateString()} ${date.toLocaleTimeString()} | ${e.method}`}
{
`${dateString} ${timeString} | ` +
`${e.origin} | ${methodName}`
}
<i className="caret"></i>
</summary>
<ul>
Expand All @@ -58,11 +70,13 @@ export default class PermissionsLog extends Component {
e.method.endsWith('getPermissions') ||
e.method.endsWith('requestPermissions')
) {
if (e.response.result.length === 0) return (
<li className="settings-page__content-list-item">
{'[]'}
</li>
)
if (e.response.result.length === 0) {
return (
<li className="settings-page__content-list-item">
{'[]'}
</li>
)
}
return e.response.result.map(perm => (
<li
key={perm.parentCapability}
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { default } from './permissions-list.component'
export { default } from './permissions-list.component'
20 changes: 10 additions & 10 deletions ui/app/pages/settings/permissions-tab/permissions-tab.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,21 +67,21 @@ export default class PermissionsTab extends Component {
siteMetadata={this.props.siteMetadata}
/>
{
this.renderClearButton(
'clearPermissions',
this.props.showClearPermissionsModal,
!hasPermissions
)
this.renderClearButton(
'clearPermissions',
this.props.showClearPermissionsModal,
!hasPermissions
)
}
<PermissionsActivity
permissionsLog={this.props.permissionsLog}
/>
{
this.renderClearButton(
'clearPermissionsActivity',
this.props.showClearPermissionsActivityModal,
!hasPermissionsActivity
)
this.renderClearButton(
'clearPermissionsActivity',
this.props.showClearPermissionsActivityModal,
!hasPermissionsActivity
)
}
</div>
)
Expand Down

0 comments on commit 879ee72

Please sign in to comment.