-
Notifications
You must be signed in to change notification settings - Fork 476
[LWDM] feat(LIVE-29441): add wallet quote warning metadata #17315
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
Merged
Changes from all commits
Commits
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
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 |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| "@ledgerhq/live-common": minor | ||
| "@ledgerhq/wallet-api-exchange-module": minor | ||
| --- | ||
|
|
||
| Add wallet quote errors and warnings metadata for swap consumers. |
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
168 changes: 168 additions & 0 deletions
168
libs/ledger-live-common/src/wallet-api/Exchange/quotes/computeQuotesErrors.test.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 |
|---|---|---|
| @@ -0,0 +1,168 @@ | ||
| import { computeQuotesErrors } from "./computeQuotesErrors"; | ||
| import type { RawQuoteError } from "./service/types"; | ||
|
|
||
| function makeProviderError(overrides: Partial<RawQuoteError> = {}): RawQuoteError { | ||
| return { | ||
| code: "amount_off_limits", | ||
| type: "float", | ||
| provider: "lifi", | ||
| message: "amount out of range", | ||
| parameter: {}, | ||
| ...overrides, | ||
| }; | ||
| } | ||
|
|
||
| describe("computeQuotesErrors", () => { | ||
| it("returns an empty list when at least one successful quote came back, regardless of providerErrors", () => { | ||
| const result = computeQuotesErrors({ | ||
| successfulQuotesCount: 1, | ||
| providerErrors: [ | ||
| makeProviderError({ parameter: { minAmount: "10" } }), | ||
| makeProviderError({ parameter: { maxAmount: "1" } }), | ||
| ], | ||
| amountFrom: "5", | ||
| }); | ||
|
|
||
| expect(result).toEqual([]); | ||
| }); | ||
|
|
||
| it("emits only `noQuotes` when no successful quotes and no rejection rows", () => { | ||
| const result = computeQuotesErrors({ | ||
| successfulQuotesCount: 0, | ||
| providerErrors: [], | ||
| amountFrom: "5", | ||
| }); | ||
|
|
||
| expect(result).toEqual([{ code: "noQuotes" }]); | ||
| }); | ||
|
|
||
| it("stacks `amountTooLow` on top of `noQuotes` when a min-bound row brackets amountFrom", () => { | ||
| const result = computeQuotesErrors({ | ||
| successfulQuotesCount: 0, | ||
| providerErrors: [makeProviderError({ parameter: { minAmount: "10" } })], | ||
| amountFrom: "5", | ||
| }); | ||
|
|
||
| expect(result).toEqual([ | ||
| { code: "noQuotes" }, | ||
| { code: "amountTooLow", minAmount: "10" }, | ||
| ]); | ||
| }); | ||
|
|
||
| it("stacks `amountTooHigh` on top of `noQuotes` when a max-bound row brackets amountFrom", () => { | ||
| const result = computeQuotesErrors({ | ||
| successfulQuotesCount: 0, | ||
| providerErrors: [makeProviderError({ parameter: { maxAmount: "100" } })], | ||
| amountFrom: "200", | ||
| }); | ||
|
|
||
| expect(result).toEqual([ | ||
| { code: "noQuotes" }, | ||
| { code: "amountTooHigh", maxAmount: "100" }, | ||
| ]); | ||
| }); | ||
|
|
||
| it("stacks all three when both bounds match", () => { | ||
| const result = computeQuotesErrors({ | ||
| successfulQuotesCount: 0, | ||
| providerErrors: [ | ||
| makeProviderError({ parameter: { minAmount: "10" } }), | ||
| makeProviderError({ parameter: { maxAmount: "1" }, provider: "okx" }), | ||
| ], | ||
| amountFrom: "5", | ||
| }); | ||
|
|
||
| expect(result).toEqual([ | ||
| { code: "noQuotes" }, | ||
| { code: "amountTooLow", minAmount: "10" }, | ||
| { code: "amountTooHigh", maxAmount: "1" }, | ||
| ]); | ||
| }); | ||
|
|
||
| it("picks the lowest reported `minAmount` across providers", () => { | ||
| const result = computeQuotesErrors({ | ||
| successfulQuotesCount: 0, | ||
| providerErrors: [ | ||
| makeProviderError({ provider: "lifi", parameter: { minAmount: "20" } }), | ||
| makeProviderError({ provider: "okx", parameter: { minAmount: "12" } }), | ||
| makeProviderError({ provider: "uniswap", parameter: { minAmount: "30" } }), | ||
| ], | ||
| amountFrom: "5", | ||
| }); | ||
|
|
||
| expect(result).toEqual([ | ||
| { code: "noQuotes" }, | ||
| { code: "amountTooLow", minAmount: "12" }, | ||
| ]); | ||
| }); | ||
|
|
||
| it("picks the highest reported `maxAmount` across providers", () => { | ||
| const result = computeQuotesErrors({ | ||
| successfulQuotesCount: 0, | ||
| providerErrors: [ | ||
| makeProviderError({ provider: "lifi", parameter: { maxAmount: "100" } }), | ||
| makeProviderError({ provider: "okx", parameter: { maxAmount: "150" } }), | ||
| makeProviderError({ provider: "uniswap", parameter: { maxAmount: "50" } }), | ||
| ], | ||
| amountFrom: "200", | ||
| }); | ||
|
|
||
| expect(result).toEqual([ | ||
| { code: "noQuotes" }, | ||
| { code: "amountTooHigh", maxAmount: "150" }, | ||
| ]); | ||
| }); | ||
|
|
||
| it("ignores `amount_off_limits` rows whose threshold does not bracket amountFrom (legacy filter)", () => { | ||
| const result = computeQuotesErrors({ | ||
| successfulQuotesCount: 0, | ||
| providerErrors: [ | ||
| // user input 5 is ABOVE this provider's minimum -> not a `tooLow` candidate | ||
| makeProviderError({ parameter: { minAmount: "1" } }), | ||
| // user input 5 is BELOW this provider's maximum -> not a `tooHigh` candidate | ||
| makeProviderError({ parameter: { maxAmount: "10" }, provider: "okx" }), | ||
| ], | ||
| amountFrom: "5", | ||
| }); | ||
|
|
||
| expect(result).toEqual([{ code: "noQuotes" }]); | ||
| }); | ||
|
|
||
| it("treats edge case `minAmount === amountFrom` as below the limit (legacy `gte`)", () => { | ||
| // Legacy filter: BigNumber(minAmount).gte(amountFrom) — equality counts. | ||
| const result = computeQuotesErrors({ | ||
| successfulQuotesCount: 0, | ||
| providerErrors: [makeProviderError({ parameter: { minAmount: "5" } })], | ||
| amountFrom: "5", | ||
| }); | ||
|
|
||
| expect(result).toEqual([ | ||
| { code: "noQuotes" }, | ||
| { code: "amountTooLow", minAmount: "5" }, | ||
| ]); | ||
| }); | ||
|
|
||
| it("ignores rejection rows with codes other than `amount_off_limits`", () => { | ||
| const result = computeQuotesErrors({ | ||
| successfulQuotesCount: 0, | ||
| providerErrors: [ | ||
| // legacy never inspects these; they remain in providerErrors for the | ||
| // consumer to surface directly if it wants to. | ||
| makeProviderError({ code: "unknown_error", parameter: { minAmount: "10" } }), | ||
| ], | ||
| amountFrom: "5", | ||
| }); | ||
|
|
||
| expect(result).toEqual([{ code: "noQuotes" }]); | ||
| }); | ||
|
|
||
| it("ignores `amount_off_limits` rows missing both bound parameters", () => { | ||
| const result = computeQuotesErrors({ | ||
| successfulQuotesCount: 0, | ||
| providerErrors: [makeProviderError({ parameter: {} })], | ||
| amountFrom: "5", | ||
| }); | ||
|
|
||
| expect(result).toEqual([{ code: "noQuotes" }]); | ||
| }); | ||
| }); |
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.
Uh oh!
There was an error while loading. Please reload this page.