Skip to content

Commit

Permalink
LIVE-14970: prevent undefined error on swap mobile (#8459)
Browse files Browse the repository at this point in the history
  • Loading branch information
andreicovaciu authored Dec 3, 2024
1 parent 9e52ed1 commit 1e153ea
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 16 deletions.
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,11 @@ const completeExchange = (

const payoutAddressParameters = await perFamily[
mainPayoutCurrency.family
].getSerializedAddressParameters(mainAccount.freshAddressPath, mainAccount.derivationMode);
]?.getSerializedAddressParameters(mainAccount.freshAddressPath, mainAccount.derivationMode);
if (unsubscribed) return;
if (!payoutAddressParameters) {
throw new Error(`Family not supported: ${mainPayoutCurrency.family}`);
}

const { config: payoutAddressConfig, signature: payoutAddressConfigSignature } =
await getCurrencyExchangeConfig(payoutCurrency);
Expand Down
17 changes: 11 additions & 6 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 @@ -130,12 +129,15 @@ const completeExchange = (

const payoutAddressParameters = await perFamily[
mainPayoutCurrency.family
].getSerializedAddressParameters(
]?.getSerializedAddressParameters(
payoutAccount.freshAddressPath,
payoutAccount.derivationMode,
mainPayoutCurrency.id,
);
if (unsubscribed) return;
if (!payoutAddressParameters) {
throw new Error(`Family not supported: ${mainPayoutCurrency.family}`);
}

//-- Special case of SPLToken
//- NOT READY YET
Expand Down Expand Up @@ -184,12 +186,15 @@ const completeExchange = (
if (unsubscribed) return;
const refundAddressParameters = await perFamily[
mainRefundCurrency.family
].getSerializedAddressParameters(
]?.getSerializedAddressParameters(
refundAccount.freshAddressPath,
refundAccount.derivationMode,
mainRefundCurrency.id,
);
if (unsubscribed) return;
if (!refundAddressParameters) {
throw new Error(`Family not supported: ${mainRefundCurrency.family}`);
}

const { config: refundAddressConfig, signature: refundAddressConfigSignature } =
await getCurrencyExchangeConfig(refundCurrency);
Expand Down
22 changes: 15 additions & 7 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";
import { CEXProviderConfig } from "../providers/swap";

Expand Down Expand Up @@ -196,12 +198,15 @@ const initSwap = (input: InitSwapInput): Observable<SwapRequestEvent> => {
}
const payoutAddressParameters = await perFamily[
mainPayoutCurrency.family
].getSerializedAddressParameters(
]?.getSerializedAddressParameters(
payoutAccount.freshAddressPath,
payoutAccount.derivationMode,
mainPayoutCurrency.id,
);
if (unsubscribed) return;
if (!payoutAddressParameters) {
throw new Error(`Family not supported: ${mainPayoutCurrency.family}`);
}
const { config: payoutAddressConfig, signature: payoutAddressConfigSignature } =
await getCurrencyExchangeConfig(payoutCurrency);

Expand Down Expand Up @@ -230,12 +235,15 @@ const initSwap = (input: InitSwapInput): Observable<SwapRequestEvent> => {
}
const refundAddressParameters = await perFamily[
mainRefundCurrency.family
].getSerializedAddressParameters(
]?.getSerializedAddressParameters(
refundAccount.freshAddressPath,
refundAccount.derivationMode,
mainRefundCurrency.id,
);
if (unsubscribed) return;
if (!refundAddressParameters) {
throw new Error(`Family not supported: ${mainRefundCurrency.family}`);
}
const { config: refundAddressConfig, signature: refundAddressConfigSignature } =
await getCurrencyExchangeConfig(refundCurrency);
if (unsubscribed) return;
Expand Down

0 comments on commit 1e153ea

Please sign in to comment.