setEnvironment function

void setEnvironment(
  1. String env,
  2. String? web3ApiKey, {
  3. EnvParams? envParams,
})

Sets an environment from a supported environment configuration or from a custom environment object @param {String} env - Supported environment name @param {String} web3ApiKey - Web3 api key @param optional {EnvParams} envParams - Custom environment object, only used when env value is 'custom'

Implementation

void setEnvironment(String env, String? web3ApiKey, {EnvParams? envParams}) {
  if (env == null) {
    throw new ArgumentError('A environment is required');
  }

  if (env != 'custom' && (web3ApiKey == null || web3ApiKey.isEmpty)) {
    throw new ArgumentError('A web3 api key is required');
  }

  if (!getSupportedEnvironments().contains(env)) {
    throw new ArgumentError('Environment not supported');
  }

  if (env == 'custom' && envParams != null) {
    params = envParams;
  } else {
    params = Env(web3ApiKey: web3ApiKey!).params[env];
  }

  coordinatorApi.setBaseApiUrl(params!.baseApiUrl);
}