Fix isLoading reset in popup confirms

This commit is contained in:
artur
2024-02-16 13:30:04 +03:00
parent 87ec23c737
commit 1e6bf8679c
4 changed files with 16 additions and 22 deletions

View File

@@ -65,7 +65,7 @@ function App() {
useEffect(() => { useEffect(() => {
ndk.connect().then(() => { ndk.connect().then(() => {
console.log('NDK connected', { ndk }) console.log('NDK connected')
setIsConnected(true) setIsConnected(true)
}) })
// eslint-disable-next-line // eslint-disable-next-line

View File

@@ -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(() => { useEffect(() => {
if (isModalOpened) { if (isModalOpened) {
if (isPopup) { if (isPopup) {
console.log("waiting for sw")
// wait for SW to start // wait for SW to start
swicWaitStarted().then(() => { swicWaitStarted().then(() => {
// give it some time to load the pending reqs etc // give it some time to load the pending reqs etc
console.log("waiting for sw done")
setTimeout(() => setIsLoaded(true), 500) setTimeout(() => setIsLoaded(true), 500)
}) })
} else { } else {
@@ -75,7 +86,7 @@ export const ModalConfirmConnect = () => {
} else { } else {
setIsLoaded(false) setIsLoaded(false)
} }
}, [isModalOpened]) }, [isModalOpened, isPopup])
if (isLoaded) { if (isLoaded) {
const isNpubExists = npub.trim().length && keys.some((key) => key.npub === npub) const isNpubExists = npub.trim().length && keys.some((key) => key.npub === npub)
@@ -88,8 +99,6 @@ export const ModalConfirmConnect = () => {
else closeModalAfterRequest() else closeModalAfterRequest()
return null return null
} }
// reset
setIsLoaded(false)
} }
const handleActionTypeChange = (_: any, value: ACTION_TYPE | null) => { const handleActionTypeChange = (_: any, value: ACTION_TYPE | null) => {
@@ -208,7 +217,7 @@ export const ModalConfirmConnect = () => {
</StyledToggleButtonsGroup> </StyledToggleButtonsGroup>
<Stack direction={'row'} gap={'1rem'}> <Stack direction={'row'} gap={'1rem'}>
<StyledButton onClick={disallow} varianttype="secondary"> <StyledButton onClick={disallow} varianttype="secondary">
Disallow Ignore
</StyledButton> </StyledButton>
<StyledButton fullWidth onClick={allow}> <StyledButton fullWidth onClick={allow}>
Connect Connect

View File

@@ -76,20 +76,7 @@ export const ModalConfirmEvent: FC<ModalConfirmEventProps> = ({ confirmEventReqs
} else { } else {
setIsLoaded(false) setIsLoaded(false)
} }
}, [isModalOpened]) }, [isModalOpened, isPopup])
// 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?
if (isLoaded) { if (isLoaded) {
const isNpubExists = npub.trim().length && keys.some((key) => key.npub === npub) const isNpubExists = npub.trim().length && keys.some((key) => key.npub === npub)
@@ -100,8 +87,6 @@ export const ModalConfirmEvent: FC<ModalConfirmEventProps> = ({ confirmEventReqs
else closeModalAfterRequest() else closeModalAfterRequest()
return null return null
} }
// reset
setIsLoaded(false)
} }
const triggerApp = apps.find((app) => app.appNpub === appNpub) const triggerApp = apps.find((app) => app.appNpub === appNpub)

View File

@@ -31,7 +31,7 @@ export const useModalSearchParams = () => {
const enumKey = getEnumParam(modal) const enumKey = getEnumParam(modal)
searchParams.delete(enumKey) searchParams.delete(enumKey)
extraOptions?.onClose && extraOptions?.onClose(searchParams) extraOptions?.onClose && extraOptions?.onClose(searchParams)
console.log({ searchParams }) // console.log({ searchParams })
setSearchParams(searchParams, { replace: !!extraOptions?.replace }) setSearchParams(searchParams, { replace: !!extraOptions?.replace })
} }