Skip to content

Commit

Permalink
chore: revert
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisduma-ledger committed Sep 3, 2024
1 parent 232df5e commit 10f99fd
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 84 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
Expand All @@ -59,7 +59,7 @@ export const BodyContent = (props: BodyContentProps) => {
return (
<TransactionBroadcastedContent
swapId={props.result.swapId}
mode={props.result.mode}
isSell={props.result.isSell}
provider={props.result.provider}
sourceCurrency={props.result.sourceCurrency}
targetCurrency={props.result.targetCurrency}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,18 @@ import { useGetSellTrackingProperties } from "~/renderer/screens/exchange/Sell/u
import TrackPage from "~/renderer/analytics/TrackPage";
import { Currency } from "@ledgerhq/types-cryptoassets";
import SellCompleted from "~/renderer/screens/exchange/Sell/SellCompleted";
import { ExchangeMode, ExchangeModeEnum } from "./Body";

type TransactionBroadcastedContentProps = {
swapId?: string;
mode: ExchangeMode;
isSell?: boolean;
provider: string;
sourceCurrency: Currency;
targetCurrency?: Currency;
onViewDetails: (id: string) => void;
};

export function TransactionBroadcastedContent(props: TransactionBroadcastedContentProps) {
const { swapId, provider, sourceCurrency, targetCurrency, onViewDetails, mode } = props;
const { swapId, provider, sourceCurrency, targetCurrency, onViewDetails, isSell } = props;
const swapDefaultTrack = useGetSwapTrackingProperties();
const sellDefaultTrack = useGetSellTrackingProperties();

Expand All @@ -35,7 +34,7 @@ export function TransactionBroadcastedContent(props: TransactionBroadcastedConte
provider={provider}
{...(swapId ? swapDefaultTrack : sellDefaultTrack)}
/>
{mode === ExchangeModeEnum.Swap && swapId && targetCurrency && (
{swapId && targetCurrency && (
<>
<Box justifyContent="center" flex={1}>
<SwapCompleted
Expand All @@ -54,7 +53,7 @@ export function TransactionBroadcastedContent(props: TransactionBroadcastedConte
</Box>
</>
)}
{mode === ExchangeModeEnum.Sell && sourceCurrency && (
{isSell && sourceCurrency && (
<>
<Box>
<SellCompleted />
Expand Down
24 changes: 10 additions & 14 deletions apps/ledger-live-mobile/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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
Expand All @@ -292,4 +288,4 @@ DEPENDENCIES
semver2 (~> 3.4, >= 3.4.2)

BUNDLED WITH
2.4.22
2.5.7
3 changes: 0 additions & 3 deletions libs/exchange-module/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,15 +154,13 @@ export class ExchangeModule extends CustomModule {
binaryPayload,
signature,
feeStrategy,
quoteId,
}: {
provider: string;
fromAccountId: string;
transaction: Transaction;
binaryPayload: Buffer;
signature: Buffer;
feeStrategy: ExchangeCompleteParams["feeStrategy"];
quoteId: string;
}): Promise<string> {
const result = await this.request<ExchangeCompleteParams, ExchangeCompleteResult>(
"custom.exchange.complete",
Expand All @@ -174,7 +172,6 @@ export class ExchangeModule extends CustomModule {
hexBinaryPayload: binaryPayload.toString("hex"),
hexSignature: signature.toString("hex"),
feeStrategy,
quoteId,
},
);

Expand Down
3 changes: 0 additions & 3 deletions libs/exchange-module/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 & {
Expand Down
17 changes: 1 addition & 16 deletions libs/ledger-live-common/src/wallet-api/Exchange/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ export type CompleteExchangeUiRequest = {
feesStrategy: string;
exchangeType: number;
swapId?: string;
quoteId?: string;
amountExpectedTo?: number;
magnitudeAwareRate?: BigNumber;
};
Expand Down Expand Up @@ -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: {
Expand All @@ -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,
},
Expand Down

0 comments on commit 10f99fd

Please sign in to comment.