-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathuseFixedPools.ts
46 lines (38 loc) · 1.36 KB
/
useFixedPools.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import { useMemo } from 'react';
import { FixedPool, Pool } from 'types/FixedPool';
import useAccountData from './useAccountData';
export default () => {
const { accountData } = useAccountData();
const fixedPools = useMemo(() => {
const data = { deposits: {} as FixedPool, borrows: {} as FixedPool };
if (!accountData) return data;
accountData.forEach((asset) => {
asset.fixedDepositPositions.forEach((pool) => {
const date = pool.maturity;
const entry: Pool = {
maturity: date,
symbol: asset.assetSymbol,
market: asset.market,
fee: pool.position.fee,
decimals: asset.decimals,
previewValue: pool.previewValue,
};
data.deposits[String(date)] = data.deposits[String(date)] ? [...data.deposits[String(date)], entry] : [entry];
});
asset.fixedBorrowPositions.forEach((pool) => {
const date = pool.maturity;
const entry: Pool = {
maturity: date,
symbol: asset.assetSymbol,
market: asset.market,
fee: pool.position.fee,
decimals: asset.decimals,
previewValue: pool.previewValue,
};
data.borrows[String(date)] = data.borrows[String(date)] ? [...data.borrows[String(date)], entry] : [entry];
});
});
return data;
}, [accountData]);
return fixedPools;
};