Skip to content

Flutter ReownAppKitModal: Trust Wallet crashes when trying to connect and make signature request #369

@usdtbanc

Description

@usdtbanc

SDK Affected

I am reown_appkit: ^1.5.0

Describe the bug

When trying to connect and making signature request using Trust Wallet, as soon as I click "Sign", the app crashes.
If I just connect, the connect pop up appears and it gets connected without any issue but when trying to connect with signing request at the same time, the app crashes.
I think it's because the connect popup window gets hidden by signature request popup hence causing the app to crash.

To Reproduce

Just try to connect Trust Wallet using SIWE config so that the signature request can also be made

Expected behavior

First, connect popup should show and once connected successfully, signature request popup should come.
It works fine with metamask and this is how it works (connect request, go back, click sign, signature request, session created)

Reproducible code

final appKitModal = ReownAppKitModal(
        // ignore: use_build_context_synchronously
        context: context!,
        disconnectOnDispose: false,
        projectId: web3WalletSetting?.ownAppKitProjectId,
        includedWalletIds: web3WalletSetting?.wallets!
            .map((item) => item.walletAddress)
            .toSet(),
        featuredWalletIds: web3WalletSetting?.wallets!
            .map((item) => item.walletAddress)
            .toSet(),
        metadata: PairingMetadata(
          name: web3WalletSetting!.metadataName,
          description: web3WalletSetting!.metadataDescp,
          url: web3WalletSetting!.metadataURL,
          icons: [web3WalletSetting!.metadataIcons],
        ),
        siweConfig: SIWEConfig(
            signOutOnDisconnect: true,
            signOutOnAccountChange: true,
            signOutOnNetworkChange: true,
            signOut: () async {
              return true;
            },
            getNonce: () async {
              try {
                await getWeb3Nonce();
                if (fetchWeb3NonceModel?.nonce != null) {
                  return (fetchWeb3NonceModel?.nonce ?? '');
                }
              } catch (e) {
                Utils.showLog("Connect Wallet error: $e");
                Utils.showToast("Connect wallet failed. Please try again.");
              }
              return '';
            },
            getMessageParams: () async {
              return SIWEMessageArgs(
                domain: Uri.parse(web3WalletSetting!.signDomain).authority,
                uri: web3WalletSetting!.signDomain,
                statement: web3WalletSetting?.signStatement,
                methods: web3WalletSetting?.signMethods!
                    .map((item) => item.name)
                    .toList(),
              );
            },
            createMessage: (SIWECreateMessageArgs args) {
              return SIWEUtils.formatMessage(args);
            },
            verifyMessage: (SIWEVerifyMessageArgs args) async {
              final chainId = SIWEUtils.getChainIdFromMessage(args.message);
              final address = SIWEUtils.getAddressFromMessage(args.message);
              final cacaoSignature = args.cacao != null
                  ? args.cacao!.s
                  : CacaoSignature(
                      t: CacaoSignature.EIP191,
                      s: args.signature,
                    );

              String projId = web3WalletSetting?.ownAppKitProjectId ?? "";
              bool valid = await SIWEUtils.verifySignature(
                address,
                args.message,
                cacaoSignature,
                chainId,
                projId,
              );

              if (valid) {
                await verifyWeb3Signature(
                    address, chainId, fetchWeb3NonceModel?.nonce);

                if (verifyWeb3SignatureModel?.isValidMessage != null) {
                  return (verifyWeb3SignatureModel?.isValidMessage ?? false);
                }
              }

              return false;
},
            getSession: () async {
              try {
                await getWeb3Session();

                if (fetchWeb3SessionModel?.address != null) {
                  return SIWESession(
                      address: fetchWeb3SessionModel!.address,
                      chains: [fetchWeb3SessionModel!.chainid]);
                }
              } catch (e) {
                Utils.showLog("Connect Wallet error: $e");
                Utils.showToast("Connect wallet failed. Please try again.");
              }
              return const SIWESession(address: "0x123", chains: ["1"]);
            }),
      );

      await appKitModal.init();

Smartphone (please complete the following information):

  • Device: Android
  • API Version: 35+

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions