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: modify usePSBT hook and related wallet hooks #171

Open
wants to merge 2 commits into
base: dev
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
32 changes: 25 additions & 7 deletions src/app/hooks/use-leather.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,18 @@ import { BITCOIN_NETWORK_MAP } from '@shared/constants/bitcoin.constants';
interface UseLeatherReturnType {
connectLeatherWallet: () => Promise<void>;
handleFundingTransaction: (
dlcHandler: SoftwareWalletDLCHandler,
vault: RawVault,
bitcoinAmount: number,
attestorGroupPublicKey: string,
feeRateMultiplier: number
) => Promise<Transaction>;
handleDepositTransaction: (
dlcHandler: SoftwareWalletDLCHandler,
vault: RawVault,
bitcoinAmount: number,
attestorGroupPublicKey: string,
feeRateMultiplier: number
) => Promise<Transaction>;
handleWithdrawalTransaction: (
dlcHandler: SoftwareWalletDLCHandler,
withdrawAmount: number,
attestorGroupPublicKey: string,
vault: RawVault,
Expand All @@ -50,7 +47,7 @@ interface UseLeatherReturnType {
}

export function useLeather(): UseLeatherReturnType {
const { setDLCHandler, setBitcoinWalletContextState, setBitcoinWalletType } =
const { setDLCHandler, setBitcoinWalletContextState, setBitcoinWalletType, dlcHandler } =
useContext(BitcoinWalletContext);

const [isLoading, setIsLoading] = useState<[boolean, string]>([false, '']);
Expand Down Expand Up @@ -151,13 +148,20 @@ export function useLeather(): UseLeatherReturnType {
* @returns The Signed Funding Transaction.
*/
async function handleFundingTransaction(
dlcHandler: SoftwareWalletDLCHandler,
vault: RawVault,
bitcoinAmount: number,
attestorGroupPublicKey: string,
feeRateMultiplier: number
): Promise<Transaction> {
try {
if (!dlcHandler) {
throw new LeatherError('DLC Handler not initialized');
}

if (!(dlcHandler instanceof SoftwareWalletDLCHandler)) {
throw new LeatherError('DLC Handler is not Software Wallet');
}

setIsLoading([true, 'Creating Funding Transaction']);

// ==> Create Funding Transaction
Expand Down Expand Up @@ -190,13 +194,20 @@ export function useLeather(): UseLeatherReturnType {
* @returns The Signed Deposit Transaction.
*/
async function handleDepositTransaction(
dlcHandler: SoftwareWalletDLCHandler,
vault: RawVault,
bitcoinAmount: number,
attestorGroupPublicKey: string,
feeRateMultiplier: number
): Promise<Transaction> {
try {
if (!dlcHandler) {
throw new LeatherError('DLC Handler not initialized');
}

if (!(dlcHandler instanceof SoftwareWalletDLCHandler)) {
throw new LeatherError('DLC Handler is not Software Wallet');
}

setIsLoading([true, 'Creating Deposit Transaction']);

// ==> Create Deposit Transaction
Expand Down Expand Up @@ -231,13 +242,20 @@ export function useLeather(): UseLeatherReturnType {
}

async function handleWithdrawalTransaction(
dlcHandler: SoftwareWalletDLCHandler,
withdrawAmount: number,
attestorGroupPublicKey: string,
vault: RawVault,
feeRateMultiplier: number
): Promise<string> {
try {
if (!dlcHandler) {
throw new LeatherError('DLC Handler not initialized');
}

if (!(dlcHandler instanceof SoftwareWalletDLCHandler)) {
throw new LeatherError('DLC Handler is not Software Wallet');
}

setIsLoading([true, 'Creating Withdrawal Transaction']);

const withdrawalTransaction = await dlcHandler.createWithdrawPSBT(
Expand Down
33 changes: 26 additions & 7 deletions src/app/hooks/use-ledger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,18 @@ interface UseLedgerReturnType {
paymentType: SupportedPaymentType
) => Promise<void>;
handleFundingTransaction: (
dlcHandler: LedgerDLCHandler,
vault: RawVault,
bitcoinAmount: number,
attestorGroupPublicKey: string,
feeRateMultiplier: number
) => Promise<Transaction>;
handleDepositTransaction: (
dlcHandler: LedgerDLCHandler,
vault: RawVault,
withdrawAmount: number,
attestorGroupPublicKey: string,
feeRateMultiplier: number
) => Promise<Transaction>;
handleWithdrawalTransaction: (
dlcHandler: LedgerDLCHandler,
withdrawAmount: number,
attestorGroupPublicKey: string,
vault: RawVault,
Expand All @@ -64,7 +61,8 @@ interface UseLedgerReturnType {
}

export function useLedger(): UseLedgerReturnType {
const { setBitcoinWalletContextState, setDLCHandler } = useContext(BitcoinWalletContext);
const { setBitcoinWalletContextState, setDLCHandler, dlcHandler } =
useContext(BitcoinWalletContext);

const [ledgerApp, setLedgerApp] = useState<AppClient | undefined>(undefined);
const [isLoading, setIsLoading] = useState<[boolean, string]>([false, '']);
Expand Down Expand Up @@ -227,13 +225,20 @@ export function useLedger(): UseLedgerReturnType {
* @returns The Signed Funding Transaction.
*/
async function handleFundingTransaction(
dlcHandler: LedgerDLCHandler,
vault: RawVault,
bitcoinAmount: number,
attestorGroupPublicKey: string,
feeRateMultiplier: number
): Promise<Transaction> {
try {
if (!dlcHandler) {
throw new LedgerError('DLC Handler not initialized');
}

if (!(dlcHandler instanceof LedgerDLCHandler)) {
throw new LedgerError('DLC Handler is not Ledger Wallet');
}

setIsLoading([true, 'Accept Multisig Wallet Policy on your Ledger Device']);

// ==> Create Funding Transaction
Expand All @@ -258,13 +263,20 @@ export function useLedger(): UseLedgerReturnType {
}

async function handleDepositTransaction(
dlcHandler: LedgerDLCHandler,
vault: RawVault,
withdrawAmount: number,
attestorGroupPublicKey: string,
feeRateMultiplier: number
): Promise<Transaction> {
try {
if (!dlcHandler) {
throw new LedgerError('DLC Handler not initialized');
}

if (!(dlcHandler instanceof LedgerDLCHandler)) {
throw new LedgerError('DLC Handler is not Ledger Wallet');
}

setIsLoading([true, 'Accept Multisig Wallet Policy on your Ledger Device']);

const depositPSBT = await dlcHandler.createDepositPSBT(
Expand All @@ -288,13 +300,20 @@ export function useLedger(): UseLedgerReturnType {
}

async function handleWithdrawalTransaction(
dlcHandler: LedgerDLCHandler,
withdrawAmount: number,
attestorGroupPublicKey: string,
vault: RawVault,
feeRateMultiplier: number
): Promise<string> {
try {
if (!dlcHandler) {
throw new LedgerError('DLC Handler not initialized');
}

if (!(dlcHandler instanceof LedgerDLCHandler)) {
throw new LedgerError('DLC Handler is not Ledger Wallet');
}

setIsLoading([true, 'Accept Multisig Wallet Policy on your Ledger Device']);

const withdrawalPSBT = await dlcHandler.createWithdrawPSBT(
Expand Down
Loading
Loading