Skip to content

Commit 4356565

Browse files
committed
feat: set unisat explorer as default explorer in fractal
1 parent 00128c2 commit 4356565

File tree

9 files changed

+59
-45
lines changed

9 files changed

+59
-45
lines changed

src/shared/constant/index.ts

+13-6
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ type TypeChain = {
236236
disable?: boolean;
237237
isFractal?: boolean;
238238
showPrice: boolean;
239+
defaultExplorer: 'mempool-space' | 'unisat-explorer';
239240
};
240241

241242
export const CHAINS_MAP: { [key: string]: TypeChain } = {
@@ -251,7 +252,8 @@ export const CHAINS_MAP: { [key: string]: TypeChain } = {
251252
ordinalsUrl: 'https://ordinals.com',
252253
unisatExplorerUrl: '',
253254
okxExplorerUrl: '',
254-
showPrice: true
255+
showPrice: true,
256+
defaultExplorer: 'mempool-space'
255257
},
256258
[ChainType.BITCOIN_TESTNET]: {
257259
enum: ChainType.BITCOIN_TESTNET,
@@ -265,7 +267,8 @@ export const CHAINS_MAP: { [key: string]: TypeChain } = {
265267
ordinalsUrl: 'https://testnet.ordinals.com',
266268
unisatExplorerUrl: '',
267269
okxExplorerUrl: '',
268-
showPrice: false
270+
showPrice: false,
271+
defaultExplorer: 'mempool-space'
269272
},
270273
[ChainType.BITCOIN_TESTNET4]: {
271274
enum: ChainType.BITCOIN_TESTNET4,
@@ -279,7 +282,8 @@ export const CHAINS_MAP: { [key: string]: TypeChain } = {
279282
ordinalsUrl: 'https://testnet4.ordinals.com',
280283
unisatExplorerUrl: '',
281284
okxExplorerUrl: '',
282-
showPrice: false
285+
showPrice: false,
286+
defaultExplorer: 'mempool-space'
283287
},
284288
[ChainType.BITCOIN_SIGNET]: {
285289
enum: ChainType.BITCOIN_SIGNET,
@@ -293,7 +297,8 @@ export const CHAINS_MAP: { [key: string]: TypeChain } = {
293297
ordinalsUrl: 'https://signet.ordinals.com',
294298
unisatExplorerUrl: '',
295299
okxExplorerUrl: '',
296-
showPrice: false
300+
showPrice: false,
301+
defaultExplorer: 'mempool-space'
297302
},
298303
[ChainType.FRACTAL_BITCOIN_MAINNET]: {
299304
enum: ChainType.FRACTAL_BITCOIN_MAINNET,
@@ -310,7 +315,8 @@ export const CHAINS_MAP: { [key: string]: TypeChain } = {
310315
isViewTxHistoryInternally: false,
311316
disable: false,
312317
isFractal: true,
313-
showPrice: true
318+
showPrice: true,
319+
defaultExplorer: 'unisat-explorer'
314320
},
315321
[ChainType.FRACTAL_BITCOIN_TESTNET]: {
316322
enum: ChainType.FRACTAL_BITCOIN_TESTNET,
@@ -326,7 +332,8 @@ export const CHAINS_MAP: { [key: string]: TypeChain } = {
326332
okxExplorerUrl: '',
327333
isViewTxHistoryInternally: false,
328334
isFractal: true,
329-
showPrice: false
335+
showPrice: false,
336+
defaultExplorer: 'unisat-explorer'
330337
}
331338
};
332339

src/ui/components/AddressDetailPopover/index.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useBlockstreamUrl } from '@/ui/state/settings/hooks';
1+
import { useAddressExplorerUrl } from '@/ui/state/settings/hooks';
22
import { copyToClipboard, shortAddress } from '@/ui/utils';
33

44
import { useTools } from '../ActionComponent';
@@ -11,7 +11,7 @@ import { Text } from '../Text';
1111

1212
export const AddressDetailPopover = ({ address, onClose }: { address: string; onClose: () => void }) => {
1313
const tools = useTools();
14-
const blockstreamUrl = useBlockstreamUrl();
14+
const addressExplorerUrl = useAddressExplorerUrl(address);
1515
return (
1616
<Popover onClose={onClose}>
1717
<Column>
@@ -37,7 +37,7 @@ export const AddressDetailPopover = ({ address, onClose }: { address: string; on
3737
<Row
3838
justifyCenter
3939
onClick={() => {
40-
window.open(`${blockstreamUrl}/address/${address}`);
40+
window.open(addressExplorerUrl);
4141
}}>
4242
<Icon icon="eye" color="textDim" />
4343
<Text preset="regular-bold" text="View on Block Explorer" color="textDim" />

src/ui/pages/Atomicals/AtomicalsNFTScreen.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { useTools } from '@/ui/components/ActionComponent';
77
import InscriptionPreview from '@/ui/components/InscriptionPreview';
88
import { useCurrentAccount } from '@/ui/state/accounts/hooks';
99
import { useAppDispatch } from '@/ui/state/hooks';
10-
import { useTxIdUrl } from '@/ui/state/settings/hooks';
10+
import { useTxExplorerUrl } from '@/ui/state/settings/hooks';
1111
import { transactionsActions } from '@/ui/state/transactions/reducer';
1212
import { copyToClipboard, useLocationState, useWallet } from '@/ui/utils';
1313

@@ -25,7 +25,7 @@ export default function AtomicalsNFTScreen() {
2525
const isUnconfirmed = inscription.timestamp == 0;
2626
const date = moment(inscription.timestamp * 1000).format('YYYY-MM-DD hh:mm:ss');
2727

28-
const genesisTxUrl = useTxIdUrl(inscription.genesisTransaction);
28+
const genesisTxUrl = useTxExplorerUrl(inscription.genesisTransaction);
2929

3030
const [isMultiStuck, setIsMultiStuck] = useState(false);
3131
const [splitReason, setSplitReason] = useState('');

src/ui/pages/Main/WalletTabScreen/index.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { accountActions } from '@/ui/state/accounts/reducer';
1717
import { useAppDispatch } from '@/ui/state/hooks';
1818
import { useCurrentKeyring } from '@/ui/state/keyrings/hooks';
1919
import {
20-
useBlockstreamUrl,
20+
useAddressExplorerUrl,
2121
useBTCUnit,
2222
useChain,
2323
useChainType,
@@ -164,7 +164,7 @@ export default function WalletTabScreen() {
164164
}
165165
}, [assetTabKey, chainType]);
166166

167-
const blockstreamUrl = useBlockstreamUrl();
167+
const addressExplorerUrl = useAddressExplorerUrl(currentAccount.address);
168168
const resetUiTxCreateScreen = useResetUiTxCreateScreen();
169169
const btcUnit = useBTCUnit();
170170

@@ -322,7 +322,7 @@ export default function WalletTabScreen() {
322322
if (chain.isViewTxHistoryInternally) {
323323
navigate('HistoryScreen');
324324
} else {
325-
window.open(`${blockstreamUrl}/address/${currentAccount.address}`);
325+
window.open(addressExplorerUrl);
326326
}
327327
}}
328328
/>

src/ui/pages/Ordinals/OrdinalsInscriptionScreen.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { useTools } from '@/ui/components/ActionComponent';
77
import InscriptionPreview from '@/ui/components/InscriptionPreview';
88
import { useCurrentAccount } from '@/ui/state/accounts/hooks';
99
import { useAppDispatch } from '@/ui/state/hooks';
10-
import { useTxIdUrl } from '@/ui/state/settings/hooks';
10+
import { useTxExplorerUrl } from '@/ui/state/settings/hooks';
1111
import { transactionsActions } from '@/ui/state/transactions/reducer';
1212
import { copyToClipboard, useLocationState, useWallet } from '@/ui/utils';
1313

@@ -26,7 +26,7 @@ export default function OrdinalsInscriptionScreen() {
2626
const isUnconfirmed = inscription.timestamp == 0;
2727
const date = moment(inscription.timestamp * 1000).format('YYYY-MM-DD hh:mm:ss');
2828

29-
const genesisTxUrl = useTxIdUrl(inscription.genesisTransaction);
29+
const genesisTxUrl = useTxExplorerUrl(inscription.genesisTransaction);
3030

3131
const [isNeedToSplit, setIsNeedToSplit] = useState(false);
3232
const [isMultiStuck, setIsMultiStuck] = useState(false);

src/ui/pages/Runes/RunesTokenScreen.tsx

+14-12
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ import { Button, Column, Content, Header, Icon, Layout, Row, Text } from '@/ui/c
66
import { useTools } from '@/ui/components/ActionComponent';
77
import { BRC20Ticker } from '@/ui/components/BRC20Ticker';
88
import InscriptionPreview from '@/ui/components/InscriptionPreview';
9+
import { TickUsdWithoutPrice } from '@/ui/components/TickUsd';
910
import { useCurrentAccount } from '@/ui/state/accounts/hooks';
10-
import { useBlockstreamUrl, useOrdinalsWebsite, useUnisatWebsite } from '@/ui/state/settings/hooks';
11+
import { useOrdinalsWebsite, useTxExplorerUrl, useUnisatWebsite } from '@/ui/state/settings/hooks';
1112
import { colors } from '@/ui/theme/colors';
1213
import { fontSizes } from '@/ui/theme/font';
1314
import { copyToClipboard, showLongNumber, useLocationState, useWallet } from '@/ui/utils';
1415
import { LoadingOutlined } from '@ant-design/icons';
1516

1617
import { useNavigate } from '../MainRoute';
17-
import { TickUsdWithoutPrice } from '@/ui/components/TickUsd';
1818

1919
interface LocationState {
2020
runeid: string;
@@ -95,7 +95,8 @@ export default function RunesTokenScreen() {
9595

9696
const ordinalsWebsite = useOrdinalsWebsite();
9797

98-
const mempoolWebsite = useBlockstreamUrl();
98+
const txExplorerUrl = useTxExplorerUrl(tokenSummary.runeInfo.etching);
99+
99100
if (loading) {
100101
return (
101102
<Layout>
@@ -132,10 +133,15 @@ export default function RunesTokenScreen() {
132133
<BRC20Ticker tick={tokenSummary.runeBalance.symbol} preset="lg" />
133134
</Row>
134135
<Row justifyCenter fullX>
135-
<TickUsdWithoutPrice tick={tokenSummary.runeInfo.spacedRune} balance={runesUtils.toDecimalAmount(
136-
tokenSummary.runeBalance.amount,
137-
tokenSummary.runeBalance.divisibility
138-
)} type={'runes'} size={'md'}/>
136+
<TickUsdWithoutPrice
137+
tick={tokenSummary.runeInfo.spacedRune}
138+
balance={runesUtils.toDecimalAmount(
139+
tokenSummary.runeBalance.amount,
140+
tokenSummary.runeBalance.divisibility
141+
)}
142+
type={'runes'}
143+
size={'md'}
144+
/>
139145
</Row>
140146

141147
<Row justifyBetween mt="lg">
@@ -216,11 +222,7 @@ export default function RunesTokenScreen() {
216222

217223
<Section title="transactions" value={showLongNumber(tokenSummary.runeInfo.transactions)} />
218224

219-
<Section
220-
title="etching"
221-
value={tokenSummary.runeInfo.etching}
222-
link={`${mempoolWebsite}/tx/${tokenSummary.runeInfo.etching}`}
223-
/>
225+
<Section title="etching" value={tokenSummary.runeInfo.etching} link={txExplorerUrl} />
224226

225227
{tokenSummary.runeInfo.parent ? (
226228
<Section

src/ui/pages/Wallet/TxSuccessScreen.tsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { Layout, Header, Content, Icon, Text, Column, Footer, Button, Row } from '@/ui/components';
1+
import { Button, Column, Content, Footer, Header, Icon, Layout, Row, Text } from '@/ui/components';
22
import { useNavigate } from '@/ui/pages/MainRoute';
3-
import { useBlockstreamUrl } from '@/ui/state/settings/hooks';
3+
import { useTxExplorerUrl } from '@/ui/state/settings/hooks';
44
import { spacing } from '@/ui/theme/spacing';
55
import { useLocationState } from '@/ui/utils';
66

@@ -11,7 +11,7 @@ interface LocationState {
1111
export default function TxSuccessScreen() {
1212
const { txid } = useLocationState<LocationState>();
1313
const navigate = useNavigate();
14-
const blockstreamUrl = useBlockstreamUrl();
14+
const txidUrl = useTxExplorerUrl(txid);
1515

1616
return (
1717
<Layout>
@@ -29,7 +29,7 @@ export default function TxSuccessScreen() {
2929
<Row
3030
justifyCenter
3131
onClick={() => {
32-
window.open(`${blockstreamUrl}/tx/${txid}`);
32+
window.open(`${txidUrl}`);
3333
}}>
3434
<Icon icon="eye" color="textDim" />
3535
<Text preset="regular-bold" text="View on Block Explorer" color="textDim" />

src/ui/pages/Wallet/UnavailableUtxoScreen.tsx

+2-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import Arc20PreviewCard from '@/ui/components/Arc20PreviewCard';
88
import AssetTag from '@/ui/components/AssetTag';
99
import { Empty } from '@/ui/components/Empty';
1010
import InscriptionPreview from '@/ui/components/InscriptionPreview';
11-
import { useBlockstreamUrl, useBTCUnit, useOrdinalsWebsite } from '@/ui/state/settings/hooks';
11+
import { useBTCUnit, useOrdinalsWebsite } from '@/ui/state/settings/hooks';
1212
import { useSetSpendUnavailableUtxosCallback } from '@/ui/state/transactions/hooks';
1313
import { colors } from '@/ui/theme/colors';
1414
import { fontSizes } from '@/ui/theme/font';
@@ -35,8 +35,6 @@ export default function UnavailableUtxoScreen() {
3535
});
3636
}, []);
3737

38-
const blockstreamUrl = useBlockstreamUrl();
39-
4038
const setSpendUnavailableUtxos = useSetSpendUnavailableUtxosCallback();
4139

4240
const selectedCount = useMemo(() => {
@@ -73,7 +71,7 @@ export default function UnavailableUtxoScreen() {
7371
color: '#65D5F0'
7472
}}
7573
onClick={() => {
76-
window.open(`${blockstreamUrl}/tx/${item.txid}#vout=${item.vout}`);
74+
// window.open(`${blockstreamUrl}/tx/${item.txid}#vout=${item.vout}`);
7775
}}
7876
/>
7977
</Row>

src/ui/state/settings/hooks.ts

+16-9
Original file line numberDiff line numberDiff line change
@@ -105,20 +105,27 @@ export function useChangeChainTypeCallback() {
105105
);
106106
}
107107

108-
export function useBlockstreamUrl() {
109-
const chainType = useChainType();
110-
return CHAINS_MAP[chainType].mempoolSpaceUrl;
111-
}
112-
113108
export function useBTCUnit() {
114109
const chainType = useChainType();
115110
return CHAINS_MAP[chainType].unit;
116111
}
117112

118-
export function useTxIdUrl(txid: string) {
119-
const chainType = useChainType();
120-
const mempoolSpaceUrl = CHAINS_MAP[chainType].mempoolSpaceUrl;
121-
return `${mempoolSpaceUrl}/tx/${txid}`;
113+
export function useTxExplorerUrl(txid: string) {
114+
const chain = useChain();
115+
if (chain.defaultExplorer === 'mempool-space') {
116+
return `${chain.mempoolSpaceUrl}/tx/${txid}`;
117+
} else {
118+
return `${chain.unisatExplorerUrl}/tx/${txid}`;
119+
}
120+
}
121+
122+
export function useAddressExplorerUrl(address: string) {
123+
const chain = useChain();
124+
if (chain.defaultExplorer === 'mempool-space') {
125+
return `${chain.mempoolSpaceUrl}/address/${address}`;
126+
} else {
127+
return `${chain.unisatExplorerUrl}/address/${address}`;
128+
}
122129
}
123130

124131
export function useUnisatWebsite() {

0 commit comments

Comments
 (0)