Skip to content

Commit

Permalink
feature(unlock-app): remove Coinbase WaaS API handling and improve mi…
Browse files Browse the repository at this point in the history
…gration messaging (#15241)
  • Loading branch information
0xTxbi authored Dec 4, 2024
1 parent 2ad2a2f commit b57b86f
Show file tree
Hide file tree
Showing 13 changed files with 36 additions and 811 deletions.
68 changes: 0 additions & 68 deletions unlock-app/app/api/auth/[...nextauth]/route.ts

This file was deleted.

8 changes: 0 additions & 8 deletions unlock-app/app/google-sign-in/page.tsx

This file was deleted.

25 changes: 11 additions & 14 deletions unlock-app/app/providers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import { ConnectModalProvider } from '~/hooks/useConnectModal'
import Privy from '~/config/PrivyProvider'
import LoadingFallback from './Components/LoadingFallback'
import AuthenticationContext from '~/contexts/AuthenticationContext'
import { SessionProvider as NextAuthSessionProvider } from 'next-auth/react'

function makeQueryClient() {
return new QueryClient({
Expand Down Expand Up @@ -55,20 +54,18 @@ export default function Providers({ children }: { children: React.ReactNode }) {
<GlobalWrapper>
<SessionProvider>
<Suspense fallback={<LoadingFallback />}>
<NextAuthSessionProvider>
<ConnectModalProvider>
<AirstackProvider
apiKey={'162b7c4dda5c44afdb0857b6b04454f99'}
<ConnectModalProvider>
<AirstackProvider
apiKey={'162b7c4dda5c44afdb0857b6b04454f99'}
>
<ErrorBoundary
fallback={(props: any) => <ErrorFallback {...props} />}
>
<ErrorBoundary
fallback={(props: any) => <ErrorFallback {...props} />}
>
<ShouldOpenConnectModal />
{children}
</ErrorBoundary>
</AirstackProvider>
</ConnectModalProvider>
</NextAuthSessionProvider>
<ShouldOpenConnectModal />
{children}
</ErrorBoundary>
</AirstackProvider>
</ConnectModalProvider>
<Toaster />
</Suspense>
</SessionProvider>
Expand Down
2 changes: 0 additions & 2 deletions unlock-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
},
"dependencies": {
"@airstack/airstack-react": "0.6.4",
"@coinbase/waas-sdk-web": "3.3.3",
"@crossmint/client-sdk-react-ui": "1.2.2",
"@decent.xyz/box-common": "4.0.3",
"@enzoferey/ethers-error-parser": "0.2.3",
Expand Down Expand Up @@ -45,7 +44,6 @@
"graphql": "16.9.0",
"lottie-react": "2.4.0",
"next": "14.2.18",
"next-auth": "4.24.10",
"node-forge": "1.3.1",
"postmate": "1.5.2",
"qr-scanner": "1.4.2",
Expand Down
99 changes: 0 additions & 99 deletions unlock-app/src/components/interface/connect/EnterCode.tsx

This file was deleted.

7 changes: 0 additions & 7 deletions unlock-app/src/components/legacy-auth/ConnectToPrivy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import { useLogin } from '@privy-io/react-auth'
import { useEffect, useRef } from 'react'
import { LoginModal } from '@privy-io/react-auth'
import { signOut as nextAuthSignOut, useSession } from 'next-auth/react'

interface ConnectToPrivyProps {
userEmail: string
Expand All @@ -16,14 +15,8 @@ export default function ConnectToPrivy({
onNext,
setPrivyConnected,
}: ConnectToPrivyProps) {
const { data: session } = useSession()

const { login } = useLogin({
onComplete: async () => {
// When Privy login is complete, sign out of next-auth session
if (session) {
await nextAuthSignOut({ redirect: false })
}
// Set Privy connection status to true
setPrivyConnected(true)
// Then proceed to next step
Expand Down
40 changes: 0 additions & 40 deletions unlock-app/src/components/legacy-auth/GoogleSignInContent.tsx

This file was deleted.

36 changes: 6 additions & 30 deletions unlock-app/src/components/legacy-auth/MigrateUserCheckout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ import { useState, useEffect } from 'react'
import { useMutation } from '@tanstack/react-query'
import { locksmith } from '~/config/locksmith'
import MigrationFeedback from './MigrationFeedback'
import { UserAccountType } from '~/utils/userAccountType'
import { SignInWithPassword } from './SignInWithPassword'
import { SignInWithCode } from './SignInWithCode'
import { SignInWithGoogle } from './SignInWithGoogle'
import { Placeholder } from '@unlock-protocol/ui'

interface MigrateUserCheckoutProps {
Expand All @@ -20,38 +17,23 @@ export const MigrateUserCheckout = ({
onSignOut,
}: MigrateUserCheckoutProps) => {
const [walletPk, setWalletPk] = useState<string | null>(null)
const [userAccountType, setUserAccountType] = useState<UserAccountType[]>([])
const [isUnlockAccount, setIsUnlockAccount] = useState<boolean>(false)

// Mutation to handle the user account type
const checkUserAccountType = useMutation({
mutationFn: async (email: string) => {
const response = await locksmith.getUserAccountType(email)
// Map the API response to our local enum
const userAccountType =
response.data.userAccountType?.map((type: string) => {
switch (type) {
case 'EMAIL_CODE':
return UserAccountType.EmailCodeAccount
case 'UNLOCK_ACCOUNT':
return UserAccountType.UnlockAccount
case 'GOOGLE_ACCOUNT':
return UserAccountType.GoogleAccount
case 'PASSKEY_ACCOUNT':
return UserAccountType.PasskeyAccount
default:
throw new Error(`Unknown account type: ${type}`)
}
}) || []
return userAccountType
// Check if user has an Unlock 1.0 account type
return response.data.userAccountType?.includes('UNLOCK_ACCOUNT') || false
},
})

// trigger the mutation when component loads
useEffect(() => {
if (userEmail) {
checkUserAccountType.mutate(userEmail, {
onSuccess: (types) => {
setUserAccountType(types)
onSuccess: (isUnlock) => {
setIsUnlockAccount(isUnlock)
},
})
}
Expand All @@ -68,15 +50,9 @@ export const MigrateUserCheckout = ({
)
}

if (userAccountType?.includes(UserAccountType.UnlockAccount)) {
if (isUnlockAccount) {
return <SignInWithPassword userEmail={userEmail} onNext={setWalletPk} />
}
if (userAccountType?.includes(UserAccountType.EmailCodeAccount)) {
return <SignInWithCode email={userEmail} onNext={setWalletPk} />
}
if (userAccountType?.includes(UserAccountType.GoogleAccount)) {
return <SignInWithGoogle onNext={setWalletPk} />
}
return null
}

Expand Down
Loading

0 comments on commit b57b86f

Please sign in to comment.