diff --git a/explorer-nextjs/src/app/api/types.ts b/explorer-nextjs/src/app/api/types.ts index 644d8addb6..ea841f14ae 100644 --- a/explorer-nextjs/src/app/api/types.ts +++ b/explorer-nextjs/src/app/api/types.ts @@ -365,3 +365,22 @@ export type GatewayStatus = { }; }; }; + +type BalanceDetails = { + amount: number; + denom: string; +}; + +export type ObservatoryRewards = { + operator_commissions: BalanceDetails; + staking_rewards: BalanceDetails; + unlocked: BalanceDetails; +}; + +export type ObservatoryBalance = { + delegated: BalanceDetails; + locked: BalanceDetails; + rewards: ObservatoryRewards; + self_bonded: BalanceDetails; + spendable: BalanceDetails; +}; diff --git a/explorer-nextjs/src/app/api/urls.ts b/explorer-nextjs/src/app/api/urls.ts index 548863c24f..a46e5e7afa 100644 --- a/explorer-nextjs/src/app/api/urls.ts +++ b/explorer-nextjs/src/app/api/urls.ts @@ -34,3 +34,7 @@ export const VALIDATOR_BASE_URL = process.env.NEXT_PUBLIC_VALIDATOR_URL || "https://rpc.nymtech.net"; export const DATA_OBSERVATORY_NODES_URL = "https://api.nym.spectredao.net/api/v1/nodes"; +export const DATA_OBSERVATORY_DELEGATIONS_URL = + "https://api.nym.spectredao.net/api/v1/delegations"; +export const DATA_OBSERVATORY_BALANCES_URL = + "https://api.nym.spectredao.net/api/v1/balances"; diff --git a/explorer-nextjs/src/components/staking/StakeTable.tsx b/explorer-nextjs/src/components/staking/StakeTable.tsx index 42f295cf2e..16b8d5cbde 100644 --- a/explorer-nextjs/src/components/staking/StakeTable.tsx +++ b/explorer-nextjs/src/components/staking/StakeTable.tsx @@ -224,6 +224,7 @@ const StakeTable = ({ nodes }: { nodes: MappedNymNodes }) => { ), }, + { id: "action", header: "Action", diff --git a/explorer-nextjs/src/components/staking/TotalRewardsCard.tsx b/explorer-nextjs/src/components/staking/TotalRewardsCard.tsx index d485d060df..2094dc0b78 100644 --- a/explorer-nextjs/src/components/staking/TotalRewardsCard.tsx +++ b/explorer-nextjs/src/components/staking/TotalRewardsCard.tsx @@ -1,14 +1,49 @@ +import type { ObservatoryBalance } from "@/app/api/types"; +import { DATA_OBSERVATORY_BALANCES_URL } from "@/app/api/urls"; +import { useNymClient } from "@/hooks/useNymClient"; +import { formatBigNum } from "@/utils/formatBigNumbers"; import { Typography } from "@mui/material"; +import { useEffect, useState } from "react"; import ExplorerCard from "../cards/ExplorerCard"; const TotalRewardsCard = () => { + const [totalStakerRewards, setTotalStakerRewards] = useState(); + const { nymClient, address } = useNymClient(); + + useEffect(() => { + if (!nymClient || !address) return; + + const fetchBalances = async () => { + const data = await fetch(`${DATA_OBSERVATORY_BALANCES_URL}/${address}`, { + headers: { + Accept: "application/json", + "Content-Type": "application/json; charset=utf-8", + }, + next: { revalidate: 60 }, + // refresh event list cache at given interval + }); + const balances: ObservatoryBalance = await data.json(); + console.log("balances :>> ", balances); + const stakerRewards = formatBigNum( + +balances.rewards.staking_rewards.amount / 1_000_000, + ); + + return setTotalStakerRewards(stakerRewards); + }; + + fetchBalances(); + }, [address, nymClient]); + + if (!address) { + return null; + } return ( - - NYM + {totalStakerRewards || 0} NYM );