useGetEscrowsFromIndexerByContractId

Returns all

Usage

This custom hook exposes a function to get the balances that you are looking obtain.

import { useGetEscrowFromIndexerByContractId } from "@trustless-work/escrow/hooks";
import { GetEscrowFromIndexerByContractIdParams } from "@trustless-work/escrow/types";

/*
 *  useGetMultipleEscrowBalances
*/
const { getEscrowByContractId } = useGetEscrowFromIndexerByContractId();

/* 
 * It returns the escrow that you are looking for
 * payload should be of type `GetEscrowFromIndexerByContractIdParams`
*/
await getEscrowByContractId(payload);

Function

  • getEscrowByContractId Responsible for building and returning data based on the provided payload.

Argument:

GetEscrowFromIndexerByContractIdParams: An object containing the required fields to get the escrow.

Types

Return Value:

escrow: The escrow that you are looking for.


Usage ExampleForm

src/hooks/useGetEscrowFromIndexerByContractId.ts
import {
  useGetEscrowFromIndexerByContractId,
} from "@trustless-work/escrow/hooks";
import {
  GetEscrowFromIndexerByContractIdParams, 
} from "@trustless-work/escrow/types";

export const useGetEscrowFromIndexerByContractIdForm = () => {

 /*
  *  useGetMultipleEscrowBalances
 */
 const { getEscrowByContractId } = useGetEscrowFromIndexerByContractId();

/*
 * onSubmit function, this could be called by form button
*/
 const onSubmit = async (payload: GetEscrowFromIndexerByContractIdParams) => {

    try {
      /**
       * API call by using the trustless work hooks
       * @Note:
       * - We need to pass the payload to the getEscrowByContractId function
       * - The result will be an escrow
      */
      const escrow = await getEscrowByContractId(payload);
      
      if (!escrow) {
        throw new Error("Escrow not found");
      }

      /**
       * @Responses:
       * escrow !== null
       * - Escrow received successfully
       * - Show a success toast
       *
       * escrow === null
       * - Show an error toast
       */
      if (balances) {
        toast.success("Escrow Received");
      }
    } catch (error: unknown) {
      // catch error logic
    }
  };
}

Last updated

Was this helpful?