From 782b4bb2d95e4d0a38e250628867922e8cf3026d Mon Sep 17 00:00:00 2001 From: lukachi Date: Tue, 21 May 2024 17:41:59 +0300 Subject: [PATCH] fix proposal metadata parsing --- CHANGELOG.md | 7 ++++++- package.json | 2 +- src/hooks/useProposalMetadata.ts | 14 ++++++-------- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f0b9d65..1ba3130 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,10 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog], and this project adheres to [Semantic Versioning]. +## [1.4.7] - 2024-05-21 +### Fixed +- `useProposalMetadata` hook + ## [1.4.6] - 2024-05-17 ### Fixed - `useTablePagination` hook @@ -128,7 +132,8 @@ The format is based on [Keep a Changelog], and this project adheres to [Semantic - Initiated project -[Unreleased]: https://gitlab.com/rarimo/scan/compare/1.4.6...HEAD +[Unreleased]: https://gitlab.com/rarimo/scan/compare/1.4.7...HEAD +[1.4.7]: https://gitlab.com/rarimo/scan/compare/1.4.6...1.4.7 [1.4.6]: https://gitlab.com/rarimo/scan/compare/1.4.5...1.4.6 [1.4.5]: https://gitlab.com/rarimo/scan/compare/1.4.4...1.4.5 [1.4.4]: https://gitlab.com/rarimo/scan/compare/1.4.3...1.4.4 diff --git a/package.json b/package.json index dd38d73..380980a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "scan", - "version": "1.4.6", + "version": "1.4.7", "private": true, "gitHooks": { "pre-commit": "yarn lint", diff --git a/src/hooks/useProposalMetadata.ts b/src/hooks/useProposalMetadata.ts index ad86e92..bf39516 100644 --- a/src/hooks/useProposalMetadata.ts +++ b/src/hooks/useProposalMetadata.ts @@ -19,6 +19,8 @@ export const useProposalMetadata = (proposal?: ProposalBaseFragment | ProposalFr return PROPOSAL_TYPES_MAP[key as keyof typeof PROPOSAL_TYPES_MAP] } } + + return undefined } const proposalType = useMemo(() => { @@ -26,11 +28,9 @@ export const useProposalMetadata = (proposal?: ProposalBaseFragment | ProposalFr const content = proposal?.content - if (isContentArray) { - return getProposalType(content[0]?.content?.['@type'] ?? '') - } + const proposalType = isContentArray ? content[0]?.content?.['@type'] : content?.['@type'] - return getProposalType(content?.['@type'] ?? '') + return getProposalType(proposalType ?? '') }, [proposal, isContentArray]) const proposalTypesLocalized = useMemo(() => { @@ -69,8 +69,6 @@ export const useProposalMetadata = (proposal?: ProposalBaseFragment | ProposalFr if (metadata.title && metadata.description) return metadata - let parseErr = false - if (proposal?.metadata) { try { const parsedMetadata = JSON.parse(proposal.metadata) @@ -81,11 +79,11 @@ export const useProposalMetadata = (proposal?: ProposalBaseFragment | ProposalFr metadata.description = parsedMetadata.description } } catch (e) { - parseErr = true + /* empty */ } } - if (proposal?.metadata && !parseErr) return metadata + return metadata }, [proposal, localizeProposalType, proposalType, t, isContentArray]) return { metadata, proposalTypesLocalized }