commit
4f00a014d0
@ -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
|
||||||
|
@ -1,15 +1,22 @@
|
|||||||
import { useModalSearchParams } from '@/hooks/useModalSearchParams'
|
import { useModalSearchParams } from '@/hooks/useModalSearchParams'
|
||||||
import { Modal } from '@/shared/Modal/Modal'
|
import { Modal } from '@/shared/Modal/Modal'
|
||||||
import { MODAL_PARAMS_KEYS } from '@/types/modal'
|
import { MODAL_PARAMS_KEYS } from '@/types/modal'
|
||||||
import { askNotificationPermission, call, getAppIconTitle, getDomain, getReferrerAppUrl, getShortenNpub } from '@/utils/helpers/helpers'
|
import {
|
||||||
|
askNotificationPermission,
|
||||||
|
call,
|
||||||
|
getAppIconTitle,
|
||||||
|
getDomain,
|
||||||
|
getReferrerAppUrl,
|
||||||
|
getShortenNpub,
|
||||||
|
} from '@/utils/helpers/helpers'
|
||||||
import { Avatar, Box, Stack, Typography } from '@mui/material'
|
import { Avatar, Box, Stack, Typography } from '@mui/material'
|
||||||
import { useNavigate, useParams, useSearchParams } from 'react-router-dom'
|
import { useNavigate, useParams, useSearchParams } from 'react-router-dom'
|
||||||
import { useAppSelector } from '@/store/hooks/redux'
|
import { useAppSelector } from '@/store/hooks/redux'
|
||||||
import { selectAppsByNpub, selectKeys, selectPendingsByNpub } from '@/store'
|
import { selectAppsByNpub, selectKeys, selectPendingsByNpub } from '@/store'
|
||||||
import { StyledButton, StyledToggleButtonsGroup } from './styled'
|
import { StyledButton, StyledToggleButtonsGroup } from './styled'
|
||||||
import { ActionToggleButton } from './сomponents/ActionToggleButton'
|
import { ActionToggleButton } from './сomponents/ActionToggleButton'
|
||||||
import { useState } from 'react'
|
import { useEffect, useState } from 'react'
|
||||||
import { swicCall } from '@/modules/swic'
|
import { swicCall, swicWaitStarted } from '@/modules/swic'
|
||||||
import { ACTION_TYPE } from '@/utils/consts'
|
import { ACTION_TYPE } from '@/utils/consts'
|
||||||
import { useEnqueueSnackbar } from '@/hooks/useEnqueueSnackbar'
|
import { useEnqueueSnackbar } from '@/hooks/useEnqueueSnackbar'
|
||||||
|
|
||||||
@ -28,6 +35,7 @@ export const ModalConfirmConnect = () => {
|
|||||||
const pending = useAppSelector((state) => selectPendingsByNpub(state, npub))
|
const pending = useAppSelector((state) => selectPendingsByNpub(state, npub))
|
||||||
|
|
||||||
const [selectedActionType, setSelectedActionType] = useState<ACTION_TYPE>(ACTION_TYPE.BASIC)
|
const [selectedActionType, setSelectedActionType] = useState<ACTION_TYPE>(ACTION_TYPE.BASIC)
|
||||||
|
const [isLoaded, setIsLoaded] = useState(false)
|
||||||
|
|
||||||
const appNpub = searchParams.get('appNpub') || ''
|
const appNpub = searchParams.get('appNpub') || ''
|
||||||
const pendingReqId = searchParams.get('reqId') || ''
|
const pendingReqId = searchParams.get('reqId') || ''
|
||||||
@ -37,7 +45,7 @@ export const ModalConfirmConnect = () => {
|
|||||||
const triggerApp = apps.find((app) => app.appNpub === appNpub)
|
const triggerApp = apps.find((app) => app.appNpub === appNpub)
|
||||||
const { name, url = '', icon = '' } = triggerApp || {}
|
const { name, url = '', icon = '' } = triggerApp || {}
|
||||||
|
|
||||||
const appUrl = url || searchParams.get('appUrl') || getReferrerAppUrl();
|
const appUrl = url || searchParams.get('appUrl') || getReferrerAppUrl()
|
||||||
const appDomain = getDomain(appUrl)
|
const appDomain = getDomain(appUrl)
|
||||||
const appName = name || appDomain || getShortenNpub(appNpub)
|
const appName = name || appDomain || getShortenNpub(appNpub)
|
||||||
const appAvatarTitle = getAppIconTitle(name || appDomain, appNpub)
|
const appAvatarTitle = getAppIconTitle(name || appDomain, appNpub)
|
||||||
@ -53,14 +61,44 @@ export const ModalConfirmConnect = () => {
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
const isNpubExists = npub.trim().length && keys.some((key) => key.npub === npub)
|
// NOTE: when opened directly to this modal using authUrl,
|
||||||
// App doesn't exist yet!
|
// we might not have pending requests visible yet bcs we haven't
|
||||||
// const isAppNpubExists = appNpub.trim().length && apps.some((app) => app.appNpub === appNpub)
|
// loaded them yet, which means this modal will be closed with
|
||||||
const isPendingReqIdExists = pendingReqId.trim().length && pending.some((p) => p.id === pendingReqId)
|
// the logic below. So now if it's popup then we wait for SW
|
||||||
// console.log("pending", {isModalOpened, isPendingReqIdExists, isNpubExists, /*isAppNpubExists,*/ pendingReqId, pending});
|
// and then wait a little more to give it time to fetch
|
||||||
if (!isPopup && isModalOpened && (!isNpubExists /*|| !isAppNpubExists*/ || (pendingReqId && !isPendingReqIdExists))) {
|
// pending reqs from db. Same logic implemented in confirm-event.
|
||||||
closeModalAfterRequest()
|
|
||||||
return null
|
// 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 {
|
||||||
|
setIsLoaded(true)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
setIsLoaded(false)
|
||||||
|
}
|
||||||
|
}, [isModalOpened, isPopup])
|
||||||
|
|
||||||
|
if (isLoaded) {
|
||||||
|
const isNpubExists = npub.trim().length && keys.some((key) => key.npub === npub)
|
||||||
|
// NOTE: app doesn't exist yet!
|
||||||
|
// const isAppNpubExists = appNpub.trim().length && apps.some((app) => app.appNpub === appNpub)
|
||||||
|
const isPendingReqIdExists = pendingReqId.trim().length && pending.some((p) => p.id === pendingReqId)
|
||||||
|
// console.log("pending", {isModalOpened, isPendingReqIdExists, isNpubExists, /*isAppNpubExists,*/ pendingReqId, pending});
|
||||||
|
if (isModalOpened && (!isNpubExists /*|| !isAppNpubExists*/ || (pendingReqId && !isPendingReqIdExists))) {
|
||||||
|
if (isPopup) window.close()
|
||||||
|
else closeModalAfterRequest()
|
||||||
|
return null
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleActionTypeChange = (_: any, value: ACTION_TYPE | null) => {
|
const handleActionTypeChange = (_: any, value: ACTION_TYPE | null) => {
|
||||||
@ -179,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
|
||||||
|
@ -10,7 +10,7 @@ import { ActionToggleButton } from './сomponents/ActionToggleButton'
|
|||||||
import { FC, useEffect, useMemo, useState } from 'react'
|
import { FC, useEffect, useMemo, useState } from 'react'
|
||||||
import { StyledActionsListContainer, StyledButton, StyledToggleButtonsGroup } from './styled'
|
import { StyledActionsListContainer, StyledButton, StyledToggleButtonsGroup } from './styled'
|
||||||
import { SectionTitle } from '@/shared/SectionTitle/SectionTitle'
|
import { SectionTitle } from '@/shared/SectionTitle/SectionTitle'
|
||||||
import { swicCall } from '@/modules/swic'
|
import { swicCall, swicWaitStarted } from '@/modules/swic'
|
||||||
import { Checkbox } from '@/shared/Checkbox/Checkbox'
|
import { Checkbox } from '@/shared/Checkbox/Checkbox'
|
||||||
import { DbPending } from '@/modules/db'
|
import { DbPending } from '@/modules/db'
|
||||||
import { IPendingsByAppNpub } from '@/pages/KeyPage/hooks/useTriggerConfirmModal'
|
import { IPendingsByAppNpub } from '@/pages/KeyPage/hooks/useTriggerConfirmModal'
|
||||||
@ -47,6 +47,7 @@ export const ModalConfirmEvent: FC<ModalConfirmEventProps> = ({ confirmEventReqs
|
|||||||
|
|
||||||
const [selectedActionType, setSelectedActionType] = useState<ACTION_TYPE>(ACTION_TYPE.ALWAYS)
|
const [selectedActionType, setSelectedActionType] = useState<ACTION_TYPE>(ACTION_TYPE.ALWAYS)
|
||||||
const [pendingRequests, setPendingRequests] = useState<PendingRequest[]>([])
|
const [pendingRequests, setPendingRequests] = useState<PendingRequest[]>([])
|
||||||
|
const [isLoaded, setIsLoaded] = useState(false)
|
||||||
|
|
||||||
const currentAppPendingReqs = useMemo(() => confirmEventReqs[appNpub]?.pending || [], [confirmEventReqs, appNpub])
|
const currentAppPendingReqs = useMemo(() => confirmEventReqs[appNpub]?.pending || [], [confirmEventReqs, appNpub])
|
||||||
|
|
||||||
@ -61,25 +62,31 @@ export const ModalConfirmEvent: FC<ModalConfirmEventProps> = ({ confirmEventReqs
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
// FIXME: when opened directly to this modal using authUrl,
|
useEffect(() => {
|
||||||
// we might not have pending requests visible yet bcs we haven't
|
if (isModalOpened) {
|
||||||
// loaded them yet, which means this modal will be closed with
|
if (isPopup) {
|
||||||
// the login below. It's fine if only one app has sent pending
|
// wait for SW to start
|
||||||
// requests atm, bcs the modal would re-appear as soon as we load
|
swicWaitStarted().then(() => {
|
||||||
// the requests. But if there are several pending reqs from other
|
// give it some time to load the pending reqs etc
|
||||||
// apps then popup might show a different one! Which is very
|
setTimeout(() => setIsLoaded(true), 500)
|
||||||
// contrary to what user expects. So:
|
})
|
||||||
// - if isPopup - dont close the modal with logic below
|
} else {
|
||||||
// - show some 'loading' indicator until we've got some requests
|
setIsLoaded(true)
|
||||||
// for the specified appNpub
|
}
|
||||||
// FIXME is the same logic valid for Connect modal?
|
} else {
|
||||||
|
setIsLoaded(false)
|
||||||
|
}
|
||||||
|
}, [isModalOpened, isPopup])
|
||||||
|
|
||||||
const isNpubExists = npub.trim().length && keys.some((key) => key.npub === npub)
|
if (isLoaded) {
|
||||||
const isAppNpubExists = appNpub.trim().length && apps.some((app) => app.appNpub === appNpub)
|
const isNpubExists = npub.trim().length && keys.some((key) => key.npub === npub)
|
||||||
// console.log("confirm event", { confirmEventReqs, isModalOpened, isNpubExists, isAppNpubExists });
|
const isAppNpubExists = appNpub.trim().length && apps.some((app) => app.appNpub === appNpub)
|
||||||
if (isModalOpened && (!currentAppPendingReqs.length || !isNpubExists || !isAppNpubExists)) {
|
// console.log("confirm event", { confirmEventReqs, isModalOpened, isNpubExists, isAppNpubExists });
|
||||||
closeModalAfterRequest()
|
if (isModalOpened && (!currentAppPendingReqs.length || !isNpubExists || !isAppNpubExists)) {
|
||||||
return null
|
if (isPopup) window.close()
|
||||||
|
else closeModalAfterRequest()
|
||||||
|
return null
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const triggerApp = apps.find((app) => app.appNpub === appNpub)
|
const triggerApp = apps.find((app) => app.appNpub === appNpub)
|
||||||
|
@ -1,14 +1,30 @@
|
|||||||
|
// import { useEffect } from 'react'
|
||||||
import { useModalSearchParams } from '@/hooks/useModalSearchParams'
|
import { useModalSearchParams } from '@/hooks/useModalSearchParams'
|
||||||
import { Button } from '@/shared/Button/Button'
|
import { Button } from '@/shared/Button/Button'
|
||||||
import { Modal } from '@/shared/Modal/Modal'
|
import { Modal } from '@/shared/Modal/Modal'
|
||||||
import { MODAL_PARAMS_KEYS } from '@/types/modal'
|
import { MODAL_PARAMS_KEYS } from '@/types/modal'
|
||||||
import { Stack } from '@mui/material'
|
import { Stack } from '@mui/material'
|
||||||
|
// import { AppLink } from '@/shared/AppLink/AppLink'
|
||||||
|
|
||||||
export const ModalInitial = () => {
|
export const ModalInitial = () => {
|
||||||
const { getModalOpened, createHandleCloseReplace, handleOpen } = useModalSearchParams()
|
const { getModalOpened, createHandleCloseReplace, handleOpen } = useModalSearchParams()
|
||||||
const isModalOpened = getModalOpened(MODAL_PARAMS_KEYS.INITIAL)
|
const isModalOpened = getModalOpened(MODAL_PARAMS_KEYS.INITIAL)
|
||||||
const handleCloseModal = createHandleCloseReplace(MODAL_PARAMS_KEYS.INITIAL)
|
const handleCloseModal = createHandleCloseReplace(MODAL_PARAMS_KEYS.INITIAL)
|
||||||
|
|
||||||
|
// const [showAdvancedContent, setShowAdvancedContent] = useState(false)
|
||||||
|
|
||||||
|
// const handleShowAdvanced = () => {
|
||||||
|
// setShowAdvancedContent(true)
|
||||||
|
// }
|
||||||
|
|
||||||
|
// useEffect(() => {
|
||||||
|
// return () => {
|
||||||
|
// if (isModalOpened) {
|
||||||
|
// setShowAdvancedContent(false)
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }, [isModalOpened])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Modal open={isModalOpened} onClose={handleCloseModal}>
|
<Modal open={isModalOpened} onClose={handleCloseModal}>
|
||||||
<Stack paddingTop={'0.5rem'} gap={'1rem'}>
|
<Stack paddingTop={'0.5rem'} gap={'1rem'}>
|
||||||
|
@ -107,7 +107,7 @@ export const ModalLogin = () => {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, [searchParams, isModalOpened, setValue])
|
}, [searchParams, isModalOpened, isPopup, setValue])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
return () => {
|
return () => {
|
||||||
|
@ -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 })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,6 +7,9 @@ import NDK, {
|
|||||||
NDKNip46Backend,
|
NDKNip46Backend,
|
||||||
NDKPrivateKeySigner,
|
NDKPrivateKeySigner,
|
||||||
NDKSigner,
|
NDKSigner,
|
||||||
|
NDKSubscription,
|
||||||
|
NDKSubscriptionCacheUsage,
|
||||||
|
NDKUser,
|
||||||
} from '@nostr-dev-kit/ndk'
|
} from '@nostr-dev-kit/ndk'
|
||||||
import { NOAUTHD_URL, WEB_PUSH_PUBKEY, NIP46_RELAYS, MIN_POW, MAX_POW, KIND_RPC, DOMAIN } from '../utils/consts'
|
import { NOAUTHD_URL, WEB_PUSH_PUBKEY, NIP46_RELAYS, MIN_POW, MAX_POW, KIND_RPC, DOMAIN } from '../utils/consts'
|
||||||
import { Nip04 } from './nip04'
|
import { Nip04 } from './nip04'
|
||||||
@ -28,6 +31,7 @@ interface Key {
|
|||||||
backoff: number
|
backoff: number
|
||||||
signer: NDKSigner
|
signer: NDKSigner
|
||||||
backend: NDKNip46Backend
|
backend: NDKNip46Backend
|
||||||
|
watcher: Watcher
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Pending {
|
interface Pending {
|
||||||
@ -46,6 +50,46 @@ interface IAllowCallbackParams {
|
|||||||
params?: any
|
params?: any
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class Watcher {
|
||||||
|
private ndk: NDK
|
||||||
|
private signer: NDKSigner
|
||||||
|
private onReply: (id: string) => void
|
||||||
|
private sub?: NDKSubscription
|
||||||
|
|
||||||
|
constructor(ndk: NDK, signer: NDKSigner, onReply: (id: string) => void) {
|
||||||
|
this.ndk = ndk
|
||||||
|
this.signer = signer
|
||||||
|
this.onReply = onReply
|
||||||
|
}
|
||||||
|
|
||||||
|
async start() {
|
||||||
|
this.sub = this.ndk.subscribe({
|
||||||
|
kinds: [KIND_RPC],
|
||||||
|
authors: [(await this.signer.user()).pubkey],
|
||||||
|
since: Math.floor((Date.now() / 1000) - 10),
|
||||||
|
}, {
|
||||||
|
closeOnEose: false,
|
||||||
|
cacheUsage: NDKSubscriptionCacheUsage.ONLY_RELAY
|
||||||
|
})
|
||||||
|
this.sub.on('event', async (e: NDKEvent) => {
|
||||||
|
const peer = e.tags.find(t => t.length >= 2 && t[0] === "p")
|
||||||
|
console.log("watcher got event", { e, peer })
|
||||||
|
if (!peer) return
|
||||||
|
const decryptedContent = await this.signer.decrypt(
|
||||||
|
new NDKUser({ pubkey: peer[1] }), e.content);
|
||||||
|
const parsedContent = JSON.parse(decryptedContent);
|
||||||
|
const { id, method, params, result, error } = parsedContent;
|
||||||
|
console.log("watcher got", { peer, id, method, params, result, error })
|
||||||
|
if (method || result === 'auth_url') return
|
||||||
|
this.onReply(id)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
stop() {
|
||||||
|
this.sub!.stop()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class Nip46Backend extends NDKNip46Backend {
|
class Nip46Backend extends NDKNip46Backend {
|
||||||
public async processEvent(event: NDKEvent) {
|
public async processEvent(event: NDKEvent) {
|
||||||
this.handleIncomingEvent(event)
|
this.handleIncomingEvent(event)
|
||||||
@ -784,7 +828,11 @@ export class NoauthBackend {
|
|||||||
|
|
||||||
const signer = new NDKPrivateKeySigner(sk) // PrivateKeySigner
|
const signer = new NDKPrivateKeySigner(sk) // PrivateKeySigner
|
||||||
const backend = new Nip46Backend(ndk, signer, () => Promise.resolve(true))
|
const backend = new Nip46Backend(ndk, signer, () => Promise.resolve(true))
|
||||||
this.keys.push({ npub, backend, signer, ndk, backoff })
|
const watcher = new Watcher(ndk, signer, (id) => {
|
||||||
|
// drop pending request
|
||||||
|
dbi.removePending(id).then(() => this.updateUI())
|
||||||
|
})
|
||||||
|
this.keys.push({ npub, backend, signer, ndk, backoff, watcher })
|
||||||
|
|
||||||
// new method
|
// new method
|
||||||
backend.handlers['get_nip04_key'] = new Nip04KeyHandlingStrategy(sk)
|
backend.handlers['get_nip04_key'] = new Nip04KeyHandlingStrategy(sk)
|
||||||
@ -802,6 +850,7 @@ export class NoauthBackend {
|
|||||||
|
|
||||||
// start
|
// start
|
||||||
backend.start()
|
backend.start()
|
||||||
|
watcher.start()
|
||||||
console.log('started', npub)
|
console.log('started', npub)
|
||||||
|
|
||||||
// backoff reset on successfull connection
|
// backoff reset on successfull connection
|
||||||
@ -825,11 +874,13 @@ export class NoauthBackend {
|
|||||||
const bo = self.keys.find((k) => k.npub === npub)?.backoff || 1000
|
const bo = self.keys.find((k) => k.npub === npub)?.backoff || 1000
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
console.log(new Date(), 'reconnect relays for key', npub, 'backoff', bo)
|
console.log(new Date(), 'reconnect relays for key', npub, 'backoff', bo)
|
||||||
// @ts-ignore
|
|
||||||
for (const r of ndk.pool.relays.values()) r.disconnect()
|
for (const r of ndk.pool.relays.values()) r.disconnect()
|
||||||
// make sure it no longer activates
|
// make sure it no longer activates
|
||||||
backend.handlers = {}
|
backend.handlers = {}
|
||||||
|
|
||||||
|
// stop watching
|
||||||
|
watcher.stop()
|
||||||
|
|
||||||
self.keys = self.keys.filter((k) => k.npub !== npub)
|
self.keys = self.keys.filter((k) => k.npub !== npub)
|
||||||
self.startKey({ npub, sk, backoff: Math.min(bo * 2, 60000) })
|
self.startKey({ npub, sk, backoff: Math.min(bo * 2, 60000) })
|
||||||
}, bo)
|
}, bo)
|
||||||
|
@ -5,7 +5,7 @@ export let swr: ServiceWorkerRegistration | null = null
|
|||||||
const reqs = new Map<number, { ok: (r: any) => void; rej: (r: any) => void }>()
|
const reqs = new Map<number, { ok: (r: any) => void; rej: (r: any) => void }>()
|
||||||
let nextReqId = 1
|
let nextReqId = 1
|
||||||
let onRender: (() => void) | null = null
|
let onRender: (() => void) | null = null
|
||||||
const queue: (() => Promise<void>)[] = []
|
const queue: (() => Promise<void> | void)[] = []
|
||||||
|
|
||||||
export async function swicRegister() {
|
export async function swicRegister() {
|
||||||
serviceWorkerRegistration.register({
|
serviceWorkerRegistration.register({
|
||||||
@ -36,6 +36,13 @@ export async function swicRegister() {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function swicWaitStarted() {
|
||||||
|
return new Promise<void>(ok => {
|
||||||
|
if (swr && swr.active) ok()
|
||||||
|
else queue.push(ok)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
function onMessage(data: any) {
|
function onMessage(data: any) {
|
||||||
const { id, result, error } = data
|
const { id, result, error } = data
|
||||||
console.log('SW message', id, result, error)
|
console.log('SW message', id, result, error)
|
||||||
|
@ -6,7 +6,6 @@ import { formatTimestampDate } from '@/utils/helpers/date'
|
|||||||
import ClearRoundedIcon from '@mui/icons-material/ClearRounded'
|
import ClearRoundedIcon from '@mui/icons-material/ClearRounded'
|
||||||
import DoneRoundedIcon from '@mui/icons-material/DoneRounded'
|
import DoneRoundedIcon from '@mui/icons-material/DoneRounded'
|
||||||
import MoreVertRoundedIcon from '@mui/icons-material/MoreVertRounded'
|
import MoreVertRoundedIcon from '@mui/icons-material/MoreVertRounded'
|
||||||
import { ACTIONS } from '@/utils/consts'
|
|
||||||
import { getReqActionName } from '@/utils/helpers/helpers'
|
import { getReqActionName } from '@/utils/helpers/helpers'
|
||||||
|
|
||||||
type ItemActivityProps = DbHistory
|
type ItemActivityProps = DbHistory
|
||||||
|
@ -121,7 +121,7 @@ export const getDomain = (url: string) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const getReferrerAppUrl = () => {
|
export const getReferrerAppUrl = () => {
|
||||||
console.log('referrer', window.document.referrer)
|
// console.log('referrer', window.document.referrer)
|
||||||
if (!window.document.referrer) return ''
|
if (!window.document.referrer) return ''
|
||||||
try {
|
try {
|
||||||
const u = new URL(window.document.referrer.toLocaleLowerCase())
|
const u = new URL(window.document.referrer.toLocaleLowerCase())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user