-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SOV-1606: fix ugly liquality error message (#2510)
* fix: SOV-1606 ugly liquality error message * fix: error message * chore: resolve review comment * chore: remove top error text for user declined txs * Fix error message in tx dialog * fix: try to find out liquality wallet error --------- Co-authored-by: soulBit <[email protected]> Co-authored-by: tiltom <[email protected]>
- Loading branch information
1 parent
f9b1ecd
commit 2ec70af
Showing
4 changed files
with
78 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
src/app/components/TransactionDialog/hooks/useGetNormalizedError.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { translations } from 'locales/i18n'; | ||
import { useMemo } from 'react'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { useSelector } from 'react-redux'; | ||
import { selectRequestDialogState } from 'store/global/transactions-store/selectors'; | ||
|
||
export const useGetNormalizedError = () => { | ||
const { t } = useTranslation(); | ||
const { error } = useSelector(selectRequestDialogState); | ||
|
||
const hasUserDeclinedTx = useMemo( | ||
() => | ||
error?.includes('User denied transaction signature') || | ||
error?.includes('UserDeclinedError'), | ||
[error], | ||
); | ||
|
||
const normalizedError = useMemo(() => { | ||
if (hasUserDeclinedTx) { | ||
return t(translations.walletProvider.userDenied); | ||
} | ||
if (error?.includes('LIQUALITY_ERROR_FROM_ERROR_PARSER_PACKAGE')) { | ||
const searchReason = error.match( | ||
/(?<=\\"reason\\":\\")([A-Za-z0-9 ]+)(?=\\")/g, | ||
); | ||
if (searchReason?.length) { | ||
return searchReason[0]; | ||
} | ||
|
||
const searchErrorName = error.match( | ||
/(?<=\\"name\\":\\")([A-Za-z0-9 ]+)(?=\\")/g, | ||
); | ||
if (searchErrorName?.length) { | ||
return searchErrorName[0]; | ||
} | ||
} | ||
return error; | ||
}, [hasUserDeclinedTx, error, t]); | ||
|
||
return { | ||
hasUserDeclinedTx, | ||
normalizedError, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters