Skip to content

Commit

Permalink
feat: modified explorer link maker function to have a regtest option
Browse files Browse the repository at this point in the history
  • Loading branch information
Polybius93 committed Nov 30, 2023
1 parent 34f5553 commit 4b158d2
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/app/common/hooks/use-bitcoin-contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ export function useBitcoinContracts() {
const txMoney = createMoneyFromDecimal(bitcoinValue, 'BTC');
const txFiatValue = i18nFormatCurrency(calculateFiatValue(txMoney)).toString();
const txFiatValueSymbol = bitcoinMarketData.price.symbol;
const txLink = { blockchain: 'bitcoin', txId };
const txLink = { blockchain: 'bitcoin', txid: txId };

return {
txId,
Expand Down
10 changes: 6 additions & 4 deletions src/app/common/hooks/use-explorer-link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ export interface HandleOpenTxLinkArgs {
txid: string;
}
export function useExplorerLink() {
const { mode } = useCurrentNetworkState();
const { mode, chain } = useCurrentNetworkState();
const { bitcoin } = chain;
const handleOpenTxLink = useCallback(
({ blockchain, suffix, txid }: HandleOpenTxLinkArgs) =>
openInNewTab(makeTxExplorerLink({ blockchain, mode, suffix, txid })),
[mode]
({ blockchain, suffix, txid }: HandleOpenTxLinkArgs) => {
openInNewTab(makeTxExplorerLink({ blockchain, mode, suffix, txid, bitcoin }));
},
[mode, bitcoin]
);

return {
Expand Down
7 changes: 6 additions & 1 deletion src/app/common/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
} from '@stacks/transactions';
import { toUnicode } from 'punycode';

import { BitcoinNetworkModes, KEBAB_REGEX } from '@shared/constants';
import { BitcoinChainConfig, BitcoinNetworkModes, KEBAB_REGEX } from '@shared/constants';
import type { Blockchains } from '@shared/models/blockchain.model';

export function createNullArrayOfLength(length: number) {
Expand Down Expand Up @@ -44,15 +44,20 @@ interface MakeTxExplorerLinkArgs {
mode: BitcoinNetworkModes;
suffix?: string;
txid: string;
bitcoin: BitcoinChainConfig;
}
export function makeTxExplorerLink({
blockchain,
mode,
suffix = '',
txid,
bitcoin: { bitcoinUrl, bitcoinNetwork },
}: MakeTxExplorerLinkArgs) {
switch (blockchain) {
case 'bitcoin':
if (bitcoinNetwork === 'regtest') {
return `${bitcoinUrl}/tx/${txid}`;
}
return `https://mempool.space/${mode !== 'mainnet' ? mode + '/' : ''}tx/${txid}`;
case 'stacks':
return `https://explorer.hiro.so/txid/${txid}?chain=${mode}${suffix}`;
Expand Down
2 changes: 1 addition & 1 deletion src/shared/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ interface BaseChainConfig {
blockchain: Blockchains;
}

interface BitcoinChainConfig extends BaseChainConfig {
export interface BitcoinChainConfig extends BaseChainConfig {
blockchain: 'bitcoin';
bitcoinUrl: string;
bitcoinNetwork: BitcoinNetworkModes;
Expand Down

0 comments on commit 4b158d2

Please sign in to comment.