From abaa83df342923e1cd3aa520d9e524623d4284e2 Mon Sep 17 00:00:00 2001 From: Artur Guseinov Date: Mon, 29 Jan 2024 19:36:01 +0300 Subject: [PATCH] Update NotifySubsctiptionsUpdater.swift --- .../Client/Wallet/NotifySubsctiptionsUpdater.swift | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Sources/WalletConnectNotify/Client/Wallet/NotifySubsctiptionsUpdater.swift b/Sources/WalletConnectNotify/Client/Wallet/NotifySubsctiptionsUpdater.swift index 367e3b23a..6b48492d0 100644 --- a/Sources/WalletConnectNotify/Client/Wallet/NotifySubsctiptionsUpdater.swift +++ b/Sources/WalletConnectNotify/Client/Wallet/NotifySubsctiptionsUpdater.swift @@ -42,9 +42,13 @@ final class NotifySubsctiptionsUpdater { try kms.setSymmetricKey(symKey, for: subscription.topic) } - let topics = newSubscriptions.map { $0.topic } + let topicsToSubscribe = newSubscriptions.map { $0.topic } - try await networkingInteractor.batchSubscribe(topics: topics) + let oldTopics = Set(oldSubscriptions.map { $0.topic }) + let topicsToUnsubscribe = Array(oldTopics.subtracting(topicsToSubscribe)) + + try await networkingInteractor.batchUnsubscribe(topics: topicsToUnsubscribe) + try await networkingInteractor.batchSubscribe(topics: topicsToSubscribe) try Task.checkCancellation()