Skip to content

Commit

Permalink
Merge pull request #60 from skip-mev/griko/spe-283-add-a-tx-history-a…
Browse files Browse the repository at this point in the history
…nd-pending-tab-to-ibcfun

[SPE-283] feat: add tx history interface
  • Loading branch information
thal0x authored Oct 31, 2023
2 parents fa46b54 + dc0c2a2 commit 21ec2cc
Show file tree
Hide file tree
Showing 41 changed files with 3,345 additions and 1,399 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v3
with:
submodules: true

- name: Use Node 18.x
uses: actions/setup-node@v3
Expand All @@ -28,7 +30,11 @@ jobs:
container:
image: mcr.microsoft.com/playwright:v1.38.0-jammy
steps:
- uses: actions/checkout@v3
- name: Checkout
uses: actions/checkout@v3
with:
submodules: true
- run: git config --system --add safe.directory /__w/ibc-dot-fun/ibc-dot-fun
- uses: actions/setup-node@v3
with:
node-version: 18
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "chain-registry"]
path = chain-registry
url = https://github.com/cosmos/chain-registry.git
1 change: 1 addition & 0 deletions chain-registry
Submodule chain-registry added at 5a391c
4 changes: 4 additions & 0 deletions jest.setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,7 @@ global.ResizeObserver = require("resize-observer-polyfill");

// eslint-disable-next-line @typescript-eslint/no-var-requires
global.TextEncoder = require("util").TextEncoder;

// suppress zustand deprecation notice to clear out logs
global.console.warn = (...args) =>
args[0]?.includes("vanilla store") ? void 0 : global.console.warn;
3,360 changes: 2,147 additions & 1,213 deletions package-lock.json

Large diffs are not rendered by default.

14 changes: 11 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"scripts": {
"dev": "next dev",
"build": "next build",
"postinstall": "node ./scripts/generate.js",
"postinstall": "git submodule init && git submodule update && tsx ./src/scripts/codegen.ts",
"start": "next start",
"lint": "next lint",
"test": "jest",
Expand All @@ -31,6 +31,7 @@
"@evmos/proto": "^0.2.1",
"@evmos/provider": "^0.3.1",
"@evmos/transactions": "^0.3.2",
"@graz-sh/types": "^0.0.12",
"@headlessui/react": "^1.7.14",
"@heroicons/react": "^2.0.18",
"@injectivelabs/sdk-ts": "^1.11.0",
Expand All @@ -50,8 +51,8 @@
"@web3modal/ui": "^2.7.0",
"autoprefixer": "10.4.14",
"axios": "^1.4.0",
"chain-registry": "^1.18.0",
"classnames": "^2.3.2",
"clsx": "^2.0.0",
"cosmjs-types": "^0.7.2",
"download": "^8.0.0",
"eslint-config-next": "13.4.1",
Expand All @@ -66,30 +67,37 @@
"tailwindcss": "3.3.2",
"usehooks-ts": "^2.9.1",
"viem": "^1.14.0",
"wagmi": "^1.4.3"
"wagmi": "^1.4.3",
"zod": "^3.22.4",
"zustand": "^4.4.4"
},
"devDependencies": {
"@playwright/test": "^1.38.0",
"@tanstack/eslint-plugin-query": "^4.36.0",
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^14.0.0",
"@testing-library/user-event": "^14.4.3",
"@types/degit": "^2.8.5",
"@types/download": "^8.0.2",
"@types/http-proxy": "^1.17.11",
"@types/jest": "^29.5.3",
"@types/testing-library__jest-dom": "^5.14.5",
"@typescript-eslint/eslint-plugin": "^6.7.0",
"@typescript-eslint/parser": "^6.7.0",
"degit": "npm:tiged@^2.12.5",
"eslint": "^8.49.0",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-prettier": "^5.0.0",
"eslint-plugin-simple-import-sort": "^10.0.0",
"globby": "^13.2.2",
"jest": "^29.5.0",
"jest-environment-jsdom": "^29.5.0",
"msw": "^1.2.3",
"p-map": "^6.0.0",
"prettier": "^3.0.3",
"resize-observer-polyfill": "^1.5.1",
"ts-jest": "^29.1.1",
"tsx": "^3.14.0",
"typescript": "^5.0.4"
}
}
54 changes: 0 additions & 54 deletions scripts/generate.js

This file was deleted.

11 changes: 4 additions & 7 deletions src/api/queries.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Chain as SkipChain } from "@skip-router/core";
import { useQuery } from "@tanstack/react-query";
import * as chainRegistry from "chain-registry";

import { chainRecord } from "@/chains";
import { useSkipClient } from "@/solve";

export type Chain = {
prettyName: string;
record?: (typeof chainRegistry.chains)[number];
record?: (typeof chainRecord)[string];
} & SkipChain;

export type UseChainsQueryArgs<T = Chain[]> = {
Expand All @@ -26,11 +26,8 @@ export function useChains<T = Chain[]>(args: UseChainsQueryArgs<T> = {}) {
});

return chains
.map((chain) => {
const record = chainRegistry.chains.find(
(c) => c.chain_id === chain.chainID,
);

.map((chain): Chain => {
const record = chainRecord[chain.chainID];
return {
...chain,
prettyName: record?.pretty_name ?? chain.chainName,
Expand Down
3 changes: 3 additions & 0 deletions src/ast/_constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import * as os from "os";

export const concurrency = Math.max(1, (os.cpus() || { length: 1 }).length - 1);
15 changes: 15 additions & 0 deletions src/ast/_types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Asset, AssetList, Chain } from "@graz-sh/types";

export interface Variables {
assetlists: AssetList[];
chains: Chain[];

chainIds: string[];
chainNames: string[];

chainIdToName: Record<string, string>;
chainNameToId: Record<string, string>;

chainRecord: Record<string, Chain>;
assetsRecord: Record<string, Asset[]>;
}
17 changes: 17 additions & 0 deletions src/ast/get-chains-paths.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { globby } from "globby";

interface Args {
registryPath: string;
}

export async function getChainsPaths({ registryPath }: Args) {
const mainnetGlobs = ["*", "!_*", "!testnets"];
const testnetGlobs = ["testnets/*", "!testnets/_*"];

const paths = await globby([...mainnetGlobs, ...testnetGlobs], {
cwd: registryPath,
onlyDirectories: true,
});

return paths;
}
26 changes: 26 additions & 0 deletions src/ast/parse-asset-list-json.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { AssetList } from "@graz-sh/types";
import { assetListSchema } from "@graz-sh/types/zod";
import * as fs from "fs/promises";
import * as path from "path";

interface Args {
registryPath: string;
chainPath: string;
}

export async function parseAssetListJson({ registryPath, chainPath }: Args) {
const jsonPath = path.resolve(registryPath, chainPath, "assetlist.json");

let data: AssetList;
try {
const content = await fs.readFile(jsonPath, "utf-8");
data = await assetListSchema.parseAsync(JSON.parse(content));
} catch (error) {
data = {
chain_name: chainPath,
assets: [],
};
}

return data;
}
18 changes: 18 additions & 0 deletions src/ast/parse-chain-json.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Chain } from "@graz-sh/types";
import { chainSchema } from "@graz-sh/types/zod";
import * as fs from "fs/promises";
import * as path from "path";

interface Args {
registryPath: string;
chainPath: string;
}

export async function parseChainJson({ registryPath, chainPath }: Args) {
const jsonPath = path.resolve(registryPath, chainPath, "chain.json");

const content = await fs.readFile(jsonPath, "utf-8");
const data: Chain = await chainSchema.parseAsync(JSON.parse(content));

return data;
}
63 changes: 63 additions & 0 deletions src/ast/parse-chain-paths.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { Asset, AssetList, Chain } from "@graz-sh/types";
import pMap from "p-map";

import { concurrency } from "./_constants";
import { Variables } from "./_types";
import { parseAssetListJson } from "./parse-asset-list-json";
import { parseChainJson } from "./parse-chain-json";

interface Args {
registryPath: string;
chainPaths: string[];
}

export async function parseChainPaths({
registryPath,
chainPaths,
}: Args): Promise<Variables> {
const chains: Chain[] = [];
const assetlists: AssetList[] = [];

const chainIds: string[] = [];
const chainNames: string[] = [];

const chainIdToName: Record<string, string> = {};
const chainNameToId: Record<string, string> = {};
const chainRecord: Record<string, Chain> = {};
const assetsRecord: Record<string, Asset[]> = {};

async function loadChainPath(chainPath: string) {
const [assetlist, chain] = await Promise.all([
parseAssetListJson({ registryPath, chainPath }),
parseChainJson({ registryPath, chainPath }),
]);

chains.push(chain);
assetlists.push(assetlist);

chainIds.push(chain.chain_id);
chainNames.push(chain.chain_name);

chainIdToName[chain.chain_id] = chain.chain_name;
chainIdToName[chain.chain_name] = chain.chain_name;

chainNameToId[chain.chain_name] = chain.chain_id;
chainNameToId[chain.chain_id] = chain.chain_id;

chainRecord[chain.chain_id] = chain;
assetsRecord[chain.chain_id] = assetlist.assets;
}

await pMap(chainPaths, loadChainPath, { concurrency });

return {
chains,
assetlists,
chainIds,
chainNames,
chainIdToName,
chainNameToId,
chainRecord,
assetsRecord,
};
}
31 changes: 31 additions & 0 deletions src/ast/validate-chains-paths.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import * as fs from "fs/promises";
import pMap, { pMapSkip } from "p-map";
import * as path from "path";

import { concurrency } from "./_constants";

interface Args {
registryPath: string;
chainPaths: string[];
}

export async function validateChainsPaths({ registryPath, chainPaths }: Args) {
const filesToCheck = ["chain.json"];

const checkFiles = async (chainPath: string) => {
try {
await Promise.all(
filesToCheck.map((file) => {
return fs.lstat(path.resolve(registryPath, chainPath, file));
}),
);
return chainPath;
} catch (error) {
return pMapSkip;
}
};

const validChainPaths = await pMap(chainPaths, checkFiles, { concurrency });

return validChainPaths;
}
Loading

0 comments on commit 21ec2cc

Please sign in to comment.