Skip to content

Commit

Permalink
feat(dapp-console): disable claim flow when user does not have github…
Browse files Browse the repository at this point in the history
… account linked (ethereum-optimism#465)
  • Loading branch information
tremarkley authored Sep 6, 2024
1 parent 4acee11 commit 36ebd5e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 15 deletions.
4 changes: 2 additions & 2 deletions apps/dapp-console/app/faucet/components/ClaimButton.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { apiClient } from '@/app/helpers/apiClient'
import { useConnectedWallet } from '@/app/hooks/useConnectedWallet'
import { Button } from '@eth-optimism/ui-components/src/components/ui/button/button'
import { usePrivy } from '@privy-io/react-auth'
import { forwardRef } from 'react'
import { Authentications } from '@/app/faucet/types'
import {
getOnchainAuthentication,
hasAuthentication,
} from '@/app/faucet/helpers'
import { trackFaucetClaim } from '@/app/event-tracking/mixpanel'
import { useFaucetVerifications } from '@/app/hooks/useFaucetVerifications'

interface ClaimButtonProps {
isDisabled: boolean
Expand Down Expand Up @@ -40,7 +40,7 @@ const ClaimButton = forwardRef<HTMLButtonElement, ClaimButtonProps>(
ref,
) => {
const { connectedWallet } = useConnectedWallet()
const { authenticated } = usePrivy()
const { authenticated } = useFaucetVerifications()

const { mutateAsync: claimOnchain } =
apiClient.faucet.onChainClaims.useMutation()
Expand Down
4 changes: 1 addition & 3 deletions apps/dapp-console/app/faucet/components/FaucetContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import { SuccessDialog } from '@/app/faucet/components/SuccessDialog'
import { useConnectedWallet } from '@/app/hooks/useConnectedWallet'
import { generateClaimSignature } from '@/app/faucet/helpers'
import { getFaucetNetworks } from '@/app/constants/faucet'
import { usePrivy } from '@privy-io/react-auth'
import { ClaimButton } from '@/app/faucet/components/ClaimButton'
import { useFaucetVerifications } from '@/app/hooks/useFaucetVerifications'
import { Alert } from '@eth-optimism/ui-components/src/components/ui/alert/alert'
Expand All @@ -30,9 +29,8 @@ import { useFeatureFlag } from '@/app/hooks/useFeatureFlag'

const FaucetContent = () => {
const { connectedWallet } = useConnectedWallet()
const { faucetAuthentications } = useFaucetVerifications()
const { authenticated, faucetAuthentications } = useFaucetVerifications()

const { authenticated } = usePrivy()
const { secondsUntilNextDrip, refetchNextDrips } = useFaucetVerifications()
const { unavailableNetworksChainIds } = useFaucetNetworks()

Expand Down
30 changes: 20 additions & 10 deletions apps/dapp-console/app/hooks/useFaucetVerifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { usePrivy } from '@privy-io/react-auth'
import { useAuth } from '@/app/hooks/useAuth'

const useFaucetVerifications = () => {
const { authenticated, ready } = usePrivy()
const { authenticated: privyAuthenticated, ready } = usePrivy()
const { userNeedsGithubAuth } = useAuth()
const { connectedWallet } = useConnectedWallet()
const walletAddress = connectedWallet?.address ?? ''
Expand All @@ -18,7 +18,7 @@ const useFaucetVerifications = () => {
address: walletAddress,
},
{
enabled: !!walletAddress && !!authenticated,
enabled: !!walletAddress && !!privyAuthenticated,
refetchOnWindowFocus: false,
},
)
Expand All @@ -29,7 +29,10 @@ const useFaucetVerifications = () => {
authMode: 'COINBASE_VERIFICATION',
walletAddress: walletAddress,
},
{ enabled: !!isCoinbaseVerified && !!walletAddress && !!authenticated },
{
enabled:
!!isCoinbaseVerified && !!walletAddress && !!privyAuthenticated,
},
)

// EAS check
Expand All @@ -39,7 +42,7 @@ const useFaucetVerifications = () => {
address: walletAddress,
},
{
enabled: !!walletAddress && !!authenticated,
enabled: !!walletAddress && !!privyAuthenticated,
refetchOnWindowFocus: false,
},
)
Expand All @@ -50,7 +53,7 @@ const useFaucetVerifications = () => {
authMode: 'ATTESTATION',
walletAddress: walletAddress,
},
{ enabled: !!isAttested && !!walletAddress && !!authenticated },
{ enabled: !!isAttested && !!walletAddress && !!privyAuthenticated },
)

// Gitcoin check
Expand All @@ -60,7 +63,7 @@ const useFaucetVerifications = () => {
address: walletAddress,
},
{
enabled: !!walletAddress && !!authenticated,
enabled: !!walletAddress && !!privyAuthenticated,
refetchOnWindowFocus: false,
},
)
Expand All @@ -71,7 +74,9 @@ const useFaucetVerifications = () => {
authMode: 'GITCOIN_PASSPORT',
walletAddress: walletAddress,
},
{ enabled: !!isGitcoinVerified && !!walletAddress && !!authenticated },
{
enabled: !!isGitcoinVerified && !!walletAddress && !!privyAuthenticated,
},
)

// World ID check
Expand All @@ -80,7 +85,7 @@ const useFaucetVerifications = () => {
refetch: refetchWorldId,
isFetching: isWorldIDUserLoading,
} = apiClient.auth.isWorldIdUser.useQuery(undefined, {
enabled: !!authenticated,
enabled: !!privyAuthenticated,
refetchOnWindowFocus: false,
})

Expand All @@ -89,15 +94,15 @@ const useFaucetVerifications = () => {
{
authMode: 'WORLD_ID',
},
{ enabled: !!isWorldIdUser && !!authenticated },
{ enabled: !!isWorldIdUser && !!privyAuthenticated },
)

const { data: nextDripsPrivy, refetch: refetchPrivyNextDrips } =
apiClient.faucet.nextDrips.useQuery(
{
authMode: 'PRIVY',
},
{ enabled: !!authenticated && !userNeedsGithubAuth },
{ enabled: !!privyAuthenticated && !userNeedsGithubAuth },
)

const isAuthenticationLoading =
Expand Down Expand Up @@ -141,12 +146,17 @@ const useFaucetVerifications = () => {
secondsUntilNextDrip = nextDripsPrivy?.secondsUntilNextDrip || 0
}

const authenticated =
Object.values(faucetAuthentications).some((auth) => auth === true) ||
(ready && privyAuthenticated && !userNeedsGithubAuth)

return {
faucetAuthentications,
secondsUntilNextDrip,
refetchWorldId,
refetchNextDrips,
isAuthenticationLoading,
authenticated,
}
}

Expand Down

0 comments on commit 36ebd5e

Please sign in to comment.