Skip to content

Commit a115097

Browse files
authored
feat: support dynamic balance text for asset input (aave#1349)
* feat: support dynamic balance text for asset input * chore: withdraw modal text * chore: use lt() method
1 parent 7e43fc0 commit a115097

File tree

11 files changed

+38
-3
lines changed

11 files changed

+38
-3
lines changed

src/components/transactions/AssetInput.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ export interface AssetInputProps<T extends Asset = Asset> {
7474
maxValue?: string;
7575
isMaxSelected?: boolean;
7676
inputTitle?: ReactNode;
77+
balanceText?: ReactNode; // Support translated text
7778
}
7879

7980
export const AssetInput = <T extends Asset = Asset>({
@@ -87,8 +88,9 @@ export const AssetInput = <T extends Asset = Asset>({
8788
assets,
8889
capType,
8990
maxValue,
90-
inputTitle,
9191
isMaxSelected,
92+
inputTitle,
93+
balanceText,
9294
}: AssetInputProps<T>) => {
9395
const handleSelect = (event: SelectChangeEvent) => {
9496
const newAsset = assets.find((asset) => asset.symbol === event.target.value) as T;
@@ -256,7 +258,7 @@ export const AssetInput = <T extends Asset = Asset>({
256258
{asset.balance && onChange && (
257259
<>
258260
<Typography component="div" variant="secondary12" color="text.secondary">
259-
<Trans>Balance</Trans>{' '}
261+
{balanceText && balanceText !== '' ? balanceText : <Trans>Balance</Trans>}{' '}
260262
<FormattedNumber
261263
value={asset.balance}
262264
compact

src/components/transactions/Borrow/BorrowModalContent.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ export const BorrowModalContent = ({
242242
capType={CapType.borrowCap}
243243
isMaxSelected={isMaxSelected}
244244
maxValue={maxAmountToBorrow.toString(10)}
245+
balanceText={<Trans>Available</Trans>}
245246
/>
246247

247248
{blockingError !== undefined && (

src/components/transactions/Repay/CollateralRepayModalContent.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ export function CollateralRepayModalContent({
200200
isMaxSelected={isMaxSelected}
201201
maxValue={debt}
202202
inputTitle={<Trans>Debt amount to repay</Trans>}
203+
balanceText={<Trans>Borrow balance</Trans>}
203204
/>
204205
<AssetInput
205206
value={inputAmount}
@@ -208,6 +209,7 @@ export function CollateralRepayModalContent({
208209
assets={repayTokens}
209210
onSelect={setTokenToRepayWith}
210211
inputTitle={<Trans>Collateral amount to repay with</Trans>}
212+
balanceText={<Trans>Borrow balance</Trans>}
211213
disableInput
212214
/>
213215
{blockingError !== undefined && (

src/components/transactions/Repay/RepayModalContent.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ export const RepayModalContent = ({
219219
onSelect={setTokenToRepayWith}
220220
isMaxSelected={isMaxSelected}
221221
maxValue={maxAmountToRepay.toString(10)}
222+
balanceText={<Trans>Wallet balance</Trans>}
222223
/>
223224

224225
{maxRepayWithDustRemaining && (

src/components/transactions/Stake/StakeModalContent.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ export const StakeModalContent = ({ stakeAssetName, icon }: StakeProps) => {
118118
]}
119119
isMaxSelected={isMaxSelected}
120120
maxValue={walletBalance.toString()}
121+
balanceText={<Trans>Wallet balance</Trans>}
121122
/>
122123
{blockingError !== undefined && (
123124
<Typography variant="helperText" color="red">

src/components/transactions/Supply/SupplyModalContent.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ export const SupplyModalContent = ({
241241
isMaxSelected={isMaxSelected}
242242
disabled={supplyTxState.loading}
243243
maxValue={maxAmountToSupply.toString(10)}
244+
balanceText={<Trans>Wallet balance</Trans>}
244245
/>
245246

246247
{blockingError !== undefined && (

src/components/transactions/Swap/SwapModalContent.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,13 +190,15 @@ export const SwapModalContent = ({
190190
]}
191191
maxValue={maxAmountToSwap}
192192
isMaxSelected={isMaxSelected}
193+
balanceText={<Trans>Supply balance</Trans>}
193194
/>
194195
<AssetInput
195196
value={outputAmount}
196197
onSelect={setTargetReserve}
197198
usdValue={outputAmountUSD}
198199
symbol={targetReserve.symbol}
199200
assets={swapTargets}
201+
balanceText={<Trans>Supply balance</Trans>}
200202
disableInput
201203
/>
202204
<Box

src/components/transactions/UnStake/UnStakeModalContent.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ export const UnStakeModalContent = ({ stakeAssetName, icon }: UnStakeProps) => {
115115
]}
116116
isMaxSelected={isMaxSelected}
117117
maxValue={walletBalance}
118+
balanceText={<Trans>Staking balance</Trans>}
118119
/>
119120
{blockingError !== undefined && (
120121
<Typography variant="helperText" color="red">

src/components/transactions/Withdraw/WithdrawModalContent.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,13 @@ export const WithdrawModalContent = ({
183183
isMaxSelected={isMaxSelected}
184184
disabled={withdrawTxState.loading}
185185
maxValue={maxAmountToWithdraw.toString(10)}
186+
balanceText={
187+
unborrowedLiquidity.lt(underlyingBalance) ? (
188+
<Trans>Available</Trans>
189+
) : (
190+
<Trans>Supply balance</Trans>
191+
)
192+
}
186193
/>
187194

188195
{blockingError !== undefined && (

src/locales/en/messages.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)