Skip to content

Commit

Permalink
[Updated] Reduce drops sent in MySavings only by poolId
Browse files Browse the repository at this point in the history
  • Loading branch information
greedyboi committed Feb 28, 2024
1 parent 3026313 commit 9d1c394
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/utils/lumClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ class LumClient {
}

const aggregatedDeposits = await PoolsUtils.reduceDepositsByPoolId(deposits);
const aggregatedDepositDropsSent = await PoolsUtils.reduceDepositDropsByPoolIdAndDays(deposits);
const aggregatedDepositDropsSent = await PoolsUtils.reduceDepositDropsByPoolIdAndDays(deposits, { reduceBy: 'poolId' });

let withdrawalsNextPageKey = new Uint8Array();
const withdrawals: Withdrawal[] = [];
Expand Down
17 changes: 14 additions & 3 deletions src/utils/pools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,18 @@ export const getPoolByPoolId = (pools: PoolModel[], poolId: string) => {
};

// DROPS
export const reduceDepositDropsByPoolIdAndDays = async (deposits: Partial<DepositModel>[]) => {
export const reduceDepositDropsByPoolIdAndDays = async (deposits: Partial<DepositModel>[], options: { reduceBy: 'poolId' | 'date' } = { reduceBy: 'date' }) => {
const aggregatedDeposits: AggregatedDepositModel[] = [];

for (const deposit of deposits) {
const poolId = deposit.poolId;
const reduceByDate = options.reduceBy === 'date';

if (poolId === undefined || deposit.createdAt === undefined) {
if (poolId === undefined) {
continue;
}

if (reduceByDate && deposit.createdAt === undefined) {
continue;
}

Expand All @@ -140,7 +145,13 @@ export const reduceDepositDropsByPoolIdAndDays = async (deposits: Partial<Deposi
continue;
}

const existingDeposit = aggregatedDeposits.find((d) => d.poolId?.toString() === poolId.toString() && dayjs(d.createdAt).format('YYYY-MM-DD') === createdAt);
const existingDeposit = aggregatedDeposits.find((d) => {
if (reduceByDate) {
return d.poolId?.toString() === poolId.toString() && dayjs(d.createdAt).format('YYYY-MM-DD') === createdAt;
} else {
return d.poolId?.toString() === poolId.toString();
}
});

if (
existingDeposit &&
Expand Down

0 comments on commit 9d1c394

Please sign in to comment.