ReownAppKitModal constructor

ReownAppKitModal({
  1. required BuildContext context,
  2. IReownAppKit? appKit,
  3. String? projectId,
  4. PairingMetadata? metadata,
  5. bool? enableAnalytics,
  6. SIWEConfig? siweConfig,
  7. FeaturesConfig? featuresConfig,
  8. Map<String, RequiredNamespace>? requiredNamespaces,
  9. Map<String, RequiredNamespace>? optionalNamespaces,
  10. Set<String>? featuredWalletIds,
  11. Set<String>? includedWalletIds,
  12. Set<String>? excludedWalletIds,
  13. Future<double> getBalanceFallback()?,
  14. LogLevel logLevel = LogLevel.nothing,
})

Implementation

ReownAppKitModal({
  required BuildContext context,
  IReownAppKit? appKit,
  String? projectId,
  PairingMetadata? metadata,
  bool? enableAnalytics,
  SIWEConfig? siweConfig,
  FeaturesConfig? featuresConfig,
  Map<String, RequiredNamespace>? requiredNamespaces,
  Map<String, RequiredNamespace>? optionalNamespaces,
  Set<String>? featuredWalletIds,
  Set<String>? includedWalletIds,
  Set<String>? excludedWalletIds,
  Future<double> Function()? getBalanceFallback,
  LogLevel logLevel = LogLevel.nothing,
}) {
  if (appKit == null) {
    if (projectId == null) {
      throw ReownAppKitModalException(
        'Either a `projectId` and `metadata` must be provided or an already created `appKit`',
      );
    }
    if (metadata == null) {
      throw ReownAppKitModalException(
        '`metadata:` parameter is required when using `projectId:`',
      );
    }
  }

  this.featuresConfig = featuresConfig ?? FeaturesConfig(email: false);

  _context = context;
  _getBalance = getBalanceFallback;

  _appKit = appKit ??
      ReownAppKit(
        core: ReownCore(
          projectId: projectId!,
          logLevel: logLevel,
        ),
        metadata: metadata!,
      );
  _projectId = _appKit.core.projectId;

  // TODO should be moved to init()
  _setRequiredNamespaces(requiredNamespaces);
  _setOptionalNamespaces(optionalNamespaces);

  GetIt.I.registerSingletonIfAbsent<IUriService>(
    () => UriService(core: _appKit.core),
  );
  GetIt.I.registerSingletonIfAbsent<IAnalyticsService>(
    () => AnalyticsService(
      core: _appKit.core,
      enableAnalytics: enableAnalytics,
    ),
  );
  // TODO should be moved to init()
  _analyticsService.init().then(
        (_) => _analyticsService.sendEvent(ModalLoadedEvent()),
      );
  GetIt.I.registerSingletonIfAbsent<IExplorerService>(
    () => ExplorerService(
      core: _appKit.core,
      referer: _appKit.metadata.name.replaceAll(' ', ''),
      featuredWalletIds: featuredWalletIds,
      includedWalletIds: includedWalletIds,
      excludedWalletIds: excludedWalletIds,
      namespaces: {..._requiredNamespaces, ..._optionalNamespaces},
    ),
  );
  GetIt.I.registerSingletonIfAbsent<INetworkService>(() => NetworkService());
  GetIt.I.registerSingletonIfAbsent<IToastService>(() => ToastService());
  GetIt.I.registerSingletonIfAbsent<IBlockChainService>(
    () => BlockChainService(
      core: _appKit.core,
    ),
  );
  GetIt.I.registerSingletonIfAbsent<IMagicService>(
    () => MagicService(
      core: _appKit.core,
      metadata: _appKit.metadata,
      featuresConfig: this.featuresConfig,
    ),
  );
  GetIt.I.registerSingletonIfAbsent<ICoinbaseService>(
    () => CoinbaseService(
      core: _appKit.core,
      metadata: _appKit.metadata,
      enabled: _initializeCoinbaseSDK,
    ),
  );
  GetIt.I.registerSingletonIfAbsent<ISiweService>(
    () => SiweService(
      appKit: _appKit,
      siweConfig: siweConfig,
      namespaces: {..._requiredNamespaces, ..._optionalNamespaces},
    ),
  );
}