Don't use referrer if it's our domain
This commit is contained in:
parent
45c39ca904
commit
e9b290db30
@ -1,7 +1,7 @@
|
||||
import { useModalSearchParams } from '@/hooks/useModalSearchParams'
|
||||
import { Modal } from '@/shared/Modal/Modal'
|
||||
import { MODAL_PARAMS_KEYS } from '@/types/modal'
|
||||
import { askNotificationPermission, call, getAppIconTitle, getDomain, 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 { useNavigate, useParams, useSearchParams } from 'react-router-dom'
|
||||
import { useAppSelector } from '@/store/hooks/redux'
|
||||
@ -37,15 +37,7 @@ export const ModalConfirmConnect = () => {
|
||||
const triggerApp = apps.find((app) => app.appNpub === appNpub)
|
||||
const { name, url = '', icon = '' } = triggerApp || {}
|
||||
|
||||
let appUrl = url || searchParams.get('appUrl') || ''
|
||||
console.log('referrer', window.document.referrer, appUrl)
|
||||
if (!appUrl && window.document.referrer) {
|
||||
try {
|
||||
const u = new URL(window.document.referrer)
|
||||
appUrl = u.origin
|
||||
} catch {}
|
||||
}
|
||||
|
||||
const appUrl = url || searchParams.get('appUrl') || getReferrerAppUrl();
|
||||
const appDomain = getDomain(appUrl)
|
||||
const appName = name || appDomain || getShortenNpub(appNpub)
|
||||
const appAvatarTitle = getAppIconTitle(name || appDomain, appNpub)
|
||||
|
@ -8,6 +8,7 @@ import { ModalConfirmConnect } from '@/components/Modal/ModalConfirmConnect/Moda
|
||||
import { useModalSearchParams } from '@/hooks/useModalSearchParams'
|
||||
import { MODAL_PARAMS_KEYS } from '@/types/modal'
|
||||
import { useState } from 'react'
|
||||
import { getReferrerAppUrl } from '@/utils/helpers/helpers'
|
||||
|
||||
const CreatePage = () => {
|
||||
const notify = useEnqueueSnackbar()
|
||||
@ -32,13 +33,7 @@ const CreatePage = () => {
|
||||
try {
|
||||
const key: any = await swicCall('generateKey', name)
|
||||
|
||||
let appUrl = ''
|
||||
if (window.document.referrer) {
|
||||
try {
|
||||
const u = new URL(window.document.referrer)
|
||||
appUrl = u.origin
|
||||
} catch {}
|
||||
}
|
||||
const appUrl = getReferrerAppUrl();
|
||||
|
||||
console.log('Created', key.npub, 'app', appUrl)
|
||||
setCreated(true)
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { nip19 } from 'nostr-tools'
|
||||
import { ACTIONS, ACTION_TYPE, NIP46_RELAYS } from '../consts'
|
||||
import { ACTIONS, ACTION_TYPE, DOMAIN, NIP46_RELAYS } from '../consts'
|
||||
import { DbPending, DbPerm } from '@/modules/db'
|
||||
import { MetaEvent } from '@/types/meta-event'
|
||||
|
||||
@ -105,6 +105,17 @@ export const getDomain = (url: string) => {
|
||||
}
|
||||
}
|
||||
|
||||
export const getReferrerAppUrl = () => {
|
||||
console.log('referrer', window.document.referrer)
|
||||
if (!window.document.referrer) return ''
|
||||
try {
|
||||
const u = new URL(window.document.referrer.toLocaleLowerCase())
|
||||
if (u.hostname != DOMAIN && !u.hostname.endsWith("."+DOMAIN))
|
||||
return u.origin
|
||||
} catch {}
|
||||
return ''
|
||||
}
|
||||
|
||||
export const getAppIconTitle = (name: string | undefined, appNpub: string) => {
|
||||
return name ? name[0].toLocaleUpperCase() : appNpub.substring(4, 7)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user