button to revoke permissions.
This commit is contained in:
@@ -81,3 +81,9 @@ export async function updatePermission(host, permission) {
|
||||
}
|
||||
browser.storage.local.set({permissions})
|
||||
}
|
||||
|
||||
export async function removePermissions(host) {
|
||||
let {permissions = {}} = await browser.storage.local.get('permissions')
|
||||
delete permissions[host]
|
||||
browser.storage.local.set({permissions})
|
||||
}
|
||||
|
||||
@@ -3,7 +3,11 @@ import React, {useState, useCallback, useEffect} from 'react'
|
||||
import {render} from 'react-dom'
|
||||
import {generatePrivateKey, nip19} from 'nostr-tools'
|
||||
|
||||
import {getPermissionsString, readPermissions} from './common'
|
||||
import {
|
||||
getPermissionsString,
|
||||
readPermissions,
|
||||
removePermissions
|
||||
} from './common'
|
||||
|
||||
function Options() {
|
||||
let [key, setKey] = useState('')
|
||||
@@ -34,18 +38,7 @@ function Options() {
|
||||
}, [])
|
||||
|
||||
useEffect(() => {
|
||||
readPermissions().then(permissions => {
|
||||
setPermissions(
|
||||
Object.entries(permissions).map(
|
||||
([host, {level, condition, created_at}]) => ({
|
||||
host,
|
||||
level,
|
||||
condition,
|
||||
created_at
|
||||
})
|
||||
)
|
||||
)
|
||||
})
|
||||
loadPermissions()
|
||||
}, [])
|
||||
|
||||
return (
|
||||
@@ -123,6 +116,7 @@ function Options() {
|
||||
<th>permissions</th>
|
||||
<th>condition</th>
|
||||
<th>since</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@@ -138,6 +132,11 @@ function Options() {
|
||||
.split('T')
|
||||
.join(' ')}
|
||||
</td>
|
||||
<td>
|
||||
<button onClick={handleRevoke} data-domain={host}>
|
||||
revoke
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
@@ -216,6 +215,31 @@ function Options() {
|
||||
setNewRelayURL('')
|
||||
}
|
||||
|
||||
async function handleRevoke(e) {
|
||||
e.preventDefault()
|
||||
let host = e.target.dataset.domain
|
||||
if (window.confirm(`revoke all permissions from ${host}?`)) {
|
||||
await removePermissions(host)
|
||||
showMessage(`removed permissions from ${host}`)
|
||||
loadPermissions()
|
||||
}
|
||||
}
|
||||
|
||||
function loadPermissions() {
|
||||
readPermissions().then(permissions => {
|
||||
setPermissions(
|
||||
Object.entries(permissions).map(
|
||||
([host, {level, condition, created_at}]) => ({
|
||||
host,
|
||||
level,
|
||||
condition,
|
||||
created_at
|
||||
})
|
||||
)
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
async function saveRelays() {
|
||||
await browser.storage.local.set({
|
||||
relays: Object.fromEntries(
|
||||
|
||||
Reference in New Issue
Block a user