From a72bc2a09d37a276e60adfd6e44af5e328a3d720 Mon Sep 17 00:00:00 2001 From: SorinC6 Date: Mon, 16 Oct 2023 22:22:28 +0300 Subject: [PATCH] added parse safe helper --- .../src/features/Swap/common/helpers.ts | 13 +++---------- apps/wallet-mobile/src/yoroi-wallets/types/other.ts | 2 +- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/apps/wallet-mobile/src/features/Swap/common/helpers.ts b/apps/wallet-mobile/src/features/Swap/common/helpers.ts index 25dc941e2d..c4e7221e0d 100644 --- a/apps/wallet-mobile/src/features/Swap/common/helpers.ts +++ b/apps/wallet-mobile/src/features/Swap/common/helpers.ts @@ -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' @@ -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' @@ -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 } diff --git a/apps/wallet-mobile/src/yoroi-wallets/types/other.ts b/apps/wallet-mobile/src/yoroi-wallets/types/other.ts index 8b04a2985c..cf19fef102 100644 --- a/apps/wallet-mobile/src/yoroi-wallets/types/other.ts +++ b/apps/wallet-mobile/src/yoroi-wallets/types/other.ts @@ -417,7 +417,7 @@ export type TransactionInfo = { tokens: Record blockNumber: number memo: null | string - metadata: TxMetadataInfo | undefined + metadata: TxMetadataInfo } export type IOData = {