solana-mobile / mobile-wallet-adapter

Other
250 stars 104 forks source link

Found no installed wallet that supports the mobile wallet protocol. But only for 1 specific transaction #918

Open LatentDream opened 3 months ago

LatentDream commented 3 months ago

Hi, I'm experiencing an issue here when send the transaction to the sendTransaction from the MobileAdapter, I have the following error:

WalletSendTransactionError: Found no installed wallet that supports the mobile wallet protocol.

The weird part is, only the following transaction cause this error. All other transaction detect the wallet protocol

export async function getOrCreateAssociatedTokenAccount(
  connection: Connection,
  mint: PublicKey,
  owner: PublicKey,
sendTransactionFromAdapter: Sender   /* This is the sendTransaction from the MobileAdapter. Extracted from `const { sendTransaction } = useWallet(); */
): Promise<Result<Account>> {
  const associatedToken = await getAssociatedTokenAddress(mint, owner);
  let account;
  try {
    account = await getAccount(connection, associatedToken);
  } catch (error: unknown) {
    if (error instanceof TokenAccountNotFoundError || error instanceof TokenInvalidAccountOwnerError) {
      try {
        const confirmed = confirm("You don't have a account for this token yet. Do you want to create one?");
        if (!confirmed) {
          return { ok: false, message: "User cancelled the operation" };
        }
        // Check if the owner has enought SOL to pay for the creation
        const solBalance = await connection.getBalance(window.solanaClient.publicKey);
        console.log("solBalance", solBalance);
        if (BigNumber(solBalance).eq(0)) {
          return { ok: false, message: "Not enough SOL to pay the transaction fee" };
        }

        const transaction = new Transaction().add(
          createAssociatedTokenAccountInstruction(window.solanaClient.publicKey, associatedToken, owner, mint)
        );

        // FAILED WITH THIS
        // console.log(window.solanaClient);  // The adapter is attached to the window when the user connect. This line would print the adapter. Picture of the output at the end
        // const signature = await window.solanaClient.sendTransaction(transaction, connection);  // This will give the same error
        // ALSO FAIL WITH THIS
        const signature = await sendTransactionFromAdapter(transaction, connection);
        console.log("Won't be logged");
        await connection.confirmTransaction(signature, "singleGossip");

      } catch (error: unknown) {
        console.error("Failed to create associated token account", error);
        // Error log here
      }
      account = await getAccount(connection, associatedToken);
    } else {
      console.error("Unexpected Error while creating user Token Account", error);
      return { ok: false, message: "Unexpected Error while creating user Token Account" };
    }
  }
  return { ok: true, value: account };
}
...

The version of the packages are:

"@solana-mobile/mobile-wallet-adapter-protocol": "^2.1.3",
"@solana-mobile/mobile-wallet-adapter-protocol-web3js": "^2.1.3",
"@solana-mobile/wallet-adapter-mobile": "^2.1.3",
"@solana/spl-token": "^0.3.11",
"@solana/wallet-adapter-base": "^0.9.23",
"@solana/wallet-adapter-react": "^0.15.35",
"@solana/wallet-adapter-react-ui": "^0.9.35",
"@solana/wallet-adapter-wallets": "^0.19.32",
...
"react": "^18.3.1",
"react-app-rewired": "^2.2.1",

Smartphone (please complete the following information): Android Virtual device: Pixel 8 Pro API 35, Chrome browser Tested on multiple real Android device, with the same outcome

Additional context I can send in private a link to a deploy version for a dev to test this if needed.


Picture of the console.log from the code:

Screenshot 2024-08-09 at 5 16 56 PM
Funkatronics commented 3 months ago

Hey @LatentDream. Its hard to say for certain without seeing your transaction in detail. My guess is that your transaction is incorrect and the adapter is throwing the wrong error. Its hard to say without a MRE. Can you record a video of what your seeing?

LatentDream commented 3 months ago

Sorry for the delay; @augyg will take over the discussion for this issue. He will share an example with the problem

augyg commented 3 months ago

@Funkatronics

I believe the part he was confused about is that this transaction for sure works in every other context (iOS and Desktop, etc.) just specifically not on Chrome for Android

augyg commented 3 months ago

https://astrovault-testnet.vercel.app/outbid

This is a deployed version of it and the transaction in question is attached to "Faucet: Test Token"

Funkatronics commented 1 month ago

@augyg can I see the implementation of the sendTransactionFromAdapter function? One common mistake we see that causes the WalletSendTransactionError: Found no installed wallet that supports the mobile wallet protocol. error is when trying to autoconnect to a mobile wallet. Chrome (and all other browsers I have tested) will block any redirect that did not come from a user action - popup blocking.