Skip to content

Commit

Permalink
Improvements to the WC v2 error messages we show to users (#5075)
Browse files Browse the repository at this point in the history
  • Loading branch information
jinchung authored Oct 10, 2023
1 parent ba397cd commit d86260f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/languages/en_US.json
Original file line number Diff line number Diff line change
Expand Up @@ -2258,6 +2258,8 @@
"pairing_timeout": "This session timed-out before a connection could be established. This is usually due to a network error. Please try again.",
"pairing_unsupported_methods": "The dapp requested wallet RPC methods that are unsupported by Rainbow.",
"pairing_unsupported_networks": "The dapp requested network(s) that are unsupported by Rainbow.",
"read_only_wallet_on_signing_method": "It looks like you're using a read-only wallet, which is not allowed for this request.",
"namespaces_invalid": "There was an issue with the namespaces requested by the dapp. Please try again or contact Rainbow and/or dapp support teams.",
"request_invalid": "The request contained invalid parameters. Please try again or contact Rainbow and/or dapp support teams.",
"request_unsupported_network": "The network specified in this request is not supported by Rainbow.",
"request_unsupported_methods": "The RPC method(s) specified in this request are not supported by Rainbow."
Expand Down
12 changes: 9 additions & 3 deletions src/walletConnect/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ export async function onSessionProposal(

showErrorSheet({
title: lang.t(T.errors.generic_title),
body: `${lang.t(T.errors.generic_error)} \n \n ${
body: `${lang.t(T.errors.namespaces_invalid)} \n \n ${
namespaces.error.message
}`,
sheetHeight: 400,
Expand Down Expand Up @@ -621,6 +621,7 @@ export async function onSessionProposal(
}
}

// For WC v2
export async function onSessionRequest(
event: SignClientTypes.EventArguments['session_request']
) {
Expand Down Expand Up @@ -692,7 +693,8 @@ export async function onSessionRequest(

const selectedWallet = findWalletWithAccount(allWallets, address);

if (!selectedWallet || selectedWallet?.type === WalletTypes.readOnly) {
const isReadOnly = selectedWallet?.type === WalletTypes.readOnly;
if (!selectedWallet || isReadOnly) {
logger.error(
new RainbowError(
`WC v2: session_request exited, selectedWallet was falsy or read only`
Expand All @@ -702,14 +704,18 @@ export async function onSessionRequest(
}
);

const errorMessageBody = isReadOnly
? lang.t(T.errors.read_only_wallet_on_signing_method)
: lang.t(T.errors.generic_error);

await client.respondSessionRequest({
topic,
response: formatJsonRpcError(id, `Wallet is read-only`),
});

showErrorSheet({
title: lang.t(T.errors.generic_title),
body: lang.t(T.errors.request_invalid),
body: errorMessageBody,
sheetHeight: 270,
onClose: maybeGoBackAndClearHasPendingRedirect,
});
Expand Down

0 comments on commit d86260f

Please sign in to comment.