W3MService constructor

W3MService({
  1. BuildContext? context,
  2. IWeb3App? web3App,
  3. String? projectId,
  4. PairingMetadata? metadata,
  5. SIWEConfig? siweConfig,
  6. Map<String, W3MNamespace>? requiredNamespaces,
  7. Map<String, W3MNamespace>? optionalNamespaces,
  8. Set<String>? featuredWalletIds,
  9. Set<String>? includedWalletIds,
  10. Set<String>? excludedWalletIds,
  11. bool? enableAnalytics,
  12. bool enableEmail = false,
  13. LogLevel logLevel = LogLevel.nothing,
})

context is required if SIWEConfig is passed.

Implementation

W3MService({
  BuildContext? context,
  IWeb3App? web3App,
  String? projectId,
  PairingMetadata? metadata,
  SIWEConfig? siweConfig,
  Map<String, W3MNamespace>? requiredNamespaces,
  Map<String, W3MNamespace>? optionalNamespaces,
  Set<String>? featuredWalletIds,
  Set<String>? includedWalletIds,
  Set<String>? excludedWalletIds,
  bool? enableAnalytics,
  bool enableEmail = false,
  LogLevel logLevel = LogLevel.nothing,
}) {
  if (web3App == null) {
    if (projectId == null) {
      throw W3MServiceException(
        'Either a `projectId` and `metadata` must be provided or an already created `web3App`',
      );
    }
    if (metadata == null) {
      throw W3MServiceException(
        '`metadata:` parameter is required when using `projectId:`',
      );
    }
  }
  if (siweConfig?.enabled == true && context == null) {
    throw W3MServiceException(
      '`context:` parameter is required if using `siweConfig:`. Also, `context:` parameter will be enforced in future versions.',
    );
  }

  _context = context;

  _web3App = web3App ??
      Web3App(
        core: Core(projectId: projectId!),
        metadata: metadata!,
      );
  _projectId = _web3App.core.projectId;

  loggerService.instance = LoggerService(
    level: logLevel,
    debugMode: kDebugMode,
  );

  _setRequiredNamespaces(requiredNamespaces);
  _setOptionalNamespaces(optionalNamespaces);

  analyticsService.instance = AnalyticsService(
    projectId: _projectId,
    enableAnalytics: enableAnalytics,
  )..init().then((_) {
      analyticsService.instance.sendEvent(ModalLoadedEvent());
    });

  explorerService.instance = ExplorerService(
    core: _web3App.core,
    referer: _web3App.metadata.name.replaceAll(' ', ''),
    featuredWalletIds: featuredWalletIds,
    includedWalletIds: includedWalletIds,
    excludedWalletIds: excludedWalletIds,
  );

  blockchainService.instance = BlockChainService(
    core: _web3App.core,
  );

  magicService.instance = MagicService(
    web3app: _web3App,
    enabled: enableEmail,
  );

  coinbaseService.instance = CoinbaseService(
    metadata: _web3App.metadata,
    enabled: _initializeCoinbaseSDK,
  );

  siweService.instance = SiweService(
    web3app: _web3App,
    siweConfig: siweConfig,
  );
}