Skip to content

Commit

Permalink
bump, cleanup, format
Browse files Browse the repository at this point in the history
  • Loading branch information
beeinger committed Dec 23, 2024
1 parent 6e6b8e4 commit 7616411
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 79 deletions.
Binary file modified bun.lockb
Binary file not shown.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
"typescript": "^5.0.0"
},
"dependencies": {
"viem": "2.21.55"
"viem": "2.21.57"
}
}
29 changes: 7 additions & 22 deletions public/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@
"https://*.snowscan.xyz/*",
"https://*.arbiscan.io/*"
],
"js": [
"src/content-scripts/tab-tracker.content.js",
"src/content-scripts/login-herodotus.content.js"
]
"js": ["src/content-scripts/tab-tracker.content.js", "src/content-scripts/login-herodotus.content.js"]
},
{
"matches": [
Expand Down Expand Up @@ -66,9 +63,7 @@
"https://*.arbiscan.io/writecontract/index*"
],
"all_frames": true,
"js": [
"src/content-scripts/proxy-diamond-inject.content.js"
]
"js": ["src/content-scripts/proxy-diamond-inject.content.js"]
},
{
"matches": [
Expand All @@ -83,10 +78,7 @@
"https://*.snowscan.xyz/block/*",
"https://*.arbiscan.io/block/*"
],
"js": [
"src/content-scripts/prove-block.content.js",
"src/content-scripts/block-superset.content.js"
]
"js": ["src/content-scripts/prove-block.content.js", "src/content-scripts/block-superset.content.js"]
},
{
"matches": [
Expand All @@ -101,17 +93,12 @@
"https://*.snowscan.xyz/tx/*",
"https://*.arbiscan.io/tx/*"
],
"js": [
"src/content-scripts/transaction-superset.content.js"
]
"js": ["src/content-scripts/transaction-superset.content.js"]
}
],
"web_accessible_resources": [
{
"resources": [
"src/contract-page-inject.js",
"src/proxy-diamond-inject.js"
],
"resources": ["src/contract-page-inject.js", "src/proxy-diamond-inject.js"],
"matches": [
"https://*.etherscan.io/*",
"https://*.polygonscan.com/*",
Expand All @@ -126,7 +113,5 @@
]
}
],
"permissions": [
"storage"
]
}
"permissions": ["storage"]
}
64 changes: 32 additions & 32 deletions src/contract-page-inject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,44 +78,44 @@ declare let tempI: number;
// In original script obj is assumed to be an iframe.
// However, in diamond view, it can also be a div containing multiple iframes.
// So we handle that case in else block.
window.resizeIframe = function(obj, addwidth) {
window.resizeIframe = function (obj, addwidth) {
setTimeout(function () {
if(obj.tagName === 'IFRAME') {
const iframe = obj as HTMLIFrameElement;
iframe.style.height = (iframe.contentWindow!.document.body.scrollHeight + addwidth) + 20 + 'px';
const id = iframe.id;
if(id != 'readdiamondcontractiframe' && id != 'writediamondcontractiframe') iframe.parentElement!.style.visibility = 'visible';
if (obj.tagName === "IFRAME") {
const iframe = obj as HTMLIFrameElement;
iframe.style.height = iframe.contentWindow!.document.body.scrollHeight + addwidth + 20 + "px";
const id = iframe.id;
if (id != "readdiamondcontractiframe" && id != "writediamondcontractiframe") iframe.parentElement!.style.visibility = "visible";
} else {
const div = obj as HTMLDivElement;
if (div.id == "readdiamondcontractiframe") {
if (window.readNumberOfIframes && window.readNumberOfIframes > 0) {
window.readNumberOfIframes--;
if (window.readNumberOfIframes > 0) return;
}
} else {
const div = obj as HTMLDivElement;
if(div.id == 'readdiamondcontractiframe') {
if(window.readNumberOfIframes && window.readNumberOfIframes > 0) {
window.readNumberOfIframes--;
if(window.readNumberOfIframes > 0) return;
}
} else {
if(window.writeNumberOfIframes && window.writeNumberOfIframes > 0) {
window.writeNumberOfIframes--;
if(window.writeNumberOfIframes > 0) return;
}
if (window.writeNumberOfIframes && window.writeNumberOfIframes > 0) {
window.writeNumberOfIframes--;
if (window.writeNumberOfIframes > 0) return;
}
// TODO: fix - if page is not visible during loading, it will calculate incorrect height.
for(const sub of Array.from(div.children) as HTMLIFrameElement[]) {
let content_height = sub.contentWindow!.document.getElementById('readContractAccordion')?.getBoundingClientRect()?.bottom;
if(!content_height) {
const sel = sub.contentWindow!.document.querySelectorAll('body > .card');
content_height = sel[sel.length - 1]?.getBoundingClientRect()?.bottom;
}
if (!content_height) {
content_height = sub.contentWindow!.document.body.scrollHeight;
}
sub.style.height = (Math.ceil(content_height) + 50) + 'px';
}
// TODO: fix - if page is not visible during loading, it will calculate incorrect height.
for (const sub of Array.from(div.children) as HTMLIFrameElement[]) {
let content_height = sub.contentWindow!.document.getElementById("readContractAccordion")?.getBoundingClientRect()?.bottom;
if (!content_height) {
const sel = sub.contentWindow!.document.querySelectorAll("body > .card");
content_height = sel[sel.length - 1]?.getBoundingClientRect()?.bottom;
}
for(const sub of Array.from(obj.children)) {
sub.parentElement!.style.visibility = 'visible';
if (!content_height) {
content_height = sub.contentWindow!.document.body.scrollHeight;
}
const capital = div.id == 'readdiamondcontractiframe' ? 'Read' : 'Write';
window.parent.document.getElementById("loading" + capital + "DiamondContractframe")!.style.display = "none";
sub.style.height = Math.ceil(content_height) + 50 + "px";
}
for (const sub of Array.from(obj.children)) {
sub.parentElement!.style.visibility = "visible";
}
const capital = div.id == "readdiamondcontractiframe" ? "Read" : "Write";
window.parent.document.getElementById("loading" + capital + "DiamondContractframe")!.style.display = "none";
}
}, 300);
};

Expand Down
22 changes: 7 additions & 15 deletions src/proxy-diamond-inject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ window.onload = function () {
if (param != "read" && param != "write") {
return;
}
window.contractframe = param +'diamondcontractiframe_' + searchParams.get("iframeId");
window.contractframe = param + "diamondcontractiframe_" + searchParams.get("iframeId");

setTimeout(function () {
var obj = window.parent.document.getElementById(param + "diamondcontractiframe");
Expand All @@ -24,7 +24,7 @@ window.openModal = function openModal() {
'Please take note that this is a beta version feature and is provided on an "as is" and "as available" basis. Etherscan does not give any warranties and will not be liable for any loss, direct or indirect through continued use of this feature.';
if (confirm(msg)) {
try {
const urlParams = new URLSearchParams(window.location.search)
const urlParams = new URLSearchParams(window.location.search);
const diamondAction = urlParams.get("diamond");
if (diamondAction == "read" || diamondAction == "write") {
const iframeId = diamondAction + "diamondcontractiframe_" + urlParams.get("iframeId");
Expand All @@ -35,28 +35,20 @@ window.openModal = function openModal() {
// window.parent.document
// .getElementById("readContractMessage")
// .classList.remove("d-flex");
} else if (
window.parent.document.URL.indexOf("writeProxyContract") != -1
) {
window.parent.document
.getElementById("readContractMessageProxy")
?.classList.remove("d-flex");
} else if (window.parent.document.URL.indexOf("writeProxyContract") != -1) {
window.parent.document.getElementById("readContractMessageProxy")?.classList.remove("d-flex");
parent.openProxyModal("writeproxycontractiframe");
} else {
var isInIFrame = window.location != window.parent.location;
if (isInIFrame) {
parent.openModal("writecontractiframe");
var parentIframe = window.parent.document.getElementById(
"writecontractiframe"
);
var parentIframe = window.parent.document.getElementById("writecontractiframe");
parentIframe!.style.minHeight = "600px";
window.parent.document
.getElementById("readContractMessage")
?.classList.remove("d-flex");
window.parent.document.getElementById("readContractMessage")?.classList.remove("d-flex");
} else {
$("#WalletModalProxyIframeNew").modal("show");
}
}
} catch (err) {}
}
};
};
6 changes: 3 additions & 3 deletions src/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const ALL_SCANS = [
"fraxscan.com",
"snowscan.xyz",
"testnet.snowscan.xyz",
'sepolia.arbiscan.io',
"sepolia.arbiscan.io",
] as const;

export const RPC_ENDPOINTS: Record<(typeof ALL_SCANS)[number], string> = {
Expand All @@ -45,7 +45,7 @@ export const RPC_ENDPOINTS: Record<(typeof ALL_SCANS)[number], string> = {
"fraxscan.com": "https://rpc.frax.com",
"snowscan.xyz": "https://avalanche-c-chain-rpc.publicnode.com",
"testnet.snowscan.xyz": "https://avalanche-fuji-c-chain-rpc.publicnode.com",
'sepolia.arbiscan.io': 'https://arbitrum-sepolia-rpc.publicnode.com',
"sepolia.arbiscan.io": "https://arbitrum-sepolia-rpc.publicnode.com",
};

export const CHAIN_IDS: Record<(typeof ALL_SCANS)[number], string> = {
Expand All @@ -70,5 +70,5 @@ export const CHAIN_IDS: Record<(typeof ALL_SCANS)[number], string> = {
"fraxscan.com": "252",
"snowscan.xyz": "43114",
"testnet.snowscan.xyz": "43113",
'sepolia.arbiscan.io': '421614',
"sepolia.arbiscan.io": "421614",
};
8 changes: 2 additions & 6 deletions src/utils/rlp.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
// RLP logic ported from ethereumjs: https://github.com/ethereumjs/ethereumjs-monorepo/tree/master/packages/rlp
export function rlp_encode(input) {
let bytes = rlp_encode_bytes(input);
return bytes.reduce(
(str, byte) => str + byte.toString(16).padStart(2, "0"),
"0x"
);
return bytes.reduce((str, byte) => str + byte.toString(16).padStart(2, "0"), "0x");

function rlp_encode_bytes(input) {
if (Array.isArray(input)) {
Expand Down Expand Up @@ -58,8 +55,7 @@ export function rlp_encode(input) {
if (typeof hex !== "string") {
throw new TypeError("hexToBytes: expected string, got " + typeof hex);
}
if (hex.length % 2)
throw new Error("hexToBytes: received invalid unpadded hex");
if (hex.length % 2) throw new Error("hexToBytes: received invalid unpadded hex");
const array = new Uint8Array(hex.length / 2);
for (let i = 0; i < array.length; i++) {
const j = i * 2;
Expand Down

0 comments on commit 7616411

Please sign in to comment.