Skip to content

Commit

Permalink
A better wrong chain message
Browse files Browse the repository at this point in the history
  • Loading branch information
katspaugh committed Nov 1, 2023
1 parent 1b3b4f8 commit 4d42ad3
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,4 @@
width: 100%;
overflow: hidden;
text-overflow: ellipsis;
hyphens: auto;
}
6 changes: 1 addition & 5 deletions src/components/walletconnect/WcSessionMananger/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,7 @@ const WcSessionManager = ({ sessions, uri }: WcSessionManagerProps) => {
setOpen(true)

let timer = setTimeout(() => {
setOpen(false)

timer = setTimeout(() => {
setChangedSession(undefined)
}, 500)
setChangedSession(undefined)
}, SESSION_INFO_TIMEOUT)

return () => clearTimeout(timer)
Expand Down
14 changes: 13 additions & 1 deletion src/services/walletconnect/WalletConnectContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ import { WALLETCONNECT_EVENTS } from '../analytics/events/walletconnect'
import { SafeAppsTag } from '@/config/constants'
import { useRemoteSafeApps } from '@/hooks/safe-apps/useRemoteSafeApps'

enum Errors {
WRONG_CHAIN = '%%dappName%% made a request on a different chain than the one you are connected to',
}

const getWrongChainError = (dappName: string): Error => {
const message = Errors.WRONG_CHAIN.replace('%%dappName%%', dappName)
return new Error(message)
}

const walletConnectSingleton = new WalletConnectWallet()

export const WalletConnectContext = createContext<{
Expand Down Expand Up @@ -81,8 +90,11 @@ export const WalletConnectProvider = ({ children }: { children: ReactNode }) =>
const getResponse = () => {
// Get error if wrong chain
if (!session || requestChainId !== chainId) {
if (session) {
setError(getWrongChainError(getPeerName(session.peer)))
}

const error = getSdkError('UNSUPPORTED_CHAINS')
setError(new Error(error.message))
return formatJsonRpcError(event.id, error)
}

Expand Down

0 comments on commit 4d42ad3

Please sign in to comment.