Skip to content

Commit

Permalink
- wc2 now removes its own unused pairings after a short time. Remove …
Browse files Browse the repository at this point in the history
…my cleanup code

- hide any temporary peer-less pairings in connected apps
  • Loading branch information
simonmcl committed Dec 14, 2023
1 parent d34f950 commit 745663d
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 22 deletions.
4 changes: 2 additions & 2 deletions Kukai Mobile/Modules/Side Menu/WalletConnectViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ class WalletConnectViewModel: ViewModel, UITableViewDiffableDataSourceHandler {
}

// Get data
pairs = Pair.instance.getPairings().map({ pair -> PairObj in
pairs = Pair.instance.getPairings().compactMap({ pair -> PairObj? in

if pair.peer == nil {
return PairObj(icon: nil, site: "Pending ...", address: nil, network: nil, topic: pair.topic)
return nil

} else {
let firstSession = Sign.instance.getSessions().filter({ $0.pairingTopic == pair.topic }).first
Expand Down
20 changes: 0 additions & 20 deletions Kukai Mobile/Services/WalletConnectService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -324,31 +324,11 @@ public class WalletConnectService {
})
}


@MainActor
public static func cleanupDanglingPairings() async {
var pairsToClean: [Pairing] = []
Pair.instance.getPairings().forEach({ pair in
if pair.peer == nil {
pairsToClean.append(pair)
}
})

await pairsToClean.asyncForEach({ pair in
try? await Pair.instance.disconnect(topic: pair.topic)

await Sign.instance.getSessions().filter({ $0.pairingTopic == pair.topic }).asyncForEach({ session in
try? await Sign.instance.disconnect(topic: session.topic)
})
})
}

@MainActor
public static func reject(proposalId: String, reason: RejectionReason) throws {
Logger.app.info("WC Reject Pairing \(proposalId)")
Task {
try await Sign.instance.reject(proposalId: proposalId, reason: reason)
await WalletConnectService.cleanupDanglingPairings()
TransactionService.shared.resetWalletConnectState()
}
}
Expand Down

0 comments on commit 745663d

Please sign in to comment.