Skip to content

Commit 24b7522

Browse files
Merge pull request #500 from mysteriumnetwork/features/clickboarding
Make all redirect links feature aware
2 parents ae114e6 + 3f5a259 commit 24b7522

File tree

7 files changed

+24
-12
lines changed

7 files changed

+24
-12
lines changed

src/Pages/Authenticated/Components/Claim/ClaimButton.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ import { Button } from '../../../../Components/Inputs/Button'
88
import { tequila } from '../../../../api/tequila'
99
import { useState } from 'react'
1010
import errors from '../../../../commons/errors'
11+
import { useAppSelector } from '../../../../commons/hooks'
12+
import { selectors } from '../../../../redux/selectors'
13+
import { urls } from '../../../../commons/urls'
1114

1215
const { initClaim } = tequila
1316

@@ -16,12 +19,13 @@ type Props = {
1619
}
1720

1821
export const ClaimButton = ({ label = 'Claim' }: Props) => {
22+
const config = useAppSelector(selectors.currentConfig)
1923
const [loading, setLoading] = useState(false)
2024

2125
const handleClaim = async () => {
2226
setLoading(true)
2327
try {
24-
const { link } = await initClaim()
28+
const { link } = await initClaim(urls.featureAwareCurrentOrigin(config))
2529
window.location.href = link
2630
} catch (e) {
2731
errors.parseToastError(e)

src/Pages/Authenticated/Onboarding/Password/Heading.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const Title = styled.h1<{ $centered?: boolean }>`
2929
}
3030
`
3131

32-
const Comment = styled.p`
32+
const Comment = styled.div`
3333
color: ${({ theme }) => theme.text.colorMain};
3434
font-size: ${({ theme }) => theme.common.fontSizeNormal};
3535
@media ${devices.tablet} {

src/Pages/Authenticated/Onboarding/PasswordChangePage.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,10 @@ import complexActions from '../../../redux/complex.actions'
2626
import { WelcomePage } from './WelcomePage'
2727
import { Heading } from './Password/Heading'
2828
import { urls } from '../../../commons/urls'
29-
import routes from '../../../constants/routes'
3029
import { media } from '../../../commons/media'
3130
import { useMediaQuery } from 'react-responsive'
31+
import { useAppSelector } from '../../../commons/hooks'
32+
import { selectors } from '../../../redux/selectors'
3233

3334
const { isMobileQuery } = media
3435
const { api } = tequila
@@ -206,6 +207,7 @@ const INITIAL_STATE: State = {
206207
}
207208

208209
export const PasswordChangePage = () => {
210+
const config = useAppSelector(selectors.currentConfig)
209211
const query = useQuery()
210212
const mmnApiKey = query.get('mmnApiKey')
211213
const isMobile = useMediaQuery(isMobileQuery)
@@ -243,7 +245,7 @@ export const PasswordChangePage = () => {
243245
const mmnError = state.mmnError.length > 0
244246

245247
const getLinkAndRedirect = async () => {
246-
const { link } = await tequila.initClickBoarding(urls.currentOrigin(routes.CLICKBOARDING))
248+
const { link } = await tequila.initClickBoarding(urls.featureAwareCurrentOrigin(config))
247249
window.location.href = link
248250
}
249251

src/Pages/Authenticated/Onboarding/RegistrationModal/RegistrationModal.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,6 @@ export const RegistrationModal = ({ show }: Props) => {
156156
}
157157
if (existingOrders.length !== 0) {
158158
const order = existingOrders[0]
159-
console.log('existingOrders[0]', existingOrders[0])
160159
setGateway(order.gatewayName)
161160
setStep(1)
162161
}

src/Pages/Login/MystnodesSSO.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,11 @@ import { tequila } from '../../api/tequila'
1010
import { useMediaQuery } from 'react-responsive'
1111
import { media } from '../../commons/media'
1212
import styled from 'styled-components'
13-
import routes from '../../constants/routes'
1413
import { urls } from '../../commons/urls'
1514
import { useAppSelector } from '../../commons/hooks'
1615
import { selectors } from '../../redux/selectors'
1716
import { configs } from '../../commons/config'
1817
import FEATURES from '../../commons/features'
19-
import { ANDROID_DEEPLINK } from '../../constants/urls'
2018

2119
const { initSSOAuth } = tequila
2220

@@ -28,10 +26,9 @@ const Label = styled.div`
2826
export const MystnodesSSO = () => {
2927
const config = useAppSelector(selectors.currentConfig)
3028
const ssoDisabled = configs.isFeatureEnabled(config, FEATURES.SSO_HIDE.name)
31-
const deeplinkEnabled = configs.isFeatureEnabled(config, FEATURES.SSO_DEEPLINK.name)
3229
const isDesktop = useMediaQuery(media.isDesktopQuery)
3330
const onClick = async () => {
34-
const { link } = await initSSOAuth(deeplinkEnabled ? ANDROID_DEEPLINK : urls.currentOrigin(routes.AUTH_SSO))
31+
const { link } = await initSSOAuth(urls.featureAwareCurrentOrigin(config))
3532
window.location.href = link
3633
}
3734
return (

src/api/tequila.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ import { DEFAULT_PASSWORD, DEFAULT_USERNAME } from '../constants/defaults'
1010
import qs from 'qs'
1111
import { AxiosInstance } from 'axios'
1212
import errorInterceptors from './error.interceptors'
13-
import { urls } from '../commons/urls'
14-
import routes from '../constants/routes'
1513

1614
const buildAxios = (): AxiosInstance => {
1715
const instance = new TequilapiClientFactory(
@@ -99,7 +97,7 @@ const initSSOAuth = async (redirectUrl: string): Promise<LinkResponse> =>
9997
const initClickBoarding = async (redirectUrl: string): Promise<LinkResponse> =>
10098
http.get<LinkResponse>(`/mmn/onboarding?redirect_uri=${encodeURIComponent(redirectUrl)}`).then((r) => r.data)
10199

102-
const initClaim = async (redirectUrl: string = urls.currentOrigin(routes.CLAIM)): Promise<LinkResponse> =>
100+
const initClaim = async (redirectUrl: string): Promise<LinkResponse> =>
103101
http.get<LinkResponse>(`/mmn/claim-link?redirect_uri=${encodeURIComponent(redirectUrl)}`).then((r) => r.data)
104102

105103
const loginWithAuthorizationGrant = async ({ authorizationGrantToken }: { authorizationGrantToken: string }) =>

src/commons/urls.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,20 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*/
7+
import { Config } from 'mysterium-vpn-js'
8+
import { configs } from './config'
9+
import FEATURES from './features'
10+
import { ANDROID_DEEPLINK } from '../constants/urls'
11+
import routes from '../constants/routes'
12+
713
const current = (path?: string): string => `${new URL(window.location.href).origin}${path ? `/#${path}` : ''}`
814

15+
const featureAwareCurrentOrigin = (config: Config): string => {
16+
const deeplinkEnabled = configs.isFeatureEnabled(config, FEATURES.SSO_DEEPLINK.name)
17+
return deeplinkEnabled ? ANDROID_DEEPLINK : current(routes.AUTH_SSO)
18+
}
19+
920
export const urls = {
1021
currentOrigin: current,
22+
featureAwareCurrentOrigin,
1123
}

0 commit comments

Comments
 (0)