Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Make Magic user sign the ephemeral wallet #13

Merged
merged 2 commits into from
Dec 14, 2023
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
28 changes: 25 additions & 3 deletions src/components/Pages/CallbackPage/CallbackPage.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
import { useCallback, useEffect } from 'react'
import { useCallback, useEffect, useState } from 'react'
import { useNavigate } from 'react-router-dom'
import { ProviderType } from '@dcl/schemas'
import { Loader } from 'decentraland-ui/dist/components/Loader/Loader'
import { getConfiguration, connection } from 'decentraland-connect'
import { useAfterLoginRedirection } from '../../../hooks/redirection'
import { ConnectionModal, ConnectionModalState } from '../../ConnectionModal'
import { getSignature } from '../LoginPage/utils'

const MAGIC_KEY = getConfiguration().magic.apiKey

export const CallbackPage = () => {
const redirectTo = useAfterLoginRedirection()
const navigate = useNavigate()
const [isLoading, setIsLoading] = useState(true)

const getUserSignature = useCallback(async () => {
const connectionData = await connection.connect(ProviderType.MAGIC)
await getSignature(connectionData.account?.toLowerCase() ?? '', connectionData.provider)
}, [])

const logInAndRedirect = useCallback(async () => {
// eslint-disable-next-line @typescript-eslint/naming-convention
Expand All @@ -26,11 +34,16 @@ export const CallbackPage = () => {
try {
await magic?.oauth.getRedirectResult()
// Perform the connection once logged in to store the connection data
await connection.connect(ProviderType.MAGIC)
setIsLoading(false)
await getUserSignature()
// Store the signature using the SSO client
// TODO

if (redirectTo) {
window.location.href = redirectTo
} else {
// Navigate to user or to any other site
// TODO: Navigate to the landing page.
navigate('/user')
}
} catch (error) {
Expand All @@ -43,5 +56,14 @@ export const CallbackPage = () => {
logInAndRedirect()
}, [])

return <Loader active size="huge" />
return isLoading ? (
<Loader active size="huge" />
) : (
<ConnectionModal
open={true}
state={ConnectionModalState.WAITING_FOR_SIGNATURE}
onTryAgain={getUserSignature}
onClose={() => undefined}
/>
)
}
2 changes: 2 additions & 0 deletions src/components/Pages/LoginPage/LoginPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ export const LoginPage = () => {
setConnectionModalState(ConnectionModalState.CONNECTING_WALLET)
try {
const connectionData = await connectToProvider(connectionType)
// This is not reached if Magic is used
setConnectionModalState(ConnectionModalState.WAITING_FOR_SIGNATURE)
await getSignature(connectionData.account?.toLowerCase() ?? '', connectionData.provider)
// TODO: Store the signature using the SSO client
// Do something after logging in
if (redirectTo) {
window.location.href = redirectTo
Expand Down
Loading