Skip to content

Commit

Permalink
feedback from PR #292
Browse files Browse the repository at this point in the history
  • Loading branch information
CedarMist authored and aefhm committed Jul 15, 2024
1 parent 9983bdd commit 4220787
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 15 deletions.
20 changes: 11 additions & 9 deletions clients/js/src/calldatapublickey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,10 @@ export abstract class AbstractKeyFetcher {
export class KeyFetcher extends AbstractKeyFetcher {
readonly timeoutMilliseconds: number;
public pubkey?: CallDataPublicKey;
#isBackgroundRunning = false;
#isBackgroundRunning?: ReturnType<typeof setTimeout>;

get isBackgroundRunning(): boolean {
return this.#isBackgroundRunning;
return this.#isBackgroundRunning !== undefined;
}

constructor(in_timeoutMilliseconds?: number) {
Expand Down Expand Up @@ -232,22 +232,24 @@ export class KeyFetcher extends AbstractKeyFetcher {
}

public stopBackground() {
this.#isBackgroundRunning = false;
if (this.#isBackgroundRunning) {
clearTimeout(this.#isBackgroundRunning);
this.#isBackgroundRunning = undefined;
return true;
}
return false;
}

public async runInBackground(upstream: UpstreamProvider) {
public runInBackground(upstream: UpstreamProvider) {
if (this.#isBackgroundRunning) return;

// Reduce wait time by 10%, so it eagerly fetches
const waitMilliseconds =
this.timeoutMilliseconds - this.timeoutMilliseconds / 10;

while (this.#isBackgroundRunning) {
await new Promise((resolve) =>
setTimeout(resolve, this.timeoutMilliseconds),
);
this.#isBackgroundRunning = setTimeout(async () => {
await this.fetch(upstream, waitMilliseconds);
}
}, waitMilliseconds);
}
}

Expand Down
4 changes: 2 additions & 2 deletions clients/js/src/compat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ export function wrap<U extends Ethers5Signer>(
options?: SapphireWrapOptions,
): U & SapphireAnnex; // Ethers signers

export function wrap<U extends string>(
upstream: U,
export function wrap(
upstream: string,
options?: SapphireWrapOptions,
): Ethers5Provider & EIP1193Provider & SapphireAnnex; // Gateway URL

Expand Down
2 changes: 1 addition & 1 deletion examples/hardhat-viem/contracts/Example.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-License-Identifier: UNLICENSED
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.0;

contract Example {
Expand Down
2 changes: 1 addition & 1 deletion examples/hardhat-viem/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"scripts": {},
"keywords": [],
"author": "",
"license": "UNLICENSED",
"license": "Apache-2.0",
"dependencies": {
"@nomicfoundation/hardhat-toolbox-viem": "3.x",
"@nomicfoundation/hardhat-viem": "2.x",
Expand Down
1 change: 1 addition & 0 deletions examples/wagmi-v2/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"private": true,
"version": "0.0.0",
"type": "module",
"license": "Apache-2.0",
"scripts": {
"dev": "vite",
"build": "tsc && vite build",
Expand Down
2 changes: 1 addition & 1 deletion examples/wagmi-v2/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
import type { Abi } from "abitype";

/*
// SPDX-License-Identifier: UNLICENSED
// SPDX-License-Identifier: Apache-2.0
pragma solidity >=0.8.2 <0.9.0;
contract Storage {
uint256 number;
Expand Down
6 changes: 5 additions & 1 deletion examples/wagmi-v2/src/wagmi.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { createConfig } from "wagmi";
import { sapphire, sapphireTestnet } from "wagmi/chains";
import { injectedWithSapphire, sapphireTransport, sapphireLocalnet } from "@oasisprotocol/sapphire-wagmi-v2";
import {
injectedWithSapphire,
sapphireTransport,
sapphireLocalnet,
} from "@oasisprotocol/sapphire-wagmi-v2";

export const config = createConfig({
multiInjectedProviderDiscovery: false,
Expand Down

0 comments on commit 4220787

Please sign in to comment.