Skip to content

Commit

Permalink
feat: set unisat explorer as default explorer in fractal
Browse files Browse the repository at this point in the history
  • Loading branch information
slient-coder committed Sep 7, 2024
1 parent 00128c2 commit 4356565
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 45 deletions.
19 changes: 13 additions & 6 deletions src/shared/constant/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ type TypeChain = {
disable?: boolean;
isFractal?: boolean;
showPrice: boolean;
defaultExplorer: 'mempool-space' | 'unisat-explorer';
};

export const CHAINS_MAP: { [key: string]: TypeChain } = {
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -326,7 +332,8 @@ export const CHAINS_MAP: { [key: string]: TypeChain } = {
okxExplorerUrl: '',
isViewTxHistoryInternally: false,
isFractal: true,
showPrice: false
showPrice: false,
defaultExplorer: 'unisat-explorer'
}
};

Expand Down
6 changes: 3 additions & 3 deletions src/ui/components/AddressDetailPopover/index.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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 (
<Popover onClose={onClose}>
<Column>
Expand All @@ -37,7 +37,7 @@ export const AddressDetailPopover = ({ address, onClose }: { address: string; on
<Row
justifyCenter
onClick={() => {
window.open(`${blockstreamUrl}/address/${address}`);
window.open(addressExplorerUrl);
}}>
<Icon icon="eye" color="textDim" />
<Text preset="regular-bold" text="View on Block Explorer" color="textDim" />
Expand Down
4 changes: 2 additions & 2 deletions src/ui/pages/Atomicals/AtomicalsNFTScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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('');
Expand Down
6 changes: 3 additions & 3 deletions src/ui/pages/Main/WalletTabScreen/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -164,7 +164,7 @@ export default function WalletTabScreen() {
}
}, [assetTabKey, chainType]);

const blockstreamUrl = useBlockstreamUrl();
const addressExplorerUrl = useAddressExplorerUrl(currentAccount.address);
const resetUiTxCreateScreen = useResetUiTxCreateScreen();
const btcUnit = useBTCUnit();

Expand Down Expand Up @@ -322,7 +322,7 @@ export default function WalletTabScreen() {
if (chain.isViewTxHistoryInternally) {
navigate('HistoryScreen');
} else {
window.open(`${blockstreamUrl}/address/${currentAccount.address}`);
window.open(addressExplorerUrl);
}
}}
/>
Expand Down
4 changes: 2 additions & 2 deletions src/ui/pages/Ordinals/OrdinalsInscriptionScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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);
Expand Down
26 changes: 14 additions & 12 deletions src/ui/pages/Runes/RunesTokenScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -95,7 +95,8 @@ export default function RunesTokenScreen() {

const ordinalsWebsite = useOrdinalsWebsite();

const mempoolWebsite = useBlockstreamUrl();
const txExplorerUrl = useTxExplorerUrl(tokenSummary.runeInfo.etching);

if (loading) {
return (
<Layout>
Expand Down Expand Up @@ -132,10 +133,15 @@ export default function RunesTokenScreen() {
<BRC20Ticker tick={tokenSummary.runeBalance.symbol} preset="lg" />
</Row>
<Row justifyCenter fullX>
<TickUsdWithoutPrice tick={tokenSummary.runeInfo.spacedRune} balance={runesUtils.toDecimalAmount(
tokenSummary.runeBalance.amount,
tokenSummary.runeBalance.divisibility
)} type={'runes'} size={'md'}/>
<TickUsdWithoutPrice
tick={tokenSummary.runeInfo.spacedRune}
balance={runesUtils.toDecimalAmount(
tokenSummary.runeBalance.amount,
tokenSummary.runeBalance.divisibility
)}
type={'runes'}
size={'md'}
/>
</Row>

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

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

<Section
title="etching"
value={tokenSummary.runeInfo.etching}
link={`${mempoolWebsite}/tx/${tokenSummary.runeInfo.etching}`}
/>
<Section title="etching" value={tokenSummary.runeInfo.etching} link={txExplorerUrl} />

{tokenSummary.runeInfo.parent ? (
<Section
Expand Down
8 changes: 4 additions & 4 deletions src/ui/pages/Wallet/TxSuccessScreen.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Layout, Header, Content, Icon, Text, Column, Footer, Button, Row } from '@/ui/components';
import { Button, Column, Content, Footer, Header, Icon, Layout, Row, Text } from '@/ui/components';
import { useNavigate } from '@/ui/pages/MainRoute';
import { useBlockstreamUrl } from '@/ui/state/settings/hooks';
import { useTxExplorerUrl } from '@/ui/state/settings/hooks';
import { spacing } from '@/ui/theme/spacing';
import { useLocationState } from '@/ui/utils';

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

return (
<Layout>
Expand All @@ -29,7 +29,7 @@ export default function TxSuccessScreen() {
<Row
justifyCenter
onClick={() => {
window.open(`${blockstreamUrl}/tx/${txid}`);
window.open(`${txidUrl}`);
}}>
<Icon icon="eye" color="textDim" />
<Text preset="regular-bold" text="View on Block Explorer" color="textDim" />
Expand Down
6 changes: 2 additions & 4 deletions src/ui/pages/Wallet/UnavailableUtxoScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -35,8 +35,6 @@ export default function UnavailableUtxoScreen() {
});
}, []);

const blockstreamUrl = useBlockstreamUrl();

const setSpendUnavailableUtxos = useSetSpendUnavailableUtxosCallback();

const selectedCount = useMemo(() => {
Expand Down Expand Up @@ -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}`);
}}
/>
</Row>
Expand Down
25 changes: 16 additions & 9 deletions src/ui/state/settings/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 4356565

Please sign in to comment.