fix: load screen on sign, block on missing counterpart #170

Merged
enes merged 7 commits from 137-sign-loading-error into staging 2024-08-29 11:02:19 +00:00
Showing only changes of commit e2b12afc72 - Show all commits

View File

@ -730,10 +730,7 @@ export const CreatePage = () => {
setIsLoading(true) setIsLoading(true)
Review

I wonder if this flow should be refactored, given our recent conversation about error handling. I also thing that there are more efficient ways to handle loading state changes.

Having said that, perhaps it is best left to a separate PR. Worth adding as an issue?

I wonder if this flow should be refactored, given our recent conversation about error handling. I also thing that there are more efficient ways to handle loading state changes. Having said that, perhaps it is best left to a separate PR. Worth adding as an issue?
Review

I think we can for now just leave finally, to execute setIsLoading(false) once, we don't need it in each return

I think we can for now just leave `finally`, to execute `setIsLoading(false)` once, we don't need it in each return
setLoadingSpinnerDesc('Generating file hashes') setLoadingSpinnerDesc('Generating file hashes')
const fileHashes = await generateFileHashes() const fileHashes = await generateFileHashes()
if (!fileHashes) { if (!fileHashes) return
setIsLoading(false)
return
}
setLoadingSpinnerDesc('Generating encryption key') setLoadingSpinnerDesc('Generating encryption key')
const encryptionKey = await generateEncryptionKey() const encryptionKey = await generateEncryptionKey()
@ -741,10 +738,7 @@ export const CreatePage = () => {
if (await isOnline()) { if (await isOnline()) {
setLoadingSpinnerDesc('generating files.zip') setLoadingSpinnerDesc('generating files.zip')
const arrayBuffer = await generateFilesZip() const arrayBuffer = await generateFilesZip()
if (!arrayBuffer) { if (!arrayBuffer) return
setIsLoading(false)
return
}
setLoadingSpinnerDesc('Encrypting files.zip') setLoadingSpinnerDesc('Encrypting files.zip')
const encryptedArrayBuffer = await encryptZipFile( const encryptedArrayBuffer = await encryptZipFile(
@ -756,10 +750,7 @@ export const CreatePage = () => {
setLoadingSpinnerDesc('Uploading files.zip to file storage') setLoadingSpinnerDesc('Uploading files.zip to file storage')
const fileUrl = await uploadFile(encryptedArrayBuffer) const fileUrl = await uploadFile(encryptedArrayBuffer)
if (!fileUrl) { if (!fileUrl) return
setIsLoading(false)
return
}
setLoadingSpinnerDesc('Generating create signature') setLoadingSpinnerDesc('Generating create signature')
const createSignature = await generateCreateSignature( const createSignature = await generateCreateSignature(
@ -767,10 +758,7 @@ export const CreatePage = () => {
fileHashes, fileHashes,
fileUrl fileUrl
) )
if (!createSignature) { if (!createSignature) return
setIsLoading(false)
return
}
setLoadingSpinnerDesc('Generating keys for decryption') setLoadingSpinnerDesc('Generating keys for decryption')
@ -782,11 +770,8 @@ export const CreatePage = () => {
} }
const keys = await generateKeys(pubkeys, encryptionKey) const keys = await generateKeys(pubkeys, encryptionKey)
if (!keys) return
if (!keys) {
setIsLoading(false)
return
}
const meta: Meta = { const meta: Meta = {
createSignature, createSignature,
keys, keys,
@ -796,10 +781,7 @@ export const CreatePage = () => {
setLoadingSpinnerDesc('Updating user app data') setLoadingSpinnerDesc('Updating user app data')
const event = await updateUsersAppData(meta) const event = await updateUsersAppData(meta)
if (!event) { if (!event) return
setIsLoading(false)
return
}
setLoadingSpinnerDesc('Sending notifications to counterparties') setLoadingSpinnerDesc('Sending notifications to counterparties')
const promises = sendNotifications(meta) const promises = sendNotifications(meta)
@ -828,10 +810,7 @@ export const CreatePage = () => {
fileHashes, fileHashes,
'' ''
) )
if (!createSignature) { if (!createSignature) return
setIsLoading(false)
return
}
const meta: Meta = { const meta: Meta = {
createSignature, createSignature,
@ -850,10 +829,7 @@ export const CreatePage = () => {
} }
const arrayBuffer = await generateZipFile(zip) const arrayBuffer = await generateZipFile(zip)
if (!arrayBuffer) { if (!arrayBuffer) return
setIsLoading(false)
return
}
setLoadingSpinnerDesc('Encrypting zip file') setLoadingSpinnerDesc('Encrypting zip file')
const encryptedArrayBuffer = await encryptZipFile( const encryptedArrayBuffer = await encryptZipFile(
@ -917,7 +893,7 @@ export const CreatePage = () => {
<ol className={`${styles.paperGroup} ${styles.orderedFilesList}`}> <ol className={`${styles.paperGroup} ${styles.orderedFilesList}`}>
{selectedFiles.length > 0 && {selectedFiles.length > 0 &&
selectedFiles.map((file, index) => ( selectedFiles.map((file, index) => (
<div <li
key={index} key={index}
className={`${fileListStyles.fileItem} ${isActive(file) && fileListStyles.active}`} className={`${fileListStyles.fileItem} ${isActive(file) && fileListStyles.active}`}
onClick={() => { onClick={() => {
@ -925,9 +901,9 @@ export const CreatePage = () => {
setCurrentFile(file) setCurrentFile(file)
}} }}
> >
<>
<span className={styles.fileName}>{file.name}</span> <span className={styles.fileName}>{file.name}</span>
<Button <Button
aria-label={`delete ${file.name}`}
variant="text" variant="text"
onClick={(event) => handleRemoveFile(event, file)} onClick={(event) => handleRemoveFile(event, file)}
sx={{ sx={{
@ -936,21 +912,21 @@ export const CreatePage = () => {
> >
<FontAwesomeIcon icon={faTrash} /> <FontAwesomeIcon icon={faTrash} />
</Button> </Button>
</> </li>
</div>
))} ))}
</ol> </ol>
<Button variant="contained" onClick={handleUploadButtonClick}> <Button variant="contained" onClick={handleUploadButtonClick}>
<FontAwesomeIcon icon={faUpload} /> <FontAwesomeIcon icon={faUpload} />
<span className={styles.uploadFileText}>Upload new files</span> <span className={styles.uploadFileText}>Upload new files</span>
</Button>
<input <input
ref={fileInputRef} ref={fileInputRef}
hidden={true} hidden={true}
multiple={true} multiple={true}
type="file" type="file"
aria-label="file-upload"
onChange={handleSelectFiles} onChange={handleSelectFiles}
/> />
</Button>
</div> </div>
} }
right={ right={