Fix isLoading reset in popup confirms
This commit is contained in:
@@ -65,7 +65,7 @@ function App() {
|
||||
|
||||
useEffect(() => {
|
||||
ndk.connect().then(() => {
|
||||
console.log('NDK connected', { ndk })
|
||||
console.log('NDK connected')
|
||||
setIsConnected(true)
|
||||
})
|
||||
// eslint-disable-next-line
|
||||
|
||||
@@ -61,12 +61,23 @@ export const ModalConfirmConnect = () => {
|
||||
},
|
||||
})
|
||||
|
||||
// NOTE: 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 logic below. So now if it's popup then we wait for SW
|
||||
// and then wait a little more to give it time to fetch
|
||||
// pending reqs from db. Same logic implemented in confirm-event.
|
||||
|
||||
// FIXME move to a separate hook and reuse?
|
||||
|
||||
useEffect(() => {
|
||||
if (isModalOpened) {
|
||||
if (isPopup) {
|
||||
console.log("waiting for sw")
|
||||
// wait for SW to start
|
||||
swicWaitStarted().then(() => {
|
||||
// give it some time to load the pending reqs etc
|
||||
console.log("waiting for sw done")
|
||||
setTimeout(() => setIsLoaded(true), 500)
|
||||
})
|
||||
} else {
|
||||
@@ -75,7 +86,7 @@ export const ModalConfirmConnect = () => {
|
||||
} else {
|
||||
setIsLoaded(false)
|
||||
}
|
||||
}, [isModalOpened])
|
||||
}, [isModalOpened, isPopup])
|
||||
|
||||
if (isLoaded) {
|
||||
const isNpubExists = npub.trim().length && keys.some((key) => key.npub === npub)
|
||||
@@ -88,8 +99,6 @@ export const ModalConfirmConnect = () => {
|
||||
else closeModalAfterRequest()
|
||||
return null
|
||||
}
|
||||
// reset
|
||||
setIsLoaded(false)
|
||||
}
|
||||
|
||||
const handleActionTypeChange = (_: any, value: ACTION_TYPE | null) => {
|
||||
@@ -208,7 +217,7 @@ export const ModalConfirmConnect = () => {
|
||||
</StyledToggleButtonsGroup>
|
||||
<Stack direction={'row'} gap={'1rem'}>
|
||||
<StyledButton onClick={disallow} varianttype="secondary">
|
||||
Disallow
|
||||
Ignore
|
||||
</StyledButton>
|
||||
<StyledButton fullWidth onClick={allow}>
|
||||
Connect
|
||||
|
||||
@@ -76,20 +76,7 @@ export const ModalConfirmEvent: FC<ModalConfirmEventProps> = ({ confirmEventReqs
|
||||
} else {
|
||||
setIsLoaded(false)
|
||||
}
|
||||
}, [isModalOpened])
|
||||
|
||||
// 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 logic 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?
|
||||
}, [isModalOpened, isPopup])
|
||||
|
||||
if (isLoaded) {
|
||||
const isNpubExists = npub.trim().length && keys.some((key) => key.npub === npub)
|
||||
@@ -100,8 +87,6 @@ export const ModalConfirmEvent: FC<ModalConfirmEventProps> = ({ confirmEventReqs
|
||||
else closeModalAfterRequest()
|
||||
return null
|
||||
}
|
||||
// reset
|
||||
setIsLoaded(false)
|
||||
}
|
||||
|
||||
const triggerApp = apps.find((app) => app.appNpub === appNpub)
|
||||
|
||||
@@ -31,7 +31,7 @@ export const useModalSearchParams = () => {
|
||||
const enumKey = getEnumParam(modal)
|
||||
searchParams.delete(enumKey)
|
||||
extraOptions?.onClose && extraOptions?.onClose(searchParams)
|
||||
console.log({ searchParams })
|
||||
// console.log({ searchParams })
|
||||
setSearchParams(searchParams, { replace: !!extraOptions?.replace })
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user