Skip to content

Commit

Permalink
remove duplicates
Browse files Browse the repository at this point in the history
  • Loading branch information
llbartekll committed Mar 18, 2024
1 parent f5499fd commit 83d9673
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions Sources/WalletConnectSign/Namespace.swift
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@ public enum AutoNamespaces {
) throws -> [String: SessionNamespace] {
var sessionNamespaces = [String: SessionNamespace]()

let chains = chains.removeDuplicates()
let accounts = accounts.removeDuplicates()
try sessionProposal.requiredNamespaces.forEach {
let caip2Namespace = $0.key
let proposalNamespace = $0.value
Expand Down Expand Up @@ -365,4 +367,19 @@ fileprivate extension Array where Element: Hashable {
}
return combined
}

func removeDuplicates() -> [Element] {
var uniqueElements = [Element]()
var seenElements = Set<Element>()

for element in self {
if !seenElements.contains(element) {
uniqueElements.append(element)
seenElements.insert(element)
}
}

return uniqueElements
}

}

0 comments on commit 83d9673

Please sign in to comment.