explorer: Fix setting custom RPC URL (#22187)
This commit is contained in:
parent
29edb130cc
commit
3f88994e0f
|
@ -92,8 +92,8 @@ function CustomClusterInput({ activeSuffix, active }: InputProps) {
|
||||||
: "btn-white";
|
: "btn-white";
|
||||||
|
|
||||||
const clusterLocation = (location: Location) => {
|
const clusterLocation = (location: Location) => {
|
||||||
|
query.set("cluster", "custom");
|
||||||
if (customUrl.length > 0) {
|
if (customUrl.length > 0) {
|
||||||
query.set("cluster", "custom");
|
|
||||||
query.set("customUrl", customUrl);
|
query.set("customUrl", customUrl);
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
|
@ -105,7 +105,6 @@ function CustomClusterInput({ activeSuffix, active }: InputProps) {
|
||||||
const onUrlInput = useDebounceCallback((url: string) => {
|
const onUrlInput = useDebounceCallback((url: string) => {
|
||||||
updateCustomUrl(url);
|
updateCustomUrl(url);
|
||||||
if (url.length > 0) {
|
if (url.length > 0) {
|
||||||
query.set("cluster", "custom");
|
|
||||||
query.set("customUrl", url);
|
query.set("customUrl", url);
|
||||||
history.push({ ...location, search: query.toString() });
|
history.push({ ...location, search: query.toString() });
|
||||||
}
|
}
|
||||||
|
@ -119,7 +118,7 @@ function CustomClusterInput({ activeSuffix, active }: InputProps) {
|
||||||
</Link>
|
</Link>
|
||||||
{active && (
|
{active && (
|
||||||
<input
|
<input
|
||||||
type="text"
|
type="url"
|
||||||
defaultValue={customUrl}
|
defaultValue={customUrl}
|
||||||
className={`form-control ${inputTextClass}`}
|
className={`form-control ${inputTextClass}`}
|
||||||
onFocus={() => setEditing(true)}
|
onFocus={() => setEditing(true)}
|
||||||
|
|
|
@ -3,7 +3,7 @@ import { Buffer } from "buffer";
|
||||||
import { Copyable } from "./Copyable";
|
import { Copyable } from "./Copyable";
|
||||||
|
|
||||||
export function HexData({ raw }: { raw: Buffer }) {
|
export function HexData({ raw }: { raw: Buffer }) {
|
||||||
if (!raw) {
|
if (!raw || raw.length === 0) {
|
||||||
return <span>No data</span>;
|
return <span>No data</span>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -145,9 +145,8 @@ export function ClusterProvider({ children }: ClusterProviderProps) {
|
||||||
const enableCustomUrl =
|
const enableCustomUrl =
|
||||||
localStorageIsAvailable() &&
|
localStorageIsAvailable() &&
|
||||||
localStorage.getItem("enableCustomUrl") !== null;
|
localStorage.getItem("enableCustomUrl") !== null;
|
||||||
const customUrl = enableCustomUrl
|
const customUrl =
|
||||||
? query.get("customUrl") || ""
|
(enableCustomUrl && query.get("customUrl")) || state.customUrl;
|
||||||
: state.customUrl;
|
|
||||||
const history = useHistory();
|
const history = useHistory();
|
||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
|
|
||||||
|
@ -161,15 +160,6 @@ export function ClusterProvider({ children }: ClusterProviderProps) {
|
||||||
|
|
||||||
// Reconnect to cluster when params change
|
// Reconnect to cluster when params change
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
if (cluster === Cluster.Custom) {
|
|
||||||
// Remove cluster param if custom url has not been set
|
|
||||||
if (customUrl.length === 0) {
|
|
||||||
query.delete("cluster");
|
|
||||||
history.push({ ...location, search: query.toString() });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
updateCluster(dispatch, cluster, customUrl);
|
updateCluster(dispatch, cluster, customUrl);
|
||||||
}, [cluster, customUrl]); // eslint-disable-line react-hooks/exhaustive-deps
|
}, [cluster, customUrl]); // eslint-disable-line react-hooks/exhaustive-deps
|
||||||
|
|
||||||
|
@ -196,6 +186,9 @@ async function updateCluster(
|
||||||
});
|
});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
// validate url
|
||||||
|
new URL(customUrl);
|
||||||
|
|
||||||
const connection = new Connection(clusterUrl(cluster, customUrl));
|
const connection = new Connection(clusterUrl(cluster, customUrl));
|
||||||
const [firstAvailableBlock, epochSchedule, epochInfo, genesisHash] =
|
const [firstAvailableBlock, epochSchedule, epochInfo, genesisHash] =
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
|
|
Loading…
Reference in New Issue