From 45238de28d06fa45a3d1d81f13ff29d55e6994b0 Mon Sep 17 00:00:00 2001 From: devtealeaf Date: Fri, 11 Oct 2024 02:04:55 +0300 Subject: [PATCH 1/2] fix: remove form error alert --- package.json | 2 +- .../components/InvestForm/InvestError.tsx | 97 ------------------- .../Vault/components/InvestForm/index.tsx | 22 ++--- src/store/index.ts | 4 +- src/ui/ErrorMessage.tsx | 10 +- src/ui/TimeDifferenceIndicator.tsx | 8 +- 6 files changed, 20 insertions(+), 123 deletions(-) delete mode 100644 src/modules/Vault/components/InvestForm/InvestError.tsx diff --git a/package.json b/package.json index fd82286e..fb75d6d0 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "stability-ui", "type": "module", - "version": "0.12.18-alpha", + "version": "0.12.19-alpha", "scripts": { "dev": "astro dev", "start": "astro dev", diff --git a/src/modules/Vault/components/InvestForm/InvestError.tsx b/src/modules/Vault/components/InvestForm/InvestError.tsx deleted file mode 100644 index 104b4c9e..00000000 --- a/src/modules/Vault/components/InvestForm/InvestError.tsx +++ /dev/null @@ -1,97 +0,0 @@ -import { DEFAULT_ERROR } from "@constants"; - -import type { TError } from "@types"; - -interface IProps { - error: TError; - setError: React.Dispatch>; -} - -const InvestError: React.FC = ({ error, setError }) => { - return ( -
-
-
- - - -

{error?.type}

- setError(DEFAULT_ERROR)} - > - - - - - - - - - - - - - - - - -
-

- {error?.description} -

-
-
- ); -}; -export { InvestError }; diff --git a/src/modules/Vault/components/InvestForm/index.tsx b/src/modules/Vault/components/InvestForm/index.tsx index 85c9dd3b..70aeaaa5 100644 --- a/src/modules/Vault/components/InvestForm/index.tsx +++ b/src/modules/Vault/components/InvestForm/index.tsx @@ -9,7 +9,6 @@ import { writeContract, waitForTransactionReceipt } from "@wagmi/core"; import { SettingsModal } from "./SettingsModal"; import { TabSwitcher } from "./TabSwitcher"; -import { InvestError } from "./InvestError"; import { Loader, ShareSkeleton, AssetsSkeleton } from "@ui"; @@ -23,6 +22,7 @@ import { lastTx, connected, transactionSettings, + error, } from "@store"; import { @@ -64,7 +64,6 @@ import type { TVault, TBalances, TAsset, - TError, TUnderlyingToken, TZAPData, TLocalStorageToken, @@ -171,8 +170,6 @@ const InvestForm: React.FC = ({ network, vault }) => { const [needConfirm, setNeedConfirm] = useState(false); const [loader, setLoader] = useState(false); - const [error, setError] = useState(DEFAULT_ERROR); - const tokenSelectorRef = useRef(null); let isAnyCCFOptionVisible = false; @@ -247,8 +244,7 @@ const InvestForm: React.FC = ({ network, vault }) => { : 150; const errorMessage = err.message.substring(0, errorMessageLength) + "..."; - - setError({ state: true, type: errName, description: errorMessage }); + error.set({ state: true, type: errName, description: errorMessage }); } setLoader(false); setNeedConfirm(false); @@ -609,7 +605,7 @@ const InvestForm: React.FC = ({ network, vault }) => { const zapApprove = async () => { ///// ZAP TOKENS & UNDERLYING TOKENS - setError(DEFAULT_ERROR); + error.set(DEFAULT_ERROR); setTransactionInProgress(true); const amount = inputs[option[0]]; @@ -695,7 +691,7 @@ const InvestForm: React.FC = ({ network, vault }) => { } ///// UNDERLYING - setError(DEFAULT_ERROR); + error.set(DEFAULT_ERROR); setTransactionInProgress(true); setLoader(true); @@ -1014,7 +1010,7 @@ const InvestForm: React.FC = ({ network, vault }) => { }; const withdrawZapApprove = async () => { - setError(DEFAULT_ERROR); + error.set(DEFAULT_ERROR); setTransactionInProgress(true); const amount = inputs[option[0]]; @@ -1105,7 +1101,7 @@ const InvestForm: React.FC = ({ network, vault }) => { ? maxUint256 : parseUnits(amount, decimals); - setError(DEFAULT_ERROR); + error.set(DEFAULT_ERROR); const needApprove = option.filter( (asset) => @@ -1193,7 +1189,7 @@ const InvestForm: React.FC = ({ network, vault }) => { }; const deposit = async () => { - setError(DEFAULT_ERROR); + error.set(DEFAULT_ERROR); setTransactionInProgress(true); let assets: string[] = []; let input: any = []; @@ -1318,7 +1314,7 @@ const InvestForm: React.FC = ({ network, vault }) => { }; const withdraw = async () => { - setError(DEFAULT_ERROR); + error.set(DEFAULT_ERROR); setTransactionInProgress(true); const sharesToBurn = parseUnits(inputs[option[0]], 18); @@ -3157,8 +3153,6 @@ const InvestForm: React.FC = ({ network, vault }) => { )} - - {error?.state && } ); diff --git a/src/store/index.ts b/src/store/index.ts index c22d4515..2e5d0222 100644 --- a/src/store/index.ts +++ b/src/store/index.ts @@ -5,7 +5,7 @@ import { QueryClient } from "@tanstack/react-query"; import { deserialize, serialize } from "wagmi"; -import { DEFAULT_TRANSACTION_SETTINGS } from "@constants"; +import { DEFAULT_ERROR, DEFAULT_TRANSACTION_SETTINGS } from "@constants"; import type { TPlatformData, @@ -42,7 +42,7 @@ const tokens = atom({}); const connected = atom(); const reload = atom(false); -const error = atom({ state: false, type: "", description: "" }); +const error = atom(DEFAULT_ERROR); const isWeb3Load = atom(true); const apiData = atom(); diff --git a/src/ui/ErrorMessage.tsx b/src/ui/ErrorMessage.tsx index 41b54f21..15c60810 100644 --- a/src/ui/ErrorMessage.tsx +++ b/src/ui/ErrorMessage.tsx @@ -12,12 +12,12 @@ const ErrorMessage: React.FC = ({ type }) => { if ($error.state && type === "API") { return ( -
+

{$error.description.slice(0, 20)}...

@@ -27,7 +27,7 @@ const ErrorMessage: React.FC = ({ type }) => { } if ($error.state && type === "WEB3") { return ( -
+
error.set({ state: false, type: "", description: "" })} className="absolute right-5 top-5 cursor-pointer" @@ -88,10 +88,10 @@ const ErrorMessage: React.FC = ({ type }) => { -

{$error.description.slice(0, 20)}...

+

{$error.description.slice(0, 25)}...

diff --git a/src/ui/TimeDifferenceIndicator.tsx b/src/ui/TimeDifferenceIndicator.tsx index 396a088b..7a663898 100644 --- a/src/ui/TimeDifferenceIndicator.tsx +++ b/src/ui/TimeDifferenceIndicator.tsx @@ -19,14 +19,14 @@ const TimeDifferenceIndicator: React.FC = ({
{timeDifference.days < 1000 ? (
{timeDifference.days} {timeDifference.days > 1 ? "days" : "day"}{" "} {timeDifference.hours}h ago
) : (
None
@@ -40,8 +40,8 @@ const TimeDifferenceIndicator: React.FC = ({
4 - ? "bg-accent-950 text-accent-400" - : "bg-success-950 text-success-400" + ? "bg-accent-950 text-accent-400 border border-accent-400" + : "bg-success-950 border border-success-400 text-success-400" }`} > {timeDifference.hours}h ago From f9c720130c433e27bc9783ffe737892861eeec6c Mon Sep 17 00:00:00 2001 From: devtealeaf Date: Fri, 11 Oct 2024 02:30:33 +0300 Subject: [PATCH 2/2] upd: form swaps --- .../Vault/components/InvestForm/index.tsx | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/modules/Vault/components/InvestForm/index.tsx b/src/modules/Vault/components/InvestForm/index.tsx index 70aeaaa5..147e9993 100644 --- a/src/modules/Vault/components/InvestForm/index.tsx +++ b/src/modules/Vault/components/InvestForm/index.tsx @@ -2598,14 +2598,24 @@ const InvestForm: React.FC = ({ network, vault }) => { isSingleTokenStrategy || !isNotUnderlying) && (

You Receive

)}
{(option.length > 1 || isSingleTokenStrategy || @@ -2732,7 +2742,12 @@ const InvestForm: React.FC = ({ network, vault }) => {

{!isEmptyObject(inputs) && (