useGetEscrowFromIndexerByContractIds

Returns the escrows that you're looking for. It comes from our indexer (database) synchronizer with the blockchain.

Usage

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

import { useGetEscrowFromIndexerByContractIds } from "@trustless-work/escrow/hooks";
import { GetEscrowFromIndexerByContractIdsParams } from "@trustless-work/escrow/types";

/*
 *  useGetEscrowFromIndexerByContractIds
*/
const { getEscrowByContractIds } = useGetEscrowFromIndexerByContractIds();

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

Function

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

Argument:

GetEscrowFromIndexerByContractIdsParams: An object containing the required fields to get the escrows.

Types

Return Value:

escrows: The escrows that you are looking for.


Usage ExampleForm

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

export const useGetEscrowFromIndexerByContractIdsForm = () => {

 /*
  *  useGetEscrowFromIndexerByContractIds
 */
 const { getEscrowByContractIds } = useGetEscrowFromIndexerByContractIds();

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

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

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

Last updated

Was this helpful?