WalletConnect / Web3ModalFlutter

The Web3Modal for WalletConnect built using Flutter.
https://pub.dev/packages/web3modal_flutter
Apache License 2.0
44 stars 44 forks source link

W3MService made app freezed when hard-reloading #150

Closed mthinh closed 4 months ago

mthinh commented 4 months ago

When I started building the app, it works just fine. If I do the hard-reload, my app freezed

// Loggging
flutter: │ #0   LoggerService.d (package:web3modal_flutter/services/logger_service/logger_service.dart:49:13)
flutter: │ #1   ExplorerService._fetchListings (package:web3modal_flutter/services/explorer_service/explorer_service.dart:288:28)
flutter: │ #2   <asynchronous suspension>
flutter: │ #3   ExplorerService.getCoinbaseWalletObject (package:web3modal_flutter/services/explorer_service/explorer_service.dart:423:21)
flutter: │ #4   <asynchronous suspension>
flutter: │ #5   W3MService.init (package:web3modal_flutter/services/w3m_service/w3m_service.dart:206:24)
flutter: │ #6   <asynchronous suspension>
flutter: │ #7   WalletConnectService.init (package:app/core/service/wallet/wallet_connect_service.dart:90:7)
flutter: │ #8   <asynchronous suspension>
flutter: │ #9   main (package:app/main_staging.dart:30:5)
flutter: │ #10   <asynchronous suspension>
flutter: ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
flutter: │ 🐛 [ExplorerService] fetching https://api.web3modal.com/getWallets?page=1&entries=1&search=coinbase+wallet
// main.dart
void main() async {
 await w3mService.init();
 runApp(const MyApp());
}
 @override
  Future<void> init() async {
    _serviceInitialized = false;
    if (!coreUtils.instance.isValidProjectID(_projectId)) {
      loggerService.instance.e(
          '[$runtimeType] projectId $_projectId is invalid. Please provide a valid projectId. '
          'See https://docs.walletconnect.com/web3modal/flutter/options for details.');
      return;
    }
    if (_status == W3MServiceStatus.initializing ||
        _status == W3MServiceStatus.initialized) {
      return;
    }
    _status = W3MServiceStatus.initializing;
    _notify();

    _registerListeners();

    await storageService.instance.init();
    await networkService.instance.init();
    await explorerService.instance.init();
    if (_initializeCoinbaseSDK) {
      // final isInstalled = await cbIsInstalled();
      // Fetch Coinbase Wallet object to get updated metadata
      final cbWallet = await explorerService.instance.getCoinbaseWalletObject();

    ** I notice that when I do hard reload, this future is not resolved **
    // seems like we have issue with cbInit
      await cbInit(metadata: _web3App.metadata, cbWallet: cbWallet);
    }
quetool commented 4 months ago

Please could you try web3modal_flutter: ^3.3.0-beta06 instead? Also why are you initializing w3mService outside of runApp()?

// main.dart
void main() async {
 await w3mService.init();
 runApp(const MyApp());
}
mthinh commented 4 months ago

@quetool not sure if it's a bad practice ? cause I have global bloc which use w3mservice, so I wanna make sure it's initialized before the app is rendered

quetool commented 4 months ago

It's not a bad practice but not ideal in our case, W3MService uses a BuildContext internally (and it will be required in the future) so that might have some troubles. I would init it inside MyApp().

Anyway, have the issue been fixed by updating to latest beta?

quetool commented 4 months ago

Is this fixed, @mthinh ?

mthinh commented 4 months ago

@quetool yah i think it's fixed. May I know the reason behind ?

mthinh commented 4 months ago

It's not a bad practice but not ideal in our case, W3MService uses a BuildContext internally (and it will be required in the future) so that might have some troubles. I would init it inside MyApp().

Anyway, have the issue been fixed by updating to latest beta?

Nice advice, let me take a look on this

quetool commented 4 months ago

@quetool yah i think it's fixed. May I know the reason behind ?

Probably due to an issue on a thirty party SDK that got fixed and updated recently.