Skip to content

Commit

Permalink
feat(sofi-referral): create redirect handler for migration + anon ref…
Browse files Browse the repository at this point in the history
…erral
  • Loading branch information
mrodriguez-bc authored and mperdomo-bc committed Jan 26, 2024
1 parent 09e3e60 commit dc5c93b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import React from 'react'
import { Redirect, RouteComponentProps } from 'react-router-dom'

const SofiReferralComponent: React.FC<RouteComponentProps> = ({ location }) => {
const searchParams = new URLSearchParams(location.search)
const hasAllRequiredJwtParams = ['aesCiphertext', 'aesIV', 'aesTag', 'aesKeyCiphertext'].every(
(param) => searchParams.has(param)
)

let redirectTo = ''
if (hasAllRequiredJwtParams) {
redirectTo = '/sofi'
} else {
redirectTo = 'https://blockchainwallet.page.link/buysofi'
const viewParam = searchParams.get('buy')
if (viewParam) {
redirectTo += `?code=${viewParam}`
}
}

redirectTo += location.search

return <Redirect to={redirectTo} />
}

export default SofiReferralComponent
6 changes: 6 additions & 0 deletions packages/blockchain-wallet-v4-frontend/src/scenes/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ const SofiLanding = React.lazy(() => import('./SofiLanding'))
const SofiSignupSuccess = React.lazy(() => import('./Signup/SofiSignupSuccess'))
const SofiSignupFailure = React.lazy(() => import('./Signup/SofiSignupFailure'))
const SofiVerify = React.lazy(() => import('./Signup/components/SofiVerifySsn'))
const SofiReferral = React.lazy(() => import('./Refer/Sofi'))
const Prove = React.lazy(() => import('./Prove'))
// need to be authed to see this, but uses public layout
const ContinueOnPhone = React.lazy(() => import('./ContinueOnPhone'))
Expand Down Expand Up @@ -122,8 +123,10 @@ const App = ({
})

const isSofi = window.location.pathname === '/sofi'
const isReferral = window.location.pathname === '/refer/sofi'

const sofiParams = isSofi && window.location.search
const referralParams = isReferral && window.location.search
return (
<QueryClientProvider client={queryClient}>
<Provider store={store}>
Expand All @@ -140,6 +143,7 @@ const App = ({
<Switch>
{/* Unauthenticated Wallet routes */}
<Route path='/app-error' component={AppError} />
<Route path='/refer/sofi' component={SofiReferral} exact />
<AuthLayout
path='/account-recovery'
component={VerifyAccountRecovery}
Expand Down Expand Up @@ -353,6 +357,8 @@ const App = ({
hasUkBanner
/>
{isSofi && window.location.replace(`/#/sofi${sofiParams}`)}
{isReferral &&
window.location.replace(`/#/refer/sofi${referralParams}`)}
{isAuthenticated ? <Redirect to='/home' /> : <Redirect to='/login' />}
</Switch>
</Suspense>
Expand Down

0 comments on commit dc5c93b

Please sign in to comment.