Skip to content

Commit

Permalink
fix proposal metadata parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
lukachi committed May 21, 2024
1 parent 16d9945 commit 782b4bb
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "scan",
"version": "1.4.6",
"version": "1.4.7",
"private": true,
"gitHooks": {
"pre-commit": "yarn lint",
Expand Down
14 changes: 6 additions & 8 deletions src/hooks/useProposalMetadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@ export const useProposalMetadata = (proposal?: ProposalBaseFragment | ProposalFr
return PROPOSAL_TYPES_MAP[key as keyof typeof PROPOSAL_TYPES_MAP]
}
}

return undefined
}

const proposalType = useMemo(() => {
if (!proposal) return ''

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(() => {
Expand Down Expand Up @@ -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)
Expand All @@ -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 }
Expand Down

0 comments on commit 782b4bb

Please sign in to comment.