Skip to content

Commit

Permalink
LIVE-4306: [feat] select exchange when navigating to smart routing
Browse files Browse the repository at this point in the history
  • Loading branch information
dreis-ledger committed Nov 21, 2022
1 parent dd7c82f commit 2d2e6b7
Show file tree
Hide file tree
Showing 10 changed files with 141 additions and 208 deletions.
5 changes: 5 additions & 0 deletions .changeset/stale-rabbits-deliver.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"ledger-live-desktop": patch
---

Improve redirection to Exchange screen
Original file line number Diff line number Diff line change
Expand Up @@ -116,22 +116,15 @@ export default function BalanceInfos({ totalBalance, valueChange, isAvailable, u

const onBuy = useCallback(() => {
setTrackingSource("Page Portfolio");
// PTX smart routing redirect to live app or to native implementation
if (ptxSmartRouting?.enabled) {
const params = {
mode: "buy", // buy or sell
};

history.push({
// replace 'multibuy' in case live app id changes
pathname: `/platform/${ptxSmartRouting?.params?.liveAppId ?? "multibuy"}`,
state: params,
});
} else {
history.push({
pathname: "/exchange",
});
}

history.push({
pathname: "/exchange",
state: ptxSmartRouting?.enabled
? {
mode: "buy", // buy or sell
}
: undefined,
});
}, [history, ptxSmartRouting]);

const onSwap = useCallback(() => {
Expand Down
37 changes: 15 additions & 22 deletions apps/ledger-live-desktop/src/renderer/components/BuyButton.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,28 +24,21 @@ const BuyButton = ({ currency, account }: { currency: CryptoCurrency, account: A
const onClick = useCallback(() => {
dispatch(closeAllModal());
setTrackingSource("send flow");
if (ptxSmartRouting?.enabled) {
const params = {
currency: currency.id,
account: account.id,
mode: "buy", // buy or sell
};

history.push({
// replace 'multibuy' in case live app id changes
pathname: `/platform/${ptxSmartRouting?.params?.liveAppId ?? "multibuy"}`,
state: params,
});
} else {
history.push({
pathname: "/exchange",
state: {
tab: 0,
defaultCurrency: currency,
defaultAccount: account,
},
});
}

history.push({
pathname: "/exchange",
state: ptxSmartRouting?.enabled
? {
currency: currency.id,
account: account.id,
mode: "buy", // buy or sell
}
: {
tab: 0,
defaultCurrency: currency,
defaultAccount: account,
},
});
}, [account, currency, dispatch, history, ptxSmartRouting]);

if (!isCurrencySupported("BUY", currency)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,27 +68,20 @@ export default function AccountContextMenu({
Icon: IconBuy,
callback: () => {
setTrackingSource("account context menu");
if (ptxSmartRouting?.enabled) {
const params = {
currency: currency?.id,
account: mainAccount?.id,
mode: "buy", // buy or sell
};

history.push({
// replace 'multibuy' in case live app id changes
pathname: `/platform/${ptxSmartRouting?.params?.liveAppId ?? "multibuy"}`,
state: params,
});
} else {
history.push({
pathname: "/exchange",
state: {
defaultCurrency: currency,
defaultAccount: mainAccount,
},
});
}

history.push({
pathname: "/exchange",
state: ptxSmartRouting?.enabled
? {
currency: currency?.id,
account: mainAccount?.id,
mode: "buy", // buy or sell
}
: {
defaultCurrency: currency,
defaultAccount: mainAccount,
},
});
},
});
}
Expand All @@ -100,27 +93,20 @@ export default function AccountContextMenu({
Icon: IconBuy,
callback: () => {
setTrackingSource("account context menu");
if (ptxSmartRouting?.enabled) {
const params = {
currency: currency?.id,
account: mainAccount?.id,
mode: "sell", // buy or sell
};

history.push({
// replace 'multibuy' in case live app id changes
pathname: `/platform/${ptxSmartRouting?.params?.liveAppId ?? "multibuy"}`,
state: params,
});
} else {
history.push({
pathname: "/exchange",
state: {
defaultCurrency: currency,
defaultAccount: mainAccount,
},
});
}

history.push({
pathname: "/exchange",
state: ptxSmartRouting?.enabled
? {
currency: currency?.id,
account: mainAccount?.id,
mode: "sell", // buy or sell
}
: {
defaultCurrency: currency,
defaultAccount: mainAccount,
},
});
},
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,29 +203,21 @@ const AccountHeaderActions = ({ account, parentAccount, openModal }: Props) => {
const onBuySell = useCallback(
(mode = "buy") => {
setTrackingSource("account header actions");
// PTX smart routing redirect to live app or to native implementation
if (ptxSmartRouting?.enabled) {
const params = {
currency: currency?.id,
account: mainAccount?.id,
mode, // buy or sell
};

history.push({
// replace 'multibuy' in case live app id changes
pathname: `/platform/${ptxSmartRouting?.params?.liveAppId ?? "multibuy"}`,
state: params,
});
} else {
history.push({
pathname: "/exchange",
state: {
mode: "onRamp",
currencyId: currency.id,
accountId: mainAccount.id,
},
});
}

history.push({
pathname: "/exchange",
state: ptxSmartRouting?.enabled
? {
currency: currency?.id,
account: mainAccount?.id,
mode, // buy or sell
}
: {
mode: "onRamp",
currencyId: currency.id,
accountId: mainAccount.id,
},
});
},
[currency, history, mainAccount, ptxSmartRouting],
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,29 +77,21 @@ function EmptyStateAccount({ t, account, parentAccount, openModal, history }: Pr

const onBuy = useCallback(() => {
setTrackingSource("empty state account");
// PTX smart routing redirect to live app or to native implementation
if (ptxSmartRouting?.enabled) {
const params = {
currency: currency?.id,
account: mainAccount?.id,
mode: "buy", // buy or sell
};

history.push({
// replace 'multibuy' in case live app id changes
pathname: `/platform/${ptxSmartRouting?.params?.liveAppId ?? "multibuy"}`,
state: params,
});
} else {
history.push({
pathname: "/exchange",
state: {
mode: "onRamp",
currencyId: currency.id,
accountId: mainAccount.id,
},
});
}

history.push({
pathname: "/exchange",
state: ptxSmartRouting?.enabled
? {
currency: currency?.id,
account: mainAccount?.id,
mode: "buy", // buy or sell
}
: {
mode: "onRamp",
currencyId: currency.id,
accountId: mainAccount.id,
},
});
}, [currency, history, mainAccount, ptxSmartRouting]);

if (!mainAccount) return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,27 +100,19 @@ export default function AssetBalanceSummaryHeader({

const onBuy = useCallback(() => {
setTrackingSource("asset header actions");
// PTX smart routing redirect to live app or to native implementation
if (ptxSmartRouting?.enabled) {
const params = {
currency: currency?.id,
mode: "buy", // buy or sell
};

history.push({
// replace 'multibuy' in case live app id changes
pathname: `/platform/${ptxSmartRouting?.params?.liveAppId ?? "multibuy"}`,
state: params,
});
} else {
history.push({
pathname: "/exchange",
state: {
mode: "onRamp",
currencyId: currency.id,
},
});
}

history.push({
pathname: "/exchange",
state: ptxSmartRouting?.enabled
? {
currency: currency?.id,
mode: "buy", // buy or sell
}
: {
mode: "onRamp",
currencyId: currency.id,
},
});
}, [currency.id, history, ptxSmartRouting]);

const onSwap = useCallback(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,27 +54,19 @@ const NoEthereumAccountModal = ({ currency, account, ...rest }: Props) => {
const handleBuy = useCallback(() => {
handleClose();
setTrackingSource("lending deposit");
// PTX smart routing redirect to live app or to native implementation
if (ptxSmartRouting?.enabled) {
const params = {
currency: currency?.id,
mode: "buy", // buy or sell
};

history.push({
// replace 'multibuy' in case live app id changes
pathname: `/platform/${ptxSmartRouting?.params?.liveAppId ?? "multibuy"}`,
state: params,
});
} else {
history.push({
pathname: "/exchange",
state: {
mode: "onRamp",
currencyId: currency.id,
},
});
}
history.push({
pathname: "/exchange",
state: ptxSmartRouting?.enabled
? {
currency: currency?.id,
mode: "buy", // buy or sell
}
: {
mode: "onRamp",
currencyId: currency.id,
},
});
}, [currency, handleClose, history, ptxSmartRouting]);

const TokenCurrencyIcon = getTokenCurrencyIcon(currency);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useCallback, useEffect, useMemo } from "react";
import React, { useCallback, useMemo } from "react";
import { Flex, Text, Icon } from "@ledgerhq/react-ui";
import { useSelector, useDispatch } from "react-redux";
import { useHistory, useParams } from "react-router-dom";
Expand Down Expand Up @@ -86,7 +86,6 @@ export default function MarketCoinScreen() {
counterCurrency,
setCounterCurrency,
supportedCounterCurrencies,
selectCurrency,
} = useSingleCoinMarketData(currencyId);

const rampCatalog = useRampCatalog();
Expand Down Expand Up @@ -135,27 +134,21 @@ export default function MarketCoinScreen() {
e.preventDefault();
e.stopPropagation();
setTrackingSource("Page Market Coin");
// PTX smart routing redirect to live app or to native implementation
if (ptxSmartRouting?.enabled && currency?.internalCurrency) {
const params = {
currency: currency.internalCurrency?.id,
mode: "buy", // buy or sell
};

history.push({
// replace 'multibuy' in case live app id changes
pathname: `/platform/${ptxSmartRouting?.params?.liveAppId ?? "multibuy"}`,
state: params,
});
} else {
history.push({
pathname: "/exchange",
state: {
mode: "onRamp",
defaultTicker: currency && currency.ticker ? currency.ticker.toUpperCase() : undefined,
},
});
}
history.push({
pathname: "/exchange",
state:
ptxSmartRouting?.enabled && currency?.internalCurrency
? {
currency: currency.internalCurrency?.id,
mode: "buy", // buy or sell
}
: {
mode: "onRamp",
defaultTicker:
currency && currency.ticker ? currency.ticker.toUpperCase() : undefined,
},
});
},
[currency, history, ptxSmartRouting],
);
Expand Down
Loading

0 comments on commit 2d2e6b7

Please sign in to comment.