Skip to content

Commit

Permalink
feat(LIVE-14948): remove CDN for release issues and thorswap as DEX (#…
Browse files Browse the repository at this point in the history
…8436)

feat(LIVE-14948): changeset

feat(LIVE-14948): changeset

feat(LIVE-14948): lint

Update libs/ledger-live-common/src/exchange/providers/swap.ts

Update libs/ledger-live-common/src/exchange/providers/swap.ts

Update libs/ledger-live-common/src/exchange/providers/swap.ts

Update libs/ledger-live-common/src/exchange/providers/swap.ts

Update libs/ledger-live-common/src/exchange/providers/swap.ts

feat(LIVE-14948): fix wrong condition
  • Loading branch information
lpaquet-ledger authored Nov 26, 2024
1 parent 4fc1d7a commit 2ebf404
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 28 deletions.
5 changes: 5 additions & 0 deletions .changeset/mighty-days-tan.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@ledgerhq/live-common": minor
---

remove CDN for release issues and thorswap as DEX
9 changes: 3 additions & 6 deletions libs/ledger-live-common/src/cal/partners.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { getEnv } from "@ledgerhq/live-env";
import network from "@ledgerhq/live-network";
import { AdditionalProviderConfig, SWAP_DATA_CDN } from "../exchange/providers/swap";

const CAL_BASE_URL = getEnv("CAL_SERVICE_URL");

Expand All @@ -14,12 +15,8 @@ export type PartnerType = {
version?: number;
};

export async function getProvidersCDNData(): Promise<Record<string, PartnerType>> {
const { data: providers } = await network<Record<string, PartnerType>>({
url: "https://cdn.live.ledger.com/swap-providers/data.json",
});

return providers;
export function getProvidersCDNData(): Record<string, AdditionalProviderConfig> {
return SWAP_DATA_CDN;
}

export type ExchangeProvider = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const startExchange = (input: StartExchangeInput): Observable<ExchangeRequestEve
switch (exchangeType) {
case ExchangeTypes.Swap: {
const providerConfig = await getSwapProvider(provider);
if (providerConfig.type !== "CEX") {
if (providerConfig.useInExchangeApp === false) {
throw new Error(`Unsupported provider type ${providerConfig.type}`);
}
version = providerConfig.version;
Expand Down
39 changes: 24 additions & 15 deletions libs/ledger-live-common/src/exchange/providers/swap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,38 @@ export type SwapProviderConfig = {
needsBearerToken?: boolean;
};

type CEXProviderConfig = ExchangeProviderNameAndSignature & SwapProviderConfig & { type: "CEX" };
type DEXProviderConfig = SwapProviderConfig & { type: "DEX" };
export type CEXProviderConfig = ExchangeProviderNameAndSignature &
SwapProviderConfig & { type: "CEX" };
export type DEXProviderConfig = SwapProviderConfig & { type: "DEX" };
export type AdditionalProviderConfig = SwapProviderConfig & { type: "DEX" | "CEX" } & {
version?: number;
termsOfUseUrl: string;
supportUrl: string;
mainUrl: string;
useInExchangeApp: boolean;
displayName: string;
};

export type ProviderConfig = CEXProviderConfig | DEXProviderConfig;

export const SWAP_DATA_CDN: Record<string, AdditionalProviderConfig> = {
changelly: {
exodus: {
type: "CEX",
useInExchangeApp: true,
displayName: "Exodus",
termsOfUseUrl: "https://www.exodus.com/terms/",
supportUrl: "mailto:[email protected]",
mainUrl: "https://www.exodus.com/",
needsKYC: false,
needsBearerToken: false,
version: 2,
},
changelly: {
type: "CEX",
useInExchangeApp: true,
displayName: "Changelly",
termsOfUseUrl: "https://changelly.com/terms-of-use",
supportUrl: "https://support.changelly.com/en/support/home",
mainUrl: "https://changelly.com/",
},
exodus: {
type: "CEX",
displayName: "Exodus",
needsBearerToken: false,
termsOfUseUrl: "https://www.exodus.com/legal/exodus-tos-20240219-v29.pdf",
supportUrl: "https://www.exodus.com/contact-support/",
mainUrl: "https://www.exodus.com/",
needsKYC: false,
version: 2,
},
Expand All @@ -45,6 +48,7 @@ export const SWAP_DATA_CDN: Record<string, AdditionalProviderConfig> = {
needsBearerToken: false,
displayName: "CIC",
type: "CEX",
useInExchangeApp: true,
termsOfUseUrl: "https://criptointercambio.com/terms-of-use",
supportUrl: "https://criptointercambio.com/en/about",
mainUrl: "https://criptointercambio.com/",
Expand All @@ -54,14 +58,15 @@ export const SWAP_DATA_CDN: Record<string, AdditionalProviderConfig> = {
needsBearerToken: false,
displayName: "MoonPay",
type: "CEX",
version: 2,
useInExchangeApp: true,
termsOfUseUrl: "https://www.moonpay.com/legal/terms_of_use_row",
supportUrl: "https://support.moonpay.com/",
mainUrl: "https://www.moonpay.com/",
},
oneinch: {
type: "DEX",
needsKYC: false,
useInExchangeApp: false,
displayName: "1inch",
needsBearerToken: false,
termsOfUseUrl: "https://1inch.io/assets/1inch_network_terms_of_use.pdf",
Expand All @@ -71,24 +76,27 @@ export const SWAP_DATA_CDN: Record<string, AdditionalProviderConfig> = {
paraswap: {
type: "DEX",
needsKYC: false,
useInExchangeApp: false,
displayName: "Paraswap",
needsBearerToken: false,
termsOfUseUrl: "https://files.paraswap.io/tos_v4.pdf",
supportUrl: "https://help.paraswap.io/en/",
mainUrl: "https://www.paraswap.io/",
},
thorswap: {
type: "CEX",
type: "DEX",
needsBearerToken: false,
useInExchangeApp: true,
displayName: "THORChain",
termsOfUseUrl: "https://docs.thorswap.finance/thorswap/resources/terms-of-service",
supportUrl: "mailto:[email protected]",
supportUrl: "https://ledgerhelp.swapkit.dev/",
mainUrl: "https://www.thorswap.finance/",
needsKYC: false,
},
uniswap: {
type: "DEX",
needsBearerToken: false,
useInExchangeApp: false,
displayName: "Uniswap",
termsOfUseUrl:
"https://support.uniswap.org/hc/en-us/articles/30935100859661-Uniswap-Labs-Terms-of-Service",
Expand Down Expand Up @@ -237,6 +245,7 @@ export const getSwapProvider = async (
if (ledgerSignatureEnv === "test" && testProviderInfo) {
return {
needsKYC: false,
useInExchangeApp: false,
needsBearerToken: false,
type: "CEX",
termsOfUseUrl: "https://example.com",
Expand Down
9 changes: 6 additions & 3 deletions libs/ledger-live-common/src/exchange/swap/completeExchange.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { convertToAppExchangePartnerKey } from "../providers";
import { CompleteExchangeStep, convertTransportError } from "../error";
import { getDefaultAccountName } from "@ledgerhq/live-wallet/accountName";
import BigNumber from "bignumber.js";
import { CEXProviderConfig } from "../providers/swap";

const withDevicePromise = (deviceId, fn) =>
firstValueFrom(withDevice(deviceId)(transport => from(fn(transport))));
Expand All @@ -49,7 +50,7 @@ const completeExchange = (
const confirmExchange = async () => {
await withDevicePromise(deviceId, async transport => {
const providerConfig = await getSwapProvider(provider);
if (providerConfig.type !== "CEX") {
if (providerConfig.useInExchangeApp === false) {
throw new Error(`Unsupported provider type ${providerConfig.type}`);
}

Expand Down Expand Up @@ -102,11 +103,13 @@ const completeExchange = (
if (errorsKeys.length > 0) throw errors[errorsKeys[0]]; // throw the first error

currentStep = "SET_PARTNER_KEY";
await exchange.setPartnerKey(convertToAppExchangePartnerKey(providerConfig));
await exchange.setPartnerKey(
convertToAppExchangePartnerKey(providerConfig as CEXProviderConfig),
);
if (unsubscribed) return;

currentStep = "CHECK_PARTNER";
await exchange.checkPartner(providerConfig.signature);
await exchange.checkPartner((providerConfig as CEXProviderConfig).signature);
if (unsubscribed) return;

currentStep = "PROCESS_TRANSACTION";
Expand Down
9 changes: 6 additions & 3 deletions libs/ledger-live-common/src/exchange/swap/initSwap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import { decodePayloadProtobuf } from "@ledgerhq/hw-app-exchange";
import { getSwapProvider } from "../providers";
import { convertToAppExchangePartnerKey } from "../providers";
import { getDefaultAccountName } from "@ledgerhq/live-wallet/accountName";
import { CEXProviderConfig } from "../providers/swap";

const withDevicePromise = (deviceId, fn) =>
firstValueFrom(withDevice(deviceId)(transport => from(fn(transport))));
Expand Down Expand Up @@ -167,15 +168,17 @@ const initSwap = (input: InitSwapInput): Observable<SwapRequestEvent> => {
throw errors[errorsKeys[0]]; // throw the first error
}

if (swapProviderConfig.type !== "CEX") {
if (swapProviderConfig.useInExchangeApp === false) {
throw new Error(`Unsupported provider type ${swapProviderConfig.type}`);
}

// Prepare swap app to receive the tx to forward.
await swap.setPartnerKey(convertToAppExchangePartnerKey(swapProviderConfig));
await swap.setPartnerKey(
convertToAppExchangePartnerKey(swapProviderConfig as CEXProviderConfig),
);
if (unsubscribed) return;

await swap.checkPartner(swapProviderConfig.signature!);
await swap.checkPartner((swapProviderConfig as CEXProviderConfig).signature!);
if (unsubscribed) return;

await swap.processTransaction(Buffer.from(swapResult.binaryPayload, "hex"), estimatedFees);
Expand Down

0 comments on commit 2ebf404

Please sign in to comment.