From 6e44d11a60fc052c6c306150d9691e7a14854672 Mon Sep 17 00:00:00 2001 From: "plebeius.eth" Date: Thu, 25 Jan 2024 15:31:20 +0100 Subject: [PATCH 01/16] style(subplebbits): replace edit button with settings --- src/views/subplebbits/subplebbits.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/views/subplebbits/subplebbits.tsx b/src/views/subplebbits/subplebbits.tsx index 88f3d597..2ca15f11 100644 --- a/src/views/subplebbits/subplebbits.tsx +++ b/src/views/subplebbits/subplebbits.tsx @@ -150,7 +150,7 @@ const Subplebbit = ({ subplebbit }: SubplebbitProps) => { )} - {isUserOwner ? t('edit') : t('settings')} + {t('settings')} From 82169943b26d889bf7553bd9ddb2f119d39e318f Mon Sep 17 00:00:00 2001 From: "plebeius.eth" Date: Thu, 25 Jan 2024 16:33:04 +0100 Subject: [PATCH 02/16] feat(subplebbit settings): allow to define custom challenges in default types, using strings as values --- src/lib/utils/challenge-utils.ts | 19 +++ .../subplebbit-settings.tsx | 148 +++++------------- src/views/subplebbits/subplebbits.tsx | 1 - 3 files changed, 58 insertions(+), 110 deletions(-) diff --git a/src/lib/utils/challenge-utils.ts b/src/lib/utils/challenge-utils.ts index c19be05b..6fad2311 100644 --- a/src/lib/utils/challenge-utils.ts +++ b/src/lib/utils/challenge-utils.ts @@ -73,6 +73,25 @@ export const getDefaultExclude = () => { ]; }; +export const getDefaultChallengeDescription = (challengeType: string) => { + switch (challengeType) { + case 'text-math': + return 'Ask a plain text math question, insecure, use ONLY for testing.'; + case 'captcha-canvas-v3': + return 'Make a custom image captcha'; + case 'fail': + return 'A challenge that automatically fails with a custom error message.'; + case 'blacklist': + return 'Blacklist author addresses.'; + case 'question': + return "Ask a question, like 'What is the password?'"; + case 'evm-contract-call': + return 'The response from an EVM contract call passes a condition, e.g. a token balance challenge.'; + default: + return ''; + } +}; + export const getDefaultOptionInputs = (challengeType: string) => { switch (challengeType) { case 'text-math': diff --git a/src/views/subplebbit/subplebbit-settings/subplebbit-settings.tsx b/src/views/subplebbit/subplebbit-settings/subplebbit-settings.tsx index 1bc3a3fa..807ca7f8 100644 --- a/src/views/subplebbit/subplebbit-settings/subplebbit-settings.tsx +++ b/src/views/subplebbit/subplebbit-settings/subplebbit-settings.tsx @@ -6,7 +6,7 @@ import { useTranslation } from 'react-i18next'; import { create } from 'zustand'; import styles from './subplebbit-settings.module.css'; import { isValidURL } from '../../../lib/utils/url-utils'; -import { getDefaultExclude, getDefaultOptionInputs } from '../../../lib/utils/challenge-utils'; +import { getDefaultChallengeDescription, getDefaultExclude, getDefaultOptionInputs } from '../../../lib/utils/challenge-utils'; import LoadingEllipsis from '../../../components/loading-ellipsis'; import Sidebar from '../../../components/sidebar'; @@ -292,119 +292,49 @@ const challengesNames = ['text-math', 'captcha-canvas-v3', 'fail', 'blacklist', interface ChallengeSettingsProps { challenge: any; + index: number; + setSubmitStore: (data: Partial) => void; + settings: any; showSettings: boolean; } -const ChallengeSettings = ({ challenge, showSettings }: ChallengeSettingsProps) => { - const { name } = challenge || {}; +type OptionInput = { + option: string; + value?: string; + label: string; + default?: string; + description: string; + placeholder?: string; + required?: boolean; +}; + +const ChallengeSettings = ({ challenge, index, setSubmitStore, settings, showSettings }: ChallengeSettingsProps) => { + const { name, optionInputs } = challenge || {}; + + const handleOptionChange = (optionName: string, newValue: string) => { + const updatedOptionInputs = optionInputs.map((input: any) => (input.option === optionName ? { ...input, value: newValue } : input)); + + const updatedChallenges = settings.challenges.map((ch: any, idx: number) => (idx === index ? { ...ch, optionInputs: updatedOptionInputs } : ch)); + + setSubmitStore({ settings: { ...settings, challenges: updatedChallenges } }); + }; return (
- {name === 'text-math' && ( - <> -
Ask a plain text math question, insecure, use ONLY for testing.
-
- Difficulty -
The math difficulty of the challenge between 1-3.
- -
- - )} - {name === 'captcha-canvas-v3' && ( - <> -
Make a custom image captcha
-
- Characters -
Amount of characters of the captcha.
- -
-
- Width -
Height of the captcha.
- -
-
- Height -
Width of the captcha.
- -
-
- Color -
Color of the captcha.
- -
- - )} - {name === 'fail' && ( - <> -
A challenge that automatically fails with a custom error message.
-
- Error -
The error to display to the author.
- -
- - )} - {name === 'blacklist' && ( - <> -
Blacklist author addresses.
-
- Blacklist -
Comma separated list of author addresses to be blacklisted.
- -
-
- Error -
The error to display to the author.
- -
- - )} - {name === 'question' && ( - <> -
Ask a question, like 'What is the password?'
-
- Question -
The question to answer.
- -
-
- Answer -
The answer to the question.
- -
- - )} - {name === 'evm-contract-call' && ( - <> -
The response from an EVM contract call passes a condition, e.g. a token balance challenge.
-
- chainTicker -
The chain ticker
- -
-
- Address -
The contract address.
- -
-
- ABI -
The ABI of the contract method.
-