Skip to content

Commit

Permalink
Fetch stakes from updated indexer (#161)
Browse files Browse the repository at this point in the history
* Fetch stakes from updated indexer

* Indexer url update
  • Loading branch information
bobo-k2 authored Jul 18, 2024
1 parent 9434904 commit 9f240a1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/client/BaseApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ export interface IAstarApi {
getCurrentEra(): Promise<number>;
getApiPromise(): Promise<ApiPromise>;
getStakerInfo(address: string): Promise<bigint>;
getProtocolState(): Promise<PalletDappStakingV3ProtocolState>;
}

export class BaseApi implements IAstarApi {
Expand Down Expand Up @@ -233,6 +234,12 @@ export class BaseApi implements IAstarApi {
}
}

public async getProtocolState(): Promise<PalletDappStakingV3ProtocolState> {
await this.ensureConnection();

return await this._api.query.dappStaking.activeProtocolState<PalletDappStakingV3ProtocolState>();
}

public async getStakerInfo(address: string): Promise<bigint> {
await this.ensureConnection();
let ss558Address = address;
Expand Down
8 changes: 7 additions & 1 deletion src/services/DappsStakingEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,13 +314,19 @@ export class DappsStakingEvents extends DappStakingV3IndexerBase implements IDap

public async getDappStakingStakersList(network: NetworkType, contractAddress: string): Promise<List[]> {
this.GuardNetwork(network);
Guard.ThrowIfUndefined('contractAddress', contractAddress);

// Fetch current period
const api = this._apiFactory.getApiInstance(network);
const protocolState = await api.getProtocolState();
const period = protocolState.periodInfo.number.toNumber();

try {
const result = await axios.post(this.getApiUrl(network), {
query: `query {
stakes(
where: {
expiredAt_isNull: true,
period_eq: ${period},
dappAddress_eq: "${contractAddress}"
}
) {
Expand Down

0 comments on commit 9f240a1

Please sign in to comment.