Skip to content

Commit

Permalink
Merge pull request #12612 from brave/fix-add-account-modal-redirects-…
Browse files Browse the repository at this point in the history
…to-accounts-page

fix: remove AddAcount modal accounts page redirect
  • Loading branch information
josheleonard authored Mar 16, 2022
2 parents da8655c + 30ee9e5 commit 26cf776
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ export interface Props {
onAddHardwareAccounts: (selected: BraveWallet.HardwareWalletAccount[]) => void
getBalance: (address: string) => Promise<string>
onSetImportError: (hasError: boolean) => void
onRouteBackToAccounts: () => void
hasImportError: boolean
accounts: WalletAccountType[]
tab: AddAccountNavTypes
Expand All @@ -70,8 +69,7 @@ const AddAccountModal = (props: Props) => {
onAddHardwareAccounts,
getBalance,
onImportAccountFromJson,
onSetImportError,
onRouteBackToAccounts
onSetImportError
} = props

const [importOption, setImportOption] = React.useState<string>('key')
Expand Down Expand Up @@ -122,7 +120,6 @@ const AddAccountModal = (props: Props) => {
const onClickCreateAccount = () => {
if (tab === 'create') {
onCreateAccount(accountName, selectedAccountType?.coin || BraveWallet.CoinType.ETH)
onRouteBackToAccounts()
return
}
if (tab === 'import') {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react'
import { Route, useHistory, useParams } from 'react-router-dom'
import { Route, useHistory, useLocation, useParams } from 'react-router-dom'
import { StyledWrapper } from './style'
import {
BraveWallet,
Expand Down Expand Up @@ -87,6 +87,7 @@ export interface Props {
}

const CryptoView = (props: Props) => {
const { pathname: walletLocation } = useLocation()
let history = useHistory()
const {
onLockWallet,
Expand Down Expand Up @@ -204,24 +205,17 @@ const CryptoView = (props: Props) => {
}

const onCloseAddModal = () => {
history.push(`${WalletRoutes.Accounts}`)
if (walletLocation.includes(WalletRoutes.Accounts)) {
history.push(WalletRoutes.Accounts)
}
onHideAddModal()
}

const onClickAddAccount = (tabId: AddAccountNavTypes) => () => {
if (tabId === 'create') {
history.push(`${WalletRoutes.AddAccountModal}`)
setAddAccountModalTab(tabId)
return
}
setAddAccountModalTab(tabId)
onShowAddModal()
}

const onRouteBack = () => {
history.push(`${WalletRoutes.Accounts}`)
}

const selectAsset = (asset: BraveWallet.BlockchainToken | undefined) => {
if (asset) {
history.push(`${WalletRoutes.Portfolio}/${asset.symbol}`)
Expand Down Expand Up @@ -368,7 +362,6 @@ const CryptoView = (props: Props) => {
accounts={accounts}
selectedNetwork={selectedNetwork}
onClose={onCloseAddModal}
onRouteBackToAccounts={onRouteBack}
onCreateAccount={onCreateAccount}
onImportAccount={onImportAccount}
isFilecoinEnabled={isFilecoinEnabled}
Expand Down
3 changes: 3 additions & 0 deletions components/brave_wallet_ui/page/container.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,9 @@ function Container (props: Props) {

const onCreateAccount = (name: string, coin: BraveWallet.CoinType) => {
const created = props.walletPageActions.addAccount({ accountName: name, coin: coin })
if (walletLocation.includes(WalletRoutes.Accounts)) {
history.push(WalletRoutes.Accounts)
}
if (created) {
onHideAddModal()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,10 +204,6 @@ const CryptoStoryView = (props: Props) => {
alert('Will Nav to brave://settings/wallet')
}

const onRouteBackToAccounts = () => {
// Does nothing in storybook
}

const onClickRetryTransaction = () => {
// Does nothing in storybook
alert('Will retry transaction')
Expand Down Expand Up @@ -363,7 +359,6 @@ const CryptoStoryView = (props: Props) => {
onImportAccountFromJson={onImportAccountFromJson}
hasImportError={hasImportError}
onSetImportError={onSetImportError}
onRouteBackToAccounts={onRouteBackToAccounts}
tab={addAccountModalTab}
/>
}
Expand Down

0 comments on commit 26cf776

Please sign in to comment.