Open plebeius-eth opened 4 months ago
52cf63a497fd5131e3b50d8af7fcf8a6ef61eb7d ea7853be63a9f7604ce579d7469ad09885b2ebc8
you shouldnt hardcode challenge options like
export const getDefaultChallengeOptions = (challengeType: string) => {
switch (challengeType) {
case 'text-math':
return {
difficulty: '',
};
case 'captcha-canvas-v3':
return {
characters: '',
height: '',
width: '',
color: '',
};
case 'fail':
return {
error: '',
};
case 'blacklist':
return {
blacklist: '',
error: '',
};
case 'question':
return {
question: '',
answer: '',
};
case 'evm-contract-call':
return {
chainTicker: '',
address: '',
abi: '',
condition: '',
error: '',
};
default:
return {};
}
};
the challenge options should be dynamically provided by challenge.optionInputs. Is that value not there?
same with challenge description, this should not be hardcoded, it should be provided by challenge.description
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 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 '';
}
};
fixed ad7a8936cb158a934b53e012bc7741641edcdf0b
seems like the challenge names are still hard coded? https://github.com/plebbit/seedit/blob/ad7a8936cb158a934b53e012bc7741641edcdf0b/src/views/subplebbit/subplebbit-settings/subplebbit-settings.tsx#L358
everything should come from the plebbit-rpc, nothing should be hard coded, because the rpc will not necessarily have these challenge names, it might have more or less. even the default recommended challenge should probably not be hard coded, because the rpc will not necessarily support a challenge named 'captcha-canvas-v3'. can you make the UI work without a default recommended challenge?
I think it's fine to have a default challenge called 'captcha-canvas-v3' as long as the UI still works if the RPC doesn't offer this challenge, but it wont always offer it.
if you want to have a default challenge fallback, you could use something like:
const defaultChallengeName : string | undefined = challenges['captcha-canvas-v3'] ? 'captcha-canvas-v3' : Object.keys(challenges || {})[0]
this will use the first challenge name in the challenges object, it is possible for the challenges object to be empty, so for defaultChallengeName to be undefined, something to keep in mind. it would probably mean a buggy RPC, but the UI should still at least somewhat work if this happens.
also you shouldnt hardcode the default challenge options like https://github.com/plebbit/seedit/blob/ad7a8936cb158a934b53e012bc7741641edcdf0b/src/views/subplebbit/subplebbit-settings/subplebbit-settings.tsx#L929C1-L935C11
it's possible that the rpc has a challenge called 'captcha-canvas-v3' but with different options. if you want to use default challenge options you can use the default values provided by optionInputs
if any.
you really can't hardcode anything, the challenges provided by the plebbit rpc settings are completely arbitrary, they have to respect the type/schema, but nothing else, there could a challenge called 'captcha-canvas-v3' that doesn't do captchas at all and has different options. it's up to the plebbit rpc to give a list of challenges with options they support.
in the subplebbit settings/create page, usePlebbitRpcSettings should be used to display the challenges in the challenges setting, instead of hardcoding the challenges. When creating a new sub, the default challenge should be displayed as set automatically.