Skip to content

Commit a191c63

Browse files
authored
save asset underlying properly (#1824)
1 parent 8a4ba3c commit a191c63

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

src/app/api/leverage/history/route.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,15 @@ export async function POST(req: NextRequest) {
156156
const stats = open.reduce(
157157
(acc, position) => ({
158158
...acc,
159-
[`${position.trade.underlyingAssetSymbol}-${position.trade.underlyingAssetUnitPriceDenominator}`]:
160-
prices[position.trade.underlyingAssetSymbol!.toLowerCase()][
161-
position.trade.underlyingAssetUnitPriceDenominator!.toLowerCase()
162-
] ?? 0,
159+
...(position.trade.underlyingAssetSymbol &&
160+
position.trade.underlyingAssetUnitPriceDenominator
161+
? {
162+
[`${position.trade.underlyingAssetSymbol}-${position.trade.underlyingAssetUnitPriceDenominator}`]:
163+
prices[position.trade.underlyingAssetSymbol.toLowerCase()][
164+
position.trade.underlyingAssetUnitPriceDenominator.toLowerCase()
165+
],
166+
}
167+
: {}),
163168
}),
164169
{},
165170
)

src/lib/utils/api/database.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,12 @@ export const mapQuoteToTrade = (
5252
})
5353

5454
const getUnderlyingAssetSymbol = (quote: Quote) => {
55-
const symbol = (quote.isMinting ? quote.outputToken : quote.inputToken).symbol
55+
const symbol = (
56+
quote.isMinting ? quote.outputToken : quote.inputToken
57+
).symbol.toUpperCase()
5658

57-
if (symbol.startsWith('ETH') || symbol.startsWith('iETH')) return 'ETH'
58-
if (symbol.startsWith('BTC') || symbol.startsWith('iBTC')) return 'BTC'
59+
if (symbol.startsWith('ETH') || symbol.startsWith('IETH')) return 'ETH'
60+
if (symbol.startsWith('BTC') || symbol.startsWith('IBTC')) return 'BTC'
5961
if (symbol.startsWith('WSTETH')) return 'WSTETH'
6062
if (symbol.startsWith('USUI')) return 'SUI'
6163
if (symbol.startsWith('USOL')) return 'SOL'

0 commit comments

Comments
 (0)