Mp 3192 disable inputs on transaction initialization (#326)

* feat: inputs are disabled on swap form when executing the transaction

* feat: disabled borrow, lend, vault, deposit, withdraw form inputs when executing transaction
This commit is contained in:
Yusuf Seyrek 2023-07-31 10:57:38 +03:00 committed by GitHub
parent 1eec100907
commit 2611291028
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 46 additions and 23 deletions

View File

@ -17,9 +17,9 @@ interface Props {
asset: Asset asset: Asset
title: string title: string
coinBalances: Coin[] coinBalances: Coin[]
contentHeader?: JSX.Element
actionButtonText: string actionButtonText: string
showLoaderInButton: boolean contentHeader?: JSX.Element
showProgressIndicator: boolean
accountSummaryChange?: AccountChange accountSummaryChange?: AccountChange
onClose: () => void onClose: () => void
onChange: (value: BigNumber) => void onChange: (value: BigNumber) => void
@ -31,10 +31,10 @@ export default function AssetAmountSelectActionModal(props: Props) {
asset, asset,
title, title,
coinBalances, coinBalances,
contentHeader = null,
actionButtonText, actionButtonText,
showLoaderInButton,
accountSummaryChange, accountSummaryChange,
contentHeader = null,
showProgressIndicator,
onClose, onClose,
onChange, onChange,
onAction, onAction,
@ -79,11 +79,12 @@ export default function AssetAmountSelectActionModal(props: Props) {
max={maxAmount} max={maxAmount}
hasSelect hasSelect
maxText='Max' maxText='Max'
disabled={showProgressIndicator}
/> />
<Divider /> <Divider />
<Button <Button
onClick={handleActionClick} onClick={handleActionClick}
showProgressIndicator={showLoaderInButton} showProgressIndicator={showProgressIndicator}
disabled={!amount.toNumber()} disabled={!amount.toNumber()}
className='w-full' className='w-full'
text={actionButtonText} text={actionButtonText}

View File

@ -186,6 +186,7 @@ function BorrowModal(props: Props) {
max={max} max={max}
className='w-full' className='w-full'
maxText='Max' maxText='Max'
disabled={isConfirming}
/> />
<Divider className='my-6' /> <Divider className='my-6' />
<div className='flex flex-1 flex-wrap'> <div className='flex flex-1 flex-wrap'>
@ -199,6 +200,7 @@ function BorrowModal(props: Props) {
name='borrow-to-wallet' name='borrow-to-wallet'
checked={borrowToWallet} checked={borrowToWallet}
onChange={setBorrowToWallet} onChange={setBorrowToWallet}
disabled={isConfirming}
/> />
</div> </div>
</div> </div>

View File

@ -104,6 +104,7 @@ export default function FundWithdrawModalContent(props: Props) {
accountId={!props.isFunding ? props.account.id : undefined} accountId={!props.isFunding ? props.account.id : undefined}
hasSelect hasSelect
maxText='Max' maxText='Max'
disabled={isConfirming}
/> />
<Divider /> <Divider />
<Button <Button

View File

@ -69,7 +69,7 @@ function LendAndReclaimModal({ currentAccount, config }: Props) {
contentHeader={<DetailsHeader data={data} />} contentHeader={<DetailsHeader data={data} />}
coinBalances={coinBalances} coinBalances={coinBalances}
actionButtonText={actionText} actionButtonText={actionText}
showLoaderInButton={isConfirming} showProgressIndicator={isConfirming}
accountSummaryChange={accountChange} accountSummaryChange={accountChange}
title={`${actionText} ${asset.symbol}`} title={`${actionText} ${asset.symbol}`}
onClose={close} onClose={close}

View File

@ -158,10 +158,13 @@ export default function VaultBorrowings(props: VaultBorrowingsProps) {
maxText='Max Borrow' maxText='Max Borrow'
onChange={(amount) => updateAssets(coin.denom, amount)} onChange={(amount) => updateAssets(coin.denom, amount)}
onDelete={() => onDelete(coin.denom)} onDelete={() => onDelete(coin.denom)}
disabled={isConfirming}
/> />
) )
})} })}
{props.borrowings.length === 1 && <Slider onChange={onChangeSlider} value={percentage} />} {props.borrowings.length === 1 && (
<Slider onChange={onChangeSlider} value={percentage} disabled={isConfirming} />
)}
{props.borrowings.length === 0 && ( {props.borrowings.length === 0 && (
<div className='flex items-center gap-4 py-2'> <div className='flex items-center gap-4 py-2'>
<div className='w-4'> <div className='w-4'>
@ -173,7 +176,12 @@ export default function VaultBorrowings(props: VaultBorrowingsProps) {
</Text> </Text>
</div> </div>
)} )}
<Button text='Select borrow assets +' color='tertiary' onClick={addAsset} /> <Button
text='Select borrow assets +'
color='tertiary'
onClick={addAsset}
disabled={isConfirming}
/>
<Divider /> <Divider />
<div className='flex flex-col gap-2'> <div className='flex flex-col gap-2'>
<div className='flex justify-between'> <div className='flex justify-between'>

View File

@ -9,6 +9,7 @@ interface Props {
max: BigNumber max: BigNumber
asset: Asset asset: Asset
amount: BigNumber amount: BigNumber
disabled: boolean
maxButtonLabel: string maxButtonLabel: string
assetUSDValue: BigNumber assetUSDValue: BigNumber
amountValueText?: string amountValueText?: string
@ -24,6 +25,7 @@ export default function AssetAmountInput(props: Props) {
label, label,
amount, amount,
asset, asset,
disabled,
setAmount, setAmount,
assetUSDValue, assetUSDValue,
maxButtonLabel, maxButtonLabel,
@ -52,6 +54,7 @@ export default function AssetAmountInput(props: Props) {
className={className.input} className={className.input}
maxDecimals={asset.decimals} maxDecimals={asset.decimals}
max={max} max={max}
disabled={disabled}
onChange={setAmount} onChange={setAmount}
onFocus={onFocus} onFocus={onFocus}
onBlur={onBlur} onBlur={onBlur}

View File

@ -10,15 +10,22 @@ import { formatAmountWithSymbol } from 'utils/formatters'
interface Props { interface Props {
buyAsset: Asset buyAsset: Asset
sellAsset: Asset sellAsset: Asset
containerClassName?: string
buyButtonDisabled: boolean buyButtonDisabled: boolean
containerClassName?: string
showProgressIndicator: boolean
buyAction: () => void buyAction: () => void
} }
export default function TradeSummary(props: Props) { export default function TradeSummary(props: Props) {
const { containerClassName, buyAsset, sellAsset, buyAction, buyButtonDisabled } = props const {
buyAsset,
sellAsset,
buyAction,
buyButtonDisabled,
containerClassName,
showProgressIndicator,
} = props
const { data: routes, isLoading: isRouteLoading } = useSwapRoute(sellAsset.denom, buyAsset.denom) const { data: routes, isLoading: isRouteLoading } = useSwapRoute(sellAsset.denom, buyAsset.denom)
const [isButtonBusy, setButtonBusy] = useState(false)
const parsedRoutes = useMemo(() => { const parsedRoutes = useMemo(() => {
if (!routes.length) return '-' if (!routes.length) return '-'
@ -29,12 +36,6 @@ export default function TradeSummary(props: Props) {
return routeSymbols.join(' -> ') return routeSymbols.join(' -> ')
}, [routes, sellAsset.symbol]) }, [routes, sellAsset.symbol])
const handleBuyClick = useCallback(async () => {
setButtonBusy(true)
await buyAction()
setButtonBusy(false)
}, [buyAction])
const buttonText = useMemo( const buttonText = useMemo(
() => (routes.length ? `Buy ${buyAsset.symbol}` : 'No route found'), () => (routes.length ? `Buy ${buyAsset.symbol}` : 'No route found'),
[buyAsset.symbol, routes], [buyAsset.symbol, routes],
@ -55,9 +56,9 @@ export default function TradeSummary(props: Props) {
</div> </div>
<ActionButton <ActionButton
disabled={routes.length === 0 || buyButtonDisabled} disabled={routes.length === 0 || buyButtonDisabled}
showProgressIndicator={isButtonBusy || isRouteLoading} showProgressIndicator={showProgressIndicator || isRouteLoading}
text={buttonText} text={buttonText}
onClick={handleBuyClick} onClick={buyAction}
size='md' size='md'
color='primary' color='primary'
className='w-full' className='w-full'

View File

@ -38,6 +38,7 @@ export default function SwapForm(props: Props) {
const [focusedInput, setFocusedInput] = useState<'buy' | 'sell' | null>(null) const [focusedInput, setFocusedInput] = useState<'buy' | 'sell' | null>(null)
const [maxBuyableAmountEstimation, setMaxBuyableAmountEstimation] = useState(BN_ZERO) const [maxBuyableAmountEstimation, setMaxBuyableAmountEstimation] = useState(BN_ZERO)
const [selectedOrderType, setSelectedOrderType] = useState<AvailableOrderType>('Market') const [selectedOrderType, setSelectedOrderType] = useState<AvailableOrderType>('Market')
const [isTransactionExecuting, setTransactionExecuting] = useState(false)
const accountSellAssetDeposit = useMemo( const accountSellAssetDeposit = useMemo(
() => account?.deposits.find(byDenom(sellAsset.denom))?.amount || BN_ZERO, () => account?.deposits.find(byDenom(sellAsset.denom))?.amount || BN_ZERO,
@ -98,6 +99,7 @@ export default function SwapForm(props: Props) {
const handleBuyClick = useCallback(async () => { const handleBuyClick = useCallback(async () => {
if (account?.id) { if (account?.id) {
setTransactionExecuting(true)
const isSucceeded = await swap({ const isSucceeded = await swap({
fee: hardcodedFee, fee: hardcodedFee,
accountId: account.id, accountId: account.id,
@ -109,6 +111,7 @@ export default function SwapForm(props: Props) {
setSellAssetAmount(BN_ZERO) setSellAssetAmount(BN_ZERO)
setBuyAssetAmount(BN_ZERO) setBuyAssetAmount(BN_ZERO)
} }
setTransactionExecuting(false)
} }
}, [account?.id, buyAsset.denom, sellAsset.denom, sellAssetAmount, slippage, swap]) }, [account?.id, buyAsset.denom, sellAsset.denom, sellAssetAmount, slippage, swap])
@ -140,14 +143,16 @@ export default function SwapForm(props: Props) {
containerClassName='mx-3 my-6' containerClassName='mx-3 my-6'
onBlur={dismissInputFocus} onBlur={dismissInputFocus}
onFocus={() => setFocusedInput('buy')} onFocus={() => setFocusedInput('buy')}
disabled={isTransactionExecuting}
/> />
<RangeInput <RangeInput
max={accountSellAssetDeposit.shiftedBy(-sellAsset.decimals).toNumber()}
value={sellAssetAmount.shiftedBy(-sellAsset.decimals).toNumber()}
onChange={handleRangeInputChange}
onBlur={dismissInputFocus}
wrapperClassName='p-4' wrapperClassName='p-4'
onBlur={dismissInputFocus}
disabled={isTransactionExecuting}
onChange={handleRangeInputChange}
value={sellAssetAmount.shiftedBy(-sellAsset.decimals).toNumber()}
max={accountSellAssetDeposit.shiftedBy(-sellAsset.decimals).toNumber()}
/> />
<AssetAmountInput <AssetAmountInput
@ -161,6 +166,7 @@ export default function SwapForm(props: Props) {
containerClassName='mx-3' containerClassName='mx-3'
onBlur={dismissInputFocus} onBlur={dismissInputFocus}
onFocus={() => setFocusedInput('sell')} onFocus={() => setFocusedInput('sell')}
disabled={isTransactionExecuting}
/> />
<TradeSummary <TradeSummary
@ -169,6 +175,7 @@ export default function SwapForm(props: Props) {
sellAsset={sellAsset} sellAsset={sellAsset}
buyAction={handleBuyClick} buyAction={handleBuyClick}
buyButtonDisabled={sellAssetAmount.isZero()} buyButtonDisabled={sellAssetAmount.isZero()}
showProgressIndicator={isTransactionExecuting}
/> />
</> </>
) )