From 049c03e89fa099806005f76b757fec1e1ba3dc55 Mon Sep 17 00:00:00 2001
From: Maxime Beauchamp <15185355+baktun14@users.noreply.github.com>
Date: Tue, 10 Dec 2024 15:10:29 -0500
Subject: [PATCH] fix(billing): properly handle user state for email
verification
---
.../get-started/GetStartedStepper.tsx | 45 +++++++++++--------
.../src/components/home/YourAccount.tsx | 27 ++++++-----
.../src/components/shared/VerifyEmail.tsx | 20 +++++++++
.../src/components/user/LoginRequiredLink.tsx | 10 ++++-
.../components/wallet/ManagedWalletPopup.tsx | 27 +++--------
.../src/hooks/useHasCreditCardBanner.ts | 4 +-
.../src/hooks/useRequiredEmailVerified.ts | 6 +++
7 files changed, 88 insertions(+), 51 deletions(-)
create mode 100644 apps/deploy-web/src/components/shared/VerifyEmail.tsx
create mode 100644 apps/deploy-web/src/hooks/useRequiredEmailVerified.ts
diff --git a/apps/deploy-web/src/components/get-started/GetStartedStepper.tsx b/apps/deploy-web/src/components/get-started/GetStartedStepper.tsx
index 97a8f9899..9bfd31030 100644
--- a/apps/deploy-web/src/components/get-started/GetStartedStepper.tsx
+++ b/apps/deploy-web/src/components/get-started/GetStartedStepper.tsx
@@ -18,6 +18,7 @@ import { browserEnvConfig } from "@src/config/browser-env.config";
import { useChainParam } from "@src/context/ChainParamProvider";
import { useWallet } from "@src/context/WalletProvider";
import { useCustomUser } from "@src/hooks/useCustomUser";
+import { useIsEmailVerified } from "@src/hooks/useRequiredEmailVerified";
import { useWalletBalance } from "@src/hooks/useWalletBalance";
import walletStore from "@src/store/walletStore";
import { RouteStep } from "@src/types/route-steps.type";
@@ -26,6 +27,7 @@ import { uaktToAKT } from "@src/utils/priceUtils";
import { UrlService } from "@src/utils/urlUtils";
import LiquidityModal from "../liquidity-modal";
import { ExternalLink } from "../shared/ExternalLink";
+import { VerifyEmail } from "../shared/VerifyEmail";
import { ConnectWalletButton } from "../wallet/ConnectWalletButton";
import { QontoConnector, QontoStepIcon } from "./Stepper";
@@ -38,6 +40,7 @@ export const GetStartedStepper: React.FunctionComponent = () => {
const usdcBalance = walletBalance ? udenomToDenom(walletBalance.balanceUUSDC) : 0;
const [isSignedInWithTrial] = useAtom(walletStore.isSignedInWithTrial);
const { user } = useCustomUser();
+ const isEmailVerified = useIsEmailVerified();
useEffect(() => {
const getStartedStep = localStorage.getItem("getStartedStep");
@@ -104,27 +107,33 @@ export const GetStartedStepper: React.FunctionComponent = () => {
{isManagedWallet && (
-
-
-
- Add Funds
-
-
- )}
-
- {!isManagedWallet && (
-
- Learn how
-
+
+
+
+
+
+
+ Add Funds
+
+
+
)}
+
+ {!isManagedWallet && (
+
+ Learn how
+
+ )}
+
{isWalletConnected && isTrialing && (
diff --git a/apps/deploy-web/src/components/home/YourAccount.tsx b/apps/deploy-web/src/components/home/YourAccount.tsx
index f5fb9dd4f..0fd5ffc28 100644
--- a/apps/deploy-web/src/components/home/YourAccount.tsx
+++ b/apps/deploy-web/src/components/home/YourAccount.tsx
@@ -16,6 +16,7 @@ import { UAKT_DENOM } from "@src/config/denom.config";
import { usePricing } from "@src/context/PricingProvider";
import { useWallet } from "@src/context/WalletProvider";
import { useUsdcDenom } from "@src/hooks/useDenom";
+import { useIsEmailVerified } from "@src/hooks/useRequiredEmailVerified";
import useTailwind from "@src/hooks/useTailwind";
import { WalletBalance } from "@src/hooks/useWalletBalance";
import sdlStore from "@src/store/sdlStore";
@@ -30,6 +31,7 @@ import { ConnectWallet } from "../shared/ConnectWallet";
import { LeaseSpecDetail } from "../shared/LeaseSpecDetail";
import { PriceValue } from "../shared/PriceValue";
import { StatusPill } from "../shared/StatusPill";
+import { VerifyEmail } from "../shared/VerifyEmail";
type Props = {
isLoadingBalances: boolean;
@@ -56,6 +58,7 @@ export const YourAccount: React.FunctionComponent
= ({ isLoadingBalances,
const _storage = bytesToShrink(totalStorage);
const [, setDeploySdl] = useAtom(sdlStore.deploySdl);
const { price, isLoaded } = usePricing();
+ const isEmailVerified = useIsEmailVerified();
const colors = {
balance_akt: customColors.akashRed,
@@ -230,16 +233,20 @@ export const YourAccount: React.FunctionComponent = ({ isLoadingBalances,
)}
{isManagedWallet && (
-
-
- Add Funds
-
-
-
+ <>
+
+
+
+ Add Funds
+
+
+
+ >
)}
diff --git a/apps/deploy-web/src/components/shared/VerifyEmail.tsx b/apps/deploy-web/src/components/shared/VerifyEmail.tsx
new file mode 100644
index 000000000..884120d4b
--- /dev/null
+++ b/apps/deploy-web/src/components/shared/VerifyEmail.tsx
@@ -0,0 +1,20 @@
+import { Alert, AlertDescription } from "@akashnetwork/ui/components";
+import { cn } from "@akashnetwork/ui/utils";
+import { WarningCircle } from "iconoir-react";
+
+import { useIsEmailVerified } from "@src/hooks/useRequiredEmailVerified";
+
+export const VerifyEmail = ({ className }: { className?: string }) => {
+ const isEmailVerified = useIsEmailVerified();
+
+ if (isEmailVerified) return null;
+
+ return (
+
+
+
+ Verify your email to add funds to your balance.
+
+
+ );
+};
diff --git a/apps/deploy-web/src/components/user/LoginRequiredLink.tsx b/apps/deploy-web/src/components/user/LoginRequiredLink.tsx
index 9cb4f1b07..6bb98e628 100644
--- a/apps/deploy-web/src/components/user/LoginRequiredLink.tsx
+++ b/apps/deploy-web/src/components/user/LoginRequiredLink.tsx
@@ -1,4 +1,5 @@
import React from "react";
+import { Button } from "@akashnetwork/ui/components";
import Link, { LinkProps } from "next/link";
import { useLoginRequiredEventHandler } from "@src/hooks/useLoginRequiredEventHandler";
@@ -9,8 +10,15 @@ export const LoginRequiredLink: FCWithChildren<
LinkProps & {
children?: React.ReactNode;
message: string;
+ disabled?: boolean;
} & React.RefAttributes
> = ({ message, ...props }) => {
const whenLoggedIn = useLoginRequiredEventHandler();
- return {}), message)} />;
+ return props.disabled ? (
+
+ ) : (
+ {}), message)} />
+ );
};
diff --git a/apps/deploy-web/src/components/wallet/ManagedWalletPopup.tsx b/apps/deploy-web/src/components/wallet/ManagedWalletPopup.tsx
index 73d33e61c..9ede25f11 100644
--- a/apps/deploy-web/src/components/wallet/ManagedWalletPopup.tsx
+++ b/apps/deploy-web/src/components/wallet/ManagedWalletPopup.tsx
@@ -1,22 +1,23 @@
import React from "react";
import { FormattedNumber } from "react-intl";
-import { Alert, AlertDescription, Button, Separator } from "@akashnetwork/ui/components";
-import { CoinsSwap, HandCard, WarningCircle } from "iconoir-react";
+import { Button, Separator } from "@akashnetwork/ui/components";
+import { CoinsSwap, HandCard } from "iconoir-react";
import { TopUpAmountPicker } from "@src/components/top-up-amount-picker/TopUpAmountPicker";
import { useWallet } from "@src/context/WalletProvider";
import { useLoginRequiredEventHandler } from "@src/hooks/useLoginRequiredEventHandler";
import { useManagedEscrowFaqModal } from "@src/hooks/useManagedEscrowFaqModal";
+import { useIsEmailVerified } from "@src/hooks/useRequiredEmailVerified";
import { WalletBalance } from "@src/hooks/useWalletBalance";
import { LinkTo } from "../shared/LinkTo";
-import { useCustomUser } from "@src/hooks/useCustomUser";
+import { VerifyEmail } from "../shared/VerifyEmail";
interface ManagedWalletPopupProps extends React.PropsWithChildren {
walletBalance: WalletBalance;
}
export const ManagedWalletPopup: React.FC = ({ walletBalance }) => {
- const { user } = useCustomUser();
+ const isEmailVerified = useIsEmailVerified();
const { switchWalletType, isManaged, isTrialing } = useWallet();
const whenLoggedIn = useLoginRequiredEventHandler();
const { showManagedEscrowFaqModal } = useManagedEscrowFaqModal();
@@ -25,8 +26,6 @@ export const ManagedWalletPopup: React.FC = ({ walletBa
window.location.href = "/api/proxy/v1/checkout";
};
- console.log(user);
-
return (
{isManaged && isTrialing && (
@@ -75,22 +74,10 @@ export const ManagedWalletPopup: React.FC
= ({ walletBa
)}
- {!user?.emailVerified && (
-
-
-
- Verify your email to add funds to your balance.
-
-
- )}
+
-