Skip to content
This repository was archived by the owner on Sep 8, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 32 additions & 13 deletions src/ui/common/components/Wallet/Connect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
import { useMemo, useState } from "react";
import { AiOutlineInfoCircle } from "react-icons/ai";
import { PiWalletBold } from "react-icons/pi";
import { useLocation } from "react-router";
import { Tooltip } from "react-tooltip";
import { twMerge } from "tailwind-merge";

Expand Down Expand Up @@ -42,6 +43,10 @@ export const Connect: React.FC<ConnectProps> = ({
setIsWalletMenuOpen(open);
};

const location = useLocation();
const isBabyRoute = location.pathname.startsWith("/baby");

Copilot AI Sep 3, 2025

Copy link

Choose a reason for hiding this comment

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

The hardcoded route prefix '/baby' is duplicated from WalletConnectionProvider.tsx. This should be extracted as a shared constant to maintain consistency and avoid duplication.

Copilot uses AI. Check for mistakes.
const requireBothWallets = !isBabyRoute;

// App state and wallet context
const { includeOrdinals, excludeOrdinals, ordinalsExcluded } = useAppState();
const { linkedDelegationsVisibility, displayLinkedDelegations } =
Expand Down Expand Up @@ -108,14 +113,26 @@ export const Connect: React.FC<ConnectProps> = ({
apiMessage,
isLoading: isHealthcheckLoading,
} = useHealthCheck();

const isConnected = useMemo(
() =>
btcConnected && bbnConnected && !isGeoBlocked && !isHealthcheckLoading,
[btcConnected, bbnConnected, isGeoBlocked, isHealthcheckLoading],
(requireBothWallets ? btcConnected && bbnConnected : bbnConnected) &&
!isGeoBlocked &&
!isHealthcheckLoading,
[
requireBothWallets,
btcConnected,
bbnConnected,
isGeoBlocked,
isHealthcheckLoading,
],
);

const isLoading =
isConnected || !isApiNormal || loading || btcLoading || bbnLoading;
isConnected ||
!isApiNormal ||
loading ||
(requireBothWallets ? btcLoading || bbnLoading : bbnLoading);

const transformedWallets = useMemo(() => {
const result: Record<string, { name: string; icon: string }> = {};
Expand Down Expand Up @@ -174,16 +191,18 @@ export const Connect: React.FC<ConnectProps> = ({
trigger={
<div className="cursor-pointer">
<AvatarGroup max={2} variant="circular">
<Avatar
alt={selectedWallets["BTC"]?.name}
url={selectedWallets["BTC"]?.icon}
size="large"
className={twMerge(
"object-contain bg-accent-contrast box-content",
isWalletMenuOpen &&
"outline outline-[2px] outline-accent-primary",
)}
/>
{selectedWallets["BTC"] ? (
<Avatar
alt={selectedWallets["BTC"]?.name}
url={selectedWallets["BTC"]?.icon}
size="large"
className={twMerge(
"object-contain bg-accent-contrast box-content",
isWalletMenuOpen &&
"outline outline-[2px] outline-accent-primary",
)}
/>
) : null}
<Avatar
alt={selectedWallets["BBN"]?.name}
url={selectedWallets["BBN"]?.icon}
Expand Down
3 changes: 2 additions & 1 deletion src/ui/common/context/wallet/BTCWalletProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,9 @@ export const BTCWalletProvider = ({ children }: PropsWithChildren) => {
);

useEffect(() => {
if (!btcConnector) return;
// Ensure loading is cleared even when BTC connector is not configured
setLoading(false);
if (!btcConnector) return;
if (btcConnector.connectedWallet) {
connectBTC(btcConnector?.connectedWallet.provider);
}
Expand Down
11 changes: 9 additions & 2 deletions src/ui/common/context/wallet/WalletConnectionProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
} from "@babylonlabs-io/wallet-connector";
import { useTheme } from "next-themes";
import { useCallback, type PropsWithChildren } from "react";
import { useLocation } from "react-router";

import { logTermsAcceptance } from "@/ui/common/api/logTermAcceptance";
import { verifyBTCAddress } from "@/ui/common/api/verifyBTCAddress";
Expand All @@ -29,7 +30,7 @@
connectors: [
{
id: "tomo-btc-connector",
widget: ({ onError }) => (
widget: ({ onError }: { onError?: (e: Error) => void }) => (
<ExternalWallets chainName="bitcoin" onError={onError} />
),
},
Expand All @@ -41,7 +42,7 @@
connectors: [
{
id: "tomo-bbn-connector",
widget: ({ onError }) => (
widget: ({ onError }: { onError?: (e: Error) => void }) => (
<ExternalWallets chainName="cosmos" onError={onError} />
),
},
Expand All @@ -54,6 +55,7 @@
const { handleError } = useError();
const { theme } = useTheme();
const logger = useLogger();
const location = useLocation();

const onError = useCallback(
(error: Error) => {
Expand All @@ -74,6 +76,10 @@
[handleError, logger],
);

const requiredChains = (
location.pathname.startsWith("/baby") ? ["BBN"] : ["BTC", "BBN"]
) as ("BTC" | "BBN")[];
Comment on lines +79 to +81

Copilot AI Sep 3, 2025

Copy link

Choose a reason for hiding this comment

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

The hardcoded route prefix '/baby' should be extracted as a constant to improve maintainability and avoid magic strings. Consider defining a constant like BABY_ROUTE_PREFIX = '/baby' at the module level.

Copilot uses AI. Check for mistakes.

return (
<WalletProvider
persistent
Expand All @@ -83,6 +89,7 @@
context={context}
onError={onError}
disabledWallets={FeatureFlagService.IsLedgerEnabled ? [] : ["ledget_btc"]}
requiredChains={requiredChains}

Check failure on line 92 in src/ui/common/context/wallet/WalletConnectionProvider.tsx

View workflow job for this annotation

GitHub Actions / lint_test / build

Type '{ children: ReactNode; persistent: true; theme: string | undefined; lifecycleHooks: { acceptTermsOfService: ({ address, public_key, }: TermsPayload) => Promise<void>; verifyBTCAddress: (address: string) => Promise<...>; }; ... 4 more ...; requiredChains: ("BTC" | "BBN")[]; }' is not assignable to type 'IntrinsicAttributes & WalletProviderProps & { children?: ReactNode; }'.
>
{children}
</WalletProvider>
Expand Down
3 changes: 1 addition & 2 deletions src/ui/common/hooks/useAuthGuard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import {

export function useAuthGuard() {
const { connected } = useWalletConnect();
const btc = useChainConnector("BTC");
const baby = useChainConnector("BBN");

return { connected, loading: !btc || !baby };
return { connected, loading: !baby };
}
Loading