UNPKG

blub-sdk

Version:

A modular SDK for interacting with the BLUB ecosystem on the Sui blockchain.

89 lines (88 loc) 2.63 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.useBlubBalance = useBlubBalance; exports.useBlubCirculatingSupply = useBlubCirculatingSupply; exports.useBlubTotalSupply = useBlubTotalSupply; exports.useBlubPrice = useBlubPrice; exports.useSuiPrice = useSuiPrice; exports.useBlubMarketCap = useBlubMarketCap; const swr_1 = __importDefault(require("swr")); const client_1 = require("./client"); const prices_1 = require("./prices"); const stats_1 = require("./stats"); const marketcap_1 = require("./marketcap"); /** * Hook to fetch the BLUB token balance for a given wallet address. * * @param address - Wallet address to query. * @returns { balance, isLoading, error } */ function useBlubBalance(address) { const shouldFetch = !!address; const { data, error, isLoading } = (0, swr_1.default)(shouldFetch ? ["blubBalance", address] : null, () => (0, client_1.getBlubBalance)(address), { refreshInterval: 30000 }); return { balance: data, isLoading, error, }; } /** * Hook to retrieve the current estimated circulating supply of BLUB. * * @returns { supply, isLoading, error } */ function useBlubCirculatingSupply() { const { data, error } = (0, swr_1.default)("blubCirculatingSupply", () => (0, stats_1.getBlubCirculatingSupply)(), { refreshInterval: 60000 }); return { supply: data, error, }; } /** * Hook to retrieve the fixed total supply of BLUB. * * @returns { totalSupply } */ function useBlubTotalSupply() { const { data, error } = (0, swr_1.default)("blubTotalSupply", () => (0, stats_1.getBlubTotalSupply)()); return { totalSupply: data, error, }; } /** * Hook to fetch the current BLUB price in USD. */ function useBlubPrice() { const { data, error, isLoading } = (0, swr_1.default)("blubPrice", prices_1.getBlubPrice); return { price: data, isLoading, error, }; } /** * Hook to fetch the current SUI price in USD. */ function useSuiPrice() { const { data, error, isLoading } = (0, swr_1.default)("suiPrice", prices_1.getSuiPrice); return { price: data, isLoading, error, }; } /** * Hook to fetch the current BLUB market cap in USD. */ function useBlubMarketCap() { const { data, error, isLoading } = (0, swr_1.default)("blubMarketCap", marketcap_1.getBlubMarketCap); return { marketCap: data, isLoading, error, }; }