Skip to content

useActivity

(Available from v1.2.15)

A hook that fetches and manages transaction activity (fund, send, receive, etc.) from the Glyph widget. Supports filtering by transaction type and pagination.

Import

tsx
import {
  useActivity,
  ActivityType,
  DB_OFFCHAIN_TX_TYPE,
  DB_ONCHAIN_TX_TYPE,
} from "@use-glyph/sdk-react";

Usage

tsx
import { useEffect } from "react";

function ActivityList() {
  const {
    transactionGroups,
    fetchTransactions,
    loadMore,
    reset,
    hasMore,
    isLoading,
  } = useActivity(10);

  useEffect(() => {
    fetchTransactions(true);
  }, []);

  return (
    <div>
      {transactionGroups.map((group) => (
        <div key={group.label}>
          <h3>{group.label}</h3>
          {group.transactions.map((tx) => (
            <div key={tx.id}>
              {tx.type_text}: {tx.amount} {tx.amount_currency}
            </div>
          ))}
        </div>
      ))}
      {hasMore && (
        <button onClick={loadMore} disabled={isLoading}>
          Load more
        </button>
      )}
    </div>
  );
}

Filtering by Transaction Type

Pass an optional filter as the second argument to restrict activity to specific transaction types:

tsx
// Only show funding transactions
const { transactionGroups, fetchTransactions } = useActivity(10, {
  types: [DB_OFFCHAIN_TX_TYPE.FUND],
});

// Only show send and receive
const { transactionGroups } = useActivity(10, {
  types: [DB_ONCHAIN_TX_TYPE.SEND, DB_ONCHAIN_TX_TYPE.RECEIVE],
});

Return Type

PropertyTypeDescription
transactionGroupsActivityGroup[]Groups of transactions, typically grouped by date.
fetchTransactions(reset?: boolean) => Promise<ActivityGroup[] | null>Fetches transactions. Pass true to reset and fetch from the beginning.
loadMore() => Promise<boolean>Loads the next page of transactions. Returns true if more were loaded.
reset() => Promise<void>Resets and refetches from the beginning.
hasMorebooleanWhether more transactions are available to load.
isLoadingbooleanWhether a fetch is in progress.

Types

ActivityType

Transaction types from DB_OFFCHAIN_TX_TYPE and DB_ONCHAIN_TX_TYPE:

Offchain: FUND, SWAP, WITHDRAW
Onchain: SEND, RECEIVE, TRANSFER, PAY

ActivityItem

PropertyTypeDescription
idstringUnique transaction ID.
chain_idnumberChain ID where the transaction occurred.
typeActivityTypeTransaction type.
type_textstringHuman-readable type label.
statusstringTransaction status.
status_textstring | nullHuman-readable status.
status_colorstringColor hint for the status badge.
symbolstringToken symbol.
valuestringDisplay value.
amountstringAmount.
amount_currencystringCurrency/symbol for amount.
name_on_liststring | nullDisplay name for the transaction.
allowIdCopybooleanWhether the transaction ID can be copied.
detail_rowsstring[]Additional detail lines.
blockExplorerTxnsActivityBlockExplorerItem[] | undefinedLinks to block explorer.

ActivityBlockExplorerItem

PropertyTypeDescription
urlstringURL to the block explorer transaction.
textstringDisplay text for the link.

ActivityGroup

PropertyTypeDescription
labelstringGroup label (e.g. date).
transactionsActivityItem[]Transactions in this group.

Notes

  • This hook must be used within a GlyphProvider.
  • Activity is fetched for the current chain, or across all chains when fetchForAllNetworks is enabled.
  • The hook supports both grouped and legacy (ungrouped) API response formats.