Skip to content

Commit

Permalink
fix: optimize.
Browse files Browse the repository at this point in the history
  • Loading branch information
web3max committed Apr 16, 2024
1 parent 10fe0e0 commit 91edc6d
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 13 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "wallet-bridge",
"private": false,
"version": "1.0.0-beta.8",
"version": "1.0.0-beta.9",
"main": "./dist/wallet-bridge.umd.js",
"module": "./dist/wallet-bridge.es.js",
"types": "./dist/index.d.ts",
Expand Down
1 change: 1 addition & 0 deletions src/lib/constant/errno.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const errno = {
metaMaskUserRejectedAccountAccess: -32603,
metaMaskReplacementTransactionUnderpriced: 'replacement transaction underpriced',
metaMaskTransactionHasBeenAborted: 'the transaction has been aborted',
metaMaskUserRejectedTheRequest: 'User rejected the request',
// WalletConnect
walletConnectUserRejectedTheTransaction: 'User rejected the transaction',
walletConnectInsufficientFundsForTransfer: 'insufficient funds for transfer',
Expand Down
21 changes: 14 additions & 7 deletions src/lib/ui/Wallet/wallet.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { loadScript } from '../../utils'
import { createConfig, http } from '@wagmi/core'
import { bsc, bscTestnet, holesky, mainnet as ethereum, polygon, polygonMumbai } from '@wagmi/core/chains'
import { injected, walletConnect } from '@wagmi/connectors'
import handleError from '../../utils/handleError'

export default {
title: 'UI/Wallets',
Expand Down Expand Up @@ -97,7 +98,8 @@ const TemplateConnectWallet = () => {
// only Passkey-signed transactions can be verified.
const res = await wallet._verifyPasskeySignature({ message, signature: signature as string })
console.log(res)
} catch (err) {
} catch (err: any) {
handleError(err)
onClose?.()
console.error(err)
}
Expand All @@ -119,12 +121,17 @@ const TemplateConnectWallet = () => {
}

const onSendETH = async () => {
const signature = await wallet.sendTransaction({
to: '0x7df93d9F500fD5A9537FEE086322a988D4fDCC38',
value: '10000000000000000',
data: '0x123abc',
})
console.log(signature)
try {
const signature = await wallet.sendTransaction({
to: '0x7df93d9F500fD5A9537FEE086322a988D4fDCC38',
value: '10000000000000000',
data: '0x123abc',
})
console.log(signature)
} catch (err: any) {
handleError(err)
console.log(err)
}
}

const onSendBTC = async () => {
Expand Down
11 changes: 6 additions & 5 deletions src/lib/utils/handleError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import CustomError from './CustomError'

function isUserReject(err: any) {
const metaMaskReject =
[errno.metaMaskUserRejectedAccountAccess, errno.metaMaskUserDeniedMessageSignature].includes(err.code) &&
!(
err.message.includes(errno.metaMaskReplacementTransactionUnderpriced) ||
err.message.includes(errno.metaMaskTransactionHasBeenAborted)
)
([errno.metaMaskUserRejectedAccountAccess, errno.metaMaskUserDeniedMessageSignature].includes(err.code) &&
!(
err.message.includes(errno.metaMaskReplacementTransactionUnderpriced) ||
err.message.includes(errno.metaMaskTransactionHasBeenAborted)
)) ||
err.message.includes(errno.metaMaskUserRejectedTheRequest)
const tronReject = err === errno.tronLinkConfirmationDeclinedByUser
const torusReject = [errno.torusUserCancelledLogin, errno.torusUserClosedPopup].includes(err.message)
const walletConnectReject = [
Expand Down

0 comments on commit 91edc6d

Please sign in to comment.