From 10f99fd0f5a83f36667f7d90c22dc506f34372fa Mon Sep 17 00:00:00 2001 From: chrisduma-ledger Date: Tue, 3 Sep 2024 14:44:02 +0300 Subject: [PATCH] chore: revert --- .../Exchange/CompleteExchange/Body.tsx | 65 +++++++------------ .../Exchange/CompleteExchange/BodyContent.tsx | 6 +- .../TransactionBroadcastedContent.tsx | 9 ++- apps/ledger-live-mobile/Gemfile.lock | 24 +++---- libs/exchange-module/src/index.ts | 3 - libs/exchange-module/src/types.ts | 3 - .../src/wallet-api/Exchange/server.ts | 17 +---- 7 files changed, 43 insertions(+), 84 deletions(-) diff --git a/apps/ledger-live-desktop/src/renderer/modals/Platform/Exchange/CompleteExchange/Body.tsx b/apps/ledger-live-desktop/src/renderer/modals/Platform/Exchange/CompleteExchange/Body.tsx index 75344530e36a..508971652f94 100644 --- a/apps/ledger-live-desktop/src/renderer/modals/Platform/Exchange/CompleteExchange/Body.tsx +++ b/apps/ledger-live-desktop/src/renderer/modals/Platform/Exchange/CompleteExchange/Body.tsx @@ -32,15 +32,8 @@ export type Data = { magnitudeAwareRate?: BigNumber; }; -export enum ExchangeModeEnum { - Sell = "sell", - Swap = "swap", -} - -export type ExchangeMode = "sell" | "swap"; - type ResultsState = { - mode: ExchangeMode; + isSell?: boolean; swapId?: string; provider: string; sourceCurrency: Currency; @@ -156,44 +149,36 @@ const Body = ({ data, onClose }: { data: Data; onClose?: () => void | undefined const onBroadcastSuccess = useCallback( (operation: Operation) => { - // TODO: swapId && sellId will become quoteId - - const isValidExchangeSDKSwapTx = - (ExchangeType.SWAP || ExchangeType.SWAP_NG) && - swapId && - toAccount && - magnitudeAwareRate && - sourceCurrency && - targetCurrency; + // If swap we save to swap history and keep open the drawer + if (swapId && toAccount && magnitudeAwareRate && sourceCurrency && targetCurrency) { + const newResult = { + operation, + swapId, + }; + updateAccount({ + result: newResult, + magnitudeAwareRate, + }); + setResult({ + swapId, + provider, + sourceCurrency, + targetCurrency, + }); - const isValidExchangeSDKSellTx = - (data.exchangeType === ExchangeType.SELL || data.exchangeType === ExchangeType.SELL_NG) && - sourceCurrency; - - if (isValidExchangeSDKSellTx || isValidExchangeSDKSwapTx) { - if (isValidExchangeSDKSwapTx) { - const newResult = { - operation, - swapId, - }; - - updateAccount({ - result: newResult, - magnitudeAwareRate, - }); + if (getEnv("DISABLE_TRANSACTION_BROADCAST")) { + return onCancel(new DisabledTransactionBroadcastError()); } - - const result = isValidExchangeSDKSwapTx - ? { swapId, provider, sourceCurrency, targetCurrency, mode: ExchangeModeEnum.Swap } - : { provider, mode: ExchangeModeEnum.Sell, sourceCurrency }; - - setResult(result); - + onResult(operation); + } else if ( + (data.exchangeType === ExchangeType.SELL || data.exchangeType === ExchangeType.SELL_NG) && + sourceCurrency + ) { if (getEnv("DISABLE_TRANSACTION_BROADCAST")) { return onCancel(new DisabledTransactionBroadcastError()); } - onResult(operation); + setResult({ provider, isSell: true, sourceCurrency }); } else { // else not swap i.e card we close the drawer onResult(operation); diff --git a/apps/ledger-live-desktop/src/renderer/modals/Platform/Exchange/CompleteExchange/BodyContent.tsx b/apps/ledger-live-desktop/src/renderer/modals/Platform/Exchange/CompleteExchange/BodyContent.tsx index 6b62f9069d07..7e1527b0b0c7 100644 --- a/apps/ledger-live-desktop/src/renderer/modals/Platform/Exchange/CompleteExchange/BodyContent.tsx +++ b/apps/ledger-live-desktop/src/renderer/modals/Platform/Exchange/CompleteExchange/BodyContent.tsx @@ -11,7 +11,6 @@ import DeviceAction from "~/renderer/components/DeviceAction"; import BigSpinner from "~/renderer/components/BigSpinner"; import ErrorDisplay from "~/renderer/components/ErrorDisplay"; import { TransactionBroadcastedContent } from "./TransactionBroadcastedContent"; -import { ExchangeMode } from "./Body"; const exchangeAction = createAction(completeExchange); const sendAction = txCreateAction(connectApp); @@ -38,7 +37,8 @@ export type BodyContentProps = { }; result?: { swapId?: string; - mode: ExchangeMode; + // The isSell will probably be replaced with a sellId similar with swapId. + isSell?: boolean; provider: string; sourceCurrency: Currency; targetCurrency?: Currency; @@ -59,7 +59,7 @@ export const BodyContent = (props: BodyContentProps) => { return ( - {mode === ExchangeModeEnum.Swap && swapId && targetCurrency && ( + {swapId && targetCurrency && ( <> )} - {mode === ExchangeModeEnum.Sell && sourceCurrency && ( + {isSell && sourceCurrency && ( <> diff --git a/apps/ledger-live-mobile/Gemfile.lock b/apps/ledger-live-mobile/Gemfile.lock index 153b3c9586ee..ccfd7e88b0db 100644 --- a/apps/ledger-live-mobile/Gemfile.lock +++ b/apps/ledger-live-mobile/Gemfile.lock @@ -5,12 +5,11 @@ GEM base64 nkf rexml - activesupport (6.1.7.8) + activesupport (7.0.8.4) concurrent-ruby (~> 1.0, >= 1.0.2) i18n (>= 1.6, < 2) minitest (>= 5.1) tzinfo (~> 2.0) - zeitwerk (~> 2.3) addressable (2.8.7) public_suffix (>= 2.0.2, < 7.0) algoliasearch (1.27.5) @@ -82,14 +81,13 @@ GEM declarative (0.0.20) digest-crc (0.6.5) rake (>= 12.0.0, < 14.0.0) - domain_name (0.5.20190701) - unf (>= 0.0.5, < 1.0.0) + domain_name (0.6.20240107) dotenv (2.8.1) emoji_regex (3.2.3) escape (0.0.4) ethon (0.16.0) ffi (>= 1.15.0) - excon (0.109.0) + excon (0.111.0) faraday (1.10.3) faraday-em_http (~> 1.0) faraday-em_synchrony (~> 1.0) @@ -180,19 +178,19 @@ GEM google-apis-core (>= 0.11.0, < 2.a) google-apis-playcustomapp_v1 (0.13.0) google-apis-core (>= 0.11.0, < 2.a) - google-apis-storage_v1 (0.29.0) + google-apis-storage_v1 (0.31.0) google-apis-core (>= 0.11.0, < 2.a) - google-cloud-core (1.6.1) + google-cloud-core (1.7.1) google-cloud-env (>= 1.0, < 3.a) google-cloud-errors (~> 1.0) google-cloud-env (1.6.0) faraday (>= 0.17.3, < 3.0) - google-cloud-errors (1.3.1) - google-cloud-storage (1.45.0) + google-cloud-errors (1.4.0) + google-cloud-storage (1.47.0) addressable (~> 2.8) digest-crc (~> 0.4) google-apis-iamcredentials_v1 (~> 0.1) - google-apis-storage_v1 (~> 0.29.0) + google-apis-storage_v1 (~> 0.31.0) google-cloud-core (~> 1.6) googleauth (>= 0.16.2, < 2.a) mini_mime (~> 1.0) @@ -241,7 +239,7 @@ GEM rubyzip (2.3.2) security (0.1.3) semver2 (3.4.2) - signet (0.18.0) + signet (0.19.0) addressable (~> 2.8) faraday (>= 0.17.5, < 3.a) jwt (>= 1.5, < 3.0) @@ -263,7 +261,6 @@ GEM tzinfo (2.0.6) concurrent-ruby (~> 1.0) uber (0.1.0) - unf (0.2.0) unicode-display_width (2.5.0) word_wrap (1.0.0) xcodeproj (1.25.0) @@ -277,7 +274,6 @@ GEM rouge (~> 2.0.7) xcpretty-travis-formatter (1.0.1) xcpretty (~> 0.2, >= 0.0.7) - zeitwerk (2.6.17) PLATFORMS ruby @@ -292,4 +288,4 @@ DEPENDENCIES semver2 (~> 3.4, >= 3.4.2) BUNDLED WITH - 2.4.22 + 2.5.7 diff --git a/libs/exchange-module/src/index.ts b/libs/exchange-module/src/index.ts index b905f74c84fc..e13aadfeeed2 100644 --- a/libs/exchange-module/src/index.ts +++ b/libs/exchange-module/src/index.ts @@ -154,7 +154,6 @@ export class ExchangeModule extends CustomModule { binaryPayload, signature, feeStrategy, - quoteId, }: { provider: string; fromAccountId: string; @@ -162,7 +161,6 @@ export class ExchangeModule extends CustomModule { binaryPayload: Buffer; signature: Buffer; feeStrategy: ExchangeCompleteParams["feeStrategy"]; - quoteId: string; }): Promise { const result = await this.request( "custom.exchange.complete", @@ -174,7 +172,6 @@ export class ExchangeModule extends CustomModule { hexBinaryPayload: binaryPayload.toString("hex"), hexSignature: signature.toString("hex"), feeStrategy, - quoteId, }, ); diff --git a/libs/exchange-module/src/types.ts b/libs/exchange-module/src/types.ts index 583b4e6aadc7..c7d47fcd1eb5 100644 --- a/libs/exchange-module/src/types.ts +++ b/libs/exchange-module/src/types.ts @@ -45,13 +45,10 @@ export type ExchangeCompleteBaseParams = { export type ExchangeCompleteFundParams = ExchangeCompleteBaseParams & { exchangeType: "FUND"; - // Optional until we actually implement it - quoteId?: string; }; export type ExchangeCompleteSellParams = ExchangeCompleteBaseParams & { exchangeType: "SELL"; - quoteId: string; }; export type ExchangeCompleteSwapParams = ExchangeCompleteBaseParams & { diff --git a/libs/ledger-live-common/src/wallet-api/Exchange/server.ts b/libs/ledger-live-common/src/wallet-api/Exchange/server.ts index 39d82793ec0b..1f6e2b28f4cd 100644 --- a/libs/ledger-live-common/src/wallet-api/Exchange/server.ts +++ b/libs/ledger-live-common/src/wallet-api/Exchange/server.ts @@ -62,7 +62,6 @@ export type CompleteExchangeUiRequest = { feesStrategy: string; exchangeType: number; swapId?: string; - quoteId?: string; amountExpectedTo?: number; magnitudeAwareRate?: BigNumber; }; @@ -272,15 +271,6 @@ export const handlers = ({ magnitudeAwareRate = tx.amount && amountExpectedTo.dividedBy(tx.amount); } - // Typeguard, so typescript does not complain, - // This check is necessary because TypeScript sometimes fails to correctly infer the union type properties. - const quoteOrSwapId = - params.exchangeType === "SWAP" - ? params.swapId - : "quoteId" in params - ? params.quoteId - : undefined; - return new Promise((resolve, reject) => uiExchangeComplete({ exchangeParams: { @@ -291,12 +281,7 @@ export const handlers = ({ binaryPayload: params.hexBinaryPayload, exchange, feesStrategy: params.feeStrategy, - // swapId still here for backwards compatibility, we are planning to rename this field to quoteId to align with sell and card - swapId: - params.exchangeType === "SWAP" - ? (params as ExchangeCompleteSwapParams).swapId - : undefined, - quoteId: quoteOrSwapId, + swapId: params.exchangeType === "SWAP" ? params.swapId : undefined, amountExpectedTo, magnitudeAwareRate, },