-
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from TxnLab/feat/show-rewards
Show pending rewards and bar chart of stake per pool in validator details
- Loading branch information
Showing
6 changed files
with
69 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { Validator } from '@/interfaces/validator' | ||
import { useQuery } from '@tanstack/react-query' | ||
import { getAccountBalance } from '@/api/algod' | ||
import { getApplicationAddress } from 'algosdk' | ||
import { AlgoDisplayAmount } from '@/components/AlgoDisplayAmount' | ||
|
||
async function fetchTotalBalances(validator: Validator) { | ||
try { | ||
let totalBalances = 0 | ||
for (const pool of validator.pools) { | ||
const poolBal = await getAccountBalance(getApplicationAddress(pool.poolAppId), true) | ||
totalBalances += poolBal | ||
} | ||
return totalBalances - Number(validator.state.totalAlgoStaked) | ||
} catch (error) { | ||
console.error(error) | ||
return 0 | ||
} | ||
} | ||
|
||
interface ValidatorRewardsProps { | ||
validator: Validator | ||
} | ||
|
||
export function ValidatorRewards({ validator }: ValidatorRewardsProps) { | ||
const totalBalancesQuery = useQuery({ | ||
queryKey: ['valrewards', validator.id], | ||
queryFn: () => fetchTotalBalances(validator), | ||
refetchInterval: 30000, | ||
}) | ||
|
||
if (totalBalancesQuery.isLoading) { | ||
return <span>Loading...</span> | ||
} | ||
if (totalBalancesQuery.error || totalBalancesQuery.data == undefined) { | ||
return <span className="text-sm text-red-500">Error fetching balance</span> | ||
} | ||
return <AlgoDisplayAmount amount={totalBalancesQuery.data} microalgos /> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters