Skip to content

Commit

Permalink
fix: eliminate lint warnings (#1170)
Browse files Browse the repository at this point in the history
  • Loading branch information
szymonmaslowski authored May 21, 2024
1 parent 5e0a649 commit 946d40a
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 37 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, useMemo, useState } from 'react';
import React, { createContext, useCallback, useContext, useMemo, useState } from 'react';
import { useHistory } from 'react-router';
import { useHotWalletCreation } from '../useHotWalletCreation';
import { useWalletOnboarding } from '../walletOnboardingContext';
Expand Down Expand Up @@ -44,24 +44,27 @@ export const CreateWalletProvider = ({ children }: Props): React.ReactElement =>
});
const [step, setStep] = useState<WalletCreateStep>(WalletCreateStep.RecoveryPhraseWriteDown);

const generateMnemonic = () => {
const generateMnemonic = useCallback(() => {
setCreateWalletData((prevState) => ({ ...prevState, mnemonic: Wallet.KeyManagement.util.generateMnemonicWords() }));
};
}, [setCreateWalletData]);

const onNameAndPasswordChange: OnNameAndPasswordChange = ({ name, password }) => {
setCreateWalletData((prevState) => ({ ...prevState, name, password }));
};
const onNameAndPasswordChange: OnNameAndPasswordChange = useCallback(
({ name, password }) => {
setCreateWalletData((prevState) => ({ ...prevState, name, password }));
},
[setCreateWalletData]
);

const finalizeWalletCreation = async () => {
const finalizeWalletCreation = useCallback(async () => {
const wallet = await createHotWallet();
await sendPostWalletAddAnalytics({
extendedAccountPublicKey: wallet.source.account.extendedAccountPublicKey,
walletAddedPostHogAction: postHogActions.create.WALLET_ADDED
});
clearSecrets();
};
}, [clearSecrets, createHotWallet, postHogActions.create.WALLET_ADDED, sendPostWalletAddAnalytics]);

const next = async () => {
const next = useCallback(async () => {
switch (step) {
case WalletCreateStep.RecoveryPhraseWriteDown: {
setFormDirty(true);
Expand All @@ -78,9 +81,9 @@ export const CreateWalletProvider = ({ children }: Props): React.ReactElement =>
break;
}
}
};
}, [finalizeWalletCreation, history, setFormDirty, step]);

const back = () => {
const back = useCallback(() => {
switch (step) {
case WalletCreateStep.RecoveryPhraseWriteDown: {
history.push(walletRoutePaths.newWallet.root);
Expand All @@ -97,7 +100,7 @@ export const CreateWalletProvider = ({ children }: Props): React.ReactElement =>
break;
}
}
};
}, [generateMnemonic, history, setFormDirty, step]);

const state = useMemo(
() => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export const HardwareWalletProvider = ({ children }: HardwareWalletProviderProps
break;
}
}
}, [closeConnection, history, step]);
}, [closeConnection, history, setFormDirty, step]);

const back = useCallback(() => {
switch (step) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,23 +61,32 @@ export const RestoreWalletProvider = ({ children }: Props): React.ReactElement =
[setCreateWalletData, setFormDirty]
);

const onRecoveryPhraseLengthChange: OnRecoveryPhraseLengthChange = (length) => {
setCreateWalletData((prevState) => ({ ...prevState, mnemonic: Array.from({ length }, () => '') }));
};

const onNameAndPasswordChange: OnNameAndPasswordChange = ({ name, password }) => {
setCreateWalletData((prevState) => ({ ...prevState, name, password }));
};

const sendHdWalletAnalyticEvent = async ({ wallet }: Wallet.CardanoWallet) => {
const addresses = await firstValueFrom(wallet.addresses$.pipe(filter((a) => a.length > 0)));
const hdWalletDiscovered = addresses.some((addr) => !isScriptAddress(addr) && addr.index > 0);
if (hdWalletDiscovered) {
await analytics.sendEventToPostHog(postHogActions.restore.HD_WALLET);
}
};
const onRecoveryPhraseLengthChange: OnRecoveryPhraseLengthChange = useCallback(
(length) => {
setCreateWalletData((prevState) => ({ ...prevState, mnemonic: Array.from({ length }, () => '') }));
},
[setCreateWalletData]
);

const onNameAndPasswordChange: OnNameAndPasswordChange = useCallback(
({ name, password }) => {
setCreateWalletData((prevState) => ({ ...prevState, name, password }));
},
[setCreateWalletData]
);

const finalizeWalletRestoration = async () => {
const sendHdWalletAnalyticEvent = useCallback(
async ({ wallet }: Wallet.CardanoWallet) => {
const addresses = await firstValueFrom(wallet.addresses$.pipe(filter((a) => a.length > 0)));
const hdWalletDiscovered = addresses.some((addr) => !isScriptAddress(addr) && addr.index > 0);
if (hdWalletDiscovered) {
await analytics.sendEventToPostHog(postHogActions.restore.HD_WALLET);
}
},
[analytics, postHogActions.restore.HD_WALLET]
);

const finalizeWalletRestoration = useCallback(async () => {
const wallet = await createWallet();
void sendPostWalletAddAnalytics({
extendedAccountPublicKey: wallet.source.account.extendedAccountPublicKey,
Expand All @@ -88,9 +97,16 @@ export const RestoreWalletProvider = ({ children }: Props): React.ReactElement =
deleteFromLocalStorage('isForgotPasswordFlow');
}
clearSecrets();
};

const next = async () => {
}, [
clearSecrets,
createWallet,
forgotPasswordFlowActive,
postHogActions.restore.WALLET_ADDED,
sendHdWalletAnalyticEvent,
sendPostWalletAddAnalytics
]);

const next = useCallback(async () => {
switch (step) {
case WalletRestoreStep.RecoveryPhrase:
setStep(WalletRestoreStep.Setup);
Expand All @@ -99,9 +115,9 @@ export const RestoreWalletProvider = ({ children }: Props): React.ReactElement =
history.push(walletRoutePaths.assets);
break;
}
};
}, [history, step]);

const back = () => {
const back = useCallback(() => {
switch (step) {
case WalletRestoreStep.RecoveryPhrase:
setFormDirty(false);
Expand All @@ -111,7 +127,7 @@ export const RestoreWalletProvider = ({ children }: Props): React.ReactElement =
setStep(WalletRestoreStep.RecoveryPhrase);
break;
}
};
}, [history, setFormDirty, step]);

const state = useMemo(
() => ({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React from 'react';
import React, { VFC } from 'react';
import { ReactComponent as NeutralFaceIcon } from '../../assets/icons/neutral-face.component.svg';
import { ReactComponent as SadFaceIcon } from '../../assets/icons/sad-face.component.svg';
import styles from './ListEmptyState.module.scss';

export const ListEmptyState = (props: { message: React.ReactNode; icon: 'sad-face' | 'neutral-face' }) => {
export const ListEmptyState: VFC<{ message: React.ReactNode; icon: 'sad-face' | 'neutral-face' }> = (props) => {
const Icon: Record<string, React.ReactElement> = {
'sad-face': <SadFaceIcon className={styles.img} data-testid="sad-face-icon" />,
'neutral-face': <NeutralFaceIcon className={styles.img} data-testid="neutral-face-icon" />
Expand Down

0 comments on commit 946d40a

Please sign in to comment.