Skip to content

Commit

Permalink
chore: add margins for error
Browse files Browse the repository at this point in the history
  • Loading branch information
devceline committed Apr 11, 2024
1 parent 32ef108 commit 184555d
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions packages/notify-client/src/controllers/engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
isJsonRpcResponse,
isJsonRpcResult,
} from "@walletconnect/jsonrpc-utils";
import { FIVE_MINUTES, ONE_DAY } from "@walletconnect/time";
import { FIVE_MINUTES, ONE_DAY, THIRTY_MINUTES, THIRTY_SECONDS } from "@walletconnect/time";
import { JsonRpcRecord, RelayerTypes } from "@walletconnect/types";
import {
TYPE_1,
Expand Down Expand Up @@ -82,8 +82,11 @@ export class NotifyEngine extends INotifyEngine {
// If client has been offline for more than 5 minutes - call watch subscriptions
const timeSinceOffline = Date.now() - this.disconnectTimer;

// Allow for margin for error
const timeSinceOfflineTolerance = THIRTY_SECONDS * 1_000;

const offlineForMoreThan5Minutes =
timeSinceOffline > FIVE_MINUTES * 1_000;
(timeSinceOffline + timeSinceOfflineTolerance) >= FIVE_MINUTES * 1_000;

this.disconnectTimer = 0;

Expand All @@ -94,9 +97,13 @@ export class NotifyEngine extends INotifyEngine {
const timeSinceFirstWatchSubscriptions =
Date.now() - this.lastWatchSubscriptionsCallTimestamp;

const timeSinceFirstWatchSubscriptionsTolerance = THIRTY_MINUTES * 1_000;

const clientOnlineForOverADay =
timeSinceFirstWatchSubscriptions > ONE_DAY * 1_000;
(timeSinceFirstWatchSubscriptions + timeSinceFirstWatchSubscriptionsTolerance) > ONE_DAY * 1_000;

// Call watch subscriptionsevery 24 hours
// This check will be triggered every reconnect
if (clientOnlineForOverADay) {
this.watchLastWatchedAccountIfExists();
this.lastWatchSubscriptionsCallTimestamp = 0;
Expand Down

0 comments on commit 184555d

Please sign in to comment.