76 lines
2.8 KiB
TypeScript
76 lines
2.8 KiB
TypeScript
"use client";
|
|
|
|
import { useEffect, useState } from 'react';
|
|
import axios from 'axios';
|
|
import { PrivyProvider, usePrivy } from '@privy-io/react-auth';
|
|
import Link from 'next/link';
|
|
|
|
const Home: React.FC = () => {
|
|
const { login, ready, user } = usePrivy();
|
|
|
|
useEffect(() => {
|
|
|
|
const setResult = async (result: string, wallet: string) => {
|
|
const params = new URLSearchParams(window.location.search);
|
|
const requestIdFromUrl = params.get('request_id');
|
|
|
|
if(!result.includes('privy')){
|
|
return;
|
|
}
|
|
try {
|
|
await axios({
|
|
method: 'get',
|
|
url: `https://vps.playpoolstudios.com/metahunt/api/launcher/set_request_response.php`,
|
|
withCredentials: false,
|
|
params: {
|
|
id: requestIdFromUrl,
|
|
result: result
|
|
},
|
|
});
|
|
console.log(`https://vps.playpoolstudios.com/metahunt/api/launcher/set_request_response.php?id=${requestIdFromUrl}&result=${result}`);
|
|
await axios({
|
|
method: 'get',
|
|
url: `https://vps.playpoolstudios.com/metahunt/api/launcher/set_wallet.php`,
|
|
withCredentials: false,
|
|
params: {
|
|
id: result,
|
|
wallet: wallet
|
|
},
|
|
});
|
|
} catch (error) {
|
|
console.error('Error making GET request:', error);
|
|
}
|
|
};
|
|
|
|
const requestIdFromUrl = new URLSearchParams(window.location.search).get('request_id');
|
|
|
|
if (!ready) {
|
|
console.log("not ready yet");
|
|
}
|
|
else if (requestIdFromUrl) {
|
|
setResult(user?.id ?? "", user?.wallet?.address ?? "no wallet"); // Replace 'some_result' with the actual result you want to send
|
|
}
|
|
}, [ready, user]);
|
|
|
|
return (
|
|
<div className='flex items-center justify-center bg-black h-screen text-white'>
|
|
{user && ready ? (
|
|
<div className='justify-center grid-flow-row grid items-center flex-col '>
|
|
<h1 className='neon-text mb-4 text-3xl'>Login Success. You may close this now.</h1>
|
|
<Link href="/dashboard">
|
|
<div className='bg-purple-700 w-36 items-center justify-center flex rounded-xl h-10'>Dashboard</div>
|
|
</Link>
|
|
</div>
|
|
|
|
) : (
|
|
<>
|
|
<h1 className='neon-text mb-4 text-3xl'>Complete W3B Wallet Login</h1>
|
|
<button className='bg-green-700 rounded-full p-1 px-4 text-lg m-5' onClick={login}>Login</button>
|
|
</>
|
|
)}
|
|
</div>
|
|
);
|
|
};
|
|
|
|
export default Home;
|