Skip to content

Commit

Permalink
(feat) #101 - force network by hostname,
Browse files Browse the repository at this point in the history
(feat) #83 - reload scilla contract state.
  • Loading branch information
rrw-zilliqa committed Jan 23, 2025
1 parent 5a3cb83 commit f65c94b
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 29 deletions.
14 changes: 7 additions & 7 deletions src/execution/address/ScillaState.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { FC, useContext, useState, useRef } from "react";
import { FC, useContext, useState } from "react";
import { RuntimeContext } from "../../useRuntime";
import { ContractState, useSmartContractState, invalidateSmartContractState } from "../../useZilliqaHooks";
import { ContractState, useSmartContractState } from "../../useZilliqaHooks";

type ScillaStateProps = {
address: string;
loadContractState: boolean | undefined;
setLoadContractState: (arg0: boolean) => void;
loadContractState: number | undefined;
setLoadContractState: React.Dispatch<React.SetStateAction<number>>;
};

type ScillaStateRowProps = {
Expand Down Expand Up @@ -42,7 +42,7 @@ export const ScillaState: FC<ScillaStateProps> = ({
const { data, isLoading } = useSmartContractState(
loadContractState ? zilliqa : undefined,
address,
loadContractState
loadContractState ?? 0
);
if (data && contractState == null) {
setContractState(data);
Expand All @@ -53,7 +53,7 @@ export const ScillaState: FC<ScillaStateProps> = ({
<div className="mt-6">
<button
className="text-link-blue hover:text-link-blue-hover"
onClick={() => setLoadContractState(prev => prev + 1)}
onClick={() => setLoadContractState((prev: number) => prev + 1)}
>
Load Contract State
</button>
Expand All @@ -69,7 +69,7 @@ export const ScillaState: FC<ScillaStateProps> = ({
<div className="mt-6">
<button
className="text-link-blue hover:text-link-blue-hover"
onClick={() => { setContractState(null); setLoadContractState(prev => prev + 1); }}
onClick={() => { setContractState(null); setLoadContractState((prev : number) => prev + 1); }}
>
Refresh
</button>
Expand Down
50 changes: 28 additions & 22 deletions src/useConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,6 @@ export type OtterscanConfig = {
*/
backendFormat?: string;

/** Should we display the connection menu?
*/
displayConnectionMenu?: boolean;
};

/**
Expand All @@ -212,6 +209,7 @@ export type OtterscanConfig = {
* a trailing forward slash, e.g. "https://sepolia.otterscan.io".
*/
l1ExplorerURL?: string;

};

/**
Expand All @@ -227,6 +225,10 @@ export type OtterscanConfig = {
/** Chain connections
*/
connections?: ChainConnection[];

/** Should we display the connection menu?
*/
displayConnectionMenu?: boolean;
};

/**
Expand Down Expand Up @@ -376,7 +378,7 @@ export const loadOtterscanConfig = async (): Promise<OtterscanConfig> => {
try {
var host = window.location.host;
// Ignore locally stored connections when matching hostnames.
var connections = config.connections;
var connections : ChainConnection[] | undefined = config.connections;
if (connections !== undefined) {
for (var c of connections) {
const hosts = c.hostnames;
Expand All @@ -397,7 +399,7 @@ export const loadOtterscanConfig = async (): Promise<OtterscanConfig> => {
// If we've still not got a connection, use the first one.
try {
if (config.erigonURL === undefined || config.erigonURL == null) {
var connections =
var connections : ChainConnection[] | undefined =
storageConfiguration["connections"] ?? config.connections;
if (connections !== undefined) {
if (!("erigonURL" in storageConfiguration)) {
Expand All @@ -418,27 +420,31 @@ export const loadOtterscanConfig = async (): Promise<OtterscanConfig> => {
if (params.has("network")) {
const url = params.get("network");
storageConfiguration["erigonURL"] = url;
var connections =
var connections: ChainConnection[] | undefined =
storageConfiguration["connections"] ?? config.connections;
var found = false;
for (var c of connections) {
if (c.url === url) {
if (params.has("name")) {
let name = params.get("name");
connections = connections.map((c: ChainConnection) => {
if (c.url == url) {
c.menuName = name!;
}
return c;
});
if (connections) {
for (var c of connections) {
if (c.url === url) {
if (params.has("name")) {
let name = params.get("name");
connections = connections.map((c: ChainConnection) => {
if (c.url == url) {
c.menuName = name!;
}
return c;
});
}
found = true;
break;
}
}
if (!found) {
var name = params.get("name") ?? url;
if (name && url) {
connections.push({ menuName: name, url });
}
found = true;
break;
}
}
if (!found) {
var name = params.get("name") ?? url;
connections.push({ menuName: name, url });
}
storageConfiguration["connections"] = connections;
}
Expand Down

0 comments on commit f65c94b

Please sign in to comment.