Skip to content

Commit

Permalink
Merge branch 'main' into feature/pricing-table
Browse files Browse the repository at this point in the history
  • Loading branch information
Zishan-7 committed Sep 30, 2024
2 parents 4b0bce9 + 0f3a2e0 commit 13e931b
Show file tree
Hide file tree
Showing 12 changed files with 203 additions and 35 deletions.
16 changes: 9 additions & 7 deletions src/@services/AVSService.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import BaseService from './BaseService';

export default class AVSService extends BaseService {
constructor(context) {
super(context);
}

async getAll(pageNumber, pageSize = 10, search, sort, signal) {
const pageIndex = Math.max(0, pageNumber - 1);
const response = await BaseService._get('/avs', {
const response = await this._get('/avs', {
query: { 'page-index': pageIndex, 'page-size': pageSize, search, sort },
signal
});
Expand All @@ -16,7 +20,7 @@ export default class AVSService extends BaseService {
}

async getAVSDetails(address) {
const response = await BaseService._get(`/avs/${address}`);
const response = await this._get(`/avs/${address}`);

if (response.ok) {
return await response.json();
Expand All @@ -27,7 +31,7 @@ export default class AVSService extends BaseService {

async getAVSOperators(address, pageNumber, search, sort, signal) {
const pageIndex = Math.max(0, pageNumber - 1);
const response = await BaseService._get(`/avs/${address}/operators`, {
const response = await this._get(`/avs/${address}/operators`, {
query: {
'page-index': pageIndex,
search,
Expand All @@ -44,7 +48,7 @@ export default class AVSService extends BaseService {
}

async getAVSTotalValue(address) {
const response = await BaseService._get(`/avs/${address}/tvl`);
const response = await this._get(`/avs/${address}/tvl`);

if (response.ok) {
return await response.json();
Expand All @@ -54,9 +58,7 @@ export default class AVSService extends BaseService {
}

async getAVSOperatorsOvertime(address) {
const response = await BaseService._get(
`/avs/${address}/operators/over-time`
);
const response = await this._get(`/avs/${address}/operators/over-time`);

if (response.ok) {
return await response.json();
Expand Down
32 changes: 25 additions & 7 deletions src/@services/BaseService.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
export default class BaseService {
static async #call(endpoint, options) {
#context;

constructor(context) {
if (!context) {
throw new Error('`context` is required');
}

this.#context = context;
}

async #call(endpoint, options) {
const url = new URL(
`${endpoint.startsWith('/') ? '' : '/'}${endpoint}`,
import.meta.env.VITE_API_BASE_URL
Expand All @@ -22,7 +32,7 @@ export default class BaseService {
const request = {
credentials: 'include',
headers: {
Accept: 'application/json',
accept: 'application/json',
'accept-language': 'en-us',
'content-type': `application/json; charset=utf-8`,
...options?.headers
Expand All @@ -31,6 +41,14 @@ export default class BaseService {
signal: options?.signal
};

if (this.#context.session) {
const token = await this.#context.session.getToken();

if (token) {
request.headers.authorization = `Bearer ${token}`;
}
}

if (options?.body != null) {
const isFormData = options.body instanceof FormData;

Expand Down Expand Up @@ -62,7 +80,7 @@ export default class BaseService {
* @param {{body: object, headers: object, query: object}?} options
* @returns {Promise<Response>}
*/
static _delete(endpoint, options) {
_delete(endpoint, options) {
return this.#call(endpoint, { ...options, method: 'delete' });
}

Expand All @@ -72,7 +90,7 @@ export default class BaseService {
* @param {{body: object, headers: object, query: object}?} options
* @returns {Promise<Response>}
*/
static _get(endpoint, options) {
_get(endpoint, options) {
return this.#call(endpoint, { ...options, method: 'get' });
}

Expand All @@ -82,7 +100,7 @@ export default class BaseService {
* @param {{body: object, headers: object, query: object}?} options
* @returns {Promise<Response>}
*/
static _patch(endpoint, options) {
_patch(endpoint, options) {
return this.#call(endpoint, { ...options, method: 'patch' });
}

Expand All @@ -92,7 +110,7 @@ export default class BaseService {
* @param {{body: object, headers: object, query: object}?} options
* @returns {Promise<Response>}
*/
static _post(endpoint, options) {
_post(endpoint, options) {
return this.#call(endpoint, { ...options, method: 'post' });
}

Expand All @@ -102,7 +120,7 @@ export default class BaseService {
* @param {{body: object, headers: object, query: object}?} options
* @returns {Promise<Response>}
*/
static _put(endpoint, options) {
_put(endpoint, options) {
return this.#call(endpoint, { ...options, method: 'put' });
}

Expand Down
8 changes: 6 additions & 2 deletions src/@services/EigenLayerService.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import BaseService from './BaseService';

export default class EigenLayerService extends BaseService {
constructor(context) {
super(context);
}

async getEigenLayerTVLOvertime() {
const response = await BaseService._get(`/eigenlayer/tvl`);
const response = await this._get(`/eigenlayer/tvl`);

if (response.ok) {
return await response.json();
Expand All @@ -12,7 +16,7 @@ export default class EigenLayerService extends BaseService {
}

async getEigenLayerLSTTotalValue() {
const response = await BaseService._get(`/eigenlayer/tvl/lst`);
const response = await this._get(`/eigenlayer/tvl/lst`);

if (response.ok) {
return await response.json();
Expand Down
10 changes: 7 additions & 3 deletions src/@services/LRTService.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import BaseService from './BaseService';

export default class LRTService extends BaseService {
constructor(context) {
super(context);
}

async getAll() {
const response = await BaseService._get('/lrt/all');
const response = await this._get('/lrt/all');

if (response.ok) {
return await response.json();
Expand All @@ -12,7 +16,7 @@ export default class LRTService extends BaseService {
}

async getLatestDelegations() {
const response = await BaseService._get('/lrt/delegations/latest');
const response = await this._get('/lrt/delegations/latest');

if (response.ok) {
return await response.json();
Expand All @@ -22,7 +26,7 @@ export default class LRTService extends BaseService {
}

async getLatest() {
const response = await BaseService._get('/lrt/latest');
const response = await this._get('/lrt/latest');

if (response.ok) {
return await response.json();
Expand Down
12 changes: 8 additions & 4 deletions src/@services/OperatorService.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import BaseService from './BaseService';

export default class OperatorService extends BaseService {
constructor(context) {
super(context);
}

async getAll(pageNumber, pageSize = 10, search, sort, signal) {
const pageIndex = Math.max(0, pageNumber - 1);
const response = await BaseService._get(`operators`, {
const response = await this._get(`operators`, {
query: {
'page-index': pageIndex,
'page-size': pageSize,
Expand All @@ -21,7 +25,7 @@ export default class OperatorService extends BaseService {
}

async getOperator(address) {
const response = await BaseService._get(`operators/${address}`);
const response = await this._get(`operators/${address}`);

if (response.ok) {
return await response.json();
Expand All @@ -31,7 +35,7 @@ export default class OperatorService extends BaseService {
}

async getOperatorTVL(address) {
const response = await BaseService._get(`operators/${address}/tvl`);
const response = await this._get(`operators/${address}/tvl`);

if (response.ok) {
return await response.json();
Expand All @@ -41,7 +45,7 @@ export default class OperatorService extends BaseService {
}

async getRestakerTrend(address) {
const response = await BaseService._get(`operators/${address}/restakers`);
const response = await this._get(`operators/${address}/restakers`);

if (response.ok) {
return await response.json();
Expand Down
10 changes: 6 additions & 4 deletions src/@services/RestakingDashboardService.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import BaseService from './BaseService';

export default class RestakingDashboardService extends BaseService {
constructor(context) {
super(context);
}

async getPromotedOperators() {
const response = await BaseService._get('/rd/promotion/operators');
const response = await this._get('/rd/promotion/operators');

if (response.ok) {
return await response.json();
Expand All @@ -12,9 +16,7 @@ export default class RestakingDashboardService extends BaseService {
}

async getAVSPromotedOperators(address) {
const response = await BaseService._get(
`/rd/promotion/avs/${address}/operators`
);
const response = await this._get(`/rd/promotion/avs/${address}/operators`);

if (response.ok) {
return await response.json();
Expand Down
20 changes: 14 additions & 6 deletions src/@services/ServiceContext.jsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,35 @@
import { createContext, useContext } from 'react';
import { createContext, useContext, useEffect } from 'react';
import AVSService from './AVSService';
import EigenLayerService from './EigenLayerService';
import LRTService from './LRTService';
import OperatorService from './OperatorService';
import RestakingDashboardService from './RestakingDashboardService';
import { useSession } from '@clerk/clerk-react';

export const ServiceContext = createContext();

// eslint-disable-next-line react-refresh/only-export-components
export const useServices = () => useContext(ServiceContext);

export function ServiceProvider({ children }) {
const { session } = useSession();

useEffect(() => {
context.session = session;
}, [session]);

return (
<ServiceContext.Provider value={services}>
{children}
</ServiceContext.Provider>
);
}

const context = {};
const services = {
avsService: new AVSService(),
lrtService: new LRTService(),
operatorService: new OperatorService(),
eigenlayerService: new EigenLayerService(),
rdService: new RestakingDashboardService()
avsService: new AVSService(context),
lrtService: new LRTService(context),
operatorService: new OperatorService(context),
eigenlayerService: new EigenLayerService(context),
rdService: new RestakingDashboardService(context)
};
4 changes: 4 additions & 0 deletions src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ import { ClerkProvider } from '@clerk/clerk-react';
import Home from './home/Home';
import Layout from './shared/Layout';
import log from './shared/logger';
import Login from './onboarding/Login';
import LRT from './lrt/LRT';
import LST from './lst/LST';
import { NextUIProvider } from '@nextui-org/react';
import NotFound from './shared/NotFound';
import OperatorDetails from './operators/OperatorDetails';
import OperatorList from './operators/OperatorList';
import Register from './onboarding/Register';
import { ServiceProvider } from './@services/ServiceContext';
import SubscriptionPlans from './subscription/SubscriptionPlans';
import { ThemeProvider } from './shared/ThemeContext';
Expand All @@ -32,6 +34,8 @@ const router = createBrowserRouter(
<Route element={<OperatorDetails />} path="/operators/:address/:tab?" />
<Route element={<LST />} path="/lst" />
<Route element={<SubscriptionPlans />} path="/subscriptions" />
<Route element={<Login />} path="/login" />
<Route element={<Register />} path="/register" />
<Route element={<NotFound />} path="*" />
</Route>
)
Expand Down
55 changes: 55 additions & 0 deletions src/onboarding/Login.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { Link } from 'react-router-dom';
import { SignIn } from '@clerk/clerk-react';

export default function Login() {
return (
<div className="flex h-full flex-col items-center justify-center gap-y-9">
<div className="flex flex-col gap-y-4 text-center">
<h1 className="font-display text-3xl font-normal text-foreground-1">
Login
</h1>
<p className="text-foreground-2">
Let's sign in to your account or if you don't have one, sign up
</p>
</div>
<div className="flex flex-col items-center justify-center rounded-xl border border-outline bg-content1">
<SignIn
appearance={{
layout: {
socialButtonsPlacement: 'bottom'
},
elements: {
rootBox: 'lg:w-[31rem]',
cardBox: 'lg:w-[31rem]',
card: 'bg-content1 px-5',
headerTitle:
'text-foreground-1 text-3xl font-display font-normal',
headerSubtitle: 'hidden',
socialButtons: 'border rounded-md border-outline py-2',
socialButtonsBlockButtonText__google: 'text-foreground-2',
dividerLine: 'bg-outline',
formFieldLabel: 'text-foreground-1',
formFieldInput:
'bg-transparent !border !border-outline text-white px-4 py-4 focus:!border-foreground-1',
formFieldInputShowPasswordButton: 'text-foreground-2',
formButtonPrimary:
'!border bg-transparent text-secondary after:!bg-none after:border py-3 after:border-secondary hover:bg-content1 hover:border hover:border-focus hover:text-focus',
footer: 'hidden',
footerAction: 'bg-content1',
otpCodeFieldInput: '!border !border-outline text-white',
formResendCodeLink: 'text-foreground-2',
backLink: 'text-foreground-2'
}
}}
/>
<p className="mb-2 text-foreground-2">Don't have an account?</p>
<Link
className="mb-7 cursor-pointer text-foreground-1 hover:underline"
to={'/register'}
>
Create account
</Link>
</div>
</div>
);
}
Loading

0 comments on commit 13e931b

Please sign in to comment.