diff --git a/explorer/src/providers/network.tsx b/explorer/src/providers/network.tsx index fe67e933a1..eb95a1f955 100644 --- a/explorer/src/providers/network.tsx +++ b/explorer/src/providers/network.tsx @@ -78,7 +78,8 @@ function networkReducer(state: State, action: Action): State { } function initState(): State { - const networkUrlParam = findGetParameter("networkUrl"); + const networkUrlParam = + findGetParameter("clusterUrl") || findGetParameter("networkUrl"); let network; let customUrl = DEFAULT_CUSTOM_URL; diff --git a/explorer/src/providers/transactions.tsx b/explorer/src/providers/transactions.tsx index de0625410e..883958b461 100644 --- a/explorer/src/providers/transactions.tsx +++ b/explorer/src/providers/transactions.tsx @@ -1,6 +1,6 @@ import React from "react"; import { TransactionSignature, Connection } from "@solana/web3.js"; -import { findGetParameter } from "../utils"; +import { findGetParameter, findPathSegment } from "../utils"; import { useNetwork } from "../providers/network"; export enum Status { @@ -85,9 +85,22 @@ function reducer(state: State, action: Action): State { return state; } +function urlSignatures(): Array { + const signatures: Array = []; + return signatures + .concat(findGetParameter("tx")?.split(",") || []) + .concat(findGetParameter("txn")?.split(",") || []) + .concat(findGetParameter("txs")?.split(",") || []) + .concat(findGetParameter("txns")?.split(",") || []) + .concat(findGetParameter("transaction")?.split(",") || []) + .concat(findGetParameter("transactions")?.split(",") || []) + .concat(findPathSegment("transaction")?.split(",") || []) + .concat(findPathSegment("transactions")?.split(",") || []); +} + function initState(): State { let idCounter = 0; - const signatures = findGetParameter("txs")?.split(",") || []; + const signatures = urlSignatures(); const transactions = signatures.reduce( (transactions: Transactions, signature) => { const id = ++idCounter; diff --git a/explorer/src/utils.ts b/explorer/src/utils.ts index bb9fb4d973..6d1d5cd8ce 100644 --- a/explorer/src/utils.ts +++ b/explorer/src/utils.ts @@ -11,6 +11,20 @@ export function findGetParameter(parameterName: string): string | null { return result; } +export function findPathSegment(pathName: string): string | null { + const segments = window.location.pathname.substr(1).split("/"); + if (segments.length < 2) return null; + + // remove all but last two segments + segments.splice(0, segments.length - 2); + + if (segments[0] === pathName) { + return segments[1]; + } + + return null; +} + export function assertUnreachable(x: never): never { throw new Error("Unreachable!"); }