Compare commits
No commits in common. "35b1378aa79b69b0375b92d91cfa1488a587eb56" and "59c3fc69a255c54475daa6a2efad3ae8a4b3efd8" have entirely different histories.
35b1378aa7
...
59c3fc69a2
@ -11,6 +11,7 @@ import {
|
||||
hexToNpub,
|
||||
parseNostrEvent,
|
||||
parseCreateSignatureEventContent,
|
||||
SigitMetaParseError,
|
||||
SigitStatus,
|
||||
SignStatus
|
||||
} from '../utils'
|
||||
@ -20,7 +21,6 @@ import { Event } from 'nostr-tools'
|
||||
import store from '../store/store'
|
||||
import { AuthState } from '../store/auth/types'
|
||||
import { NostrController } from '../controllers'
|
||||
import { MetaParseError } from '../types/errors/MetaParseError'
|
||||
|
||||
/**
|
||||
* Flattened interface that combines properties `Meta`, `CreateSignatureEventContent`,
|
||||
@ -247,7 +247,7 @@ export const useSigitMeta = (meta: Meta): FlatMeta => {
|
||||
)
|
||||
}
|
||||
} catch (error) {
|
||||
if (error instanceof MetaParseError) {
|
||||
if (error instanceof SigitMetaParseError) {
|
||||
toast.error(error.message)
|
||||
}
|
||||
console.error(error)
|
||||
|
@ -17,11 +17,9 @@ export const StickySideColumns = ({
|
||||
<div className={`${styles.sidesWrap} ${styles.files}`}>
|
||||
<div className={styles.sides}>{left}</div>
|
||||
</div>
|
||||
<div>
|
||||
<div id="content-preview" className={styles.content}>
|
||||
{children}
|
||||
</div>
|
||||
</div>
|
||||
<div className={styles.sidesWrap}>
|
||||
<div className={styles.sides}>{right}</div>
|
||||
</div>
|
||||
|
@ -514,9 +514,6 @@ export const CreatePage = () => {
|
||||
return (
|
||||
file.pages?.flatMap((page, index) => {
|
||||
return page.drawnFields.map((drawnField) => {
|
||||
if (!drawnField.counterpart) {
|
||||
throw new Error('Missing counterpart')
|
||||
}
|
||||
return {
|
||||
type: drawnField.type,
|
||||
location: {
|
||||
@ -673,7 +670,6 @@ export const CreatePage = () => {
|
||||
}
|
||||
|
||||
const generateCreateSignature = async (
|
||||
markConfig: Mark[],
|
||||
fileHashes: {
|
||||
[key: string]: string
|
||||
},
|
||||
@ -681,6 +677,7 @@ export const CreatePage = () => {
|
||||
) => {
|
||||
const signers = users.filter((user) => user.role === UserRole.signer)
|
||||
const viewers = users.filter((user) => user.role === UserRole.viewer)
|
||||
const markConfig = createMarks(fileHashes)
|
||||
|
||||
const content: CreateSignatureEventContent = {
|
||||
signers: signers.map((signer) => hexToNpub(signer.pubkey)),
|
||||
@ -724,7 +721,6 @@ export const CreatePage = () => {
|
||||
}
|
||||
|
||||
const handleCreate = async () => {
|
||||
try {
|
||||
if (!validateInputs()) return
|
||||
|
||||
setIsLoading(true)
|
||||
@ -752,8 +748,6 @@ export const CreatePage = () => {
|
||||
encryptionKey
|
||||
)
|
||||
|
||||
const markConfig = createMarks(fileHashes)
|
||||
|
||||
setLoadingSpinnerDesc('Uploading files.zip to file storage')
|
||||
const fileUrl = await uploadFile(encryptedArrayBuffer)
|
||||
if (!fileUrl) {
|
||||
@ -762,11 +756,7 @@ export const CreatePage = () => {
|
||||
}
|
||||
|
||||
setLoadingSpinnerDesc('Generating create signature')
|
||||
const createSignature = await generateCreateSignature(
|
||||
markConfig,
|
||||
fileHashes,
|
||||
fileUrl
|
||||
)
|
||||
const createSignature = await generateCreateSignature(fileHashes, fileUrl)
|
||||
if (!createSignature) {
|
||||
setIsLoading(false)
|
||||
return
|
||||
@ -820,14 +810,8 @@ export const CreatePage = () => {
|
||||
zip.file(`files/${file.name}`, file)
|
||||
})
|
||||
|
||||
const markConfig = createMarks(fileHashes)
|
||||
|
||||
setLoadingSpinnerDesc('Generating create signature')
|
||||
const createSignature = await generateCreateSignature(
|
||||
markConfig,
|
||||
fileHashes,
|
||||
''
|
||||
)
|
||||
const createSignature = await generateCreateSignature(fileHashes, '')
|
||||
if (!createSignature) {
|
||||
setIsLoading(false)
|
||||
return
|
||||
@ -863,14 +847,6 @@ export const CreatePage = () => {
|
||||
|
||||
await handleOfflineFlow(encryptedArrayBuffer, encryptionKey)
|
||||
}
|
||||
} catch (error) {
|
||||
if (error instanceof Error) {
|
||||
toast.error(error.message)
|
||||
}
|
||||
console.error(error)
|
||||
} finally {
|
||||
setIsLoading(false)
|
||||
}
|
||||
}
|
||||
|
||||
const onDrawFieldsChange = (sigitFiles: SigitFile[]) => {
|
||||
|
@ -542,13 +542,10 @@ export const SignPage = () => {
|
||||
setLoadingSpinnerDesc('Signing nostr event')
|
||||
|
||||
const prevSig = getPrevSignersSig(hexToNpub(usersPubkey!))
|
||||
if (!prevSig) {
|
||||
setIsLoading(false)
|
||||
toast.error('Previous signature is invalid')
|
||||
return
|
||||
}
|
||||
if (!prevSig) return
|
||||
|
||||
const marks = getSignerMarksForMeta() || []
|
||||
const marks = getSignerMarksForMeta()
|
||||
if (!marks) return
|
||||
|
||||
const signedEvent = await signEventForMeta({ prevSig, marks })
|
||||
if (!signedEvent) return
|
||||
|
@ -1,23 +0,0 @@
|
||||
import { Jsonable } from '.'
|
||||
|
||||
// Reuse common error messages for meta parsing
|
||||
export enum MetaParseErrorType {
|
||||
'PARSE_ERROR_EVENT' = 'error occurred in parsing the create signature event',
|
||||
'PARSE_ERROR_SIGNATURE_EVENT_CONTENT' = "err in parsing the createSignature event's content"
|
||||
}
|
||||
|
||||
export class MetaParseError extends Error {
|
||||
public readonly context?: Jsonable
|
||||
|
||||
constructor(
|
||||
message: string,
|
||||
options: { cause?: Error; context?: Jsonable } = {}
|
||||
) {
|
||||
const { cause, context } = options
|
||||
|
||||
super(message, { cause })
|
||||
this.name = this.constructor.name
|
||||
|
||||
this.context = context
|
||||
}
|
||||
}
|
@ -1,29 +0,0 @@
|
||||
export type Jsonable =
|
||||
| string
|
||||
| number
|
||||
| boolean
|
||||
| null
|
||||
| undefined
|
||||
| readonly Jsonable[]
|
||||
| { readonly [key: string]: Jsonable }
|
||||
| { toJSON(): Jsonable }
|
||||
|
||||
/**
|
||||
* Handle errors
|
||||
* Wraps the errors without message property and stringify to a message so we can use it later
|
||||
* @param error
|
||||
* @returns
|
||||
*/
|
||||
export function handleError(error: unknown): Error {
|
||||
if (error instanceof Error) return error
|
||||
|
||||
// No message error, wrap it and stringify
|
||||
let stringified = 'Unable to stringify the thrown value'
|
||||
try {
|
||||
stringified = JSON.stringify(error)
|
||||
} catch (error) {
|
||||
console.error(stringified, error)
|
||||
}
|
||||
|
||||
return new Error(`Wrapped Error: ${stringified}`)
|
||||
}
|
@ -47,7 +47,7 @@ const filterMarksByPubkey = (marks: Mark[], pubkey: string): Mark[] => {
|
||||
|
||||
/**
|
||||
* Takes Signed Doc Signatures part of Meta and extracts
|
||||
* all Marks into one flat array, regardless of the user.
|
||||
* all Marks into one flar array, regardless of the user.
|
||||
* @param meta
|
||||
*/
|
||||
const extractMarksFromSignedMeta = (meta: Meta): Mark[] => {
|
||||
|
@ -3,11 +3,6 @@ import { fromUnixTimestamp, parseJson } from '.'
|
||||
import { Event, verifyEvent } from 'nostr-tools'
|
||||
import { toast } from 'react-toastify'
|
||||
import { extractFileExtensions } from './file'
|
||||
import { handleError } from '../types/errors'
|
||||
import {
|
||||
MetaParseError,
|
||||
MetaParseErrorType
|
||||
} from '../types/errors/MetaParseError'
|
||||
|
||||
export enum SignStatus {
|
||||
Signed = 'Signed',
|
||||
@ -22,6 +17,58 @@ export enum SigitStatus {
|
||||
Complete = 'Completed'
|
||||
}
|
||||
|
||||
type Jsonable =
|
||||
| string
|
||||
| number
|
||||
| boolean
|
||||
| null
|
||||
| undefined
|
||||
| readonly Jsonable[]
|
||||
| { readonly [key: string]: Jsonable }
|
||||
| { toJSON(): Jsonable }
|
||||
|
||||
export class SigitMetaParseError extends Error {
|
||||
public readonly context?: Jsonable
|
||||
|
||||
constructor(
|
||||
message: string,
|
||||
options: { cause?: Error; context?: Jsonable } = {}
|
||||
) {
|
||||
const { cause, context } = options
|
||||
|
||||
super(message, { cause })
|
||||
this.name = this.constructor.name
|
||||
|
||||
this.context = context
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle meta errors
|
||||
* Wraps the errors without message property and stringify to a message so we can use it later
|
||||
* @param error
|
||||
* @returns
|
||||
*/
|
||||
function handleError(error: unknown): Error {
|
||||
if (error instanceof Error) return error
|
||||
|
||||
// No message error, wrap it and stringify
|
||||
let stringified = 'Unable to stringify the thrown value'
|
||||
try {
|
||||
stringified = JSON.stringify(error)
|
||||
} catch (error) {
|
||||
console.error(stringified, error)
|
||||
}
|
||||
|
||||
return new Error(`[SiGit Error]: ${stringified}`)
|
||||
}
|
||||
|
||||
// Reuse common error messages for meta parsing
|
||||
export enum SigitMetaParseErrorType {
|
||||
'PARSE_ERROR_EVENT' = 'error occurred in parsing the create signature event',
|
||||
'PARSE_ERROR_SIGNATURE_EVENT_CONTENT' = "err in parsing the createSignature event's content"
|
||||
}
|
||||
|
||||
export interface SigitCardDisplayInfo {
|
||||
createdAt?: number
|
||||
title?: string
|
||||
@ -42,7 +89,7 @@ export const parseNostrEvent = async (raw: string): Promise<Event> => {
|
||||
const event = await parseJson<Event>(raw)
|
||||
return event
|
||||
} catch (error) {
|
||||
throw new MetaParseError(MetaParseErrorType.PARSE_ERROR_EVENT, {
|
||||
throw new SigitMetaParseError(SigitMetaParseErrorType.PARSE_ERROR_EVENT, {
|
||||
cause: handleError(error),
|
||||
context: raw
|
||||
})
|
||||
@ -62,8 +109,8 @@ export const parseCreateSignatureEventContent = async (
|
||||
await parseJson<CreateSignatureEventContent>(raw)
|
||||
return createSignatureEventContent
|
||||
} catch (error) {
|
||||
throw new MetaParseError(
|
||||
MetaParseErrorType.PARSE_ERROR_SIGNATURE_EVENT_CONTENT,
|
||||
throw new SigitMetaParseError(
|
||||
SigitMetaParseErrorType.PARSE_ERROR_SIGNATURE_EVENT_CONTENT,
|
||||
{
|
||||
cause: handleError(error),
|
||||
context: raw
|
||||
@ -118,7 +165,7 @@ export const extractSigitCardDisplayInfo = async (meta: Meta) => {
|
||||
|
||||
return sigitInfo
|
||||
} catch (error) {
|
||||
if (error instanceof MetaParseError) {
|
||||
if (error instanceof SigitMetaParseError) {
|
||||
toast.error(error.message)
|
||||
console.error(error.name, error.message, error.cause, error.context)
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user