Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: init ark lib + tests #262

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,14 @@ jobs:

- name: Typecheck
run: turbo typecheck

test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Setup
uses: ./tooling/github/setup

- name: Test
run: turbo test
2 changes: 1 addition & 1 deletion apps/auth-proxy/eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ export default [
ignores: [".nitro/**", ".output/**"],
},
...baseConfig,
];
];
2 changes: 2 additions & 0 deletions apps/auth-proxy/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
"build": "nitro build",
"clean": "git clean -xdf .cache .nitro .output .turbo .vercel node_modules",
"lint": "eslint",
"lint:fix": "eslint --fix",
"format": "prettier --check . --ignore-path ../../.gitignore",
"format:write": "prettier --check --write . --ignore-path ../../.gitignore",
"typecheck": "tsc --noEmit"
},
"dependencies": {
Expand Down
3 changes: 3 additions & 0 deletions apps/frontinus-house/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,6 @@ dist-ssr
*.njsproj
*.sln
*.sw?

# Million Lint
.million
16 changes: 16 additions & 0 deletions apps/frontinus-house/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import baseConfig, {
restrictEnvAccess,
} from "@realms-world/eslint-config/base";
import nextjsConfig from "@realms-world/eslint-config/nextjs";
import reactConfig from "@realms-world/eslint-config/react";

/** @type {import('typescript-eslint').Config} */
export default [
{
ignores: [".next/**", "src/.graphclient/**", "public/**", "dist/**"],
},
...baseConfig,
...reactConfig,
...nextjsConfig,
...restrictEnvAccess,
];
4 changes: 3 additions & 1 deletion apps/frontinus-house/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
"dev": "vite",
"clean": "git clean -xdf .next .turbo node_modules",
"build": "tsc && vite build",
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"lint": "eslint --report-unused-disable-directives --max-warnings 0",
"lint:fix": "eslint --report-unused-disable-directives --max-warnings 0 --fix",
"preview": "vite preview"
},
"dependencies": {
"@apollo/client": "^3.10.8",
"@argent/get-starknet": "^6.4.7",
"@iconify-json/heroicons-outline": "^1.1.10",
"@million/lint": "^1.0.0-rc.84",
"@snapshot-labs/sx": "0.1.2",
"@types/remarkable": "^2.0.8",
"autoprefixer": "^10.4.19",
Expand Down
16 changes: 9 additions & 7 deletions apps/frontinus-house/src/components/Markdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,16 @@ export function Markdown({ body }: { body: string }) {
breaks: true,
typographer: false,
linkTarget: "_blank",
highlight: function (str: any, lang: any) {
highlight: function (str: string, lang: string) {
if (lang && hljs.getLanguage(lang)) {
try {
return hljs.highlight(str, { language: lang }).value;
} catch (e) {}
} catch (e) { console.error(`failed to highlight code block ${e as string}`) }
}

try {
return hljs.highlightAuto(str).value;
} catch (e) {}
} catch (e) { console.error(`failed to auto highlight ${e as string}`) }

return "";
},
Expand Down Expand Up @@ -70,7 +70,7 @@ export function Markdown({ body }: { body: string }) {
const parsed = () => {
const formattedBody = body.replace(
/ipfs:\/\/(\w+)/g,
(value) => getUrl(value) || "#",
(value) => getUrl(value) ?? "#",
);

return remarkable.render(formattedBody);
Expand All @@ -82,7 +82,7 @@ export function Markdown({ body }: { body: string }) {
if (!body) return;

body.querySelectorAll("pre>code").forEach((code) => {
const parent = code.parentElement!;
const parent = code.parentElement;

const copyButton = document.createElement("button");
const copySvg = `<svg viewBox="0 0 24 24" width="20px" height="20px">${icons.icons.duplicate?.body}</svg>`;
Expand All @@ -107,11 +107,13 @@ export function Markdown({ body }: { body: string }) {

const language = document.createElement("div");
language.innerHTML =
code.getAttribute("class")?.split("language-")[1] || "";
code.getAttribute("class")?.split("language-")[1] ?? "";

titleBar.append(language);
titleBar.append(copyButton);
parent.prepend(titleBar);
if (parent !== null) {
parent.prepend(titleBar);
}
});
});

Expand Down
8 changes: 0 additions & 8 deletions apps/frontinus-house/src/components/header.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,12 @@
import { sidelinks } from "@/data/menuLinks";
import {
Bell,
CircleUser,
Home,
LineChart,
Menu,
Package,
Package2,
Search,
ShoppingCart,
Users,
} from "lucide-react";
import { Link } from "react-router-dom";

import {
Badge,
Button,
Card,
CardContent,
Expand Down
14 changes: 5 additions & 9 deletions apps/frontinus-house/src/components/sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,12 @@ import {
CardTitle,
} from "@realms-world/ui";

interface SidebarProps extends React.HTMLAttributes<HTMLElement> {
isCollapsed: boolean;
setIsCollapsed: React.Dispatch<React.SetStateAction<boolean>>;
}
// interface SidebarProps extends React.HTMLAttributes<HTMLElement> {
// isCollapsed: boolean;
// setIsCollapsed: React.Dispatch<React.SetStateAction<boolean>>;
// }

export default function Sidebar({
className,
isCollapsed,
setIsCollapsed,
}: SidebarProps) {
export default function Sidebar() {
return (
<div className="bg-muted/40 hidden border-r md:block">
<div className="flex h-full max-h-screen flex-col gap-2">
Expand Down
20 changes: 8 additions & 12 deletions apps/frontinus-house/src/components/space-provider.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { createContext, useContext, useEffect, useState } from "react";
import { getNetwork } from "@/lib/network";
import { Space } from "@/types";
import type { Space } from "@/types";

type SpaceProviderState = {
interface SpaceProviderState {
space?: Space | null;
setSpace: (theme: Space) => void;
};
}

const initialState: SpaceProviderState = {
space: null,
Expand All @@ -24,9 +24,11 @@ export function SpaceProvider({ children }: { children: React.ReactNode }) {
const spaceData = await getNetwork("sn-sep").api.loadSpace(
"0x0011c8d7674bb371708933d29c5e2a4ea31a6535809950b863851373f1afc112",
);
spaceData && setSpace(spaceData);
if (spaceData) {
setSpace(spaceData)
}
};
fetchProposals();
fetchProposals().catch(console.error);
}, []);

const value = {
Expand All @@ -43,12 +45,6 @@ export function SpaceProvider({ children }: { children: React.ReactNode }) {
);
}

// eslint-disable-next-line react-refresh/only-export-components
export const useSpace = () => {
const context = useContext(SpaceProviderContext);

if (context === undefined)
throw new Error("useTheme must be used within a ThemeProvider");

return context;
return useContext(SpaceProviderContext);
};
2 changes: 1 addition & 1 deletion apps/frontinus-house/src/data/constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { VoteType } from '@/types';
import type { VoteType } from '@/types';

export const ETH_CONTRACT = '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee';

Expand Down
5 changes: 0 additions & 5 deletions apps/frontinus-house/src/data/menuLinks.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
import {
Bell,
CircleUser,
HandCoins,
Home,
LineChart,
Menu,
Package,
ShoppingCart,
Users,
} from "lucide-react";

Expand Down
29 changes: 19 additions & 10 deletions apps/frontinus-house/src/hooks/use-delegates.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,24 @@ import {
} from "@apollo/client/core";
import gql from "graphql-tag";

type ApiDelegate = {
interface ApiDelegate {
id: string;
delegatedVotes: string;
delegatedVotesRaw: string;
tokenHoldersRepresentedAmount: number;
};
}

type Delegate = ApiDelegate & {
name: string | null;
delegatorsPercentage: number;
votesPercentage: number;
};

type Governance = {
interface Governance {
delegatedVotes: string;
totalTokenHolders: string;
totalDelegates: string;
};
}

const DELEGATES_LIMIT = 40;

Expand Down Expand Up @@ -59,7 +59,7 @@ function convertUrl(apiUrl: string) {
const hostedPattern =
/https:\/\/thegraph\.com\/hosted-service\/subgraph\/([\w-]+)\/([\w-]+)/;

const hostedMatch = apiUrl.match(hostedPattern);
const hostedMatch = hostedPattern.exec(apiUrl);
if (hostedMatch) {
return `https://api.thegraph.com/subgraphs/name/${hostedMatch[1]}/${hostedMatch[2]}`;
}
Expand Down Expand Up @@ -91,6 +91,14 @@ export function useDelegates(delegationApiUrl: string) {
},
});

interface DelegatesQueryResult {
data: {
delegates: ApiDelegate[];
governance: Governance;

}
}

async function _fetch(
overwrite: boolean,
sortBy:
Expand All @@ -101,7 +109,7 @@ export function useDelegates(delegationApiUrl: string) {
) {
const [orderBy, orderDirection] = sortBy.split("-");

const { data } = await apollo.query({
const { data }: DelegatesQueryResult = await apollo.query({
query: DELEGATES_QUERY,
variables: {
orderBy,
Expand All @@ -113,8 +121,8 @@ export function useDelegates(delegationApiUrl: string) {

console.log(data)

const governanceData = data.governance as Governance;
const delegatesData = data.delegates as ApiDelegate[];
const governanceData = data.governance;
const delegatesData = data.delegates;
const addresses = delegatesData.map((delegate) => delegate.id);

const names = await getNames(addresses);
Expand All @@ -127,10 +135,10 @@ export function useDelegates(delegationApiUrl: string) {
const votesPercentage =
(Number(delegate.delegatedVotes) /
Number(governanceData.delegatedVotes)) *
100 || 0;
100 || 0;

return {
name: names[delegate.id] || null,
name: names[delegate.id] ?? null,
...delegate,
delegatorsPercentage,
votesPercentage,
Expand All @@ -155,6 +163,7 @@ export function useDelegates(delegationApiUrl: string) {

setLoaded(true);
} catch (e) {
console.error(e)
setFailed(true);
} finally {
setLoading(false);
Expand Down
28 changes: 15 additions & 13 deletions apps/frontinus-house/src/lib/alchemy/index.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { ETH_CONTRACT } from "@/data/constants";

import {
import type {
GetBalancesResponse,
GetTokenBalancesResponse,
GetTokensMetadataResponse,
} from "./types";

export * from "./types";

const apiKey = import.meta.env.VITE_ALCHEMY_API_KEY;
const apiKey = import.meta.env.VITE_ALCHEMY_API_KEY as string;

const NETWORKS = {
1: "eth-mainnet",
Expand All @@ -19,15 +19,17 @@ const NETWORKS = {
42161: "arb-mainnet",
};
function getApiUrl(networkId: number) {
const network = NETWORKS[networkId as keyof typeof NETWORKS] ?? "mainnet";
const network = NETWORKS[networkId as keyof typeof NETWORKS];

return `https://${network}.g.alchemy.com/v2/${apiKey}`;
}
export async function request(

interface RpcResponse<T> { id: number; jsonrpc: "2.0"; result: T }
export async function request<Req, Res>(
method: string,
params: any[],
params: Req[],
networkId: number,
) {
): Promise<Res> {
const res = await fetch(getApiUrl(networkId), {
method: "POST",
body: JSON.stringify({
Expand All @@ -38,15 +40,15 @@ export async function request(
}),
});

const { result } = await res.json();
const response = await res.json() as RpcResponse<Res>;

return result;
return response.result;
}

export async function batchRequest(
requests: { method: string; params: any[] }[],
export async function batchRequest<Req, Res>(
requests: { method: string; params: Req[] }[],
networkId: number,
) {
): Promise<Res[]> {
const res = await fetch(getApiUrl(networkId), {
method: "POST",
body: JSON.stringify(
Expand All @@ -59,9 +61,9 @@ export async function batchRequest(
),
});

const response = await res.json();
const response = await res.json() as RpcResponse<Res>[];

return response.map((entry: { result: any }) => entry.result);
return response.map((entry: { result: Res }) => entry.result);
}

/**
Expand Down
Loading
Loading