Skip to content

Commit

Permalink
added parse safe helper
Browse files Browse the repository at this point in the history
  • Loading branch information
SorinC6 committed Oct 16, 2023
1 parent b143bc2 commit a72bc2a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 11 deletions.
13 changes: 3 additions & 10 deletions apps/wallet-mobile/src/features/Swap/common/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {createTypeGuardFromSchema} from '@yoroi/common'
import {createTypeGuardFromSchema, parseSafe} from '@yoroi/common'
import {Swap} from '@yoroi/types'
import {SwapApi} from '@yoroi/types/src/swap/api'
import {useMutation, UseMutationOptions} from 'react-query'
Expand All @@ -11,7 +11,6 @@ import {
} from '../../../yoroi-wallets/cardano/common/signatureUtils'
import {YoroiWallet} from '../../../yoroi-wallets/cardano/types'
import {generateCIP30UtxoCbor} from '../../../yoroi-wallets/cardano/utils'
import {Logger} from '../../../yoroi-wallets/logging'
import {YoroiEntry} from '../../../yoroi-wallets/types'
import {Quantities} from '../../../yoroi-wallets/utils'

Expand Down Expand Up @@ -96,12 +95,6 @@ const isOrderTxMetadata = createTypeGuardFromSchema(OrderTxMetadataSchema)
* @returns The parsed metadata object or null if parsing fails or validation fails.
*/
export const parseOrderTxMetadata = (metadataJson: string): OrderTxMetadata | null => {
try {
const metadata = JSON.parse(metadataJson)

return isOrderTxMetadata(metadata) ? metadata : null
} catch (error) {
Logger.warn('JSON parsing error:', error)
return null
}
const parsedMetadata = parseSafe(metadataJson)
return isOrderTxMetadata(parsedMetadata) ? parsedMetadata : null
}
2 changes: 1 addition & 1 deletion apps/wallet-mobile/src/yoroi-wallets/types/other.ts
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ export type TransactionInfo = {
tokens: Record<string, Token>
blockNumber: number
memo: null | string
metadata: TxMetadataInfo | undefined
metadata: TxMetadataInfo
}

export type IOData = {
Expand Down

0 comments on commit a72bc2a

Please sign in to comment.