feat(actions): add community export hook#62
Conversation
📝 WalkthroughWalkthroughThis PR introduces community export functionality by adding a new ChangesCommunity Export Feature
Sequence DiagramsequenceDiagram
participant Component
participant useExportCommunity
participant accountsActions
participant Community
Component->>useExportCommunity: exportCommunity(addresses)
activate useExportCommunity
useExportCommunity->>useExportCommunity: setState("exporting")
useExportCommunity->>accountsActions: exportCommunity(addresses)
activate accountsActions
accountsActions->>accountsActions: validate & deduplicate addresses
loop for each address
accountsActions->>Community: createPkcCommunity(address)
accountsActions->>Community: export(options)
activate Community
Community->>Community: append exportRecord
Community->>Community: emit "exportschange"
Community-->>accountsActions: { exportId }
deactivate Community
end
accountsActions-->>useExportCommunity: CommunityExport[]
deactivate accountsActions
useExportCommunity->>useExportCommunity: setState("succeeded")
useExportCommunity->>useExportCommunity: setCommunityExports(results)
useExportCommunity-->>Component: { communityExports, state: "succeeded" }
deactivate useExportCommunity
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
src/types.ts (1)
594-606: ⚡ Quick winTighten the shared export contracts to avoid type erosion.
At Line 594 and Line 606,
[key: string]: anyweakens the new cross-layer contract and can hide payload drift between hook/store/mock. Prefer explicit fields plusunknownfor extensibility.♻️ Proposed contract tightening
-export type ExportCommunityOptions = { [key: string]: any }; +export interface ExportCommunityOptions { + includePrivateKey?: boolean; + exportPath?: string; + signal?: AbortSignal; + [key: string]: unknown; +} -export type CommunityExport = { communityAddress: string; exportId: string; [key: string]: any }; +export type CommunityExport = { + communityAddress: string; + exportId: string; + name?: string; + publicKey?: string; + includePrivateKey?: boolean; + progress?: number; + url?: string; + [key: string]: unknown; +};🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/types.ts` around lines 594 - 606, Replace the overly permissive {[key: string]: any} index signatures across the exported types (ExportCommunityOptions, Challenge, ChallengeVerification, CreateCommentOptions, CreateCommunityOptions, CreateVoteOptions, Comment, Vote, CommentEdit, CommentModeration, CommunityEdit, Community, CommunityExport) with tightened contracts: declare explicit known fields for each type and use unknown (or Record<string, unknown>) for any additional extensibility, e.g., change trailing any-indexes to Record<string, unknown> or an explicit optional extras field to prevent silent payload drift while preserving forward-compatibility.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@README.md`:
- Line 174: Update the README's useExportCommunity signature to match the actual
public contract: replace the generic return shown as {communityExports:
{communityAddress: string, exportId: string}[], exportCommunity: Function} with
the full UseExportCommunityResult shape used in src/types.ts, and document
exportCommunity as an async function (exportCommunity(): Promise<void>) that
also exposes Result fields; ensure you reference the UseExportCommunityResult
type and the useExportCommunity hook name so the docs match the hook
implementation and exported types.
In `@src/stores/accounts/accounts-actions.ts`:
- Around line 815-819: The log call in accountsActions.exportCommunity currently
prints full payloads (communityAddresses, exportCommunityOptions,
communityExports) which can contain private keys; change the export logging to
avoid raw objects by either omitting/redacting sensitive fields (e.g., do not
log privateKey or when exportCommunityOptions.includePrivateKey is true) or
replace the payloads with a sanitized summary (counts, flags) before calling
log("accountsActions.exportCommunity", ...); specifically update the code around
the log invocation to inspect exportCommunityOptions and communityExports and
only include non-sensitive metadata or masked values rather than the full
objects.
---
Nitpick comments:
In `@src/types.ts`:
- Around line 594-606: Replace the overly permissive {[key: string]: any} index
signatures across the exported types (ExportCommunityOptions, Challenge,
ChallengeVerification, CreateCommentOptions, CreateCommunityOptions,
CreateVoteOptions, Comment, Vote, CommentEdit, CommentModeration, CommunityEdit,
Community, CommunityExport) with tightened contracts: declare explicit known
fields for each type and use unknown (or Record<string, unknown>) for any
additional extensibility, e.g., change trailing any-indexes to Record<string,
unknown> or an explicit optional extras field to prevent silent payload drift
while preserving forward-compatibility.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: f4d7fecc-566e-43d6-9430-421721a67cb6
⛔ Files ignored due to path filters (1)
yarn.lockis excluded by!**/yarn.lock,!**/*.lock
📒 Files selected for processing (10)
README.mdllms-full.txtpackage.jsonsrc/hooks/actions/actions.test.tssrc/hooks/actions/actions.tssrc/index.tssrc/lib/pkc-js/pkc-js-mock.tssrc/stores/accounts/accounts-actions.test.tssrc/stores/accounts/accounts-actions.tssrc/types.ts
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 14b96b0. Configure here.
| setExportingState("failed"); | ||
| setErrors((errors) => [...errors, e]); | ||
| onError?.(e); | ||
| } |
There was a problem hiding this comment.
Stale export overwrites newer run
High Severity
exportCommunity applies setCommunityExports, setExportingState, and error updates when the awaited store call finishes, without checking that the export still matches the active exportingContext. A slower earlier export can finish after a later one starts and show the wrong communities as succeeded or failed.
Reviewed by Cursor Bugbot for commit 14b96b0. Configure here.
| setExportingState("failed"); | ||
| setErrors((errors) => [...errors, e]); | ||
| onError?.(e); | ||
| } |
There was a problem hiding this comment.
Success keeps prior export error
Medium Severity
Calling exportCommunity again after a failure does not reset errors, yet error still exposes errors[errors.length - 1] whenever hasCurrentExportState is true. A later successful run can leave state as succeeded while error still reflects the earlier failure.
Reviewed by Cursor Bugbot for commit 14b96b0. Configure here.
|
Review feedback handled in the latest commits:
Verification:
Local |


Summary
@pkcprotocol/pkc-jsto0.0.41.accountsActions.exportCommunity()anduseExportCommunity()for one, many, or all account communities.Verification
yarn buildyarn testyarn test:coverageNote:
node scripts/verify-hooks-stores-coverage.mjsstill reports existing repo-wide hooks/stores coverage gaps outside this feature.Note
Medium Risk
Touches account actions and optional private-key export via upgraded pkc-js; well-covered by tests but desktop/export paths warrant careful review.
Overview
Adds desktop community export end-to-end: bumps
@pkcprotocol/pkc-jsto 0.0.41, implementsaccountsActions.exportCommunity()(single address, list, or default to all PKC-listed communities; concurrent exports; optionalincludePrivateKey/exportPath), and exposesuseExportCommunity()withstate/error/communityExportsand context-aware clearing when the account or export targets change.Public API updates include new
ExportCommunityOptions/CommunityExporttypes, package exports, README and LLM docs recipes, and mockCommunity.exportfor tests.Reviewed by Cursor Bugbot for commit 14b96b0. Bugbot is set up for automated code reviews on this repo. Configure here.
Summary by CodeRabbit
New Features
useExportCommunityhook enabling users to export single, multiple, or all communities associated with their accountDocumentation
Chores
@pkcprotocol/pkc-jsdependency to v0.0.41