Skip to content

Commit

Permalink
update token locks №2
Browse files Browse the repository at this point in the history
  • Loading branch information
Ridel1e committed Mar 22, 2024
1 parent 2ec5abc commit c25bf7a
Showing 1 changed file with 18 additions and 22 deletions.
40 changes: 18 additions & 22 deletions src/network/cardano/api/common/tokenLocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import groupBy from 'lodash/groupBy';
import last from 'lodash/last';
import uniq from 'lodash/uniq';
import uniqBy from 'lodash/uniqBy';
import { combineLatest, map, of, switchMap } from 'rxjs';
import { catchError, combineLatest, map, of, switchMap } from 'rxjs';

import { appTick$ } from '../../../../common/streams/appTick.ts';
import { PoolId } from '../../../../common/types.ts';
Expand Down Expand Up @@ -36,27 +36,22 @@ export const locks$ = appTick$.pipe(
),
);

return appTick$.pipe(
map(() => creds),
switchMap((creds) => appTick$.pipe(map(() => creds))),
switchMap((creds) => {
const credsBatches: string[][] = [[]];
//
for (const cred of creds) {
const lastItem = last(credsBatches);
if (!lastItem) {
break;
}
if (lastItem.length >= 400) {
credsBatches.push([cred]);
} else {
lastItem.push(cred);
}
}
return combineLatest(
credsBatches.map((batch) => getLocksByPaymentCreds(batch)),
);
}),
const credsBatches: string[][] = [[]];
//
for (const cred of creds) {
const lastItem = last(credsBatches);
if (!lastItem) {
break;
}
if (lastItem.length >= 400) {
credsBatches.push([cred]);
} else {
lastItem.push(cred);
}
}
return combineLatest(
credsBatches.map((batch) => getLocksByPaymentCreds(batch)),
).pipe(
map((locksBatches) => {
return groupBy(
uniqBy(
Expand All @@ -66,6 +61,7 @@ export const locks$ = appTick$.pipe(
(item) => item.poolId,
);
}),
catchError(() => of({})),
);
}

Expand Down

0 comments on commit c25bf7a

Please sign in to comment.