Skip to content

Commit

Permalink
handle wallet sign message error
Browse files Browse the repository at this point in the history
  • Loading branch information
ys authored and ys committed Nov 13, 2024
1 parent b2ad782 commit e83db83
Showing 1 changed file with 12 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit e83db83

Please sign in to comment.