Skip to content

Commit

Permalink
[1958] Move fetchUserInfo to subscribe (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
Anton-rock authored Oct 31, 2024
1 parent af1a64d commit 73b44d3
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 16 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@compolabs/spark-orderbook-ts-sdk",
"version": "1.12.0",
"version": "1.12.1",
"type": "module",
"main": "./dist/index.сjs",
"module": "./dist/index.js",
Expand Down
17 changes: 5 additions & 12 deletions src/IndexerApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
gql,
Observable,
} from "@apollo/client";
import { Undefinable } from "tsdef";

import BN from "./utils/BN";
import { generateWhereFilter } from "./utils/generateWhereFilter";
Expand Down Expand Up @@ -174,11 +173,11 @@ export class IndexerApi extends GraphClient {
};
};

getUserInfo = async (
subscribeUserInfo = (
params: UserInfoParams,
): Promise<Undefinable<UserInfo>> => {
): Observable<FetchResult<{ User: UserInfo[] }>> => {
const query = gql`
query UserQuery($where: User_bool_exp) {
subscription UserQuery($where: User_bool_exp) {
User(where: $where) {
id
active
Expand All @@ -189,19 +188,13 @@ export class IndexerApi extends GraphClient {
}
`;

const response = await this.client.query<{
UserQuery: UserInfo[];
return this.client.subscribe<{
User: UserInfo[];
}>({
query,
variables: {
where: generateWhereFilter(params),
},
});

if (!response.data.UserQuery.length) {
return;
}

return response.data.UserQuery[0];
};
}
6 changes: 4 additions & 2 deletions src/SparkOrderbook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,10 @@ export class SparkOrderbook {
return this.activeIndexerApi.getVolume(params);
}

async fetchUserInfo(params: UserInfoParams): Promise<Undefinable<UserInfo>> {
return this.activeIndexerApi.getUserInfo(params);
subscribeUserInfo(
params: UserInfoParams,
): Observable<FetchResult<{ User: UserInfo[] }>> {
return this.activeIndexerApi.subscribeUserInfo(params);
}

async fetchMarkets(assetIdPairs: [string, string][]): Promise<Markets> {
Expand Down
2 changes: 1 addition & 1 deletion src/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ export interface UserProtocolFee {
}

export interface UserInfoParams {
user: string;
id: string;
}

export interface UserInfo {
Expand Down

0 comments on commit 73b44d3

Please sign in to comment.