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: add wagmi + viem #1404

Merged
merged 4 commits into from
Jan 31, 2025
Merged
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
1 change: 1 addition & 0 deletions jest.config.cjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/** @type {import('ts-jest/dist/types').JestConfigWithTsJest} */

module.exports = {
setupFiles: ["<rootDir>/setup.jest.ts"],
preset: "ts-jest",
testEnvironment: "node",
moduleDirectories: ["node_modules", "<rootDir>"],
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@
"react-router-dom": "v5",
"react-tooltip": "^5.18.0",
"superstruct": "^0.15.4",
"typescript": "^5.7.3"
"typescript": "^5.7.3",
"viem": "2.x",
"wagmi": "^2.14.9"
},
"scripts": {
"start": "export REACT_APP_GIT_COMMIT_HASH=$(git rev-parse HEAD) && vite",
Expand Down
32 changes: 32 additions & 0 deletions scripts/generate-ui-assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@ const externAssetsTargetDir = process.cwd() + "/src/assets/extern-logos";
async function generateUiAssets() {
const chainsFileImports: string[] = [
"// This file is auto-generated by scripts/generate-ui-assets.ts",
'import { defineChain } from "viem";',
];
const chainsFileContent: string[] = [];
const chainVarNames: string[] = [];
const chainViemVarNames: string[] = [];
const externVarNames: string[] = [];

for (const [chainKey, chainConfig] of Object.entries(chainConfigs)) {
const { chainId, logoPath, grayscaleLogoPath, name, fullName } =
chainConfig;
Expand Down Expand Up @@ -66,7 +69,33 @@ async function generateUiAssets() {
pollingInterval: ${(chainConfig.blockTimeSeconds || 15) * 1000},
};
`);
chainsFileContent.push(`
export const ${chainVarName}_viem = defineChain({
id: ${chainVarName}.chainId,
name: ${chainVarName}.name,
nativeCurrency: {
name: ${chainVarName}.nativeCurrencySymbol,
symbol: ${chainVarName}.nativeCurrencySymbol,
decimals: 18,
},
rpcUrls: {
default: {
http: [
${chainVarName}.rpcUrl,
${chainVarName}.customRpcUrl ? ${chainVarName}.customRpcUrl : [],
].flat(),
},
},
blockExplorers: {
default: {
name: ${chainVarName}.name + " Explorer",
url: ${chainVarName}.explorerUrl,
},
},
});
`);
chainVarNames.push(chainVarName);
chainViemVarNames.push(chainVarName + "_viem");
}

// Process external project configs
Expand Down Expand Up @@ -130,6 +159,9 @@ async function generateUiAssets() {
return acc;
}, {} as Record<number, typeof ${chainVarNames[0]}>);
`);
chainsFileContent.push(`
export const chains_viem = [${chainViemVarNames.join(", ")}] as const;
`);

chainsFileContent.push(`
export const externConfigs = [${externVarNames.join(", ")}].reduce((acc, extern) => {
Expand Down
4 changes: 4 additions & 0 deletions setup.jest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { TextEncoder, TextDecoder } from "util";
global.TextEncoder = TextEncoder;
// @ts-expect-error - The types are incompatible but the implementation works correctly
global.TextDecoder = TextDecoder;
Loading
Loading