Skip to content

Commit

Permalink
feat(connect-kit): lazy load upgrade-account-modal
Browse files Browse the repository at this point in the history
  • Loading branch information
runjuu committed Jun 22, 2023
1 parent 98dfd99 commit 4a6dd29
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 97 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ import { Loading } from "@crossbell/ui";
import styles from "./index.module.css";
import { DynamicScenesContainer } from "../dynamic-scenes-container";

export function createLazyDynamicScene(Component: React.ComponentType) {
return function LazyModal() {
export function createLazyDynamicScene<T extends object>(
Component: React.ComponentType<T>
) {
return function LazyModal(props: T) {
return (
<React.Suspense fallback={<Placeholder />}>
<Component />
<Component {...props} />
</React.Suspense>
);
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,97 +1,7 @@
import React from "react";
import { useAccount } from "wagmi";
import { useRefCallback } from "@crossbell/util-hooks";

import {
WalletIcon,
EmailIcon,
OptionList,
OptionListItem,
DynamicScenesHeader,
DynamicScenesContainer,
BottomTips,
useDynamicScenesModal,
} from "../../../components";
import { createLazyDynamicScene } from "../../../components";

import { ConnectKindDifferences } from "../../connect-kind-differences";
import { SelectWalletToConnect } from "../select-wallet-to-connect";
import { ConfirmUpgrade } from "../confirm-upgrade";

import styles from "./index.module.css";

export type SelectOptionsProps = {
onCancel?: () => void;
};

export function SelectOptions({ onCancel }: SelectOptionsProps) {
const { goTo, hide } = useDynamicScenesModal();
const { isConnected } = useAccount();

const onSelectDifferences = useRefCallback(() => {
goTo({
kind: "connect-kind-differences",
Component: ConnectKindDifferences,
});
});

const onSelectWallet = useRefCallback(() => {
if (isConnected) {
goTo({
kind: "confirm-upgrade",
Component: () => <ConfirmUpgrade scene="confirm" />,
});
} else {
goTo({
kind: "select-wallet-to-connect",
Component: SelectWalletToConnect,
});
}
});

return (
<DynamicScenesContainer
padding="0 24px 18px"
header={<DynamicScenesHeader title="Upgrade Account" />}
>
<div data-animation="scale-fade-in">
<p className={styles.tips}>
{`Email account can't mint because a wallet is required to keep your assets. `}
<a
className={styles.tipsBtn}
href="https://crossbell-io-updates.xlog.app/Weekly-Updates-2023%2F02%2F06"
target="_blank"
rel="noreferrer"
>
Learn More
</a>
</p>
<OptionList>
<OptionListItem
color="green"
onClick={onSelectWallet}
className={styles.item}
>
Upgrade to Wallet
<WalletIcon className={styles.walletIcon} />
</OptionListItem>

<OptionListItem
color="gray"
onClick={onCancel ?? hide}
className={styles.item}
>
Keep Email Login
<EmailIcon className={styles.emailIcon} />
</OptionListItem>
</OptionList>

<BottomTips
className={styles.differenceBtn}
onClick={onSelectDifferences}
>
What’s the difference
</BottomTips>
</div>
</DynamicScenesContainer>
);
}
export const SelectOptions = createLazyDynamicScene(
React.lazy(() => import("./lazy"))
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import React from "react";
import { useAccount } from "wagmi";
import { useRefCallback } from "@crossbell/util-hooks";

import {
WalletIcon,
EmailIcon,
OptionList,
OptionListItem,
DynamicScenesHeader,
DynamicScenesContainer,
BottomTips,
useDynamicScenesModal,
} from "../../../components";

import { ConnectKindDifferences } from "../../connect-kind-differences";
import { SelectWalletToConnect } from "../select-wallet-to-connect";
import { ConfirmUpgrade } from "../confirm-upgrade";

import styles from "./index.module.css";

export type SelectOptionsProps = {
onCancel?: () => void;
};

export default function SelectOptions({ onCancel }: SelectOptionsProps) {
const { goTo, hide } = useDynamicScenesModal();
const { isConnected } = useAccount();

const onSelectDifferences = useRefCallback(() => {
goTo({
kind: "connect-kind-differences",
Component: ConnectKindDifferences,
});
});

const onSelectWallet = useRefCallback(() => {
if (isConnected) {
goTo({
kind: "confirm-upgrade",
Component: () => <ConfirmUpgrade scene="confirm" />,
});
} else {
goTo({
kind: "select-wallet-to-connect",
Component: SelectWalletToConnect,
});
}
});

return (
<DynamicScenesContainer
padding="0 24px 18px"
header={<DynamicScenesHeader title="Upgrade Account" />}
>
<div data-animation="scale-fade-in">
<p className={styles.tips}>
{`Email account can't mint because a wallet is required to keep your assets. `}
<a
className={styles.tipsBtn}
href="https://crossbell-io-updates.xlog.app/Weekly-Updates-2023%2F02%2F06"
target="_blank"
rel="noreferrer"
>
Learn More
</a>
</p>
<OptionList>
<OptionListItem
color="green"
onClick={onSelectWallet}
className={styles.item}
>
Upgrade to Wallet
<WalletIcon className={styles.walletIcon} />
</OptionListItem>

<OptionListItem
color="gray"
onClick={onCancel ?? hide}
className={styles.item}
>
Keep Email Login
<EmailIcon className={styles.emailIcon} />
</OptionListItem>
</OptionList>

<BottomTips
className={styles.differenceBtn}
onClick={onSelectDifferences}
>
What’s the difference
</BottomTips>
</div>
</DynamicScenesContainer>
);
}

1 comment on commit 4a6dd29

@vercel
Copy link

@vercel vercel bot commented on 4a6dd29 Jun 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

crossbell-universe – ./

crossbell-universe-git-main-crossbell.vercel.app
crossbell-universe-crossbell.vercel.app
crossbell-dev.vercel.app

Please sign in to comment.