Skip to content
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

LIVE-14970: prevent undefined error on swap mobile #8459

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/shy-penguins-itch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@ledgerhq/live-common": minor
---

Prevent undefined error on mobile swap
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import { TransportStatusError, WrongDeviceForAccount } from "@ledgerhq/errors";

import { delay } from "../../../promise";
import {
isExchangeTypeNg,
ExchangeTypes,
createExchange,
ExchangeTypes,
isExchangeTypeNg,
PayloadSignatureComputedFormat,
} from "@ledgerhq/hw-app-exchange";
import perFamily from "../../../generated/exchange";
Expand Down Expand Up @@ -106,8 +106,8 @@ const completeExchange = (

const payoutAddressParameters = await perFamily[
mainPayoutCurrency.family
].getSerializedAddressParameters(mainAccount.freshAddressPath, mainAccount.derivationMode);
if (unsubscribed) return;
]?.getSerializedAddressParameters(mainAccount.freshAddressPath, mainAccount.derivationMode);
if (unsubscribed || !payoutAddressParameters) return;

const { config: payoutAddressConfig, signature: payoutAddressConfigSignature } =
await getCurrencyExchangeConfig(payoutCurrency);
Expand Down
15 changes: 7 additions & 8 deletions libs/ledger-live-common/src/exchange/swap/completeExchange.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {
TransportStatusError,
WrongDeviceForAccountRefund,
WrongDeviceForAccountPayout,
WrongDeviceForAccountRefund,
} from "@ledgerhq/errors";
import { log } from "@ledgerhq/logs";
import { firstValueFrom, from, Observable } from "rxjs";
Expand All @@ -14,14 +14,13 @@ import perFamily from "../../generated/exchange";
import { withDevice } from "../../hw/deviceAccess";
import { delay } from "../../promise";
import {
ExchangeTypes,
createExchange,
ExchangeTypes,
getExchangeErrorMessage,
PayloadSignatureComputedFormat,
} from "@ledgerhq/hw-app-exchange";
import type { CompleteExchangeInputSwap, CompleteExchangeRequestEvent } from "../platform/types";
import { getSwapProvider } from "../providers";
import { convertToAppExchangePartnerKey } from "../providers";
import { convertToAppExchangePartnerKey, getSwapProvider } from "../providers";
import { CompleteExchangeStep, convertTransportError } from "../error";
import { getDefaultAccountName } from "@ledgerhq/live-wallet/accountName";
import BigNumber from "bignumber.js";
Expand Down Expand Up @@ -126,12 +125,12 @@ const completeExchange = (

const payoutAddressParameters = await perFamily[
mainPayoutCurrency.family
].getSerializedAddressParameters(
]?.getSerializedAddressParameters(
payoutAccount.freshAddressPath,
payoutAccount.derivationMode,
mainPayoutCurrency.id,
);
if (unsubscribed) return;
if (unsubscribed || !payoutAddressParameters) return;

const { config: payoutAddressConfig, signature: payoutAddressConfigSignature } =
await getCurrencyExchangeConfig(payoutCurrency);
Expand Down Expand Up @@ -165,12 +164,12 @@ const completeExchange = (
if (unsubscribed) return;
const refundAddressParameters = await perFamily[
mainRefundCurrency.family
].getSerializedAddressParameters(
]?.getSerializedAddressParameters(
refundAccount.freshAddressPath,
refundAccount.derivationMode,
mainRefundCurrency.id,
);
if (unsubscribed) return;
if (unsubscribed || !refundAddressParameters) return;

const { config: refundAddressConfig, signature: refundAddressConfigSignature } =
await getCurrencyExchangeConfig(refundCurrency);
Expand Down
20 changes: 11 additions & 9 deletions libs/ledger-live-common/src/exchange/swap/initSwap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@ import {
WrongDeviceForAccountPayout,
WrongDeviceForAccountRefund,
} from "@ledgerhq/errors";
import Exchange, { ExchangeTypes, RateTypes } from "@ledgerhq/hw-app-exchange";
import Exchange, {
decodePayloadProtobuf,
ExchangeTypes,
RateTypes,
} from "@ledgerhq/hw-app-exchange";
import network from "@ledgerhq/live-network/network";
import { log } from "@ledgerhq/logs";
import { BigNumber } from "bignumber.js";
import invariant from "invariant";
import { Observable, firstValueFrom, from } from "rxjs";
import { firstValueFrom, from, Observable } from "rxjs";
import secp256k1 from "secp256k1";
import { getCurrencyExchangeConfig } from "../";
import { getAccountCurrency, getMainAccount } from "../../account";
Expand All @@ -26,9 +30,7 @@ import { delay } from "../../promise";
import { getSwapAPIBaseURL, getSwapUserIP } from "./";
import { mockInitSwap } from "./mock";
import type { InitSwapInput, SwapRequestEvent } from "./types";
import { decodePayloadProtobuf } from "@ledgerhq/hw-app-exchange";
import { getSwapProvider } from "../providers";
import { convertToAppExchangePartnerKey } from "../providers";
import { convertToAppExchangePartnerKey, getSwapProvider } from "../providers";
import { getDefaultAccountName } from "@ledgerhq/live-wallet/accountName";

const withDevicePromise = (deviceId, fn) =>
Expand Down Expand Up @@ -193,12 +195,12 @@ const initSwap = (input: InitSwapInput): Observable<SwapRequestEvent> => {
}
const payoutAddressParameters = await perFamily[
mainPayoutCurrency.family
].getSerializedAddressParameters(
]?.getSerializedAddressParameters(
payoutAccount.freshAddressPath,
payoutAccount.derivationMode,
mainPayoutCurrency.id,
);
if (unsubscribed) return;
if (unsubscribed || !payoutAddressParameters) return;
const { config: payoutAddressConfig, signature: payoutAddressConfigSignature } =
await getCurrencyExchangeConfig(payoutCurrency);

Expand Down Expand Up @@ -227,12 +229,12 @@ const initSwap = (input: InitSwapInput): Observable<SwapRequestEvent> => {
}
const refundAddressParameters = await perFamily[
mainRefundCurrency.family
].getSerializedAddressParameters(
]?.getSerializedAddressParameters(
refundAccount.freshAddressPath,
refundAccount.derivationMode,
mainRefundCurrency.id,
);
if (unsubscribed) return;
if (unsubscribed || !refundAddressParameters) return;
const { config: refundAddressConfig, signature: refundAddressConfigSignature } =
await getCurrencyExchangeConfig(refundCurrency);
if (unsubscribed) return;
Expand Down
Loading