Merge pull request #64 from nostrband/develop
Fix - close confirm event popup after confirmed
This commit is contained in:
@@ -57,7 +57,7 @@ export const ModalConfirmConnect = () => {
|
|||||||
// App doesn't exist yet!
|
// App doesn't exist yet!
|
||||||
// const isAppNpubExists = appNpub.trim().length && apps.some((app) => app.appNpub === appNpub)
|
// const isAppNpubExists = appNpub.trim().length && apps.some((app) => app.appNpub === appNpub)
|
||||||
const isPendingReqIdExists = pendingReqId.trim().length && pending.some((p) => p.id === pendingReqId)
|
const isPendingReqIdExists = pendingReqId.trim().length && pending.some((p) => p.id === pendingReqId)
|
||||||
console.log("pending", {isModalOpened, isPendingReqIdExists, isNpubExists, /*isAppNpubExists,*/ pendingReqId, pending});
|
// console.log("pending", {isModalOpened, isPendingReqIdExists, isNpubExists, /*isAppNpubExists,*/ pendingReqId, pending});
|
||||||
if (!isPopup && isModalOpened && (!isNpubExists /*|| !isAppNpubExists*/ || (pendingReqId && !isPendingReqIdExists))) {
|
if (!isPopup && isModalOpened && (!isNpubExists /*|| !isAppNpubExists*/ || (pendingReqId && !isPendingReqIdExists))) {
|
||||||
closeModalAfterRequest()
|
closeModalAfterRequest()
|
||||||
return null
|
return null
|
||||||
|
@@ -61,10 +61,23 @@ export const ModalConfirmEvent: FC<ModalConfirmEventProps> = ({ confirmEventReqs
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// FIXME: when opened directly to this modal using authUrl,
|
||||||
|
// we might not have pending requests visible yet bcs we haven't
|
||||||
|
// loaded them yet, which means this modal will be closed with
|
||||||
|
// the login below. It's fine if only one app has sent pending
|
||||||
|
// requests atm, bcs the modal would re-appear as soon as we load
|
||||||
|
// the requests. But if there are several pending reqs from other
|
||||||
|
// apps then popup might show a different one! Which is very
|
||||||
|
// contrary to what user expects. So:
|
||||||
|
// - if isPopup - dont close the modal with logic below
|
||||||
|
// - show some 'loading' indicator until we've got some requests
|
||||||
|
// for the specified appNpub
|
||||||
|
// FIXME is the same logic valid for Connect modal?
|
||||||
|
|
||||||
const isNpubExists = npub.trim().length && keys.some((key) => key.npub === npub)
|
const isNpubExists = npub.trim().length && keys.some((key) => key.npub === npub)
|
||||||
const isAppNpubExists = appNpub.trim().length && apps.some((app) => app.appNpub === appNpub)
|
const isAppNpubExists = appNpub.trim().length && apps.some((app) => app.appNpub === appNpub)
|
||||||
|
// console.log("confirm event", { confirmEventReqs, isModalOpened, isNpubExists, isAppNpubExists });
|
||||||
if (isModalOpened && (!isNpubExists || !isAppNpubExists)) {
|
if (isModalOpened && (!currentAppPendingReqs.length || !isNpubExists || !isAppNpubExists)) {
|
||||||
closeModalAfterRequest()
|
closeModalAfterRequest()
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
@@ -743,9 +743,9 @@ export class NoauthBackend {
|
|||||||
})
|
})
|
||||||
|
|
||||||
// OAuth flow
|
// OAuth flow
|
||||||
const confirmMethod = method === 'connect' ? 'confirm-connect' : 'confirm-event'
|
const isConnect = method === 'connect'
|
||||||
|
const confirmMethod = isConnect ? 'confirm-connect' : 'confirm-event'
|
||||||
const authUrl = `${self.swg.location.origin}/key/${npub}?${confirmMethod}=true&appNpub=${appNpub}&reqId=${id}&popup=true`
|
const authUrl = `${self.swg.location.origin}/key/${npub}?${confirmMethod}=true&appNpub=${appNpub}&reqId=${id}&popup=true`
|
||||||
// const authUrl = `${self.swg.location.origin}/key/${npub}?popup=true`
|
|
||||||
console.log('sending authUrl', authUrl, 'for', req)
|
console.log('sending authUrl', authUrl, 'for', req)
|
||||||
// NOTE: if you set 'Update on reload' in the Chrome SW console
|
// NOTE: if you set 'Update on reload' in the Chrome SW console
|
||||||
// then this message will cause a new tab opened by the peer,
|
// then this message will cause a new tab opened by the peer,
|
||||||
|
@@ -3,6 +3,7 @@ import { DbPending, DbPerm } from '@/modules/db'
|
|||||||
import { MODAL_PARAMS_KEYS } from '@/types/modal'
|
import { MODAL_PARAMS_KEYS } from '@/types/modal'
|
||||||
import { ACTION_TYPE } from '@/utils/consts'
|
import { ACTION_TYPE } from '@/utils/consts'
|
||||||
import { useCallback, useEffect, useRef } from 'react'
|
import { useCallback, useEffect, useRef } from 'react'
|
||||||
|
import { useSearchParams } from 'react-router-dom'
|
||||||
|
|
||||||
export type IPendingsByAppNpub = {
|
export type IPendingsByAppNpub = {
|
||||||
[appNpub: string]: {
|
[appNpub: string]: {
|
||||||
@@ -18,6 +19,9 @@ type IShownConfirmModals = {
|
|||||||
export const useTriggerConfirmModal = (npub: string, pending: DbPending[], perms: DbPerm[]) => {
|
export const useTriggerConfirmModal = (npub: string, pending: DbPending[], perms: DbPerm[]) => {
|
||||||
const { handleOpen, getModalOpened } = useModalSearchParams()
|
const { handleOpen, getModalOpened } = useModalSearchParams()
|
||||||
|
|
||||||
|
const [searchParams] = useSearchParams()
|
||||||
|
const isPopup = searchParams.get('popup') === 'true'
|
||||||
|
|
||||||
const isConfirmConnectModalOpened = getModalOpened(MODAL_PARAMS_KEYS.CONFIRM_CONNECT)
|
const isConfirmConnectModalOpened = getModalOpened(MODAL_PARAMS_KEYS.CONFIRM_CONNECT)
|
||||||
const isConfirmEventModalOpened = getModalOpened(MODAL_PARAMS_KEYS.CONFIRM_EVENT)
|
const isConfirmEventModalOpened = getModalOpened(MODAL_PARAMS_KEYS.CONFIRM_EVENT)
|
||||||
|
|
||||||
@@ -66,6 +70,7 @@ export const useTriggerConfirmModal = (npub: string, pending: DbPending[], perms
|
|||||||
search: {
|
search: {
|
||||||
appNpub: req.appNpub,
|
appNpub: req.appNpub,
|
||||||
reqId: req.id,
|
reqId: req.id,
|
||||||
|
popup: isPopup ? 'true' : ''
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
break
|
break
|
||||||
@@ -86,6 +91,7 @@ export const useTriggerConfirmModal = (npub: string, pending: DbPending[], perms
|
|||||||
handleOpen(MODAL_PARAMS_KEYS.CONFIRM_EVENT, {
|
handleOpen(MODAL_PARAMS_KEYS.CONFIRM_EVENT, {
|
||||||
search: {
|
search: {
|
||||||
appNpub,
|
appNpub,
|
||||||
|
popup: isPopup ? 'true' : ''
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
break
|
break
|
||||||
|
Reference in New Issue
Block a user