diff --git a/src/components/configuration/index.tsx b/src/components/configuration/index.tsx index a7d7e35..f93634d 100644 --- a/src/components/configuration/index.tsx +++ b/src/components/configuration/index.tsx @@ -7,7 +7,6 @@ import { import { toast } from "react-hot-toast"; import deleteIcon from "../../assets/icons/delete-icon.png"; import { GlobalConfig, TokenConfig } from "../../middlelayers/datafetch/types"; -import BetterSelect, { SelectOption } from "../common/select"; import { LoadingContext } from "../../App"; import { CurrencyRateDetail } from "../../middlelayers/types"; import { listAllCurrencyRates } from "../../middlelayers/currency"; @@ -106,6 +105,21 @@ const walletOptions = [ }, ]; +const querySizeOptions = [ + { + value: "10", + label: "10", + }, + { + value: "20", + label: "20", + }, + { + value: "50", + label: "50", + }, +]; + const Configuration = ({ onConfigurationSave, }: { @@ -115,6 +129,10 @@ const Configuration = ({ const [groupUSD, setGroupUSD] = useState(true); const [querySize, setQuerySize] = useState(0); const [preferCurrency, setPreferCurrency] = useState("USD"); + const [addExchangeDialogOpen, setAddExchangeDialogOpen] = useState(false); + const [addWalletDialogOpen, setAddWalletDialogOpen] = useState(false); + const [addOtherDialogOpen, setAddOtherDialogOpen] = useState(false); + const [addExchangeConfig, setAddExchangeConfig] = useState< | { type: string; @@ -168,25 +186,6 @@ const Configuration = ({ }[] >([]); - const querySizeOptions = useMemo( - () => - [ - { - value: "10", - label: "10", - }, - { - value: "20", - label: "20", - }, - { - value: "50", - label: "50", - }, - ] as SelectOption[], - [] - ); - const preferCurrencyOptions = useMemo( () => _(currencies) @@ -542,65 +541,6 @@ const Configuration = ({

- //
- // - // - // - // handleRemoveWallet(idx)}> - // delete - // - //
); }) .value(); @@ -657,24 +597,12 @@ const Configuration = ({ setExchanges(_.filter(exchanges, (_, i) => i !== idx)); } - function handleAddWallet() { - setWallets([ - ...wallets, - { - type: "btc", - address: "", - }, - ]); + function handleAddWallet(val: { type: string; address: string }) { + setWallets([...wallets, val]); } - function handleAddOther() { - setOthers([ - ...others, - { - symbol: "", - amount: 0, - }, - ]); + function handleAddOther(val: { symbol: string; amount: number }) { + setOthers([...others, val]); } function handleRemoveOther(idx: number) { @@ -685,15 +613,46 @@ const Configuration = ({ setWallets(_.filter(wallets, (_, i) => i !== idx)); } - function handleExchangeChange(idx: number, key: string, val: string) { - const newExs = _.set(exchanges, [idx, key], val); + function handleExchangeChange(val: { + type: string; + apiKey: string; + secret: string; + password?: string; + alias?: string; + }) { + setExchanges([...exchanges, val]); + } + + // submit button clicked in add exchange form + function onAddExchangeFormSubmit() { + if ( + !addExchangeConfig || + !addExchangeConfig.type || + !addExchangeConfig.apiKey || + !addExchangeConfig.secret + ) { + toast.error("Exchange type, api key and secret is required"); + return; + } + + if (addExchangeConfig.type === "okex" && !addExchangeConfig.password) { + toast.error("Password is required for okex"); + return; + } + + handleExchangeChange(addExchangeConfig); - setExchanges([...newExs]); + // clear + setAddExchangeConfig(undefined); + setAddExchangeDialogOpen(false); } function renderAddExchangeForm() { return ( - + @@ -803,16 +762,33 @@ const Configuration = ({ )} - + ); } + // submit button clicked in add wallet form + function onAddWalletFormSubmit() { + if (!addWalletConfig || !addWalletConfig.type || !addWalletConfig.address) { + // alert + toast.error("Wallet type and address is required"); + return; + } + handleAddWallet(addWalletConfig); + + // clear + setAddWalletConfig(undefined); + + setAddWalletDialogOpen(false); + } + function renderAddWalletForm() { return ( - + @@ -886,16 +862,31 @@ const Configuration = ({ - + ); } + // submit button clicked in add other form + function onAddOtherFormSubmit() { + if (!addOtherConfig || !addOtherConfig.symbol) { + // alert + toast.error("Symbol is required"); + return; + } + handleAddOther(addOtherConfig); + // clear + setAddOtherConfig(undefined); + setAddOtherDialogOpen(false); + } + function renderAddOtherForm() { return ( - + @@ -942,7 +933,9 @@ const Configuration = ({ - +