Skip to content

Commit

Permalink
refactor: sets active pairing expiry of 5mins
Browse files Browse the repository at this point in the history
  • Loading branch information
ganchoradkov committed Jan 8, 2025
1 parent 051e587 commit b478e37
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
5 changes: 3 additions & 2 deletions packages/core/src/controllers/pairing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import {
isJsonRpcResult,
isJsonRpcError,
} from "@walletconnect/jsonrpc-utils";
import { FIVE_MINUTES, ONE_MINUTE, toMiliseconds } from "@walletconnect/time";
import { FIVE_MINUTES, toMiliseconds } from "@walletconnect/time";
import EventEmitter from "events";
import {
PAIRING_CONTEXT,
Expand Down Expand Up @@ -187,14 +187,15 @@ export class Pairing implements IPairing {

public activate: IPairing["activate"] = async ({ topic }) => {
this.isInitialized();
const expiry = calcExpiry(ONE_MINUTE);
const expiry = calcExpiry(FIVE_MINUTES);
this.core.expirer.set(topic, expiry);
await this.pairings.update(topic, { active: true, expiry });
};

public ping: IPairing["ping"] = async (params) => {
this.isInitialized();
await this.isValidPing(params);
this.logger.warn("ping() is deprecated and will be removed in the next major release.");
const { topic } = params;
if (this.pairings.keys.includes(topic)) {
const id = await this.sendRequest(topic, "wc_pairingPing", {});
Expand Down
7 changes: 3 additions & 4 deletions packages/core/test/pairing.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ICore } from "@walletconnect/types";
import { Core, CORE_PROTOCOL, CORE_VERSION, PAIRING_EVENTS, SUBSCRIBER_EVENTS } from "../src";
import { TEST_CORE_OPTIONS, disconnectSocket, waitForEvent } from "./shared";
import { calcExpiry, generateRandomBytes32, parseUri, toBase64 } from "@walletconnect/utils";
import { FIVE_MINUTES, ONE_MINUTE } from "@walletconnect/time";
import { FIVE_MINUTES } from "@walletconnect/time";

const createCoreClients: () => Promise<{ coreA: ICore; coreB: ICore }> = async () => {
const coreA = new Core(TEST_CORE_OPTIONS);
Expand Down Expand Up @@ -124,11 +124,10 @@ describe("Pairing", () => {
await coreA.pairing.activate({ topic });
const activePairing = coreA.pairing.pairings.get(topic);
expect(activePairing.active).toBe(true);
expect(activePairing.expiry > inactivePairing.expiry).toBe(false);
// inactive pairing should have an expiry of 5 minutes
expect(inactivePairing.expiry).to.be.approximately(calcExpiry(FIVE_MINUTES), 5);
// active pairing should have an expiry of 1 minute
expect(activePairing.expiry).to.be.approximately(calcExpiry(ONE_MINUTE), 5);
// active pairing should still have an expiry of 5 minutes
expect(activePairing.expiry).to.be.approximately(calcExpiry(FIVE_MINUTES), 5);
});
});

Expand Down

0 comments on commit b478e37

Please sign in to comment.