mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
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:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user