From e83db835a83c458621d45198ee5095a159931a6b Mon Sep 17 00:00:00 2001 From: ys Date: Thu, 14 Nov 2024 00:04:09 +0800 Subject: [PATCH] handle wallet sign message error --- .../useAuthErrorHandlingSolana.ts | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/packages/huma-web-shared/src/hooks/useAuthErrorHandling/useAuthErrorHandlingSolana.ts b/packages/huma-web-shared/src/hooks/useAuthErrorHandling/useAuthErrorHandlingSolana.ts index 8c174428..5414c4f4 100644 --- a/packages/huma-web-shared/src/hooks/useAuthErrorHandling/useAuthErrorHandlingSolana.ts +++ b/packages/huma-web-shared/src/hooks/useAuthErrorHandling/useAuthErrorHandlingSolana.ts @@ -7,6 +7,7 @@ import { SolanaChainEnum, } from '@huma-finance/shared' import { useConnection, useWallet } from '@solana/wallet-adapter-react' +import { WalletSignMessageError } from '@solana/wallet-adapter-base' import { Connection, PublicKey, @@ -89,15 +90,17 @@ const verifyOwnershipSolana = async ( chainId, isDev, ) - } catch (e) { - console.error(e) - // If the wallet does not support message signing, try to sign a transaction - const tx = await buildAuthTx(account, message) - tx.feePayer = account - tx.recentBlockhash = (await connection.getLatestBlockhash()).blockhash - const signedTx = await signTransaction(tx) - const serializedTx = signedTx.serialize().toString('base64') - await AuthService.verifySolanaTx(message, serializedTx, chainId, isDev) + } catch (e: unknown) { + console.error(e); + if(e instanceof WalletSignMessageError) { + // If the wallet does not support message signing, try to sign a transaction + const tx = await buildAuthTx(account, message) + tx.feePayer = account + tx.recentBlockhash = (await connection.getLatestBlockhash()).blockhash + const signedTx = await signTransaction(tx) + const serializedTx = signedTx.serialize().toString('base64') + await AuthService.verifySolanaTx(message, serializedTx, chainId, isDev) + } } onVerificationComplete()