Skip to content

Commit

Permalink
refactor: fix code issues
Browse files Browse the repository at this point in the history
  • Loading branch information
szymonmaslowski committed May 13, 2024
1 parent 8735dad commit 0e565eb
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 36 deletions.
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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 <CreateWalletContext.Provider value={state}>{children(state)}</CreateWalletContext.Provider>;
};
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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 <HardwareWalletContext.Provider value={value}>{children(value)}</HardwareWalletContext.Provider>;
};
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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 <RestoreWalletContext.Provider value={state}>{children(state)}</RestoreWalletContext.Provider>;
};
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ export const WalletSetupWizard = ({
const analytics = useAnalyticsContext();
const { t } = useTranslation();

// TODO
const { updateEnteredAtTime } = useTimeSpentOnPage();
useEffect(() => {
updateEnteredAtTime();
Expand Down Expand Up @@ -196,7 +195,6 @@ export const WalletSetupWizard = ({
}
});

// TODO
if (setupType === SetupType.FORGOT_PASSWORD) {
deleteFromLocalStorage('isForgotPasswordFlow');
} else {
Expand All @@ -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();
};

Expand Down

0 comments on commit 0e565eb

Please sign in to comment.