diff --git a/clients/js/src/calldatapublickey.ts b/clients/js/src/calldatapublickey.ts index f638154f..5f3d2f4c 100644 --- a/clients/js/src/calldatapublickey.ts +++ b/clients/js/src/calldatapublickey.ts @@ -182,10 +182,10 @@ export abstract class AbstractKeyFetcher { export class KeyFetcher extends AbstractKeyFetcher { readonly timeoutMilliseconds: number; public pubkey?: CallDataPublicKey; - #isBackgroundRunning = false; + #isBackgroundRunning?: ReturnType; get isBackgroundRunning(): boolean { - return this.#isBackgroundRunning; + return this.#isBackgroundRunning !== undefined; } constructor(in_timeoutMilliseconds?: number) { @@ -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); } } diff --git a/clients/js/src/compat.ts b/clients/js/src/compat.ts index 81fa799b..e6da658f 100644 --- a/clients/js/src/compat.ts +++ b/clients/js/src/compat.ts @@ -82,8 +82,8 @@ export function wrap( options?: SapphireWrapOptions, ): U & SapphireAnnex; // Ethers signers -export function wrap( - upstream: U, +export function wrap( + upstream: string, options?: SapphireWrapOptions, ): Ethers5Provider & EIP1193Provider & SapphireAnnex; // Gateway URL diff --git a/examples/hardhat-viem/contracts/Example.sol b/examples/hardhat-viem/contracts/Example.sol index ec9f9006..01298cfb 100644 --- a/examples/hardhat-viem/contracts/Example.sol +++ b/examples/hardhat-viem/contracts/Example.sol @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: UNLICENSED +// SPDX-License-Identifier: Apache-2.0 pragma solidity ^0.8.0; contract Example { diff --git a/examples/hardhat-viem/package.json b/examples/hardhat-viem/package.json index 7e16a993..8799c176 100644 --- a/examples/hardhat-viem/package.json +++ b/examples/hardhat-viem/package.json @@ -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", diff --git a/examples/wagmi-v2/package.json b/examples/wagmi-v2/package.json index 7cbc335d..e99641ac 100644 --- a/examples/wagmi-v2/package.json +++ b/examples/wagmi-v2/package.json @@ -3,6 +3,7 @@ "private": true, "version": "0.0.0", "type": "module", + "license": "Apache-2.0", "scripts": { "dev": "vite", "build": "tsc && vite build", diff --git a/examples/wagmi-v2/src/App.tsx b/examples/wagmi-v2/src/App.tsx index 54f0896d..eab1fd1e 100644 --- a/examples/wagmi-v2/src/App.tsx +++ b/examples/wagmi-v2/src/App.tsx @@ -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; diff --git a/examples/wagmi-v2/src/wagmi.ts b/examples/wagmi-v2/src/wagmi.ts index 973f4faf..944d51e2 100644 --- a/examples/wagmi-v2/src/wagmi.ts +++ b/examples/wagmi-v2/src/wagmi.ts @@ -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,