Skip to content
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
11 changes: 6 additions & 5 deletions src/app/(mobile-ui)/home/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import { PEANUT_WALLET_TOKEN_DECIMALS } from '@/constants'
import { PostSignupActionManager } from '@/components/Global/PostSignupActionManager'
import { useWithdrawFlow } from '@/context/WithdrawFlowContext'
import { useClaimBankFlow } from '@/context/ClaimBankFlowContext'
import { useDeviceType, DeviceType } from '@/hooks/useGetDeviceType'

const BALANCE_WARNING_THRESHOLD = parseInt(process.env.NEXT_PUBLIC_BALANCE_WARNING_THRESHOLD ?? '500')
const BALANCE_WARNING_EXPIRY = parseInt(process.env.NEXT_PUBLIC_BALANCE_WARNING_EXPIRY ?? '1814400') // 21 days in seconds
Expand All @@ -50,6 +51,7 @@ export default function Home() {
const [isRewardsModalOpen, setIsRewardsModalOpen] = useState(false)
const { resetFlow: resetClaimBankFlow } = useClaimBankFlow()
const { resetWithdrawFlow } = useWithdrawFlow()
const { deviceType } = useDeviceType()
const [isBalanceHidden, setIsBalanceHidden] = useState(() => {
const prefs = getUserPreferences()
return prefs?.balanceHidden ?? false
Expand Down Expand Up @@ -89,6 +91,7 @@ export default function Home() {
}, [resetClaimBankFlow, resetWithdrawFlow])

useEffect(() => {
if (isFetchingUser) return
// We have some users that didn't have the peanut wallet created
// correctly, so we need to create it
if (address && user && !user.accounts.some((a) => a.type === AccountType.PEANUT_WALLET)) {
Expand All @@ -98,7 +101,7 @@ export default function Home() {
userId: user.user.userId,
})
}
}, [user, address, addAccount])
}, [user, address, isFetchingUser])

// always reset external wallet connection on home page
useEffect(() => {
Expand All @@ -110,9 +113,7 @@ export default function Home() {
// effect for showing iOS PWA Install modal
useEffect(() => {
if (typeof window !== 'undefined') {
const isIOS =
/iPad|iPhone|iPod/.test(navigator.userAgent) ||
(navigator.platform === 'MacIntel' && navigator.maxTouchPoints > 1)
const isIOS = deviceType === DeviceType.IOS
const isStandalone = window.matchMedia('(display-mode: standalone)').matches
const hasSeenModalThisSession = sessionStorage.getItem('hasSeenIOSPWAPromptThisSession')
const redirectUrl = getFromLocalStorage('redirect')
Expand All @@ -131,7 +132,7 @@ export default function Home() {
setShowIOSPWAInstallModal(false)
}
}
}, [user?.hasPwaInstalled, isPostSignupActionModalVisible])
}, [user?.hasPwaInstalled, isPostSignupActionModalVisible, deviceType])

// effect for showing balance warning modal
useEffect(() => {
Expand Down
12 changes: 7 additions & 5 deletions src/components/Setup/Views/SetupPasskey.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { useAuth } from '@/context/authContext'
import { useEffect, useState } from 'react'
import { useRouter } from 'next/navigation'
import * as Sentry from '@sentry/nextjs'
import { WalletProviderType } from '@/interfaces'
import { WalletProviderType, AccountType } from '@/interfaces'
import { WebAuthnError } from '@simplewebauthn/browser'
import Link from 'next/link'
import { getFromLocalStorage } from '@/utils'
Expand All @@ -18,12 +18,14 @@ const SetupPasskey = () => {
const { username, telegramHandle } = useSetupStore()
const { isLoading } = useSetupFlow()
const { handleRegister, address } = useZeroDev()
const { user } = useAuth()
const { user, isFetchingUser } = useAuth()
const { addAccount } = useAuth()
const [error, setError] = useState<string | null>(null)
const router = useRouter()

useEffect(() => {
// Dont try to double add the account
if (isFetchingUser || user?.accounts.some((a) => a.type === AccountType.PEANUT_WALLET)) return
if (address && user) {
addAccount({
accountIdentifier: address,
Expand Down Expand Up @@ -57,15 +59,15 @@ const SetupPasskey = () => {
dispatch(setupActions.setLoading(false))
})
}
}, [address, user])
}, [address, user, isFetchingUser])

return (
<div>
<div className="flex h-full flex-col justify-between gap-11 p-0 md:min-h-32">
<div className="flex h-full flex-col justify-end gap-2 text-center">
<Button
loading={isLoading}
disabled={isLoading}
loading={isLoading || isFetchingUser}
disabled={isLoading || isFetchingUser}
onClick={async () => {
dispatch(setupActions.setLoading(true))
try {
Expand Down
Loading