From 997ebcea788979238c7e97c4f1f98f1c495dcd60 Mon Sep 17 00:00:00 2001 From: AzizbekFayziyev Date: Mon, 23 Jun 2025 21:15:14 +0500 Subject: [PATCH] finish: fix types --- .eslintrc | 2 + src/app/App.tsx | 113 ++++++----- .../ModalConfirmation/ModalConfirmation.tsx | 7 +- .../OuterConfirmation/OuterConfirmation.tsx | 47 +++-- src/app/components/WalletSend/WalletSend.tsx | 31 ++- src/app/hooks/useCensorDigits.ts | 2 +- src/app/hooks/useGetAsset.ts | 8 +- src/app/hooks/useValidation.ts | 6 +- src/app/store/actions.ts | 7 +- src/app/store/store-reducer.tsx | 2 +- src/app/utils/classNames.ts | 2 +- src/app/utils/utils.ts | 1 + src/background/background.ts | 176 +++++++--------- src/background/wallet.ts | 129 ++++++------ src/types/index.ts | 191 +++++++++++++++++- 15 files changed, 461 insertions(+), 263 deletions(-) diff --git a/.eslintrc b/.eslintrc index f550444..05e441c 100644 --- a/.eslintrc +++ b/.eslintrc @@ -30,7 +30,9 @@ } ], "import/no-unresolved": "off", + "import/no-mutable-exports": "off", "no-async-promise-executor": "off", + "default-param-last": "off", "no-use-before-define": ["error", { "functions": false, "classes": true, "variables": true }], "func-names": "off", "consistent-return": "off", diff --git a/src/app/App.tsx b/src/app/App.tsx index 614b655..a960ce1 100644 --- a/src/app/App.tsx +++ b/src/app/App.tsx @@ -45,7 +45,7 @@ import { AcceptSwapReq, AssetWhitelistReq, dispatchType, - RequestType, + BurnAssetRequestType, SwapRequest, transferType, } from '../types'; @@ -82,6 +82,7 @@ function App() { const response = await fetchBackground({ method: 'EXECUTE_BRIDGING_TRANSFER', }); + if (response.data.error) { return { sent: false, status: response.data.error }; } @@ -129,6 +130,7 @@ function App() { const walletActive = await fetchBackground({ method: 'GET_WALLET_DATA', }); + updateWalletConnected(dispatch as dispatchType, !walletActive.error); updateLoading(dispatch as dispatchType, false); }; @@ -137,6 +139,7 @@ function App() { if (!chrome?.runtime?.sendMessage) return; const walletsList = await fetchBackground({ method: 'GET_WALLETS' }); + if (!walletsList.data) return; updateWalletsList(dispatch as dispatchType, walletsList.data); @@ -192,7 +195,7 @@ function App() { useEffect(() => { const listener = ( - request: RequestType, + request: BurnAssetRequestType, sender: chrome.runtime.MessageSender, sendResponse: (response: { status: string }) => void, ) => { @@ -380,7 +383,11 @@ function App() { const swapPageReqs = swapRequests.map((e: SwapRequest) => { const { swap } = e; - const swapParams: { address: string } | any = {}; + const swapParams: { + address?: string; + receiving?: React.JSX.Element; + sending?: React.JSX.Element; + } | null = {}; swapParams.address = swap.destinationAddress; @@ -389,13 +396,16 @@ function App() { swapParams.receiving = getSwapAmountText( receivingAmount, - receivingAsset as any, + receivingAsset as unknown as { ticker: string }, ); const sendingAsset = swap.currentAsset; const sendingAmount = new Big(swap.currentAssetAmount); - swapParams.sending = getSwapAmountText(sendingAmount, sendingAsset as any); + swapParams.sending = getSwapAmountText( + sendingAmount, + sendingAsset as unknown as { ticker: string }, + ); return { id: e.id, @@ -433,7 +443,10 @@ function App() { const swap = e?.swapProposal; - const swapParams: { receiving: string } | any = {}; + const swapParams: { + receiving?: React.JSX.Element; + sending?: React.JSX.Element; + } = {}; function toBigWithDecimal(amount: Big, decimalPoint: number) { if (amount) { @@ -451,7 +464,7 @@ function App() { if (receivingAmount !== undefined) { swapParams.receiving = getSwapAmountText( receivingAmount, - receivingAsset as any, + receivingAsset as unknown as { ticker: string }, ); } @@ -464,7 +477,7 @@ function App() { if (sendingAmount !== undefined) { swapParams.sending = getSwapAmountText( sendingAmount, - sendingAsset as any, + sendingAsset as unknown as { ticker: string }, ); } } @@ -532,7 +545,7 @@ function App() { const response = await fetchBackground({ method: 'GET_BURN_ASSET_REQUESTS' }); const burnRequests = response.data; - const pageReqs = burnRequests.map((e: any) => { + const pageReqs = burnRequests.map((e: { burn: unknown; id: string }) => { const data = e.burn; return { @@ -569,7 +582,7 @@ function App() { credentials: { token: state.connectCredentials.token, port: state?.connectCredentials?.port || defaultPort, - } as any, + } as { token: string; port: string }, }); } }, [state.connectCredentials]); @@ -617,44 +630,50 @@ function App() { {loggedIn && state.isConnected &&
} - {appConnected && !connectOpened ? ( - loggedIn ? ( - state.isConnected ? ( -
- - - - -
- ) : ( - - ) - ) : ( - PasswordPages() - ) - ) : ( - { - const password = inputPassword || (await getSessionPassword()); - - if (!password) return; - setPassword(password); - - if (connectKey) - ConnectKeyUtils.setConnectData( - connectKey, - String(walletPort), - password, + {(() => { + if (appConnected && !connectOpened) { + if (loggedIn) { + if (state.isConnected) { + return ( +
+ + + + +
); - setLoggedIn(true); - await setSessionPassword(password); - }} - /> - )} + } + return ; + } + return PasswordPages(); + } + + return ( + { + const password = inputPassword || (await getSessionPassword()); + if (!password) return; + + setPassword(password); + + if (connectKey) { + ConnectKeyUtils.setConnectData( + connectKey, + String(walletPort), + password, + ); + } + + setLoggedIn(true); + await setSessionPassword(password); + }} + /> + ); + })()} ); diff --git a/src/app/components/ModalConfirmation/ModalConfirmation.tsx b/src/app/components/ModalConfirmation/ModalConfirmation.tsx index 262ce6c..1314213 100644 --- a/src/app/components/ModalConfirmation/ModalConfirmation.tsx +++ b/src/app/components/ModalConfirmation/ModalConfirmation.tsx @@ -10,9 +10,14 @@ interface ModalConfirmationProps { onConfirm: () => void; } +interface confirmationModalType { + params: string; + method: string; +} + const ModalConfirmation = ({ isOpen, onClose, onConfirm }: ModalConfirmationProps) => { const { state } = useContext(Store); - const { method, params } = state.confirmationModal || {}; + const { method, params } = (state.confirmationModal as unknown as confirmationModalType) || {}; const closeHandler = useCallback(() => { onClose(); diff --git a/src/app/components/OuterConfirmation/OuterConfirmation.tsx b/src/app/components/OuterConfirmation/OuterConfirmation.tsx index 366b0dc..2adb4cf 100644 --- a/src/app/components/OuterConfirmation/OuterConfirmation.tsx +++ b/src/app/components/OuterConfirmation/OuterConfirmation.tsx @@ -44,6 +44,7 @@ const OuterConfirmation = () => { const transactionParams = params ? Object.fromEntries((params as ParamsType[]).map((item) => [item.key, item.value])) : {}; + const totalAmount = Number( isMultipleDestinations ? destinations.reduce( @@ -113,7 +114,7 @@ const OuterConfirmation = () => {
From
-

{transactionParams?.F}

+

{transactionParams?.From}

Asset
@@ -248,12 +249,14 @@ const OuterConfirmation = () => {
Burn Amount

{burnAmount}

- {nativeAmount && ( + + {typeof nativeAmount === 'string' && (
Native Amount

{nativeAmount}

)} + {pointTxToAddress && (
Send Tx To
@@ -317,6 +320,7 @@ const OuterConfirmation = () => { ); } + return (
@@ -344,28 +348,27 @@ const OuterConfirmation = () => {
{getConfirmationContent()}
- {isTransferMethod || - (isBurnMethod && ( - <> -
-
- Transaction fee -
-

0.01 ZANO

-
+ {(isTransferMethod || isBurnMethod) && ( + <> +
+
+ Transaction fee +
+

0.01 ZANO

+
- {isTransferMethod && ( - <> -
+ {isTransferMethod && ( + <> +
-
-
Total
-

{totalAmount}

-
- - )} - - ))} +
+
Total
+

{totalAmount}

+
+ + )} + + )}