Skip to content
This repository was archived by the owner on Sep 8, 2025. It is now read-only.

Commit 625c583

Browse files
author
Jony Bursztyn
authored
feat: implement non-btc wallet selection on BABY staking (#1536)
* implement non-btc wallet selection on BABY staking * implement non-btc wallet selection on BABY staking * bump
1 parent f2c9078 commit 625c583

6 files changed

Lines changed: 55 additions & 48 deletions

File tree

package-lock.json

Lines changed: 9 additions & 28 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@
3232
"@babylonlabs-io/babylon-proto-ts": "1.12.0",
3333
"@babylonlabs-io/bsn-registry": "0.2.2",
3434
"@babylonlabs-io/btc-staking-ts": "2.5.6",
35-
"@babylonlabs-io/core-ui": "1.35.3",
36-
"@babylonlabs-io/wallet-connector": "1.11.6",
35+
"@babylonlabs-io/core-ui": "1.36.0",
36+
"@babylonlabs-io/wallet-connector": "1.12.0",
3737
"@bitcoin-js/tiny-secp256k1-asmjs": "2.2.3",
3838
"@cosmjs/proto-signing": "^0.33.1",
3939
"@cosmjs/stargate": "^0.33.1",

src/ui/common/components/Wallet/Connect.tsx

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
import { useMemo, useState } from "react";
1212
import { AiOutlineInfoCircle } from "react-icons/ai";
1313
import { PiWalletBold } from "react-icons/pi";
14+
import { useLocation } from "react-router";
1415
import { Tooltip } from "react-tooltip";
1516
import { twMerge } from "tailwind-merge";
1617

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

46+
const location = useLocation();
47+
const isBabyRoute = location.pathname.startsWith("/baby");
48+
const requireBothWallets = !isBabyRoute;
49+
4550
// App state and wallet context
4651
const { includeOrdinals, excludeOrdinals, ordinalsExcluded } = useAppState();
4752
const { linkedDelegationsVisibility, displayLinkedDelegations } =
@@ -108,14 +113,26 @@ export const Connect: React.FC<ConnectProps> = ({
108113
apiMessage,
109114
isLoading: isHealthcheckLoading,
110115
} = useHealthCheck();
116+
111117
const isConnected = useMemo(
112118
() =>
113-
btcConnected && bbnConnected && !isGeoBlocked && !isHealthcheckLoading,
114-
[btcConnected, bbnConnected, isGeoBlocked, isHealthcheckLoading],
119+
(requireBothWallets ? btcConnected && bbnConnected : bbnConnected) &&
120+
!isGeoBlocked &&
121+
!isHealthcheckLoading,
122+
[
123+
requireBothWallets,
124+
btcConnected,
125+
bbnConnected,
126+
isGeoBlocked,
127+
isHealthcheckLoading,
128+
],
115129
);
116130

117131
const isLoading =
118-
isConnected || !isApiNormal || loading || btcLoading || bbnLoading;
132+
isConnected ||
133+
!isApiNormal ||
134+
loading ||
135+
(requireBothWallets ? btcLoading || bbnLoading : bbnLoading);
119136

120137
const transformedWallets = useMemo(() => {
121138
const result: Record<string, { name: string; icon: string }> = {};
@@ -174,16 +191,18 @@ export const Connect: React.FC<ConnectProps> = ({
174191
trigger={
175192
<div className="cursor-pointer">
176193
<AvatarGroup max={2} variant="circular">
177-
<Avatar
178-
alt={selectedWallets["BTC"]?.name}
179-
url={selectedWallets["BTC"]?.icon}
180-
size="large"
181-
className={twMerge(
182-
"object-contain bg-accent-contrast box-content",
183-
isWalletMenuOpen &&
184-
"outline outline-[2px] outline-accent-primary",
185-
)}
186-
/>
194+
{selectedWallets["BTC"] ? (
195+
<Avatar
196+
alt={selectedWallets["BTC"]?.name}
197+
url={selectedWallets["BTC"]?.icon}
198+
size="large"
199+
className={twMerge(
200+
"object-contain bg-accent-contrast box-content",
201+
isWalletMenuOpen &&
202+
"outline outline-[2px] outline-accent-primary",
203+
)}
204+
/>
205+
) : null}
187206
<Avatar
188207
alt={selectedWallets["BBN"]?.name}
189208
url={selectedWallets["BBN"]?.icon}

src/ui/common/context/wallet/BTCWalletProvider.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,9 @@ export const BTCWalletProvider = ({ children }: PropsWithChildren) => {
196196
);
197197

198198
useEffect(() => {
199-
if (!btcConnector) return;
199+
// Ensure loading is cleared even when BTC connector is not configured
200200
setLoading(false);
201+
if (!btcConnector) return;
201202
if (btcConnector.connectedWallet) {
202203
connectBTC(btcConnector?.connectedWallet.provider);
203204
}

src/ui/common/context/wallet/WalletConnectionProvider.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
} from "@babylonlabs-io/wallet-connector";
66
import { useTheme } from "next-themes";
77
import { useCallback, type PropsWithChildren } from "react";
8+
import { useLocation } from "react-router";
89

910
import { logTermsAcceptance } from "@/ui/common/api/logTermAcceptance";
1011
import { verifyBTCAddress } from "@/ui/common/api/verifyBTCAddress";
@@ -29,7 +30,7 @@ const config: ChainConfigArr = [
2930
connectors: [
3031
{
3132
id: "tomo-btc-connector",
32-
widget: ({ onError }) => (
33+
widget: ({ onError }: { onError?: (e: Error) => void }) => (
3334
<ExternalWallets chainName="bitcoin" onError={onError} />
3435
),
3536
},
@@ -41,7 +42,7 @@ const config: ChainConfigArr = [
4142
connectors: [
4243
{
4344
id: "tomo-bbn-connector",
44-
widget: ({ onError }) => (
45+
widget: ({ onError }: { onError?: (e: Error) => void }) => (
4546
<ExternalWallets chainName="cosmos" onError={onError} />
4647
),
4748
},
@@ -54,6 +55,7 @@ export const WalletConnectionProvider = ({ children }: PropsWithChildren) => {
5455
const { handleError } = useError();
5556
const { theme } = useTheme();
5657
const logger = useLogger();
58+
const location = useLocation();
5759

5860
const onError = useCallback(
5961
(error: Error) => {
@@ -74,6 +76,10 @@ export const WalletConnectionProvider = ({ children }: PropsWithChildren) => {
7476
[handleError, logger],
7577
);
7678

79+
const requiredChains = (
80+
location.pathname.startsWith("/baby") ? ["BBN"] : ["BTC", "BBN"]
81+
) as ("BTC" | "BBN")[];
82+
7783
return (
7884
<WalletProvider
7985
persistent
@@ -83,6 +89,7 @@ export const WalletConnectionProvider = ({ children }: PropsWithChildren) => {
8389
context={context}
8490
onError={onError}
8591
disabledWallets={FeatureFlagService.IsLedgerEnabled ? [] : ["ledget_btc"]}
92+
requiredChains={requiredChains}
8693
>
8794
{children}
8895
</WalletProvider>

src/ui/common/hooks/useAuthGuard.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ import {
55

66
export function useAuthGuard() {
77
const { connected } = useWalletConnect();
8-
const btc = useChainConnector("BTC");
98
const baby = useChainConnector("BBN");
109

11-
return { connected, loading: !btc || !baby };
10+
return { connected, loading: !baby };
1211
}

0 commit comments

Comments
 (0)