Skip to content

Commit

Permalink
deposit modal fixes (#124)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sorizen authored Nov 18, 2024
1 parent 15c99c8 commit e4ca06b
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ const lblText = computed(() =>
: {
lbl: t('mainnet-deposit-modal-content.swap-lbl'),
text: t('mainnet-deposit-modal-content.swap-txt', {
asset: chosenAsset.value,
input: chosenAsset.value,
output: SWAP_ASSETS_NAMES.STETH,
}),
},
)
Expand Down
64 changes: 44 additions & 20 deletions src/common/modals/compositions/DepositModal/SwapStep.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,17 @@
:error-message="getFieldErrorMessage('amount')"
:disabled="isLoadFailed || !isLoaded"
@blur="touchField('amount')"
/>
>
<template #nodeRight>
<app-button
class="swap-step__input-btn"
scheme="link"
text="max"
:disabled="isLoadFailed || !isLoaded || !Number(userBalance)"
@click="inputMaxAmount"
/>
</template>
</input-field>
<div class="swap-step__desc-wrp">
<div class="swap-step__desc">
<span class="swap-step__desc-text">
Expand Down Expand Up @@ -62,7 +72,9 @@ import { ErrorHandler } from '@/helpers'
import { utils } from 'ethers'
import { AppButton } from '@/common'
import { config } from '@config'
import { parseUnits } from '@/utils'
const MIN_SWAP_AMOUNT = '0.001'
const PRECISION = 5
const emit = defineEmits<{
Expand Down Expand Up @@ -106,7 +118,7 @@ const { estimatedTokenOutAmount, estimatedGasCost, executeTrade } = useSwap(
const validationRules = computed(() => ({
amount: {
required,
minEther: minEther(0),
minEther: minEther(parseUnits(MIN_SWAP_AMOUNT, 'ether')),
...(userBalance.value && {
maxEther: maxEther(userBalance.value),
}),
Expand Down Expand Up @@ -147,33 +159,41 @@ const humanizeEtherValue = (number: string, symbol: string) =>
`${parseFloat(Number(number).toFixed(PRECISION))} ${symbol}`
const getUserBalance = async () => {
await web3ProvidersStore.provider.switchChain(ETHEREUM_CHAIN_IDS.ethereum)
const balance = await erc20Contract.value.providerBased.value.balanceOf(
web3ProvidersStore.address,
)
const tokenDecimals = await erc20Contract.value.providerBased.value.decimals()
userBalance.value = utils.formatUnits(
balance.toString(),
Number(tokenDecimals.toString()),
)
}
const inputMaxAmount = () => {
form.amount = userBalance.value
}
const submit = async () => {
isLoaded.value = false
isLoadFailed.value = false
try {
await web3ProvidersStore.provider.switchChain(ETHEREUM_CHAIN_IDS.ethereum)
const balance = await erc20Contract.value.providerBased.value.balanceOf(
web3ProvidersStore.address,
)
const tokenDecimals =
await erc20Contract.value.providerBased.value.decimals()
userBalance.value = utils.formatUnits(
balance.toString(),
Number(tokenDecimals.toString()),
)
await executeTrade()
emit('swap-success')
} catch (e) {
isLoadFailed.value = true
ErrorHandler.processWithoutFeedback(e)
ErrorHandler.process(e)
}
isLoaded.value = true
}
const submit = async () => {
const init = async () => {
isLoaded.value = false
isLoadFailed.value = false
try {
await executeTrade()
emit('swap-success')
await getUserBalance()
} catch (e) {
ErrorHandler.process(e)
isLoadFailed.value = true
ErrorHandler.processWithoutFeedback(e)
}
isLoaded.value = true
}
Expand All @@ -183,7 +203,7 @@ watch(
() => web3ProvidersStore.provider.chainId,
() => web3ProvidersStore.provider.selectedAddress,
],
getUserBalance,
init,
{
immediate: true,
},
Expand Down Expand Up @@ -249,4 +269,8 @@ watch(
.swap-step__button {
width: toRem(200);
}
.swap-step__input-btn {
@include body-3-semi-bold;
}
</style>
2 changes: 1 addition & 1 deletion src/localization/resources/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,7 @@
},
"mainnet-deposit-modal-content": {
"swap-lbl": "Step 1/2:",
"swap-txt": "Swap for {asset}",
"swap-txt": "Swap {input} for {output}",
"deposit-lbl": "Step 2/2",
"deposit-txt": "Deposit {asset}"
},
Expand Down

0 comments on commit e4ca06b

Please sign in to comment.