feat: added the ability to re-broadcast sigit
All checks were successful
Open PR on Staging / audit_and_check (pull_request) Successful in 56s
All checks were successful
Open PR on Staging / audit_and_check (pull_request) Successful in 56s
This commit is contained in:
parent
b97afdecfd
commit
5db4d1b429
@ -16,6 +16,7 @@ interface FileListProps {
|
||||
setCurrentFile: (file: CurrentUserFile) => void
|
||||
handleExport?: () => void
|
||||
handleEncryptedExport?: () => void
|
||||
reBroadcastSigit?: () => void
|
||||
}
|
||||
|
||||
const FileList = ({
|
||||
@ -23,7 +24,8 @@ const FileList = ({
|
||||
currentFile,
|
||||
setCurrentFile,
|
||||
handleExport,
|
||||
handleEncryptedExport
|
||||
handleEncryptedExport,
|
||||
reBroadcastSigit
|
||||
}: FileListProps) => {
|
||||
const isActive = (file: CurrentUserFile) => file.id === currentFile.id
|
||||
return (
|
||||
@ -91,6 +93,12 @@ const FileList = ({
|
||||
)}
|
||||
</PopupState>
|
||||
)}
|
||||
|
||||
{typeof reBroadcastSigit === 'function' && (
|
||||
<Button variant="contained" onClick={reBroadcastSigit}>
|
||||
Re-Broadcast
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
@ -28,7 +28,8 @@ import {
|
||||
ARRAY_BUFFER,
|
||||
DEFLATE,
|
||||
uploadMetaToFileStorage,
|
||||
decrypt
|
||||
decrypt,
|
||||
SignStatus
|
||||
} from '../../utils'
|
||||
import styles from './style.module.scss'
|
||||
import { useLocation, useParams } from 'react-router-dom'
|
||||
@ -217,6 +218,7 @@ export const VerifyPage = () => {
|
||||
encryptionKey,
|
||||
signers,
|
||||
viewers,
|
||||
signersStatus,
|
||||
fileHashes,
|
||||
parsedSignatureEvents,
|
||||
timestamps
|
||||
@ -732,6 +734,76 @@ export const VerifyPage = () => {
|
||||
return Promise.resolve(arrayBuffer)
|
||||
}
|
||||
|
||||
const reBroadcastSigit = async () => {
|
||||
const usersNpub = hexToNpub(usersPubkey!)
|
||||
|
||||
if (!encryptionKey) {
|
||||
toast.error('Encryption key is missing')
|
||||
return
|
||||
}
|
||||
|
||||
setIsLoading(true)
|
||||
setLoadingSpinnerDesc('storing meta on blossom server')
|
||||
|
||||
let metaUrl: string
|
||||
try {
|
||||
metaUrl = await uploadMetaToFileStorage(meta, encryptionKey)
|
||||
} catch (error) {
|
||||
if (error instanceof Error) {
|
||||
toast.error(error.message)
|
||||
}
|
||||
console.error(error)
|
||||
setIsLoading(false)
|
||||
return
|
||||
}
|
||||
|
||||
const userSet = new Set<`npub1${string}`>()
|
||||
if (submittedBy && submittedBy !== usersPubkey) {
|
||||
userSet.add(hexToNpub(submittedBy))
|
||||
}
|
||||
|
||||
// add all the signers who have signed and next signer to userSet
|
||||
signers.forEach((signer) => {
|
||||
// skip current user
|
||||
if (signer === usersNpub) return
|
||||
|
||||
if (signersStatus[signer] === SignStatus.Signed) {
|
||||
userSet.add(signer)
|
||||
} else if (signersStatus[signer] === SignStatus.Awaiting) {
|
||||
userSet.add(signer)
|
||||
}
|
||||
})
|
||||
|
||||
// If all signers have signed then include viewers too
|
||||
if (
|
||||
signers.every((signer) => signersStatus[signer] === SignStatus.Signed)
|
||||
) {
|
||||
viewers.forEach((viewer) => {
|
||||
// skip current user
|
||||
if (viewer === usersNpub) return
|
||||
|
||||
userSet.add(viewer)
|
||||
})
|
||||
}
|
||||
|
||||
setLoadingSpinnerDesc('Sending notifications')
|
||||
const users = Array.from(userSet)
|
||||
const promises = users.map((user) =>
|
||||
sendNotification(npubToHex(user)!, { metaUrl, keys: meta.keys })
|
||||
)
|
||||
|
||||
await Promise.all(promises)
|
||||
.then(() => {
|
||||
toast.success('Notifications sent successfully')
|
||||
setMeta(meta)
|
||||
})
|
||||
.catch(() => {
|
||||
toast.error('Failed to publish notifications')
|
||||
})
|
||||
|
||||
setIsLoading(false)
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
{isLoading && <LoadingSpinner desc={loadingSpinnerDesc} />}
|
||||
@ -780,6 +852,7 @@ export const VerifyPage = () => {
|
||||
setCurrentFile={setCurrentFile}
|
||||
handleExport={handleExport}
|
||||
handleEncryptedExport={handleEncryptedExport}
|
||||
reBroadcastSigit={reBroadcastSigit}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user