Skip to content

Commit

Permalink
Revert "Add theme origin mismatch warning (#1183)"
Browse files Browse the repository at this point in the history
This reverts commit e418c13.
  • Loading branch information
tarrencev committed Dec 18, 2024
1 parent e418c13 commit 75d59fd
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 63 deletions.
4 changes: 2 additions & 2 deletions packages/keychain/src/components/Provider/connection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import Controller from "utils/controller";
import { ConnectionCtx } from "utils/connection";
import { Prefund } from "@cartridge/controller";
import { UpgradeInterface } from "hooks/upgrade";
import { ControllerTheme } from "@cartridge/presets";
import { ParsedSessionPolicies } from "hooks/session";
import { VerifiableControllerTheme } from "hooks/theme";

export const ConnectionContext = createContext<
ConnectionContextValue | undefined
Expand All @@ -18,7 +18,7 @@ export type ConnectionContextValue = {
chainId?: string;
chainName?: string;
policies?: ParsedSessionPolicies;
theme: VerifiableControllerTheme;
theme: ControllerTheme;
prefunds: Prefund[];
hasPrefundRequest: boolean;
error?: Error;
Expand Down
13 changes: 0 additions & 13 deletions packages/keychain/src/components/layout/Footer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import { CartridgeLogo } from "@cartridge/ui";
import React, { useEffect, useRef } from "react";
import { FOOTER_HEIGHT, useLayout } from "components/layout";
import NextLink from "next/link";
import { useControllerTheme } from "hooks/theme";
import { ErrorAlert } from "../../ErrorAlert";

export function Footer({
children,
Expand All @@ -14,7 +12,6 @@ export function Footer({
}) {
const ref = useRef<HTMLDivElement | null>(null);
const { footer } = useLayout();
const theme = useControllerTheme();

useEffect(() => {
if (!ref.current) return;
Expand Down Expand Up @@ -55,16 +52,6 @@ export function Footer({
p={4}
pb={showCatridgeLogo ? 1 : 4}
>
{!theme.verified && (
<div className="mb-5">
<ErrorAlert
title="Please proceed with caution"
description="Application domain does not match the configured domain."
variant="warning"
isExpanded
/>
</div>
)}
{children}
</VStack>

Expand Down
54 changes: 15 additions & 39 deletions packages/keychain/src/hooks/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { RpcProvider } from "starknet";
import {
Prefund,
ResponseCodes,
toArray,
toSessionPolicies,
} from "@cartridge/controller";
import { mergeDefaultETHPrefund } from "utils/token";
Expand All @@ -29,7 +28,6 @@ import {
ControllerTheme,
} from "@cartridge/presets";
import { ParsedSessionPolicies, parseSessionPolicies } from "./session";
import { VerifiableControllerTheme } from "./theme";

type ParentMethods = AsyncMethodReturns<{ close: () => Promise<void> }>;

Expand All @@ -40,10 +38,7 @@ export function useConnectionValue() {
const [rpcUrl, setRpcUrl] = useState<string>();
const [chainId, setChainId] = useState<string>();
const [policies, setPolicies] = useState<ParsedSessionPolicies>();
const [theme, setTheme] = useState<VerifiableControllerTheme>({
verified: true,
...defaultTheme,
});
const [theme, setTheme] = useState<ControllerTheme>(defaultTheme);
const [controller, setControllerRaw] = useState<Controller | undefined>();
const [prefunds, setPrefunds] = useState<Prefund[]>([]);
const [hasPrefundRequest, setHasPrefundRequest] = useState<boolean>(false);
Expand Down Expand Up @@ -136,17 +131,9 @@ export function useConnectionValue() {
const decodedPreset = decodeURIComponent(themeParam);
try {
const parsedTheme = JSON.parse(decodedPreset) as ControllerTheme;
setTheme({
...parsedTheme,
verified: true,
});
setTheme(parsedTheme);
} catch (e) {
if (controllerConfigs[decodedPreset].theme) {
setTheme({
...controllerConfigs[decodedPreset].theme,
verified: true,
});
}
setTheme(controllerConfigs[decodedPreset].theme || defaultTheme);
}
}

Expand All @@ -169,39 +156,28 @@ export function useConnectionValue() {
}

// Application provided policies take precedence over preset policies.
if (presetParam && presetParam in controllerConfigs) {
const verified =
origin &&
toArray(controllerConfigs[presetParam].origin).some((allowedOrigin) => {
const originUrl = new URL(origin);
return originUrl.hostname === allowedOrigin;
});

if (controllerConfigs[presetParam].theme) {
setTheme({
verified: !!verified,
...controllerConfigs[presetParam].theme,
});
}
if (
presetParam &&
presetParam in controllerConfigs
// TODO: Reenable
// &&
// origin &&
// (origin.startsWith("http://localhost") ||
// toArray(controllerConfigs[presetParam].origin).includes(origin))
) {
setTheme(controllerConfigs[presetParam].theme || defaultTheme);

// Set policies from preset if no URL policies
if (!policiesParam && controllerConfigs[presetParam].policies) {
setPolicies(
parseSessionPolicies({
verified: !!verified,
verified: true,
policies: controllerConfigs[presetParam].policies,
}),
);
}
}
}, [
origin,
setTheme,
setPolicies,
setHasPrefundRequest,
setOrigin,
setPrefunds,
]);
}, [setTheme, setPolicies, setHasPrefundRequest, setOrigin, setPrefunds]);

useEffect(() => {
const connection = connectToController<ParentMethods>({
Expand Down
12 changes: 3 additions & 9 deletions packages/keychain/src/hooks/theme.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,20 @@ import { ControllerColor, ControllerTheme } from "@cartridge/presets";
import { CartridgeTheme } from "@cartridge/ui";
import { useContext, createContext, useMemo } from "react";

export type VerifiableControllerTheme = ControllerTheme & {
verified: boolean;
};

export const ControllerThemeContext = createContext<
VerifiableControllerTheme | undefined
ControllerTheme | undefined
>(undefined);

export function useControllerTheme() {
const ctx = useContext<VerifiableControllerTheme | undefined>(
ControllerThemeContext,
);
const ctx = useContext<ControllerTheme | undefined>(ControllerThemeContext);
if (!ctx) {
throw new Error("ControllerThemeProvider must be placed");
}

return ctx;
}

export function useChakraTheme(preset: VerifiableControllerTheme) {
export function useChakraTheme(preset: ControllerTheme) {
return useMemo(
() => ({
...CartridgeTheme,
Expand Down

0 comments on commit 75d59fd

Please sign in to comment.