From 9d330ca19b33aed7df13618891cd89f8cce223d9 Mon Sep 17 00:00:00 2001 From: Jordan Ribbink Date: Fri, 15 Nov 2024 16:44:35 -0800 Subject: [PATCH] Add fclWc.disableUNotifications session property --- packages/fcl-wc/src/service.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/packages/fcl-wc/src/service.ts b/packages/fcl-wc/src/service.ts index efe8f4f75..51185aab7 100644 --- a/packages/fcl-wc/src/service.ts +++ b/packages/fcl-wc/src/service.ts @@ -13,6 +13,7 @@ import {showNotification} from "./ui/notifications" import type {FclWalletConnectConfig} from "./fcl-wc" import mobileIcon from "./ui/assets/mobile.png" import {CurrentUser, Service} from "@onflow/typedefs" +import { SessionTypes } from "@walletconnect/types" type WalletConnectModalType = import("@walletconnect/modal").WalletConnectModal @@ -66,7 +67,7 @@ const makeExec = ( const client = await clientPromise invariant(!!client, "WalletConnect is not initialized") - let session: any, pairing: any + let session: SessionTypes.Struct | null = null, pairing: any const method = service.endpoint const appLink = validateAppLink(service) const pairings = client.pairing.getAll({active: true}) @@ -81,7 +82,7 @@ const makeExec = ( } if (session == null) { - session = await new Promise((resolve, reject) => { + session = await new Promise((resolve, reject) => { function onClose() { reject(`Declined: Externally Halted`) } @@ -117,7 +118,8 @@ const makeExec = ( } // Show notification to the user if enabled - const notification = showNotifications + const walletDisabledNotifications = session?.sessionProperties?.["fclWc.disableUiNotifications"] === "true" + const notification = showNotifications && !walletDisabledNotifications ? showWcRequestNotification({ user, service, @@ -170,7 +172,7 @@ function connectWc( wcRequestHook: any pairingModalOverride: any abortSignal?: AbortSignal - }) => { + }): Promise => { const projectId = client.opts?.projectId invariant( !!projectId, @@ -230,7 +232,7 @@ function connectWc( const session = await Promise.race([ approval(), - new Promise((_, reject) => { + new Promise((_, reject) => { if (abortSignal?.aborted) { reject(new Error("Session request aborted")) }