Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/angry-mayflies-push.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"thirdweb": patch
---

Sanitize block explorer URLs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import { ExternalLinkIcon } from "@radix-ui/react-icons";
import { useState } from "react";
import type { ThirdwebClient } from "../../../../client/client.js";
import { formatExplorerAddressUrl } from "../../../../utils/url.js";
import { iconSize } from "../../../core/design-system/index.js";
import { useChainExplorers } from "../../../core/hooks/others/useChainQuery.js";
import { useActiveAccount } from "../../../core/hooks/wallets/useActiveAccount.js";
Expand Down Expand Up @@ -125,7 +126,10 @@
<ButtonLink
fullWidth
variant="outline"
href={`${chainExplorers.explorers[0]?.url}/address/${activeAccount?.address}`}
href={formatExplorerAddressUrl(
chainExplorers.explorers[0]?.url ?? "",
activeAccount?.address ?? "",
)}

Check warning on line 132 in packages/thirdweb/src/react/web/ui/ConnectWallet/TransactionsScreen.tsx

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/react/web/ui/ConnectWallet/TransactionsScreen.tsx#L129-L132

Added lines #L129 - L132 were not covered by tests
target="_blank"
as="a"
gap="xs"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import type { BuyWithFiatQuote } from "../../../../../../../pay/buyWithFiat/getQuote.js";
import type { BuyWithFiatStatus } from "../../../../../../../pay/buyWithFiat/getStatus.js";
import { formatNumber } from "../../../../../../../utils/formatNumber.js";
import { formatExplorerTxUrl } from "../../../../../../../utils/url.js";
import {
type Theme,
fontSize,
Expand Down Expand Up @@ -345,7 +346,10 @@
onRampExplorers.explorers[0]?.url && onRampTxHash
? {
label: "View on Explorer",
url: `${onRampExplorers.explorers[0]?.url}/tx/${onRampTxHash}`,
url: formatExplorerTxUrl(
onRampExplorers.explorers[0]?.url,
onRampTxHash,
),

Check warning on line 352 in packages/thirdweb/src/react/web/ui/ConnectWallet/screens/Buy/fiat/FiatSteps.tsx

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/react/web/ui/ConnectWallet/screens/Buy/fiat/FiatSteps.tsx#L349-L352

Added lines #L349 - L352 were not covered by tests
}
: undefined
}
Expand Down Expand Up @@ -382,7 +386,10 @@
toChainExplorers.explorers[0]?.url && toTokenTxHash
? {
label: "View on Explorer",
url: `${toChainExplorers.explorers[0].url}/tx/${toTokenTxHash}`,
url: formatExplorerTxUrl(
toChainExplorers.explorers[0]?.url,
toTokenTxHash,
),

Check warning on line 392 in packages/thirdweb/src/react/web/ui/ConnectWallet/screens/Buy/fiat/FiatSteps.tsx

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/react/web/ui/ConnectWallet/screens/Buy/fiat/FiatSteps.tsx#L389-L392

Added lines #L389 - L392 were not covered by tests
}
: undefined
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import { getCachedChain } from "../../../../../../../chains/utils.js";
import type { ThirdwebClient } from "../../../../../../../client/client.js";
import { formatNumber } from "../../../../../../../utils/formatNumber.js";
import { formatExplorerTxUrl } from "../../../../../../../utils/url.js";
import {
fontSize,
iconSize,
Expand Down Expand Up @@ -121,9 +122,10 @@
<ButtonLink
fullWidth
variant="outline"
href={`${
onRampExplorers.explorers[0].url || ""
}/tx/${onrampTxHash}`}
href={formatExplorerTxUrl(
onRampExplorers.explorers[0]?.url,
onrampTxHash,
)}

Check warning on line 128 in packages/thirdweb/src/react/web/ui/ConnectWallet/screens/Buy/fiat/FiatTxDetailsTable.tsx

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/react/web/ui/ConnectWallet/screens/Buy/fiat/FiatTxDetailsTable.tsx#L125-L128

Added lines #L125 - L128 were not covered by tests
target="_blank"
gap="xs"
style={{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import type { BuyWithCryptoQuote } from "../../../../../../../pay/buyWithCrypto/getQuote.js";
import type { ValidBuyWithCryptoStatus } from "../../../../../../../pay/buyWithCrypto/getStatus.js";
import { shortenAddress } from "../../../../../../../utils/address.js";
import { formatExplorerTxUrl } from "../../../../../../../utils/url.js";
import {
fontSize,
iconSize,
Expand Down Expand Up @@ -199,7 +200,10 @@
<ButtonLink
fullWidth
variant="outline"
href={`${fromChainExplorers.explorers[0].url}/tx/${sourceTxHash}`}
href={formatExplorerTxUrl(
fromChainExplorers.explorers[0]?.url,
sourceTxHash,
)}

Check warning on line 206 in packages/thirdweb/src/react/web/ui/ConnectWallet/screens/Buy/pay-transactions/SwapDetailsScreen.tsx

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/react/web/ui/ConnectWallet/screens/Buy/pay-transactions/SwapDetailsScreen.tsx#L203-L206

Added lines #L203 - L206 were not covered by tests
target="_blank"
gap="xs"
style={{
Expand Down Expand Up @@ -330,7 +334,10 @@
<ButtonLink
fullWidth
variant="outline"
href={`${fromChainExplorers.explorers[0].url}/tx/${sourceTxHash}`}
href={formatExplorerTxUrl(
fromChainExplorers.explorers[0]?.url,
sourceTxHash,
)}

Check warning on line 340 in packages/thirdweb/src/react/web/ui/ConnectWallet/screens/Buy/pay-transactions/SwapDetailsScreen.tsx

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/react/web/ui/ConnectWallet/screens/Buy/pay-transactions/SwapDetailsScreen.tsx#L337-L340

Added lines #L337 - L340 were not covered by tests
target="_blank"
gap="xs"
style={{
Expand All @@ -352,7 +359,10 @@
<ButtonLink
fullWidth
variant="outline"
href={`${toChainExplorers.explorers[0].url}/tx/${destinationTxHash}`}
href={formatExplorerTxUrl(
toChainExplorers.explorers[0]?.url,
destinationTxHash,
)}

Check warning on line 365 in packages/thirdweb/src/react/web/ui/ConnectWallet/screens/Buy/pay-transactions/SwapDetailsScreen.tsx

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/react/web/ui/ConnectWallet/screens/Buy/pay-transactions/SwapDetailsScreen.tsx#L362-L365

Added lines #L362 - L365 were not covered by tests
target="_blank"
gap="xs"
style={{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import { getTransactionStore } from "../../../../../transaction/transaction-store.js";
import { shortenHex } from "../../../../../utils/address.js";
import type { Hex } from "../../../../../utils/encoding/hex.js";
import { formatExplorerTxUrl } from "../../../../../utils/url.js";
import { useCustomTheme } from "../../../../core/design-system/CustomThemeProvider.js";
import { iconSize, spacing } from "../../../../core/design-system/index.js";
import { useWaitForReceipt } from "../../../../core/hooks/contract/useWaitForReceipt.js";
Expand Down Expand Up @@ -192,7 +193,7 @@
if (props.explorerUrl) {
return (
<a
href={`${props.explorerUrl}/tx/${props.hash}`}
href={formatExplorerTxUrl(props.explorerUrl, props.hash)}

Check warning on line 196 in packages/thirdweb/src/react/web/ui/ConnectWallet/screens/WalletTransactionHistory.tsx

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/react/web/ui/ConnectWallet/screens/WalletTransactionHistory.tsx#L196

Added line #L196 was not covered by tests
target="_blank"
rel="noreferrer"
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import type { Hex } from "viem";
import type { WaitForReceiptOptions } from "../../../../transaction/actions/wait-for-tx-receipt.js";
import type { PreparedTransaction } from "../../../../transaction/prepare-transaction.js";
import { formatExplorerTxUrl } from "../../../../utils/url.js";
import { iconSize } from "../../../core/design-system/index.js";
import { useChainExplorers } from "../../../core/hooks/others/useChainQuery.js";
import { useSendTransaction } from "../../hooks/transaction/useSendTransaction.js";
Expand Down Expand Up @@ -106,7 +107,10 @@
<ButtonLink
fullWidth
variant="outline"
href={`${chainExplorers.explorers[0]?.url}/tx/${txHash}`}
href={formatExplorerTxUrl(
chainExplorers.explorers[0]?.url ?? "",
txHash,
)}

Check warning on line 113 in packages/thirdweb/src/react/web/ui/TransactionButton/ExecutingScreen.tsx

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/react/web/ui/TransactionButton/ExecutingScreen.tsx#L110-L113

Added lines #L110 - L113 were not covered by tests
target="_blank"
as="a"
gap="xs"
Expand Down
8 changes: 8 additions & 0 deletions packages/thirdweb/src/utils/url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,11 @@ export function formatWalletConnectUrl(
? formatUniversalUrl(appUrl, wcUri)
: formatNativeUrl(appUrl, wcUri);
}

export function formatExplorerTxUrl(explorerUrl: string, txHash: string) {
return `${explorerUrl.endsWith("/") ? explorerUrl : `${explorerUrl}/`}tx/${txHash}`;
}

export function formatExplorerAddressUrl(explorerUrl: string, address: string) {
return `${explorerUrl.endsWith("/") ? explorerUrl : `${explorerUrl}/`}address/${address}`;
}