WalletConnect / Web3ModalFlutter

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

Error when calling Web3App.createInstance() #123

Closed kinggongzilla closed 6 days ago

kinggongzilla commented 2 weeks ago

Describe the bug An error LateError (LateInitializationError: Field '_web3App@594340753' has not been initialized.) is thrown when calling Web3App.createInstance().

This error occurs with version web3modal_flutter version 3.1.3

This error does NOT occur with web3modal_flutter version version: 3.0.21

The error is thrown in Line 73 in w3m_service.dart.

To Reproduce Steps to reproduce the behavior:

  1. Try to create new Web3App instance Code:
    Web3App wcClient = await Web3App.createInstance(
    relayUrl: 'wss://relay.walletconnect.com',
    projectId: dotenv.env['WC_PROJECT_ID']!,
    metadata: const PairingMetadata(
      name: 'OwnerChip',
      description: 'OwnerChip - Connecting physical objects to the blockchain',
      url: 'https://www.ownerchip.com',
      icons: ['https://avatars.githubusercontent.com/u/116345848'],
    ),
    );

Expected behavior New Web3App instance is created without errors.

Smartphone (please complete the following information):

kinggongzilla commented 2 weeks ago

Moreover I am encountering an issue when sending personal_sign request to Trust Wallet.

Describe the bug After sending the personal_sign request, there is no popup in Trust Wallet to sign the request. The issue does NOT exist with Metamask or 1inch wallet. This issue is only happening since 1 or 2 weeks. Previously the exact same code worked just fine.

There is no error thrown in the code. After calling await wc.request() the code seems to be "stuck".

Steps to reproduce

  1. Install
  2. Connect Trust Wallet via Web3Modal
  3. Send personal_sign request with:
String signature = await wc.request(
    topic: wcSession.topic,
    chainId: 'eip155:1',
    request: SessionRequestParams(
      method: 'personal_sign',
      params: [hexUtf8EncodedMessage, walletAddress.toString()],
    ),
  );

Version: web3modal_flutter version 3.0.21

I tried to check if upgrading to version 3.1.3 would fix the issue, but was unable to upgrade due to the other issue described above.

quetool commented 2 weeks ago

Hello @kinggongzilla, are you trying to create a Web3Modal or just work with Web3App? This is equal to ask if you are trying to use web3modal_flutter package or walletconnect_flutter_v2 package

kinggongzilla commented 2 weeks ago

I'm using web3modal_flutter and we're using the modal for UI

quetool commented 2 weeks ago

But what are you using this code for?:

  Web3App wcClient = await Web3App wcClient = await Web3App.createInstance(
    relayUrl: 'wss://relay.walletconnect.com',
    projectId: dotenv.env['WC_PROJECT_ID']!,
    metadata: const PairingMetadata(
      name: 'OwnerChip',
      description: 'OwnerChip - Connecting physical objects to the blockchain',
      url: 'https://www.ownerchip.com',
      icons: ['https://avatars.githubusercontent.com/u/116345848'],
    ),
  );

This is how Web3Modal should be used

https://docs.walletconnect.com/web3modal/flutter/options

kinggongzilla commented 2 weeks ago

Thanks for your quick reply. Sorry I left out a crucial part of the code. I pass it to W3MService to create a new instance like this.

final W3MService w3mService = W3MService(web3App: wcClient);
await w3mService.init();
quetool commented 2 weeks ago

Hello @kinggongzilla! You are right, I was able to reproduce. There's a bug in the code when using the instance through a web3app instance, however if you use it in the regular way you'll have no issues https://docs.walletconnect.com/web3modal/flutter/options#w3mservice-initialization

That would mean this

w3mService = W3MService(
  projectId: dotenv.env['WC_PROJECT_ID']!,
  metadata: const PairingMetadata(
    name: 'OwnerChip',
    description:
        'OwnerChip - Connecting physical objects to the blockchain',
    url: 'https://www.ownerchip.com',
    icons: ['https://avatars.githubusercontent.com/u/116345848'],
  ),
);
await w3mService!.init();

Instead of this

   Web3App wcClient = await Web3App.createInstance(
    relayUrl: 'wss://relay.walletconnect.com',
    projectId: dotenv.env['WC_PROJECT_ID']!,
    metadata: const PairingMetadata(
      name: 'OwnerChip',
      description: 'OwnerChip - Connecting physical objects to the blockchain',
      url: 'https://www.ownerchip.com',
      icons: ['https://avatars.githubusercontent.com/u/116345848'],
    ),
  );
quetool commented 6 days ago

GM @kinggongzilla! This bug have been fixed in latest 3.2.0 version! Thanks!