diff --git a/.gitignore b/.gitignore index 2eadbdd5..0a6a87db 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. +src/chains/ tests/downloads/ # dependencies diff --git a/package-lock.json b/package-lock.json index 26cadf5a..f5910bfe 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7,6 +7,7 @@ "": { "name": "ibc-dot-fun", "version": "0.1.0", + "hasInstallScript": true, "dependencies": { "@cosmjs/amino": "^0.31.0", "@cosmjs/cosmwasm-stargate": "^0.31.0", @@ -36,7 +37,7 @@ "@radix-ui/react-dialog": "^1.0.4", "@radix-ui/react-toast": "^1.1.4", "@radix-ui/react-tooltip": "^1.0.6", - "@skip-router/core": "^0.1.0-rc12", + "@skip-router/core": "^0.1.0-rc13", "@tanstack/react-query": "^4.29.5", "@types/node": "20.1.2", "@types/react": "18.2.6", @@ -5516,9 +5517,9 @@ } }, "node_modules/@skip-router/core": { - "version": "0.1.0-rc12", - "resolved": "https://registry.npmjs.org/@skip-router/core/-/core-0.1.0-rc12.tgz", - "integrity": "sha512-6YcT2+AonBsL4tCxd6Ebj3MkeCqvj2njfqaeQOA/nwN8xSplMf/3KH770wzEVFgpmBhA7tgn/mL7IiaYulEUmQ==", + "version": "0.1.0-rc13", + "resolved": "https://registry.npmjs.org/@skip-router/core/-/core-0.1.0-rc13.tgz", + "integrity": "sha512-117uNndVWgAVTGAPz3FbqwgqZZJY41ms9ceyxdpdz84eqY1sx5jjiCmEBwt7geFpzZ3DfzkK7pFrdXcT44NyXg==", "dependencies": { "@axelar-network/axelarjs-sdk": "^0.13.6", "@cosmjs/amino": "^0.31.1", @@ -24077,9 +24078,9 @@ } }, "@skip-router/core": { - "version": "0.1.0-rc12", - "resolved": "https://registry.npmjs.org/@skip-router/core/-/core-0.1.0-rc12.tgz", - "integrity": "sha512-6YcT2+AonBsL4tCxd6Ebj3MkeCqvj2njfqaeQOA/nwN8xSplMf/3KH770wzEVFgpmBhA7tgn/mL7IiaYulEUmQ==", + "version": "0.1.0-rc13", + "resolved": "https://registry.npmjs.org/@skip-router/core/-/core-0.1.0-rc13.tgz", + "integrity": "sha512-117uNndVWgAVTGAPz3FbqwgqZZJY41ms9ceyxdpdz84eqY1sx5jjiCmEBwt7geFpzZ3DfzkK7pFrdXcT44NyXg==", "requires": { "@axelar-network/axelarjs-sdk": "^0.13.6", "@cosmjs/amino": "^0.31.1", diff --git a/package.json b/package.json index 9649fb9a..910b9c9e 100644 --- a/package.json +++ b/package.json @@ -5,6 +5,7 @@ "scripts": { "dev": "next dev", "build": "next build", + "postinstall": "node ./scripts/generate.js", "start": "next start", "lint": "next lint", "test": "jest", @@ -39,7 +40,7 @@ "@radix-ui/react-dialog": "^1.0.4", "@radix-ui/react-toast": "^1.1.4", "@radix-ui/react-tooltip": "^1.0.6", - "@skip-router/core": "^0.1.0-rc12", + "@skip-router/core": "^0.1.0-rc13", "@tanstack/react-query": "^4.29.5", "@types/node": "20.1.2", "@types/react": "18.2.6", diff --git a/scripts/generate.js b/scripts/generate.js new file mode 100644 index 00000000..64cb8db9 --- /dev/null +++ b/scripts/generate.js @@ -0,0 +1,54 @@ +/* eslint-disable @typescript-eslint/no-var-requires */ + +const { chains } = require("chain-registry"); +const fs = require("fs/promises"); + +async function generate() { + /** @type {string[]} */ + const chainIds = []; + + /** @type {Record} */ + const chainRecord = {}; + + for (const chain of chains) { + if (!chain.chain_id) continue; + chainIds.push(chain.chain_id); + chainRecord[chain.chain_id] = chain; + } + + await fs.mkdir("src/chains/", { recursive: true }).catch(() => {}); + + await fs.writeFile( + "src/chains/chainIds.js", + "module.exports=" + JSON.stringify(chainIds), + "utf-8", + ); + + const chainIdLiteralType = chainIds + .map((id) => `"${id}"`) + .concat("(string & {})") + .join("|"); + + const chainIdsDts = `/* eslint-disable */ +export type ChainId = ${chainIdLiteralType}; +declare const chainIds: ChainId[]; +export default chainIds; +`; + await fs.writeFile("src/chains/chainIds.d.ts", chainIdsDts, "utf-8"); + + await fs.writeFile( + "src/chains/chainRecord.js", + "module.exports=" + JSON.stringify(chainRecord), + "utf-8", + ); + + const chainRecordDts = `/* eslint-disable */ +import { Chain } from "@chain-registry/types"; +import { ChainId } from "./chainIds"; +declare const chainRecord: Record; +export default chainRecord; +`; + await fs.writeFile("src/chains/chainRecord.d.ts", chainRecordDts, "utf-8"); +} + +void generate(); diff --git a/src/components/SwapWidget/SwapWidget.tsx b/src/components/SwapWidget/SwapWidget.tsx index 5eebc18d..eda0f4d9 100644 --- a/src/components/SwapWidget/SwapWidget.tsx +++ b/src/components/SwapWidget/SwapWidget.tsx @@ -3,7 +3,6 @@ import { FC, Fragment } from "react"; import { useChains as useSkipChains } from "@/api/queries"; import { useAccount } from "@/hooks/useAccount"; -import { getExplorerLinkForTx } from "@/utils/utils"; import AssetInput from "../AssetInput"; import { ConnectedWalletButton } from "../ConnectedWalletButton"; @@ -36,6 +35,7 @@ export const SwapWidget: FC = () => { onSourceAssetChange, onDestinationChainChange, onDestinationAssetChange, + noRouteFound, } = useSwapWidget(); const { address, isWalletConnected, wallet } = useAccount( @@ -148,6 +148,11 @@ export const SwapWidget: FC = () => { numberOfTransactions={numberOfTransactions} /> )} + {noRouteFound && ( +
+

No route found

+
+ )} {sourceChain && !isWalletConnected && (