From 62d463c40e5092fb1ecfc06b43bacc0d3943e3c1 Mon Sep 17 00:00:00 2001 From: Denys Karmazyn Date: Fri, 27 Sep 2024 12:10:11 +0200 Subject: [PATCH] feat(frontend): add exporerUrl to BTC networks [GIX-2795] (#2557) # Motivation The goal is to extend BTC networks with already defined explorer URLs. It will be used in the BTC transaction detail modal. --- src/frontend/src/btc/types/network.ts | 3 +++ src/frontend/src/env/networks.env.ts | 18 +++++++++++++----- src/frontend/src/eth/types/network.ts | 8 ++------ src/frontend/src/lib/types/network.ts | 4 ++++ 4 files changed, 22 insertions(+), 11 deletions(-) create mode 100644 src/frontend/src/btc/types/network.ts diff --git a/src/frontend/src/btc/types/network.ts b/src/frontend/src/btc/types/network.ts new file mode 100644 index 0000000000..b372861fad --- /dev/null +++ b/src/frontend/src/btc/types/network.ts @@ -0,0 +1,3 @@ +import type { Network, NetworkAppMetadata } from '$lib/types/network'; + +export type BitcoinNetwork = Network & Partial; diff --git a/src/frontend/src/env/networks.env.ts b/src/frontend/src/env/networks.env.ts index 45557f2cec..616aae2949 100644 --- a/src/frontend/src/env/networks.env.ts +++ b/src/frontend/src/env/networks.env.ts @@ -1,4 +1,10 @@ -import { ETHEREUM_EXPLORER_URL, SEPOLIA_EXPLORER_URL } from '$env/explorers.env'; +import type { BitcoinNetwork } from '$btc/types/network'; +import { + BTC_MAINNET_EXPLORER_URL, + BTC_TESTNET_EXPLORER_URL, + ETHEREUM_EXPLORER_URL, + SEPOLIA_EXPLORER_URL +} from '$env/explorers.env'; import { ETH_MAINNET_ENABLED } from '$env/networks.eth.env'; import sepolia from '$eth/assets/sepolia.svg'; import type { EthereumChainId, EthereumNetwork } from '$eth/types/network'; @@ -82,11 +88,12 @@ export const BTC_MAINNET_NETWORK_SYMBOL = 'BTC'; export const BTC_MAINNET_NETWORK_ID = Symbol(BTC_MAINNET_NETWORK_SYMBOL); -export const BTC_MAINNET_NETWORK: Network = { +export const BTC_MAINNET_NETWORK: BitcoinNetwork = { id: BTC_MAINNET_NETWORK_ID, env: 'mainnet', name: 'Bitcoin', icon: bitcoin, + explorerUrl: BTC_MAINNET_EXPLORER_URL, buy: { onramperId: 'bitcoin' } }; @@ -94,10 +101,11 @@ export const BTC_TESTNET_NETWORK_SYMBOL = 'BTC (Testnet)'; export const BTC_TESTNET_NETWORK_ID = Symbol(BTC_TESTNET_NETWORK_SYMBOL); -export const BTC_TESTNET_NETWORK: Network = { +export const BTC_TESTNET_NETWORK: BitcoinNetwork = { id: BTC_TESTNET_NETWORK_ID, env: 'testnet', name: 'Bitcoin', + explorerUrl: BTC_TESTNET_EXPLORER_URL, icon: bitcoinTestnet }; @@ -105,13 +113,13 @@ export const BTC_REGTEST_NETWORK_SYMBOL = 'BTC (Regtest)'; export const BTC_REGTEST_NETWORK_ID = Symbol(BTC_REGTEST_NETWORK_SYMBOL); -export const BTC_REGTEST_NETWORK: Network = { +export const BTC_REGTEST_NETWORK: BitcoinNetwork = { id: BTC_REGTEST_NETWORK_ID, env: 'testnet', name: 'Bitcoin (Regtest)' }; -export const BITCOIN_NETWORKS: Network[] = [ +export const BITCOIN_NETWORKS: BitcoinNetwork[] = [ BTC_MAINNET_NETWORK, BTC_TESTNET_NETWORK, ...(LOCAL ? [BTC_REGTEST_NETWORK] : []) diff --git a/src/frontend/src/eth/types/network.ts b/src/frontend/src/eth/types/network.ts index 8418ac6aa8..33b0d10916 100644 --- a/src/frontend/src/eth/types/network.ts +++ b/src/frontend/src/eth/types/network.ts @@ -1,4 +1,4 @@ -import type { Network } from '$lib/types/network'; +import type { Network, NetworkAppMetadata } from '$lib/types/network'; export type EthereumChainId = bigint; @@ -6,8 +6,4 @@ export interface NetworkChainId { chainId: EthereumChainId; } -export interface EthereumAppMetadata { - explorerUrl: string; -} - -export type EthereumNetwork = Network & NetworkChainId & EthereumAppMetadata; +export type EthereumNetwork = Network & NetworkChainId & NetworkAppMetadata; diff --git a/src/frontend/src/lib/types/network.ts b/src/frontend/src/lib/types/network.ts index cc4d8da352..e3e2646d07 100644 --- a/src/frontend/src/lib/types/network.ts +++ b/src/frontend/src/lib/types/network.ts @@ -16,3 +16,7 @@ export interface Network { export interface NetworkBuy { onramperId?: OnramperNetworkId; } + +export interface NetworkAppMetadata { + explorerUrl: string; +}