-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: only show banner when user doesn't have managed wallet
- Loading branch information
Showing
2 changed files
with
22 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,28 @@ | ||
import { browserEnvConfig } from "@src/config/browser-env.config"; | ||
import { useWallet } from "@src/context/WalletProvider"; | ||
import { useEffect, useMemo, useState } from "react"; | ||
import { useUser } from "./useUser"; | ||
|
||
const withBilling = browserEnvConfig.NEXT_PUBLIC_BILLING_ENABLED; | ||
|
||
export function useHasCreditCardBanner() { | ||
const { hasManagedWallet, isTrialing } = useWallet(); | ||
const user = useUser(); | ||
const [isBannerVisible, setIsBannerVisible] = useState(false); | ||
const [isInitialized, setIsInitialized] = useState(false); | ||
const { hasManagedWallet, isWalletLoading } = useWallet(); | ||
const shouldShowBanner = useMemo(() => isInitialized && withBilling && !hasManagedWallet && !isWalletLoading, [isInitialized, hasManagedWallet, isWalletLoading]); | ||
|
||
return withBilling && !hasManagedWallet && !isTrialing; | ||
useEffect(() => { | ||
if (user?.id) { | ||
setIsInitialized(true); | ||
} | ||
}, [user?.id]); | ||
|
||
useEffect(() => { | ||
if (shouldShowBanner) { | ||
setIsBannerVisible(true); | ||
} | ||
}, [shouldShowBanner]); | ||
|
||
return isBannerVisible; | ||
} |