Skip to content

Commit

Permalink
cleanup: resources & type errors (#19)
Browse files Browse the repository at this point in the history
* fix: type errors

* move+refacto: campaigns

* move: chain files into modules

* clean: tags

* move: token code

* fix: tags

* cleanup: tokens

* fix: type errors

* cleanup

* clean

* fix: lint

* update: dappkit

* update: lint

* update: lint

* update: workflow

* update: workflow

* remove: extension

* split: workflow

* link runner

* update

* fix

* fix: steps

* fix

* fix

* update: dappkit

* update: dappkit

* fix: dappkit

* update: dappkit

* split: checks VM
  • Loading branch information
clmntsnr authored Jan 28, 2025
1 parent 8717c32 commit 9a1ff8a
Show file tree
Hide file tree
Showing 96 changed files with 990 additions and 974 deletions.
66 changes: 57 additions & 9 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -1,25 +1,73 @@
name: test code quality
name: Check code quality

on:
pull_request:
push:
branches:
- main

defaults:
run:
shell: bash

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
install-dependencies:
if: ${{ always() }}
runs-on: ubuntu-latest
name: 'Dependencies'
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
submodules: recursive

- name: Set up Bun
uses: oven-sh/setup-bun@v2
with:
bun-version: latest

- name: Check dependencies
run: bun install

check-lint:
name: 'Linting'
needs: install-dependencies
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
submodules: recursive

- name: Set up Bun
uses: oven-sh/setup-bun@v2
with:
bun-version: latest

- name: Check dependencies
run: bun install

- name: Check codebase linting
run: bun lint:ci

check-type:
name: 'Typing'
runs-on: ubuntu-latest
needs: check-lint
steps:
- uses: actions/checkout@v3
- name: Checkout repository
uses: actions/checkout@v3
with:
submodules: recursive

- name: Set up Bun
uses: oven-sh/setup-bun@v1
uses: oven-sh/setup-bun@v2
with:
bun-version: latest
- name: Install dependencies

- name: Check dependencies
run: bun install
- name: Lint merkl-api codebase
run: bun lint:ci

- name: Check codebase typing
run: bun typecheck
Binary file removed bun.lockb
Binary file not shown.

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions dist/merkl-app-core/tsconfig.tsbuildinfo

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"@ariakit/react": "^0.4.12",
"@elysiajs/eden": "^1.1.3",
"@lifi/widget": "^3.13.1",
"@merkl/api": "0.10.307",
"@merkl/api": "0.10.347",
"@radix-ui/react-accordion": "^1.2.1",
"@radix-ui/react-scroll-area": "^1.2.0",
"@remix-run/dev": "^2.15.2",
Expand Down
2 changes: 2 additions & 0 deletions src/I18n/en.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//TODO: embed this in merkl config
//@ts-ignore
import clientEn from "../../../../I18n/en";

const en = {
Expand Down
32 changes: 32 additions & 0 deletions src/api/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ function logSize(bytes: number) {
return `[${kb}kb]`;
}

/**
* Eden response structure for a given return type
*/
export type ApiResponse<R> = { data: R; status: number; response: Response };

export async function fetchWithLogs<R, T extends { data: R; status: number; response: Response }>(
call: () => Promise<T>,
) {
Expand All @@ -34,3 +39,30 @@ export async function fetchWithLogs<R, T extends { data: R; status: number; resp

return response;
}

/**
* Fetch resource or throw appropriate error
* @param call callback to api call i.e. () => api.v4.campaigns.index.get()
* @param resource to insert name in errors i.e. Campaigns not found (404)
* @returns return type of api call
*/
export async function safeFetch<R, T extends ApiResponse<R>>(
call: () => Promise<T>,
resource = "Campaign",
): Promise<NonNullable<T["data"]>> {
const { data, status } = await fetchWithLogs(call);

if (status === 404) throw new Response(`${resource} not found`, { status });
if (status === 500) throw new Response(`${resource} unavailable`, { status });
if (data == null) throw new Response(`${resource} unavailable`, { status });
return data;
}

/**
* Wraps the safeFetch function to always declare the same resource name
* @param resourceName i.e. Campaigns
* @returns a safeFetch function without resource name parameters
*/
export function fetchResource<R, T extends ApiResponse<R>>(resourceName: string) {
return (call: () => Promise<T>) => safeFetch<R, T>(call, resourceName);
}
Loading

0 comments on commit 9a1ff8a

Please sign in to comment.