Skip to content

Commit

Permalink
refactor: use hook in mobile webviews
Browse files Browse the repository at this point in the history
  • Loading branch information
beths-ledger committed Apr 19, 2024
1 parent d99742b commit 11592fe
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,8 @@ import {
} from "@ledgerhq/live-common/platform/react";
import trackingWrapper from "@ledgerhq/live-common/platform/tracking";
import BigNumber from "bignumber.js";
import {
DEFAULT_MULTIBUY_APP_ID,
BUY_SELL_UI_APP_ID,
} from "@ledgerhq/live-common/wallet-api/constants";
import { INTERNAL_APP_IDS } from "@ledgerhq/live-common/wallet-api/constants";
import { useInternalAppIds } from "@ledgerhq/live-common/hooks/useInternalAppIds";
import { safeGetRefValue } from "@ledgerhq/live-common/wallet-api/react";
import { NavigatorName, ScreenName } from "~/const";
import { broadcastSignedTx } from "~/logic/screenTransactionHooks";
Expand All @@ -50,7 +48,6 @@ import { BaseNavigatorStackParamList } from "../RootNavigator/types/BaseNavigato
import { WebviewAPI, WebviewProps } from "./types";
import { useWebviewState } from "./helpers";
import { currentRouteNameRef } from "~/analytics/screenRefs";
import { useFeature } from "@ledgerhq/live-common/featureFlags/index";

function renderLoading() {
return (
Expand Down Expand Up @@ -512,12 +509,9 @@ export const PlatformAPIWebview = forwardRef<WebviewAPI, WebviewProps>(
tracking.platformLoad(manifest);
}, [manifest, tracking]);

const buySellUiFlag = useFeature("buySellUi");
const buySellAppIds = buySellUiFlag?.params?.manifestId
? [buySellUiFlag.params.manifestId, DEFAULT_MULTIBUY_APP_ID, BUY_SELL_UI_APP_ID]
: [DEFAULT_MULTIBUY_APP_ID, BUY_SELL_UI_APP_ID];
const internalAppIds = useInternalAppIds() || INTERNAL_APP_IDS;

const javaScriptCanOpenWindowsAutomatically = buySellAppIds.includes(manifest.id);
const javaScriptCanOpenWindowsAutomatically = internalAppIds.includes(manifest.id);

return (
<RNWebView
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,10 @@ import Config from "react-native-config";
import { WebviewAPI, WebviewProps } from "./types";
import { useWebView } from "./helpers";
import { NetworkError } from "./NetworkError";
import {
DEFAULT_MULTIBUY_APP_ID,
BUY_SELL_UI_APP_ID,
} from "@ledgerhq/live-common/wallet-api/constants";
import { INTERNAL_APP_IDS } from "@ledgerhq/live-common/wallet-api/constants";
import { useInternalAppIds } from "@ledgerhq/live-common/hooks/useInternalAppIds";
import { INJECTED_JAVASCRIPT } from "./dappInject";
import { NoAccountScreen } from "./NoAccountScreen";
import { useFeature } from "@ledgerhq/live-common/featureFlags/index";

export const WalletAPIWebview = forwardRef<WebviewAPI, WebviewProps>(
(
Expand Down Expand Up @@ -40,12 +37,9 @@ export const WalletAPIWebview = forwardRef<WebviewAPI, WebviewProps>(
webviewRef.current?.reload();
};

const buySellUiFlag = useFeature("buySellUi");
const buySellAppIds = buySellUiFlag?.params?.manifestId
? [buySellUiFlag.params.manifestId, DEFAULT_MULTIBUY_APP_ID, BUY_SELL_UI_APP_ID]
: [DEFAULT_MULTIBUY_APP_ID, BUY_SELL_UI_APP_ID];
const internalAppIds = useInternalAppIds() || INTERNAL_APP_IDS;

const javaScriptCanOpenWindowsAutomatically = buySellAppIds.includes(manifest.id);
const javaScriptCanOpenWindowsAutomatically = internalAppIds.includes(manifest.id);

if (!!manifest.dapp && noAccounts) {
return <NoAccountScreen manifest={manifest} currentAccountHistDb={currentAccountHistDb} />;
Expand Down

0 comments on commit 11592fe

Please sign in to comment.