Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
tyleroooo committed Dec 13, 2024
1 parent e7d5a2a commit 2c7563a
Showing 1 changed file with 3 additions and 32 deletions.
35 changes: 3 additions & 32 deletions src/abacus-ts/calculators/orders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@ import { assertNever } from '@/lib/assertNever';
import { MustBigNumber } from '@/lib/numbers';

import { Loadable } from '../lib/loadable';
import { mapLoadableData } from '../lib/mapLoadable';
import { mergeObjects } from '../lib/mergeObjects';
import { OrdersData } from '../rawTypes';
import { OrderStatus } from '../summaryTypes';

const BN_0 = MustBigNumber(0);
const BN_1 = MustBigNumber(1);

// todo these are calculating the same thing twice pasically
function calculateOpenOrders(liveOrders: Loadable<OrdersData>, restOrders: Loadable<OrdersData>) {

Check failure on line 17 in src/abacus-ts/calculators/orders.ts

View workflow job for this annotation

GitHub Actions / lint

'calculateOpenOrders' is defined but never used
const getOpenOrders = (data: Loadable<OrdersData>) =>
Expand Down Expand Up @@ -59,6 +58,7 @@ function getSimpleOrderStatus(status: OrderStatus) {
return OrderStatus.Filled;
default:
assertNever(status);
// should never happen since we made OrderStatus manually
return OrderStatus.Open;
}
}
Expand Down Expand Up @@ -128,32 +128,3 @@ function calculateMergedOrders(liveOrders: Loadable<OrdersData>, restOrders: Loa
maxBy([a, b], (o) => MustBigNumber(o.updatedAtHeight ?? o.createdAtHeight).toNumber())!
);
}

function mapLoadableData<T, R>(load: Loadable<T>, map: (obj: T) => R): Loadable<R> {
return {
...load,
data: load.data != null ? map(load.data) : undefined,
} as Loadable<R>;
}

type SimpleMap<T> = { [key: string]: T };
function mergeObjects<T>(one: SimpleMap<T>, two: SimpleMap<T>, merge: (a: T, b: T) => T) {
const finalObj: SimpleMap<T> = {};

[...Object.keys(one), ...Object.keys(two)].forEach((key) => {
if (finalObj[key] != null) {
return;
}
const obj = one[key];
const otherObj = two[key];
if (obj != null && otherObj != null) {
finalObj[key] = merge(obj, otherObj);
} else if (obj == null && otherObj == null) {
// do nothing
} else {
// we know one of them is non-null
finalObj[key] = (obj ?? otherObj)!;
}
});
return finalObj;
}

0 comments on commit 2c7563a

Please sign in to comment.