Extension login infinite loading #198

Merged
enes merged 13 commits from 196-ext-login-infinite-loading into staging 2024-09-16 12:27:44 +00:00
20 changed files with 248 additions and 461 deletions
Showing only changes of commit a53914b59d - Show all commits

View File

@ -37,7 +37,7 @@ import { setUserRobotImage } from '../../store/userRobotImage/action'
import { Container } from '../Container' import { Container } from '../Container'
import { ButtonIcon } from '../ButtonIcon' import { ButtonIcon } from '../ButtonIcon'
const metadataController = new MetadataController() const metadataController = MetadataController.getInstance()
export const AppBar = () => { export const AppBar = () => {
const navigate = useNavigate() const navigate = useNavigate()

View File

@ -1,7 +1,7 @@
import { Meta } from '../../types' import { Meta } from '../../types'
import { SigitCardDisplayInfo, SigitStatus, SignStatus } from '../../utils' import { SigitCardDisplayInfo, SigitStatus, SignStatus } from '../../utils'
import { Link } from 'react-router-dom' import { Link } from 'react-router-dom'
import { formatTimestamp, hexToNpub, npubToHex, shorten } from '../../utils' import { formatTimestamp, npubToHex } from '../../utils'
import { appPublicRoutes, appPrivateRoutes } from '../../routes' import { appPublicRoutes, appPrivateRoutes } from '../../routes'
import { Button, Divider, Tooltip } from '@mui/material' import { Button, Divider, Tooltip } from '@mui/material'
import { DisplaySigner } from '../DisplaySigner' import { DisplaySigner } from '../DisplaySigner'
@ -17,9 +17,7 @@ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
import { UserAvatarGroup } from '../UserAvatarGroup' import { UserAvatarGroup } from '../UserAvatarGroup'
import styles from './style.module.scss' import styles from './style.module.scss'
import { TooltipChild } from '../TooltipChild'
import { getExtensionIconLabel } from '../getExtensionIconLabel' import { getExtensionIconLabel } from '../getExtensionIconLabel'
import { useSigitProfiles } from '../../hooks/useSigitProfiles'
import { useSigitMeta } from '../../hooks/useSigitMeta' import { useSigitMeta } from '../../hooks/useSigitMeta'
import { extractFileExtensions } from '../../utils/file' import { extractFileExtensions } from '../../utils/file'
@ -33,12 +31,6 @@ export const DisplaySigit = ({ meta, parsedMeta }: SigitProps) => {
parsedMeta parsedMeta
const { signersStatus, fileHashes } = useSigitMeta(meta) const { signersStatus, fileHashes } = useSigitMeta(meta)
const profiles = useSigitProfiles([
...(submittedBy ? [submittedBy] : []),
...signers
])
const { extensions, isSame } = extractFileExtensions(Object.keys(fileHashes)) const { extensions, isSame } = extractFileExtensions(Object.keys(fileHashes))
return ( return (
@ -54,62 +46,29 @@ export const DisplaySigit = ({ meta, parsedMeta }: SigitProps) => {
></Link> ></Link>
<p className={`line-clamp-2 ${styles.title}`}>{title}</p> <p className={`line-clamp-2 ${styles.title}`}>{title}</p>
<div className={styles.users}> <div className={styles.users}>
{submittedBy && {submittedBy && (
(function () { <DisplaySigner
const profile = profiles[submittedBy] status={isValid ? SignStatus.Signed : SignStatus.Invalid}
return ( pubkey={submittedBy}
<Tooltip />
key={submittedBy} )}
title={
profile?.display_name ||
profile?.name ||
shorten(hexToNpub(submittedBy))
}
placement="top"
arrow
disableInteractive
>
<TooltipChild>
<DisplaySigner
status={isValid ? SignStatus.Signed : SignStatus.Invalid}
profile={profile}
pubkey={submittedBy}
/>
</TooltipChild>
</Tooltip>
)
})()}
{submittedBy && signers.length ? ( {submittedBy && signers.length ? (
<Divider orientation="vertical" flexItem /> <Divider orientation="vertical" flexItem />
) : null} ) : null}
<UserAvatarGroup max={7}> <UserAvatarGroup max={7}>
{signers.map((signer) => { {signers.map((signer) => {
const pubkey = npubToHex(signer)! const pubkey = npubToHex(signer)!
const profile = profiles[pubkey]
return ( return (
<Tooltip <DisplaySigner
key={signer} key={pubkey}
title={ status={signersStatus[signer]}
profile?.display_name || profile?.name || shorten(pubkey) pubkey={pubkey}
} />
placement="top"
arrow
disableInteractive
>
<TooltipChild>
<DisplaySigner
status={signersStatus[signer]}
profile={profile}
pubkey={pubkey}
/>
</TooltipChild>
</Tooltip>
) )
})} })}
</UserAvatarGroup> </UserAvatarGroup>
</div> </div>
<div className={`${styles.details} ${styles.date} ${styles.iconLabel}`}> <div className={`${styles.details} ${styles.iconLabel}`}>
<FontAwesomeIcon icon={faCalendar} /> <FontAwesomeIcon icon={faCalendar} />
{createdAt ? formatTimestamp(createdAt) : null} {createdAt ? formatTimestamp(createdAt) : null}
</div> </div>

View File

@ -1,5 +1,4 @@
import { Badge } from '@mui/material' import { Badge } from '@mui/material'
import { ProfileMetadata } from '../../types'
import styles from './style.module.scss' import styles from './style.module.scss'
import { UserAvatar } from '../UserAvatar' import { UserAvatar } from '../UserAvatar'
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
@ -15,38 +14,33 @@ import { SignStatus } from '../../utils'
import { Spinner } from '../Spinner' import { Spinner } from '../Spinner'
type DisplaySignerProps = { type DisplaySignerProps = {
profile: ProfileMetadata
pubkey: string pubkey: string
status: SignStatus status: SignStatus
} }
export const DisplaySigner = ({ const getStatusIcon = (status: SignStatus) => {
status, switch (status) {
profile, case SignStatus.Signed:
pubkey return <FontAwesomeIcon icon={faCheck} />
}: DisplaySignerProps) => { case SignStatus.Awaiting:
const getStatusIcon = (status: SignStatus) => { return (
switch (status) { <Spinner>
case SignStatus.Signed: <FontAwesomeIcon icon={faHourglass} />
return <FontAwesomeIcon icon={faCheck} /> </Spinner>
case SignStatus.Awaiting: )
return ( case SignStatus.Pending:
<Spinner> return <FontAwesomeIcon icon={faEllipsis} />
<FontAwesomeIcon icon={faHourglass} /> case SignStatus.Invalid:
</Spinner> return <FontAwesomeIcon icon={faExclamation} />
) case SignStatus.Viewer:
case SignStatus.Pending: return <FontAwesomeIcon icon={faEye} />
return <FontAwesomeIcon icon={faEllipsis} />
case SignStatus.Invalid:
return <FontAwesomeIcon icon={faExclamation} />
case SignStatus.Viewer:
return <FontAwesomeIcon icon={faEye} />
default: default:
return <FontAwesomeIcon icon={faQuestion} /> return <FontAwesomeIcon icon={faQuestion} />
}
} }
}
export const DisplaySigner = ({ status, pubkey }: DisplaySignerProps) => {
return ( return (
<Badge <Badge
className={styles.signer} className={styles.signer}
@ -56,7 +50,7 @@ export const DisplaySigner = ({
<div className={styles.statusBadge}>{getStatusIcon(status)}</div> <div className={styles.statusBadge}>{getStatusIcon(status)}</div>
} }
> >
<UserAvatar pubkey={pubkey} image={profile?.picture} /> <UserAvatar pubkey={pubkey} />
</Badge> </Badge>
) )
} }

View File

@ -3,34 +3,56 @@ import { getProfileRoute } from '../../routes'
import styles from './styles.module.scss' import styles from './styles.module.scss'
import { AvatarIconButton } from '../UserAvatarIconButton' import { AvatarIconButton } from '../UserAvatarIconButton'
import { Link } from 'react-router-dom' import { Link } from 'react-router-dom'
import { useProfileMetadata } from '../../hooks/useProfileMetadata'
import { Tooltip } from '@mui/material'
import { shorten } from '../../utils'
import { TooltipChild } from '../TooltipChild'
interface UserAvatarProps { interface UserAvatarProps {
name?: string
pubkey: string pubkey: string
image?: string isNameVisible?: boolean
} }
/** /**
* This component will be used for the displaying username and profile picture. * This component will be used for the displaying username and profile picture.
* Clicking will navigate to the user's profile. * Clicking will navigate to the user's profile.
*/ */
export const UserAvatar = ({ pubkey, name, image }: UserAvatarProps) => { export const UserAvatar = ({
pubkey,
isNameVisible = false
}: UserAvatarProps) => {
const profile = useProfileMetadata(pubkey)
const name = profile?.display_name || profile?.name || shorten(pubkey)
const image = profile?.picture
return ( return (
<Link <Link
to={getProfileRoute(pubkey)} to={getProfileRoute(pubkey)}
className={styles.container} className={styles.container}
tabIndex={-1} tabIndex={-1}
> >
<AvatarIconButton <Tooltip
src={image} key={pubkey}
hexKey={pubkey} title={name}
aria-label={`account of user ${name || pubkey}`} placement="top"
color="inherit" arrow
sx={{ disableInteractive
padding: 0 >
}} <TooltipChild>
/> <AvatarIconButton
{name ? <span className={styles.username}>{name}</span> : null} src={image}
hexKey={pubkey}
aria-label={`account of user ${name}`}
color="inherit"
sx={{
padding: 0
}}
/>
</TooltipChild>
</Tooltip>
{isNameVisible && name ? (
<span className={styles.username}>{name}</span>
) : null}
</Link> </Link>
) )
} }

View File

@ -1,11 +1,9 @@
import { Divider, Tooltip } from '@mui/material' import { Divider, Tooltip } from '@mui/material'
import { useSigitProfiles } from '../../hooks/useSigitProfiles'
import { import {
formatTimestamp, formatTimestamp,
fromUnixTimestamp, fromUnixTimestamp,
hexToNpub, hexToNpub,
npubToHex, npubToHex,
shorten,
SignStatus SignStatus
} from '../../utils' } from '../../utils'
import { useSigitMeta } from '../../hooks/useSigitMeta' import { useSigitMeta } from '../../hooks/useSigitMeta'
@ -24,10 +22,10 @@ import {
import { getExtensionIconLabel } from '../getExtensionIconLabel' import { getExtensionIconLabel } from '../getExtensionIconLabel'
import { useSelector } from 'react-redux' import { useSelector } from 'react-redux'
import { State } from '../../store/rootReducer' import { State } from '../../store/rootReducer'
import { TooltipChild } from '../TooltipChild'
import { DisplaySigner } from '../DisplaySigner' import { DisplaySigner } from '../DisplaySigner'
import { Meta } from '../../types' import { Meta } from '../../types'
import { extractFileExtensions } from '../../utils/file' import { extractFileExtensions } from '../../utils/file'
import { UserAvatar } from '../UserAvatar'
interface UsersDetailsProps { interface UsersDetailsProps {
meta: Meta meta: Meta
@ -36,6 +34,7 @@ interface UsersDetailsProps {
export const UsersDetails = ({ meta }: UsersDetailsProps) => { export const UsersDetails = ({ meta }: UsersDetailsProps) => {
const { const {
submittedBy, submittedBy,
exportedBy,
signers, signers,
viewers, viewers,
fileHashes, fileHashes,
@ -47,11 +46,6 @@ export const UsersDetails = ({ meta }: UsersDetailsProps) => {
isValid isValid
} = useSigitMeta(meta) } = useSigitMeta(meta)
const { usersPubkey } = useSelector((state: State) => state.auth) const { usersPubkey } = useSelector((state: State) => state.auth)
const profiles = useSigitProfiles([
...(submittedBy ? [submittedBy] : []),
...signers,
...viewers
])
const userCanSign = const userCanSign =
typeof usersPubkey !== 'undefined' && typeof usersPubkey !== 'undefined' &&
signers.includes(hexToNpub(usersPubkey)) signers.includes(hexToNpub(usersPubkey))
@ -63,31 +57,12 @@ export const UsersDetails = ({ meta }: UsersDetailsProps) => {
<div className={styles.section}> <div className={styles.section}>
<p>Signers</p> <p>Signers</p>
<div className={styles.users}> <div className={styles.users}>
{submittedBy && {submittedBy && (
(function () { <DisplaySigner
const profile = profiles[submittedBy] status={isValid ? SignStatus.Signed : SignStatus.Invalid}
return ( pubkey={submittedBy}
<Tooltip />
key={submittedBy} )}
title={
profile?.display_name ||
profile?.name ||
shorten(hexToNpub(submittedBy))
}
placement="top"
arrow
disableInteractive
>
<TooltipChild>
<DisplaySigner
status={isValid ? SignStatus.Signed : SignStatus.Invalid}
profile={profile}
pubkey={submittedBy}
/>
</TooltipChild>
</Tooltip>
)
})()}
{submittedBy && signers.length ? ( {submittedBy && signers.length ? (
<Divider orientation="vertical" flexItem /> <Divider orientation="vertical" flexItem />
@ -96,26 +71,12 @@ export const UsersDetails = ({ meta }: UsersDetailsProps) => {
<UserAvatarGroup max={20}> <UserAvatarGroup max={20}>
{signers.map((signer) => { {signers.map((signer) => {
const pubkey = npubToHex(signer)! const pubkey = npubToHex(signer)!
const profile = profiles[pubkey]
return ( return (
<Tooltip <DisplaySigner
key={signer} key={pubkey}
title={ status={signersStatus[signer]}
profile?.display_name || profile?.name || shorten(pubkey) pubkey={pubkey}
} />
placement="top"
arrow
disableInteractive
>
<TooltipChild>
<DisplaySigner
status={signersStatus[signer]}
profile={profile}
pubkey={pubkey}
/>
</TooltipChild>
</Tooltip>
) )
})} })}
</UserAvatarGroup> </UserAvatarGroup>
@ -128,34 +89,28 @@ export const UsersDetails = ({ meta }: UsersDetailsProps) => {
<UserAvatarGroup max={20}> <UserAvatarGroup max={20}>
{viewers.map((signer) => { {viewers.map((signer) => {
const pubkey = npubToHex(signer)! const pubkey = npubToHex(signer)!
const profile = profiles[pubkey]
return ( return (
<Tooltip <DisplaySigner
key={signer} key={pubkey}
title={ status={SignStatus.Viewer}
profile?.display_name || pubkey={pubkey}
profile?.name || />
shorten(pubkey)
}
placement="top"
arrow
disableInteractive
>
<TooltipChild>
<DisplaySigner
status={SignStatus.Viewer}
profile={profile}
pubkey={pubkey}
/>
</TooltipChild>
</Tooltip>
) )
})} })}
</UserAvatarGroup> </UserAvatarGroup>
</div> </div>
</> </>
)} )}
{exportedBy && (
<>
<p>Exported By</p>
<div className={styles.users}>
<UserAvatar pubkey={exportedBy} />
</div>
</>
)}
</div> </div>
<div className={styles.section}> <div className={styles.section}>
<p>Details</p> <p>Details</p>

View File

@ -25,7 +25,7 @@ export class AuthController {
constructor() { constructor() {
this.nostrController = NostrController.getInstance() this.nostrController = NostrController.getInstance()
this.metadataController = new MetadataController() this.metadataController = MetadataController.getInstance()
} }
/** /**

View File

@ -22,6 +22,7 @@ import {
import { DEFAULT_LOOK_UP_RELAY_LIST } from '../utils/const' import { DEFAULT_LOOK_UP_RELAY_LIST } from '../utils/const'
export class MetadataController extends EventEmitter { export class MetadataController extends EventEmitter {
private static instance: MetadataController
private nostrController: NostrController private nostrController: NostrController
private specialMetadataRelay = 'wss://purplepag.es' private specialMetadataRelay = 'wss://purplepag.es'
private pendingFetches = new Map<string, Promise<Event | null>>() // Track pending fetches private pendingFetches = new Map<string, Promise<Event | null>>() // Track pending fetches
@ -31,6 +32,13 @@ export class MetadataController extends EventEmitter {
this.nostrController = NostrController.getInstance() this.nostrController = NostrController.getInstance()
} }
public static getInstance(): MetadataController {
if (!MetadataController.instance) {
MetadataController.instance = new MetadataController()
}
return MetadataController.instance
}
/** /**
* Asynchronously checks for more recent metadata events authored by a specific key. * Asynchronously checks for more recent metadata events authored by a specific key.
* If a more recent metadata event is found, it is handled and returned. * If a more recent metadata event is found, it is handled and returned.
@ -119,7 +127,6 @@ export class MetadataController extends EventEmitter {
// Check if the cached metadata is older than one day // Check if the cached metadata is older than one day
if (isOlderThanOneDay(cachedMetadataEvent.cachedAt)) { if (isOlderThanOneDay(cachedMetadataEvent.cachedAt)) {
// If older than one week, find the metadata from relays in background // If older than one week, find the metadata from relays in background
this.checkForMoreRecentMetadata(hexKey, cachedMetadataEvent.event) this.checkForMoreRecentMetadata(hexKey, cachedMetadataEvent.event)
} }

View File

@ -0,0 +1,46 @@
import { useEffect, useState } from 'react'
import { ProfileMetadata } from '../types/profile'
import { MetadataController } from '../controllers/MetadataController'
import { Event, kinds } from 'nostr-tools'
export const useProfileMetadata = (pubkey: string) => {
const [profileMetadata, setProfileMetadata] = useState<ProfileMetadata>()
useEffect(() => {
const metadataController = MetadataController.getInstance()
const handleMetadataEvent = (event: Event) => {
const metadataContent =
metadataController.extractProfileMetadataContent(event)
if (metadataContent) {
setProfileMetadata(metadataContent)
}
}
if (pubkey) {
metadataController.on(pubkey, (kind: number, event: Event) => {
if (kind === kinds.Metadata) {
handleMetadataEvent(event)
}
})
metadataController
.findMetadata(pubkey)
.then((metadataEvent) => {
if (metadataEvent) handleMetadataEvent(metadataEvent)
})
.catch((err) => {
console.error(
`error occurred in finding metadata for: ${pubkey}`,
err
)
})
}
return () => {
metadataController.off(pubkey, handleMetadataEvent)
}
}, [pubkey])
return profileMetadata
}

View File

@ -33,6 +33,10 @@ export interface FlatMeta
// Remove pubkey and use submittedBy as `npub1${string}` // Remove pubkey and use submittedBy as `npub1${string}`
submittedBy?: `npub1${string}` submittedBy?: `npub1${string}`
// Optional field only present on exported sigits
// Exporting adds user's pubkey
exportedBy?: `npub1${string}`
// Remove created_at and replace with createdAt // Remove created_at and replace with createdAt
createdAt?: number createdAt?: number
@ -68,6 +72,7 @@ export const useSigitMeta = (meta: Meta): FlatMeta => {
const [tags, setTags] = useState<string[][]>() const [tags, setTags] = useState<string[][]>()
const [createdAt, setCreatedAt] = useState<number>() const [createdAt, setCreatedAt] = useState<number>()
const [submittedBy, setSubmittedBy] = useState<`npub1${string}`>() // submittedBy, pubkey from nostr event const [submittedBy, setSubmittedBy] = useState<`npub1${string}`>() // submittedBy, pubkey from nostr event
const [exportedBy, setExportedBy] = useState<`npub1${string}`>() // pubkey from export signature nostr event
const [id, setId] = useState<string>() const [id, setId] = useState<string>()
const [sig, setSig] = useState<string>() const [sig, setSig] = useState<string>()
@ -99,6 +104,18 @@ export const useSigitMeta = (meta: Meta): FlatMeta => {
if (!meta) return if (!meta) return
;(async function () { ;(async function () {
try { try {
if (meta.exportSignature) {
const exportSignatureEvent = await parseNostrEvent(
meta.exportSignature
)
if (
verifyEvent(exportSignatureEvent) &&
exportSignatureEvent.pubkey
) {
setExportedBy(exportSignatureEvent.pubkey as `npub1${string}`)
}
}
const createSignatureEvent = await parseNostrEvent(meta.createSignature) const createSignatureEvent = await parseNostrEvent(meta.createSignature)
const { kind, tags, created_at, pubkey, id, sig, content } = const { kind, tags, created_at, pubkey, id, sig, content } =
@ -265,6 +282,7 @@ export const useSigitMeta = (meta: Meta): FlatMeta => {
tags, tags,
createdAt, createdAt,
submittedBy, submittedBy,
exportedBy,
id, id,
sig, sig,
signers, signers,

View File

@ -1,71 +0,0 @@
import { useEffect, useState } from 'react'
import { ProfileMetadata } from '../types'
import { MetadataController } from '../controllers'
import { npubToHex } from '../utils'
import { Event, kinds } from 'nostr-tools'
/**
* Extracts profiles from metadata events
* @param pubkeys Array of npubs to check
* @returns ProfileMetadata
*/
export const useSigitProfiles = (
pubkeys: `npub1${string}`[]
): { [key: string]: ProfileMetadata } => {
const [profileMetadata, setProfileMetadata] = useState<{
[key: string]: ProfileMetadata
}>({})
useEffect(() => {
if (pubkeys.length) {
const metadataController = new MetadataController()
// Remove duplicate keys
const users = new Set<string>([...pubkeys])
const handleMetadataEvent = (key: string) => (event: Event) => {
const metadataContent =
metadataController.extractProfileMetadataContent(event)
if (metadataContent) {
setProfileMetadata((prev) => ({
...prev,
[key]: metadataContent
}))
}
}
users.forEach((user) => {
const hexKey = npubToHex(user)
if (hexKey && !(hexKey in profileMetadata)) {
metadataController.on(hexKey, (kind: number, event: Event) => {
if (kind === kinds.Metadata) {
handleMetadataEvent(hexKey)(event)
}
})
metadataController
.findMetadata(hexKey)
.then((metadataEvent) => {
if (metadataEvent) handleMetadataEvent(hexKey)(metadataEvent)
})
.catch((err) => {
console.error(
`error occurred in finding metadata for: ${user}`,
err
)
})
}
})
return () => {
users.forEach((key) => {
metadataController.off(key, handleMetadataEvent(key))
})
}
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [pubkeys])
return profileMetadata
}

View File

@ -38,7 +38,7 @@ export const MainLayout = () => {
const hasSubscribed = useRef(false) const hasSubscribed = useRef(false)
useEffect(() => { useEffect(() => {
const metadataController = new MetadataController() const metadataController = MetadataController.getInstance()
const logout = () => { const logout = () => {
dispatch( dispatch(

View File

@ -36,7 +36,6 @@ import {
npubToHex, npubToHex,
queryNip05, queryNip05,
sendNotification, sendNotification,
shorten,
signEventForMetaFile, signEventForMetaFile,
updateUsersAppData, updateUsersAppData,
uploadToFileStorage uploadToFileStorage
@ -113,6 +112,8 @@ export const CreatePage = () => {
const [error, setError] = useState<string>() const [error, setError] = useState<string>()
const [users, setUsers] = useState<User[]>([]) const [users, setUsers] = useState<User[]>([])
const signers = users.filter((u) => u.role === UserRole.signer)
const viewers = users.filter((u) => u.role === UserRole.viewer)
const usersPubkey = useSelector((state: State) => state.auth.usersPubkey) const usersPubkey = useSelector((state: State) => state.auth.usersPubkey)
@ -252,7 +253,7 @@ export const CreatePage = () => {
useEffect(() => { useEffect(() => {
users.forEach((user) => { users.forEach((user) => {
if (!(user.pubkey in metadata)) { if (!(user.pubkey in metadata)) {
const metadataController = new MetadataController() const metadataController = MetadataController.getInstance()
const handleMetadataEvent = (event: Event) => { const handleMetadataEvent = (event: Event) => {
const metadataContent = const metadataContent =
@ -647,6 +648,11 @@ export const CreatePage = () => {
} }
saveAs(finalZipFile, `request-${unixNow()}.sigit.zip`) saveAs(finalZipFile, `request-${unixNow()}.sigit.zip`)
// If user is the next signer, we can navigate directly to sign page
if (signers[0].pubkey === usersPubkey) {
navigate(appPrivateRoutes.sign, { state: { uploadedZip: finalZipFile } })
}
setIsLoading(false) setIsLoading(false)
} }
@ -672,9 +678,6 @@ export const CreatePage = () => {
}, },
zipUrl: string zipUrl: string
) => { ) => {
const signers = users.filter((user) => user.role === UserRole.signer)
const viewers = users.filter((user) => user.role === UserRole.viewer)
const content: CreateSignatureEventContent = { const content: CreateSignatureEventContent = {
signers: signers.map((signer) => hexToNpub(signer.pubkey)), signers: signers.map((signer) => hexToNpub(signer.pubkey)),
viewers: viewers.map((viewer) => hexToNpub(viewer.pubkey)), viewers: viewers.map((viewer) => hexToNpub(viewer.pubkey)),
@ -703,9 +706,6 @@ export const CreatePage = () => {
// Send notifications to signers and viewers // Send notifications to signers and viewers
const sendNotifications = (meta: Meta) => { const sendNotifications = (meta: Meta) => {
const signers = users.filter((user) => user.role === UserRole.signer)
const viewers = users.filter((user) => user.role === UserRole.viewer)
// no need to send notification to self so remove it from the list // no need to send notification to self so remove it from the list
const receivers = ( const receivers = (
signers.length > 0 signers.length > 0
@ -787,7 +787,7 @@ export const CreatePage = () => {
toast.error('Failed to publish notifications') toast.error('Failed to publish notifications')
}) })
navigate(appPrivateRoutes.sign, { state: { meta: meta } }) navigate(appPrivateRoutes.sign, { state: { meta } })
} else { } else {
const zip = new JSZip() const zip = new JSZip()
@ -914,7 +914,6 @@ export const CreatePage = () => {
<div className={styles.flexWrap}> <div className={styles.flexWrap}>
<div className={`${styles.paperGroup} ${styles.users}`}> <div className={`${styles.paperGroup} ${styles.users}`}>
<DisplayUser <DisplayUser
metadata={metadata}
users={users} users={users}
handleUserRoleChange={handleUserRoleChange} handleUserRoleChange={handleUserRoleChange}
handleRemoveUser={handleRemoveUser} handleRemoveUser={handleRemoveUser}
@ -1011,7 +1010,6 @@ export const CreatePage = () => {
} }
type DisplayUsersProps = { type DisplayUsersProps = {
metadata: { [key: string]: ProfileMetadata }
users: User[] users: User[]
handleUserRoleChange: (role: UserRole, pubkey: string) => void handleUserRoleChange: (role: UserRole, pubkey: string) => void
handleRemoveUser: (pubkey: string) => void handleRemoveUser: (pubkey: string) => void
@ -1019,7 +1017,6 @@ type DisplayUsersProps = {
} }
const DisplayUser = ({ const DisplayUser = ({
metadata,
users, users,
handleUserRoleChange, handleUserRoleChange,
handleRemoveUser, handleRemoveUser,
@ -1033,7 +1030,6 @@ const DisplayUser = ({
.map((user, index) => ( .map((user, index) => (
<SignerCounterpart <SignerCounterpart
key={`signer-${user.pubkey}`} key={`signer-${user.pubkey}`}
userMeta={metadata[user.pubkey]}
user={user} user={user}
index={index} index={index}
moveSigner={moveSigner} moveSigner={moveSigner}
@ -1048,7 +1044,6 @@ const DisplayUser = ({
return ( return (
<div className={styles.user} key={`viewer-${user.pubkey}`}> <div className={styles.user} key={`viewer-${user.pubkey}`}>
<Counterpart <Counterpart
userMeta={metadata[user.pubkey]}
user={user} user={user}
handleUserRoleChange={handleUserRoleChange} handleUserRoleChange={handleUserRoleChange}
handleRemoveUser={handleRemoveUser} handleRemoveUser={handleRemoveUser}
@ -1067,7 +1062,6 @@ interface DragItem {
} }
type CounterpartProps = { type CounterpartProps = {
userMeta: ProfileMetadata
user: User user: User
handleUserRoleChange: (role: UserRole, pubkey: string) => void handleUserRoleChange: (role: UserRole, pubkey: string) => void
handleRemoveUser: (pubkey: string) => void handleRemoveUser: (pubkey: string) => void
@ -1079,7 +1073,6 @@ type SignerCounterpartProps = CounterpartProps & {
} }
const SignerCounterpart = ({ const SignerCounterpart = ({
userMeta,
user, user,
index, index,
moveSigner, moveSigner,
@ -1172,7 +1165,6 @@ const SignerCounterpart = ({
<FontAwesomeIcon width={'14px'} fontSize={'14px'} icon={faGripLines} /> <FontAwesomeIcon width={'14px'} fontSize={'14px'} icon={faGripLines} />
<Counterpart <Counterpart
user={user} user={user}
userMeta={userMeta}
handleRemoveUser={handleRemoveUser} handleRemoveUser={handleRemoveUser}
handleUserRoleChange={handleUserRoleChange} handleUserRoleChange={handleUserRoleChange}
/> />
@ -1181,7 +1173,6 @@ const SignerCounterpart = ({
} }
const Counterpart = ({ const Counterpart = ({
userMeta,
user, user,
handleUserRoleChange, handleUserRoleChange,
handleRemoveUser handleRemoveUser
@ -1189,15 +1180,7 @@ const Counterpart = ({
return ( return (
<> <>
<div className={styles.avatar}> <div className={styles.avatar}>
<UserAvatar <UserAvatar pubkey={user.pubkey} isNameVisible={true} />
pubkey={user.pubkey}
name={
userMeta?.display_name ||
userMeta?.name ||
shorten(hexToNpub(user.pubkey))
}
image={userMeta?.picture}
/>
</div> </div>
<Tooltip title="Toggle User Role" arrow disableInteractive> <Tooltip title="Toggle User Role" arrow disableInteractive>
<Button <Button

View File

@ -35,7 +35,7 @@ export const Nostr = () => {
const navigate = useNavigate() const navigate = useNavigate()
const authController = new AuthController() const authController = new AuthController()
const metadataController = new MetadataController() const metadataController = MetadataController.getInstance()
const nostrController = NostrController.getInstance() const nostrController = NostrController.getInstance()
const [isLoading, setIsLoading] = useState(false) const [isLoading, setIsLoading] = useState(false)

View File

@ -27,7 +27,7 @@ export const ProfilePage = () => {
const { npub } = useParams() const { npub } = useParams()
const metadataController = useMemo(() => new MetadataController(), []) const metadataController = useMemo(() => MetadataController.getInstance(), [])
const [pubkey, setPubkey] = useState<string>() const [pubkey, setPubkey] = useState<string>()
const [nostrJoiningBlock, setNostrJoiningBlock] = const [nostrJoiningBlock, setNostrJoiningBlock] =

View File

@ -12,7 +12,7 @@ import {
useTheme useTheme
} from '@mui/material' } from '@mui/material'
import { UnsignedEvent, nip19, kinds, VerifiedEvent, Event } from 'nostr-tools' import { UnsignedEvent, nip19, kinds, VerifiedEvent, Event } from 'nostr-tools'
import React, { useEffect, useMemo, useRef, useState } from 'react' import React, { useEffect, useRef, useState } from 'react'
import { Link, useParams } from 'react-router-dom' import { Link, useParams } from 'react-router-dom'
import { toast } from 'react-toastify' import { toast } from 'react-toastify'
import { MetadataController, NostrController } from '../../../controllers' import { MetadataController, NostrController } from '../../../controllers'
@ -41,7 +41,7 @@ export const ProfileSettingsPage = () => {
const dispatch: Dispatch = useDispatch() const dispatch: Dispatch = useDispatch()
const metadataController = useMemo(() => new MetadataController(), []) const metadataController = MetadataController.getInstance()
const nostrController = NostrController.getInstance() const nostrController = NostrController.getInstance()
const [pubkey, setPubkey] = useState<string>() const [pubkey, setPubkey] = useState<string>()

View File

@ -33,7 +33,8 @@ import {
sendNotification, sendNotification,
signEventForMetaFile, signEventForMetaFile,
updateUsersAppData, updateUsersAppData,
findOtherUserMarks findOtherUserMarks,
timeout
} from '../../utils' } from '../../utils'
import { Container } from '../../components/Container' import { Container } from '../../components/Container'
import { DisplayMeta } from './internal/displayMeta' import { DisplayMeta } from './internal/displayMeta'
@ -276,17 +277,10 @@ export const SignPage = () => {
setAuthUrl(url) setAuthUrl(url)
}) })
// Set up timeout promise to handle encryption timeout // decrypt the encryptionKey, with timeout (duration = 60 seconds)
const timeoutPromise = new Promise<never>((_, reject) => {
setTimeout(() => {
reject(new Error('Timeout occurred'))
}, 60000) // Timeout duration = 60 seconds
})
// decrypt the encryptionKey, with timeout
const encryptionKey = await Promise.race([ const encryptionKey = await Promise.race([
nostrController.nip04Decrypt(sender, key), nostrController.nip04Decrypt(sender, key),
timeoutPromise timeout(60000)
]) ])
.then((res) => { .then((res) => {
return res return res
@ -468,20 +462,20 @@ export const SignPage = () => {
const fileNames = Object.values(zip.files) const fileNames = Object.values(zip.files)
.filter((entry) => entry.name.startsWith('files/') && !entry.dir) .filter((entry) => entry.name.startsWith('files/') && !entry.dir)
.map((entry) => entry.name) .map((entry) => entry.name)
.map((entry) => entry.replace(/^files\//, ''))
// generate hashes for all entries in files folder of zipArchive for (const zipFilePath of fileNames) {
// these hashes can be used to verify the originality of files
for (const fileName of fileNames) {
const arrayBuffer = await readContentOfZipEntry( const arrayBuffer = await readContentOfZipEntry(
zip, zip,
fileName, zipFilePath,
'arraybuffer' 'arraybuffer'
) )
const fileName = zipFilePath.replace(/^files\//, '')
if (arrayBuffer) { if (arrayBuffer) {
files[fileName] = await convertToSigitFile(arrayBuffer, fileName) files[fileName] = await convertToSigitFile(arrayBuffer, fileName)
// generate hashes for all entries in files folder of zipArchive
// these hashes can be used to verify the originality of files
const hash = await getHash(arrayBuffer) const hash = await getHash(arrayBuffer)
if (hash) { if (hash) {
fileHashes[fileName] = hash fileHashes[fileName] = hash

View File

@ -32,7 +32,7 @@ import { useState, useEffect } from 'react'
import { toast } from 'react-toastify' import { toast } from 'react-toastify'
import { UserAvatar } from '../../../components/UserAvatar' import { UserAvatar } from '../../../components/UserAvatar'
import { MetadataController } from '../../../controllers' import { MetadataController } from '../../../controllers'
import { npubToHex, shorten, hexToNpub, parseJson } from '../../../utils' import { npubToHex, hexToNpub, parseJson } from '../../../utils'
import styles from '../style.module.scss' import styles from '../style.module.scss'
import { SigitFile } from '../../../utils/file' import { SigitFile } from '../../../utils/file'
@ -105,7 +105,7 @@ export const DisplayMeta = ({
}, [signers, viewers]) }, [signers, viewers])
useEffect(() => { useEffect(() => {
const metadataController = new MetadataController() const metadataController = MetadataController.getInstance()
const hexKeys: string[] = [ const hexKeys: string[] = [
npubToHex(submittedBy)!, npubToHex(submittedBy)!,
@ -167,20 +167,7 @@ export const DisplayMeta = ({
<Typography variant="h6" sx={{ color: textColor }}> <Typography variant="h6" sx={{ color: textColor }}>
Submitted By Submitted By
</Typography> </Typography>
{(function () { <UserAvatar pubkey={submittedBy} isNameVisible={true} />
const profile = metadata[submittedBy]
return (
<UserAvatar
pubkey={submittedBy}
name={
profile?.display_name ||
profile?.name ||
shorten(hexToNpub(submittedBy))
}
image={profile?.picture}
/>
)
})()}
</ListItem> </ListItem>
<ListItem <ListItem
sx={{ sx={{
@ -280,14 +267,12 @@ type DisplayUserProps = {
const DisplayUser = ({ const DisplayUser = ({
meta, meta,
user, user,
metadata,
signedBy, signedBy,
nextSigner, nextSigner,
getPrevSignersSig getPrevSignersSig
}: DisplayUserProps) => { }: DisplayUserProps) => {
const theme = useTheme() const theme = useTheme()
const userMeta = metadata[user.pubkey]
const [userStatus, setUserStatus] = useState<UserStatus>(UserStatus.Pending) const [userStatus, setUserStatus] = useState<UserStatus>(UserStatus.Pending)
const [prevSignatureStatus, setPreviousSignatureStatus] = const [prevSignatureStatus, setPreviousSignatureStatus] =
useState<PrevSignatureValidationEnum>(PrevSignatureValidationEnum.Pending) useState<PrevSignatureValidationEnum>(PrevSignatureValidationEnum.Pending)
@ -370,15 +355,7 @@ const DisplayUser = ({
return ( return (
<TableRow> <TableRow>
<TableCell className={styles.tableCell}> <TableCell className={styles.tableCell}>
<UserAvatar <UserAvatar pubkey={user.pubkey} isNameVisible={true} />
pubkey={user.pubkey}
name={
userMeta?.display_name ||
userMeta?.name ||
shorten(hexToNpub(user.pubkey))
}
image={userMeta?.picture}
/>
</TableCell> </TableCell>
<TableCell className={styles.tableCell}>{user.role}</TableCell> <TableCell className={styles.tableCell}>{user.role}</TableCell>
<TableCell> <TableCell>

View File

@ -1,16 +1,11 @@
import { Box, Button, Tooltip, Typography } from '@mui/material' import { Box, Button, Typography } from '@mui/material'
import JSZip from 'jszip' import JSZip from 'jszip'
import { MuiFileInput } from 'mui-file-input' import { MuiFileInput } from 'mui-file-input'
import { Event, verifyEvent } from 'nostr-tools'
import { useEffect, useRef, useState } from 'react' import { useEffect, useRef, useState } from 'react'
import { toast } from 'react-toastify' import { toast } from 'react-toastify'
import { LoadingSpinner } from '../../components/LoadingSpinner' import { LoadingSpinner } from '../../components/LoadingSpinner'
import { NostrController } from '../../controllers' import { NostrController } from '../../controllers'
import { import { DocSignatureEvent, Meta } from '../../types'
CreateSignatureEventContent,
DocSignatureEvent,
Meta
} from '../../types'
import { import {
decryptArrayBuffer, decryptArrayBuffer,
extractMarksFromSignedMeta, extractMarksFromSignedMeta,
@ -20,7 +15,6 @@ import {
parseJson, parseJson,
readContentOfZipEntry, readContentOfZipEntry,
signEventForMetaFile, signEventForMetaFile,
shorten,
getCurrentUserFiles getCurrentUserFiles
} from '../../utils' } from '../../utils'
import styles from './style.module.scss' import styles from './style.module.scss'
@ -42,9 +36,6 @@ import { Container } from '../../components/Container'
import { useSigitMeta } from '../../hooks/useSigitMeta.tsx' import { useSigitMeta } from '../../hooks/useSigitMeta.tsx'
import { StickySideColumns } from '../../layouts/StickySideColumns.tsx' import { StickySideColumns } from '../../layouts/StickySideColumns.tsx'
import { UsersDetails } from '../../components/UsersDetails.tsx/index.tsx' import { UsersDetails } from '../../components/UsersDetails.tsx/index.tsx'
import { UserAvatar } from '../../components/UserAvatar/index.tsx'
import { useSigitProfiles } from '../../hooks/useSigitProfiles.tsx'
import { TooltipChild } from '../../components/TooltipChild.tsx'
import FileList from '../../components/FileList' import FileList from '../../components/FileList'
import { CurrentUserFile } from '../../types/file.ts' import { CurrentUserFile } from '../../types/file.ts'
import { Mark } from '../../types/mark.ts' import { Mark } from '../../types/mark.ts'
@ -163,12 +154,26 @@ const SlimPdfView = ({
export const VerifyPage = () => { export const VerifyPage = () => {
const location = useLocation() const location = useLocation()
const usersPubkey = useSelector((state: State) => state.auth.usersPubkey)
const nostrController = NostrController.getInstance()
const [isLoading, setIsLoading] = useState(false)
const [loadingSpinnerDesc, setLoadingSpinnerDesc] = useState('')
/** /**
* uploadedZip will be received from home page when a user uploads a sigit zip wrapper that contains meta.json * uploadedZip will be received from home page when a user uploads a sigit zip wrapper that contains meta.json
* meta will be received in navigation from create & home page in online mode * meta will be received in navigation from create & home page in online mode
*/ */
const { uploadedZip, meta } = location.state || {} const { uploadedZip, meta: metaInNavState } = location.state || {}
const [selectedFile, setSelectedFile] = useState<File | null>(null)
useEffect(() => {
if (uploadedZip) {
setSelectedFile(uploadedZip)
}
}, [uploadedZip])
const [meta, setMeta] = useState<Meta>(metaInNavState)
const { const {
submittedBy, submittedBy,
zipUrl, zipUrl,
@ -179,44 +184,22 @@ export const VerifyPage = () => {
parsedSignatureEvents parsedSignatureEvents
} = useSigitMeta(meta) } = useSigitMeta(meta)
const profiles = useSigitProfiles([ const [files, setFiles] = useState<{ [filename: string]: SigitFile }>({})
...(submittedBy ? [submittedBy] : []),
...signers,
...viewers
])
const [isLoading, setIsLoading] = useState(false)
const [loadingSpinnerDesc, setLoadingSpinnerDesc] = useState('')
const [selectedFile, setSelectedFile] = useState<File | null>(null)
const [currentFile, setCurrentFile] = useState<CurrentUserFile | null>(null)
const [currentFileHashes, setCurrentFileHashes] = useState<{ const [currentFileHashes, setCurrentFileHashes] = useState<{
[key: string]: string | null [key: string]: string | null
}>({}) }>({})
const [files, setFiles] = useState<{ [filename: string]: SigitFile }>({})
const [currentFile, setCurrentFile] = useState<CurrentUserFile | null>(null)
const [signatureFileHashes, setSignatureFileHashes] = useState<{
[key: string]: string
}>(fileHashes)
useEffect(() => {
setSignatureFileHashes(fileHashes)
}, [fileHashes])
useEffect(() => { useEffect(() => {
if (Object.entries(files).length > 0) { if (Object.entries(files).length > 0) {
const tmp = getCurrentUserFiles(files, fileHashes, signatureFileHashes) const tmp = getCurrentUserFiles(files, currentFileHashes, fileHashes)
setCurrentFile(tmp[0]) setCurrentFile(tmp[0])
} }
}, [signatureFileHashes, fileHashes, files]) }, [currentFileHashes, fileHashes, files])
const usersPubkey = useSelector((state: State) => state.auth.usersPubkey)
const nostrController = NostrController.getInstance()
useEffect(() => { useEffect(() => {
if (uploadedZip) { if (metaInNavState && encryptionKey) {
setSelectedFile(uploadedZip)
} else if (meta && encryptionKey) {
const processSigit = async () => { const processSigit = async () => {
setIsLoading(true) setIsLoading(true)
@ -301,7 +284,7 @@ export const VerifyPage = () => {
processSigit() processSigit()
} }
}, [encryptionKey, meta, uploadedZip, zipUrl]) }, [encryptionKey, metaInNavState, zipUrl])
const handleVerify = async () => { const handleVerify = async () => {
if (!selectedFile) return if (!selectedFile) return
@ -315,6 +298,7 @@ export const VerifyPage = () => {
if (!zip) return if (!zip) return
const files: { [filename: string]: SigitFile } = {}
const fileHashes: { [key: string]: string | null } = {} const fileHashes: { [key: string]: string | null } = {}
const fileNames = Object.values(zip.files) const fileNames = Object.values(zip.files)
.filter((entry) => entry.name.startsWith('files/') && !entry.dir) .filter((entry) => entry.name.startsWith('files/') && !entry.dir)
@ -322,24 +306,27 @@ export const VerifyPage = () => {
// generate hashes for all entries in files folder of zipArchive // generate hashes for all entries in files folder of zipArchive
// these hashes can be used to verify the originality of files // these hashes can be used to verify the originality of files
for (const fileName of fileNames) { for (const zipFilePath of fileNames) {
const arrayBuffer = await readContentOfZipEntry( const arrayBuffer = await readContentOfZipEntry(
zip, zip,
fileName, zipFilePath,
'arraybuffer' 'arraybuffer'
) )
const fileName = zipFilePath.replace(/^files\//, '')
if (arrayBuffer) { if (arrayBuffer) {
files[fileName] = await convertToSigitFile(arrayBuffer, fileName)
const hash = await getHash(arrayBuffer) const hash = await getHash(arrayBuffer)
if (hash) { if (hash) {
fileHashes[fileName.replace(/^files\//, '')] = hash fileHashes[fileName] = hash
} }
} else { } else {
fileHashes[fileName.replace(/^files\//, '')] = null fileHashes[fileName] = null
} }
} }
setFiles(files)
setCurrentFileHashes(fileHashes) setCurrentFileHashes(fileHashes)
setLoadingSpinnerDesc('Parsing meta.json') setLoadingSpinnerDesc('Parsing meta.json')
@ -368,43 +355,7 @@ export const VerifyPage = () => {
if (!parsedMetaJson) return if (!parsedMetaJson) return
const createSignatureEvent = await parseJson<Event>( setMeta(parsedMetaJson)
parsedMetaJson.createSignature
).catch((err) => {
console.log('err in parsing the createSignature event:>> ', err)
toast.error(
err.message || 'error occurred in parsing the create signature event'
)
setIsLoading(false)
return null
})
if (!createSignatureEvent) return
const isValidCreateSignature = verifyEvent(createSignatureEvent)
if (!isValidCreateSignature) {
toast.error('Create signature is invalid')
setIsLoading(false)
return
}
const createSignatureContent = await parseJson<CreateSignatureEventContent>(
createSignatureEvent.content
).catch((err) => {
console.log(
`err in parsing the createSignature event's content :>> `,
err
)
toast.error(
err.message ||
`error occurred in parsing the create signature event's content`
)
setIsLoading(false)
return null
})
if (!createSignatureContent) return
setIsLoading(false) setIsLoading(false)
} }
@ -479,47 +430,6 @@ export const VerifyPage = () => {
setIsLoading(false) setIsLoading(false)
} }
const displayExportedBy = () => {
if (!meta || !meta.exportSignature) return null
const exportSignatureString = meta.exportSignature
try {
const exportSignatureEvent = JSON.parse(exportSignatureString) as Event
if (verifyEvent(exportSignatureEvent)) {
const exportedBy = exportSignatureEvent.pubkey
const profile = profiles[exportedBy]
return (
<Tooltip
title={
profile?.display_name ||
profile?.name ||
shorten(hexToNpub(exportedBy))
}
placement="top"
arrow
disableInteractive
>
<TooltipChild>
<UserAvatar pubkey={exportedBy} image={profile?.picture} />
</TooltipChild>
</Tooltip>
)
} else {
toast.error(`Invalid export signature!`)
return (
<Typography component="label" sx={{ color: 'red' }}>
Invalid export signature
</Typography>
)
}
} catch (error) {
console.error(`An error occurred wile parsing exportSignature`, error)
return null
}
}
return ( return (
<> <>
{isLoading && <LoadingSpinner desc={loadingSpinnerDesc} />} {isLoading && <LoadingSpinner desc={loadingSpinnerDesc} />}
@ -554,22 +464,19 @@ export const VerifyPage = () => {
{meta && ( {meta && (
<StickySideColumns <StickySideColumns
left={ left={
<> currentFile !== null && (
{currentFile !== null && ( <FileList
<FileList files={getCurrentUserFiles(
files={getCurrentUserFiles( files,
files, currentFileHashes,
currentFileHashes, fileHashes
signatureFileHashes )}
)} currentFile={currentFile}
currentFile={currentFile} setCurrentFile={setCurrentFile}
setCurrentFile={setCurrentFile} handleDownload={handleExport}
handleDownload={handleExport} downloadLabel="Download Sigit"
downloadLabel="Download Sigit" />
/> )
)}
{displayExportedBy()}
</>
} }
right={<UsersDetails meta={meta} />} right={<UsersDetails meta={meta} />}
leftIcon={faFileDownload} leftIcon={faFileDownload}
@ -578,11 +485,7 @@ export const VerifyPage = () => {
> >
<SlimPdfView <SlimPdfView
currentFile={currentFile} currentFile={currentFile}
files={getCurrentUserFiles( files={getCurrentUserFiles(files, currentFileHashes, fileHashes)}
files,
currentFileHashes,
signatureFileHashes
)}
parsedSignatureEvents={parsedSignatureEvents} parsedSignatureEvents={parsedSignatureEvents}
/> />
</StickySideColumns> </StickySideColumns>

View File

@ -13,7 +13,7 @@ import { setRelayInfoAction } from '../store/actions'
export const getNostrJoiningBlockNumber = async ( export const getNostrJoiningBlockNumber = async (
hexKey: string hexKey: string
): Promise<NostrJoiningBlock | null> => { ): Promise<NostrJoiningBlock | null> => {
const metadataController = new MetadataController() const metadataController = MetadataController.getInstance()
const relaySet = await metadataController.findRelayListMetadata(hexKey) const relaySet = await metadataController.findRelayListMetadata(hexKey)

View File

@ -365,7 +365,7 @@ export const getUsersAppData = async (): Promise<UserAppData | null> => {
// Check if relayMap is undefined in the Redux store // Check if relayMap is undefined in the Redux store
if (!relayMap) { if (!relayMap) {
// If relayMap is not present, fetch relay list metadata // If relayMap is not present, fetch relay list metadata
const metadataController = new MetadataController() const metadataController = MetadataController.getInstance()
const relaySet = await metadataController const relaySet = await metadataController
.findRelayListMetadata(usersPubkey) .findRelayListMetadata(usersPubkey)
.catch((err) => { .catch((err) => {
@ -835,7 +835,7 @@ const getUserAppDataFromBlossom = async (url: string, privateKey: string) => {
*/ */
export const subscribeForSigits = async (pubkey: string) => { export const subscribeForSigits = async (pubkey: string) => {
// Instantiate the MetadataController to retrieve relay list metadata // Instantiate the MetadataController to retrieve relay list metadata
const metadataController = new MetadataController() const metadataController = MetadataController.getInstance()
const relaySet = await metadataController const relaySet = await metadataController
.findRelayListMetadata(pubkey) .findRelayListMetadata(pubkey)
.catch((err) => { .catch((err) => {
@ -939,7 +939,7 @@ export const sendNotification = async (receiver: string, meta: Meta) => {
const wrappedEvent = createWrap(unsignedEvent, receiver) const wrappedEvent = createWrap(unsignedEvent, receiver)
// Instantiate the MetadataController to retrieve relay list metadata // Instantiate the MetadataController to retrieve relay list metadata
const metadataController = new MetadataController() const metadataController = MetadataController.getInstance()
const relaySet = await metadataController const relaySet = await metadataController
.findRelayListMetadata(receiver) .findRelayListMetadata(receiver)
.catch((err) => { .catch((err) => {