mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
fix(hooks): handle pkc rebrand regressions
This commit is contained in:
@@ -7,6 +7,8 @@ describe('buildEditableAccountJson', () => {
|
||||
id: 'abc',
|
||||
name: 'Account 1',
|
||||
author: { address: '0x123', shortAddress: '0x1...3', avatar: { url: 'https://example.com' } },
|
||||
pkc: { someOption: true },
|
||||
pkcReactOptions: { foo: 'baz' },
|
||||
plebbit: { someOption: true },
|
||||
karma: 42,
|
||||
plebbitReactOptions: { foo: 'bar' },
|
||||
@@ -17,6 +19,8 @@ describe('buildEditableAccountJson', () => {
|
||||
expect(result.account.name).toBe('Account 1');
|
||||
expect(result.account.author.address).toBe('0x123');
|
||||
expect(result.account.author.avatar).toBeUndefined();
|
||||
expect(result.account.pkc).toBeUndefined();
|
||||
expect(result.account.pkcReactOptions).toBeUndefined();
|
||||
expect(result.account.plebbit).toBeUndefined();
|
||||
expect(result.account.karma).toBeUndefined();
|
||||
expect(result.account.plebbitReactOptions).toBeUndefined();
|
||||
|
||||
@@ -50,6 +50,18 @@ describe('challenge-utils', () => {
|
||||
expect(alertMock).toHaveBeenCalledWith('Error from unknown-board.eth: first error second error');
|
||||
});
|
||||
|
||||
it('uses communityAddress when the upgraded publication no longer exposes subplebbitAddress', () => {
|
||||
alertChallengeVerificationFailed(
|
||||
{
|
||||
challengeErrors: ['first error'],
|
||||
challengeSuccess: false,
|
||||
} as never,
|
||||
{ communityAddress: 'business-and-finance.bso' },
|
||||
);
|
||||
|
||||
expect(alertMock).toHaveBeenCalledWith('Error from /biz/: first error');
|
||||
});
|
||||
|
||||
it('warns about invalid challenge error payloads and falls back to an unknown error', () => {
|
||||
alertChallengeVerificationFailed(
|
||||
{
|
||||
|
||||
@@ -4,6 +4,8 @@ type AccountLike = {
|
||||
id?: string;
|
||||
name?: string;
|
||||
author?: { address?: string; shortAddress?: string; avatar?: unknown };
|
||||
pkc?: unknown;
|
||||
pkcReactOptions?: unknown;
|
||||
plebbit?: unknown;
|
||||
karma?: unknown;
|
||||
plebbitReactOptions?: unknown;
|
||||
@@ -19,6 +21,8 @@ export const buildEditableAccountJson = (account: AccountLike | undefined): stri
|
||||
account: {
|
||||
...account,
|
||||
author: { ...account?.author, avatar: undefined },
|
||||
pkc: undefined,
|
||||
pkcReactOptions: undefined,
|
||||
plebbit: undefined,
|
||||
karma: undefined,
|
||||
plebbitReactOptions: undefined,
|
||||
|
||||
@@ -2,13 +2,13 @@ import { ChallengeVerification } from '@bitsocialnet/bitsocial-react-hooks';
|
||||
import directoriesData from '../../data/5chan-directories.json';
|
||||
import { getBoardPath } from './route-utils';
|
||||
|
||||
const resolveBoardIdentifier = (subplebbitAddress: unknown): string => {
|
||||
if (typeof subplebbitAddress !== 'string' || !subplebbitAddress) {
|
||||
const resolveBoardIdentifier = (communityAddress: unknown): string => {
|
||||
if (typeof communityAddress !== 'string' || !communityAddress) {
|
||||
return 'unknown board';
|
||||
}
|
||||
|
||||
const boardPath = getBoardPath(subplebbitAddress, directoriesData.communities);
|
||||
return boardPath === subplebbitAddress ? subplebbitAddress : `/${boardPath}/`;
|
||||
const boardPath = getBoardPath(communityAddress, directoriesData.communities);
|
||||
return boardPath === communityAddress ? communityAddress : `/${boardPath}/`;
|
||||
};
|
||||
|
||||
export const alertChallengeVerificationFailed = (challengeVerification: ChallengeVerification, publication: any) => {
|
||||
@@ -35,8 +35,9 @@ export const alertChallengeVerificationFailed = (challengeVerification: Challeng
|
||||
}
|
||||
|
||||
const finalMessage = errorMessages.filter(Boolean).join(' ');
|
||||
const publicationCommunityAddress = publication?.communityAddress || publication?.subplebbitAddress;
|
||||
|
||||
alert(`Error from ${resolveBoardIdentifier(publication?.subplebbitAddress)}: ${finalMessage || 'unknown error'}`);
|
||||
alert(`Error from ${resolveBoardIdentifier(publicationCommunityAddress)}: ${finalMessage || 'unknown error'}`);
|
||||
} else {
|
||||
console.log('Challenge verification succeeded:', challengeVerification);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user