Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: switch to @stacks/connect #87

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"@heroicons/react": "2.1.5",
"@noble/hashes": "1.5.0",
"@scure/bip32": "1.3.3",
"@stacks/connect": "7.10.1-alpha.cab6b28.0",
"@stacks/transactions": "7.0.2",
"@tanstack/react-query": "5.61.5",
"add": "2.0.6",
Expand Down
173 changes: 0 additions & 173 deletions src/comps/ConnectWallet.tsx

This file was deleted.

57 changes: 17 additions & 40 deletions src/comps/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,19 @@ import Image from "next/image";
import Link from "next/link";
import { useMemo } from "react";

import { getSelectedProviderId } from "@stacks/connect";
import { AnimatePresence } from "framer-motion";
import { useAtom, useAtomValue } from "jotai";
import {
BridgeConfig,
showConnectWalletAtom,
showTosAtom,
walletInfoAtom,
} from "@/util/atoms";
import { useAtomValue } from "jotai";

import ConnectWallet from "./ConnectWallet";
import useMintCaps from "@/hooks/use-mint-caps";
import { BridgeConfig, showTosAtom, walletInfoAtom } from "@/util/atoms";
import {
useConnectWallet,
useDisconnectWallet,
} from "../hooks/use-connect-wallet";
import { GetTestnetBTC } from "./get-testnet-btc";
import { useNotifications } from "@/hooks/use-notifications";
import { NotificationStatusType } from "./Notifications";
import SBTCBalance from "./ui/sbtc-balance";
import TOS from "./tos";
import useMintCaps from "@/hooks/use-mint-caps";
import SBTCBalance from "./ui/sbtc-balance";

// converting to lower case to avoid case sensitive issue

Expand All @@ -29,27 +26,12 @@ const Header = ({ config }: { config: BridgeConfig }) => {
const isTestnet =
config.WALLET_NETWORK?.toLowerCase() === "sbtcTestnet".toLowerCase();

const { notify } = useNotifications();
const walletInfo = useAtomValue(walletInfoAtom);

const connectWallet = useConnectWallet();
const disconnectWallet = useDisconnectWallet();

const [walletInfo, setWalletInfo] = useAtom(walletInfoAtom);
const handleSignOut = () => {
setWalletInfo({
selectedWallet: null,
addresses: {
payment: null,
taproot: null,
stacks: null,
},
});
notify({
type: NotificationStatusType.SUCCESS,
message: `Wallet disconnected`,
});
};
const isConnected = useMemo(() => !!walletInfo.selectedWallet, [walletInfo]);
const [showConnectWallet, setShowConnectWallet] = useAtom(
showConnectWalletAtom,
);

const { currentCap } = useMintCaps();

Expand All @@ -61,7 +43,7 @@ const Header = ({ config }: { config: BridgeConfig }) => {
{isTestnet && <GetTestnetBTC />}
<SBTCBalance address={walletInfo.addresses.stacks!.address} />
<button
onClick={() => handleSignOut()}
onClick={() => disconnectWallet()}
className="px-4 py-2 rounded-md border-2 border-orange"
>
<h3 className="font-Matter text-xs text-orange font-semibold tracking-wide">
Expand Down Expand Up @@ -107,12 +89,12 @@ const Header = ({ config }: { config: BridgeConfig }) => {
renderUserWalletInfo()
) : (
<button
onClick={() => setShowConnectWallet(true)}
onClick={() => connectWallet()}
disabled={isMintCapReached}
className=" bg-orange px-4 py-2 rounded-md disabled:opacity-50 disabled:cursor-not-allowed"
className="bg-orange px-4 py-2 rounded-md disabled:opacity-50 disabled:cursor-not-allowed"
>
<h3 className="font-Matter text-xs font-semibold tracking-wide">
CONNECT WALLET
CONNECT WALLET ({getSelectedProviderId()})
</h3>
</button>
)}
Expand All @@ -121,11 +103,6 @@ const Header = ({ config }: { config: BridgeConfig }) => {
</header>
{/* <Metrics /> */}

<AnimatePresence>
{showConnectWallet && (
<ConnectWallet onClose={() => setShowConnectWallet(false)} />
)}
</AnimatePresence>
<AnimatePresence>{showTos && <TOS />}</AnimatePresence>
</>
);
Expand Down
12 changes: 4 additions & 8 deletions src/comps/ReclaimManager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,7 @@ import { useShortAddress } from "@/hooks/use-short-address";
import { InformationCircleIcon } from "@heroicons/react/16/solid";
import { PrimaryButton } from "./core/FlowButtons";
import { useAtomValue, useSetAtom } from "jotai";
import {
bridgeConfigAtom,
walletInfoAtom,
showConnectWalletAtom,
WalletProvider,
} from "@/util/atoms";
import { bridgeConfigAtom, walletInfoAtom, WalletProvider } from "@/util/atoms";

import { useNotifications } from "@/hooks/use-notifications";
import { NotificationStatusType } from "./Notifications";
Expand All @@ -30,6 +25,7 @@ import {
signPSBTLeather,
signPSBTXverse,
} from "@/util/wallet-utils/src/sign-psbt";
import { useConnectWallet } from "../hooks/use-connect-wallet";

/*
Goal : User server side rendering as much as possible
Expand Down Expand Up @@ -327,8 +323,8 @@ const ReclaimDeposit = ({
}: ReclaimDepositProps) => {
const { notify } = useNotifications();
const walletInfo = useAtomValue(walletInfoAtom);
const setShowWallet = useSetAtom(showConnectWalletAtom);
const router = useRouter();
const connectWallet = useConnectWallet();

const { WALLET_NETWORK: walletNetwork, SUPPORT_LINK } =
useAtomValue(bridgeConfigAtom);
Expand All @@ -341,7 +337,7 @@ const ReclaimDeposit = ({
const btcAddress = getWalletAddress();

if (!btcAddress) {
return setShowWallet(true);
return connectWallet();
}

// FIXME: move to util or its own file
Expand Down
12 changes: 7 additions & 5 deletions src/comps/core/Form.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { walletInfoAtom } from "@/util/atoms";
import { useFormik } from "formik";
import { PrimaryButton } from "./FlowButtons";
import { useAtomValue, useSetAtom } from "jotai";
import { showConnectWalletAtom, walletInfoAtom } from "@/util/atoms";
import { useAtomValue } from "jotai";
import { useMemo } from "react";
import { Schema as YupSchema } from "yup";
import { PrimaryButton } from "./FlowButtons";
import { useConnectWallet } from "../../hooks/use-connect-wallet";

// this is supposed to be as reusable as possible given all the flows are very similar in order and action
type FlowFormProps = {
nameKey: string;
Expand All @@ -29,7 +31,7 @@ export const FlowForm = ({
}: FlowFormProps) => {
const walletInfo = useAtomValue(walletInfoAtom);
const isConnected = useMemo(() => !!walletInfo.selectedWallet, [walletInfo]);
const setShowConnectWallet = useSetAtom(showConnectWalletAtom);
const connectWallet = useConnectWallet();

const formik = useFormik({
initialValues: {
Expand Down Expand Up @@ -74,7 +76,7 @@ export const FlowForm = ({
<button
disabled={disabled}
type="button"
onClick={() => setShowConnectWallet(true)}
onClick={() => connectWallet()}
className="bg-orange px-4 py-2 rounded-md font-Matter text-xs font-semibold tracking-wide disabled:opacity-50 disabled:cursor-not-allowed"
>
CONNECT WALLET
Expand Down
Loading
Loading