Skip to content

Commit

Permalink
fix: update usage after owm refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielSchiavini committed Oct 8, 2024
1 parent f3f657b commit 1980bae
Show file tree
Hide file tree
Showing 29 changed files with 174 additions and 188 deletions.
14 changes: 7 additions & 7 deletions apps/lend/src/components/DetailInfoHealth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const DetailInfoHealth = ({
loading: boolean
setHealthMode: React.Dispatch<React.SetStateAction<HealthMode>>
}) => {
const owmData = useOneWayMarket(rChainId, rOwmId)?.data
const market = useOneWayMarket(rChainId, rOwmId)?.data
const oraclePriceBand = useStore((state) => state.markets.pricesMapper[rChainId]?.[rOwmId]?.prices?.oraclePriceBand)
const userLoanDetails = useStore((state) => state.user.loansDetailsMapper[userActiveKey]?.details)

Expand All @@ -58,7 +58,7 @@ const DetailInfoHealth = ({
if (typeof oraclePriceBand === 'number' && healthFull) {
setHealthMode(
getHealthMode(
owmData,
market,
oraclePriceBand,
amount,
bands,
Expand All @@ -79,7 +79,7 @@ const DetailInfoHealth = ({
formType,
healthFull,
newHealthModeColorKey,
owmData,
market,
setHealthMode,
])

Expand All @@ -88,10 +88,10 @@ const DetailInfoHealth = ({
if (typeof oraclePriceBand === 'number' && userLoanDetails) {
const { healthFull, bands } = userLoanDetails
setCurrentHealthMode(
getHealthMode(owmData, oraclePriceBand, amount, bands, formType, healthFull, '', newHealthModeColorKey)
getHealthMode(market, oraclePriceBand, amount, bands, formType, healthFull, '', newHealthModeColorKey)
)
}
}, [oraclePriceBand, amount, formType, newHealthModeColorKey, owmData, userLoanDetails])
}, [oraclePriceBand, amount, formType, newHealthModeColorKey, market, userLoanDetails])

const healthPercent = useMemo(() => {
if (healthMode.percent) {
Expand Down Expand Up @@ -153,7 +153,7 @@ export default DetailInfoHealth
// 1. If health(full=true) < loan_discount, user is at risk to go from healthy mode to soft liquidation mode (green —> orange).
// 2. If health(full=false) < liquidation_discount , user is at risk to go from soft liquidation mode to hard liquidation mode (orange —> red).
export function getHealthMode(
owmData: OneWayMarketTemplate | undefined,
market: OneWayMarketTemplate | undefined,
oraclePriceBand: number | null,
amount: string,
bands: [number, number] | number[],
Expand All @@ -179,7 +179,7 @@ export function getHealthMode(
message = t`You are still close to soft liquidation.`
} else if (newColorKey === 'close_to_liquidation') {
const formattedAmount = formatNumber(amount)
const borrowedToken = owmData?.borrowed_token?.symbol
const borrowedToken = market?.borrowed_token?.symbol
if (formType === 'collateral-decrease') {
message = t`Removing ${formattedAmount} collateral, will put you close to soft liquidation.`
} else if (formType === 'create-loan') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ import ChartOhlcWrapper from '@/components/ChartOhlcWrapper'
import ListInfoItem, { ListInfoItems, ListInfoItemsWrapper } from '@/ui/ListInfo'

const DetailsLoan = ({ type, ...pageProps }: PageContentProps & { type: MarketListType }) => {
const { rChainId, rOwmId, owmDataCachedOrApi, borrowed_token, collateral_token, titleMapper, userActiveKey } =
const { rChainId, rOwmId, market, titleMapper, userActiveKey } =
pageProps
const chartExpanded = useStore((state) => state.ohlcCharts.chartExpanded)

const cellProps = {
rChainId,
rOwmId,
owmDataCachedOrApi,
market,
size: 'md' as const,
}

Expand Down Expand Up @@ -73,18 +73,15 @@ const DetailsLoan = ({ type, ...pageProps }: PageContentProps & { type: MarketLi
<DetailsLoanChartBalances
rChainId={rChainId}
rOwmId={rOwmId}
borrowed_token={borrowed_token}
collateral_token={collateral_token}
market={market}
/>
</ContentWrapper>

<Wrapper>
<ContentWrapper paddingTop>
<DetailsContracts
rChainId={rChainId}
owmDataCachedOrApi={owmDataCachedOrApi}
borrowed_token={borrowed_token}
collateral_token={collateral_token}
market={market}
type={type}
/>
</ContentWrapper>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ import ListInfoItem, { ListInfoItems, ListInfoItemsWrapper } from '@/ui/ListInfo
import MarketParameters from '@/components/DetailsMarket/components/MarketParameters'

const DetailsSupply = ({ type, ...pageProps }: PageContentProps & { type: MarketListType }) => {
const { rChainId, rOwmId, owmDataCachedOrApi, borrowed_token, collateral_token, titleMapper } = pageProps
const { rChainId, rOwmId, market, titleMapper } = pageProps

const cellProps = {
rChainId,
rOwmId,
owmDataCachedOrApi,
market,
size: 'md' as const,
}

Expand Down Expand Up @@ -63,9 +63,7 @@ const DetailsSupply = ({ type, ...pageProps }: PageContentProps & { type: Market
<div>
<DetailsContracts
rChainId={rChainId}
owmDataCachedOrApi={owmDataCachedOrApi}
borrowed_token={borrowed_token}
collateral_token={collateral_token}
market={market}
type={type}
/>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import ChartOhlcWrapper from '@/components/ChartOhlcWrapper'
import ListInfoItem, { ListInfoItems, ListInfoItemsWrapper } from '@/ui/ListInfo'

const DetailsUserLoan = (pageProps: PageContentProps) => {
const { rChainId, rOwmId, api, owmDataCachedOrApi, titleMapper, userActiveKey } = pageProps
const { rChainId, rOwmId, api, market, titleMapper, userActiveKey } = pageProps

const isAdvanceMode = useStore((state) => state.isAdvanceMode)
const loanExistsResp = useStore((state) => state.user.loansExistsMapper[userActiveKey])
Expand All @@ -43,7 +43,7 @@ const DetailsUserLoan = (pageProps: PageContentProps) => {
rChainId,
rOwmId,
isBold: true,
owmDataCachedOrApi,
market: market!,
userActiveKey,
size: 'md' as const,
}
Expand Down Expand Up @@ -83,20 +83,17 @@ const DetailsUserLoan = (pageProps: PageContentProps) => {

<ContentWrapper paddingTop isBorderBottom>
<StatsWrapper>
<CellUserMain {...pageProps} type="borrow" />
<CellUserMain {...pageProps} market={market!} type="borrow" />

{/* stats */}
<ListInfoItemsWrapper>
{contents.map((groupedContents, idx) => (
<ListInfoItems key={`contents${idx}`}>
{groupedContents.map(({ titleKey, content, show, ...props }, idx) => {
if (!_showContent(show)) return null
return (
<ListInfoItem key={`content${idx}`} {...titleMapper[titleKey]}>
{content}
</ListInfoItem>
)
})}
{groupedContents.filter(({show}) => _showContent(show)).map(({ titleKey, content }, idx) => (
<ListInfoItem key={`content${idx}`} {...titleMapper[titleKey]}>
{content}
</ListInfoItem>
))}
</ListInfoItems>
))}
</ListInfoItemsWrapper>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import AlertBox from '@/ui/AlertBox'
import Box from '@/ui/Box'
import ExternalLink from '@/ui/Link/ExternalLink'

const DetailsUserLoanAlertSoftLiquidation = ({ borrowed_token, collateral_token, userActiveKey }: PageContentProps) => {
const DetailsUserLoanAlertSoftLiquidation = ({ market, userActiveKey }: PageContentProps) => {
const {borrowed_token, collateral_token} = market ?? {}
const userLoanDetails = useStore((state) => state.user.loansDetailsMapper[userActiveKey])

// TODO handle error
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import DetailsUserSupplyStakedUnstaked from '@/components/DetailsUser/components
import ListInfoItem, { ListInfoItems, ListInfoItemsWrapper } from '@/ui/ListInfo'

const DetailsUserSupply = (pageProps: PageContentProps) => {
const { rChainId, rOwmId, api, userActiveKey, owmDataCachedOrApi, titleMapper } = pageProps
const { rChainId, rOwmId, api, userActiveKey, market, titleMapper } = pageProps

const userBalancesResp = useStore((state) => state.user.marketsBalancesMapper[userActiveKey])

Expand All @@ -28,7 +28,7 @@ const DetailsUserSupply = (pageProps: PageContentProps) => {
rChainId,
rOwmId,
isBold: true,
owmDataCachedOrApi,
market,
userActiveKey,
size: 'md' as const,
}
Expand All @@ -50,7 +50,7 @@ const DetailsUserSupply = (pageProps: PageContentProps) => {
) : foundVaultShares ? (
<ContentWrapper paddingTop>
<Wrapper>
<CellUserMain {...pageProps} type="supply" />
<CellUserMain {...pageProps} market={market!} type="supply" />

{/* stats */}
<ListInfoItemsWrapper>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { LiqRangeSliderIdx } from '@/store/types'
import type { DetailInfoCompProps, DetailInfoCompAdditionalProps } from '@/components/PageLoanCreate/types'
import type { DetailInfoCompAdditionalProps, DetailInfoCompProps } from '@/components/PageLoanCreate/types'

import React, { useMemo } from 'react'

Expand All @@ -10,11 +10,9 @@ import DetailInfoNonLeverage from '@/components/PageLoanCreate/LoanFormCreate/co
import DetailInfoLeverage from '@/components/PageLoanCreate/LoanFormCreate/components/DetailInfoLeverage'

const DetailInfoComp = ({ isLeverage, ...props }: PageContentProps & DetailInfoCompProps & { isLeverage: boolean }) => {
const { api, owmData, steps, updateFormValues } = props
const { api, market, steps, updateFormValues } = props

const { signerAddress } = api ?? {}
const { owm } = owmData ?? {}

const activeKeyLiqRange = useStore((state) => state.loanCreate.activeKeyLiqRange)
const formValues = useStore((state) => state.loanCreate.formValues)
const isEditLiqRange = useStore((state) => state.loanCreate.isEditLiqRange)
Expand All @@ -26,12 +24,12 @@ const DetailInfoComp = ({ isLeverage, ...props }: PageContentProps & DetailInfoC
const selectedLiqRange = useMemo(() => {
if (formValues.n && liqRanges) {
return liqRanges[formValues.n]
} else if (owm) {
return { n: owm.defaultBands } as LiqRangeSliderIdx
} else if (market) {
return { n: market.defaultBands } as LiqRangeSliderIdx
} else {
return undefined
}
}, [formValues.n, liqRanges, owm])
}, [formValues.n, liqRanges, market])

const handleLiqRangesEdit = () => {
const showEditLiqRange = !isEditLiqRange
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,8 @@ const DetailInfoLeverage = ({
api,
healthMode,
isLoaded,
owm,
market,
steps,
borrowed_token,
collateral_token,
userActiveKey,
handleSelLiqRange,
selectedLiqRange,
Expand All @@ -49,7 +47,7 @@ const DetailInfoLeverage = ({
const maxSlippage = useStore((state) => state.maxSlippage)

const { signerAddress } = api ?? {}
const { minBands, maxBands } = owm ?? {}
const { minBands, maxBands, borrowed_token, collateral_token } = market ?? {}
const { expectedCollateral, routes } = detailInfo ?? {}
const { userBorrowed, debt } = formValues
const { symbol: collateralSymbol = '' } = collateral_token ?? {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,9 @@ const DetailInfoNonLeverage = ({
rChainId,
rOwmId,
api,
borrowed_token,
collateral_token,
healthMode,
isLoaded,
owm,
market,
steps,
userActiveKey,
handleSelLiqRange,
Expand All @@ -39,6 +37,7 @@ const DetailInfoNonLeverage = ({
const liqRanges = useStore((state) => state.loanCreate.liqRanges[activeKeyLiqRange])

const { signerAddress } = api ?? {}
const { borrowed_token, collateral_token } = market ?? {}

const loading = !isLoaded || typeof detailInfo === 'undefined'

Expand All @@ -60,8 +59,8 @@ const DetailInfoNonLeverage = ({
<DetailInfoLiqRangeEdit
{...detailInfo}
liqRanges={liqRanges}
maxBands={owm?.maxBands}
minBands={owm?.minBands}
maxBands={market?.maxBands}
minBands={market?.minBands}
selectedLiqRange={selectedLiqRange}
showEditLiqRange={isEditLiqRange}
handleSelLiqRange={handleSelLiqRange}
Expand All @@ -79,7 +78,7 @@ const DetailInfoNonLeverage = ({
setHealthMode={setHealthMode}
userActiveKey={userActiveKey}
/>
<DetailInfoRate isBorrow rChainId={rChainId} rOwmId={rOwmId} futureRates={detailInfo?.futureRates} />
<DetailInfoRate isBorrow={true} rChainId={rChainId} rOwmId={rOwmId} futureRates={detailInfo?.futureRates} />
{isAdvanceMode && (
<DetailInfoLTV
loading={loading}
Expand Down
Loading

0 comments on commit 1980bae

Please sign in to comment.