feat: improve contract error message#5587
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
🦋 Changeset detectedLatest commit: 111ec78 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Coverage Report for ./apps/evm
File Coverage
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@greptile review this pr |
Greptile SummaryThis PR introduces a dedicated contract-error display layer: it decodes viem
Confidence Score: 4/5Safe to merge after fixing the static translation map in customErrorPhrases.ts. The translation phrases in customErrorPhrases are resolved once at module import time into fixed string primitives. A user who switches languages mid-session will continue to see error messages in the original language, making the i18n support effectively broken for that file. The rest of the pipeline — ABI-based decode, toast rendering, raw-error toggle — is well-structured and tested. apps/evm/src/libs/errors/customErrorPhrases.ts and its consumer apps/evm/src/libs/errors/handleContractError/index.tsx (getFriendlyPhrase call site). Important Files Changed
Reviews (3): Last reviewed commit: "feat: update transacation && format type" | Re-trigger Greptile |
|
@greptile review again |
| import { t } from 'libs/translations'; | ||
|
|
||
| export const customErrorPhrases: Record<string, string> = { | ||
| ActionPaused: t('contractErrors.actionPaused'), | ||
| InsufficientLiquidity: t('contractErrors.insufficientLiquidity'), | ||
| InsufficientCollateral: t('contractErrors.insufficientCollateral'), | ||
| SupplyCapExceeded: t('contractErrors.supplyCapExceeded'), | ||
| BorrowCapExceeded: t('contractErrors.borrowCapExceeded'), | ||
| TooMuchRepay: t('contractErrors.tooMuchRepay'), | ||
| }; |
There was a problem hiding this comment.
Stale translations on language switch
t() is called at module-initialization time, so the string values in customErrorPhrases are resolved once into the language that is active when the module is first imported. If a user subsequently switches languages, all error phrases from this map will still appear in the original language. The i18n-patterns guide mandates calling t() at render time (via useTranslation()) rather than at module load time. Converting this to a factory function and calling it inside getFriendlyPhrase fixes the problem.
| import { t } from 'libs/translations'; | |
| export const customErrorPhrases: Record<string, string> = { | |
| ActionPaused: t('contractErrors.actionPaused'), | |
| InsufficientLiquidity: t('contractErrors.insufficientLiquidity'), | |
| InsufficientCollateral: t('contractErrors.insufficientCollateral'), | |
| SupplyCapExceeded: t('contractErrors.supplyCapExceeded'), | |
| BorrowCapExceeded: t('contractErrors.borrowCapExceeded'), | |
| TooMuchRepay: t('contractErrors.tooMuchRepay'), | |
| }; | |
| import { t } from 'libs/translations'; | |
| export const getCustomErrorPhrases = (): Record<string, string> => ({ | |
| ActionPaused: t('contractErrors.actionPaused'), | |
| InsufficientLiquidity: t('contractErrors.insufficientLiquidity'), | |
| InsufficientCollateral: t('contractErrors.insufficientCollateral'), | |
| SupplyCapExceeded: t('contractErrors.supplyCapExceeded'), | |
| BorrowCapExceeded: t('contractErrors.borrowCapExceeded'), | |
| TooMuchRepay: t('contractErrors.tooMuchRepay'), | |
| }); |
There was a problem hiding this comment.
won't fix - follows existing convention
Jira ticket(s)
VPD-1166
Changes
needed at call site
tailwind override)
chip, copy/show-raw buttons