Skip to content

Commit

Permalink
chore: refactor wallet connect error handling (#2179)
Browse files Browse the repository at this point in the history
* chore: improve wallet connect error handling

* Update packages/shared/src/lib/auxiliary/wallet-connect/utils/getBloomError.ts

Co-authored-by: Mark Nardi <[email protected]>

* chore: update imports

---------

Co-authored-by: Mark Nardi <[email protected]>
  • Loading branch information
Tuditi and MarkNerdi authored Mar 21, 2024
1 parent 89b9440 commit 3596f8f
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { IChain } from '@core/network'
import { IConnectedDapp } from '../interface'
import { CallbackParameters } from '../types'
import { PopupId, openPopup } from '../../../../../../desktop/lib/auxiliary/popup'
import { switchToRequiredAccount } from '../utils'
import { getBloomError, switchToRequiredAccount } from '../utils'
import { getSdkError } from '@walletconnect/utils'
import { Platform } from '@core/app/classes'
import { SignTypedDataVersion } from '@metamask/eth-sig-util'
Expand Down Expand Up @@ -54,7 +54,7 @@ export async function handleEthSignTypedData(
},
})
} catch (err) {
responseCallback({ error: getSdkError(err) })
responseCallback(getBloomError(err))
}

return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { IConnectedDapp } from '@auxiliary/wallet-connect/interface'
import { CallbackParameters } from '@auxiliary/wallet-connect/types'
import { buildEvmTransactionData } from '@core/layer-2/utils'
import { EvmTransactionData } from '@core/layer-2'
import { switchToRequiredAccount } from '@auxiliary/wallet-connect/utils'
import { getBloomError, switchToRequiredAccount } from '@auxiliary/wallet-connect/utils'
import { getSdkError } from '@walletconnect/utils'
import { Platform } from '@core/app'
import { DappVerification, RpcMethod } from '../enums'
Expand Down Expand Up @@ -41,12 +41,7 @@ export async function handleEthTransaction(
evmTransactionData.gasPrice = gasPrice
evmTransactionData.gasLimit = gasLimit
} catch (err) {
responseCallback({
error: {
message: err.message,
code: 1000,
},
})
responseCallback(getBloomError(err))
return
}
}
Expand All @@ -68,6 +63,6 @@ export async function handleEthTransaction(
},
})
} catch (err) {
responseCallback({ error: getSdkError(err) })
responseCallback(getBloomError(err))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { openPopup, PopupId } from '../../../../../../desktop/lib/auxiliary/popu
import { IConnectedDapp } from '../interface'
import { IChain } from '@core/network'
import { CallbackParameters } from '../types'
import { switchToRequiredAccount } from '../utils'
import { getBloomError, switchToRequiredAccount } from '../utils'
import { getSdkError } from '@walletconnect/utils'
import { Platform } from '@core/app'
import { DappVerification, RpcMethod } from '../enums'
Expand Down Expand Up @@ -78,6 +78,6 @@ export async function handleSignMessage(
})
}
} catch (err) {
responseCallback({ error: getSdkError(err) })
responseCallback(getBloomError(err))
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { CallbackParameters } from '@auxiliary/wallet-connect/types'
import { getSdkError } from '@walletconnect/utils'
import { IError } from '@core/error/interfaces'

export function getBloomError(err: unknown): Omit<CallbackParameters, 'result'> {
try {
// @ts-expect-error the error types aren't exported from @walletconnect
return { error: getSdkError(err) }
} catch {
return {
error: {
message: (err as IError).message ?? 'Something went wrong',
code: 1000,
},
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export * from './disconnectAllDapps'
export * from './getAllEvmAddresses'
export * from './getBloomError'
export * from './getPermissionForMethod'
export * from './rejectSession'
export * from './switchToRequiredAccount'
Expand Down

0 comments on commit 3596f8f

Please sign in to comment.