-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: unify codebase of the onboarding and multi-wallet flows
- Loading branch information
1 parent
1dd354c
commit 665d666
Showing
33 changed files
with
446 additions
and
485 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
116 changes: 31 additions & 85 deletions
116
apps/browser-extension-wallet/src/views/browser-view/features/multi-wallet/MultiWallet.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
); |
56 changes: 56 additions & 0 deletions
56
...r-extension-wallet/src/views/browser-view/features/multi-wallet/WalletOnboardingFlows.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 11 additions & 18 deletions
29
...ension-wallet/src/views/browser-view/features/multi-wallet/create-wallet/CreateWallet.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,18 @@ | ||
import React from 'react'; | ||
import { Redirect, Route, Switch } from 'react-router-dom'; | ||
import { Setup } from './steps/Setup'; | ||
import { NewRecoveryPhrase } from './steps/NewRecoveryPhrase'; | ||
import { CreateWalletProvider } from './context'; | ||
import { walletRoutePaths } from '@routes'; | ||
import { Providers } from './types'; | ||
import { WalletCreateStep } from './types'; | ||
|
||
const { | ||
newWallet: { create } | ||
} = walletRoutePaths; | ||
|
||
interface Props { | ||
providers: Providers; | ||
} | ||
|
||
export const CreateWallet = ({ providers }: Props): JSX.Element => ( | ||
<CreateWalletProvider providers={providers}> | ||
<Switch> | ||
<Route path={create.recoveryPhrase} component={NewRecoveryPhrase} /> | ||
<Route path={create.setup} component={Setup} /> | ||
<Redirect from={create.root} to={create.recoveryPhrase} /> | ||
</Switch> | ||
export const CreateWallet = (): JSX.Element => ( | ||
<CreateWalletProvider> | ||
{({ step }) => ( | ||
<> | ||
{(step === WalletCreateStep.RecoveryPhraseWriteDown || step === WalletCreateStep.RecoveryPhraseInput) && ( | ||
<NewRecoveryPhrase /> | ||
)} | ||
{step === WalletCreateStep.Setup && <Setup />} | ||
</> | ||
)} | ||
</CreateWalletProvider> | ||
); |
Oops, something went wrong.