Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix report #1037

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
196 commits
Select commit Hold shift + click to select a range
573393d
aave page static components, mobile first
matzapata Aug 7, 2024
14aa7e5
responsive panels
matzapata Aug 8, 2024
c26c396
functional static borrow asset list
matzapata Aug 8, 2024
1ba0838
cleanup
matzapata Aug 8, 2024
c31694b
renaming
matzapata Aug 8, 2024
9678ceb
lend assets list
matzapata Aug 8, 2024
c67474f
Lend positions list
matzapata Aug 8, 2024
6813ccc
fixes and cleanup
matzapata Aug 8, 2024
ba90308
cleanup
matzapata Aug 8, 2024
e42e0e2
cleanup
matzapata Aug 8, 2024
bcc105c
cleanup
matzapata Aug 8, 2024
0c02b70
static ui done. missing validations
matzapata Aug 9, 2024
eecce08
add validations
matzapata Aug 9, 2024
23a9d44
add validations
matzapata Aug 9, 2024
d48a4b2
move errors down
matzapata Aug 9, 2024
dbbc38c
borrow form modal
matzapata Aug 9, 2024
c59d8f8
pr comments
matzapata Aug 9, 2024
2a84650
pr comments
matzapata Aug 9, 2024
d625ee6
fix typo
matzapata Aug 9, 2024
292ef14
Update apps/frontend/src/app/5_pages/AavePage/components/LendPosition…
matzapata Aug 9, 2024
87b4049
repay modals
matzapata Aug 9, 2024
8434d4b
Merge pull request #1 from wakeuplabs-io/static-ui-position-tables
matzapata Aug 9, 2024
babaf69
Merge pull request #2 from wakeuplabs-io/SAF-13_withdraw-components
matzapata Aug 9, 2024
760afe4
Merge branch 'develop' into SAF-15_repay-components
matzapata Aug 9, 2024
fe53d9f
Merge branch 'develop' into SAF-10_borrow-components
matzapata Aug 9, 2024
3f43631
lend modal
matzapata Aug 9, 2024
5fa3b69
Merge pull request #3 from wakeuplabs-io/SAF-10_borrow-components
matzapata Aug 12, 2024
2973255
Merge branch 'develop' into SAF-15_repay-components
matzapata Aug 12, 2024
0370d2e
Merge pull request #4 from wakeuplabs-io/SAF-15_repay-components
matzapata Aug 12, 2024
ad384c6
Merge pull request #5 from wakeuplabs-io/SAF-37_lend-components
matzapata Aug 12, 2024
f6c103d
use simple table row
matzapata Aug 12, 2024
aa1e9b9
asset amount input
matzapata Aug 12, 2024
1f6cec5
add missing translations
matzapata Aug 12, 2024
b935c06
fix translation
matzapata Aug 12, 2024
ff19631
units and prices mock
matzapata Aug 12, 2024
a8c6b6d
setup layout for pool details screen
matzapata Aug 12, 2024
5407531
Merge pull request #6 from wakeuplabs-io/SAF-36_cleanups
matzapata Aug 12, 2024
92c87f6
wallet overview panel
matzapata Aug 12, 2024
5aa4199
emode card mock
matzapata Aug 12, 2024
5b5f826
max with for emode category
matzapata Aug 12, 2024
5c0935a
Merge branch 'develop' into SAF-42_MockEmodeCard
matzapata Aug 12, 2024
45ab4c8
Merge pull request #9 from wakeuplabs-io/SAF-42_MockEmodeCard
matzapata Aug 12, 2024
8bdcea5
top bar mock
matzapata Aug 12, 2024
2df5d70
Merge pull request #10 from wakeuplabs-io/SAF-44_MockTopBar
matzapata Aug 13, 2024
f61ea42
network switch
matzapata Aug 13, 2024
6cf3a44
cleanup
matzapata Aug 13, 2024
a3cfaed
ui fixes
matzapata Aug 13, 2024
7fede62
ui fixes, usd prices
matzapata Aug 13, 2024
488223e
Efficiency card
matzapata Aug 13, 2024
bbfe45f
ordering
matzapata Aug 13, 2024
0a1a91e
fix filter 0 balances checkbox
matzapata Aug 13, 2024
cb76d67
pr comment
matzapata Aug 13, 2024
f0d549a
Merge pull request #11 from wakeuplabs-io/SAF-45_AutomaticSwicth
matzapata Aug 13, 2024
20b3aee
token
matzapata Aug 14, 2024
b0c20de
Merge pull request #13 from wakeuplabs-io/cleanup
matzapata Aug 14, 2024
5cab202
Mocked table cards plus refactor of statistics card (#14)
matzapata Aug 14, 2024
6946a5f
Saf 41 charts (#16)
luchopcerra Aug 19, 2024
8359dbb
removed view transactions button (out of scope)
chescalante Aug 20, 2024
dd23931
fix breakpoints
matzapata Aug 20, 2024
14878b4
[SAF-41] fix color constant and background for mobile vs desktop view…
luchopcerra Aug 20, 2024
704e86c
Dashboard pool data integration (#15) (#22)
matzapata Aug 20, 2024
ce56708
Lend integration (#19)
matzapata Aug 21, 2024
1f2ab87
Cache for aave hooks (#23)
matzapata Aug 22, 2024
e3d37b2
Develop mockups (#25)
luchopcerra Aug 23, 2024
ae64540
Withdraw integration (#21)
matzapata Aug 23, 2024
b960b79
Borrow integration (#24)
matzapata Aug 23, 2024
63767a6
Repay integration (#26)
matzapata Aug 26, 2024
b4f6b1c
implement collateral switch (#27)
matzapata Aug 26, 2024
6312a54
Cleanup (#28)
matzapata Aug 26, 2024
8a4b2ab
Update apps/frontend/package.json
matzapata Aug 27, 2024
2be1e51
Update apps/frontend/src/app/2_molecules/AmountTransition/AmountTrans…
matzapata Aug 27, 2024
6bb5809
Update apps/frontend/src/app/2_molecules/AssetAmountPriceRenderer/Ass…
matzapata Aug 27, 2024
76153dd
Update apps/frontend/src/app/2_molecules/NetworkSwitch/NetworkSwitch.tsx
matzapata Aug 27, 2024
987d265
Update apps/frontend/src/app/5_pages/AaveReserveOverviewPage/componen…
matzapata Aug 27, 2024
6f46c5f
Update apps/frontend/src/app/5_pages/AaveReserveOverviewPage/componen…
matzapata Aug 27, 2024
1cc3cc7
Update apps/frontend/src/app/5_pages/AaveReserveOverviewPage/componen…
matzapata Aug 27, 2024
a282895
Apply suggestions from code review
matzapata Aug 27, 2024
e916e33
remove LinkIcon
matzapata Aug 27, 2024
99c512e
Apply suggestions from code review
matzapata Aug 27, 2024
b927ea6
Apply suggestions from code review
matzapata Aug 27, 2024
55f38c9
Apply suggestions from code review
matzapata Aug 27, 2024
ab1ae57
pr comments
matzapata Aug 27, 2024
5f0f5b4
Merge branch 'develop-mockups-pr-comments' into develop-mockups
matzapata Aug 27, 2024
f8ad82d
Merge branch 'develop-mockups' into develop
matzapata Aug 28, 2024
c648b45
fixes
matzapata Aug 28, 2024
2d10454
Merge branch 'develop-mockups' into develop
matzapata Aug 28, 2024
2cf45e6
fixes
matzapata Aug 28, 2024
1769f6b
SAF-49 setup bob (#29)
matzapata Aug 29, 2024
9d02403
SAF 50 - E-Mode (#30)
matzapata Sep 3, 2024
b57d002
Toggle lend mode
matzapata Sep 3, 2024
de0cfa2
Fixes and cleanup (#33)
matzapata Sep 5, 2024
8deb00a
Fixes UI (#35)
matzapata Sep 5, 2024
faa3d5a
Saf 20/pool details integration topbar (#40)
matzapata Sep 5, 2024
d884245
Saf 20/pool details integration sidebar (#41)
matzapata Sep 5, 2024
7b72932
Saf 20/pool details integration graphs stats (#42)
matzapata Sep 6, 2024
8525737
Merge branch 'feat/aave' into develop
matzapata Sep 6, 2024
fe0ed74
fixes
matzapata Sep 6, 2024
5870b39
Saf 20/charts integration (exclude supply and borrow by now) (#46)
luchopcerra Sep 6, 2024
b137a7a
cleanup
matzapata Sep 6, 2024
8db5467
cleanup
matzapata Sep 6, 2024
292170e
fixes
matzapata Sep 6, 2024
2b0cbf6
fix: prevent NaN in interest rate charts when no data is retrieved
luchopcerra Sep 6, 2024
7b64c5e
fix stats
matzapata Sep 6, 2024
0e00afe
fix available liquidity
matzapata Sep 6, 2024
1b0a825
Update apps/frontend/src/app/5_pages/AavePage/components/LendAssetsLi…
matzapata Sep 6, 2024
f16fd71
Update apps/frontend/src/app/5_pages/AavePage/components/BorrowPositi…
matzapata Sep 6, 2024
f8a4b5f
Update apps/frontend/src/app/5_pages/AavePage/components/BorrowPositi…
matzapata Sep 6, 2024
c75aa34
Merge pull request #44 from wakeuplabs-io/develop
chescalante Sep 6, 2024
cde6014
coments
matzapata Sep 6, 2024
a6054bd
fix borrow power
matzapata Sep 9, 2024
b3b4764
fixes and cleanup
matzapata Sep 9, 2024
b58373a
Fixes and cleanup (#48)
matzapata Sep 9, 2024
60f93c2
cleanup
matzapata Sep 9, 2024
4064d8b
Cleanup (#49)
matzapata Sep 9, 2024
dd1df1f
refactor config for same code style and handle mainnet config
matzapata Sep 9, 2024
fb0a928
Merge branch 'feat/aave' into develop
matzapata Sep 9, 2024
28b105d
Refactor config for same code style and handle mainnet config (#50)
matzapata Sep 9, 2024
6968768
small fixes
matzapata Sep 9, 2024
c9256be
remove unused files and fix repay with balance future collateral ratio
matzapata Sep 9, 2024
19dafc9
Merge branch 'feat/aave' into develop
matzapata Sep 9, 2024
e48cb0c
remove unused files and fix repay with balance future collateral rati…
matzapata Sep 9, 2024
c2917c3
cleanup and fixes
matzapata Sep 9, 2024
47a41eb
disable collateral toggle if liquidation risk arises from it
matzapata Sep 9, 2024
97e840f
add sorting in tables
matzapata Sep 9, 2024
4ec8686
precision and percentage
matzapata Sep 9, 2024
83ae7f5
fix hex chainId
matzapata Sep 10, 2024
a497df3
fix chain id
matzapata Sep 10, 2024
cb7aabf
Apply suggestions from code review
matzapata Sep 11, 2024
0935773
rename USD to Usd
matzapata Sep 11, 2024
67fa6f0
pr comments
matzapata Sep 11, 2024
ba4e595
Update apps/frontend/src/app/5_pages/AaveReserveOverviewPage/componen…
matzapata Sep 11, 2024
8364324
pr comment
matzapata Sep 11, 2024
47deadf
disable tooltip for infinite
matzapata Sep 11, 2024
7d65cab
Merge branch 'feat/aave' into develop
matzapata Sep 11, 2024
132dfca
[SAF_20] integrate charts data and api (#47)
luchopcerra Sep 12, 2024
ecef760
Merge remote-tracking branch 'sovryn/feat/money-market' into develop
luchopcerra Sep 12, 2024
783e145
fix(ui): fix size of wallet card
juandahl Sep 12, 2024
38f6159
Merge pull request #54 from wakeuplabs-io/fix/wallet-card
juandahl Sep 12, 2024
549748a
Apply suggestions from code review
luchopcerra Sep 13, 2024
500fe4c
@pietro-maximoff suggestion applied: 'it doesn't need to be changed'
luchopcerra Sep 13, 2024
e9e53d5
fixes and improvements
matzapata Sep 13, 2024
f8fbe66
Qa fixes (#57)
matzapata Sep 20, 2024
1a5504d
remove % from health factor
matzapata Sep 20, 2024
918fc4a
fix: code improvements
juandahl Sep 23, 2024
ba64102
Merge pull request #58 from wakeuplabs-io/improvements/code
juandahl Sep 24, 2024
8b865d7
solving conflicts
juandahl Sep 24, 2024
a1f60f2
fix(borrow): use apy instead of apr and fix rounding numbers
juandahl Oct 2, 2024
ab293b5
fix: typo
juandahl Oct 2, 2024
10ba2df
Merge branch 'develop' into fix-borrow
juandahl Oct 2, 2024
3fb98d4
fix: add validations
juandahl Oct 3, 2024
cf4a014
Merge pull request #59 from wakeuplabs-io/fix-borrow
juandahl Oct 3, 2024
158c7db
fix: increase error factor for eth debts
juandahl Oct 3, 2024
208e497
fix: increase error factor for eth debts
juandahl Oct 3, 2024
9f72a68
Merge pull request #60 from wakeuplabs-io/fix-borrow
juandahl Oct 3, 2024
3954ba8
solving conflicts
juandahl Oct 3, 2024
44526ed
fix: use math utils
juandahl Oct 4, 2024
533779e
working earn aave history
matzapata Oct 10, 2024
f89dfa2
cleanup
matzapata Oct 10, 2024
3f5e453
new deployment
matzapata Oct 10, 2024
036fdbf
fix typo
matzapata Oct 10, 2024
ffd3a5f
fix maximum withdrawal
matzapata Oct 10, 2024
9223931
cleanup
matzapata Oct 10, 2024
355b2f5
withdraw everything if no borrows
matzapata Oct 10, 2024
1eef6bb
fix max borrow using health factor
matzapata Oct 13, 2024
552da81
new loan form
matzapata Oct 13, 2024
4dffdd4
Aave close with deposit
matzapata Oct 13, 2024
3c4f4e9
liquidations table
matzapata Oct 13, 2024
30c1fa7
swap rate mode
matzapata Oct 13, 2024
52e976a
add missing translation
matzapata Oct 13, 2024
1f635cb
cleanup
matzapata Oct 14, 2024
a8bb76d
cleanup
matzapata Oct 14, 2024
ff0928a
fix
matzapata Oct 14, 2024
866a835
add comment
matzapata Oct 14, 2024
5e2fbb9
cleanup
matzapata Oct 14, 2024
68363b0
fix
matzapata Oct 14, 2024
b1cee35
fix borrow text style
matzapata Oct 14, 2024
56f7e1a
rename `isMax` from `withdraw` to `withdrawAll` and update accordingly.
matzapata Oct 14, 2024
57dfca6
add cte for readability
matzapata Oct 14, 2024
490dcfd
cleanup
matzapata Oct 14, 2024
84981fe
Merge pull request #61 from wakeuplabs-io/history
juandahl Oct 14, 2024
b37a6c5
Merge pull request #63 from wakeuplabs-io/qa-fixes-2-max-borrow
juandahl Oct 14, 2024
f45c7bf
fix: solving conflicts
juandahl Oct 14, 2024
5241582
Merge pull request #62 from wakeuplabs-io/qa-fixes-2
juandahl Oct 14, 2024
924c1cc
Merge remote-tracking branch 'upstream/feat/money-market' into develop
juandahl Oct 15, 2024
72e9f88
add missing apy value
juandahl Oct 16, 2024
9b08d7c
feat(HF): change collateral ratio by health factor
juandahl Oct 17, 2024
87a2648
fix(graphs): improve precission and add go back button
juandahl Oct 17, 2024
8ac128e
Merge pull request #64 from wakeuplabs-io/feat/HF
juandahl Oct 18, 2024
4e0b0aa
fix: add tokens to wallet
juandahl Oct 18, 2024
c397ce4
Merge pull request #65 from wakeuplabs-io/fix/wallet
juandahl Oct 18, 2024
28d5876
Update apps/frontend/.env.example
juandahl Oct 22, 2024
82b8593
Update apps/frontend/src/app/3_organisms/EarnHistoryFrame/components/…
juandahl Oct 22, 2024
8e725a7
add translations
juandahl Oct 22, 2024
01f7416
solving conflicts
juandahl Oct 22, 2024
336279b
fix: add more timeframes
juandahl Oct 22, 2024
e228be9
Merge pull request #66 from wakeuplabs-io/fix/report
juandahl Oct 23, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions apps/frontend/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,5 @@ REACT_APP_SIMULATE_TX=false
REACT_APP_ESTIMATOR_URI=https://simulator.sovryn.app

REACT_APP_DATADOG_CLIENT_TOKEN=

REACT_APP_GRAPH_BOB_AAVE=https://bob-mm.test.sovryn.app/subgraphs/name/DistributedCollective/subgraph-template
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ export const COLUMNS = [
},
{
id: 'interestRate',
title: 'Interest Rate',
title: t(translations.loanHistory.table.interestRate),
cellRenderer: (tx: NewBorrowHistoryItem) => (
<AmountRenderer value={tx.borrowRate} precision={2} suffix="%" />
),
},
{
id: 'interestRateMode',
title: 'Interest Rate Mode',
title: t(translations.loanHistory.table.interestRateMode),
cellRenderer: (tx: NewBorrowHistoryItem) => (
<span>{tx.borrowRateMode}</span>
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const normalizeUserLiquidationTransactions = (
],
),
to:
tx.borrowRateModeTo === BorrowRateMode.STABLE ? 'Stable' : 'Variable',
tx.borrowRateModeTo === BorrowRateMode.STABLE ? 'stable' : 'variable',
timestamp: tx.timestamp,
hash: tx.txHash,
variableBorrowRate: Decimal.from(tx.variableBorrowRate)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export const COLUMNS_CONFIG = [
showRoundingPrefix
/>
) : (
<span>{t(translations.common.na)} </span>
<span>{t(translations.common.na)}</span>
)}
{item.reserve.symbol}
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { FC, useCallback, useMemo, useState } from 'react';
import React, { FC, useCallback, useEffect, useMemo, useState } from 'react';

import { t } from 'i18next';

Expand All @@ -19,7 +19,7 @@ import { BOB_CHAIN_ID } from '../../../../../../../config/chains';
import { AmountRenderer } from '../../../../../../2_molecules/AmountRenderer/AmountRenderer';
import { AssetAmountInput } from '../../../../../../2_molecules/AssetAmountInput/AssetAmountInput';
import { AssetRenderer } from '../../../../../../2_molecules/AssetRenderer/AssetRenderer';
import { MINIMUM_COLLATERAL_RATIO_LENDING_POOLS_AAVE } from '../../../../../../../constants/aave';
import { MINIMUM_HEALTH_FACTOR } from '../../../../../../../constants/aave';
import { useAaveBorrow } from '../../../../../../../hooks/aave/useAaveBorrow';
import { useAaveUserReservesData } from '../../../../../../../hooks/aave/useAaveUserReservesData';
import { useDecimalAmountInput } from '../../../../../../../hooks/useDecimalAmountInput';
Expand Down Expand Up @@ -68,6 +68,17 @@ export const BorrowForm: FC<BorrowFormProps> = ({ asset, onComplete }) => {
[summary.reserves, borrowAsset],
);

useEffect(() => {
// if borrow size is greater than available to borrow, set borrow amount to available to borrow
// this is to prevent users from borrowing more than they can even if maximum gets updated
const isBorrowBiggerThanAvailable = borrowSize.gt(
borrowReserve?.availableToBorrow ?? 0,
);
if (isBorrowBiggerThanAvailable) {
setBorrowAmount(borrowReserve?.availableToBorrow.toString() ?? '0');
}
}, [borrowReserve?.availableToBorrow, borrowSize, setBorrowAmount]);

const borrowUsdAmount = useMemo(
() => borrowSize.mul(borrowReserve?.reserve.priceInUSD ?? 0),
[borrowSize, borrowReserve?.reserve.priceInUSD],
Expand All @@ -80,11 +91,17 @@ export const BorrowForm: FC<BorrowFormProps> = ({ asset, onComplete }) => {

const newCollateralRatio = useMemo(
() =>
AaveCalculations.computeCollateralRatio(
AaveCalculations.computeHealthFactor(
summary.collateralBalance,
summary.currentLiquidationThreshold,
summary.borrowBalance.add(borrowUsdAmount),
),
[summary.collateralBalance, summary.borrowBalance, borrowUsdAmount],
[
summary.collateralBalance,
summary.currentLiquidationThreshold,
summary.borrowBalance,
borrowUsdAmount,
],
);

const liquidationPrice = useMemo(
Expand Down Expand Up @@ -166,7 +183,7 @@ export const BorrowForm: FC<BorrowFormProps> = ({ asset, onComplete }) => {

<CollateralRatioHealthBar
ratio={Decimal.from(newCollateralRatio)}
minimum={MINIMUM_COLLATERAL_RATIO_LENDING_POOLS_AAVE}
minimum={MINIMUM_HEALTH_FACTOR}
/>

<SimpleTable>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ export const BorrowPositionsList: FC<BorrowPositionsListProps> = ({
orderOptions={orderOptions}
setOrderOptions={setOrderOptions}
noData={
<span className="text-gray-30 text-sm lg:text-white">
<span className="text-gray-30 text-xs italic lg:text-white">
{t(pageTranslations.borrowPositionsList.noData)}
</span>
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,9 @@ export const BorrowRateModeSelect: FC<BorrowRateModeSelectProps> = ({
const options = useMemo(() => {
const borrowRateModeOptions = [
{
label: t(
translations.aavePage.borrowPositionsList.selectVariableApy,
{},
),
label: t(translations.aavePage.borrowPositionsList.selectVariableApy, {
apy: formatValue(position.variableApy, 2),
}),
value: String(BorrowRateMode.VARIABLE),
},
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ export const getCollateralRatioThresholds = (minimum: Decimal) => {
const minimumCollateralRatio = minimum.mul(100);

return {
START: minimumCollateralRatio.mul(0.9).toNumber(),
START: 100,
MIDDLE_START: minimumCollateralRatio.toNumber() - 0.1,
MIDDLE_END: minimumCollateralRatio.mul(1.2).toNumber(),
END: minimumCollateralRatio.mul(1.6).toNumber(),
MIDDLE_END: minimumCollateralRatio.mul(1.5).toNumber(),
END: minimumCollateralRatio.mul(2).toNumber(),
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ export const LendPositionsList: FC<LendPositionsListProps> = ({
orderOptions={orderOptions}
setOrderOptions={setOrderOptions}
noData={
<span className="text-gray-30 text-sm lg:text-white">
<span className="text-gray-30 text-xs italic lg:text-white">
{t(pageTranslations.lendPositionsList.noData)}
</span>
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { FC, useCallback, useMemo, useState } from 'react';
import React, { FC, useCallback, useEffect, useMemo, useState } from 'react';

import { t } from 'i18next';

Expand All @@ -19,7 +19,7 @@ import { BOB_CHAIN_ID } from '../../../../../../../config/chains';
import { AmountRenderer } from '../../../../../../2_molecules/AmountRenderer/AmountRenderer';
import { AssetAmountInput } from '../../../../../../2_molecules/AssetAmountInput/AssetAmountInput';
import { AssetRenderer } from '../../../../../../2_molecules/AssetRenderer/AssetRenderer';
import { MINIMUM_COLLATERAL_RATIO_LENDING_POOLS_AAVE } from '../../../../../../../constants/aave';
import { MINIMUM_HEALTH_FACTOR } from '../../../../../../../constants/aave';
import { useAaveUserReservesData } from '../../../../../../../hooks/aave/useAaveUserReservesData';
import { useAaveWithdraw } from '../../../../../../../hooks/aave/useAaveWithdraw';
import { useDecimalAmountInput } from '../../../../../../../hooks/useDecimalAmountInput';
Expand Down Expand Up @@ -84,16 +84,25 @@ export const WithdrawForm: FC<WithdrawFormProps> = ({ asset, onComplete }) => {
return Decimal.from(0);
}

if (summary.borrowBalance.eq(0)) {
return withdrawReserve.supplied;
}

// min collateral at which we reach minimum collateral ratio
const minCollateralUsd = MINIMUM_COLLATERAL_RATIO_LENDING_POOLS_AAVE.mul(
withdrawReserve.borrowedUsd,
const minCollateralUsd = MINIMUM_HEALTH_FACTOR.mul(
summary.borrowBalance.div(summary.currentLiquidationThreshold),
);
const maxUsdWithdrawal = summary.supplyBalance.sub(minCollateralUsd);

return maxUsdWithdrawal.gt(withdrawReserve.suppliedUsd)
? withdrawReserve.supplied // we can withdraw all, we'll still have collateral on other asset
: maxUsdWithdrawal.div(withdrawReserve.reserve.priceInUSD); // only partial withdraw
}, [withdrawReserve, summary.supplyBalance]);
}, [
withdrawReserve,
summary.supplyBalance,
summary.borrowBalance,
summary.currentLiquidationThreshold,
]);

const withdrawAmountUsd = useMemo(
() => withdrawSize.mul(withdrawReserve?.reserve.priceInUSD ?? 0),
Expand All @@ -105,6 +114,14 @@ export const WithdrawForm: FC<WithdrawFormProps> = ({ asset, onComplete }) => {
[withdrawSize, withdrawReserve?.supplied],
);

useEffect(() => {
// if withdraw size is greater than maximum, set withdraw amount to maximum possible
// this is to prevent users from trying to withdraw more than they can even if maximum gets updated
if (withdrawSize.gt(maximumWithdrawAmount)) {
setWithdrawAmount(maximumWithdrawAmount.toString());
}
}, [withdrawSize, maximumWithdrawAmount, setWithdrawAmount]);

const [isValidWithdrawAmount, errorMessage] = useMemo(() => {
if (withdrawSize.eq(0)) {
return [true, ''];
Expand Down Expand Up @@ -135,19 +152,10 @@ export const WithdrawForm: FC<WithdrawFormProps> = ({ asset, onComplete }) => {

const onConfirm = useCallback(
() =>
handleWithdraw(
withdrawSize,
withdrawAsset,
withdrawSize.eq(maximumWithdrawAmount),
{ onComplete },
),
[
handleWithdraw,
withdrawSize,
withdrawAsset,
onComplete,
maximumWithdrawAmount,
],
handleWithdraw(withdrawSize, withdrawAsset, remainingSupply.eq(0), {
onComplete,
}),
[handleWithdraw, withdrawSize, withdrawAsset, onComplete, remainingSupply],
);

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ export const BorrowDetailsGraph: FC<BorrowDetailsGraphProps> = ({
[history],
);

if (!reserve.borrowingEnabled) {
return null;
}

return (
<Accordion
label={
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export const InterestRateModelGraph: FC<InterestRateModelGraphProps> = ({
[reserve.borrowUsageRatio],
);

if (!rates) {
if (!rates || !reserve.borrowingEnabled) {
return null;
}
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { theme } from '@sovryn/tailwindcss-config';

export const GRID_COLOR = '#484d59';
export const TICK_COLOR = '#b6bac1';
export const CHART_PERCENTAGES = [0, 0.25, 0.5, 0.75, 1];

const SM_BREAKPOINT = parseInt(theme.screens.sm, 10) || 576;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import 'chartjs-adapter-date-fns';
import { theme } from '@sovryn/tailwindcss-config';

import {
CHART_PERCENTAGES,
CUSTOM_CANVAS_BACKGROUND_COLOR,
GRID_COLOR,
TICK_COLOR,
} from './Chart.constants';
import { RatesData } from './Chart.types';
import {
calculateVariableInterestRateModel,
generatePercentages,
htmlLegendPlugin,
} from './Chart.utils';

Expand All @@ -31,7 +31,7 @@ export const Chart: FC<ChartProps> = ({ meta, rates }) => {

const variableValues = useMemo(
() =>
CHART_PERCENTAGES.map(x => ({
generatePercentages().map(x => ({
x: x * 100,
y: calculateVariableInterestRateModel(x, rates).mul(100).toNumber(),
})),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ const getOrCreateLegendList = (id: string) => {
return listContainer;
};

export const generatePercentages = (step: number = 0.05) => {
return Array.from({ length: Math.floor(1 / step) + 1 }, (_, i) => i * step);
};

export const htmlLegendPlugin = {
id: 'htmlLegend',
afterUpdate(chart, args, options) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,16 @@ export const SupplyDetailsGraph: FC<SupplyDetailsGraphProps> = ({
/>
</div>

<Chart
input={{
data: supplyChartData,
label: t(pageTranslations.chart.suppApr),
lineColor: theme.colors['primary-30'],
}}
onTimeRangeChange={setTimeRange}
/>
{reserve.borrowingEnabled && (
<Chart
input={{
data: supplyChartData,
label: t(pageTranslations.chart.suppApr),
lineColor: theme.colors['primary-30'],
}}
onTimeRangeChange={setTimeRange}
/>
)}

<div className="space-y-6">
{/* collateral usage */}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,26 @@ export const TimeRangeButtons: FC<TimeRangeButtonsProps> = ({ onChange }) => {

return (
<div className="flex space-x-2 justify-end mb-4">
{' '}
<button
className={`py-1.5 px-4 rounded-md text-sm font-medium ${
activeRange === ESupportedTimeRanges.OneDay
? 'bg-gray-50 text-white'
: 'bg-gray-70 text-gray-400'
}`}
onClick={() => handleClick(ESupportedTimeRanges.OneDay)}
>
{ESupportedTimeRanges.OneDay}
</button>
<button
className={`py-1.5 px-4 rounded-md text-sm font-medium ${
activeRange === ESupportedTimeRanges.OneWeek
? 'bg-gray-50 text-white'
: 'bg-gray-70 text-gray-400'
}`}
onClick={() => handleClick(ESupportedTimeRanges.OneWeek)}
>
{ESupportedTimeRanges.OneWeek}
</button>
<button
className={`py-1.5 px-4 rounded-md text-sm font-medium ${
activeRange === ESupportedTimeRanges.OneMonth
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { Decimal } from '@sovryn/utils';

import { BOB_CHAIN_ID } from '../../../../../config/chains';

import { GoBackButton } from '../../../../1_atoms/GoBackButton/GoBackButton';
import { WalletIcon } from '../../../../1_atoms/Icons/Icons';
import { AmountRenderer } from '../../../../2_molecules/AmountRenderer/AmountRenderer';
import { AssetRenderer } from '../../../../2_molecules/AssetRenderer/AssetRenderer';
Expand Down Expand Up @@ -57,6 +58,10 @@ export const TopPanel: FC<TopPanelProps> = ({ reserve, className }) => {
window.open(`${explorer}/address/${tokenAddress}`, '_blank');
}, []);

const goBack = useCallback(() => {
window.history.back();
}, []);

const oracleLink = useMemo(
() => getBobExplorerUrl() + '/address/' + reserve.priceOracle,
[reserve.priceOracle],
Expand All @@ -80,6 +85,10 @@ export const TopPanel: FC<TopPanelProps> = ({ reserve, className }) => {

<div className="gap-6 lg:gap-9 flex-shrink-0 grid grid-cols-2 lg:flex">
<div className="col-span-2 flex items-center lg:items-start gap-3">
<div className="flex items-center gap-3 h-8">
<GoBackButton onClick={goBack} />
</div>

<div className="flex items-center gap-1">
<AssetRenderer
asset={reserve.symbol}
Expand Down
Loading