Skip to content

Commit

Permalink
Merge branch 'main' into fix/search-debounce
Browse files Browse the repository at this point in the history
  • Loading branch information
rubo authored Sep 13, 2024
2 parents edef772 + dcddf76 commit ae8c58c
Show file tree
Hide file tree
Showing 36 changed files with 1,562 additions and 524 deletions.
1 change: 1 addition & 0 deletions .env.development
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
VITE_API_BASE_URL=http://localhost:3000
VITE_CLERK_PUBLISHABLE_KEY=pk_test_b3B0aW1hbC1jaGlja2VuLTU3LmNsZXJrLmFjY291bnRzLmRldiQ
VITE_LOG_LEVEL=debug
3 changes: 3 additions & 0 deletions .env.staging
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
VITE_API_BASE_URL=https://api-stage.restaking.info
VITE_CLERK_PUBLISHABLE_KEY=pk_test_b3B0aW1hbC1jaGlja2VuLTU3LmNsZXJrLmFjY291bnRzLmRldiQ
VITE_LOG_LEVEL=info
16 changes: 16 additions & 0 deletions amplify.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
version: 1
frontend:
phases:
preBuild:
commands:
- 'npm ci --cache .npm --prefer-offline'
build:
commands:
- '[[ "$AWS_BRANCH" == release* ]] && npm run build || npm run build:stage'
artifacts:
baseDirectory: dist
files:
- '**/*'
cache:
paths:
- '.npm/**/*'
129 changes: 126 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@
"scripts": {
"dev": "vite --host",
"build": "vite build",
"lint": "eslint . --report-unused-disable-directives --max-warnings 0",
"build:stage": "vite build --mode staging",
"preview": "vite preview"
},
"dependencies": {
"@clerk/clerk-react": "^5.4.5",
"@nextui-org/react": "^2.4.6",
"@visx/axis": "^3.10.1",
"@visx/curve": "^3.3.0",
"@visx/event": "^3.3.0",
"@visx/gradient": "^3.3.0",
"@visx/grid": "^3.5.0",
"@visx/group": "^3.3.0",
"@visx/hierarchy": "^3.3.0",
Expand Down
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
Loading

0 comments on commit ae8c58c

Please sign in to comment.