From 4356565fc82457f5553a18a92586f9332acaee48 Mon Sep 17 00:00:00 2001 From: hunaniangstudio <891863891@qq.com> Date: Sat, 7 Sep 2024 16:21:43 +0800 Subject: [PATCH] feat: set unisat explorer as default explorer in fractal --- src/shared/constant/index.ts | 19 +++++++++----- .../components/AddressDetailPopover/index.tsx | 6 ++--- src/ui/pages/Atomicals/AtomicalsNFTScreen.tsx | 4 +-- src/ui/pages/Main/WalletTabScreen/index.tsx | 6 ++--- .../Ordinals/OrdinalsInscriptionScreen.tsx | 4 +-- src/ui/pages/Runes/RunesTokenScreen.tsx | 26 ++++++++++--------- src/ui/pages/Wallet/TxSuccessScreen.tsx | 8 +++--- src/ui/pages/Wallet/UnavailableUtxoScreen.tsx | 6 ++--- src/ui/state/settings/hooks.ts | 25 +++++++++++------- 9 files changed, 59 insertions(+), 45 deletions(-) diff --git a/src/shared/constant/index.ts b/src/shared/constant/index.ts index f36c40ab..c537c6dc 100644 --- a/src/shared/constant/index.ts +++ b/src/shared/constant/index.ts @@ -236,6 +236,7 @@ type TypeChain = { disable?: boolean; isFractal?: boolean; showPrice: boolean; + defaultExplorer: 'mempool-space' | 'unisat-explorer'; }; export const CHAINS_MAP: { [key: string]: TypeChain } = { @@ -251,7 +252,8 @@ export const CHAINS_MAP: { [key: string]: TypeChain } = { ordinalsUrl: 'https://ordinals.com', unisatExplorerUrl: '', okxExplorerUrl: '', - showPrice: true + showPrice: true, + defaultExplorer: 'mempool-space' }, [ChainType.BITCOIN_TESTNET]: { enum: ChainType.BITCOIN_TESTNET, @@ -265,7 +267,8 @@ export const CHAINS_MAP: { [key: string]: TypeChain } = { ordinalsUrl: 'https://testnet.ordinals.com', unisatExplorerUrl: '', okxExplorerUrl: '', - showPrice: false + showPrice: false, + defaultExplorer: 'mempool-space' }, [ChainType.BITCOIN_TESTNET4]: { enum: ChainType.BITCOIN_TESTNET4, @@ -279,7 +282,8 @@ export const CHAINS_MAP: { [key: string]: TypeChain } = { ordinalsUrl: 'https://testnet4.ordinals.com', unisatExplorerUrl: '', okxExplorerUrl: '', - showPrice: false + showPrice: false, + defaultExplorer: 'mempool-space' }, [ChainType.BITCOIN_SIGNET]: { enum: ChainType.BITCOIN_SIGNET, @@ -293,7 +297,8 @@ export const CHAINS_MAP: { [key: string]: TypeChain } = { ordinalsUrl: 'https://signet.ordinals.com', unisatExplorerUrl: '', okxExplorerUrl: '', - showPrice: false + showPrice: false, + defaultExplorer: 'mempool-space' }, [ChainType.FRACTAL_BITCOIN_MAINNET]: { enum: ChainType.FRACTAL_BITCOIN_MAINNET, @@ -310,7 +315,8 @@ export const CHAINS_MAP: { [key: string]: TypeChain } = { isViewTxHistoryInternally: false, disable: false, isFractal: true, - showPrice: true + showPrice: true, + defaultExplorer: 'unisat-explorer' }, [ChainType.FRACTAL_BITCOIN_TESTNET]: { enum: ChainType.FRACTAL_BITCOIN_TESTNET, @@ -326,7 +332,8 @@ export const CHAINS_MAP: { [key: string]: TypeChain } = { okxExplorerUrl: '', isViewTxHistoryInternally: false, isFractal: true, - showPrice: false + showPrice: false, + defaultExplorer: 'unisat-explorer' } }; diff --git a/src/ui/components/AddressDetailPopover/index.tsx b/src/ui/components/AddressDetailPopover/index.tsx index cb283871..8dede793 100644 --- a/src/ui/components/AddressDetailPopover/index.tsx +++ b/src/ui/components/AddressDetailPopover/index.tsx @@ -1,4 +1,4 @@ -import { useBlockstreamUrl } from '@/ui/state/settings/hooks'; +import { useAddressExplorerUrl } from '@/ui/state/settings/hooks'; import { copyToClipboard, shortAddress } from '@/ui/utils'; import { useTools } from '../ActionComponent'; @@ -11,7 +11,7 @@ import { Text } from '../Text'; export const AddressDetailPopover = ({ address, onClose }: { address: string; onClose: () => void }) => { const tools = useTools(); - const blockstreamUrl = useBlockstreamUrl(); + const addressExplorerUrl = useAddressExplorerUrl(address); return ( @@ -37,7 +37,7 @@ export const AddressDetailPopover = ({ address, onClose }: { address: string; on { - window.open(`${blockstreamUrl}/address/${address}`); + window.open(addressExplorerUrl); }}> diff --git a/src/ui/pages/Atomicals/AtomicalsNFTScreen.tsx b/src/ui/pages/Atomicals/AtomicalsNFTScreen.tsx index faf79646..c76e457e 100644 --- a/src/ui/pages/Atomicals/AtomicalsNFTScreen.tsx +++ b/src/ui/pages/Atomicals/AtomicalsNFTScreen.tsx @@ -7,7 +7,7 @@ import { useTools } from '@/ui/components/ActionComponent'; import InscriptionPreview from '@/ui/components/InscriptionPreview'; import { useCurrentAccount } from '@/ui/state/accounts/hooks'; import { useAppDispatch } from '@/ui/state/hooks'; -import { useTxIdUrl } from '@/ui/state/settings/hooks'; +import { useTxExplorerUrl } from '@/ui/state/settings/hooks'; import { transactionsActions } from '@/ui/state/transactions/reducer'; import { copyToClipboard, useLocationState, useWallet } from '@/ui/utils'; @@ -25,7 +25,7 @@ export default function AtomicalsNFTScreen() { const isUnconfirmed = inscription.timestamp == 0; const date = moment(inscription.timestamp * 1000).format('YYYY-MM-DD hh:mm:ss'); - const genesisTxUrl = useTxIdUrl(inscription.genesisTransaction); + const genesisTxUrl = useTxExplorerUrl(inscription.genesisTransaction); const [isMultiStuck, setIsMultiStuck] = useState(false); const [splitReason, setSplitReason] = useState(''); diff --git a/src/ui/pages/Main/WalletTabScreen/index.tsx b/src/ui/pages/Main/WalletTabScreen/index.tsx index a71d057a..d124ab44 100644 --- a/src/ui/pages/Main/WalletTabScreen/index.tsx +++ b/src/ui/pages/Main/WalletTabScreen/index.tsx @@ -17,7 +17,7 @@ import { accountActions } from '@/ui/state/accounts/reducer'; import { useAppDispatch } from '@/ui/state/hooks'; import { useCurrentKeyring } from '@/ui/state/keyrings/hooks'; import { - useBlockstreamUrl, + useAddressExplorerUrl, useBTCUnit, useChain, useChainType, @@ -164,7 +164,7 @@ export default function WalletTabScreen() { } }, [assetTabKey, chainType]); - const blockstreamUrl = useBlockstreamUrl(); + const addressExplorerUrl = useAddressExplorerUrl(currentAccount.address); const resetUiTxCreateScreen = useResetUiTxCreateScreen(); const btcUnit = useBTCUnit(); @@ -322,7 +322,7 @@ export default function WalletTabScreen() { if (chain.isViewTxHistoryInternally) { navigate('HistoryScreen'); } else { - window.open(`${blockstreamUrl}/address/${currentAccount.address}`); + window.open(addressExplorerUrl); } }} /> diff --git a/src/ui/pages/Ordinals/OrdinalsInscriptionScreen.tsx b/src/ui/pages/Ordinals/OrdinalsInscriptionScreen.tsx index 733053f2..fcc897d4 100644 --- a/src/ui/pages/Ordinals/OrdinalsInscriptionScreen.tsx +++ b/src/ui/pages/Ordinals/OrdinalsInscriptionScreen.tsx @@ -7,7 +7,7 @@ import { useTools } from '@/ui/components/ActionComponent'; import InscriptionPreview from '@/ui/components/InscriptionPreview'; import { useCurrentAccount } from '@/ui/state/accounts/hooks'; import { useAppDispatch } from '@/ui/state/hooks'; -import { useTxIdUrl } from '@/ui/state/settings/hooks'; +import { useTxExplorerUrl } from '@/ui/state/settings/hooks'; import { transactionsActions } from '@/ui/state/transactions/reducer'; import { copyToClipboard, useLocationState, useWallet } from '@/ui/utils'; @@ -26,7 +26,7 @@ export default function OrdinalsInscriptionScreen() { const isUnconfirmed = inscription.timestamp == 0; const date = moment(inscription.timestamp * 1000).format('YYYY-MM-DD hh:mm:ss'); - const genesisTxUrl = useTxIdUrl(inscription.genesisTransaction); + const genesisTxUrl = useTxExplorerUrl(inscription.genesisTransaction); const [isNeedToSplit, setIsNeedToSplit] = useState(false); const [isMultiStuck, setIsMultiStuck] = useState(false); diff --git a/src/ui/pages/Runes/RunesTokenScreen.tsx b/src/ui/pages/Runes/RunesTokenScreen.tsx index a509d016..a5540b59 100644 --- a/src/ui/pages/Runes/RunesTokenScreen.tsx +++ b/src/ui/pages/Runes/RunesTokenScreen.tsx @@ -6,15 +6,15 @@ import { Button, Column, Content, Header, Icon, Layout, Row, Text } from '@/ui/c import { useTools } from '@/ui/components/ActionComponent'; import { BRC20Ticker } from '@/ui/components/BRC20Ticker'; import InscriptionPreview from '@/ui/components/InscriptionPreview'; +import { TickUsdWithoutPrice } from '@/ui/components/TickUsd'; import { useCurrentAccount } from '@/ui/state/accounts/hooks'; -import { useBlockstreamUrl, useOrdinalsWebsite, useUnisatWebsite } from '@/ui/state/settings/hooks'; +import { useOrdinalsWebsite, useTxExplorerUrl, useUnisatWebsite } from '@/ui/state/settings/hooks'; import { colors } from '@/ui/theme/colors'; import { fontSizes } from '@/ui/theme/font'; import { copyToClipboard, showLongNumber, useLocationState, useWallet } from '@/ui/utils'; import { LoadingOutlined } from '@ant-design/icons'; import { useNavigate } from '../MainRoute'; -import { TickUsdWithoutPrice } from '@/ui/components/TickUsd'; interface LocationState { runeid: string; @@ -95,7 +95,8 @@ export default function RunesTokenScreen() { const ordinalsWebsite = useOrdinalsWebsite(); - const mempoolWebsite = useBlockstreamUrl(); + const txExplorerUrl = useTxExplorerUrl(tokenSummary.runeInfo.etching); + if (loading) { return ( @@ -132,10 +133,15 @@ export default function RunesTokenScreen() { - + @@ -216,11 +222,7 @@ export default function RunesTokenScreen() {
-
+
{tokenSummary.runeInfo.parent ? (
(); const navigate = useNavigate(); - const blockstreamUrl = useBlockstreamUrl(); + const txidUrl = useTxExplorerUrl(txid); return ( @@ -29,7 +29,7 @@ export default function TxSuccessScreen() { { - window.open(`${blockstreamUrl}/tx/${txid}`); + window.open(`${txidUrl}`); }}> diff --git a/src/ui/pages/Wallet/UnavailableUtxoScreen.tsx b/src/ui/pages/Wallet/UnavailableUtxoScreen.tsx index 78fe13fa..02b8fd12 100644 --- a/src/ui/pages/Wallet/UnavailableUtxoScreen.tsx +++ b/src/ui/pages/Wallet/UnavailableUtxoScreen.tsx @@ -8,7 +8,7 @@ import Arc20PreviewCard from '@/ui/components/Arc20PreviewCard'; import AssetTag from '@/ui/components/AssetTag'; import { Empty } from '@/ui/components/Empty'; import InscriptionPreview from '@/ui/components/InscriptionPreview'; -import { useBlockstreamUrl, useBTCUnit, useOrdinalsWebsite } from '@/ui/state/settings/hooks'; +import { useBTCUnit, useOrdinalsWebsite } from '@/ui/state/settings/hooks'; import { useSetSpendUnavailableUtxosCallback } from '@/ui/state/transactions/hooks'; import { colors } from '@/ui/theme/colors'; import { fontSizes } from '@/ui/theme/font'; @@ -35,8 +35,6 @@ export default function UnavailableUtxoScreen() { }); }, []); - const blockstreamUrl = useBlockstreamUrl(); - const setSpendUnavailableUtxos = useSetSpendUnavailableUtxosCallback(); const selectedCount = useMemo(() => { @@ -73,7 +71,7 @@ export default function UnavailableUtxoScreen() { color: '#65D5F0' }} onClick={() => { - window.open(`${blockstreamUrl}/tx/${item.txid}#vout=${item.vout}`); + // window.open(`${blockstreamUrl}/tx/${item.txid}#vout=${item.vout}`); }} /> diff --git a/src/ui/state/settings/hooks.ts b/src/ui/state/settings/hooks.ts index 4db6e12b..c963a058 100644 --- a/src/ui/state/settings/hooks.ts +++ b/src/ui/state/settings/hooks.ts @@ -105,20 +105,27 @@ export function useChangeChainTypeCallback() { ); } -export function useBlockstreamUrl() { - const chainType = useChainType(); - return CHAINS_MAP[chainType].mempoolSpaceUrl; -} - export function useBTCUnit() { const chainType = useChainType(); return CHAINS_MAP[chainType].unit; } -export function useTxIdUrl(txid: string) { - const chainType = useChainType(); - const mempoolSpaceUrl = CHAINS_MAP[chainType].mempoolSpaceUrl; - return `${mempoolSpaceUrl}/tx/${txid}`; +export function useTxExplorerUrl(txid: string) { + const chain = useChain(); + if (chain.defaultExplorer === 'mempool-space') { + return `${chain.mempoolSpaceUrl}/tx/${txid}`; + } else { + return `${chain.unisatExplorerUrl}/tx/${txid}`; + } +} + +export function useAddressExplorerUrl(address: string) { + const chain = useChain(); + if (chain.defaultExplorer === 'mempool-space') { + return `${chain.mempoolSpaceUrl}/address/${address}`; + } else { + return `${chain.unisatExplorerUrl}/address/${address}`; + } } export function useUnisatWebsite() {