Skip to content

Commit

Permalink
Refining strategy to make the code act more lightly when collecting t…
Browse files Browse the repository at this point in the history
…he balances.
  • Loading branch information
danilo-silva-funttastic committed Aug 27, 2024
1 parent e5bd058 commit 4cbd9ed
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/connectors/kujira/kujira.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1229,6 +1229,10 @@ export class Kujira {
ownerAddress: options.ownerAddress,
tokenIds: options.tokenId ? [options.tokenId] : undefined,
tokenSymbols: options.tokenSymbol ? [options.tokenSymbol] : undefined,
marketId: options.marketId,
marketName: options.marketName,
marketIds: options.marketIds,
marketNames: options.marketNames,
});

if (options.tokenId) {
Expand All @@ -1254,6 +1258,10 @@ export class Kujira {
async getBalances(options: GetBalancesRequest): Promise<GetBalancesResponse> {
const allBalances = await this.getAllBalances({
ownerAddress: options.ownerAddress,
marketId: options.marketId,
marketName: options.marketName,
marketIds: options.marketIds,
marketNames: options.marketNames,
});

const balances: Balances = {
Expand Down Expand Up @@ -1319,6 +1327,10 @@ export class Kujira {

const orders = (await this.getOrders({
ownerAddress: options.ownerAddress,
marketId: options.marketId,
marketName: options.marketName,
marketIds: options.marketIds,
marketNames: options.marketNames,
})) as IMap<OrderId, Order>;

const quotations = await this.getAllTokensQuotationsInUSD({});
Expand Down Expand Up @@ -1428,14 +1440,9 @@ export class Kujira {
bundles,
});
} else {
// TODO Handle better the case when no market is informed. The ideal is to fetch the orders only from the markets who have them!!!
// const marketIds =
// options.marketIds ||
// (await this.getAllMarkets({}, this.network)).keySeq().toArray();

const marketIds =
options.marketIds ||
[];
(await this.getAllMarkets({}, this.network)).keySeq().toArray();

orders = IMap<OrderId, Order>().asMutable();

Expand Down
12 changes: 12 additions & 0 deletions src/connectors/kujira/kujira.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,10 @@ export interface GetBalanceRequest {
tokenId: TokenId;
tokenSymbol: TokenSymbol;
ownerAddress: OwnerAddress;
marketId?: MarketId;
marketName?: MarketName;
marketIds?: MarketId[];
marketNames?: MarketName[];
}

// eslint-disable-next-line @typescript-eslint/no-empty-interface
Expand All @@ -529,6 +533,10 @@ export interface GetBalancesRequest {
tokenIds?: TokenId[];
tokenSymbols?: TokenSymbol[];
ownerAddress: OwnerAddress;
marketId?: MarketId;
marketName?: MarketName;
marketIds?: MarketId[];
marketNames?: MarketName[];
}

// eslint-disable-next-line @typescript-eslint/no-empty-interface
Expand All @@ -537,6 +545,10 @@ export interface GetBalancesResponse extends Balances {}
// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface GetAllBalancesRequest {
ownerAddress: OwnerAddress;
marketId?: MarketId;
marketName?: MarketName;
marketIds?: MarketId[];
marketNames?: MarketName[];
}

// eslint-disable-next-line @typescript-eslint/no-empty-interface
Expand Down

0 comments on commit 4cbd9ed

Please sign in to comment.