diff --git a/package-lock.json b/package-lock.json index d2ac8de1d..6521faaa1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -27609,7 +27609,7 @@ }, "packages/web3wallet": { "name": "@walletconnect/web3wallet", - "version": "2.13.3", + "version": "1.12.3", "license": "Apache-2.0", "dependencies": { "@walletconnect/auth-client": "2.1.2", diff --git a/packages/core/src/constants/verify.ts b/packages/core/src/constants/verify.ts index a61973743..479fe969d 100644 --- a/packages/core/src/constants/verify.ts +++ b/packages/core/src/constants/verify.ts @@ -1,7 +1,7 @@ export const VERIFY_CONTEXT = "verify-api"; -export const VERIFY_SERVER = "https://verify.walletconnect.com"; +const VERIFY_SERVER_COM = "https://verify.walletconnect.com"; +const VERIFY_SERVER_ORG = "https://verify.walletconnect.org"; +export const VERIFY_SERVER = VERIFY_SERVER_ORG; -export const VERIFY_FALLBACK_SERVER = "https://verify.walletconnect.org"; - -export const TRUSTED_VERIFY_URLS = [VERIFY_SERVER, VERIFY_FALLBACK_SERVER]; +export const TRUSTED_VERIFY_URLS = [VERIFY_SERVER_COM, VERIFY_SERVER_ORG]; diff --git a/packages/core/src/controllers/relayer.ts b/packages/core/src/controllers/relayer.ts index fc45b0d56..da6f3142d 100644 --- a/packages/core/src/controllers/relayer.ts +++ b/packages/core/src/controllers/relayer.ts @@ -74,9 +74,9 @@ export class Relayer extends IRelayer { private initialized = false; private connectionAttemptInProgress = false; - private relayUrl: string; - private projectId: string | undefined; - private bundleId: string | undefined; + public relayUrl: string; + public projectId: string | undefined; + public bundleId: string | undefined; private connectionStatusPollingInterval = 20; private staleConnectionErrors = ["socket hang up", "stalled", "interrupted"]; private hasExperiencedNetworkDisruption = false; diff --git a/packages/core/src/controllers/subscriber.ts b/packages/core/src/controllers/subscriber.ts index e327906a6..5fc34023d 100644 --- a/packages/core/src/controllers/subscriber.ts +++ b/packages/core/src/controllers/subscriber.ts @@ -19,6 +19,7 @@ import { createExpiringPromise, hashMessage, isValidArray, + formatRelayRpcUrl, } from "@walletconnect/utils"; import { CORE_STORAGE_PREFIX, @@ -27,8 +28,10 @@ import { SUBSCRIBER_STORAGE_VERSION, PENDING_SUB_RESOLUTION_TIMEOUT, RELAYER_EVENTS, + RELAYER_SDK_VERSION, } from "../constants"; import { SubscriberTopicMap } from "./topicmap"; +import { getBigIntRpcId } from "@walletconnect/jsonrpc-utils"; export class Subscriber extends ISubscriber { public subscriptions = new Map(); @@ -61,6 +64,73 @@ export class Subscriber extends ISubscriber { this.logger.trace(`Initialized`); this.registerEventListeners(); this.clientId = await this.relayer.core.crypto.getClientId(); + // window.addEventListener("focus", () => { + // // alert("=====onfocus==="); + // // this.reset(); + // this.batchFetchMessages(this.values); + // }); + // window.addEventListener("pageshow", () => { + // // alert("=====pageshow==="); + // // this.reset(); + // this.batchFetchMessages(this.values); + // }); + window.addEventListener("visibilitychange", async () => { + // alert("=====visibilitychange==="); + // this.reset(); + // this.batchFetchMessages(this.values); + + const subscriptions = this.values; + const relay = subscriptions[0].relay; + const api = getRelayProtocolApi(relay.protocol); + const request = { + id: getBigIntRpcId().toString() as any, + jsonrpc: "2.0", + method: api.batchFetchMessages, + params: { + topics: subscriptions.map((s) => s.topic), + }, + }; + + const auth = await this.relayer.core.crypto.signJWT( + (this.relayer as unknown as any).relayUrl, + ); + const url = formatRelayRpcUrl({ + sdkVersion: RELAYER_SDK_VERSION, + protocol: (this.relayer as unknown as any).protocol, + version: (this.relayer as unknown as any).version, + relayUrl: "http://192.168.0.159:3003/rpc", + projectId: (this.relayer as unknown as any).projectId, + auth, + useOnCloseEvent: true, + bundleId: (this.relayer as unknown as any).bundleId, + }); + const res = await fetch(url, { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify(request), + // credentials: "omit", + // mode: "no-cors", + }); + if (!res.ok) { + alert(res.status); + alert(await res.text()); + } + // console.log(await res.text()); + const response = await res.json(); + if (response && response.result?.messages) { + // alert(response.result?.messages.length); + this.pendingBatchMessages = this.pendingBatchMessages.concat(response.result.messages); + + if (this.pendingBatchMessages.length) { + await this.relayer.handleBatchMessageEvents(this.pendingBatchMessages); + this.pendingBatchMessages = []; + } + } + + // await this.relayer.restartTransport(); + }); } }; @@ -389,6 +459,7 @@ export class Subscriber extends ISubscriber { } private async reset() { + // alert(this.cached.length); if (this.cached.length) { const numOfBatches = Math.ceil(this.cached.length / this.batchSubscribeTopicsLimit); for (let i = 0; i < numOfBatches; i++) { diff --git a/packages/core/src/controllers/verify.ts b/packages/core/src/controllers/verify.ts index b9d5ac2f5..a710b0e2b 100644 --- a/packages/core/src/controllers/verify.ts +++ b/packages/core/src/controllers/verify.ts @@ -3,12 +3,7 @@ import { IVerify } from "@walletconnect/types"; import { isBrowser, isNode, isReactNative } from "@walletconnect/utils"; import { FIVE_SECONDS, ONE_SECOND, toMiliseconds } from "@walletconnect/time"; -import { - TRUSTED_VERIFY_URLS, - VERIFY_CONTEXT, - VERIFY_FALLBACK_SERVER, - VERIFY_SERVER, -} from "../constants"; +import { TRUSTED_VERIFY_URLS, VERIFY_CONTEXT, VERIFY_SERVER } from "../constants"; export class Verify extends IVerify { public name = VERIFY_CONTEXT; @@ -49,19 +44,7 @@ export class Verify extends IVerify { } catch (error) { this.logger.info(`Verify iframe failed to load: ${this.verifyUrl}`); this.logger.info(error); - } - - if (this.initialized) return; - - this.removeIframe(); - this.verifyUrl = VERIFY_FALLBACK_SERVER; - - try { - await this.createIframe(); - } catch (error) { - this.logger.info(`Verify iframe failed to load: ${this.verifyUrl}`); - this.logger.info(error); - // if the fallback url fails to load as well, disable verify + // if the iframe fails to load, disable verify this.verifyDisabled = true; } }; @@ -79,17 +62,7 @@ export class Verify extends IVerify { if (this.isDevEnv) return ""; const verifyUrl = this.getVerifyUrl(params?.verifyUrl); - let result; - try { - result = await this.fetchAttestation(params.attestationId, verifyUrl); - } catch (error) { - this.logger.info( - `failed to resolve attestation: ${params.attestationId} from url: ${verifyUrl}`, - ); - this.logger.info(error); - result = await this.fetchAttestation(params.attestationId, VERIFY_FALLBACK_SERVER); - } - return result; + return this.fetchAttestation(params.attestationId, verifyUrl); }; get context(): string { @@ -99,7 +72,7 @@ export class Verify extends IVerify { private fetchAttestation = async (attestationId: string, url: string) => { this.logger.info(`resolving attestation: ${attestationId} from url: ${url}`); // set artificial timeout to prevent hanging - const timeout = this.startAbortTimer(ONE_SECOND * 2); + const timeout = this.startAbortTimer(ONE_SECOND * 5); const result = await fetch(`${url}/attestation/${attestationId}`, { signal: this.abortController.signal, });