Skip to content

Commit

Permalink
ST-752: display error messages (#515)
Browse files Browse the repository at this point in the history
* Display error messages

* Improve error parsing

* Fix user denied error

* fix: typos

---------

Co-authored-by: Manuel Alessandro Collazo <[email protected]>
  • Loading branch information
alecande11 and terran6 authored Sep 4, 2023
1 parent 5e37cd1 commit 7fb207a
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 7 deletions.
12 changes: 5 additions & 7 deletions src/txs/Tx.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import useToPostMultisigTx from "pages/multisig/utils/useToPostMultisigTx"
import { isWallet, useAuth } from "auth"
import { PasswordError } from "auth/scripts/keystore"

import { toInput, CoinInput, calcTaxes } from "./utils"
import { toInput, CoinInput, calcTaxes, parseError } from "./utils"
import styles from "./Tx.module.scss"
import { useInterchainLCDClient } from "data/queries/lcdClient"
import { useInterchainAddresses } from "auth/hooks/useAddress"
Expand Down Expand Up @@ -232,7 +232,7 @@ function Tx<TxValues>(props: Props<TxValues>) {
: props.disabled || ""

const [submitting, setSubmitting] = useState(false)
const [error, setError] = useState<Error>()
const [error, setError] = useState<any>()

const navigate = useNavigate()
const toPostMultisigTx = useToPostMultisigTx()
Expand Down Expand Up @@ -464,12 +464,10 @@ function Tx<TxValues>(props: Props<TxValues>) {
const modal = !error
? undefined
: {
title: error?.toString().includes("UserDenied")
? t("Transaction was denied by user")
: t("Error"),
children: error?.toString().includes("UserDenied") ? null : (
title: t(parseError(error).title),
children: (
<Pre height={120} normal break>
{error?.message}
{t(parseError(error).message)}
</Pre>
),
}
Expand Down
44 changes: 44 additions & 0 deletions src/txs/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,47 @@ export const calcTaxes = (
})
)
}

export function parseError(error: any): { title: string; message: string } {
if (error instanceof Error || typeof error.message === "string") {
const { message, name } = error

switch (message) {
case "Ledger device: UNKNOWN_ERROR (0x5515)":
return {
title: "Ledger error",
message:
"Please make sure your Ledger device is connected and unlocked.",
}
case "Unknown Status Code: 28161":
return {
title: "Ledger error",
message:
"Please make sure you have the Terra and Cosmos apps installed on your Ledger device.",
}
case "Failed to execute 'claimInterface' on 'USBDevice': Unable to claim interface.":
return {
title: "Ledger error",
message:
"The Ledger device is being used on another tab, please close all the other browser windows and try again.",
}
default:
return {
title: name?.includes("Ledger") ? "Ledger error" : "Error",
message,
}
}
} else if (typeof error === "string") {
return {
title: "Error",
message: error.includes("User denied")
? "Transaction was denied by user."
: error,
}
} else {
return {
title: "Error",
message: JSON.stringify(error.error ?? error, null, 2),
}
}
}

0 comments on commit 7fb207a

Please sign in to comment.