Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { Button, DialogBody, DialogFooter, DialogHeader, Text } from "@babylonlabs-io/core-ui";
import { memo } from "react";
import { Button, Checkbox, DialogBody, DialogFooter, DialogHeader, Text } from "@babylonlabs-io/core-ui";
import { memo, useState } from "react";
import { twMerge } from "tailwind-merge";

import { ChainButton } from "@/components/ChainButton";
import { ConnectedWallet } from "@/components/ConnectedWallet";
import { FieldControl } from "@/components/FieldControl";
import type { IChain, IWallet } from "@/core/types";

interface ChainsProps {
Expand All @@ -28,6 +29,7 @@ export const Chains = memo(
onSelectChain,
onDisconnectWallet,
}: ChainsProps) => {
const [termsAccepted, setTermsAccepted] = useState(false);
const chainNames = chains.map((chain) => chain.name).join(" and ");
const subtitle = `Connect to both ${chainNames} Wallets`;

Expand Down Expand Up @@ -62,14 +64,47 @@ export const Chains = memo(
</ChainButton>
);
})}

<FieldControl
label={
<div className="block">
I certify that I have read and accept the updated{" "}
<a
href="https://babylonlabs.io/terms-of-use"
target="_blank"
rel="noopener noreferrer"
className="underline"
>
Terms of Use
</a>{" "}
and{" "}
<a
href="https://babylonlabs.io/privacy-policy"
target="_blank"
rel="noopener noreferrer"
className="underline"
>
Privacy Policy
</a>
.
</div>
}
>
<Checkbox checked={termsAccepted} onChange={(value = false) => setTermsAccepted(value)} />
</FieldControl>
</DialogBody>

<DialogFooter className="mt-auto flex gap-4 pt-10">
<Button variant="outlined" fluid onClick={onClose}>
Cancel
</Button>

<Button disabled={disabled} fluid onClick={onConfirm} data-testid="chains-done-button">
<Button
disabled={disabled || !termsAccepted}
fluid
onClick={onConfirm}
data-testid="chains-done-button"
Comment thread
jonybur marked this conversation as resolved.
>
Done
</Button>
</DialogFooter>
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { ChainsContainer as Chains } from "@/components/Chains/container";
import { ErrorContainer as Error } from "@/components/Error/container";
import { InscriptionsContainer as Inscriptions } from "@/components/Inscriptions/container";
import { LoaderScreen } from "@/components/Loader";
import { TermsOfServiceContainer as TermsOfService } from "@/components/TermsOfService/container";
import { WalletsContainer as Wallets } from "@/components/Wallets/container";
import type { Screen } from "@/context/State.context";
import type { IChain, IWallet } from "@/core/types";
Expand All @@ -16,17 +15,12 @@ interface ScreenProps {
widgets?: Record<string, JSX.Element | undefined>;
onSelectWallet?: (chain: IChain, wallet: IWallet) => void;
onDisconnectWallet?: (chainId: string) => void;
onAccepTermsOfService?: () => void;
onToggleInscriptions?: (value: boolean, showAgain: boolean) => void;
onClose?: () => void;
onConfirm?: () => void;
simplifiedTerms?: boolean;
}

const SCREENS = {
TERMS_OF_SERVICE: ({ className, onClose, onAccepTermsOfService, simplifiedTerms }: ScreenProps) => (
<TermsOfService className={className} onClose={onClose} onSubmit={onAccepTermsOfService} simplifiedTerms={simplifiedTerms} />
),
CHAINS: ({ className, onClose, onConfirm, onDisconnectWallet }: ScreenProps) => (
<Chains className={className} onClose={onClose} onConfirm={onConfirm} onDisconnectWallet={onDisconnectWallet} />
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { useCallback } from "react";
import { ResponsiveDialog } from "@/components/ResponsiveDialog/ResponsiveDialog";
import { useChainProviders } from "@/context/Chain.context";
import { useInscriptionProvider } from "@/context/Inscriptions.context";
import { useLifeCycleHooks } from "@/context/LifecycleHooks.context";
import { HashMap } from "@/core/types";
import { useWalletConnect } from "@/hooks/useWalletConnect";
import { useWalletConnectors } from "@/hooks/useWalletConnectors";
Expand All @@ -16,23 +17,19 @@ interface WalletDialogProps {
storage: HashMap;
config: any;
persistent: boolean;
simplifiedTerms?: boolean;
}

const ANIMATION_DELAY = 1000;

export function WalletDialog({ persistent, storage, config, onError, simplifiedTerms }: WalletDialogProps) {
const { visible, screen, confirmed, close, confirm, displayChains } = useWidgetState();
export function WalletDialog({ persistent, storage, config, onError }: WalletDialogProps) {
const { visible, screen, confirmed, selectedWallets, close, confirm, displayChains } = useWidgetState();
const { toggleShowAgain, toggleLockInscriptions } = useInscriptionProvider();
const { acceptTermsOfService } = useLifeCycleHooks();
const connectors = useChainProviders();
const walletWidgets = useWalletWidgets(connectors, config, onError);
const { connect, disconnect } = useWalletConnectors({ persistent, accountStorage: storage, onError });
const { disconnect: disconnectAll } = useWalletConnect();

const handleAccepTermsOfService = useCallback(() => {
displayChains?.();
}, [displayChains]);

const handleToggleInscriptions = useCallback(
(lockInscriptions: boolean, showAgain: boolean) => {
toggleShowAgain?.(showAgain);
Expand All @@ -49,10 +46,22 @@ export function WalletDialog({ persistent, storage, config, onError, simplifiedT
}
}, [close, disconnectAll, confirmed]);

const handleConfirm = useCallback(() => {
const handleConfirm = useCallback(async () => {
const btcWallet = selectedWallets["BTC"];
if (btcWallet?.account?.address && btcWallet.account.publicKeyHex) {
try {
await acceptTermsOfService?.({
address: btcWallet.account.address,
public_key: btcWallet.account.publicKeyHex,
});
} catch (e) {
onError?.(e as Error);
return;
}
}
confirm?.();
close?.();
}, [confirm]);
}, [confirm, close, selectedWallets, acceptTermsOfService, onError]);

return (
<ResponsiveDialog className="min-h-[80%]" open={visible} onClose={handleClose}>
Expand All @@ -63,11 +72,9 @@ export function WalletDialog({ persistent, storage, config, onError, simplifiedT
onClose={handleClose}
onConfirm={handleConfirm}
onSelectWallet={connect}
onAccepTermsOfService={handleAccepTermsOfService}
onToggleInscriptions={handleToggleInscriptions}
onDisconnectWallet={disconnect}
simplifiedTerms={simplifiedTerms}
/>
</ResponsiveDialog>
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,6 @@ interface WalletProviderProps {
* Provide eth and/or btc properties to enable respective chains
*/
appKitConfig?: AppKitModalConfig;
/**
* When true, only show the T&C checkbox in the terms of service dialog
* instead of all three checkboxes (inscriptions, hardware wallet warnings)
*/
simplifiedTerms?: boolean;
disableTomo?: boolean;
}

Expand All @@ -68,7 +63,6 @@ export function WalletProvider({
disabledWallets = [],
requiredChains,
appKitConfig,
simplifiedTerms = false,
disableTomo = false,
}: PropsWithChildren<WalletProviderProps>) {
const networkMap = useMemo(() => deriveNetworkMap(config), [config]);
Expand Down Expand Up @@ -113,7 +107,7 @@ export function WalletProvider({
<TomoBBNConnector persistent={persistent} storage={storage} />
</>
)}
<WalletDialog persistent={persistent} storage={storage} config={config} onError={onError} simplifiedTerms={simplifiedTerms} />
<WalletDialog persistent={persistent} storage={storage} config={config} onError={onError} />
</ChainProvider>
</LifeCycleHooksProvider>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ export type Screen<T extends string = string> = {

export type Screens =
| Screen<"LOADER">
| Screen<"TERMS_OF_SERVICE">
| Screen<"CHAINS">
| Screen<"WALLETS">
| Screen<"INSCRIPTIONS">
Expand All @@ -30,7 +29,6 @@ export interface Actions {
displayChains?: () => void;
displayWallets?: (chain: string) => void;
displayInscriptions?: () => void;
displayTermsOfService?: () => void;
displayError?: (params: {
icon?: JSX.Element;
title: string;
Expand All @@ -49,7 +47,7 @@ export interface Actions {
const defaultState: State = {
confirmed: false,
visible: false,
screen: { type: "TERMS_OF_SERVICE" },
screen: { type: "CHAINS" },
chains: {},
selectedWallets: {},
};
Expand Down Expand Up @@ -105,10 +103,6 @@ export function StateProvider({ children, chains }: PropsWithChildren<StateProvi
setState((state) => ({ ...state, screen: { type: "LOADER", params: { message } } }));
},

displayTermsOfService: () => {
setState((state) => ({ ...state, screen: { type: "TERMS_OF_SERVICE" } }));
},

displayChains: () => {
setState((state) => ({ ...state, screen: { type: "CHAINS" } }));
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export function useWalletConnectors({ persistent, accountStorage, onError }: Pro
chains: chainMap,
} = useWidgetState();
const { showAgain } = useInscriptionProvider();
const { verifyBTCAddress, acceptTermsOfService } = useLifeCycleHooks();
const { verifyBTCAddress } = useLifeCycleHooks();

// Connecting event
useEffect(() => {
Expand Down Expand Up @@ -66,11 +66,6 @@ export function useWalletConnectors({ persistent, accountStorage, onError }: Pro

validateAddress(connector.config.network, connectedWallet.account.address);

await acceptTermsOfService?.({
address: connectedWallet.account.address,
public_key: connectedWallet.account.publicKeyHex,
});

const goToNextScreen = () => void (showAgain ? displayInscriptions?.() : displayChains?.());

if (
Expand Down
2 changes: 0 additions & 2 deletions services/vault/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ NEXT_PUBLIC_TBV_SIDECAR_API_URL=https://sidecar-api.canon-devnet.babylonlabs.io
# NEXT_PUBLIC_FF_DISABLE_VAULT_CAP=true
# Shows the position notifications debug panel for testing notification scenarios
# NEXT_PUBLIC_FF_POSITION_DEBUG_PANEL=true
# Show only the T&C checkbox in the wallet connection dialog instead of all three.
# NEXT_PUBLIC_FF_SIMPLIFIED_TERMS=true


# Added by sync-env from devnet
Expand Down
Loading
Loading