Skip to content

Commit

Permalink
feat(LIVE-11102): add rate expired error message (#6592)
Browse files Browse the repository at this point in the history
* feat(LIVE-11102): add rate expired error message

* feat(LIVE-11102): add changeset

* feat(LIVE-11102): typo

* feat(LIVE-11102): typo and check keyMessage not status

* feat(LIVE-11102): add messageKey to error
  • Loading branch information
lpaquet-ledger committed Apr 11, 2024
1 parent 9729140 commit 21f9d07
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 2 deletions.
6 changes: 6 additions & 0 deletions .changeset/itchy-tools-visit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"ledger-live-desktop": patch
"@ledgerhq/live-common": patch
---

Add expired message error
4 changes: 4 additions & 0 deletions apps/ledger-live-desktop/static/i18n/en/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -5469,6 +5469,10 @@
"title": "Account not scanned by full node",
"description": "Please configure your full node to scan for the accounts associated with this device. Your full node must first scan the blockchain for this account before you can add it to your portfolio."
},
"SwapRateExpiredError": {
"title": "Rate Expired",
"description": "The exchange transaction could not be completed as the rate has expired. Please refresh the rates and try your swap again."
},
"SwapGenericAPIError": {
"title": "Something went wrong",
"description": "The exchange transaction did not go through. Please try again or contact support."
Expand Down
1 change: 1 addition & 0 deletions libs/ledger-live-common/src/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ export const SwapExchangeRateAmountTooLowOrTooHigh = createCustomErrorClass(
);

export const SwapGenericAPIError = createCustomErrorClass("SwapGenericAPIError");
export const SwapRateExpiredError = createCustomErrorClass("SwapRateExpiredError");

export const JSONRPCResponseError = createCustomErrorClass("JSONRPCResponseError");
export const JSONDecodeError = createCustomErrorClass("JSONDecodeError");
Expand Down
15 changes: 13 additions & 2 deletions libs/ledger-live-common/src/exchange/swap/initSwap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ import { getCurrencyExchangeConfig } from "../";
import { getAccountCurrency, getAccountUnit, getMainAccount } from "../../account";
import { getAccountBridge } from "../../bridge";
import { getEnv } from "@ledgerhq/live-env";
import { SwapGenericAPIError, TransactionRefusedOnDevice } from "../../errors";
import {
SwapGenericAPIError,
SwapRateExpiredError,
TransactionRefusedOnDevice,
} from "../../errors";
import perFamily from "../../generated/exchange";
import { withDevice } from "../../hw/deviceAccess";
import { delay } from "../../promise";
Expand Down Expand Up @@ -98,7 +102,14 @@ const initSwap = (input: InitSwapInput): Observable<SwapRequestEvent> => {
});

if (unsubscribed || !res || !res.data) return;
} catch (e) {
} catch (e: any) {
if (e.msg.messageKey == "WRONG_OR_EXPIRED_RATE_ID") {
o.next({
type: "init-swap-error",
error: new SwapRateExpiredError(),
swapId,
});
}
o.next({
type: "init-swap-error",
error: new SwapGenericAPIError(),
Expand Down
1 change: 1 addition & 0 deletions libs/live-network/src/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ const makeError = (msg: string, status: number, url: string | undefined, method:
status,
url,
method,
msg,
};
return (status || "").toString().startsWith("4")
? new LedgerAPI4xx(msg, obj)
Expand Down

0 comments on commit 21f9d07

Please sign in to comment.