Skip to content

Commit 40ebfbe

Browse files
nileshdev0707lazycoder1
authored andcommitted
added design for the paywall and optimise the login and register
1 parent e37cb06 commit 40ebfbe

File tree

8 files changed

+229
-112
lines changed

8 files changed

+229
-112
lines changed

src/components/common/apiCalls/jiffyApis.tsx

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -567,9 +567,20 @@ export const getGlobalMetrics = async (selectedNetwork: string, toast: any): Pro
567567
return {} as GlobalCounts;
568568
};
569569

570-
export const getUserOp = async (userOpHash: string, toast: any): Promise<UserOp[]> => {
571-
const response = await fetch(API_URL+'/v0/getUserOp?hash=' + userOpHash, {
572-
headers: { 'x-api-key': 'gFQghtJC6F734nPaUYK8M3ggf9TOpojkbNTH9gR5' },
570+
export const getUserOp = async (userOpHash: string, toast: any, Authorization?: string): Promise<UserOp[]> => {
571+
type Headers = {
572+
"x-api-key": string,
573+
Authorization?: string,
574+
}
575+
const header = {
576+
'x-api-key': 'gFQghtJC6F734nPaUYK8M3ggf9TOpojkbNTH9gR5'
577+
} as Headers;
578+
579+
if (Authorization) {
580+
header['Authorization'] = Authorization
581+
}
582+
const response = await fetch(API_URL + '/v0/getUserOp?hash=' + userOpHash, {
583+
headers: header
573584
});
574585
if (response.status != 200) {
575586
showToast(toast, 'Error fetching data');

src/lib/auth.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,16 @@ export const authOptions = {
9292
// Return true to allow sign in and false to block sign in.
9393
return true;
9494
},
95-
async redirect({baseUrl}: any) {
95+
async redirect(url: any) {
96+
console.log("Url======>", url)
9697
// Return the url to redirect to after successful sign in.
97-
return baseUrl;
98+
return url.url.startsWith(url.baseUrl)
99+
? url.url
100+
: url.baseUrl
98101
},
99102
jwt: jwt,
100103
// async jwt({token, account, profile, user}: any) {
101-
// return await jwt({token, account, profile, user})
104+
// return awaits jwt({token, account, profile, user})
102105
// },
103106
session: manageSession,
104107
// return session; // Make sure to return the modified session

src/pages/_app.tsx

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import React from 'react';
22
import type {ReactElement, ReactNode} from 'react';
3-
import type {GetServerSideProps, NextPage} from 'next';
3+
import type {NextPage} from 'next';
44
import type {AppProps} from 'next/app';
55
import {ConfigProvider} from '@/context/config';
66
import {Analytics} from '@vercel/analytics/react';
77
import '../styles/main.sass';
8+
import ReactGA from 'react-ga4';
9+
import {SessionProvider} from "next-auth/react";
810

911
export type NextPageWithLayout<P = {}, IP = P> = NextPage<P, IP> & {
1012
getLayout?: (page: ReactElement) => ReactNode;
@@ -14,23 +16,12 @@ type AppPropsWithLayout = AppProps & {
1416
Component: NextPageWithLayout;
1517
};
1618

17-
import ReactGA from 'react-ga4';
18-
import {getSession, SessionProvider} from "next-auth/react";
19-
2019
const TRACKING_ID = 'G-8HQ9S4Z1YF';
2120
ReactGA.initialize(TRACKING_ID);
22-
export const getServerSideProps: GetServerSideProps<{}> = async (ctx) => {
23-
const session = await getSession(ctx);
24-
return {
25-
props: {
26-
session,
27-
},
28-
};
29-
}
21+
3022
export default function MyApp({Component, pageProps}: AppPropsWithLayout) {
3123
// Use the layout defined at the page level, if available
3224
const getLayout = Component.getLayout ?? ((page) => page);
33-
3425
return (
3526
<div>
3627
<SessionProvider session={pageProps.session}>

src/views/home/Home.tsx

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,34 @@
11
import Button from '@/components/common/Button';
2-
import Table, { tableDataT } from '@/components/common/table/Table';
2+
import Table, {tableDataT} from '@/components/common/table/Table';
33
import Footer from '@/components/global/footer/Footer';
44
import Navbar from '@/components/global/navbar/Navbar';
55
import RecentMetrics from '@/components/global/recent_metrics/RecentMetrics';
6-
import React, { useState, useEffect } from 'react';
6+
import React, {useState, useEffect} from 'react';
77
import BundlesTable from './bundles_table.json';
88
import BundlersTable from './bundlers_table.json';
99
import PaymastersTable from './paymasters_table.json';
1010
import OperationsTable from './operations_table.json';
1111
import Searchblock from '../../components/global/searchblock/Searchblock';
1212
import NetworkSelector from '@/components/common/NetworkSelector';
13-
import { NETWORK_ICON_MAP } from '@/components/common/constants';
14-
import { getLatestBundles, getLatestUserOps, getTopBundlers, getTopPaymasters } from '@/components/common/apiCalls/jiffyApis';
15-
import { getFee, getTimePassed } from '@/components/common/utils';
16-
import { useConfig } from '../../context/config';
17-
import { ToastContainer, toast } from 'react-toastify';
13+
import {NETWORK_ICON_MAP} from '@/components/common/constants';
14+
import {
15+
getLatestBundles,
16+
getLatestUserOps,
17+
getTopBundlers,
18+
getTopPaymasters
19+
} from '@/components/common/apiCalls/jiffyApis';
20+
import {getFee, getTimePassed} from '@/components/common/utils';
21+
import {useConfig} from '../../context/config';
22+
import {ToastContainer, toast} from 'react-toastify';
1823
import 'react-toastify/dist/ReactToastify.css';
1924
import InfoButton from '@/components/common/InfoButton';
2025
import Header from '@/components/common/Header';
26+
import {session} from "next-auth/core/routes";
27+
import {useSession} from "next-auth/react";
28+
import {useRouter} from "next/router";
2129

2230
function Home() {
23-
const { selectedNetwork, setSelectedNetwork } = useConfig();
31+
const {selectedNetwork, setSelectedNetwork} = useConfig();
2432
const [bundlesTable, setBundlesTable] = useState<tableDataT>(BundlesTable as tableDataT);
2533
const [operationsTable, setOperationsTable] = useState<tableDataT>(OperationsTable as tableDataT);
2634
const [bundlersTable, setBundlersTable] = useState<tableDataT>(BundlersTable as tableDataT);
@@ -112,23 +120,24 @@ function Home() {
112120
});
113121
});
114122
setLoading(false);
115-
setOperationsTable({ ...operationsTable, rows: newRows.slice(0, 5) });
123+
setOperationsTable({...operationsTable, rows: newRows.slice(0, 5)});
116124
setUserOpTableLoading(false);
117125
};
118126

119127
return (
120128
<div>
121-
<Navbar />
129+
<Navbar/>
122130
<section className="py-6">
123131
<div className="container">
124132
<h1 className="mb-2 text-xl font-bold leading-8 md:text-3xl md:mb-4">
125133
UserOp Explorer for{' '}
126-
<a href="https://eips.ethereum.org/EIPS/eip-4337" target="_blank" style={{ textDecoration: 'underline' }}>
134+
<a href="https://eips.ethereum.org/EIPS/eip-4337" target="_blank"
135+
style={{textDecoration: 'underline'}}>
127136
4337
128137
</a>
129138
</h1>
130139
<div>
131-
<Searchblock isNavbar={false} />
140+
<Searchblock isNavbar={false}/>
132141
</div>
133142
</div>
134143
</section>
@@ -138,8 +147,9 @@ function Home() {
138147
icon="/images/cube-unfolded.svg"
139148
headerText="Select network to explore"
140149
infoText="Shows latest Activity for different entities in a chain"
141-
/>
142-
<NetworkSelector selectedNetwork={selectedNetwork} handleNetworkChange={setSelectedNetwork} disabled={loading} />
150+
/>
151+
<NetworkSelector selectedNetwork={selectedNetwork} handleNetworkChange={setSelectedNetwork}
152+
disabled={loading}/>
143153
</div>
144154
</div>
145155
{/* <RecentMetrics selectedNetwork={selectedNetwork} setLoading={setLoading} loading={loading} /> */}
@@ -209,8 +219,8 @@ function Home() {
209219
</div>
210220
</div>
211221
</section>
212-
<ToastContainer />
213-
<Footer />
222+
<ToastContainer/>
223+
<Footer/>
214224
</div>
215225
);
216226
}

src/views/login/login.tsx

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,63 @@
1-
import React, {useState} from 'react';
1+
import React, {useEffect, useState} from 'react';
22
import Image from 'next/image';
33
import logo from '../../../public/images/logo.png';
44
import Link from 'next/link';
55
import MiniFooter from '@/components/global/minifooter';
6-
import {signIn} from "next-auth/react";
6+
import {signIn, useSession} from "next-auth/react";
77
import {useRouter} from "next/router";
88
import Spinner from "@/components/common/Spinner";
9+
import {mockProviders} from "next-auth/client/__tests__/helpers/mocks";
10+
import callbackUrl = mockProviders.github.callbackUrl;
911

1012
const LoginComponent = () => {
13+
const {data: session, status, update} = useSession()
1114
const [email, setEmail] = useState('');
1215
const [password, setPassword] = useState('');
1316
const [successMessage, setSuccessMessage] = useState('');
1417
const router = useRouter();
1518
const [errorMessage, setErrorMessage] = useState('');
1619
const [loading, setLoading] = useState(false);
17-
20+
const {query} = router;
1821
const handleLoginWithGoogle = async () => {
22+
1923
try {
20-
console.log("handleLoginWithGoogle")
2124
setLoading(true)
22-
const googleSignInResponse = await signIn("cognito_google")
25+
26+
const googleSignInResponse = await signIn("cognito_google", {
27+
redirect: false,
28+
callbackUrl: `http://localhost:3000${query?.callBack}`
29+
})
30+
console.log("googleSignInResponse:", googleSignInResponse)
2331
if (googleSignInResponse?.error) {
2432
setErrorMessage(googleSignInResponse.error)
25-
} else {
26-
await router.push('/')
33+
setLoading(false)
2734
}
2835
} catch (error: any) {
2936
console.error('Error initiating Google login:', error);
37+
setLoading(false)
3038
setErrorMessage(error.message)
3139
}
32-
setLoading(false)
3340
};
3441

3542
async function handleLogin() {
3643
setLoading(true)
3744
try {
38-
const signInResponse = await signIn("Credentials_signIn", {email, password, redirect: false,})
45+
const signInResponse = await signIn("Credentials_signIn", {
46+
email,
47+
password,
48+
redirect: false,
49+
callbackUrl: `http://localhost:3000${query?.callBack}`
50+
})
3951
console.log("signInResponse:", signInResponse)
4052
if (signInResponse?.error) {
4153
setErrorMessage(signInResponse.error)
42-
} else {
43-
await router.push('/')
54+
setLoading(false)
4455
}
4556
} catch (error: any) {
4657
console.error('Error initiating cognito login:', error);
4758
setErrorMessage(error.message)
59+
setLoading(false)
4860
}
49-
setLoading(false)
5061
}
5162

5263
// useEffect(() => {

src/views/register/register.tsx

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {Amplify, Auth} from "aws-amplify";
99
import Spinner from "@/components/common/Spinner";
1010
import UserInfo from '../Profile/userInfo'
1111
import TextField from "@mui/material/TextField";
12+
import {useRouter} from "next/router";
1213

1314
const COGNITO_REGION = process.env.NEXT_PUBLIC_COGNITO_REGION;
1415
const LOGIN_REGISTER_COGNITO_CLIENT_ID = process.env.NEXT_PUBLIC_LOGIN_REGISTER_COGNITO_CLIENT_ID;
@@ -35,6 +36,7 @@ const RegisterComponent = () => {
3536
const [successMessage, setSuccessMessage] = useState('');
3637
const [errorMessage, setErrorMessage] = useState('');
3738
const [loading, setLoading] = useState(false);
39+
const {query} = useRouter();
3840
const handleRegistration = async () => {
3941
// Validate confirm password
4042
setErrorMessage('');
@@ -60,7 +62,6 @@ const RegisterComponent = () => {
6062
userPoolId: COGNITO_USER_POOL_ID,
6163
userPoolWebClientId: LOGIN_REGISTER_COGNITO_CLIENT_ID
6264
}
63-
console.log("awsAmplifyConfig:", awsAmplifyConfig)
6465
Amplify.configure(awsAmplifyConfig)
6566
const { name, designation, companyName, receiveUpdates}: userProps = user;
6667
const params = {
@@ -93,7 +94,7 @@ const RegisterComponent = () => {
9394
};
9495
const handleLoginWithGoogle = async () => {
9596
setLoading(true)
96-
await signIn("cognito_google", {redirect: false})
97+
await signIn("cognito_google", {redirect: false, callbackUrl: `http://localhost:3000${query?.callBack}`})
9798
};
9899

99100
const handleUser = async ({validates, user}: any) => {
@@ -114,24 +115,24 @@ const RegisterComponent = () => {
114115
return (
115116
<>
116117
<div
117-
className="Maincontainer bg-dark-600 d-flex justify-content-center align-items-center w-full"
118+
className="w-full Maincontainer bg-dark-600 d-flex justify-content-center align-items-center"
118119
style={{height: 'auto !important', minHeight: '100vh'}}
119120
>
120-
<div className="container w-full pt-6 px-6 gap-20"
121+
<div className="container w-full gap-20 px-6 pt-6"
121122
style={{display: 'flex', justifyContent: 'center', marginTop: "-35px"}}>
122123
<div className="mt-20">
123-
<Image src={logo} alt="logo" className=" text-center"/>
124+
<Image src={logo} alt="logo" className="text-center "/>
124125
<div style={{display: 'flex', alignItems: 'center'}} className="mt-3">
125-
<Image src={check} alt="logo" className=" text-center" style={{marginTop: '-66px'}}/>
126-
<p className="text-white ml-3">
126+
<Image src={check} alt="logo" className="text-center " style={{marginTop: '-66px'}}/>
127+
<p className="ml-3 text-white">
127128
<span style={{color: '#90A4AE'}}>Real-time Monitoring. </span>Track <br/> Ethereum
128129
network hash-rate and
129130
<br/> difficulty in real-time with charts and <br/> historical data.
130131
</p>
131132
</div>
132133
<div style={{display: 'flex', alignItems: 'center'}} className="mt-3">
133-
<Image src={check} alt="logo" className="text-center mt-2" style={{marginTop: '-66px'}}/>
134-
<p className="text-white ml-3">
134+
<Image src={check} alt="logo" className="mt-2 text-center" style={{marginTop: '-66px'}}/>
135+
<p className="ml-3 text-white">
135136
<span style={{color: '#90A4AE'}}>Miner Distribution Analysis.</span>
136137
<br/>
137138
Analyze miner distribution on the
@@ -141,8 +142,8 @@ const RegisterComponent = () => {
141142
</p>
142143
</div>
143144
<div style={{display: 'flex', alignItems: 'center'}} className="mt-3">
144-
<Image src={check} alt="logo" className="text-center mt-2" style={{marginTop: '-66px'}}/>
145-
<p className="text-white ml-3">
145+
<Image src={check} alt="logo" className="mt-2 text-center" style={{marginTop: '-66px'}}/>
146+
<p className="ml-3 text-white">
146147
<span style={{color: '#90A4AE'}}>Miner Distribution Analysis.</span>
147148
<br/>
148149
Analyze miner distribution on the
@@ -153,18 +154,18 @@ const RegisterComponent = () => {
153154
</div>
154155
</div>
155156
<div style={{display: 'flex', alignItems: 'center', justifyContent: 'center'}}>
156-
<div className="sec-box bg-white rounded px-10 mt-8 py-5"
157+
<div className="px-10 py-5 mt-8 bg-white rounded sec-box"
157158
style={{height: 'auto !important', width: '464px'}}>
158-
<p className="text-black text-xl font-weight-bold mt-4 text-center"
159+
<p className="mt-4 text-xl text-center text-black font-weight-bold"
159160
style={{fontSize: '1.5rem'}}>
160161
Register
161162
</p>
162163
{errorMessage && <div
163-
className="font-regular mt-5 relative block w-full rounded-lg bg-red-500 p-2 text-base leading-5 text-white opacity-100">
164+
className="relative block w-full p-2 mt-5 text-base leading-5 text-white bg-red-500 rounded-lg opacity-100 font-regular">
164165
{errorMessage}
165166
</div>}
166167
{successMessage && <div
167-
className="font-regular mt-5 relative block w-full rounded-lg bg-green-500 p-4 text-base leading-5 text-white opacity-100">
168+
className="relative block w-full p-4 mt-5 text-base leading-5 text-white bg-green-500 rounded-lg opacity-100 font-regular">
168169
{successMessage}
169170
</div>}
170171
{loading && <div className={'align-items-center d-flex flex justify-center mt-3'}>
@@ -211,12 +212,12 @@ const RegisterComponent = () => {
211212
/>
212213
<UserInfo handleInfo={handleUser} />
213214
<button
214-
className="text-white font-weight-bold text-center bg-dark-600 w-full rounded py-2 mt-9"
215+
className="w-full py-2 text-center text-white rounded font-weight-bold bg-dark-600 mt-9"
215216
onClick={handleRegistration}
216217
type="button">
217218
REGISTER
218219
</button>
219-
<p className="text-black text-md font-weight-bold mt-9 text-center">
220+
<p className="text-center text-black text-md font-weight-bold mt-9">
220221
By clicking “Create account” or “Continue with Google” or “Continue with Github”, you
221222
agree to the&nbsp;
222223
jiffyscan.xyz
@@ -240,7 +241,7 @@ const RegisterComponent = () => {
240241
</p>
241242

242243
<Link href="/login">
243-
<p className=" text-black text-md font-weight-bold mt-5 text-center">
244+
<p className="mt-5 text-center text-black text-md font-weight-bold">
244245
Already have an account? <span style={{color: '#1976D2'}}>Log in</span>
245246
</p>
246247
</Link>

0 commit comments

Comments
 (0)