From c7a7f36214c23eb997cc7addcc04e808a41393b3 Mon Sep 17 00:00:00 2001 From: Mark Nardi Date: Thu, 9 May 2024 15:35:01 +0200 Subject: [PATCH 1/8] cleanup explorer endpoints --- .../constants/explorer-endpoints.constant.ts | 42 ------------------- .../src/lib/core/network/constants/index.ts | 2 +- .../network/utils/getDefaultExplorerUrl.ts | 4 +- .../core/network/utils/getExplorerEndpoint.ts | 27 ++++++++++++ .../src/lib/core/network/utils/index.ts | 1 + 5 files changed, 31 insertions(+), 45 deletions(-) delete mode 100644 packages/shared/src/lib/core/network/constants/explorer-endpoints.constant.ts create mode 100644 packages/shared/src/lib/core/network/utils/getExplorerEndpoint.ts diff --git a/packages/shared/src/lib/core/network/constants/explorer-endpoints.constant.ts b/packages/shared/src/lib/core/network/constants/explorer-endpoints.constant.ts deleted file mode 100644 index 8067074838..0000000000 --- a/packages/shared/src/lib/core/network/constants/explorer-endpoints.constant.ts +++ /dev/null @@ -1,42 +0,0 @@ -import { ExplorerEndpoint } from '../enums' -import { NetworkId } from '../types' -import { SupportedNetworkId } from './supported-network-id.constant' - -export const EXPLORER_ENDPOINTS: Readonly<{ [key in NetworkId]?: { [key in ExplorerEndpoint]?: string } }> = { - [SupportedNetworkId.Iota]: { - [ExplorerEndpoint.Transaction]: `mainnet/${ExplorerEndpoint.Transaction}`, - [ExplorerEndpoint.Output]: `mainnet/${ExplorerEndpoint.Output}`, - [ExplorerEndpoint.Nft]: `mainnet/${ExplorerEndpoint.Nft}`, - [ExplorerEndpoint.Foundry]: `mainnet/${ExplorerEndpoint.Foundry}`, - [ExplorerEndpoint.Address]: 'mainnet/addr', - }, - [SupportedNetworkId.Shimmer]: { - [ExplorerEndpoint.Transaction]: `shimmer/${ExplorerEndpoint.Transaction}`, - [ExplorerEndpoint.Output]: `shimmer/${ExplorerEndpoint.Output}`, - [ExplorerEndpoint.Nft]: `shimmer/${ExplorerEndpoint.Nft}`, - [ExplorerEndpoint.Foundry]: `shimmer/${ExplorerEndpoint.Foundry}`, - [ExplorerEndpoint.Address]: 'shimmer/addr', - }, - [SupportedNetworkId.Testnet]: { - [ExplorerEndpoint.Transaction]: `testnet/${ExplorerEndpoint.Transaction}`, - [ExplorerEndpoint.Output]: `testnet/${ExplorerEndpoint.Output}`, - [ExplorerEndpoint.Nft]: `testnet/${ExplorerEndpoint.Nft}`, - [ExplorerEndpoint.Foundry]: `testnet/${ExplorerEndpoint.Foundry}`, - [ExplorerEndpoint.Address]: 'testnet/addr', - }, - [SupportedNetworkId.IotaEvm]: { - [ExplorerEndpoint.Transaction]: 'tx', - [ExplorerEndpoint.Token]: ExplorerEndpoint.Token, - [ExplorerEndpoint.Address]: ExplorerEndpoint.Address, - }, - [SupportedNetworkId.ShimmerEvm]: { - [ExplorerEndpoint.Transaction]: 'tx', - [ExplorerEndpoint.Token]: ExplorerEndpoint.Token, - [ExplorerEndpoint.Address]: ExplorerEndpoint.Address, - }, - [SupportedNetworkId.TestnetEvm]: { - [ExplorerEndpoint.Transaction]: 'tx', - [ExplorerEndpoint.Token]: ExplorerEndpoint.Token, - [ExplorerEndpoint.Address]: ExplorerEndpoint.Address, - }, -} diff --git a/packages/shared/src/lib/core/network/constants/index.ts b/packages/shared/src/lib/core/network/constants/index.ts index ca78462814..280049df78 100644 --- a/packages/shared/src/lib/core/network/constants/index.ts +++ b/packages/shared/src/lib/core/network/constants/index.ts @@ -12,7 +12,7 @@ export * from './default-protocol.constant' export * from './default-network-metadata.constant' export * from './default-node-urls.constant' export * from './empty-node.constant' -export * from './explorer-endpoints.constant' +export * from '../utils/getExplorerEndpoint' export * from './faucet-urls.constant' export * from './max-network-name-length.constant' export * from './milestone-not-found.constant' diff --git a/packages/shared/src/lib/core/network/utils/getDefaultExplorerUrl.ts b/packages/shared/src/lib/core/network/utils/getDefaultExplorerUrl.ts index 18e828e77d..5be2bef879 100644 --- a/packages/shared/src/lib/core/network/utils/getDefaultExplorerUrl.ts +++ b/packages/shared/src/lib/core/network/utils/getDefaultExplorerUrl.ts @@ -1,4 +1,4 @@ -import { DEFAULT_EXPLORER_URLS, EXPLORER_ENDPOINTS } from '../constants' +import { DEFAULT_EXPLORER_URLS, getExplorerEndpoint } from '../constants' import { ExplorerEndpoint } from '../enums' import { NetworkId } from '../types' @@ -10,7 +10,7 @@ export function getDefaultExplorerUrl( endpoint: string } { const baseUrl = DEFAULT_EXPLORER_URLS?.[networkId] ?? '' - const endpoint = EXPLORER_ENDPOINTS?.[networkId]?.[requestedEndpoint] ?? '' + const endpoint = getExplorerEndpoint(networkId, requestedEndpoint) ?? '' return { baseUrl, diff --git a/packages/shared/src/lib/core/network/utils/getExplorerEndpoint.ts b/packages/shared/src/lib/core/network/utils/getExplorerEndpoint.ts new file mode 100644 index 0000000000..6d538993a2 --- /dev/null +++ b/packages/shared/src/lib/core/network/utils/getExplorerEndpoint.ts @@ -0,0 +1,27 @@ +import { ExplorerEndpoint } from '../enums' +import { NetworkId } from '../types' +import { getExplorerApiNetworkName } from './getExplorerApiNetworkName' +import { isStardustNetwork } from './isStardustNetwork' +import { isEvmNetwork } from './isEvmNetwork' + +const STARDUST_EXPLORER_ENDPOINTS: Readonly<{ [key in ExplorerEndpoint]?: string }> = { + [ExplorerEndpoint.Transaction]: ExplorerEndpoint.Transaction, + [ExplorerEndpoint.Output]: ExplorerEndpoint.Output, + [ExplorerEndpoint.Nft]: ExplorerEndpoint.Nft, + [ExplorerEndpoint.Foundry]: ExplorerEndpoint.Foundry, + [ExplorerEndpoint.Address]: 'addr', +} + +const EVM_EXPLORER_ENDPOINTS: Readonly<{ [key in ExplorerEndpoint]?: string }> = { + [ExplorerEndpoint.Transaction]: 'tx', + [ExplorerEndpoint.Token]: ExplorerEndpoint.Token, + [ExplorerEndpoint.Address]: ExplorerEndpoint.Address, +} + +export function getExplorerEndpoint(networkId: NetworkId, explorerEndpoint: ExplorerEndpoint): string | undefined { + if (isStardustNetwork(networkId)) { + return `${getExplorerApiNetworkName(networkId)}/${STARDUST_EXPLORER_ENDPOINTS[explorerEndpoint]}` + } else if (isEvmNetwork(networkId)) { + return EVM_EXPLORER_ENDPOINTS[explorerEndpoint] + } +} diff --git a/packages/shared/src/lib/core/network/utils/index.ts b/packages/shared/src/lib/core/network/utils/index.ts index ccedd61c98..7301487f1b 100644 --- a/packages/shared/src/lib/core/network/utils/index.ts +++ b/packages/shared/src/lib/core/network/utils/index.ts @@ -9,6 +9,7 @@ export * from './getDefaultExplorerUrl' export * from './getDefaultNodes' export * from './getDefaultStardustNetwork' export * from './getEvmTransactionOptions' +export * from './getExplorerEndpoint' export * from './getExplorerApiNetworkName' export * from './getNetworkIdFromOnboardingNetworkType' export * from './getOnboardingNetworkTypeFromNetworkId' From b3edb64c8570189c2ff196cdb8f0ce995a93ac75 Mon Sep 17 00:00:00 2001 From: Mark Nardi Date: Thu, 9 May 2024 15:35:02 +0200 Subject: [PATCH 2/8] dont show explorer button for balance changes --- .../components/popup/popups/EvmActivityDetailsPopup.svelte | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/desktop/components/popup/popups/EvmActivityDetailsPopup.svelte b/packages/desktop/components/popup/popups/EvmActivityDetailsPopup.svelte index 7f5d79a2cb..9d4a73ddc3 100644 --- a/packages/desktop/components/popup/popups/EvmActivityDetailsPopup.svelte +++ b/packages/desktop/components/popup/popups/EvmActivityDetailsPopup.svelte @@ -33,6 +33,9 @@ $: explorerUrl = getExplorerUrl(activity) function getExplorerUrl(_activity: EvmActivity): string | undefined { + if (_activity.type === EvmActivityType.BalanceChange) { + return + } const { baseUrl, endpoint } = getDefaultExplorerUrl(activity?.sourceNetworkId, ExplorerEndpoint.Transaction) return buildUrl({ origin: baseUrl, pathname: `${endpoint}/${_activity?.transactionId}` })?.href } From 2087d8127a3d5199ebb17a4f9be063e602a11691 Mon Sep 17 00:00:00 2001 From: Mark Nardi Date: Fri, 10 May 2024 10:34:06 +0200 Subject: [PATCH 3/8] add explorer url to stardust network --- .../core/network/classes/stardust-network.class.ts | 2 ++ .../constants/default-network-metadata.constant.ts | 4 ++++ .../network/interfaces/base-network.interface.ts | 1 + .../network/interfaces/evm-network.interface.ts | 1 - .../profile/constants/profile-version.constant.ts | 2 +- .../alpha/alpha-profile-migration-18-to-19.ts | 13 +++++++++++++ .../prod/prod-profile-migration-8-to-9.ts | 7 ++++++- 7 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 packages/shared/src/lib/core/profile/migrations/alpha/alpha-profile-migration-18-to-19.ts diff --git a/packages/shared/src/lib/core/network/classes/stardust-network.class.ts b/packages/shared/src/lib/core/network/classes/stardust-network.class.ts index 91c2a02f61..1bb5e6ee16 100644 --- a/packages/shared/src/lib/core/network/classes/stardust-network.class.ts +++ b/packages/shared/src/lib/core/network/classes/stardust-network.class.ts @@ -21,6 +21,7 @@ export class StardustNetwork implements IStardustNetwork { public readonly bech32Hrp: string public readonly protocol: IProtocol public readonly baseToken: IBaseToken + public readonly explorerUrl: string | undefined public readonly type = NetworkType.Stardust public iscChains: IscChain[] @@ -38,6 +39,7 @@ export class StardustNetwork implements IStardustNetwork { this.networkName = persistedNetwork.protocol.networkName this.protocol = persistedNetwork.protocol this.baseToken = persistedNetwork.baseToken + this.explorerUrl = persistedNetwork.explorerUrl this.iscChains = persistedNetwork.chainConfigurations .map((chainConfiguration) => { diff --git a/packages/shared/src/lib/core/network/constants/default-network-metadata.constant.ts b/packages/shared/src/lib/core/network/constants/default-network-metadata.constant.ts index 568f5bad9e..d61574abe6 100644 --- a/packages/shared/src/lib/core/network/constants/default-network-metadata.constant.ts +++ b/packages/shared/src/lib/core/network/constants/default-network-metadata.constant.ts @@ -3,6 +3,7 @@ import { IStardustNetworkMetadata } from '../interfaces' import { NetworkMetadata, StardustNetworkId } from '../types' import { DEFAULT_BASE_TOKEN } from './default-base-token.constant' import { DEFAULT_COIN_TYPE } from './default-coin-type.constant' +import { DEFAULT_EXPLORER_URLS } from './default-explorer-urls.constant' import { DEFAULT_PROTOCOL } from './default-protocol.constant' import { SupportedNetworkId } from './supported-network-id.constant' @@ -15,6 +16,7 @@ export const DEFAULT_NETWORK_METADATA: Readonly<{ [key in StardustNetworkId]?: N coinType: DEFAULT_COIN_TYPE[SupportedNetworkId.Iota], protocol: DEFAULT_PROTOCOL[SupportedNetworkId.Iota], baseToken: DEFAULT_BASE_TOKEN[SupportedNetworkId.Iota], + explorerUrl: DEFAULT_EXPLORER_URLS[SupportedNetworkId.Iota], }, [SupportedNetworkId.Shimmer]: { id: SupportedNetworkId.Shimmer, @@ -23,6 +25,7 @@ export const DEFAULT_NETWORK_METADATA: Readonly<{ [key in StardustNetworkId]?: N coinType: DEFAULT_COIN_TYPE[SupportedNetworkId.Shimmer], protocol: DEFAULT_PROTOCOL[SupportedNetworkId.Shimmer], baseToken: DEFAULT_BASE_TOKEN[SupportedNetworkId.Shimmer], + explorerUrl: DEFAULT_EXPLORER_URLS[SupportedNetworkId.Shimmer], }, [SupportedNetworkId.Testnet]: { id: SupportedNetworkId.Testnet, @@ -31,5 +34,6 @@ export const DEFAULT_NETWORK_METADATA: Readonly<{ [key in StardustNetworkId]?: N coinType: DEFAULT_COIN_TYPE[SupportedNetworkId.Testnet], protocol: DEFAULT_PROTOCOL[SupportedNetworkId.Testnet], baseToken: DEFAULT_BASE_TOKEN[SupportedNetworkId.Testnet], + explorerUrl: DEFAULT_EXPLORER_URLS[SupportedNetworkId.Testnet], }, } diff --git a/packages/shared/src/lib/core/network/interfaces/base-network.interface.ts b/packages/shared/src/lib/core/network/interfaces/base-network.interface.ts index 47df3fd118..79d812d181 100644 --- a/packages/shared/src/lib/core/network/interfaces/base-network.interface.ts +++ b/packages/shared/src/lib/core/network/interfaces/base-network.interface.ts @@ -17,4 +17,5 @@ export interface IBaseNetworkMetadata { name: string baseToken: IBaseToken coinType: number + explorerUrl: string | undefined } diff --git a/packages/shared/src/lib/core/network/interfaces/evm-network.interface.ts b/packages/shared/src/lib/core/network/interfaces/evm-network.interface.ts index 7fb570df06..755944d7eb 100644 --- a/packages/shared/src/lib/core/network/interfaces/evm-network.interface.ts +++ b/packages/shared/src/lib/core/network/interfaces/evm-network.interface.ts @@ -28,7 +28,6 @@ export interface IEvmNetwork extends IBaseNetwork, IBaseNetworkMetadata { id: EvmNetworkId namespace: NetworkNamespace.Evm chainId: ChainId - explorerUrl: string | undefined rpcEndpoint: string provider: Web3Provider diff --git a/packages/shared/src/lib/core/profile/constants/profile-version.constant.ts b/packages/shared/src/lib/core/profile/constants/profile-version.constant.ts index 1a12367c83..0a6e60205b 100644 --- a/packages/shared/src/lib/core/profile/constants/profile-version.constant.ts +++ b/packages/shared/src/lib/core/profile/constants/profile-version.constant.ts @@ -1,7 +1,7 @@ import { AppStage } from '@core/app/enums' export const PROFILE_VERSION: Record = { - [AppStage.ALPHA]: 18, + [AppStage.ALPHA]: 19, [AppStage.BETA]: 1, [AppStage.PROD]: 9, } diff --git a/packages/shared/src/lib/core/profile/migrations/alpha/alpha-profile-migration-18-to-19.ts b/packages/shared/src/lib/core/profile/migrations/alpha/alpha-profile-migration-18-to-19.ts new file mode 100644 index 0000000000..9966705aa7 --- /dev/null +++ b/packages/shared/src/lib/core/profile/migrations/alpha/alpha-profile-migration-18-to-19.ts @@ -0,0 +1,13 @@ +import { DEFAULT_EXPLORER_URLS } from '@core/network' +import { IPersistedProfile } from '@core/profile/interfaces' + +export function alphaProfileMigration17To18(existingProfile: unknown): Promise { + const profile = existingProfile as IPersistedProfile + + profile.network = { + ...profile.network, + explorerUrl: DEFAULT_EXPLORER_URLS[profile.network.id], + } + + return Promise.resolve() +} diff --git a/packages/shared/src/lib/core/profile/migrations/prod/prod-profile-migration-8-to-9.ts b/packages/shared/src/lib/core/profile/migrations/prod/prod-profile-migration-8-to-9.ts index eb69df554d..b6e44a0789 100644 --- a/packages/shared/src/lib/core/profile/migrations/prod/prod-profile-migration-8-to-9.ts +++ b/packages/shared/src/lib/core/profile/migrations/prod/prod-profile-migration-8-to-9.ts @@ -1,6 +1,6 @@ import { DappVerification } from '@auxiliary/wallet-connect/enums' import { persistDapp, persistedDappNamespaces } from '@auxiliary/wallet-connect/stores' -import { DEFAULT_BASE_TOKEN } from '@core/network/constants' +import { DEFAULT_BASE_TOKEN, DEFAULT_EXPLORER_URLS } from '@core/network/constants' import { IPersistedProfile } from '@core/profile/interfaces' import { IBaseToken } from '@core/token/interfaces' import { persistedTokens } from '@core/token/stores' @@ -19,6 +19,11 @@ export function prodProfileMigration8To9(existingProfile: unknown): Promise ({ ...evmNetwork, baseToken: DEFAULT_BASE_TOKEN[evmNetwork.id] as IBaseToken, From 716db99b49648375ac314861b6c7dbd7015c6b77 Mon Sep 17 00:00:00 2001 From: Mark Nardi Date: Fri, 10 May 2024 10:40:16 +0200 Subject: [PATCH 4/8] rename `getDefaultExplorerUrl` to `getExplorerUrl` --- packages/desktop/components/ContactAddressCard.svelte | 4 ++-- packages/desktop/components/NetworkCard.svelte | 4 ++-- .../popup/popups/EvmActivityDetailsPopup.svelte | 8 ++++---- .../popup/popups/EvmTransactionFromDappPopup.svelte | 4 ++-- .../popup/popups/StardustActivityDetailsPopup.svelte | 10 +++++----- .../components/Erc721CollectibleDetails.svelte | 10 +++++----- .../components/Irc27CollectibleDetails.svelte | 10 +++++----- .../evm/info/EvmSmartContractInformation.svelte | 4 ++-- .../stardust/info/StardustAliasInformation.svelte | 4 ++-- .../stardust/info/StardustFoundryInformation.svelte | 6 +++--- .../stardust/info/StardustGenericInformation.svelte | 4 ++-- .../stardust/info/StardustNftInformation.svelte | 6 +++--- .../{getDefaultExplorerUrl.ts => getExplorerUrl.ts} | 7 ++++--- packages/shared/src/lib/core/network/utils/index.ts | 2 +- 14 files changed, 42 insertions(+), 41 deletions(-) rename packages/shared/src/lib/core/network/utils/{getDefaultExplorerUrl.ts => getExplorerUrl.ts} (64%) diff --git a/packages/desktop/components/ContactAddressCard.svelte b/packages/desktop/components/ContactAddressCard.svelte index 7c3cda58fc..b8210dfec9 100644 --- a/packages/desktop/components/ContactAddressCard.svelte +++ b/packages/desktop/components/ContactAddressCard.svelte @@ -3,7 +3,7 @@ import { IContact, IContactAddress, IContactAddressMap, setSelectedContactNetworkAddress } from '@core/contact' import { localize } from '@core/i18n' import { resetLedgerPreparedOutput, resetShowInternalVerificationPopup } from '@core/ledger' - import { ExplorerEndpoint, getDefaultExplorerUrl, getNameFromNetworkId, NetworkId } from '@core/network' + import { ExplorerEndpoint, getExplorerUrl, getNameFromNetworkId, NetworkId } from '@core/network' import { Router } from '@core/router' import { buildUrl, truncateString } from '@core/utils' import { SendFlowType, setSendFlowParameters, SubjectType } from '@core/wallet' @@ -21,7 +21,7 @@ export let contact: IContact export let contactAddressMap: IContactAddressMap - const explorer = getDefaultExplorerUrl(networkId, ExplorerEndpoint.Address) + const explorer = getExplorerUrl(networkId, ExplorerEndpoint.Address) function onExplorerClick(address: string): void { const url = buildUrl({ origin: explorer.baseUrl, pathname: `${explorer.endpoint}/${address}` }) diff --git a/packages/desktop/components/NetworkCard.svelte b/packages/desktop/components/NetworkCard.svelte index dfee38008b..421959336d 100644 --- a/packages/desktop/components/NetworkCard.svelte +++ b/packages/desktop/components/NetworkCard.svelte @@ -11,7 +11,7 @@ ExplorerEndpoint, Network, NetworkNamespace, - getDefaultExplorerUrl, + getExplorerUrl, setSelectedNetworkForNetworkDrawer, } from '@core/network' import { ProfileType } from '@core/profile' @@ -24,7 +24,7 @@ export let network: Network let address: string | undefined - const explorer = getDefaultExplorerUrl(network.id, ExplorerEndpoint.Address) + const explorer = getExplorerUrl(network.id, ExplorerEndpoint.Address) $: health = network.health $: address = getAddressFromAccountForNetwork($selectedAccount as IAccountState, network.id) diff --git a/packages/desktop/components/popup/popups/EvmActivityDetailsPopup.svelte b/packages/desktop/components/popup/popups/EvmActivityDetailsPopup.svelte index 9d4a73ddc3..471d404c9f 100644 --- a/packages/desktop/components/popup/popups/EvmActivityDetailsPopup.svelte +++ b/packages/desktop/components/popup/popups/EvmActivityDetailsPopup.svelte @@ -6,7 +6,7 @@ import { openUrlInBrowser } from '@core/app' import { localize } from '@core/i18n' import { ExplorerEndpoint } from '@core/network' - import { getDefaultExplorerUrl } from '@core/network/utils' + import { getExplorerUrl } from '@core/network/utils' import { NftStandard } from '@core/nfts' import { Nft } from '@core/nfts/interfaces' import { ownedNfts, selectedNftId, getNftByIdForAccount } from '@core/nfts/stores' @@ -31,12 +31,12 @@ } } - $: explorerUrl = getExplorerUrl(activity) - function getExplorerUrl(_activity: EvmActivity): string | undefined { + $: explorerUrl = buildExplorerUrl(activity) + function buildExplorerUrl(_activity: EvmActivity): string | undefined { if (_activity.type === EvmActivityType.BalanceChange) { return } - const { baseUrl, endpoint } = getDefaultExplorerUrl(activity?.sourceNetworkId, ExplorerEndpoint.Transaction) + const { baseUrl, endpoint } = getExplorerUrl(activity?.sourceNetworkId, ExplorerEndpoint.Transaction) return buildUrl({ origin: baseUrl, pathname: `${endpoint}/${_activity?.transactionId}` })?.href } diff --git a/packages/desktop/components/popup/popups/EvmTransactionFromDappPopup.svelte b/packages/desktop/components/popup/popups/EvmTransactionFromDappPopup.svelte index ed66aedd08..124ffe4377 100644 --- a/packages/desktop/components/popup/popups/EvmTransactionFromDappPopup.svelte +++ b/packages/desktop/components/popup/popups/EvmTransactionFromDappPopup.svelte @@ -5,7 +5,7 @@ import { CallbackParameters } from '@auxiliary/wallet-connect/types' import { sendAndPersistTransactionFromEvm, signEvmTransaction } from '@core/wallet/actions' import { getSelectedAccount, selectedAccount } from '@core/account/stores' - import { ExplorerEndpoint, IEvmNetwork, getDefaultExplorerUrl } from '@core/network' + import { ExplorerEndpoint, IEvmNetwork, getExplorerUrl } from '@core/network' import { DappInfo, TransactionAssetSection } from '@ui' import PopupTemplate from '../PopupTemplate.svelte' import { EvmTransactionData } from '@core/layer-2/types' @@ -166,7 +166,7 @@ } function onExplorerClick(contractAddress: string): void { - const { baseUrl, endpoint } = getDefaultExplorerUrl(evmNetwork.id, ExplorerEndpoint.Address) + const { baseUrl, endpoint } = getExplorerUrl(evmNetwork.id, ExplorerEndpoint.Address) const url = buildUrl({ origin: baseUrl, pathname: `${endpoint}/${contractAddress}` }) openUrlInBrowser(url?.href) } diff --git a/packages/desktop/components/popup/popups/StardustActivityDetailsPopup.svelte b/packages/desktop/components/popup/popups/StardustActivityDetailsPopup.svelte index 37bc5c7a5e..2f5f2fd075 100644 --- a/packages/desktop/components/popup/popups/StardustActivityDetailsPopup.svelte +++ b/packages/desktop/components/popup/popups/StardustActivityDetailsPopup.svelte @@ -12,7 +12,7 @@ import { openUrlInBrowser } from '@core/app' import { localize } from '@core/i18n' import { ExplorerEndpoint } from '@core/network' - import { getDefaultExplorerUrl } from '@core/network/utils' + import { getExplorerUrl } from '@core/network/utils' import { getNftByIdForAccount, ownedNfts, selectedNftId } from '@core/nfts/stores' import { CollectiblesRoute, DashboardRoute, collectiblesRouter, dashboardRouter } from '@core/router' import { buildUrl, setClipboard, truncateString } from '@core/utils' @@ -45,14 +45,14 @@ } } - $: explorerUrl = getExplorerUrl(activity) - function getExplorerUrl(_activity: StardustActivity): string | undefined { + $: explorerUrl = buildExplorerUrl(activity) + function buildExplorerUrl(_activity: StardustActivity): string | undefined { if (activity?.direction === ActivityDirection.Genesis) { - const { baseUrl, endpoint } = getDefaultExplorerUrl(activity?.sourceNetworkId, ExplorerEndpoint.Output) + const { baseUrl, endpoint } = getExplorerUrl(activity?.sourceNetworkId, ExplorerEndpoint.Output) const url = buildUrl({ origin: baseUrl, pathname: `${endpoint}/${_activity?.outputId}` }) return url?.href } else { - const { baseUrl, endpoint } = getDefaultExplorerUrl(activity?.sourceNetworkId, ExplorerEndpoint.Transaction) + const { baseUrl, endpoint } = getExplorerUrl(activity?.sourceNetworkId, ExplorerEndpoint.Transaction) const url = buildUrl({ origin: baseUrl, pathname: `${endpoint}/${_activity?.transactionId}` }) return url?.href } diff --git a/packages/desktop/views/dashboard/collectibles/components/Erc721CollectibleDetails.svelte b/packages/desktop/views/dashboard/collectibles/components/Erc721CollectibleDetails.svelte index 6471eea989..b7634ae6df 100644 --- a/packages/desktop/views/dashboard/collectibles/components/Erc721CollectibleDetails.svelte +++ b/packages/desktop/views/dashboard/collectibles/components/Erc721CollectibleDetails.svelte @@ -3,7 +3,7 @@ import { type IItem } from '@bloomwalletio/ui' import { localize } from '@core/i18n' import { IErc721Nft } from '@core/nfts' - import { ExplorerEndpoint, EvmNetworkId, getDefaultExplorerUrl } from '@core/network' + import { ExplorerEndpoint, EvmNetworkId, getExplorerUrl } from '@core/network' import CollectibleDetails from './CollectibleDetails.svelte' import { buildUrl } from '@core/utils' @@ -11,10 +11,10 @@ const { standard, networkId, contractMetadata, tokenId, metadata, mediaUrl } = nft const address = contractMetadata.address - const explorerEndpoint = getExplorerEndpoint(networkId) + const explorerUrl = buildExplorerUrl(networkId) - function getExplorerEndpoint(networkId: EvmNetworkId): string | undefined { - const { baseUrl, endpoint } = getDefaultExplorerUrl(networkId, ExplorerEndpoint.Token) + function buildExplorerUrl(networkId: EvmNetworkId): string | undefined { + const { baseUrl, endpoint } = getExplorerUrl(networkId, ExplorerEndpoint.Token) const url = buildUrl({ origin: baseUrl, pathname: tokenId ? `${endpoint}/${address}/instance/${tokenId}` : address, @@ -64,4 +64,4 @@ ] - + diff --git a/packages/desktop/views/dashboard/collectibles/components/Irc27CollectibleDetails.svelte b/packages/desktop/views/dashboard/collectibles/components/Irc27CollectibleDetails.svelte index ef72b2be55..9bf1016a27 100644 --- a/packages/desktop/views/dashboard/collectibles/components/Irc27CollectibleDetails.svelte +++ b/packages/desktop/views/dashboard/collectibles/components/Irc27CollectibleDetails.svelte @@ -1,7 +1,7 @@ - + diff --git a/packages/shared/src/components/activities/evm/info/EvmSmartContractInformation.svelte b/packages/shared/src/components/activities/evm/info/EvmSmartContractInformation.svelte index dc4af1aa66..b8250682ec 100644 --- a/packages/shared/src/components/activities/evm/info/EvmSmartContractInformation.svelte +++ b/packages/shared/src/components/activities/evm/info/EvmSmartContractInformation.svelte @@ -3,12 +3,12 @@ import { localize } from '@core/i18n' import { EvmContractCallActivity, EvmTokenMintingActivity, EvmTokenTransferActivity } from '@core/activity' import { openUrlInBrowser } from '@core/app' - import { ExplorerEndpoint, getDefaultExplorerUrl } from '@core/network' + import { ExplorerEndpoint, getExplorerUrl } from '@core/network' import { buildUrl } from '@core/utils' export let activity: EvmContractCallActivity | EvmTokenTransferActivity | EvmTokenMintingActivity - $: explorer = getDefaultExplorerUrl(activity.destinationNetworkId, ExplorerEndpoint.Address) + $: explorer = getExplorerUrl(activity.destinationNetworkId, ExplorerEndpoint.Address) function onExplorerClick(address: string): void { const url = buildUrl({ origin: explorer.baseUrl, pathname: `${explorer.endpoint}/${address}` }) openUrlInBrowser(url?.href) diff --git a/packages/shared/src/components/activities/stardust/info/StardustAliasInformation.svelte b/packages/shared/src/components/activities/stardust/info/StardustAliasInformation.svelte index 47a38fd543..5c6a91eb50 100644 --- a/packages/shared/src/components/activities/stardust/info/StardustAliasInformation.svelte +++ b/packages/shared/src/components/activities/stardust/info/StardustAliasInformation.svelte @@ -2,7 +2,7 @@ import { Table } from '@bloomwalletio/ui' import { localize } from '@core/i18n' import { StardustAliasActivity } from '@core/activity' - import { getDefaultExplorerUrl } from '@core/network/utils' + import { getExplorerUrl } from '@core/network/utils' import { ExplorerEndpoint } from '@core/network/enums' import { openUrlInBrowser } from '@core/app/utils' import { buildUrl } from '@core/utils/url' @@ -10,7 +10,7 @@ export let activity: StardustAliasActivity function onAddressClick(address: string) { - const { baseUrl, endpoint } = getDefaultExplorerUrl(activity?.sourceNetworkId, ExplorerEndpoint.Address) ?? '' + const { baseUrl, endpoint } = getExplorerUrl(activity?.sourceNetworkId, ExplorerEndpoint.Address) ?? '' const url = buildUrl({ origin: baseUrl, pathname: `${endpoint}/${address}` }) openUrlInBrowser(url?.href) } diff --git a/packages/shared/src/components/activities/stardust/info/StardustFoundryInformation.svelte b/packages/shared/src/components/activities/stardust/info/StardustFoundryInformation.svelte index 0be338be04..28af127531 100644 --- a/packages/shared/src/components/activities/stardust/info/StardustFoundryInformation.svelte +++ b/packages/shared/src/components/activities/stardust/info/StardustFoundryInformation.svelte @@ -4,19 +4,19 @@ import { openUrlInBrowser } from '@core/app' import { localize } from '@core/i18n' import { ExplorerEndpoint } from '@core/network/enums' - import { getDefaultExplorerUrl } from '@core/network/utils' + import { getExplorerUrl } from '@core/network/utils' import { buildUrl } from '@core/utils' export let activity: StardustFoundryActivity function onAliasClick(aliasAddress: string) { - const { baseUrl, endpoint } = getDefaultExplorerUrl(activity?.sourceNetworkId, ExplorerEndpoint.Address) + const { baseUrl, endpoint } = getExplorerUrl(activity?.sourceNetworkId, ExplorerEndpoint.Address) const url = buildUrl({ origin: baseUrl, pathname: `${endpoint}/${aliasAddress}` }) openUrlInBrowser(url?.href) } function onTokenClick(tokenId: string) { - const { baseUrl, endpoint } = getDefaultExplorerUrl(activity?.sourceNetworkId, ExplorerEndpoint.Foundry) + const { baseUrl, endpoint } = getExplorerUrl(activity?.sourceNetworkId, ExplorerEndpoint.Foundry) const url = buildUrl({ origin: baseUrl, pathname: `${endpoint}/${tokenId}` }) openUrlInBrowser(url?.href) } diff --git a/packages/shared/src/components/activities/stardust/info/StardustGenericInformation.svelte b/packages/shared/src/components/activities/stardust/info/StardustGenericInformation.svelte index b9db387564..f42d62a4e1 100644 --- a/packages/shared/src/components/activities/stardust/info/StardustGenericInformation.svelte +++ b/packages/shared/src/components/activities/stardust/info/StardustGenericInformation.svelte @@ -4,7 +4,7 @@ import { openUrlInBrowser } from '@core/app' import { time } from '@core/app/stores' import { getFormattedTimeStamp, localize } from '@core/i18n' - import { ExplorerEndpoint, getDefaultExplorerUrl, getNetwork } from '@core/network' + import { ExplorerEndpoint, getExplorerUrl, getNetwork } from '@core/network' import { formatTokenAmount } from '@core/token' import { buildUrl } from '@core/utils' import { getTimeDifference } from '@core/utils/time' @@ -21,7 +21,7 @@ $: formattedMaxGasFee = formatAmount(BigInt(gasLimit ?? 0)) $: formattedTransactionFee = formatAmount(activity.transactionFee ?? BigInt(0)) - $: explorer = getDefaultExplorerUrl(activity.sourceNetworkId, ExplorerEndpoint.Transaction) ?? '' + $: explorer = getExplorerUrl(activity.sourceNetworkId, ExplorerEndpoint.Transaction) ?? '' function onTransactionIdClick(): void { const url = buildUrl({ origin: explorer.baseUrl, diff --git a/packages/shared/src/components/activities/stardust/info/StardustNftInformation.svelte b/packages/shared/src/components/activities/stardust/info/StardustNftInformation.svelte index 6388824265..69e074fefe 100644 --- a/packages/shared/src/components/activities/stardust/info/StardustNftInformation.svelte +++ b/packages/shared/src/components/activities/stardust/info/StardustNftInformation.svelte @@ -5,7 +5,7 @@ import { openUrlInBrowser } from '@core/app/utils' import { localize } from '@core/i18n' import { ExplorerEndpoint } from '@core/network/enums' - import { getDefaultExplorerUrl } from '@core/network/utils' + import { getExplorerUrl } from '@core/network/utils' import { NftStandard } from '@core/nfts/enums' import { getNftByIdForAccount } from '@core/nfts/stores' import { buildUrl } from '@core/utils' @@ -18,13 +18,13 @@ $: issuer = nft?.standard === NftStandard.Irc27 ? nft?.issuer : undefined function onNftIdClick(nftId: string) { - const { baseUrl, endpoint } = getDefaultExplorerUrl(activity?.sourceNetworkId, ExplorerEndpoint.Nft) + const { baseUrl, endpoint } = getExplorerUrl(activity?.sourceNetworkId, ExplorerEndpoint.Nft) const url = buildUrl({ origin: baseUrl, pathname: `${endpoint}/${nftId}` }) openUrlInBrowser(url?.href) } function onIssuerClick(issuer: Address) { - const { baseUrl, endpoint } = getDefaultExplorerUrl(activity?.sourceNetworkId, ExplorerEndpoint.Address) + const { baseUrl, endpoint } = getExplorerUrl(activity?.sourceNetworkId, ExplorerEndpoint.Address) const url = buildUrl({ origin: baseUrl, pathname: `${endpoint}/${getBech32AddressFromAddressTypes(issuer)}` }) openUrlInBrowser(url?.href) } diff --git a/packages/shared/src/lib/core/network/utils/getDefaultExplorerUrl.ts b/packages/shared/src/lib/core/network/utils/getExplorerUrl.ts similarity index 64% rename from packages/shared/src/lib/core/network/utils/getDefaultExplorerUrl.ts rename to packages/shared/src/lib/core/network/utils/getExplorerUrl.ts index 5be2bef879..618a042aa7 100644 --- a/packages/shared/src/lib/core/network/utils/getDefaultExplorerUrl.ts +++ b/packages/shared/src/lib/core/network/utils/getExplorerUrl.ts @@ -1,15 +1,16 @@ -import { DEFAULT_EXPLORER_URLS, getExplorerEndpoint } from '../constants' +import { getExplorerEndpoint } from '../constants' import { ExplorerEndpoint } from '../enums' +import { getNetwork } from '../stores' import { NetworkId } from '../types' -export function getDefaultExplorerUrl( +export function getExplorerUrl( networkId: NetworkId, requestedEndpoint: ExplorerEndpoint ): { baseUrl: string endpoint: string } { - const baseUrl = DEFAULT_EXPLORER_URLS?.[networkId] ?? '' + const baseUrl = getNetwork(networkId)?.explorerUrl ?? '' const endpoint = getExplorerEndpoint(networkId, requestedEndpoint) ?? '' return { diff --git a/packages/shared/src/lib/core/network/utils/index.ts b/packages/shared/src/lib/core/network/utils/index.ts index 7301487f1b..ac15c45520 100644 --- a/packages/shared/src/lib/core/network/utils/index.ts +++ b/packages/shared/src/lib/core/network/utils/index.ts @@ -5,7 +5,7 @@ export * from './checkIfOnSameNetwork' export * from './checkNodeUrlValidity' export * from './getDefaultClientOptions' export * from './getAllNetworkIds' -export * from './getDefaultExplorerUrl' +export * from './getExplorerUrl' export * from './getDefaultNodes' export * from './getDefaultStardustNetwork' export * from './getEvmTransactionOptions' From fb713b8bc2d8adecb3a84ff56f133f75cdbfaf17 Mon Sep 17 00:00:00 2001 From: Mark Nardi Date: Fri, 10 May 2024 10:59:28 +0200 Subject: [PATCH 5/8] cleanup getExplorerUrl --- .../desktop/components/ContactAddressCard.svelte | 12 ++++++------ packages/desktop/components/NetworkCard.svelte | 11 +++++------ .../popup/popups/EvmActivityDetailsPopup.svelte | 5 ++--- .../popups/EvmTransactionFromDappPopup.svelte | 7 +++---- .../popups/StardustActivityDetailsPopup.svelte | 10 +++------- .../components/Erc721CollectibleDetails.svelte | 12 +++++------- .../components/Irc27CollectibleDetails.svelte | 15 ++------------- .../evm/info/EvmSmartContractInformation.svelte | 6 ++---- .../info/StardustAliasInformation.svelte | 6 ++---- .../info/StardustFoundryInformation.svelte | 11 ++++------- .../info/StardustGenericInformation.svelte | 16 ++++++++-------- .../stardust/info/StardustNftInformation.svelte | 15 ++++++++------- .../src/lib/core/network/utils/getExplorerUrl.ts | 15 ++++++--------- 13 files changed, 56 insertions(+), 85 deletions(-) diff --git a/packages/desktop/components/ContactAddressCard.svelte b/packages/desktop/components/ContactAddressCard.svelte index b8210dfec9..19ad9e6a34 100644 --- a/packages/desktop/components/ContactAddressCard.svelte +++ b/packages/desktop/components/ContactAddressCard.svelte @@ -3,9 +3,9 @@ import { IContact, IContactAddress, IContactAddressMap, setSelectedContactNetworkAddress } from '@core/contact' import { localize } from '@core/i18n' import { resetLedgerPreparedOutput, resetShowInternalVerificationPopup } from '@core/ledger' - import { ExplorerEndpoint, getExplorerUrl, getNameFromNetworkId, NetworkId } from '@core/network' + import { ExplorerEndpoint, getExplorerUrl, getNameFromNetworkId, getNetwork, NetworkId } from '@core/network' import { Router } from '@core/router' - import { buildUrl, truncateString } from '@core/utils' + import { truncateString } from '@core/utils' import { SendFlowType, setSendFlowParameters, SubjectType } from '@core/wallet' import { closeDrawer } from '@desktop/auxiliary/drawer' import { openPopup, PopupId } from '@desktop/auxiliary/popup' @@ -21,11 +21,11 @@ export let contact: IContact export let contactAddressMap: IContactAddressMap - const explorer = getExplorerUrl(networkId, ExplorerEndpoint.Address) + const hasExplorer = !!getNetwork(networkId)?.explorerUrl function onExplorerClick(address: string): void { - const url = buildUrl({ origin: explorer.baseUrl, pathname: `${explorer.endpoint}/${address}` }) - openUrlInBrowser(url?.href) + const url = getExplorerUrl(networkId, ExplorerEndpoint.Address, address) + openUrlInBrowser(url) } function onQrCodeClick(contactAddress: IContactAddress): void { @@ -72,7 +72,7 @@
- {#if explorer.baseUrl} + {#if hasExplorer}
- {#if explorer?.baseUrl && address} + {#if network.explorerUrl && address} diff --git a/packages/desktop/components/popup/popups/StardustActivityDetailsPopup.svelte b/packages/desktop/components/popup/popups/StardustActivityDetailsPopup.svelte index 2f5f2fd075..6645c1db70 100644 --- a/packages/desktop/components/popup/popups/StardustActivityDetailsPopup.svelte +++ b/packages/desktop/components/popup/popups/StardustActivityDetailsPopup.svelte @@ -15,7 +15,7 @@ import { getExplorerUrl } from '@core/network/utils' import { getNftByIdForAccount, ownedNfts, selectedNftId } from '@core/nfts/stores' import { CollectiblesRoute, DashboardRoute, collectiblesRouter, dashboardRouter } from '@core/router' - import { buildUrl, setClipboard, truncateString } from '@core/utils' + import { setClipboard, truncateString } from '@core/utils' import { claimActivity, rejectActivity } from '@core/wallet' import { PopupId, closePopup, openPopup } from '@desktop/auxiliary/popup' import { StardustActivityInformation, TransactionAssetSection } from '@ui' @@ -48,13 +48,9 @@ $: explorerUrl = buildExplorerUrl(activity) function buildExplorerUrl(_activity: StardustActivity): string | undefined { if (activity?.direction === ActivityDirection.Genesis) { - const { baseUrl, endpoint } = getExplorerUrl(activity?.sourceNetworkId, ExplorerEndpoint.Output) - const url = buildUrl({ origin: baseUrl, pathname: `${endpoint}/${_activity?.outputId}` }) - return url?.href + return getExplorerUrl(activity?.sourceNetworkId, ExplorerEndpoint.Output, _activity?.outputId) } else { - const { baseUrl, endpoint } = getExplorerUrl(activity?.sourceNetworkId, ExplorerEndpoint.Transaction) - const url = buildUrl({ origin: baseUrl, pathname: `${endpoint}/${_activity?.transactionId}` }) - return url?.href + return getExplorerUrl(activity?.sourceNetworkId, ExplorerEndpoint.Transaction, _activity?.transactionId) } } diff --git a/packages/desktop/views/dashboard/collectibles/components/Erc721CollectibleDetails.svelte b/packages/desktop/views/dashboard/collectibles/components/Erc721CollectibleDetails.svelte index b7634ae6df..df85163789 100644 --- a/packages/desktop/views/dashboard/collectibles/components/Erc721CollectibleDetails.svelte +++ b/packages/desktop/views/dashboard/collectibles/components/Erc721CollectibleDetails.svelte @@ -5,7 +5,6 @@ import { IErc721Nft } from '@core/nfts' import { ExplorerEndpoint, EvmNetworkId, getExplorerUrl } from '@core/network' import CollectibleDetails from './CollectibleDetails.svelte' - import { buildUrl } from '@core/utils' export let nft: IErc721Nft @@ -14,12 +13,11 @@ const explorerUrl = buildExplorerUrl(networkId) function buildExplorerUrl(networkId: EvmNetworkId): string | undefined { - const { baseUrl, endpoint } = getExplorerUrl(networkId, ExplorerEndpoint.Token) - const url = buildUrl({ - origin: baseUrl, - pathname: tokenId ? `${endpoint}/${address}/instance/${tokenId}` : address, - }) - return url?.href + if (tokenId) { + return getExplorerUrl(networkId, ExplorerEndpoint.Token, `${address}/instance/${tokenId}`) + } else { + return getExplorerUrl(networkId, ExplorerEndpoint.Address, address) + } } let details: IItem[] = [] diff --git a/packages/desktop/views/dashboard/collectibles/components/Irc27CollectibleDetails.svelte b/packages/desktop/views/dashboard/collectibles/components/Irc27CollectibleDetails.svelte index 9bf1016a27..89d17d44c3 100644 --- a/packages/desktop/views/dashboard/collectibles/components/Irc27CollectibleDetails.svelte +++ b/packages/desktop/views/dashboard/collectibles/components/Irc27CollectibleDetails.svelte @@ -9,14 +9,14 @@ import { AddressType } from '@iota/sdk/out/types' import { NetworkLabel } from '@ui' import CollectibleDetails from './CollectibleDetails.svelte' - import { buildUrl } from '@core/utils/url' export let nft: IIrc27Nft const { id, issuer, nftAddress, metadata, storageDeposit, mediaUrl } = nft ?? {} const { standard, version, issuerName, collectionName } = nft?.metadata || {} - const explorerUrl = buildExplorerUrl() + // We don't use `nft.networkId` on this one, as for IRC27 nfts we still want the L1 explorer + const explorerUrl = getExplorerUrl(getActiveNetworkId(), ExplorerEndpoint.Nft, id) const issuerAddress = getBech32AddressFromAddressTypes(issuer) const collectionId = getHexAddressFromAddressTypes(issuer) @@ -83,17 +83,6 @@ copyable: true, }, ] - - function buildExplorerUrl(): string | undefined { - // We don't use `nft.networkId` on this one, as for IRC27 nfts we still want the L1 explorer - const { baseUrl, endpoint } = getExplorerUrl(getActiveNetworkId(), ExplorerEndpoint.Nft) - const url = buildUrl({ - origin: baseUrl, - pathname: `${endpoint}/${id}`, - }) - - return url?.href - } diff --git a/packages/shared/src/components/activities/evm/info/EvmSmartContractInformation.svelte b/packages/shared/src/components/activities/evm/info/EvmSmartContractInformation.svelte index b8250682ec..10585f1736 100644 --- a/packages/shared/src/components/activities/evm/info/EvmSmartContractInformation.svelte +++ b/packages/shared/src/components/activities/evm/info/EvmSmartContractInformation.svelte @@ -4,14 +4,12 @@ import { EvmContractCallActivity, EvmTokenMintingActivity, EvmTokenTransferActivity } from '@core/activity' import { openUrlInBrowser } from '@core/app' import { ExplorerEndpoint, getExplorerUrl } from '@core/network' - import { buildUrl } from '@core/utils' export let activity: EvmContractCallActivity | EvmTokenTransferActivity | EvmTokenMintingActivity - $: explorer = getExplorerUrl(activity.destinationNetworkId, ExplorerEndpoint.Address) function onExplorerClick(address: string): void { - const url = buildUrl({ origin: explorer.baseUrl, pathname: `${explorer.endpoint}/${address}` }) - openUrlInBrowser(url?.href) + const url = getExplorerUrl(activity.destinationNetworkId, ExplorerEndpoint.Address, address) + openUrlInBrowser(url) } diff --git a/packages/shared/src/components/activities/stardust/info/StardustAliasInformation.svelte b/packages/shared/src/components/activities/stardust/info/StardustAliasInformation.svelte index 5c6a91eb50..64857ecadc 100644 --- a/packages/shared/src/components/activities/stardust/info/StardustAliasInformation.svelte +++ b/packages/shared/src/components/activities/stardust/info/StardustAliasInformation.svelte @@ -5,14 +5,12 @@ import { getExplorerUrl } from '@core/network/utils' import { ExplorerEndpoint } from '@core/network/enums' import { openUrlInBrowser } from '@core/app/utils' - import { buildUrl } from '@core/utils/url' export let activity: StardustAliasActivity function onAddressClick(address: string) { - const { baseUrl, endpoint } = getExplorerUrl(activity?.sourceNetworkId, ExplorerEndpoint.Address) ?? '' - const url = buildUrl({ origin: baseUrl, pathname: `${endpoint}/${address}` }) - openUrlInBrowser(url?.href) + const url = getExplorerUrl(activity?.sourceNetworkId, ExplorerEndpoint.Address, address) + openUrlInBrowser(url) } diff --git a/packages/shared/src/components/activities/stardust/info/StardustFoundryInformation.svelte b/packages/shared/src/components/activities/stardust/info/StardustFoundryInformation.svelte index 28af127531..4fcbf565b7 100644 --- a/packages/shared/src/components/activities/stardust/info/StardustFoundryInformation.svelte +++ b/packages/shared/src/components/activities/stardust/info/StardustFoundryInformation.svelte @@ -5,20 +5,17 @@ import { localize } from '@core/i18n' import { ExplorerEndpoint } from '@core/network/enums' import { getExplorerUrl } from '@core/network/utils' - import { buildUrl } from '@core/utils' export let activity: StardustFoundryActivity function onAliasClick(aliasAddress: string) { - const { baseUrl, endpoint } = getExplorerUrl(activity?.sourceNetworkId, ExplorerEndpoint.Address) - const url = buildUrl({ origin: baseUrl, pathname: `${endpoint}/${aliasAddress}` }) - openUrlInBrowser(url?.href) + const url = getExplorerUrl(activity?.sourceNetworkId, ExplorerEndpoint.Address, aliasAddress) + openUrlInBrowser(url) } function onTokenClick(tokenId: string) { - const { baseUrl, endpoint } = getExplorerUrl(activity?.sourceNetworkId, ExplorerEndpoint.Foundry) - const url = buildUrl({ origin: baseUrl, pathname: `${endpoint}/${tokenId}` }) - openUrlInBrowser(url?.href) + const url = getExplorerUrl(activity?.sourceNetworkId, ExplorerEndpoint.Foundry, tokenId) + openUrlInBrowser(url) } diff --git a/packages/shared/src/components/activities/stardust/info/StardustGenericInformation.svelte b/packages/shared/src/components/activities/stardust/info/StardustGenericInformation.svelte index f42d62a4e1..3006ba1021 100644 --- a/packages/shared/src/components/activities/stardust/info/StardustGenericInformation.svelte +++ b/packages/shared/src/components/activities/stardust/info/StardustGenericInformation.svelte @@ -6,7 +6,6 @@ import { getFormattedTimeStamp, localize } from '@core/i18n' import { ExplorerEndpoint, getExplorerUrl, getNetwork } from '@core/network' import { formatTokenAmount } from '@core/token' - import { buildUrl } from '@core/utils' import { getTimeDifference } from '@core/utils/time' import { NetworkLabel, ExpiredPill, TimelockPill, UnclaimedPill } from '@ui' @@ -21,13 +20,14 @@ $: formattedMaxGasFee = formatAmount(BigInt(gasLimit ?? 0)) $: formattedTransactionFee = formatAmount(activity.transactionFee ?? BigInt(0)) - $: explorer = getExplorerUrl(activity.sourceNetworkId, ExplorerEndpoint.Transaction) ?? '' + $: hasExplorer = !!getNetwork(activity.sourceNetworkId)?.explorerUrl function onTransactionIdClick(): void { - const url = buildUrl({ - origin: explorer.baseUrl, - pathname: `${explorer.endpoint}/${activity.asyncData?.claimingTransactionId}`, - }) - openUrlInBrowser(url?.href) + const url = getExplorerUrl( + activity.sourceNetworkId, + ExplorerEndpoint.Transaction, + activity.asyncData?.claimingTransactionId + ) + openUrlInBrowser(url) } function formatAmount(amount: bigint | undefined): string | undefined { @@ -129,7 +129,7 @@ value: activity.asyncData?.claimingTransactionId, copyable: true, truncate: { firstCharCount: 12, endCharCount: 12 }, - onClick: explorer.baseUrl ? onTransactionIdClick : undefined, + onClick: hasExplorer ? onTransactionIdClick : undefined, }, ]} /> diff --git a/packages/shared/src/components/activities/stardust/info/StardustNftInformation.svelte b/packages/shared/src/components/activities/stardust/info/StardustNftInformation.svelte index 69e074fefe..ae504475ac 100644 --- a/packages/shared/src/components/activities/stardust/info/StardustNftInformation.svelte +++ b/packages/shared/src/components/activities/stardust/info/StardustNftInformation.svelte @@ -8,7 +8,6 @@ import { getExplorerUrl } from '@core/network/utils' import { NftStandard } from '@core/nfts/enums' import { getNftByIdForAccount } from '@core/nfts/stores' - import { buildUrl } from '@core/utils' import { getBech32AddressFromAddressTypes, getHexAddressFromAddressTypes } from '@core/wallet' import { type Address, AddressType } from '@iota/sdk/out/types' @@ -18,15 +17,17 @@ $: issuer = nft?.standard === NftStandard.Irc27 ? nft?.issuer : undefined function onNftIdClick(nftId: string) { - const { baseUrl, endpoint } = getExplorerUrl(activity?.sourceNetworkId, ExplorerEndpoint.Nft) - const url = buildUrl({ origin: baseUrl, pathname: `${endpoint}/${nftId}` }) - openUrlInBrowser(url?.href) + const url = getExplorerUrl(activity?.sourceNetworkId, ExplorerEndpoint.Nft, nftId) + openUrlInBrowser(url) } function onIssuerClick(issuer: Address) { - const { baseUrl, endpoint } = getExplorerUrl(activity?.sourceNetworkId, ExplorerEndpoint.Address) - const url = buildUrl({ origin: baseUrl, pathname: `${endpoint}/${getBech32AddressFromAddressTypes(issuer)}` }) - openUrlInBrowser(url?.href) + const url = getExplorerUrl( + activity?.sourceNetworkId, + ExplorerEndpoint.Address, + getBech32AddressFromAddressTypes(issuer) + ) + openUrlInBrowser(url) } diff --git a/packages/shared/src/lib/core/network/utils/getExplorerUrl.ts b/packages/shared/src/lib/core/network/utils/getExplorerUrl.ts index 618a042aa7..5ea418b6d7 100644 --- a/packages/shared/src/lib/core/network/utils/getExplorerUrl.ts +++ b/packages/shared/src/lib/core/network/utils/getExplorerUrl.ts @@ -1,3 +1,4 @@ +import { buildUrl } from '@core/utils/url' import { getExplorerEndpoint } from '../constants' import { ExplorerEndpoint } from '../enums' import { getNetwork } from '../stores' @@ -5,16 +6,12 @@ import { NetworkId } from '../types' export function getExplorerUrl( networkId: NetworkId, - requestedEndpoint: ExplorerEndpoint -): { - baseUrl: string - endpoint: string -} { + requestedEndpoint: ExplorerEndpoint, + pathParameter?: string +): string | undefined { const baseUrl = getNetwork(networkId)?.explorerUrl ?? '' const endpoint = getExplorerEndpoint(networkId, requestedEndpoint) ?? '' - return { - baseUrl, - endpoint, - } + const url = buildUrl({ origin: baseUrl, pathname: `${endpoint}${pathParameter ? '/' + pathParameter : ''}` }) + return url?.href } From 170a01bf7efe4550e242c29b13406d454f35da65 Mon Sep 17 00:00:00 2001 From: Mark Nardi Date: Fri, 10 May 2024 11:10:23 +0200 Subject: [PATCH 6/8] fix imports --- packages/shared/src/lib/core/network/constants/index.ts | 1 - packages/shared/src/lib/core/network/utils/getExplorerUrl.ts | 2 +- packages/shared/src/lib/core/network/utils/index.ts | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/shared/src/lib/core/network/constants/index.ts b/packages/shared/src/lib/core/network/constants/index.ts index 280049df78..68e176a217 100644 --- a/packages/shared/src/lib/core/network/constants/index.ts +++ b/packages/shared/src/lib/core/network/constants/index.ts @@ -12,7 +12,6 @@ export * from './default-protocol.constant' export * from './default-network-metadata.constant' export * from './default-node-urls.constant' export * from './empty-node.constant' -export * from '../utils/getExplorerEndpoint' export * from './faucet-urls.constant' export * from './max-network-name-length.constant' export * from './milestone-not-found.constant' diff --git a/packages/shared/src/lib/core/network/utils/getExplorerUrl.ts b/packages/shared/src/lib/core/network/utils/getExplorerUrl.ts index 5ea418b6d7..a8dba19500 100644 --- a/packages/shared/src/lib/core/network/utils/getExplorerUrl.ts +++ b/packages/shared/src/lib/core/network/utils/getExplorerUrl.ts @@ -1,5 +1,5 @@ import { buildUrl } from '@core/utils/url' -import { getExplorerEndpoint } from '../constants' +import { getExplorerEndpoint } from '../utils' import { ExplorerEndpoint } from '../enums' import { getNetwork } from '../stores' import { NetworkId } from '../types' diff --git a/packages/shared/src/lib/core/network/utils/index.ts b/packages/shared/src/lib/core/network/utils/index.ts index ac15c45520..20ebbb806e 100644 --- a/packages/shared/src/lib/core/network/utils/index.ts +++ b/packages/shared/src/lib/core/network/utils/index.ts @@ -5,11 +5,11 @@ export * from './checkIfOnSameNetwork' export * from './checkNodeUrlValidity' export * from './getDefaultClientOptions' export * from './getAllNetworkIds' -export * from './getExplorerUrl' export * from './getDefaultNodes' export * from './getDefaultStardustNetwork' export * from './getEvmTransactionOptions' export * from './getExplorerEndpoint' +export * from './getExplorerUrl' export * from './getExplorerApiNetworkName' export * from './getNetworkIdFromOnboardingNetworkType' export * from './getOnboardingNetworkTypeFromNetworkId' From 6b0ce35ccbb7bc58ce802a79ee30a90be969f907 Mon Sep 17 00:00:00 2001 From: Mark Nardi Date: Fri, 10 May 2024 12:06:04 +0200 Subject: [PATCH 7/8] fix migrations --- .../migrations/alpha/alpha-profile-migration-18-to-19.ts | 4 ++-- .../profile/migrations/alpha/alpha-profile-migration-map.ts | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/shared/src/lib/core/profile/migrations/alpha/alpha-profile-migration-18-to-19.ts b/packages/shared/src/lib/core/profile/migrations/alpha/alpha-profile-migration-18-to-19.ts index 9966705aa7..bb5d825951 100644 --- a/packages/shared/src/lib/core/profile/migrations/alpha/alpha-profile-migration-18-to-19.ts +++ b/packages/shared/src/lib/core/profile/migrations/alpha/alpha-profile-migration-18-to-19.ts @@ -1,12 +1,12 @@ import { DEFAULT_EXPLORER_URLS } from '@core/network' import { IPersistedProfile } from '@core/profile/interfaces' -export function alphaProfileMigration17To18(existingProfile: unknown): Promise { +export function alphaProfileMigration18To19(existingProfile: unknown): Promise { const profile = existingProfile as IPersistedProfile profile.network = { ...profile.network, - explorerUrl: DEFAULT_EXPLORER_URLS[profile.network.id], + explorerUrl: structuredClone(DEFAULT_EXPLORER_URLS[profile.network.id]), } return Promise.resolve() diff --git a/packages/shared/src/lib/core/profile/migrations/alpha/alpha-profile-migration-map.ts b/packages/shared/src/lib/core/profile/migrations/alpha/alpha-profile-migration-map.ts index f3f5cb2a06..e262bfa00c 100644 --- a/packages/shared/src/lib/core/profile/migrations/alpha/alpha-profile-migration-map.ts +++ b/packages/shared/src/lib/core/profile/migrations/alpha/alpha-profile-migration-map.ts @@ -9,6 +9,7 @@ import { alphaProfileMigration14To15 } from './alpha-profile-migration-14-to-15' import { alphaProfileMigration15To16 } from './alpha-profile-migration-15-to-16' import { alphaProfileMigration16To17 } from './alpha-profile-migration-16-to-17' import { alphaProfileMigration17To18 } from './alpha-profile-migration-17-to-18' +import { alphaProfileMigration18To19 } from './alpha-profile-migration-18-to-19' import { alphaProfileMigration2To3 } from './alpha-profile-migration-2-to-3' import { alphaProfileMigration3To4 } from './alpha-profile-migration-3-to-4' import { alphaProfileMigration4To5 } from './alpha-profile-migration-4-to-5' @@ -37,4 +38,5 @@ export const ALPHA_PROFILE_MIGRATION_MAP: ProfileMigrationMap = { 15: alphaProfileMigration15To16, 16: alphaProfileMigration16To17, 17: alphaProfileMigration17To18, + 18: alphaProfileMigration18To19, } From c34be4b2b3a09176852ef4260969d55479b19e79 Mon Sep 17 00:00:00 2001 From: Mark Nardi Date: Tue, 14 May 2024 10:51:23 +0200 Subject: [PATCH 8/8] add default values to firefly import --- .../buildPersistedProfileFromThirdPartyPersistedProfile.ts | 3 +++ .../utils/buildPersistedNetworkFromNodeInfoResponse.ts | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/shared/src/lib/auxiliary/third-party/utils/buildPersistedProfileFromThirdPartyPersistedProfile.ts b/packages/shared/src/lib/auxiliary/third-party/utils/buildPersistedProfileFromThirdPartyPersistedProfile.ts index 6be5908b6b..ace1a247bf 100644 --- a/packages/shared/src/lib/auxiliary/third-party/utils/buildPersistedProfileFromThirdPartyPersistedProfile.ts +++ b/packages/shared/src/lib/auxiliary/third-party/utils/buildPersistedProfileFromThirdPartyPersistedProfile.ts @@ -2,6 +2,7 @@ import { IPersistedAccountData } from '@core/account' import { APP_STAGE } from '@core/app' import { MarketCurrency } from '@core/market' import { + DEFAULT_EXPLORER_URLS, DEFAULT_ISC_CHAINS_CONFIGURATIONS, IStardustNetworkMetadata, NetworkNamespace, @@ -78,6 +79,7 @@ function buildStardustNetworkFromThirdPartyPersistedNetwork( NETWORK_NAME_TO_STARDUST_NETWORK_ID_MAP[network.protocol.networkName] ?? `${NetworkNamespace.Stardust}:${network.protocol.networkName}` const defaultChainConfigurations = structuredClone(DEFAULT_ISC_CHAINS_CONFIGURATIONS?.[networkId]) + const explorerUrl = DEFAULT_EXPLORER_URLS[networkId] return { id: networkId, @@ -87,6 +89,7 @@ function buildStardustNetworkFromThirdPartyPersistedNetwork( protocol: network.protocol, baseToken: network.baseToken, chainConfigurations: defaultChainConfigurations ? [defaultChainConfigurations] : [], + explorerUrl, } } diff --git a/packages/shared/src/lib/core/network/utils/buildPersistedNetworkFromNodeInfoResponse.ts b/packages/shared/src/lib/core/network/utils/buildPersistedNetworkFromNodeInfoResponse.ts index 3df66fe98b..2c18279ce5 100644 --- a/packages/shared/src/lib/core/network/utils/buildPersistedNetworkFromNodeInfoResponse.ts +++ b/packages/shared/src/lib/core/network/utils/buildPersistedNetworkFromNodeInfoResponse.ts @@ -4,6 +4,7 @@ import { DEFAULT_COIN_TYPE, DEFAULT_NETWORK_METADATA, TEST_COIN_TYPE, + DEFAULT_EXPLORER_URLS, } from '../constants' import { TokenStandard } from '@core/token/enums' import { INodeInfoResponse, IStardustNetworkMetadata } from '../interfaces' @@ -21,7 +22,8 @@ export function buildPersistedNetworkFromNodeInfoResponse( const _coinType = coinType ?? DEFAULT_COIN_TYPE[id] ?? TEST_COIN_TYPE const configuration = DEFAULT_ISC_CHAINS_CONFIGURATIONS?.[id] - const chainConfigurations = configuration ? [configuration] : [] + const chainConfigurations = configuration ? [structuredClone(configuration)] : [] + const explorerUrl = DEFAULT_EXPLORER_URLS[id] return { id, name, @@ -30,5 +32,6 @@ export function buildPersistedNetworkFromNodeInfoResponse( protocol: nodeInfoResponse?.nodeInfo?.protocol, baseToken: { standard: TokenStandard.BaseToken, ...nodeInfoResponse?.nodeInfo?.baseToken }, chainConfigurations, + explorerUrl, } }