Skip to content

Commit

Permalink
(fix) Temporarily add a fixed version number until I work out how to …
Browse files Browse the repository at this point in the history
…increment the real one.

(fix) Don't pass "latest" to ots_getCode() in ZQ1 - it errors out if you do this.
(feat) A quirks feature to check (badly!) if we are Zilliqa 1.
  • Loading branch information
rrw-zilliqa committed Aug 22, 2024
1 parent 70f27fb commit bd85bab
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ const Home: FC = () => {
>
<div>Latest block: {commify(latestBlock.number)}</div>
<Timestamp value={latestBlock.timestamp} />
<div>Ziliqa Otterscan Version: {config?.version}</div>
<div>Zilliqa Otterscan Version: {config?.version}pl1</div>
</NavLink>
)}
{finalizedSlotNumber !== undefined && (
Expand Down
23 changes: 12 additions & 11 deletions src/search/TransactionResultHeader.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from "react";
import { FeeDisplay } from "./useFeeToggler";
import StandardTHead from "../components/StandardTHead";

export type ResultHeaderProps = {
feeDisplay: FeeDisplay;
Expand All @@ -10,15 +11,15 @@ const TransactionResultHeader: React.FC<ResultHeaderProps> = ({
feeDisplay,
feeDisplayToggler,
}) => (
<div className="grid grid-cols-12 gap-x-1 border-b border-t border-gray-200 bg-gray-100 px-2 py-2 text-sm font-bold text-gray-500">
<div className="col-span-2">Txn Hash</div>
<div>Method</div>
<div>Block</div>
<div>Age</div>
<div className="col-span-2 ml-1">From</div>
<div className="col-span-2 ml-1">To</div>
<div className="col-span-2">Value</div>
<div>
<StandardTHead>
<th>Txn Hash</th>
<th>Method</th>
<th className="w-28">Block</th>
<th className="w-36">Age</th>
<th>From</th>
<th>To</th>
<th className="min-w-52">Value</th>
<th>
<button
className="text-link-blue hover:text-link-blue-hover"
onClick={feeDisplayToggler}
Expand All @@ -27,8 +28,8 @@ const TransactionResultHeader: React.FC<ResultHeaderProps> = ({
{feeDisplay === FeeDisplay.TX_FEE_USD && "Txn Fee (USD)"}
{feeDisplay === FeeDisplay.GAS_PRICE && "Gas Price"}
</button>
</div>
</div>
</th>
</StandardTHead>
);

export default React.memo(TransactionResultHeader);
23 changes: 16 additions & 7 deletions src/useErigonHooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
TokenTransfer,
TransactionData,
} from "./types";
import { useQuirks, Quirks} from "./useQuirks";
import { formatter } from "./utils/formatter";

const TRANSFER_TOPIC =
Expand Down Expand Up @@ -420,13 +421,15 @@ export const useInternalOperations = (
}

const _t: InternalOperation[] = [];
for (const t of data) {
_t.push({
type: t.type,
from: formatter.address(getAddress(t.from)),
to: formatter.address(getAddress(t.to)),
value: formatter.bigInt(t.value),
});
if (data) {
for (const t of data) {
_t.push({
type: t.type,
from: formatter.address(getAddress(t.from)),
to: formatter.address(getAddress(t.to)),
value: formatter.bigInt(t.value),
});
}
}
return _t;
}, [provider, data]);
Expand Down Expand Up @@ -782,6 +785,12 @@ export const useHasCode = (
blockTag: BlockTag = "latest",
): boolean | undefined => {
const fetcher = providerFetcher(provider);
const quirks = useQuirks(provider);
if (quirks?.isZilliqa1) {
// Zilliqa 1 requires that the tag be numeric, but ignores it, so we can
// use 0 and save ourselves a fetch.
blockTag = 0;
}
const { data, error } = useSWRImmutable(
["ots_hasCode", address, blockTag],
fetcher,
Expand Down
30 changes: 30 additions & 0 deletions src/useQuirks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import {
JsonRpcApiProvider
} from "ethers";
import { useEffect, useMemo, useState } from "react";
import useSWR, { Fetcher } from "swr";
import useSWRImmutable from "swr/immutable";

export type Quirks = {
// Zilliqa 1 has so many odd quirks that we just have to declare it ..
isZilliqa1: boolean;
}

type ZilliqaVersion = {
Commit: string;
Version: string;
}

export const quirksFetcher = (provider : JsonRpcApiProvider | undefined ): Fetcher<any,Quirks> => async (key) =>{
const version = await provider?.send("GetVersion", []);
const isZilliqa1 = version?.Version.match(/^v9.[0-9]+/);
console.log(`version ${JSON.stringify(version)} is Zilliqa 1? {isZilliqa1}`);
return {
isZilliqa1
}
}

export const useQuirks = (provider: JsonRpcApiProvider | undefined) : Quirks => {
const { data : quirks } = useSWRImmutable("getVersion", quirksFetcher(provider));
return quirks;
}
1 change: 1 addition & 0 deletions src/useZilliqaHooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,4 @@ export const useBlockChainInfo = (
}
return { data, isLoading };
};

0 comments on commit bd85bab

Please sign in to comment.