Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update validator balance fetch subquery with validators table #196

Merged
merged 1 commit into from
Nov 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/components/validators/ValidatorPortfolio.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export type ValidatorPortfolioProps = {
export const ValidatorPortfolio = (props: ValidatorPortfolioProps) => {
const { hotkey } = props;

const balance = useValidatorBalance({ delegate: { equalTo: hotkey } });
const balance = useValidatorBalance({ address: { equalTo: hotkey } });
const coldKey = useColdKey(hotkey);
const validatorStaked = useValidatorStaked(hotkey, coldKey);
const loading = balance.loading || validatorStaked === undefined;
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/useValidatorBalance.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { FetchOptions } from "../model/fetchOptions";
import { DelegateBalanceFilter, getValidatorBalances } from "../services/delegateService";
import { ValidatorFilter, getValidatorBalances } from "../services/delegateService";
import { useResource } from "./useResource";

export function useValidatorBalance(
filter: DelegateBalanceFilter | undefined,
filter: ValidatorFilter | undefined,
options?: FetchOptions
) {
return useResource(getValidatorBalances, [filter], options);
Expand Down
2 changes: 1 addition & 1 deletion src/model/delegate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export type DelegateBalance = {
};

export type ValidatorBalance = {
aggregates: any;
nodes: any;
};

export type DelegateInfo = {
Expand Down
2 changes: 1 addition & 1 deletion src/screens/validators.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export const ValidatorPage = () => {

const info = verifiedDelegates[address];

const balance = useValidatorBalance({ delegate: { equalTo: address } });
const balance = useValidatorBalance({ address: { equalTo: address } });
const validatorStakeHistory = useValidatorStakeHistory(address);

const nominatorsInitialOrder: DelegateBalancesOrder = "AMOUNT_DESC";
Expand Down
17 changes: 8 additions & 9 deletions src/services/delegateService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export type DelegatesOrder =
| "BLOCK_NUMBER_ASC"
| "BLOCK_NUMBER_DESC";

export type ValidatorFilter = object;
export type DelegateBalanceFilter = object;
export type DelegateBalancesOrder =
| "ID_ASC"
Expand Down Expand Up @@ -160,15 +161,13 @@ async function fetchDelegateBalances(
}

async function fetchValidatorBalances(
filter: DelegateBalanceFilter | undefined
filter: ValidatorFilter | undefined
) {
const response = await fetchIndexer<{ delegateBalances: ValidatorBalance }>(
`query ($filter: DelegateBalanceFilter) {
delegateBalances(filter: $filter) {
aggregates {
sum {
amount
}
const response = await fetchIndexer<{ validators: ValidatorBalance }>(
`query ($filter: ValidatorFilter) {
validators(filter: $filter) {
nodes {
amount
}
}
}`,
Expand All @@ -177,7 +176,7 @@ async function fetchValidatorBalances(
}
);

const data = response.delegateBalances?.aggregates?.sum?.amount ?? 0;
const data = response.validators?.nodes[0]?.amount ?? 0;
return data;
}

Expand Down
Loading