Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Header update #1341

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
6 changes: 5 additions & 1 deletion packages/keychain/.storybook/mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@ export function useMockedConnection({
openModal: () => {},
logout: () => {},
openSettings: () => {},
controller: {},
controller: {
username: () => "test-account",
address:
"0x0000000000000000000000000000000000000000000000000000000000000000",
},
upgrade: {},
...rest,
};
Expand Down
10 changes: 6 additions & 4 deletions packages/keychain/.storybook/provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import { mainnet } from "@starknet-react/chains";
import { StarknetConfig, publicProvider, voyager } from "@starknet-react/core";
import { useThemeEffect } from "@cartridge/ui-next";
import { BrowserRouter } from "react-router-dom";

import { ConnectionContext } from "../src/components/provider/connection";
import { UIProvider } from "../src/components/provider/ui";
import { StoryParameters, useMockedConnection } from "./mock";
import {
ControllerThemeContext,
Expand Down Expand Up @@ -38,9 +38,11 @@ export function Provider({
>
<QueryClientProvider client={queryClient}>
<ConnectionContext.Provider value={connection}>
<ControllerThemeProvider theme={connection.theme}>
<BrowserRouter>{children}</BrowserRouter>
</ControllerThemeProvider>
<UIProvider>
<ControllerThemeProvider theme={connection.theme}>
<BrowserRouter>{children}</BrowserRouter>
</ControllerThemeProvider>
</UIProvider>
</ConnectionContext.Provider>
</QueryClientProvider>
</StarknetConfig>
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 1 addition & 10 deletions packages/keychain/src/components/DeployController.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ export function DeployController({
onClose: () => void;
ctrlError?: ControllerError;
}) {
const { closeModal, chainId, controller, chainName, hasPrefundRequest } =
useConnection();
const { controller, chainName, hasPrefundRequest } = useConnection();
const { deploySelf, isDeploying } = useDeploy();
const [deployHash, setDeployHash] = useState<string>();
const [error, setError] = useState<Error>();
Expand Down Expand Up @@ -112,8 +111,6 @@ export function DeployController({
variant="expanded"
title="Checking account balance..."
icon={<Spinner size="xl" />}
closeModal={closeModal}
chainId={chainId}
/>
</LayoutContainer>
);
Expand Down Expand Up @@ -143,8 +140,6 @@ export function DeployController({
icon={<WandIcon variant="line" size="lg" />}
title="Deploy Controller"
description="This will initialize your controller on the new network"
closeModal={closeModal}
chainId={chainId}
/>
<LayoutContent>
<TransactionSummary
Expand Down Expand Up @@ -181,8 +176,6 @@ export function DeployController({
icon={<Spinner size="xl" />}
title="Deploying Controller"
description={`Your controller is being deployed on ${chainName}`}
closeModal={closeModal}
chainId={chainId}
/>
<LayoutContent>
{deployHash && controller && (
Expand Down Expand Up @@ -215,8 +208,6 @@ export function DeployController({
Icon={CheckIcon}
title="Success!"
description={`Your controller has been deployed on ${chainName}`}
closeModal={closeModal}
chainId={chainId}
/>
<LayoutContent className="items-center">
{deployHash && controller && (
Expand Down
4 changes: 1 addition & 3 deletions packages/keychain/src/components/ErrorBoundary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export class ErrorBoundary extends React.Component<
}

export function ErrorPage({ error }: { error: Error }) {
const { closeModal, chainId } = useConnection();
const { closeModal } = useConnection();

const posthog = usePostHog();

Expand All @@ -54,8 +54,6 @@ export function ErrorPage({ error }: { error: Error }) {
title="Uh oh!"
description="Something went wrong"
Icon={AlertIcon}
onClose={closeModal}
chainId={chainId}
/>
<LayoutContent className="gap-4">
<div className="flex w-full px-4 py-6 bg-background-100 border border-background-200 rounded">
Expand Down
11 changes: 2 additions & 9 deletions packages/keychain/src/components/ExecutionContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export function ExecutionContainer({
children,
}: ExecutionContainerProps &
Pick<HeaderProps, "title" | "description" | "icon">) {
const { controller, closeModal, chainId, openSettings } = useConnection();
const { controller } = useConnection();
const [maxFee, setMaxFee] = useState<bigint | null>(null);
const [ctrlError, setCtrlError] = useState<ControllerError | undefined>(
executionError,
Expand Down Expand Up @@ -164,14 +164,7 @@ export function ExecutionContainer({

return (
<LayoutContainer>
<LayoutHeader
title={title}
description={description}
icon={icon}
onClose={closeModal}
chainId={chainId}
openSettings={openSettings}
/>
<LayoutHeader title={title} description={description} icon={icon} />
{children}
<LayoutFooter>
{(() => {
Expand Down
5 changes: 1 addition & 4 deletions packages/keychain/src/components/SignMessage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export function SignMessage({
onSign: (sig: Signature) => void;
onCancel: () => void;
}) {
const { closeModal, chainId, openSettings, controller } = useConnection();
const { controller } = useConnection();
const [messageData, setMessageData] = useState<TypedData>();

useEffect(() => {
Expand Down Expand Up @@ -72,9 +72,6 @@ export function SignMessage({
<LayoutHeader
title="Signature Request"
description={`${hostname} is asking you to sign a message`}
chainId={chainId}
onClose={closeModal}
openSettings={openSettings}
/>
<LayoutContent>
{messageData && (
Expand Down
4 changes: 1 addition & 3 deletions packages/keychain/src/components/connect/CreateSession.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
onConnect: (transaction_hash?: string, expiresAt?: bigint) => void;
isUpdate?: boolean;
}) {
const { closeModal, controller, upgrade, chainId, theme } = useConnection();
const { controller, upgrade, chainId, theme } = useConnection();
const [isConnecting, setIsConnecting] = useState(false);
const [isConsent, setIsConsent] = useState(false);
const [duration, setDuration] = useState<bigint>(DEFAULT_SESSION_DURATION);
Expand Down Expand Up @@ -79,7 +79,7 @@
setError(e as unknown as Error);
setIsConnecting(false);
}
}, [controller, duration, policies, maxFee, onConnect]);

Check warning on line 82 in packages/keychain/src/components/connect/CreateSession.tsx

View workflow job for this annotation

GitHub Actions / ts-lint

React Hook useCallback has a missing dependency: 'expiresAt'. Either include it or remove the dependency array

const onSkipSession = useCallback(async () => {
if (!controller || !policies) return;
Expand Down Expand Up @@ -111,8 +111,6 @@
? "The policies were updated, please update existing session"
: undefined
}
onClose={closeModal}
chainId={chainId}
/>
<LayoutContent className="gap-6">
<SessionConsent isVerified={policies?.verified} />
Expand Down
6 changes: 1 addition & 5 deletions packages/keychain/src/components/connect/Logout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,13 @@ import { useConnection } from "@/hooks/connection";
import { ResponseCodes } from "@cartridge/controller";

export function Logout() {
const { closeModal, chainId, openSettings, context, logout } =
useConnection();
const { context, logout } = useConnection();
return (
<LayoutContainer>
<LayoutHeader
Icon={SignOutIcon}
title="Log Out"
description="Are you sure?"
onClose={closeModal}
chainId={chainId}
openSettings={openSettings}
/>
<LayoutFooter>
<Button onClick={logout}>Log Out</Button>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
import { LayoutContainer, LayoutHeader, AlertIcon } from "@cartridge/ui-next";
import { useConnection } from "@/hooks/connection";

export function Unsupported({ message }: { message: string }) {
const { closeModal, chainId } = useConnection();

return (
<LayoutContainer>
<LayoutHeader
Icon={AlertIcon}
title="Device is not supported"
description={message}
onClose={closeModal}
chainId={chainId}
/>
</LayoutContainer>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { Unsupported } from "./Unsupported";
import { doSignup } from "@/hooks/account";
import { useIsSupported } from "./useIsSupported";
import { FaceIDImage } from "./FaceID";
import { useConnection } from "@/hooks/connection";

export type AuthAction = "signup" | "login";

Expand All @@ -27,7 +26,6 @@ export function Authenticate({
}) {
const [isLoading, setIsLoading] = useState(false);
const { isSupported, message } = useIsSupported();
const { closeModal, chainId } = useConnection();

const onAuth = useCallback(async () => {
setIsLoading(true);
Expand Down Expand Up @@ -75,8 +73,6 @@ export function Authenticate({
variant="expanded"
title={title}
description={description}
onClose={closeModal}
chainId={chainId}
/>
<LayoutContent className="items-center pb-10">
<FaceIDImage />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import { VerifiableControllerTheme } from "@/context/theme";
import InAppSpy from "inapp-spy";
import { usePostHog } from "@cartridge/utils";
import { useConnection } from "@/hooks/connection";

interface CreateControllerViewProps {
theme: VerifiableControllerTheme;
Expand All @@ -36,6 +35,7 @@
onSubmit: () => void;
onKeyDown: (e: React.KeyboardEvent) => void;
isInAppBrowser?: boolean;
isSlot?: boolean;
}

export function CreateControllerView({
Expand All @@ -45,14 +45,13 @@
isLoading,
error,
isInAppBrowser,
isSlot,
onUsernameChange,
onUsernameFocus,
onUsernameClear,
onSubmit,
onKeyDown,
}: CreateControllerViewProps) {
const { closeModal, chainId } = useConnection();

return (
<LayoutContainer>
<LayoutHeader
Expand All @@ -63,8 +62,8 @@
: `Play ${theme.name}`
}
description="Connect your Controller"
chainId={chainId}
onClose={closeModal}
hideNetwork={isSlot}
hideSettings
/>

<form
Expand Down Expand Up @@ -193,7 +192,7 @@
loginMode,
});

const handleFormSubmit = () => {

Check warning on line 195 in packages/keychain/src/components/connect/create/CreateController.tsx

View workflow job for this annotation

GitHub Actions / ts-lint

The 'handleFormSubmit' function makes the dependencies of useEffect Hook (at line 215) change on every render. To fix this, wrap the definition of 'handleFormSubmit' in its own useCallback() Hook
if (!usernameField.value) {
return;
}
Expand Down Expand Up @@ -267,6 +266,7 @@
isLoading={isLoading}
error={error}
isInAppBrowser={isInApp}
isSlot={isSlot}
onUsernameChange={handleUsernameChange}
onUsernameFocus={handleUsernameFocus}
onUsernameClear={handleUsernameClear}
Expand Down
5 changes: 1 addition & 4 deletions packages/keychain/src/components/failure.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@ import {
} from "@cartridge/ui-next";
import { CARTRIDGE_DISCORD_LINK } from "@/const";
import { Link } from "react-router-dom";
import { useConnection } from "@/hooks/connection";

export function Failure() {
const { closeModal, chainId } = useConnection();
return (
<LayoutContainer>
<LayoutHeader
Expand All @@ -29,8 +27,7 @@ export function Failure() {
</Link>
</>
}
chainId={chainId}
onClose={closeModal}
hideNetwork
/>
</LayoutContainer>
);
Expand Down
4 changes: 1 addition & 3 deletions packages/keychain/src/components/funding/DepositEth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export function DepositEth(innerProps: DepositEthProps) {

function DepositEthInner({ onComplete, onBack }: DepositEthProps) {
const { connectAsync, connectors, isPending: isConnecting } = useConnect();
const { closeModal, controller, chainId } = useConnection();
const { controller, chainId } = useConnection();
const { account: extAccount } = useAccount();

const [dollarAmount, setDollarAmount] = useState<number>(DEFAULT_AMOUNT);
Expand Down Expand Up @@ -159,8 +159,6 @@ function DepositEthInner({ onComplete, onBack }: DepositEthProps) {
}
Icon={EthereumIcon}
onBack={onBack}
chainId={chainId}
onClose={closeModal}
/>

<LayoutContent className="gap-6">
Expand Down
4 changes: 1 addition & 3 deletions packages/keychain/src/components/funding/PurchaseCredits.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type PurchaseCreditsProps = {
};

export function PurchaseCredits({ isSlot, onBack }: PurchaseCreditsProps) {
const { closeModal, chainId, controller } = useConnection();
const { closeModal, controller } = useConnection();

const [clientSecret, setClientSecret] = useState("");
const [isLoading, setisLoading] = useState<boolean>(false);
Expand Down Expand Up @@ -119,8 +119,6 @@ export function PurchaseCredits({ isSlot, onBack }: PurchaseCreditsProps) {
)
}
onBack={state === PurchaseState.SELECTION ? onBack : undefined}
chainId={chainId}
onClose={closeModal}
/>
<LayoutContent className="gap-6">
<Balance showBalances={["credits"]} />
Expand Down
4 changes: 1 addition & 3 deletions packages/keychain/src/components/funding/StripeCheckout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default function StripeCheckout({
}: StripeCheckoutProps) {
const stripe = useStripe();
const elements = useElements();
const { closeModal, chainId, controller } = useConnection();
const { controller } = useConnection();

const [isLoading, setIsLoading] = useState<boolean>(true);
const [isSubmitting, setIsSubmitting] = useState<boolean>(false);
Expand Down Expand Up @@ -88,8 +88,6 @@ export default function StripeCheckout({
description={controller && <CopyAddress address={controller.address} />}
icon={<CoinsIcon variant="solid" size="lg" />}
onBack={onBack}
chainId={chainId}
onClose={closeModal}
/>
<LayoutContent className="gap-6">
<form id="payment-form">
Expand Down
4 changes: 1 addition & 3 deletions packages/keychain/src/components/funding/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export type FundingProps = {
};

export function Funding({ title, isSlot, onComplete }: FundingProps) {
const { closeModal, chainId, controller } = useConnection();
const { controller } = useConnection();
const [state, setState] = useState<FundingState>(FundingState.SHOW_OPTIONS);
const showBalances: BalanceType[] = isSlot ? ["credits"] : ["credits", "eth"];
const showCredits =
Expand Down Expand Up @@ -59,8 +59,6 @@ export function Funding({ title, isSlot, onComplete }: FundingProps) {
title={title || (controller ? `Fund ${controller.username()}` : "")}
description={controller && <CopyAddress address={controller.address} />}
icon={<ArrowIcon variant="down" size="lg" />}
chainId={chainId}
onClose={closeModal}
/>
<LayoutContent className="gap-6">
<Balance showBalances={showBalances} />
Expand Down
Loading
Loading