Merge pull request 'feat: added the ability to re-broadcast sigit' (#309) from issue-240 into staging
All checks were successful
Release to Staging / build_and_release (push) Successful in 2m8s

Reviewed-on: #309
This commit is contained in:
b 2025-01-31 10:20:39 +00:00
commit 461d43e2e1
2 changed files with 83 additions and 2 deletions

View File

@ -16,6 +16,7 @@ interface FileListProps {
setCurrentFile: (file: CurrentUserFile) => void setCurrentFile: (file: CurrentUserFile) => void
handleExport?: () => void handleExport?: () => void
handleEncryptedExport?: () => void handleEncryptedExport?: () => void
reBroadcastSigit?: () => void
} }
const FileList = ({ const FileList = ({
@ -23,7 +24,8 @@ const FileList = ({
currentFile, currentFile,
setCurrentFile, setCurrentFile,
handleExport, handleExport,
handleEncryptedExport handleEncryptedExport,
reBroadcastSigit
}: FileListProps) => { }: FileListProps) => {
const isActive = (file: CurrentUserFile) => file.id === currentFile.id const isActive = (file: CurrentUserFile) => file.id === currentFile.id
return ( return (
@ -91,6 +93,12 @@ const FileList = ({
)} )}
</PopupState> </PopupState>
)} )}
{typeof reBroadcastSigit === 'function' && (
<Button variant="contained" onClick={reBroadcastSigit}>
Re-Broadcast
</Button>
)}
</div> </div>
) )
} }

View File

@ -28,7 +28,8 @@ import {
ARRAY_BUFFER, ARRAY_BUFFER,
DEFLATE, DEFLATE,
uploadMetaToFileStorage, uploadMetaToFileStorage,
decrypt decrypt,
SignStatus
} from '../../utils' } from '../../utils'
import styles from './style.module.scss' import styles from './style.module.scss'
import { useLocation, useParams } from 'react-router-dom' import { useLocation, useParams } from 'react-router-dom'
@ -217,6 +218,7 @@ export const VerifyPage = () => {
encryptionKey, encryptionKey,
signers, signers,
viewers, viewers,
signersStatus,
fileHashes, fileHashes,
parsedSignatureEvents, parsedSignatureEvents,
timestamps timestamps
@ -732,6 +734,76 @@ export const VerifyPage = () => {
return Promise.resolve(arrayBuffer) 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 ( return (
<> <>
{isLoading && <LoadingSpinner desc={loadingSpinnerDesc} />} {isLoading && <LoadingSpinner desc={loadingSpinnerDesc} />}
@ -780,6 +852,7 @@ export const VerifyPage = () => {
setCurrentFile={setCurrentFile} setCurrentFile={setCurrentFile}
handleExport={handleExport} handleExport={handleExport}
handleEncryptedExport={handleEncryptedExport} handleEncryptedExport={handleEncryptedExport}
reBroadcastSigit={reBroadcastSigit}
/> />
) )
} }