Change perm sets, add 'basic' perm, fix disallow logic
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { useModalSearchParams } from '@/hooks/useModalSearchParams'
|
||||
import { Modal } from '@/shared/Modal/Modal'
|
||||
import { MODAL_PARAMS_KEYS } from '@/types/modal'
|
||||
import { call, getShortenNpub } from '@/utils/helpers'
|
||||
import { call, getShortenNpub, getSignReqKind } from '@/utils/helpers'
|
||||
import {
|
||||
Avatar,
|
||||
Box,
|
||||
@@ -47,6 +47,8 @@ type ModalConfirmEventProps = {
|
||||
export const ACTIONS: { [type: string]: string } = {
|
||||
get_public_key: 'Get public key',
|
||||
sign_event: 'Sign event',
|
||||
nip04_encrypt: 'Encrypt message',
|
||||
nip04_decrypt: 'Decrypt message',
|
||||
}
|
||||
|
||||
type PendingRequest = DbPending & { checked: boolean }
|
||||
@@ -109,12 +111,12 @@ export const ModalConfirmEvent: FC<ModalConfirmEventProps> = ({
|
||||
},
|
||||
)
|
||||
|
||||
async function confirmPending() {
|
||||
async function confirmPending(allow: boolean) {
|
||||
selectedPendingRequests.forEach((req) => {
|
||||
call(async () => {
|
||||
const remember = selectedActionType !== ACTION_TYPE.ONCE
|
||||
await swicCall('confirm', req.id, true, remember)
|
||||
console.log('confirmed', req.id, selectedActionType)
|
||||
await swicCall('confirm', req.id, allow, remember)
|
||||
console.log('confirmed', req.id, selectedActionType, allow)
|
||||
})
|
||||
})
|
||||
closeModalAfterRequest()
|
||||
@@ -128,6 +130,16 @@ export const ModalConfirmEvent: FC<ModalConfirmEventProps> = ({
|
||||
setPendingRequests(newPendingRequests)
|
||||
}
|
||||
|
||||
const getAction = (req: PendingRequest) => {
|
||||
const action = ACTIONS[req.method]
|
||||
if (req.method === 'sign_event') {
|
||||
const kind = getSignReqKind(req)
|
||||
if (kind !== undefined)
|
||||
return `${action} of kind ${kind}`
|
||||
}
|
||||
return action
|
||||
}
|
||||
|
||||
return (
|
||||
<Modal open={isModalOpened} onClose={handleCloseModal}>
|
||||
<Stack gap={'1rem'} paddingTop={'1rem'}>
|
||||
@@ -171,7 +183,7 @@ export const ModalConfirmEvent: FC<ModalConfirmEventProps> = ({
|
||||
/>
|
||||
</ListItemIcon>
|
||||
<ListItemText>
|
||||
{ACTIONS[req.method]}
|
||||
{getAction(req)}
|
||||
</ListItemText>
|
||||
</ListItem>
|
||||
)
|
||||
@@ -191,21 +203,21 @@ export const ModalConfirmEvent: FC<ModalConfirmEventProps> = ({
|
||||
value={ACTION_TYPE.ONCE}
|
||||
title='Just once'
|
||||
/>
|
||||
<ActionToggleButton
|
||||
{/* <ActionToggleButton
|
||||
value={ACTION_TYPE.ALLOW_ALL}
|
||||
title='Allow All Advanced Actions'
|
||||
hasinfo
|
||||
/>
|
||||
/> */}
|
||||
</StyledToggleButtonsGroup>
|
||||
|
||||
<Stack direction={'row'} gap={'1rem'}>
|
||||
<StyledButton
|
||||
onClick={handleCloseModal}
|
||||
onClick={() => confirmPending(false)}
|
||||
varianttype='secondary'
|
||||
>
|
||||
Cancel
|
||||
Disallow {ACTION_LABELS[selectedActionType]}
|
||||
</StyledButton>
|
||||
<StyledButton fullWidth onClick={confirmPending}>
|
||||
<StyledButton onClick={() => confirmPending(true)}>
|
||||
Allow {ACTION_LABELS[selectedActionType]}
|
||||
</StyledButton>
|
||||
</Stack>
|
||||
|
||||
Reference in New Issue
Block a user