-
Notifications
You must be signed in to change notification settings - Fork 171
feat: support new quote api errors #7609
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+140
−131
Merged
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
87162b6
refactor: extract QuoteErrorsButton pure component
shoom3301 9de8ff6
refactor: extract QuoteApiErrorButton pure component
shoom3301 b52b891
refactor: clean up OperatorError
shoom3301 73814e7
fix: get rid of default export OperatorError
shoom3301 b755ca9
refactor: clean up QuoteApiError
shoom3301 d52bdd7
chore(i18n): extract i18n strings [automatic]
github-actions[bot] 49cb52d
feat: support new quote api errors
shoom3301 b47736a
Merge branch 'feat/new-quote-errors' of https://github.com/cowprotoco…
shoom3301 383c211
chore(i18n): extract i18n strings [automatic]
github-actions[bot] e0c0c9c
chore: fix SellAmountDoesNotCoverFee
shoom3301 16d2add
fix: improve errors displaying
shoom3301 dbdbd2f
chore(i18n): extract i18n strings [automatic]
github-actions[bot] e261db5
Merge branch 'develop' into feat/new-quote-errors
fairlighteth 1a02f1b
chore: fix error tooltip
shoom3301 61d51b0
Merge remote-tracking branch 'origin/feat/new-quote-errors-1' into fe…
shoom3301 f8774d7
chore: fix SellAmountDoesNotCoverFee text
shoom3301 a5ac2d1
chore(i18n): extract i18n strings [automatic]
github-actions[bot] 39696c2
Merge branch 'feat/new-quote-errors' into feat/new-quote-errors-1
fairlighteth 7bf1028
Merge branch 'develop' into feat/new-quote-errors
fairlighteth c624faf
chore: add NoLiquidity
shoom3301 84ee94b
Merge branch 'feat/new-quote-errors' into feat/new-quote-errors-1
fairlighteth 61b6af2
Merge branch 'develop' into feat/new-quote-errors
shoom3301 afc6a13
Merge branch 'feat/new-quote-errors' into feat/new-quote-errors-1
shoom3301 dc6ffbb
Merge branch 'develop' of https://github.com/cowprotocol/cowswap into…
shoom3301 da5625a
chore: fix code style
shoom3301 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
112 changes: 45 additions & 67 deletions
112
apps/cowswap-frontend/src/api/cowProtocol/errors/QuoteError.ts
This file contains hidden or 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 |
|---|---|---|
| @@ -1,90 +1,68 @@ | ||
| import { ApiErrorCodes, ApiErrorObject } from './OperatorError' | ||
|
|
||
| interface QuoteApiErrorObject { | ||
| export interface QuoteApiErrorObject { | ||
| errorType: QuoteApiErrorCodes | ||
| description: string | ||
| data?: unknown | ||
| } | ||
|
|
||
| // Conforms to backend API | ||
| // https://github.com/cowprotocol/services/blob/main/crates/orderbook/openapi.yml | ||
| // TODO: import from SDK `PriceEstimationError.errorType` | ||
| export enum QuoteApiErrorCodes { | ||
| UnsupportedToken = 'UnsupportedToken', | ||
| AppDataHashMismatch = 'AppDataHashMismatch', | ||
| CustomSolverError = 'CustomSolverError', | ||
| ExcessiveValidTo = 'ExcessiveValidTo', | ||
| Forbidden = 'Forbidden', | ||
| InsufficientLiquidity = 'InsufficientLiquidity', | ||
| FeeExceedsFrom = 'FeeExceedsFrom', | ||
| ZeroPrice = 'ZeroPrice', | ||
| TransferEthToContract = 'TransferEthToContract', | ||
| InsufficientValidTo = 'InsufficientValidTo', | ||
| InternalServerError = 'InternalServerError', | ||
| InvalidAppData = 'InvalidAppData', | ||
| InvalidNativeSellToken = 'InvalidNativeSellToken', | ||
| NoLiquidity = 'NoLiquidity', | ||
| QuoteNotVerified = 'QuoteNotVerified', | ||
| SameBuyAndSellToken = 'SameBuyAndSellToken', | ||
| UNHANDLED_ERROR = 'UNHANDLED_ERROR', | ||
| } | ||
|
|
||
| export const SENTRY_IGNORED_QUOTE_ERRORS = [QuoteApiErrorCodes.FeeExceedsFrom] | ||
|
|
||
| export enum QuoteApiErrorDetails { | ||
| UnsupportedToken = 'One of the tokens you are trading is unsupported. Please read the FAQ for more info.', | ||
| InsufficientLiquidity = 'Token pair selected has insufficient liquidity.', | ||
| FeeExceedsFrom = 'Current fee exceeds entered "from" amount.', | ||
| ZeroPrice = 'Quoted price is zero. This is likely due to a significant price difference between the two tokens. Please try increasing amounts.', | ||
| TransferEthToContract = 'Buying native currencies using smart contract wallets is not currently supported.', | ||
| SameBuyAndSellToken = 'You are trying to buy and sell the same token.', | ||
| SellAmountDoesNotCoverFee = 'The selling amount for the order is lower than the fee.', | ||
| UNHANDLED_ERROR = 'Quote fetch failed. This may be due to a server or network connectivity issue. Please try again later.', | ||
| SellAmountDoesNotCoverFee = 'SellAmountDoesNotCoverFee', | ||
| TokenTemporarilySuspended = 'TokenTemporarilySuspended', | ||
| TradingOutsideAllowedWindow = 'TradingOutsideAllowedWindow', | ||
| UnsupportedBuyTokenDestination = 'UnsupportedBuyTokenDestination', | ||
| UnsupportedOrderType = 'UnsupportedOrderType', | ||
| UnsupportedSellTokenSource = 'UnsupportedSellTokenSource', | ||
| UnsupportedToken = 'UnsupportedToken', | ||
| } | ||
|
|
||
| export function mapOperatorErrorToQuoteError(error?: ApiErrorObject): QuoteApiErrorObject { | ||
| switch (error?.errorType) { | ||
| case ApiErrorCodes.NotFound: | ||
| case ApiErrorCodes.NoLiquidity: | ||
| return { | ||
| errorType: QuoteApiErrorCodes.InsufficientLiquidity, | ||
| description: QuoteApiErrorDetails.InsufficientLiquidity, | ||
| } | ||
|
|
||
| case ApiErrorCodes.SellAmountDoesNotCoverFee: | ||
| return { | ||
| errorType: QuoteApiErrorCodes.FeeExceedsFrom, | ||
| description: QuoteApiErrorDetails.FeeExceedsFrom, | ||
| data: error?.data, | ||
| } | ||
| /** | ||
| * Errors that are expected to happen on regular basis | ||
| */ | ||
| export const SENTRY_IGNORED_QUOTE_ERRORS = [ | ||
| QuoteApiErrorCodes.InsufficientLiquidity, | ||
| QuoteApiErrorCodes.SellAmountDoesNotCoverFee, | ||
| QuoteApiErrorCodes.TokenTemporarilySuspended, | ||
| QuoteApiErrorCodes.TradingOutsideAllowedWindow, | ||
| QuoteApiErrorCodes.UnsupportedToken, | ||
| QuoteApiErrorCodes.NoLiquidity, | ||
| ] | ||
|
|
||
| case ApiErrorCodes.UnsupportedToken: | ||
| return { | ||
| errorType: QuoteApiErrorCodes.UnsupportedToken, | ||
| description: error.description, | ||
| } | ||
| case ApiErrorCodes.TransferEthToContract: | ||
| return { | ||
| errorType: QuoteApiErrorCodes.TransferEthToContract, | ||
| description: error.description, | ||
| } | ||
| export const UNHANDLED_ERROR_CODE = 'UNHANDLED_ERROR' as const | ||
|
|
||
| case ApiErrorCodes.SameBuyAndSellToken: | ||
| return { | ||
| errorType: QuoteApiErrorCodes.SameBuyAndSellToken, | ||
| description: QuoteApiErrorDetails.SameBuyAndSellToken, | ||
| } | ||
|
|
||
| default: | ||
| return { errorType: QuoteApiErrorCodes.UNHANDLED_ERROR, description: QuoteApiErrorDetails.UNHANDLED_ERROR } | ||
| } | ||
| } | ||
| const UNHANDLED_ERROR_DESC = | ||
| 'Quote fetch failed. This may be due to a server or network connectivity issue. Please try again later.' | ||
|
|
||
| export class QuoteApiError<Data = unknown> extends Error { | ||
| name = 'QuoteErrorObject' | ||
| type: QuoteApiErrorCodes | ||
| name = 'QuoteApiError' | ||
| type: QuoteApiErrorCodes | typeof UNHANDLED_ERROR_CODE | ||
| description: string | ||
| data?: Data | ||
|
|
||
| constructor(quoteError: QuoteApiErrorObject) { | ||
| super(quoteError.description) | ||
| constructor(quoteError: QuoteApiErrorObject | string) { | ||
| super(typeof quoteError === 'string' ? quoteError : quoteError.description) | ||
|
|
||
| if (typeof quoteError === 'string') { | ||
| this.type = UNHANDLED_ERROR_CODE | ||
| this.description = UNHANDLED_ERROR_DESC | ||
| this.message = quoteError | ||
| return | ||
| } | ||
|
|
||
| this.type = quoteError.errorType | ||
| this.description = quoteError.description | ||
| this.message = QuoteApiErrorDetails[quoteError.errorType] | ||
| this.message = quoteError.description | ||
| this.data = quoteError?.data as Data | ||
| } | ||
| } | ||
|
|
||
| export function isValidQuoteError(error: unknown): error is QuoteApiError { | ||
| return error instanceof QuoteApiError | ||
| } | ||
20 changes: 14 additions & 6 deletions
20
apps/cowswap-frontend/src/api/cowProtocol/getIsOrderBookTypedError.ts
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cowprotocol/services#4473