fix(challenge-modal): publish challenge answers with pkc object schema

pkc-js's publishChallengeAnswers destructures { challengeAnswers } from its
argument, so passing a bare string[] left challengeAnswers undefined and
silently broke challenge submission (i.e. posting). Wrap answers in the object
form via a publishPublicationChallengeAnswers helper with error logging, and
align the ChallengePublication type with the real runtime signature.
This commit is contained in:
Tommaso Casaburi
2026-06-13 18:25:04 +07:00
parent ded239bef2
commit 591aaa729f
3 changed files with 31 additions and 14 deletions
+10 -1
View File
@@ -13,19 +13,28 @@ const resolveBoardIdentifier = (communityAddress: unknown): string => {
return boardPath === communityAddress ? communityAddress : `/${boardPath}/`;
};
export type ChallengePublication = Partial<Comment> & {
type ChallengeAnswersInput = string[] | { challengeAnswers?: string[] };
export type ChallengePublication = Partial<Omit<Comment, 'publishChallengeAnswers'>> & {
author?: unknown;
commentCid?: string;
communityAddress?: string;
content?: string;
link?: string;
parentCid?: string;
publishChallengeAnswers?: (challengeAnswers?: ChallengeAnswersInput) => Promise<void> | void;
shortCommunityAddress?: string;
subplebbitAddress?: string;
title?: string;
vote?: number;
};
export const publishPublicationChallengeAnswers = async (publication: ChallengePublication | undefined, challengeAnswers: string[]) => {
const publishChallengeAnswers = publication?.publishChallengeAnswers;
if (typeof publishChallengeAnswers !== 'function') return;
await publishChallengeAnswers.call(publication, { challengeAnswers });
};
export const redactGeneratedFortuneFromPublication = <T>(publication: T): T => {
if (!publication || typeof publication !== 'object') {
return publication;