feat: in offline mode navigate creator to sign screen after creation when creator is first signer

This commit is contained in:
SwiftHawk 2024-06-03 14:01:24 +05:00
parent 074694bfac
commit 1f7980e2ca
2 changed files with 29 additions and 5 deletions

View File

@ -389,12 +389,21 @@ export const CreatePage = () => {
fileUrl
)}&key=${encodeURIComponent(encryptionKey)}`
)
} else {
if (signers[0] && signers[0].pubkey === usersPubkey) {
// Create a File object with the Blob data
const file = new File([blob], `compressed.sigit`, {
type: 'application/sigit'
})
navigate(appPrivateRoutes.sign, { state: { file, encryptionKey } })
} else {
saveAs(blob, 'request.sigit')
setTextToCopy(encryptionKey)
setOpenCopyModel(true)
}
}
}
if (authUrl) {
return (

View File

@ -23,7 +23,7 @@ import { MuiFileInput } from 'mui-file-input'
import { Event, kinds, verifyEvent } from 'nostr-tools'
import { useEffect, useState } from 'react'
import { useSelector } from 'react-redux'
import { useNavigate, useSearchParams } from 'react-router-dom'
import { useNavigate, useSearchParams, useLocation } from 'react-router-dom'
import { toast } from 'react-toastify'
import { LoadingSpinner } from '../../components/LoadingSpinner'
import { UserComponent } from '../../components/username'
@ -69,6 +69,9 @@ enum SignedStatus {
export const SignPage = () => {
const navigate = useNavigate()
const location = useLocation()
const { file, encryptionKey: encKey } = location.state || {}
const [searchParams, setSearchParams] = useSearchParams()
const [displayInput, setDisplayInput] = useState(false)
@ -217,11 +220,23 @@ export const SignPage = () => {
.finally(() => {
setIsLoading(false)
})
} else if (file && encKey) {
decrypt(file, decodeURIComponent(encKey))
.then((arrayBuffer) => {
if (arrayBuffer) handleDecryptedArrayBuffer(arrayBuffer)
})
.catch((err) => {
console.error(`error occurred in decryption`, err)
toast.error(err.message || `error occurred in decryption`)
})
.finally(() => {
setIsLoading(false)
})
} else {
setIsLoading(false)
setDisplayInput(true)
}
}, [searchParams])
}, [searchParams, file, encKey])
const decrypt = async (file: File, key: string) => {
setLoadingSpinnerDesc('Decrypting file')