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