Skip to content
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

fix(wallet): Transactions Partner Modal Bugs (uplift to 1.74.x) #27076

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ export const _PartnersConsentModal = () => {
isOpen={isOpen}
onClose={() => setIsOpen(false)}
onContinue={() => setIsOpen(false)}
onCancel={() => setIsOpen(false)}
/>
</WalletPageStory>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,12 @@ interface PartnerConsentModalProps {
isOpen: boolean
onClose: () => void
onContinue: () => void
onCancel: () => void
}

export function PartnersConsentModal(
props: Readonly<PartnerConsentModalProps>
) {
const { isOpen, onCancel, onClose, onContinue } = props
const { isOpen, onClose, onContinue } = props

// state
const [termsAccepted, setTermsAccepted] = React.useState(false)
Expand Down Expand Up @@ -98,7 +97,7 @@ export function PartnersConsentModal(
>
<Button
kind='outline'
onClick={onCancel}
onClick={onClose}
>
{getLocale('braveWalletButtonCancel')}
</Button>
Expand Down
245 changes: 143 additions & 102 deletions components/brave_wallet_ui/page/container.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

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

import ProgressRing from '@brave/leo/react/progressRing'

Expand All @@ -16,6 +16,7 @@ import {
isPersistableSessionRoute
} from '../utils/routes-utils'
import { LOCAL_STORAGE_KEYS } from '../common/constants/local-storage-keys'
import { loadTimeData } from '../../common/loadTimeData'

// actions
import * as WalletPageActions from './actions/wallet_page_actions'
Expand All @@ -34,6 +35,7 @@ import {
useSafeWalletSelector
} from '../common/hooks/use-safe-selector'
import { useLocationPathName } from '../common/hooks/use-pathname'
import { useLocalStorage } from '../common/hooks/use_local_storage'

// style
import 'emptykit.css'
Expand Down Expand Up @@ -63,10 +65,14 @@ import { UnlockedWalletRoutes } from './router/unlocked_wallet_routes'
import { Swap } from './screens/swap/swap'
import { SendScreen } from './screens/send/send_screen/send_screen'
import { DevZCash } from './screens/dev-zcash/dev-zcash'
import {
PartnersConsentModal //
} from '../components/desktop/popup-modals/partners_consent_modal/partners_consent_modal'

export const Container = () => {
// routing
const walletLocation = useLocationPathName()
const history = useHistory()

// redux
const dispatch = useDispatch()
Expand All @@ -78,9 +84,7 @@ export const Container = () => {
const isBitcoinEnabled = useSafeWalletSelector(
WalletSelectors.isBitcoinEnabled
)
const isZCashEnabled = useSafeWalletSelector(
WalletSelectors.isZCashEnabled
)
const isZCashEnabled = useSafeWalletSelector(WalletSelectors.isZCashEnabled)

// page selectors (safe)
const mnemonic = useSafePageSelector(PageSelectors.mnemonic)
Expand All @@ -95,6 +99,11 @@ export const Container = () => {

// state
const [sessionRoute, setSessionRoute] = React.useState(initialSessionRoute)
const [showPartnerConsentModal, setShowPartnerConsentModal] =
React.useState(false)

const [acceptedPartnerConsentTerms, setAcceptedPartnerConsentTerms] =
useLocalStorage(LOCAL_STORAGE_KEYS.HAS_ACCEPTED_PARTNER_TERMS, false)

// computed
const walletNotYetCreated = !isWalletCreated || setupStillInProgress
Expand All @@ -103,6 +112,21 @@ export const Container = () => {
: isWalletLocked
? WalletRoutes.Unlock
: sessionRoute || WalletRoutes.PortfolioAssets
const isAndroid = loadTimeData.getBoolean('isAndroid') || false

// Methods
const handleAcceptPartnerConsent = () => {
setAcceptedPartnerConsentTerms(true)
setShowPartnerConsentModal(false)
}

const handleDeclinePartnerConsent = () => {
setShowPartnerConsentModal(false)
// Not able to use history.goBack() in this instance
// since users could manually navigate to brave://wallet/crypto/fund-wallet
// in a new tab and there would be no history to go back to.
history.push(WalletRoutes.Portfolio)
}

// effects
React.useEffect(() => {
Expand All @@ -128,6 +152,16 @@ export const Container = () => {
}
}, [walletLocation, isPanel, mnemonic, dispatch])

React.useEffect(() => {
if (
!isAndroid &&
!acceptedPartnerConsentTerms &&
walletLocation.includes(WalletRoutes.FundWalletPageStart)
) {
setShowPartnerConsentModal(true)
}
}, [isAndroid, acceptedPartnerConsentTerms, walletLocation, history])

// render
if (!hasInitialized) {
return (
Expand All @@ -138,105 +172,112 @@ export const Container = () => {
}

return (
<Switch>
<ProtectedRoute
path={WalletRoutes.Onboarding}
requirement={walletNotYetCreated}
redirectRoute={defaultRedirect}
>
<OnboardingRoutes />
</ProtectedRoute>

{/* Post-onboarding flows */}
<Route
path={WalletRoutes.Restore}
exact={true}
>
<WalletPageLayout>
<WalletSubViewLayout>
<SimplePageWrapper>
<RestoreWallet />
</SimplePageWrapper>
</WalletSubViewLayout>
</WalletPageLayout>
</Route>

<ProtectedRoute
path={WalletRoutes.Unlock}
exact={true}
requirement={isWalletLocked}
redirectRoute={defaultRedirect}
>
<WalletPageWrapper
wrapContentInBox={true}
hideNav={true}
hideHeaderMenu={true}
noBorderRadius={true}
useDarkBackground={isPanel}
<>
<Switch>
<ProtectedRoute
path={WalletRoutes.Onboarding}
requirement={walletNotYetCreated}
redirectRoute={defaultRedirect}
>
<LockScreen />
</WalletPageWrapper>
</ProtectedRoute>

<ProtectedRoute
path={WalletRoutes.Swap}
requirement={!isWalletLocked && !walletNotYetCreated}
redirectRoute={defaultRedirect}
exact={true}
>
<Swap key='swap' />
</ProtectedRoute>

<ProtectedRoute
path={WalletRoutes.Bridge}
requirement={!isWalletLocked && !walletNotYetCreated}
redirectRoute={defaultRedirect}
exact={true}
>
<Swap key='bridge' />
</ProtectedRoute>

<ProtectedRoute
path={WalletRoutes.Send}
requirement={!isWalletLocked && !walletNotYetCreated}
redirectRoute={defaultRedirect}
exact={true}
>
<SendScreen />
</ProtectedRoute>

<ProtectedRoute
path={WalletRoutes.CryptoPage}
requirement={!isWalletLocked && !walletNotYetCreated}
redirectRoute={defaultRedirect}
>
<UnlockedWalletRoutes sessionRoute={sessionRoute} />
</ProtectedRoute>

<ProtectedRoute
path={WalletRoutes.DevBitcoin}
exact={true}
requirement={
!isWalletLocked && !walletNotYetCreated && isBitcoinEnabled
}
redirectRoute={defaultRedirect}
>
<DevBitcoin />
</ProtectedRoute>

<ProtectedRoute
path={WalletRoutes.DevZCash}
exact={true}
requirement={
!isWalletLocked && !walletNotYetCreated && isZCashEnabled
}
redirectRoute={defaultRedirect}
>
<DevZCash />
</ProtectedRoute>

<Redirect to={defaultRedirect} />
</Switch>
<OnboardingRoutes />
</ProtectedRoute>

{/* Post-onboarding flows */}
<Route
path={WalletRoutes.Restore}
exact={true}
>
<WalletPageLayout>
<WalletSubViewLayout>
<SimplePageWrapper>
<RestoreWallet />
</SimplePageWrapper>
</WalletSubViewLayout>
</WalletPageLayout>
</Route>

<ProtectedRoute
path={WalletRoutes.Unlock}
exact={true}
requirement={isWalletLocked}
redirectRoute={defaultRedirect}
>
<WalletPageWrapper
wrapContentInBox={true}
hideNav={true}
hideHeaderMenu={true}
noBorderRadius={true}
useDarkBackground={isPanel}
>
<LockScreen />
</WalletPageWrapper>
</ProtectedRoute>

<ProtectedRoute
path={WalletRoutes.Swap}
requirement={!isWalletLocked && !walletNotYetCreated}
redirectRoute={defaultRedirect}
exact={true}
>
<Swap key='swap' />
</ProtectedRoute>

<ProtectedRoute
path={WalletRoutes.Bridge}
requirement={!isWalletLocked && !walletNotYetCreated}
redirectRoute={defaultRedirect}
exact={true}
>
<Swap key='bridge' />
</ProtectedRoute>

<ProtectedRoute
path={WalletRoutes.Send}
requirement={!isWalletLocked && !walletNotYetCreated}
redirectRoute={defaultRedirect}
exact={true}
>
<SendScreen />
</ProtectedRoute>

<ProtectedRoute
path={WalletRoutes.CryptoPage}
requirement={!isWalletLocked && !walletNotYetCreated}
redirectRoute={defaultRedirect}
>
<UnlockedWalletRoutes sessionRoute={sessionRoute} />
</ProtectedRoute>

<ProtectedRoute
path={WalletRoutes.DevBitcoin}
exact={true}
requirement={
!isWalletLocked && !walletNotYetCreated && isBitcoinEnabled
}
redirectRoute={defaultRedirect}
>
<DevBitcoin />
</ProtectedRoute>

<ProtectedRoute
path={WalletRoutes.DevZCash}
exact={true}
requirement={
!isWalletLocked && !walletNotYetCreated && isZCashEnabled
}
redirectRoute={defaultRedirect}
>
<DevZCash />
</ProtectedRoute>

<Redirect to={defaultRedirect} />
</Switch>
<PartnersConsentModal
isOpen={showPartnerConsentModal}
onClose={handleDeclinePartnerConsent}
onContinue={handleAcceptPartnerConsent}
/>
</>
)
}

Expand Down
Loading
Loading