Skip to content

Commit

Permalink
Merge pull request #287 from terra-money/ST-880-throw-error-on-origin…
Browse files Browse the repository at this point in the history
…-webapp

Fix error handling for external txs
  • Loading branch information
terencelimzhengwei authored Jan 9, 2024
2 parents 85e6a47 + 7af4f7b commit e4cdbfe
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
18 changes: 13 additions & 5 deletions src/extension/modules/ConfirmTx.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,13 @@ const ConfirmTx = (props: TxRequest | SignBytesRequest) => {
actions.tx(requestType, props, response)
}
} catch (error) {
if (error instanceof Error) {
const message = (error as any)?.message
const isPasswordError =
typeof message === "string" &&
message.toLowerCase().includes("password")
if (isPasswordError) {
failed = true
setIncorrect(error.message)
setIncorrect(message)
} else {
const message = getErrorMessage(error)
const response = { success: false, error: { code: 3, message } }
Expand All @@ -198,9 +202,13 @@ const ConfirmTx = (props: TxRequest | SignBytesRequest) => {
const response = { result, success: true }
actions.tx(requestType, props, response)
} catch (error) {
if (error instanceof Error) {
const message = (error as any)?.message
const isPasswordError =
typeof message === "string" &&
message.toLowerCase().includes("password")
if (isPasswordError) {
failed = true
setIncorrect(error.message)
setIncorrect(message)
} else {
const message = getErrorMessage(error)
const response = { success: false, error: { code: 3, message } }
Expand Down Expand Up @@ -308,7 +316,7 @@ const ConfirmTx = (props: TxRequest | SignBytesRequest) => {
<TxDetails
{...props}
tx={{ ...props.tx, fee }}
onFeesReady={() => setFeesReady(true)}
onFeesReady={(state) => setFeesReady(state)}
/>
)}
{"bytes" in props && <SignBytesDetails {...props} />}
Expand Down
4 changes: 2 additions & 2 deletions src/extension/modules/TxDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const TxDetails = ({
timestamp,
tx,
onFeesReady,
}: TxRequest & { onFeesReady: () => void }) => {
}: TxRequest & { onFeesReady: (state: boolean) => void }) => {
const { msgs, memo, fee, chainID } = tx

const { t } = useTranslation()
Expand All @@ -38,7 +38,7 @@ const TxDetails = ({
gasDenom={fee?.amount.denoms()[0]}
descriptions={contents.filter(({ value }) => !!value)}
setGasDenom={() => {}}
onReady={() => onFeesReady()}
onReady={(state) => onFeesReady(state)}
/>
</Grid>
)
Expand Down

0 comments on commit e4cdbfe

Please sign in to comment.