diff --git a/frontend/src/app/components/search-form/search-form.component.ts b/frontend/src/app/components/search-form/search-form.component.ts index 745efce21..2a9983a24 100644 --- a/frontend/src/app/components/search-form/search-form.component.ts +++ b/frontend/src/app/components/search-form/search-form.component.ts @@ -186,7 +186,7 @@ export class SearchFormComponent implements OnInit { const matchesTxId = this.regexTransaction.test(searchText) && !this.regexBlockhash.test(searchText); const matchesBlockHash = this.regexBlockhash.test(searchText); let matchesAddress = !matchesTxId && this.regexAddress.test(searchText); - const otherNetworks = findOtherNetworks(searchText, this.network as any || 'mainnet'); + const otherNetworks = findOtherNetworks(searchText, this.network as any || 'mainnet', this.env); // Add B prefix to addresses in Bisq network if (!matchesAddress && this.network === 'bisq' && getRegex('address', 'mainnet').test(searchText)) { @@ -234,7 +234,14 @@ export class SearchFormComponent implements OnInit { } else if (result.short_id) { this.navigate('/lightning/channel/', result.id); } else if (result.network) { - this.navigate('/address/', result.address, undefined, result.network); + if (result.isNetworkAvailable) { + this.navigate('/address/', result.address, undefined, result.network); + } else { + this.searchForm.setValue({ + searchText: '', + }); + this.isSearching = false; + } } } diff --git a/frontend/src/app/components/search-form/search-results/search-results.component.html b/frontend/src/app/components/search-form/search-results/search-results.component.html index adc92b0bf..f83df6b93 100644 --- a/frontend/src/app/components/search-form/search-results/search-results.component.html +++ b/frontend/src/app/components/search-form/search-results/search-results.component.html @@ -38,7 +38,7 @@
Other Networks Address
- diff --git a/frontend/src/app/shared/regex.utils.ts b/frontend/src/app/shared/regex.utils.ts index 607bd704a..128f7566e 100644 --- a/frontend/src/app/shared/regex.utils.ts +++ b/frontend/src/app/shared/regex.utils.ts @@ -144,10 +144,29 @@ export type Network = typeof NETWORKS[number]; // Turn const array into union ty export const ADDRESS_REGEXES: [RegExp, Network][] = NETWORKS .map(network => [getRegex('address', network), network]) -export function findOtherNetworks(address: string, skipNetwork: Network): {network: Network, address: string}[] { +export function findOtherNetworks(address: string, skipNetwork: Network, env: Env): { network: Network, address: string, isNetworkAvailable: boolean }[] { return ADDRESS_REGEXES .filter(([regex, network]) => network !== skipNetwork && regex.test(address)) - .map(([, network]) => ({ network, address })); + .map(([, network]) => ({ network, address, isNetworkAvailable: isNetworkAvailable(network, env) })); +} + +function isNetworkAvailable(network: Network, env: Env): boolean { + switch (network) { + case 'testnet': + return env.TESTNET_ENABLED === true; + case 'signet': + return env.SIGNET_ENABLED === true; + case 'liquid': + return env.LIQUID_ENABLED === true; + case 'liquidtestnet': + return env.LIQUID_TESTNET_ENABLED === true; + case 'bisq': + return env.BISQ_ENABLED === true; + case 'mainnet': + return true; // There is no "MAINNET_ENABLED" flag + default: + return false; + } } export function needBaseModuleChange(fromBaseModule: 'mempool' | 'liquid' | 'bisq', toNetwork: Network): boolean {