Skip to content

Commit

Permalink
Merge pull request #2018 from stakwork/feature/android-login
Browse files Browse the repository at this point in the history
feat: enabled login for anroid
  • Loading branch information
Rassl authored Aug 10, 2024
2 parents 003f347 + bb8d832 commit 1fa0244
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 34 deletions.
15 changes: 12 additions & 3 deletions src/components/Auth/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { useFeatureFlagStore } from '~/stores/useFeatureFlagStore'
import { useUserStore } from '~/stores/useUserStore'
import { sphinxBridge } from '~/testSphinxBridge'
import { updateBudget } from '~/utils'
import { isWebView } from '~/utils/isWebView'
import { isAndroid, isWebView } from '~/utils/isWebView'

export const AuthGuard = ({ children }: PropsWithChildren) => {
const [unAuthorized, setUnauthorized] = useState(false)
Expand Down Expand Up @@ -96,8 +96,17 @@ export const AuthGuard = ({ children }: PropsWithChildren) => {
// auth checker
useEffect(() => {
const init = async () => {
if (isWebView() || isE2E) {
await handleAuth()
if (isWebView() || isE2E || isAndroid()) {
try {
if (isAndroid()) {
// eslint-disable-next-line no-promise-executor-return
await new Promise((r) => setTimeout(r, 5000))
}

await handleAuth()
} catch (error) {
console.log(error)

Check warning on line 108 in src/components/Auth/index.tsx

View workflow job for this annotation

GitHub Actions / build

Unexpected console statement
}
}

await handleIsAdmin()
Expand Down
34 changes: 3 additions & 31 deletions src/components/SettingsModal/SettingsView/index.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
/* eslint-disable no-restricted-syntax */
/* eslint-disable react/no-unstable-nested-components */
import Tab from '@mui/material/Tab'
import Tabs from '@mui/material/Tabs'
import * as React from 'react'
import { useEffect, useState } from 'react'
import { useState } from 'react'
import styled from 'styled-components'
import { Flex } from '~/components/common/Flex'
import { Text } from '~/components/common/Text'
Expand Down Expand Up @@ -50,37 +49,12 @@ export const SettingsView: React.FC<Props> = ({ onClose }) => {
const [value, setValue] = useState(0)
const [isAdmin] = useUserStore((s) => [s.isAdmin, s.setPubKey])
const appMetaData = useAppStore((s) => s.appMetaData)
const [navigatorData, setNavigatorData] = useState('')

const [counter, setCounter] = useState(0)

const getSettingsLabel = () => (isAdmin ? 'Admin Settings' : 'Settings')

useEffect(() => {
if (counter >= 7) {
const getNavigatorProperties = () => {
let properties = ''

// eslint-disable-next-line guard-for-in
for (const key in navigator) {
try {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
properties += `${key}: ${(navigator as any)[key]}\n`
} catch (e) {
properties += `${key}: [Unable to access]\n`
}
}

return properties
}

setNavigatorData(getNavigatorProperties())
}
}, [counter])

const SettingsHeader = ({ children }: { children: React.ReactNode }) => (
<StyledHeader>
<Flex direction="row" onClick={() => setCounter((val) => val + 1)} pt={3}>
<Flex direction="row" pt={3}>
<StyledText data-testid="setting-label">{getSettingsLabel()}</StyledText>
</Flex>
{children}
Expand All @@ -96,9 +70,7 @@ export const SettingsView: React.FC<Props> = ({ onClose }) => {
{ label: 'Appearance', component: Appearance },
]

return navigatorData ? (
<pre style={{ color: '#f0f8ff' }}>{navigatorData}</pre>
) : (
return (
<Wrapper data-testid="settings-modal" direction="column">
<SettingsHeader>
<StyledTabs aria-label="settings tabs" onChange={handleChange} value={value}>
Expand Down
2 changes: 2 additions & 0 deletions src/utils/isWebView/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ export const isWebView = () => {

return userAgent === 'Sphinx'
}

export const isAndroid = () => navigator.userAgent.includes('Android')

0 comments on commit 1fa0244

Please sign in to comment.