From 584379a19b9154412eedfc8a7a768116af333b89 Mon Sep 17 00:00:00 2001 From: Matias Poblete <86752543+MattPoblete@users.noreply.github.com> Date: Thu, 21 Nov 2024 10:50:09 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=A9=B9Fix=20multiple=20strategies=20handl?= =?UTF-8?q?e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DeployVault/AddNewStrategyButton.tsx | 52 ++++++----- .../DeployVault/ConfirmDelpoyModal.tsx | 10 +- .../components/DeployVault/DeployVault.tsx | 93 +++++++++---------- .../components/DeployVault/VaultPreview.tsx | 10 +- .../dapp/src/store/lib/features/vaultStore.ts | 37 ++++---- apps/dapp/src/store/lib/types.ts | 2 +- 6 files changed, 99 insertions(+), 105 deletions(-) diff --git a/apps/dapp/src/components/DeployVault/AddNewStrategyButton.tsx b/apps/dapp/src/components/DeployVault/AddNewStrategyButton.tsx index e7da6c9f..131e1ef1 100644 --- a/apps/dapp/src/components/DeployVault/AddNewStrategyButton.tsx +++ b/apps/dapp/src/components/DeployVault/AddNewStrategyButton.tsx @@ -9,7 +9,7 @@ import { } from '@/components/ui/dialog' import { getTokenSymbol } from '@/helpers/getTokenInfo' import { StrategyMethod, useStrategyCallback } from '@/hooks/useStrategy' -import { getDefaultStrategies, pushAmount, pushAsset, setAmountByAddress } from '@/store/lib/features/vaultStore' +import { getDefaultStrategies, pushAsset, setAssetAmount } from '@/store/lib/features/vaultStore' import { useAppDispatch, useAppSelector } from '@/store/lib/storeHooks' import { Asset, Strategy } from '@/store/lib/types' import { @@ -30,6 +30,7 @@ import { MdAdd } from 'react-icons/md' import { Checkbox } from '../ui/checkbox' import { CheckboxCard } from '../ui/checkbox-card' import { InputGroup } from '../ui/input-group' +import { NumberInputField, NumberInputRoot } from '../ui/number-input' interface AmountInputProps { amount: number @@ -44,7 +45,7 @@ function AddNewStrategyButton() { const [open, setOpen] = useState(false) const newVault = useAppSelector((state) => state.newVault) const [defaultStrategies, setDefaultStrategies] = useState([]) - const [selectedAsset, setSelectedAsset] = useState({ address: '', strategies: [], symbol: '' }) + const [selectedAsset, setSelectedAsset] = useState({ address: '', strategies: [], symbol: '', amount: 0 }) const [assets, setAssets] = useState([]) const [amountInput, setAmountInput] = useState({ amount: 0, enabled: false }) @@ -102,6 +103,11 @@ function AddNewStrategyButton() { const handleAmountInput = async (e: any) => { const input = e.target.value + if (!input) { + console.log('input is empty') + setSelectedAsset({ ...selectedAsset, amount: 0 }) + } + console.log(input) const decimalRegex = /^(\d+)?(\.\d{0,7})?$/ if (!decimalRegex.test(input)) return if (input.startsWith('.')) { @@ -122,15 +128,11 @@ function AddNewStrategyButton() { } const exists = strategyExists(selectedAsset.strategies[0]!) if (exists) { - if (amountInput.enabled && amountInput.amount! > 0) { - await dispatch(setAmountByAddress({ address: selectedAsset.address, amount: amountInput.amount })) - } else if (amountInput.enabled == false || amountInput.amount! == 0) { - await dispatch(setAmountByAddress({ address: selectedAsset.address, amount: 0 })) - } + } await dispatch(pushAsset(newAsset)) if (!exists && amountInput.enabled && amountInput.amount! > 0) { - await dispatch(pushAmount(amountInput.amount!)) + await dispatch(setAssetAmount({ address: newAsset.address, amount: amountInput.amount! })) } resetForm() } @@ -154,6 +156,7 @@ function AddNewStrategyButton() { str.address === strategy.address)} + disabled={strategyExists(strategy)} onCheckedChange={(e) => handleSelectStrategy(!!e.checked, strategy)} label={strategy.name} /> @@ -172,24 +175,27 @@ function AddNewStrategyButton() { } - {amountInput.enabled && ( - - - Amount: - - - - - - - - )} )} - + {amountInput.enabled && ( + + + Amount: + + + + + + + + + + )}