All files / app/hooks use-create-contract-call-tx.ts

0% Statements 0/14
0% Branches 0/1
0% Functions 0/4
0% Lines 0/13

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26                                                   
import { useCreateLedgerContractCallTx } from './use-create-ledger-contract-call-tx';
import { useCreateSoftwareContractCallTx } from './use-create-software-contract-call-tx';
import { useWalletType } from './use-wallet-type';
import { ContractCallOptions } from '@stacks/transactions';
import { useCallback } from 'react';
 
export function useCreateContractCallTx() {
  const { whenWallet } = useWalletType();
  const { createSoftwareContractCallTx } = useCreateSoftwareContractCallTx();
  const { createLedgerContractCallTx } = useCreateLedgerContractCallTx();
 
  return useCallback(
    async (txOptions: ContractCallOptions, privateKey?: string) =>
      whenWallet({
        async software() {
          Iif (!privateKey) throw new Error('Software wallet txs require private key');
          return createSoftwareContractCallTx({ txOptions, privateKey });
        },
        async ledger() {
          return createLedgerContractCallTx({ ...txOptions });
        },
      })(),
    [createLedgerContractCallTx, createSoftwareContractCallTx, whenWallet]
  );
}