Skip to content

Commit

Permalink
fix: drawer loading state on succes (#7815)
Browse files Browse the repository at this point in the history
chore: changeset

fix: updted the logic for disbled tr

fix: update condiiton
  • Loading branch information
liviuciulinaru authored Sep 16, 2024
1 parent e0536c5 commit 7a0bf37
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 25 deletions.
5 changes: 5 additions & 0 deletions .changeset/smooth-ears-learn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"ledger-live-desktop": patch
---

add missing swap custom methods for demo3
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import React, { useCallback, useEffect, useMemo, useRef, useState } from "react";
import { useDispatch } from "react-redux";
import { Operation, SignedOperation } from "@ledgerhq/types-live";
import { Exchange } from "@ledgerhq/live-common/exchange/types";
import { ExchangeSwap } from "@ledgerhq/live-common/exchange/swap/types";
import { DisabledTransactionBroadcastError } from "@ledgerhq/errors";
import { getUpdateAccountWithUpdaterParams } from "@ledgerhq/live-common/exchange/swap/getUpdateAccountWithUpdaterParams";
import { useBroadcast } from "@ledgerhq/live-common/hooks/useBroadcast";
import { ExchangeSwap } from "@ledgerhq/live-common/exchange/swap/types";
import { Exchange } from "@ledgerhq/live-common/exchange/types";
import { Transaction } from "@ledgerhq/live-common/generated/types";
import { useBroadcast } from "@ledgerhq/live-common/hooks/useBroadcast";
import { ExchangeType } from "@ledgerhq/live-common/wallet-api/react";
import { getEnv } from "@ledgerhq/live-env";
import { CryptoCurrency, Currency, TokenCurrency } from "@ledgerhq/types-cryptoassets";
import { updateAccountWithUpdater } from "~/renderer/actions/accounts";
import { BodyContent } from "./BodyContent";
import { AccountLike, Operation, SignedOperation } from "@ledgerhq/types-live";
import { BigNumber } from "bignumber.js";
import { AccountLike } from "@ledgerhq/types-live";
import { DisabledTransactionBroadcastError } from "@ledgerhq/errors";
import { useRedirectToSwapHistory } from "~/renderer/screens/exchange/Swap2/utils";
import { getEnv } from "@ledgerhq/live-env";
import React, { useCallback, useEffect, useMemo, useRef, useState } from "react";
import { useDispatch } from "react-redux";
import styled from "styled-components";
import { ExchangeType } from "@ledgerhq/live-common/wallet-api/react";
import { updateAccountWithUpdater } from "~/renderer/actions/accounts";
import { useIsSwapLiveFlagEnabled } from "~/renderer/screens/exchange/Swap2/hooks/useIsSwapLiveFlagEnabled";
import { useRedirectToSwapHistory } from "~/renderer/screens/exchange/Swap2/utils";
import { BodyContent } from "./BodyContent";

export type Data = {
provider: string;
Expand Down Expand Up @@ -195,13 +195,10 @@ const Body = ({ data, onClose }: { data: Data; onClose?: () => void | undefined
const handleSellTransaction = (operation: Operation, result: ResultsState) => {
handleTransactionResult(result, operation);
};
const isDemo3Enabled = useIsSwapLiveFlagEnabled("ptxSwapLiveAppDemoThree");

const onBroadcastSuccess = useCallback(
(operation: Operation) => {
if (getEnv("DISABLE_TRANSACTION_BROADCAST")) {
return onCancel(new DisabledTransactionBroadcastError());
}

const isSwapTransaction =
swapId && toAccount && magnitudeAwareRate && sourceCurrency && targetCurrency;

Expand All @@ -211,6 +208,14 @@ const Body = ({ data, onClose }: { data: Data; onClose?: () => void | undefined

const result = getResultByTransactionType(isSwapTransaction);

if (getEnv("DISABLE_TRANSACTION_BROADCAST")) {
if (!isSwapTransaction || (isSwapTransaction && !isDemo3Enabled)) {
return onCancel(new DisabledTransactionBroadcastError());
} else {
return handleTransactionResult(result, operation);
}
}

if (isSwapTransaction) {
handleSwapTransaction(operation, result);
} else if (isSellTransaction) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ import { LiveAppManifest } from "@ledgerhq/live-common/platform/types";
import { handlers as loggerHandlers } from "@ledgerhq/live-common/wallet-api/CustomLogger/server";
import { getEnv } from "@ledgerhq/live-env";

import {
accountToWalletAPIAccount,
getAccountIdFromWalletAccountId,
} from "@ledgerhq/live-common/wallet-api/converters";
import BigNumber from "bignumber.js";
import React, { useEffect, useMemo, useRef, useState } from "react";
import { useSelector } from "react-redux";
import styled from "styled-components";
Expand All @@ -24,11 +29,6 @@ import {
} from "~/renderer/reducers/settings";
import { captureException } from "~/sentry/renderer";
import WebviewErrorDrawer from "./WebviewErrorDrawer/index";
import BigNumber from "bignumber.js";
import {
accountToWalletAPIAccount,
getAccountIdFromWalletAccountId,
} from "@ledgerhq/live-common/wallet-api/converters";

import { GasOptions } from "@ledgerhq/coin-evm/lib/types/transaction";
import { getMainAccount, getParentAccount } from "@ledgerhq/live-common/account/helpers";
Expand All @@ -39,13 +39,17 @@ import {
convertToNonAtomicUnit,
getCustomFeesPerFamily,
} from "@ledgerhq/live-common/exchange/swap/webApp/utils";
import { Account, AccountLike } from "@ledgerhq/types-live";
import { useTranslation } from "react-i18next";
import { useLocation } from "react-router";
import { NetworkStatus, useNetworkStatus } from "~/renderer/hooks/useNetworkStatus";
import { transformToBigNumbers, useGetSwapTrackingProperties } from "../utils/index";
import FeesDrawerLiveApp from "./FeesDrawerLiveApp";
import { walletSelector } from "~/renderer/reducers/wallet";
import { Account, AccountLike } from "@ledgerhq/types-live";
import {
transformToBigNumbers,
useGetSwapTrackingProperties,
useRedirectToSwapHistory,
} from "../utils/index";
import FeesDrawerLiveApp from "./FeesDrawerLiveApp";

export class UnableToLoadSwapLiveError extends Error {
constructor(message: string) {
Expand Down Expand Up @@ -109,6 +113,7 @@ const SwapWebView = ({ manifest, liveAppUnavailable }: SwapWebProps) => {
const { t } = useTranslation();
const swapDefaultTrack = useGetSwapTrackingProperties();
const { state } = useLocation<{ defaultAccount?: AccountLike; defaultParentAccount?: Account }>();
const redirectToHistory = useRedirectToSwapHistory();

const { networkStatus } = useNetworkStatus();
const isOffline = networkStatus === NetworkStatus.OFFLINE;
Expand Down Expand Up @@ -257,6 +262,9 @@ const SwapWebView = ({ manifest, liveAppUnavailable }: SwapWebProps) => {
);
});
},
"custom.swapRedirectToHistory": () => {
redirectToHistory();
},
}),
// eslint-disable-next-line react-hooks/exhaustive-deps
[],
Expand Down

0 comments on commit 7a0bf37

Please sign in to comment.