-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[LW-10194] unify codebase of the onboarding and multi-wallet flows #1140
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,7 +39,7 @@ export enum TxCreationType { | |
} | ||
|
||
export type OnboardingFlows = 'create' | 'restore' | 'hw' | 'forgot_password' | 'onboarding'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you do the same here with the naming? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I want to avoid unnecessary changes in this PR. Once the old onboarding implementation is removed this can be renamed - next PR |
||
export type MultiWalletFlows = 'create' | 'restore' | 'hw'; | ||
export type MultiWalletFlows = 'create' | 'restore' | 'hardware'; | ||
export type PostHogActionsKeys = | ||
| 'SETUP_OPTION_CLICK' | ||
| 'ANALYTICS_AGREE_CLICK' | ||
|
@@ -64,10 +64,9 @@ export type PostHogActionsKeys = | |
| 'RECOVERY_PHRASE_PASTE_READ_MORE_CLICK' | ||
| 'WALLET_ADDED' | ||
| 'HD_WALLET'; | ||
export type PostHogOnboardingActionsValueType = Partial<Record<PostHogActionsKeys, PostHogAction>>; | ||
export type PostHogOnboardingActionsType = Record<OnboardingFlows, PostHogOnboardingActionsValueType>; | ||
export type PostHogMultiWalletActionsValueType = Partial<Record<PostHogActionsKeys, PostHogAction>>; | ||
export type PostHogMultiWalletActionsType = Record<MultiWalletFlows, PostHogMultiWalletActionsValueType>; | ||
export type PostHogActions = Partial<Record<PostHogActionsKeys, PostHogAction>>; | ||
export type PostHogOnboardingActionsType = Record<OnboardingFlows, PostHogActions>; | ||
export type PostHogMultiWalletActionsType = Record<MultiWalletFlows, PostHogActions>; | ||
export type PostHogPersonProperties = { | ||
$set: { | ||
user_tracking_type: UserTrackingType; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,97 +1,43 @@ | ||
/* eslint-disable unicorn/no-null */ | ||
/* eslint-disable react/no-multi-comp */ | ||
import React from 'react'; | ||
import { Route, Switch, useHistory, useRouteMatch } from 'react-router-dom'; | ||
import { Modal } from 'antd'; | ||
|
||
import styles from './MultiWallet.module.scss'; | ||
|
||
import { Home } from './components/Home'; | ||
|
||
import { | ||
WalletSetupConfirmationDialogProvider, | ||
WalletSetupFlow, | ||
WalletSetupFlowProvider, | ||
useWalletSetupConfirmationDialog | ||
} from '@lace/core'; | ||
import { CreateWallet } from './create-wallet'; | ||
import { HardwareWallet } from './hardware-wallet'; | ||
import { RestoreWallet } from './restore-wallet'; | ||
import { walletRoutePaths } from '@routes'; | ||
import { Subject } from 'rxjs'; | ||
import { Wallet } from '@lace/cardano'; | ||
import { NavigationButton } from '@lace/common'; | ||
import { WalletSetupConfirmationDialogProvider, WalletSetupFlow, WalletSetupFlowProvider } from '@lace/core'; | ||
import { useBackgroundPage } from '@providers/BackgroundPageProvider'; | ||
import { walletRoutePaths } from '@routes'; | ||
import { Modal } from 'antd'; | ||
import React from 'react'; | ||
import { useHistory } from 'react-router-dom'; | ||
import styles from './MultiWallet.module.scss'; | ||
import { WalletOnboardingFlows } from './WalletOnboardingFlows'; | ||
import { postHogMultiWalletActions } from '@providers/AnalyticsProvider/analyticsTracker'; | ||
import { Home } from './Home'; | ||
|
||
const { newWallet } = walletRoutePaths; | ||
|
||
interface Props { | ||
shouldShowConfirmationDialog$: Subject<boolean>; | ||
} | ||
|
||
export const SetupHardwareWallet = ({ shouldShowConfirmationDialog$ }: Props): JSX.Element => ( | ||
<HardwareWallet | ||
providers={{ | ||
shouldShowConfirmationDialog$ | ||
}} | ||
/> | ||
); | ||
|
||
export const SetupCreateWallet = ({ shouldShowConfirmationDialog$ }: Props): JSX.Element => ( | ||
<CreateWallet | ||
providers={{ | ||
generateMnemonicWords: Wallet.KeyManagement.util.generateMnemonicWords, | ||
shouldShowConfirmationDialog$ | ||
}} | ||
/> | ||
); | ||
|
||
export const SetupRestoreWallet = ({ shouldShowConfirmationDialog$ }: Props): JSX.Element => ( | ||
<RestoreWallet | ||
providers={{ | ||
shouldShowConfirmationDialog$ | ||
}} | ||
/> | ||
); | ||
|
||
const Component = (): JSX.Element => { | ||
const { path } = useRouteMatch(); | ||
export const MultiWallet = (): JSX.Element => { | ||
const history = useHistory(); | ||
const { page, setBackgroundPage } = useBackgroundPage(); | ||
const { isDialogOpen, withConfirmationDialog, shouldShowDialog$ } = useWalletSetupConfirmationDialog(); | ||
const closeWalletCreation = withConfirmationDialog(() => { | ||
setBackgroundPage(); | ||
history.push(page); | ||
}); | ||
|
||
return ( | ||
<WalletSetupFlowProvider flow={WalletSetupFlow.ADD_WALLET}> | ||
<Modal centered closable={false} footer={null} open={!isDialogOpen} width="100%" className={styles.modal}> | ||
<div className={styles.closeButton}> | ||
<NavigationButton icon="cross" onClick={closeWalletCreation} /> | ||
</div> | ||
<Switch> | ||
<Route | ||
path={newWallet.create.root} | ||
render={() => <SetupCreateWallet shouldShowConfirmationDialog$={shouldShowDialog$} />} | ||
/> | ||
<Route | ||
path={newWallet.hardware.root} | ||
render={() => <SetupHardwareWallet shouldShowConfirmationDialog$={shouldShowDialog$} />} | ||
/> | ||
<Route | ||
path={newWallet.restore.root} | ||
render={() => <SetupRestoreWallet shouldShowConfirmationDialog$={shouldShowDialog$} />} | ||
/> | ||
<Route exact path={`${path}/`} component={Home} /> | ||
</Switch> | ||
</Modal> | ||
<WalletSetupConfirmationDialogProvider> | ||
{({ isDialogOpen, withConfirmationDialog, shouldShowDialog$ }) => ( | ||
<Modal centered closable={false} footer={null} open={!isDialogOpen} width="100%" className={styles.modal}> | ||
<div className={styles.closeButton}> | ||
<NavigationButton | ||
icon="cross" | ||
onClick={withConfirmationDialog(() => { | ||
setBackgroundPage(); | ||
history.push(page); | ||
})} | ||
/> | ||
</div> | ||
<WalletOnboardingFlows | ||
postHogActions={postHogMultiWalletActions} | ||
renderHome={() => <Home />} | ||
setFormDirty={(dirty) => shouldShowDialog$.next(dirty)} | ||
urlPath={walletRoutePaths.newWallet} | ||
/> | ||
</Modal> | ||
)} | ||
</WalletSetupConfirmationDialogProvider> | ||
</WalletSetupFlowProvider> | ||
); | ||
}; | ||
|
||
export const MultiWallet = (): JSX.Element => ( | ||
<WalletSetupConfirmationDialogProvider> | ||
<Component /> | ||
</WalletSetupConfirmationDialogProvider> | ||
); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { useKeyboardShortcut } from '@lace/common'; | ||
import { Redirect, Route, Switch, useRouteMatch } from 'react-router-dom'; | ||
import { CreateWallet } from './create-wallet'; | ||
import { HardwareWallet } from './hardware-wallet'; | ||
import { RestoreWallet } from './restore-wallet'; | ||
import React, { ReactNode, VFC } from 'react'; | ||
import { Flows, WalletOnboardingPostHogActions, SetFormDirty } from './types'; | ||
import { WalletOnboardingProvider } from './walletOnboardingContext'; | ||
|
||
type WalletOnboardingProps = { | ||
aliasEventRequired?: boolean; | ||
flowsEnabled?: boolean; | ||
forgotPasswordFlowActive?: boolean; | ||
postHogActions: WalletOnboardingPostHogActions; | ||
renderHome: () => ReactNode; | ||
setFormDirty?: SetFormDirty; | ||
urlPath: Record<Flows, string>; | ||
}; | ||
|
||
export const WalletOnboardingFlows: VFC<WalletOnboardingProps> = ({ | ||
aliasEventRequired = false, | ||
flowsEnabled = true, | ||
forgotPasswordFlowActive = false, | ||
postHogActions, | ||
renderHome, | ||
setFormDirty = () => void 0, | ||
urlPath | ||
}) => { | ||
useKeyboardShortcut(['Enter'], () => { | ||
const nextBnt: HTMLButtonElement = document.querySelector('[data-testid="wallet-setup-step-btn-next"]'); | ||
const confirmGoBack: HTMLButtonElement = document.querySelector('[data-testid="delete-address-modal-confirm"]'); | ||
|
||
if (confirmGoBack) { | ||
confirmGoBack.click(); | ||
} else if (nextBnt && !nextBnt.getAttribute('disabled')) { | ||
nextBnt.click(); | ||
} | ||
}); | ||
|
||
const { path } = useRouteMatch(); | ||
return ( | ||
<WalletOnboardingProvider value={{ aliasEventRequired, forgotPasswordFlowActive, postHogActions, setFormDirty }}> | ||
<Switch> | ||
<Route exact path={`${path}/`} render={renderHome} /> | ||
{flowsEnabled && ( | ||
<> | ||
<Route path={urlPath.create} component={CreateWallet} /> | ||
<Route path={urlPath.hardware} component={HardwareWallet} /> | ||
<Route path={urlPath.restore} component={RestoreWallet} /> | ||
</> | ||
)} | ||
{!flowsEnabled && <Redirect to={`${path}/`} />} | ||
</Switch> | ||
</WalletOnboardingProvider> | ||
); | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🙏