Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement usePlebbitRpcSettings #335

Open
plebeius-eth opened this issue Apr 15, 2024 · 5 comments
Open

implement usePlebbitRpcSettings #335

plebeius-eth opened this issue Apr 15, 2024 · 5 comments
Assignees
Labels
enhancement New feature or request

Comments

@plebeius-eth
Copy link
Member

plebeius-eth commented Apr 15, 2024

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.

@plebeius-eth plebeius-eth self-assigned this Apr 15, 2024
@plebeius-eth plebeius-eth added the enhancement New feature or request label Apr 15, 2024
@plebeius-eth
Copy link
Member Author

52cf63a
ea7853b

@estebanabaroa
Copy link
Member

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 '';
  }
};

@estebanabaroa estebanabaroa reopened this May 31, 2024
@plebeius-eth
Copy link
Member Author

fixed ad7a893

@estebanabaroa
Copy link
Member

estebanabaroa commented Jun 9, 2024

seems like the challenge names are still hard coded?

const challengesNames = ['text-math', 'captcha-canvas-v3', 'fail', 'blacklist', 'question', 'evm-contract-call'];

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.

@estebanabaroa estebanabaroa reopened this Jun 9, 2024
@estebanabaroa
Copy link
Member

estebanabaroa commented Jun 9, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: In Progress
Development

No branches or pull requests

2 participants