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

feature: change the way the client manages the environment internally, and its urls #243

Open
elboletaire opened this issue Aug 22, 2023 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@elboletaire
Copy link
Member

elboletaire commented Aug 22, 2023

Describe the feature

I'm currently adding tests to chakra-components library, and I have had to copy-paste the constants of the urls, so I can properly test behavior changes (like, if I set a proper environment). Since the only way to see these kind of changes right now is by checking the defined urls, I ended up copy-pasting these constants to my tests, so I could make em.

A better solution would be to have the environment set internally in the VocdoniSDKClient instance, and be able to access it, but this implies changing the way the urls are accessed internally (since right now they are defined when creating the instance).

Motivation

Testing

Proposal

I think the best approach is to change the way we're using the environment internally.

IMHO we should allow setting each available URL in an (optional) associative array in the constructor. We could maintain the env argument, as something optional, that could automatically set these URLs based on our current environments.

export type ClientOptions = {
  env?: EnvOptions;
  wallet?: Wallet | Signer;
  electionId?: string;
  faucet?: FaucetOptions;
  tx_wait?: TxWaitOptions;
  urls?: Partial<ApiUris>
};

export type ApiUris = {
  main: string;
  faucet: string;
  // maybe some aren't required actually, this is just an example and you can organize the defaults as you want
  explorer: string;
  // [...]
};

// somewhere have a const with default urls set as type ApiUris

// then, in the constructor...
constructor(opts: ClientOptions) {
  if (!opts.env && !opts.urls) {
    throw Error()
  }
  // use opts.url as default values.
  // if none are passed, use `env` to define defaults
  // [...]
}

Note that, for the part of the urls, instead of creating the urls every time on each call, an axios instance with the baseUrl defined could be created when creating the VocdoniSDKClient, and then use that instance for the calls, removing the need to create the urls using the defined base every single time.

Components affected

  • client.ts
  • census3.ts
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
None yet
Development

No branches or pull requests

2 participants