From 885d1144eba5a3d37c4f38a20b0b44dcb0f6c39d Mon Sep 17 00:00:00 2001 From: Korbinian Date: Tue, 5 Mar 2024 09:58:54 +0100 Subject: [PATCH 1/3] update schema --- .../schemas/configuredChains.schema.json | 52 ++++++++++++++++--- 1 file changed, 44 insertions(+), 8 deletions(-) diff --git a/packages/bridge-ui/config/schemas/configuredChains.schema.json b/packages/bridge-ui/config/schemas/configuredChains.schema.json index 2ba1ebaa98b..8f68b41d05f 100644 --- a/packages/bridge-ui/config/schemas/configuredChains.schema.json +++ b/packages/bridge-ui/config/schemas/configuredChains.schema.json @@ -5,9 +5,6 @@ "type": "array", "items": { "type": "object", - "propertyNames": { - "pattern": "^[0-9]+$" - }, "additionalProperties": { "type": "object", "properties": { @@ -20,20 +17,59 @@ "type": { "type": "string" }, - "urls": { + "rpcUrls": { "type": "object", "properties": { - "rpc": { + "default": { + "type": "object", + "properties": { + "http": { + "type": "array", + "items": { + "type": "string" + } + } + }, + "required": ["http"] + } + }, + "required": ["default"] + }, + "nativeCurrency": { + "type": "object", + "properties": { + "name": { "type": "string" }, - "explorer": { + "symbol": { "type": "string" + }, + "decimals": { + "type": "integer" + } + }, + "required": ["name", "symbol", "decimals"] + }, + "blockExplorers": { + "type": "object", + "properties": { + "default": { + "type": "object", + "properties": { + "name": { + "type": "string" + }, + "url": { + "type": "string" + } + }, + "required": ["name", "url"] } }, - "required": ["rpc", "explorer"] + "required": ["default"] } }, - "required": ["name", "icon", "type", "urls"] + "required": ["name", "icon", "type", "rpcUrls", "nativeCurrency", "blockExplorers"] } } } From 389b8f8d3053e185eea3a98309e53e665fa9b765 Mon Sep 17 00:00:00 2001 From: Korbinian Date: Tue, 5 Mar 2024 09:59:19 +0100 Subject: [PATCH 2/3] streamline types --- packages/bridge-ui/src/libs/chain/chains.ts | 18 ++++++------------ packages/bridge-ui/src/libs/chain/types.ts | 11 +++-------- 2 files changed, 9 insertions(+), 20 deletions(-) diff --git a/packages/bridge-ui/src/libs/chain/chains.ts b/packages/bridge-ui/src/libs/chain/chains.ts index 8ccbbfed0bf..5eb8523478b 100644 --- a/packages/bridge-ui/src/libs/chain/chains.ts +++ b/packages/bridge-ui/src/libs/chain/chains.ts @@ -1,22 +1,16 @@ import type { Chain } from 'viem'; import { chainConfig } from '$chainConfig'; -import type { ChainConfigMap } from '$libs/chain'; +import type { ChainConfig } from '$libs/chain'; -function mapChainConfigToChain(chainId: string, chainConfig: ChainConfigMap[number]): Chain { +function mapChainConfigToChain(chainId: string, chainConfig: ChainConfig): Chain { return { id: Number(chainId), name: chainConfig.name, - nativeCurrency: { - name: 'ETH', - symbol: 'ETH', - decimals: 18, - }, - rpcUrls: { - public: { http: [chainConfig.urls.rpc] }, - default: { http: [chainConfig.urls.rpc] }, - }, - } as const satisfies Chain; + rpcUrls: chainConfig.rpcUrls, + nativeCurrency: chainConfig.nativeCurrency, + blockExplorers: chainConfig.blockExplorers, + }; } export const chainIdToChain = (chainId: number): Chain => { diff --git a/packages/bridge-ui/src/libs/chain/types.ts b/packages/bridge-ui/src/libs/chain/types.ts index 86cf20409ac..d5d2d1bba39 100644 --- a/packages/bridge-ui/src/libs/chain/types.ts +++ b/packages/bridge-ui/src/libs/chain/types.ts @@ -1,3 +1,5 @@ +import type { Chain } from 'viem'; + export type ChainID = bigint; export enum LayerType { @@ -6,14 +8,7 @@ export enum LayerType { L3 = 'L3', } -export type Urls = { - rpc: string; - explorer: string; -}; - -export type ChainConfig = { - name: string; - urls: Urls; +export type ChainConfig = Omit & { icon: string; type: LayerType; }; From d5bbe57e677897893ef47b6d96f98f545d742531 Mon Sep 17 00:00:00 2001 From: Korbinian Date: Tue, 5 Mar 2024 09:59:54 +0100 Subject: [PATCH 3/3] update explorer url fetching --- .../Bridge/NFTBridgeComponents/ReviewStep/ReviewStep.svelte | 2 +- .../ConfirmationStep/ConfirmationStep.svelte | 4 ++-- packages/bridge-ui/src/components/Faucet/Faucet.svelte | 3 ++- packages/bridge-ui/src/components/NFTs/NFTInfoDialog.svelte | 4 ++-- .../src/components/SideNavigation/SideNavigation.svelte | 2 +- .../src/components/Transactions/MobileDetailsDialog.svelte | 6 +++--- .../src/components/Transactions/Status/Status.svelte | 4 ++-- .../src/components/Transactions/Transaction.svelte | 4 ++-- 8 files changed, 15 insertions(+), 14 deletions(-) diff --git a/packages/bridge-ui/src/components/Bridge/NFTBridgeComponents/ReviewStep/ReviewStep.svelte b/packages/bridge-ui/src/components/Bridge/NFTBridgeComponents/ReviewStep/ReviewStep.svelte index 4d76c7d378d..11c015072cb 100644 --- a/packages/bridge-ui/src/components/Bridge/NFTBridgeComponents/ReviewStep/ReviewStep.svelte +++ b/packages/bridge-ui/src/components/Bridge/NFTBridgeComponents/ReviewStep/ReviewStep.svelte @@ -97,7 +97,7 @@
  • {shortenAddress(nft.addresses[currentChain], 8, 12)} diff --git a/packages/bridge-ui/src/components/Bridge/SharedBridgeComponents/ConfirmationStep/ConfirmationStep.svelte b/packages/bridge-ui/src/components/Bridge/SharedBridgeComponents/ConfirmationStep/ConfirmationStep.svelte index af4861ff73b..47fc46f83f9 100644 --- a/packages/bridge-ui/src/components/Bridge/SharedBridgeComponents/ConfirmationStep/ConfirmationStep.svelte +++ b/packages/bridge-ui/src/components/Bridge/SharedBridgeComponents/ConfirmationStep/ConfirmationStep.svelte @@ -58,7 +58,7 @@ const userAccount = $account?.address; if (!currentChain || !destinationChain || !userAccount) return; //TODO error handling - const explorer = chainConfig[currentChain].urls.explorer; + const explorer = chainConfig[currentChain]?.blockExplorers?.default.url; await pendingTransactions.add(txHash, currentChain); @@ -92,7 +92,7 @@ const userAccount = $account?.address; if (!currentChain || !destinationChain || !userAccount || !$selectedToken) return; //TODO error handling - const { explorer } = chainConfig[currentChain].urls; + const explorer = chainConfig[currentChain]?.blockExplorers?.default.url; infoToast({ title: $t('bridge.actions.approve.tx.title'), diff --git a/packages/bridge-ui/src/components/Faucet/Faucet.svelte b/packages/bridge-ui/src/components/Faucet/Faucet.svelte index a1e5f9c0d03..3813303ad5f 100644 --- a/packages/bridge-ui/src/components/Faucet/Faucet.svelte +++ b/packages/bridge-ui/src/components/Faucet/Faucet.svelte @@ -64,7 +64,8 @@ try { const txHash = await mint(selectedToken, $connectedSourceChain.id); - const explorer = chainConfig[$connectedSourceChain.id].urls.explorer; + + const explorer = chainConfig[$connectedSourceChain.id]?.blockExplorers?.default.url; infoToast({ title: $t('faucet.mint.tx.title'), diff --git a/packages/bridge-ui/src/components/NFTs/NFTInfoDialog.svelte b/packages/bridge-ui/src/components/NFTs/NFTInfoDialog.svelte index 850a7e1b028..668e817aba4 100644 --- a/packages/bridge-ui/src/components/NFTs/NFTInfoDialog.svelte +++ b/packages/bridge-ui/src/components/NFTs/NFTInfoDialog.svelte @@ -119,7 +119,7 @@ {:else if canonicalChain && canonicalAddress} {shortenAddress(canonicalAddress, 6, 8)} @@ -138,7 +138,7 @@ {#if bridgedChain && bridgedAddress} {shortenAddress(bridgedAddress, 6, 8)} diff --git a/packages/bridge-ui/src/components/SideNavigation/SideNavigation.svelte b/packages/bridge-ui/src/components/SideNavigation/SideNavigation.svelte index a36f9a71986..b8ab88500b7 100644 --- a/packages/bridge-ui/src/components/SideNavigation/SideNavigation.svelte +++ b/packages/bridge-ui/src/components/SideNavigation/SideNavigation.svelte @@ -105,7 +105,7 @@
  • diff --git a/packages/bridge-ui/src/components/Transactions/MobileDetailsDialog.svelte b/packages/bridge-ui/src/components/Transactions/MobileDetailsDialog.svelte index 140187ed982..74eaafa5ed1 100644 --- a/packages/bridge-ui/src/components/Transactions/MobileDetailsDialog.svelte +++ b/packages/bridge-ui/src/components/Transactions/MobileDetailsDialog.svelte @@ -144,7 +144,7 @@
    {shortenAddress(canonicalAddress, 6, 8)} @@ -162,7 +162,7 @@ {#if bridgedChain && bridgedAddress} {shortenAddress(bridgedAddress, 6, 8)} @@ -195,7 +195,7 @@

    {$t('transactions.header.explorer')}

    {$t('transactions.link.explorer')} diff --git a/packages/bridge-ui/src/components/Transactions/Status/Status.svelte b/packages/bridge-ui/src/components/Transactions/Status/Status.svelte index 4708148b5bd..72d04eb114d 100644 --- a/packages/bridge-ui/src/components/Transactions/Status/Status.svelte +++ b/packages/bridge-ui/src/components/Transactions/Status/Status.svelte @@ -112,7 +112,7 @@ // Step 5: Call claim() method on the bridge const txHash = await bridge.claim({ msgHash, message, wallet }); - const { explorer } = chainConfig[Number(bridgeTx.destChainId)].urls; + const explorer = chainConfig[Number(bridgeTx.destChainId)]?.blockExplorers?.default.url; infoToast({ title: $t('transactions.actions.claim.tx.title'), @@ -202,7 +202,7 @@ // Step 4: Call release() method on the bridge const txHash = await bridge.release({ msgHash, message, wallet }); - const { explorer } = chainConfig[Number(bridgeTx.srcChainId)].urls; + const explorer = chainConfig[Number(bridgeTx.srcChainId)]?.blockExplorers?.default.url; infoToast({ title: $t('transactions.actions.release.tx.title'), diff --git a/packages/bridge-ui/src/components/Transactions/Transaction.svelte b/packages/bridge-ui/src/components/Transactions/Transaction.svelte index ee913e7dd63..b7b7965c3b2 100644 --- a/packages/bridge-ui/src/components/Transactions/Transaction.svelte +++ b/packages/bridge-ui/src/components/Transactions/Transaction.svelte @@ -182,7 +182,7 @@