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

Asigna integration #76

Open
wants to merge 4 commits 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 @@ -11,6 +11,7 @@
"lint": "next lint"
},
"dependencies": {
"@asigna/btc-connect": "0.0.16",
"@bitcoinerlab/secp256k1": "1.1.1",
"@headlessui/react": "2.1.2",
"@heroicons/react": "2.1.5",
Expand Down
33 changes: 33 additions & 0 deletions public/images/AsignaMultisig.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 22 additions & 4 deletions src/comps/ConnectWallet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ import { useAtomValue, useSetAtom } from "jotai";
import { useNotifications } from "@/hooks/use-notifications";
import { NotificationStatusType } from "./Notifications";
import { useEffect, useState } from "react";
import { getAddresses } from "@/util/wallet-utils/src/getAddress";
import { getAddresses, getAddressesAsigna } from "@/util/wallet-utils/src/getAddress";
import { useAsignaConnect } from '@asigna/btc-connect'

const WALLET_PROVIDERS = [
{
Expand All @@ -32,6 +33,12 @@ const WALLET_PROVIDERS = [
walletProvider: WalletProvider.XVERSE,
installUrl: "https://xverse.app",
},
{
image: "/images/AsignaMultisig.svg",
name: "Asigna Multisig",
walletProvider: WalletProvider.ASIGNA,
installUrl: "https://btc.asigna.io",
},
];

type ConnectWalletProps = {
Expand All @@ -43,16 +50,20 @@ const ConnectWallet = ({ onClose }: ConnectWalletProps) => {
}>({
leather: false,
xverse: false,
asigna: false,
});
useEffect(() => {
checkAvailableWallets().then(setAvailableWallets);
}, []);

const setWalletInfo = useSetAtom(walletInfoAtom);

const setShowTos = useSetAtom(showTosAtom);

const { notify } = useNotifications();
const { WALLET_NETWORK } = useAtomValue(bridgeConfigAtom);
const { connect: asignaConnect } = useAsignaConnect();

const handleSelectWallet = async (wallet: WalletProvider) => {
try {
let addresses: Awaited<ReturnType<getAddresses>> | null = null;
Expand All @@ -62,6 +73,8 @@ const ConnectWallet = ({ onClose }: ConnectWalletProps) => {
break;
case WalletProvider.XVERSE:
addresses = await getAddressesXverse();
case WalletProvider.ASIGNA:
addresses = await getAddressesAsigna(asignaConnect);
}
const isMainnetAddress =
addresses.payment.address.startsWith("bc1") ||
Expand Down Expand Up @@ -109,7 +122,7 @@ const ConnectWallet = ({ onClose }: ConnectWalletProps) => {
style={{
backgroundColor: "#FFF5EB",
}}
className=" rounded-lg flex flex-col items-center justify-between p-6 w-full h-screen sm:h-[400px] sm:w-[340px] shadow-lg"
className=" rounded-lg flex flex-col items-center justify-between p-6 w-full h-screen sm:h-[500px] sm:w-[340px] shadow-lg"
>
<div className="w-full flex flex-col gap-2 items-center justify-center">
<Heading>Connect Wallet</Heading>
Expand Down Expand Up @@ -152,8 +165,13 @@ const ConnectWallet = ({ onClose }: ConnectWalletProps) => {
alt={provider.name}
/>
<p className="ml-4 text-black">
{provider.name}{" "}
{!available && " is not available click to install"}
{provider.walletProvider === WalletProvider.ASIGNA && !available
? 'Open as an embedded app in Asigna'
: <>
{provider.name}{""}
{!available && " is not available click to install"}
</>
}
</p>
</div>
{available ? (
Expand Down
6 changes: 6 additions & 0 deletions src/comps/Deposit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import { sendBTCLeather, sendBTCXverse } from "@/util/wallet-utils";
import useMintCaps from "@/hooks/use-mint-caps";
import { getAggregateKey } from "@/util/get-aggregate-key";
import getBitcoinNetwork from "@/util/get-bitcoin-network";
import { useAsignaConnect } from "@asigna/btc-connect";
import { useQuery } from "@tanstack/react-query";
import getBtcBalance from "@/actions/get-btc-balance";
import { useDepositStatus } from "@/hooks/use-deposit-status";
Expand Down Expand Up @@ -248,6 +249,8 @@ const DepositFlowConfirm = ({
const maxFee = useAtomValue(depositMaxFeeAtom);
const config = useAtomValue(bridgeConfigAtom);

const { openSignBtcAmount } = useAsignaConnect();

const walletInfo = useAtomValue(walletInfoAtom);
const handleNextClick = async () => {
try {
Expand Down Expand Up @@ -313,6 +316,9 @@ const DepositFlowConfirm = ({
case WalletProvider.XVERSE:
txId = await sendBTCXverse(params);
break;
case WalletProvider.ASIGNA:
txId = await openSignBtcAmount(params, true);
break;
}
} catch (error) {
let errorMessage = error;
Expand Down
11 changes: 11 additions & 0 deletions src/comps/Faqs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,17 @@ const faqs = [
wallets are supported — two leading wallets with seamless
integrations designed for Bitcoin and Stacks users.
</li>
<li>
<a
className="text-blue-600 underline"
href="https://www.asigna.io/"
target="_blank"
>
Asigna Multisig
</a>{" "}
is also supported on both the Bitcoin and Stacks sides, providing
reliable functionality for multisig setups.
</li>
<li>
We are actively working with institutional custodians, staking
providers, and other 3rd party wallets to support sBTC. More will be
Expand Down
2 changes: 2 additions & 0 deletions src/comps/HomeApp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Faqs from "./Faqs";
import DepositFlow from "./Deposit";
import { TransferAction } from "./TransferHome";
import LandingAnimation from "./core/LandingAnimation";
import { AsignaSignActionModals } from "@asigna/btc-connect";
// import { usePathname, useRouter } from "next/navigation";

export enum SECTION {
Expand Down Expand Up @@ -63,6 +64,7 @@ const HomeApp = () => {
)} */}
{selectedSection === SECTION.TRANSFER && <TransferAction />}
</LandingAnimation>
<AsignaSignActionModals />
<Faqs />
</>
);
Expand Down
1 change: 1 addition & 0 deletions src/util/atoms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export const eventsAtom = atom<NotificationEventType[]>([]);
export enum WalletProvider {
LEATHER = "leather",
XVERSE = "xverse",
ASIGNA = 'asigna',
}

type Address = {
Expand Down
2 changes: 2 additions & 0 deletions src/util/wallet-utils/src/checkWallets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const checkXverseProvider = async () => {
export enum WalletType {
xverse = "xverse",
leather = "leather",
asigna = 'asigna',
}
export const checkAvailableWallets: () => Promise<{
[key in WalletType]: boolean;
Expand All @@ -21,5 +22,6 @@ export const checkAvailableWallets: () => Promise<{
return {
leather: isLeather,
xverse: isXverse,
asigna: window.top !== window.self,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

this check is waaay too broad can we have a checker in the asigna connect library that might include like a checker for the host maybe

image

That's the only blocker for now

};
};
18 changes: 18 additions & 0 deletions src/util/wallet-utils/src/getAddress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,24 @@ export const getAddressesXverse: getAddresses = async (params) => {
return getWalletAddresses(result);
};

export const getAddressesAsigna = async (action: () => Promise<any>) => {
const response = await action();
return {
taproot: {
address: '',
publicKey: '',
},
payment: {
address: response.address,
publicKey: response.publicKey,
},
stacks: {
address: '',
publicKey: '',
},
};
}

const extractAddressByType = (
addresses: Address[],
addressType: BtcAddress["type"],
Expand Down
Loading
Loading