Skip to content

Commit f20cc42

Browse files
omit_from_total (#6103)
1 parent c8ab4b5 commit f20cc42

File tree

2 files changed

+23
-31
lines changed

2 files changed

+23
-31
lines changed

Diff for: src/resources/defi/types.ts

+3
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,15 @@ export type PositionsTotals = {
4040
export type Claimable = {
4141
asset: PositionAsset;
4242
quantity: string;
43+
omit_from_total?: boolean;
4344
};
4445
export type Deposit = {
4546
apr: string;
4647
apy: string;
4748
asset: PositionAsset;
4849
quantity: string;
4950
total_asset: string; // what does this mean?
51+
omit_from_total?: boolean;
5052
underlying: { asset: PositionAsset; quantity: string }[];
5153
};
5254
export type Borrow = {
@@ -55,6 +57,7 @@ export type Borrow = {
5557
asset: PositionAsset;
5658
quantity: string;
5759
total_asset: string; // what does this mean?
60+
omit_from_total?: boolean;
5861
underlying: { asset: PositionAsset; quantity: string }[];
5962
};
6063

Diff for: src/resources/defi/utils.ts

+20-31
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@ import {
33
AddysPositionsResponse,
44
Borrow,
55
Claimable,
6-
Deposit,
7-
NativeDisplay,
86
Position,
9-
PositionAsset,
107
PositionsTotals,
118
RainbowBorrow,
129
RainbowClaimable,
@@ -21,66 +18,58 @@ import { chainsIdByName } from '@/chains';
2118

2219
export const parsePosition = (position: Position, currency: NativeCurrencyKey): RainbowPosition => {
2320
let totalDeposits = '0';
24-
const parsedDeposits = position.deposits?.map((deposit: Deposit): RainbowDeposit => {
25-
deposit.underlying = deposit.underlying?.map(
26-
(underlying: {
27-
asset: PositionAsset;
28-
quantity: string;
29-
}): {
30-
asset: PositionAsset;
31-
quantity: string;
32-
native: NativeDisplay;
33-
} => {
21+
const parsedDeposits = position.deposits?.map((deposit): RainbowDeposit => {
22+
return {
23+
...deposit,
24+
underlying: deposit.underlying?.map(underlying => {
3425
const nativeDisplay = convertRawAmountToNativeDisplay(
3526
underlying.quantity,
3627
underlying.asset.decimals,
3728
underlying.asset.price?.value!,
3829
currency
3930
);
40-
totalDeposits = add(totalDeposits, nativeDisplay.amount);
31+
if (!deposit.omit_from_total) {
32+
totalDeposits = add(totalDeposits, nativeDisplay.amount);
33+
}
4134

4235
return {
4336
...underlying,
4437
native: nativeDisplay,
4538
};
46-
}
47-
);
48-
return deposit as RainbowDeposit;
39+
}),
40+
};
4941
});
5042

5143
let totalBorrows = '0';
5244

5345
const parsedBorrows = position.borrows?.map((borrow: Borrow): RainbowBorrow => {
54-
borrow.underlying = borrow.underlying.map(
55-
(underlying: {
56-
asset: PositionAsset;
57-
quantity: string;
58-
}): {
59-
asset: PositionAsset;
60-
quantity: string;
61-
native: NativeDisplay;
62-
} => {
46+
return {
47+
...borrow,
48+
underlying: borrow.underlying.map(underlying => {
6349
const nativeDisplay = convertRawAmountToNativeDisplay(
6450
underlying.quantity,
6551
underlying.asset.decimals,
6652
underlying.asset.price?.value!,
6753
currency
6854
);
69-
totalBorrows = add(totalBorrows, nativeDisplay.amount);
55+
if (!borrow.omit_from_total) {
56+
totalBorrows = add(totalBorrows, nativeDisplay.amount);
57+
}
7058

7159
return {
7260
...underlying,
7361
native: nativeDisplay,
7462
};
75-
}
76-
);
77-
return borrow as RainbowBorrow;
63+
}),
64+
};
7865
});
7966

8067
let totalClaimables = '0';
8168
const parsedClaimables = position.claimables?.map((claim: Claimable): RainbowClaimable => {
8269
const nativeDisplay = convertRawAmountToNativeDisplay(claim.quantity, claim.asset.decimals, claim.asset.price?.value!, currency);
83-
totalClaimables = add(totalClaimables, nativeDisplay.amount);
70+
if (!claim.omit_from_total) {
71+
totalClaimables = add(totalClaimables, nativeDisplay.amount);
72+
}
8473
return {
8574
asset: claim.asset,
8675
quantity: claim.quantity,

0 commit comments

Comments
 (0)