From 6053994c5ce76a602dedad8c40c41a288dde7f61 Mon Sep 17 00:00:00 2001 From: banklesss <105349292+banklesss@users.noreply.github.com> Date: Fri, 8 Nov 2024 12:34:12 +0100 Subject: [PATCH] refactor(wallet-metadata): new tx review metadata (#3728) --- .../common/hooks/useFormattedMetadata.tsx | 24 +++++++++---------- .../ConfirmWithSpendingPassword.tsx | 1 + 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/apps/wallet-mobile/src/features/ReviewTx/common/hooks/useFormattedMetadata.tsx b/apps/wallet-mobile/src/features/ReviewTx/common/hooks/useFormattedMetadata.tsx index 8478c7ca16..8f7aeabc91 100644 --- a/apps/wallet-mobile/src/features/ReviewTx/common/hooks/useFormattedMetadata.tsx +++ b/apps/wallet-mobile/src/features/ReviewTx/common/hooks/useFormattedMetadata.tsx @@ -15,24 +15,22 @@ export const formatMetadata = async ( try { const hash = txBody.auxiliary_data_hash ?? null - let metadata = null + let generalTransactionMetadata = null - if (unsignedTx != null) { - // eslint-disable-next-line @typescript-eslint/no-explicit-any - const msg = unsignedTx.metadata?.['674']?.['msg' as any] ?? JSON.stringify({}) - metadata = hash != null && typeof msg == 'string' ? {msg: [JSON.parse(msg) as unknown]} : null - } else if (cbor != null) { + if (unsignedTx != null && unsignedTx.unsignedTx.auxiliaryData && hash != null) { + generalTransactionMetadata = await unsignedTx.unsignedTx.auxiliaryData?.metadata() + } else if (cbor != null && hash != null) { const tx = await csl.Transaction.fromBytes(Buffer.from(cbor, 'hex')) const auxiliaryData = await tx.auxiliaryData() - const generalTransactionMetadata = await auxiliaryData?.metadata() - const metadata674 = await generalTransactionMetadata?.get(await csl.BigNum.fromStr('674')) + generalTransactionMetadata = await auxiliaryData?.metadata() + } - if (metadata674) { - const decodedMetadata = await csl.decodeMetadatumToJsonStr(metadata674, MetadataJsonSchema.BasicConversions) - const msg = JSON.parse(decodedMetadata)?.msg ?? JSON.stringify({}) - metadata = hash != null ? {msg: [msg]} : null - } + const metadata674 = await generalTransactionMetadata?.get(await csl.BigNum.fromStr('674')) + if (metadata674) { + const decodedMetadata = await csl.decodeMetadatumToJsonStr(metadata674, MetadataJsonSchema.BasicConversions) + const msg = JSON.parse(decodedMetadata)?.msg ?? '' + metadata = {msg} } return { diff --git a/apps/wallet-mobile/src/features/Swap/common/ConfirmWithSpendingPassword/ConfirmWithSpendingPassword.tsx b/apps/wallet-mobile/src/features/Swap/common/ConfirmWithSpendingPassword/ConfirmWithSpendingPassword.tsx index 114d756e7a..b7d7a390f9 100644 --- a/apps/wallet-mobile/src/features/Swap/common/ConfirmWithSpendingPassword/ConfirmWithSpendingPassword.tsx +++ b/apps/wallet-mobile/src/features/Swap/common/ConfirmWithSpendingPassword/ConfirmWithSpendingPassword.tsx @@ -77,6 +77,7 @@ const useStyles = () => { const styles = StyleSheet.create({ root: { ...atoms.flex_1, + ...atoms.px_lg, }, modalText: { paddingHorizontal: 70,