-
Notifications
You must be signed in to change notification settings - Fork 479
Expand file tree
/
Copy pathSuppliedPositionsListMobileItem.tsx
More file actions
159 lines (149 loc) · 5.2 KB
/
SuppliedPositionsListMobileItem.tsx
File metadata and controls
159 lines (149 loc) · 5.2 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
import { ProtocolAction } from '@aave/contract-helpers';
import { Trans } from '@lingui/macro';
import { Box, Button } from '@mui/material';
import { isHorizonMarket } from 'src/components/transactions/Swap/constants/shared.constants';
import { useAppDataContext } from 'src/hooks/app-data-provider/useAppDataProvider';
import { useAssetCaps } from 'src/hooks/useAssetCaps';
import { useRootStore } from 'src/store/root';
import { DashboardReserve } from 'src/utils/dashboardSortUtils';
import { showExternalIncentivesTooltip } from 'src/utils/utils';
import { useShallow } from 'zustand/shallow';
import { IncentivesCard } from '../../../../components/incentives/IncentivesCard';
import { Row } from '../../../../components/primitives/Row';
import { useModalContext } from '../../../../hooks/useModal';
import { isFeatureEnabled } from '../../../../utils/marketsAndNetworksConfig';
import { ListItemUsedAsCollateral } from '../ListItemUsedAsCollateral';
import { ListMobileItemWrapper } from '../ListMobileItemWrapper';
import { ListValueRow } from '../ListValueRow';
export const SuppliedPositionsListMobileItem = ({
reserve,
underlyingBalance,
underlyingBalanceUSD,
usageAsCollateralEnabledOnUser,
underlyingAsset,
}: DashboardReserve) => {
const { user } = useAppDataContext();
const [currentMarketData, currentMarket] = useRootStore(
useShallow((state) => [state.currentMarketData, state.currentMarket])
);
const { openSupply, openCollateralSwap, openWithdraw, openCollateralChange } = useModalContext();
const { debtCeiling } = useAssetCaps();
const isHorizon = isHorizonMarket(currentMarket);
const collateralSwapEnabledForReserve = !isHorizon || reserve.borrowingEnabled;
const isSwapButton =
isFeatureEnabled.liquiditySwap(currentMarketData) && collateralSwapEnabledForReserve;
const {
symbol,
iconSymbol,
name,
supplyAPY,
isIsolated,
aIncentivesData,
aTokenAddress,
isFrozen,
isActive,
isPaused,
} = reserve;
const canBeEnabledAsCollateral = user
? !debtCeiling.isMaxed &&
reserve.reserveLiquidationThreshold !== '0' &&
((!reserve.isIsolated && !user.isInIsolationMode) ||
user.isolatedReserve?.underlyingAsset === reserve.underlyingAsset ||
(reserve.isIsolated && user.totalCollateralMarketReferenceCurrency === '0'))
: false;
const disableSwap = !isActive || isPaused || reserve.symbol == 'stETH';
const disableWithdraw = !isActive || isPaused;
const disableSupply = !isActive || isFrozen || isPaused;
return (
<ListMobileItemWrapper
symbol={symbol}
iconSymbol={iconSymbol}
name={name}
underlyingAsset={underlyingAsset}
currentMarket={currentMarket}
frozen={reserve.isFrozen}
showSupplyCapTooltips
showDebtCeilingTooltips
showExternalIncentivesTooltips={showExternalIncentivesTooltip(
reserve.symbol,
currentMarket,
ProtocolAction.supply
)}
>
<ListValueRow
title={<Trans>Supply balance</Trans>}
value={Number(underlyingBalance)}
subValue={Number(underlyingBalanceUSD)}
disabled={Number(underlyingBalance) === 0}
/>
<Row
caption={<Trans>Supply APY</Trans>}
align="flex-start"
captionVariant="description"
mb={2}
>
<IncentivesCard
value={Number(supplyAPY)}
incentives={aIncentivesData}
address={aTokenAddress}
symbol={symbol}
variant="secondary14"
market={currentMarket}
protocolAction={ProtocolAction.supply}
/>
</Row>
<Row
caption={<Trans>Used as collateral</Trans>}
align={isIsolated ? 'flex-start' : 'center'}
captionVariant="description"
mb={2}
>
<ListItemUsedAsCollateral
disabled={reserve.isPaused}
isIsolated={isIsolated}
usageAsCollateralEnabledOnUser={usageAsCollateralEnabledOnUser}
canBeEnabledAsCollateral={canBeEnabledAsCollateral}
onToggleSwitch={() =>
openCollateralChange(
underlyingAsset,
currentMarket,
reserve.name,
'dashboard',
usageAsCollateralEnabledOnUser
)
}
/>
</Row>
<Box sx={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', mt: 5 }}>
{isSwapButton ? (
<Button
disabled={disableSwap}
variant="contained"
onClick={() => openCollateralSwap(underlyingAsset)}
fullWidth
>
<Trans>Swap</Trans>
</Button>
) : (
<Button
disabled={disableSupply}
variant="contained"
onClick={() => openSupply(underlyingAsset, currentMarket, reserve.name, 'dashboard')}
fullWidth
>
<Trans>Supply</Trans>
</Button>
)}
<Button
disabled={disableWithdraw}
variant="outlined"
onClick={() => openWithdraw(underlyingAsset, currentMarket, reserve.name, 'dashboard')}
sx={{ ml: 1.5 }}
fullWidth
>
<Trans>Withdraw</Trans>
</Button>
</Box>
</ListMobileItemWrapper>
);
};