-
Notifications
You must be signed in to change notification settings - Fork 868
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13068 from brave/chore-refactor-wallet-pages-routing
Reduce wallet page routing complexity
- Loading branch information
Showing
49 changed files
with
3,536 additions
and
3,274 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
57 changes: 57 additions & 0 deletions
57
components/brave_wallet_ui/common/hooks/use-password-strength.ts
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,57 @@ | ||
// Copyright (c) 2022 The Brave Authors. All rights reserved. | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
// you can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
import * as React from 'react' | ||
import { useLib } from './useLib' | ||
|
||
export const usePasswordStrength = () => { | ||
// custom hooks | ||
const { isStrongPassword: checkIsStrongPassword } = useLib() | ||
|
||
// state | ||
const [password, setPassword] = React.useState<string>('') | ||
const [confirmedPassword, setConfirmedPassword] = React.useState<string>('') | ||
const [isStrongPassword, setIsStrongPassword] = React.useState<boolean>(false) | ||
|
||
const onPasswordChanged = React.useCallback(async (value: string) => { | ||
setPassword(value) | ||
const isStrong = await checkIsStrongPassword(value) | ||
setIsStrongPassword(isStrong) | ||
}, []) | ||
|
||
const hasPasswordError = React.useMemo(() => { | ||
if (password === '') { | ||
return false | ||
} | ||
return !isStrongPassword | ||
}, [password, isStrongPassword]) | ||
|
||
const hasConfirmedPasswordError = React.useMemo(() => { | ||
if (confirmedPassword === '') { | ||
return false | ||
} else { | ||
return confirmedPassword !== password | ||
} | ||
}, [confirmedPassword, password]) | ||
|
||
const isValid = !( | ||
hasConfirmedPasswordError || | ||
hasPasswordError || | ||
password === '' || | ||
confirmedPassword === '' | ||
) | ||
|
||
return { | ||
confirmedPassword, | ||
password, | ||
onPasswordChanged, | ||
setConfirmedPassword, | ||
isStrongPassword, | ||
isValid, | ||
hasConfirmedPasswordError, | ||
hasPasswordError, | ||
checkIsStrongPassword | ||
} | ||
} |
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
37 changes: 37 additions & 0 deletions
37
...s/brave_wallet_ui/components/desktop/popup-modals/add-account-modal/add-account-modal.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,37 @@ | ||
// Copyright (c) 2022 The Brave Authors. All rights reserved. | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
// you can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
import * as React from 'react' | ||
import { Redirect, Route, Switch } from 'react-router' | ||
|
||
// types | ||
import { WalletRoutes } from '../../../../constants/types' | ||
|
||
// components | ||
import { AddHardwareAccountModal } from './add-hardware-account-modal' | ||
import { ImportAccountModal } from './add-imported-account-modal' | ||
import { CreateAccountModal } from './create-account-modal' | ||
|
||
export const AddAccountModal = () => { | ||
return ( | ||
<Switch> | ||
|
||
<Route path={WalletRoutes.AddHardwareAccountModal} exact> | ||
<AddHardwareAccountModal /> | ||
</Route> | ||
|
||
<Route path={WalletRoutes.ImportAccountModal} exact> | ||
<ImportAccountModal /> | ||
</Route> | ||
|
||
<Route path={WalletRoutes.CreateAccountModal} exact> | ||
<CreateAccountModal /> | ||
</Route> | ||
|
||
<Redirect to={WalletRoutes.CreateAccountModalStart} /> | ||
|
||
</Switch> | ||
) | ||
} |
101 changes: 101 additions & 0 deletions
101
...allet_ui/components/desktop/popup-modals/add-account-modal/add-hardware-account-modal.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,101 @@ | ||
// Copyright (c) 2022 The Brave Authors. All rights reserved. | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
// you can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
import * as React from 'react' | ||
import { useDispatch, useSelector } from 'react-redux' | ||
import { useHistory, useParams } from 'react-router' | ||
|
||
// utils | ||
import { getLocale } from '$web-common/locale' | ||
|
||
// options | ||
import { CreateAccountOptions } from '../../../../options/create-account-options' | ||
|
||
// types | ||
import { CreateAccountOptionsType, WalletRoutes, WalletState } from '../../../../constants/types' | ||
|
||
// actions | ||
import { WalletPageActions } from '../../../../page/actions' | ||
|
||
// components | ||
import { DividerLine } from '../../../extension' | ||
import PopupModal from '..' | ||
import { HardwareWalletConnect } from './hardware-wallet-connect' | ||
import { SelectAccountType } from './select-account-type/select-account-type' | ||
|
||
// style | ||
import { | ||
StyledWrapper | ||
} from './style' | ||
|
||
interface Params { | ||
accountTypeName: string | ||
} | ||
|
||
export const AddHardwareAccountModal = () => { | ||
// routing | ||
const history = useHistory() | ||
const { accountTypeName } = useParams<Params>() | ||
|
||
// redux | ||
const dispatch = useDispatch() | ||
const isFilecoinEnabled = useSelector(({ wallet }: { wallet: WalletState }) => wallet.isFilecoinEnabled) | ||
const isSolanaEnabled = useSelector(({ wallet }: { wallet: WalletState }) => wallet.isSolanaEnabled) | ||
|
||
// memos | ||
const createAccountOptions = React.useMemo( | ||
() => CreateAccountOptions(isFilecoinEnabled, isSolanaEnabled), | ||
[isFilecoinEnabled, isSolanaEnabled] | ||
) | ||
|
||
const selectedAccountType: CreateAccountOptionsType | undefined = React.useMemo(() => { | ||
return createAccountOptions.find((option) => { | ||
return option.name.toLowerCase() === accountTypeName?.toLowerCase() | ||
}) | ||
}, [createAccountOptions, accountTypeName]) | ||
|
||
// methods | ||
const setImportError = React.useCallback((hasError: boolean) => { | ||
dispatch(WalletPageActions.setImportAccountError(hasError)) | ||
}, []) | ||
|
||
const closeModal = React.useCallback(() => { | ||
setImportError(false) | ||
history.push(WalletRoutes.Accounts) | ||
}, []) | ||
|
||
const onSelectAccountType = React.useCallback((accountType: CreateAccountOptionsType) => () => { | ||
history.push(WalletRoutes.AddHardwareAccountModal.replace(':accountTypeName?', accountType.name.toLowerCase())) | ||
}, []) | ||
|
||
// render | ||
return ( | ||
<PopupModal | ||
title={getLocale('braveWalletAddAccountImportHardware')} | ||
onClose={closeModal} | ||
> | ||
|
||
<DividerLine /> | ||
|
||
{selectedAccountType && | ||
<StyledWrapper> | ||
<HardwareWalletConnect | ||
selectedAccountType={selectedAccountType} | ||
onSuccess={closeModal} | ||
/> | ||
</StyledWrapper> | ||
} | ||
|
||
{!selectedAccountType && | ||
<SelectAccountType | ||
onSelectAccountType={onSelectAccountType} | ||
buttonText={getLocale('braveWalletAddAccountConnect')} | ||
/> | ||
} | ||
</PopupModal> | ||
) | ||
} | ||
|
||
export default AddHardwareAccountModal |
Oops, something went wrong.