Skip to content

Commit

Permalink
Desktop Front End Loading Screens
Browse files Browse the repository at this point in the history
  • Loading branch information
Douglashdaniel authored and yrliou committed Nov 4, 2023
1 parent a6cc160 commit 5325b70
Show file tree
Hide file tree
Showing 14 changed files with 150 additions and 52 deletions.
1 change: 1 addition & 0 deletions components/brave_wallet/browser/brave_wallet_constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -1037,6 +1037,7 @@ constexpr webui::LocalizedString kLocalizedStrings[] = {
{"braveWalletPasswordIsMediumStrength",
IDS_BRAVE_WALLET_PASSWORD_IS_MEDIUM_STRENGTH},
{"braveWalletPasswordIsWeak", IDS_BRAVE_WALLET_PASSWORD_IS_WEAK},
{"braveWalletCreatingWallet", IDS_BRAVE_WALLET_CREATING_WALLET},
{"braveWalletOnboardingRecoveryPhraseBackupIntroTitle",
IDS_BRAVE_WALLET_ONBOARDING_RECOVERY_PHRASE_BACKUP_INTRO_TITLE},
{"braveWalletOnboardingRecoveryPhraseBackupIntroDescription",
Expand Down
1 change: 1 addition & 0 deletions components/brave_wallet_ui/constants/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ export interface PageState {
importWalletAttempts: number
walletTermsAcknowledged: boolean
selectedCoinMarket: BraveWallet.CoinMarket | undefined
isCreatingWallet: boolean
}

export interface WalletPageState {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,6 @@ export const {
updateSelectedAsset,
walletBackupComplete,
walletCreated,
walletSetupComplete
walletSetupComplete,
setIsCreatingWallet
} = PageActions
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,10 @@ async function importFromExternalWallet(
handler.on(
WalletPageActions.createWallet.type,
async (store: Store, payload: CreateWalletPayloadType) => {
store.dispatch(WalletPageActions.setIsCreatingWallet(true))
const keyringService = getWalletPageApiProxy().keyringService
const result = await keyringService.createWallet(payload.password)
store.dispatch(WalletPageActions.setIsCreatingWallet(false))
store.dispatch(
WalletPageActions.walletCreated({ mnemonic: result.mnemonic })
)
Expand All @@ -78,12 +80,14 @@ handler.on(
handler.on(
WalletPageActions.restoreWallet.type,
async (store: Store, payload: RestoreWalletPayloadType) => {
store.dispatch(WalletPageActions.setIsCreatingWallet(true))
const keyringService = getWalletPageApiProxy().keyringService
const result = await keyringService.restoreWallet(
payload.mnemonic,
payload.password,
payload.isLegacy
)
store.dispatch(WalletPageActions.setIsCreatingWallet(false))
if (!result.isValidMnemonic) {
store.dispatch(
WalletPageActions.hasMnemonicError(!result.isValidMnemonic)
Expand Down Expand Up @@ -159,23 +163,27 @@ handler.on(WalletPageActions.checkWalletsToImport.type, async (store) => {
handler.on(
WalletPageActions.importFromCryptoWallets.type,
async (store: Store, payload: ImportFromExternalWalletPayloadType) => {
store.dispatch(WalletPageActions.setIsCreatingWallet(true))
const results: ImportWalletErrorPayloadType =
await importFromExternalWallet(
BraveWallet.ExternalWalletType.CryptoWallets,
payload
)
store.dispatch(WalletPageActions.setIsCreatingWallet(false))
store.dispatch(WalletPageActions.setImportWalletError(results))
}
)

handler.on(
WalletPageActions.importFromMetaMask.type,
async (store: Store, payload: ImportFromExternalWalletPayloadType) => {
store.dispatch(WalletPageActions.setIsCreatingWallet(true))
const results: ImportWalletErrorPayloadType =
await importFromExternalWallet(
BraveWallet.ExternalWalletType.MetaMask,
payload
)
store.dispatch(WalletPageActions.setIsCreatingWallet(false))
store.dispatch(WalletPageActions.setImportWalletError(results))
}
)
Expand Down
7 changes: 6 additions & 1 deletion components/brave_wallet_ui/page/reducers/page_reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ const defaultState: PageState = {
isImportWalletsCheckComplete: false,
importWalletAttempts: 0,
walletTermsAcknowledged: false,
selectedCoinMarket: undefined
selectedCoinMarket: undefined,
isCreatingWallet: false
}

export const WalletPageAsyncActions = {
Expand Down Expand Up @@ -196,6 +197,10 @@ export const createPageSlice = (initialState: PageState = defaultState) => {

updateAutoPinEnabled(state, { payload }: PayloadAction<boolean>) {
state.isAutoPinEnabled = payload
},

setIsCreatingWallet(state, { payload }: PayloadAction<boolean>) {
state.isCreatingWallet = payload
}
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,21 @@
// you can obtain one at https://mozilla.org/MPL/2.0/.

import * as React from 'react'
import { useDispatch, useSelector } from 'react-redux'
import { useDispatch } from 'react-redux'

// selectors
import {
useSafePageSelector,
useSafeWalletSelector
} from '../../../../common/hooks/use-safe-selector'
import { PageSelectors } from '../../../selectors'
import { WalletSelectors } from '../../../../common/selectors'

// utils
import { getLocale } from '../../../../../common/locale'

// routes
import { WalletRoutes, WalletState } from '../../../../constants/types'
import { WalletRoutes } from '../../../../constants/types'

// actions
import { WalletPageActions } from '../../../actions'
Expand All @@ -25,6 +33,7 @@ import {
} from '../../../../components/shared/password-input/new-password-input'
import { OnboardingNewWalletStepsNavigation } from '../components/onboarding-steps-navigation/onboarding-steps-navigation'
import { CenteredPageLayout } from '../../../../components/desktop/centered-page-layout/centered-page-layout'
import { CreatingWallet } from '../creating_wallet/creating_wallet'

// styles
import {
Expand All @@ -48,9 +57,8 @@ export const OnboardingCreatePassword = (

// redux
const dispatch = useDispatch()
const isWalletCreated = useSelector(
({ wallet }: { wallet: WalletState }) => wallet.isWalletCreated
)
const isWalletCreated = useSafeWalletSelector(WalletSelectors.isWalletCreated)
const isCreatingWallet = useSafePageSelector(PageSelectors.isCreatingWallet)

// state
const [isValid, setIsValid] = React.useState(false)
Expand All @@ -73,10 +81,14 @@ export const OnboardingCreatePassword = (

// effects
React.useEffect(() => {
if (isWalletCreated) {
if (!isCreatingWallet && isWalletCreated) {
onWalletCreated()
}
}, [isWalletCreated, onWalletCreated])
}, [isWalletCreated, onWalletCreated, isCreatingWallet])

if (isCreatingWallet) {
return <CreatingWallet />
}

// render
return (
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright (c) 2023 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 https://mozilla.org/MPL/2.0/.
import styled from 'styled-components'
import ProgressRing from '@brave/leo/react/progressRing'
import * as leo from '@brave/leo/tokens/css'

// Shared Styles
import { Text } from '../../../../components/shared/style'

export const LoadingIcon = styled(ProgressRing)`
--leo-progressring-size: 40px;
--leo-progressring-background-color: rgba(217, 217, 217, 1);
--leo-progressring-color: ${leo.color.icon.interactive};
margin-bottom: 20px;
`

export const CreatingWalletText = styled(Text)`
font-weight: 500;
line-height: 28px;
color: ${leo.color.text.primary};
`
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright (c) 2023 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 https://mozilla.org/MPL/2.0/.

import * as React from 'react'

// Utils
import { getLocale } from '../../../../../common/locale'

// Components
import {
CenteredPageLayout
} from
'../../../../components/desktop/centered-page-layout/centered-page-layout'

// Styled Components
import { CreatingWalletText, LoadingIcon } from './creating_wallet.style'
import { StyledWrapper, MainWrapper } from '../onboarding.style'
import { Column } from '../../../../components/shared/style'

export const CreatingWallet = () => {
return (
<CenteredPageLayout>
<MainWrapper>
<StyledWrapper>
<Column
fullWidth={true}
padding='200px 0px'
>
<LoadingIcon />
<CreatingWalletText>
{getLocale('braveWalletCreatingWallet')}
</CreatingWalletText>
</Column>
</StyledWrapper>
</MainWrapper>
</CenteredPageLayout>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,16 @@
// you can obtain one at https://mozilla.org/MPL/2.0/.

import * as React from 'react'
import { useSelector } from 'react-redux'
import { Redirect, Route, Switch, useHistory, useLocation } from 'react-router'

// selectors
import {
useSafePageSelector, //
useSafeWalletSelector
} from '../../../common/hooks/use-safe-selector'
import { PageSelectors } from '../../selectors'
import { WalletSelectors } from '../../../common/selectors'

// utils
import { useApiProxy } from '../../../common/hooks/use-api-proxy'

Expand All @@ -20,12 +27,7 @@ import { OnboardingImportOrRestoreWallet } from './import-or-restore-wallet/impo
import { OnboardingRestoreFromRecoveryPhrase } from './restore-from-recovery-phrase/restore-from-recovery-phrase'

// types
import {
BraveWallet,
PageState,
WalletRoutes,
WalletState
} from '../../../constants/types'
import { BraveWallet, WalletRoutes } from '../../../constants/types'
import { OnboardingSuccess } from './onboarding-success/onboarding-success'
import { OnboardingConnectHardwareWallet } from './connect-hardware/onboarding-connect-hardware-wallet'

Expand All @@ -38,12 +40,11 @@ export const OnboardingRoutes = () => {
const { braveWalletP3A } = useApiProxy()

// redux
const isWalletCreated = useSelector(
({ wallet }: { wallet: WalletState }) => wallet.isWalletCreated
)
const termsAcknowledged = useSelector(
({ page }: { page: PageState }) => page.walletTermsAcknowledged
const isWalletCreated = useSafeWalletSelector(WalletSelectors.isWalletCreated)
const termsAcknowledged = useSafePageSelector(
PageSelectors.walletTermsAcknowledged
)
const isCreatingWallet = useSafePageSelector(PageSelectors.isCreatingWallet)

// methods
const goToConnectHardware = React.useCallback(() => {
Expand Down Expand Up @@ -75,6 +76,9 @@ export const OnboardingRoutes = () => {
}
}, [location])

// computed
const showOnboardingRestore = !isWalletCreated || isCreatingWallet

// render
return (
<Switch>
Expand Down Expand Up @@ -126,7 +130,7 @@ export const OnboardingRoutes = () => {
</Route>
)}

{!isWalletCreated && (
{showOnboardingRestore && (
<Route
path={WalletRoutes.OnboardingRestoreWallet}
exact
Expand All @@ -138,7 +142,7 @@ export const OnboardingRoutes = () => {
</Route>
)}

{!isWalletCreated && (
{showOnboardingRestore && (
<Route
path={WalletRoutes.OnboardingImportMetaMask}
exact
Expand All @@ -150,7 +154,7 @@ export const OnboardingRoutes = () => {
</Route>
)}

{!isWalletCreated && (
{showOnboardingRestore && (
<Route
path={WalletRoutes.OnboardingImportMetaMaskSeed}
exact
Expand All @@ -162,7 +166,7 @@ export const OnboardingRoutes = () => {
</Route>
)}

{!isWalletCreated && (
{showOnboardingRestore && (
<Route
path={WalletRoutes.OnboardingImportCryptoWallets}
exact
Expand All @@ -174,7 +178,7 @@ export const OnboardingRoutes = () => {
</Route>
)}

{!isWalletCreated && (
{showOnboardingRestore && (
<Route
path={WalletRoutes.OnboardingImportCryptoWalletsSeed}
exact
Expand Down
Loading

0 comments on commit 5325b70

Please sign in to comment.