From 0e565eb3ec8401369f95ab477e33911a4dd84fb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Szymon=20Mas=C5=82owski?= Date: Mon, 13 May 2024 14:06:02 +0200 Subject: [PATCH] refactor: fix code issues --- .../multi-wallet/create-wallet/context.tsx | 19 +++++---- .../multi-wallet/hardware-wallet/context.tsx | 40 +++++++++++++------ .../hardware-wallet/steps/Connect.tsx | 2 +- .../multi-wallet/restore-wallet/context.tsx | 34 +++++++++++----- .../components/WalletSetupWizard.tsx | 3 -- 5 files changed, 62 insertions(+), 36 deletions(-) diff --git a/apps/browser-extension-wallet/src/views/browser-view/features/multi-wallet/create-wallet/context.tsx b/apps/browser-extension-wallet/src/views/browser-view/features/multi-wallet/create-wallet/context.tsx index 8501df8fa7..7314e0da4f 100644 --- a/apps/browser-extension-wallet/src/views/browser-view/features/multi-wallet/create-wallet/context.tsx +++ b/apps/browser-extension-wallet/src/views/browser-view/features/multi-wallet/create-wallet/context.tsx @@ -1,7 +1,7 @@ import { CreateWalletParams } from '@hooks'; import { Wallet } from '@lace/cardano'; import { walletRoutePaths } from '@routes'; -import React, { createContext, useContext, useState } from 'react'; +import React, { createContext, useContext, useMemo, useState } from 'react'; import { useHistory } from 'react-router'; import { useHotWalletCreation } from '../useHotWalletCreation'; import { useWalletOnboarding } from '../walletOnboardingContext'; @@ -99,13 +99,16 @@ export const CreateWalletProvider = ({ children }: Props): React.ReactElement => } }; - const state = { - back, - createWalletData, - next, - onNameAndPasswordChange, - step - }; + const state = useMemo( + () => ({ + back, + createWalletData, + next, + onNameAndPasswordChange, + step + }), + [back, createWalletData, next, onNameAndPasswordChange, step] + ); return {children(state)}; }; diff --git a/apps/browser-extension-wallet/src/views/browser-view/features/multi-wallet/hardware-wallet/context.tsx b/apps/browser-extension-wallet/src/views/browser-view/features/multi-wallet/hardware-wallet/context.tsx index 8edbffe0cf..0210377e32 100644 --- a/apps/browser-extension-wallet/src/views/browser-view/features/multi-wallet/hardware-wallet/context.tsx +++ b/apps/browser-extension-wallet/src/views/browser-view/features/multi-wallet/hardware-wallet/context.tsx @@ -1,6 +1,6 @@ /* eslint-disable unicorn/no-useless-undefined */ import { Wallet } from '@lace/cardano'; -import React, { createContext, useCallback, useContext, useEffect, useState } from 'react'; +import React, { createContext, useCallback, useContext, useEffect, useMemo, useState } from 'react'; import { useHistory } from 'react-router-dom'; import { useWalletManager } from '@hooks'; import { ErrorDialogCode, WalletConnectStep } from './types'; @@ -219,18 +219,32 @@ export const HardwareWalletProvider = ({ children }: HardwareWalletProviderProps walletRepository ]); - const value = { - back, - connect, - createWallet, - errorDialogCode, - isStartOverDialogVisible, - next, - onErrorDialogRetry, - onNameAndAccountChange, - onStartOverDialogAction, - step - }; + const value = useMemo( + () => ({ + back, + connect, + createWallet, + errorDialogCode, + isStartOverDialogVisible, + next, + onErrorDialogRetry, + onNameAndAccountChange, + onStartOverDialogAction, + step + }), + [ + back, + connect, + createWallet, + errorDialogCode, + isStartOverDialogVisible, + next, + onErrorDialogRetry, + onNameAndAccountChange, + onStartOverDialogAction, + step + ] + ); return {children(value)}; }; diff --git a/apps/browser-extension-wallet/src/views/browser-view/features/multi-wallet/hardware-wallet/steps/Connect.tsx b/apps/browser-extension-wallet/src/views/browser-view/features/multi-wallet/hardware-wallet/steps/Connect.tsx index d3428d2717..9fdc3618a3 100644 --- a/apps/browser-extension-wallet/src/views/browser-view/features/multi-wallet/hardware-wallet/steps/Connect.tsx +++ b/apps/browser-extension-wallet/src/views/browser-view/features/multi-wallet/hardware-wallet/steps/Connect.tsx @@ -76,7 +76,7 @@ export const Connect: VFC = () => { setDiscoveryState(DiscoveryState.Requested); setConnectionError(null); void analytics.sendEventToPostHog(postHogActions.hardware.CONNECT_HW_TRY_AGAIN_CLICK); - }, [analytics]); + }, [analytics, postHogActions.hardware.CONNECT_HW_TRY_AGAIN_CLICK]); useEffect(() => { (async () => { diff --git a/apps/browser-extension-wallet/src/views/browser-view/features/multi-wallet/restore-wallet/context.tsx b/apps/browser-extension-wallet/src/views/browser-view/features/multi-wallet/restore-wallet/context.tsx index 5f63c473b1..b0add4783d 100644 --- a/apps/browser-extension-wallet/src/views/browser-view/features/multi-wallet/restore-wallet/context.tsx +++ b/apps/browser-extension-wallet/src/views/browser-view/features/multi-wallet/restore-wallet/context.tsx @@ -1,4 +1,4 @@ -import React, { createContext, useCallback, useContext, useState } from 'react'; +import React, { createContext, useCallback, useContext, useMemo, useState } from 'react'; import { WalletRestoreStep } from './types'; import { CreateWalletParams } from '@hooks'; import { Wallet } from '@lace/cardano'; @@ -113,16 +113,28 @@ export const RestoreWalletProvider = ({ children }: Props): React.ReactElement = } }; - const state = { - back, - createWalletData, - finalizeWalletRestoration, - next, - onNameAndPasswordChange, - onRecoveryPhraseLengthChange, - setMnemonic, - step - }; + const state = useMemo( + () => ({ + back, + createWalletData, + finalizeWalletRestoration, + next, + onNameAndPasswordChange, + onRecoveryPhraseLengthChange, + setMnemonic, + step + }), + [ + back, + createWalletData, + finalizeWalletRestoration, + next, + onNameAndPasswordChange, + onRecoveryPhraseLengthChange, + setMnemonic, + step + ] + ); return {children(state)}; }; diff --git a/apps/browser-extension-wallet/src/views/browser-view/features/wallet-setup/components/WalletSetupWizard.tsx b/apps/browser-extension-wallet/src/views/browser-view/features/wallet-setup/components/WalletSetupWizard.tsx index 219201c94b..d29788d284 100644 --- a/apps/browser-extension-wallet/src/views/browser-view/features/wallet-setup/components/WalletSetupWizard.tsx +++ b/apps/browser-extension-wallet/src/views/browser-view/features/wallet-setup/components/WalletSetupWizard.tsx @@ -74,7 +74,6 @@ export const WalletSetupWizard = ({ const analytics = useAnalyticsContext(); const { t } = useTranslation(); - // TODO const { updateEnteredAtTime } = useTimeSpentOnPage(); useEffect(() => { updateEnteredAtTime(); @@ -196,7 +195,6 @@ export const WalletSetupWizard = ({ } }); - // TODO if (setupType === SetupType.FORGOT_PASSWORD) { deleteFromLocalStorage('isForgotPasswordFlow'); } else { @@ -213,7 +211,6 @@ export const WalletSetupWizard = ({ const handleSubmit = async (result: { password: string; walletName: string }) => { void sendAnalytics(postHogOnboardingActions[setupType]?.ENTER_WALLET); await handleCompleteCreation(result.walletName, result.password); - // TODO void analytics.sendAliasEvent(); };