Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fix: Fix chainId type in Chain interface
  • Loading branch information
jnsdls committed Oct 16, 2023
commit 29fa05e8546df13d886e0787a267a3d661e69aff
25 changes: 11 additions & 14 deletions packages/chains/scripts/sync-db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ async function sync() {
try {
chainId = Number(chainId);
} catch {
// if we fail we ignore this, most likely the chain was out of bounds of i32 and so we leave it as a string
// if we fail here then we cannot use this chain in the chains package for now, so we skip it
return null;
}

const pkgChain: Chain = {
Expand All @@ -50,24 +51,19 @@ async function sync() {
};
// remove all null values
Object.keys(pkgChain).forEach((key) => {
// @ts-ignore
if (pkgChain[key] === null || pkgChain[key] === undefined) {
// @ts-ignore
delete pkgChain[key];
}
});

// sort top level keys alphabetically
// @ts-ignore
const sortedChain: Chain = {};
const sortedChain = {} as Chain;
Object.keys(pkgChain)
.sort()
.forEach((key) => {
// @ts-ignore
sortedChain[key] = pkgChain[key];
});

// @ts-ignore
await fs.writeFile(
`${chainsDir}/${sortedChain.chainId}.ts`,
`import type { Chain } from "../src/types";
Expand Down Expand Up @@ -102,20 +98,21 @@ export default ${JSON.stringify(

const { imports, exports, exportNames, exportNameToChain } = results.reduce(
(acc, result) => {
// @ts-ignore
// if it's a null result skip it (can happen when we skip chains above because their chainID is out of bounds)
if (result === null) {
return acc;
}
acc.imports.push(result.imp);
// @ts-ignore
acc.exports.push(result.exp);
// @ts-ignore
acc.exportNames.push(result.key);
acc.exportNameToChain[result.key] = result.chain;
return acc;
},
{
imports: [],
exports: [],
exportNames: [],
exportNameToChain: {},
imports: [] as string[],
exports: [] as string[],
exportNames: [] as string[],
exportNameToChain: {} as Record<string, Chain>,
},
);

Expand Down
2 changes: 1 addition & 1 deletion packages/chains/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export type Chain = {
};
infoURL?: string;
shortName: string;
chainId: number | string;
chainId: number;
networkId?: number;
ens?: {
registry: string;
Expand Down