Skip to content

Commit

Permalink
Merge pull request #7763 from LedgerHQ/feat/LIVE-13616
Browse files Browse the repository at this point in the history
feat: use account id instead of currency id
  • Loading branch information
kallen-ledger authored Sep 6, 2024
2 parents 46006ef + 363377f commit eb1c334
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/afraid-stingrays-hunt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"ledger-live-desktop": patch
---

use account id instead of currency id for sla passthrough
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { SwapLiveError } from "@ledgerhq/live-common/exchange/swap/types";
import { LiveAppManifest } from "@ledgerhq/live-common/platform/types";
import { getAccountIdFromWalletAccountId } from "@ledgerhq/live-common/wallet-api/converters";

import { handlers as loggerHandlers } from "@ledgerhq/live-common/wallet-api/CustomLogger/server";
import { getEnv } from "@ledgerhq/live-env";
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,6 +24,11 @@ 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,6 +44,8 @@ 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";

export class UnableToLoadSwapLiveError extends Error {
constructor(message: string) {
Expand Down Expand Up @@ -91,7 +98,7 @@ const SwapWebView = ({ manifest, liveAppUnavailable }: SwapWebProps) => {
palette: { type: themeType },
},
} = useTheme();

const walletState = useSelector(walletSelector);
const webviewAPIRef = useRef<WebviewAPI>(null);
const { setDrawer } = React.useContext(context);
const [webviewState, setWebviewState] = useState<WebviewState>(initialWebviewState);
Expand All @@ -101,7 +108,7 @@ const SwapWebView = ({ manifest, liveAppUnavailable }: SwapWebProps) => {
const accounts = useSelector(flattenAccountsSelector);
const { t } = useTranslation();
const swapDefaultTrack = useGetSwapTrackingProperties();
const { state } = useLocation<{ defaultCurrency?: { id: string } }>();
const { state } = useLocation<{ defaultAccount?: AccountLike; defaultParentAccount?: Account }>();

const { networkStatus } = useNetworkStatus();
const isOffline = networkStatus === NetworkStatus.OFFLINE;
Expand Down Expand Up @@ -258,11 +265,18 @@ const SwapWebView = ({ manifest, liveAppUnavailable }: SwapWebProps) => {
const hashString = useMemo(
() =>
new URLSearchParams({
...(state?.defaultCurrency?.id ? { from: state?.defaultCurrency?.id } : {}),
...(isOffline ? { isOffline: "true" } : {}),
...(state?.defaultAccount
? {
fromAccountId: accountToWalletAPIAccount(
walletState,
state.defaultAccount,
state?.defaultParentAccount,
).id,
}
: {}),
}).toString(),

[isOffline, state?.defaultCurrency?.id],
[isOffline, state?.defaultAccount, state?.defaultParentAccount, walletState],
);

const onSwapWebviewError = (error?: SwapLiveError) => {
Expand Down

0 comments on commit eb1c334

Please sign in to comment.