Skip to content

Commit

Permalink
Merge pull request #1190 from WalletConnect/develop
Browse files Browse the repository at this point in the history
1.9.0
  • Loading branch information
flypaper0 authored Oct 18, 2023
2 parents bb68f8f + cc7f36b commit 99e12a7
Show file tree
Hide file tree
Showing 78 changed files with 771 additions and 336 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ env:
PACKAGE_VERSION: ${{ github.event.pull_request.title }}
jobs:
set-user-agent:
runs-on: macos-latest
runs-on:
group: apple-silicon
steps:
- uses: actions/checkout@v2
with:
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ on:

jobs:
build:
runs-on: macos-12
runs-on:
group: apple-silicon

steps:
- uses: actions/checkout@v3
Expand Down
1 change: 1 addition & 0 deletions Example/ExampleApp.xcodeproj/IntegrationTests.xctestplan
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"AuthTests\/testEIP1271RespondSuccess()",
"ChatTests",
"ENSResolverTests",
"HistoryTests",
"SyncDerivationServiceTests",
"SyncTests"
],
Expand Down
14 changes: 13 additions & 1 deletion Example/ExampleApp.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@
A5629AE828772A0100094373 /* InviteViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5629AE728772A0100094373 /* InviteViewModel.swift */; };
A5629AEA2877F2D600094373 /* WalletConnectChat in Frameworks */ = {isa = PBXBuildFile; productRef = A5629AE92877F2D600094373 /* WalletConnectChat */; };
A5629AF22877F75100094373 /* Starscream in Frameworks */ = {isa = PBXBuildFile; productRef = A5629AF12877F75100094373 /* Starscream */; };
A56AC8F22AD88A5A001C8FAA /* Sequence.swift in Sources */ = {isa = PBXBuildFile; fileRef = A56AC8F12AD88A5A001C8FAA /* Sequence.swift */; };
A573C53729EC34A600E3CBFD /* SyncDerivationServiceTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A573C53629EC34A600E3CBFD /* SyncDerivationServiceTests.swift */; };
A573C53929EC365000E3CBFD /* HDWalletKit in Frameworks */ = {isa = PBXBuildFile; productRef = A573C53829EC365000E3CBFD /* HDWalletKit */; };
A573C53B29EC365800E3CBFD /* HDWalletKit in Frameworks */ = {isa = PBXBuildFile; productRef = A573C53A29EC365800E3CBFD /* HDWalletKit */; };
Expand Down Expand Up @@ -478,6 +479,7 @@
A5629AE32876E6D200094373 /* ThreadViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ThreadViewModel.swift; sourceTree = "<group>"; };
A5629AE728772A0100094373 /* InviteViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InviteViewModel.swift; sourceTree = "<group>"; };
A5629AEF2877F73000094373 /* DefaultSocketFactory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DefaultSocketFactory.swift; sourceTree = "<group>"; };
A56AC8F12AD88A5A001C8FAA /* Sequence.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Sequence.swift; sourceTree = "<group>"; };
A573C53629EC34A600E3CBFD /* SyncDerivationServiceTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SyncDerivationServiceTests.swift; sourceTree = "<group>"; };
A57879702A4EDC8100F8D10B /* TextFieldView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextFieldView.swift; sourceTree = "<group>"; };
A578FA312873036400AA7720 /* InputView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InputView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1126,6 +1128,14 @@
path = Chat;
sourceTree = "<group>";
};
A56AC8F02AD88A4B001C8FAA /* Foundation */ = {
isa = PBXGroup;
children = (
A56AC8F12AD88A5A001C8FAA /* Sequence.swift */,
);
path = Foundation;
sourceTree = "<group>";
};
A574B3592964570000C2BB91 /* Web3Inbox */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -1664,6 +1674,7 @@
C56EE262293F56D6004840D1 /* Extensions */ = {
isa = PBXGroup;
children = (
A56AC8F02AD88A4B001C8FAA /* Foundation */,
84F568C32795832A00D0A289 /* EthereumTransaction.swift */,
C56EE26D293F56D6004840D1 /* SwiftUI */,
C56EE269293F56D6004840D1 /* UIKit */,
Expand Down Expand Up @@ -2438,6 +2449,7 @@
C5B2F6FB297055B0000DBA0E /* ETHSigner.swift in Sources */,
C56EE274293F56D7004840D1 /* SceneViewController.swift in Sources */,
A5D610D42AB35BED00C20083 /* FailableDecodable.swift in Sources */,
A56AC8F22AD88A5A001C8FAA /* Sequence.swift in Sources */,
847BD1E5298A806800076C90 /* NotificationsPresenter.swift in Sources */,
A50D53C12ABA055700A4FD8B /* NotifyPreferencesModule.swift in Sources */,
A5B4F7C52ABB20AE0099AF7C /* SubscriptionRouter.swift in Sources */,
Expand Down Expand Up @@ -3223,7 +3235,7 @@
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/WalletConnect/web3modal-swift";
requirement = {
branch = "feat/ui-package";
branch = develop;
kind = branch;
};
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,8 @@
"package": "swift-web3modal",
"repositoryURL": "https://github.com/WalletConnect/web3modal-swift",
"state": {
"branch": "feat/ui-package",
"revision": "c87ab80f45452e1980b018bfabd8ec1f672c5ed3",
"branch": "develop",
"revision": "24602e2acee171fac26aa978b30666deec68a08f",
"version": null
}
}
Expand Down
4 changes: 3 additions & 1 deletion Example/IntegrationTests/Chat/ChatTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ final class ChatTests: XCTestCase {
let historyClient = HistoryClientFactory.create(
historyUrl: "https://history.walletconnect.com",
relayUrl: "wss://relay.walletconnect.com",
keychain: keychain
keyValueStorage: keyValueStorage,
keychain: keychain,
logger: logger
)

let clientId = try! networkingInteractor.getClientId()
Expand Down
8 changes: 5 additions & 3 deletions Example/IntegrationTests/History/HistoryTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ final class HistoryTests: XCTestCase {
override func setUp() {
let keychain1 = KeychainStorageMock()
let keychain2 = KeychainStorageMock()
let logger1 = ConsoleLoggerMock()
let defaults1 = RuntimeKeyValueStorage()
relayClient1 = makeRelayClient(prefix: "🐄", keychain: keychain1)
relayClient2 = makeRelayClient(prefix: "🐫", keychain: keychain2)
historyClient = makeHistoryClient(keychain: keychain1)
historyClient = makeHistoryClient(defaults: defaults1, keychain: keychain1, logger: logger1)
}

private func makeRelayClient(prefix: String, keychain: KeychainStorageProtocol) -> RelayClient {
Expand All @@ -33,8 +35,8 @@ final class HistoryTests: XCTestCase {
logger: ConsoleLogger(prefix: prefix + " [Relay]", loggingLevel: .debug))
}

private func makeHistoryClient(keychain: KeychainStorageProtocol) -> HistoryNetworkService {
let clientIdStorage = ClientIdStorage(keychain: keychain)
private func makeHistoryClient(defaults: KeyValueStorage, keychain: KeychainStorageProtocol, logger: ConsoleLogging) -> HistoryNetworkService {
let clientIdStorage = ClientIdStorage(defaults: defaults, keychain: keychain, logger: logger)
return HistoryNetworkService(clientIdStorage: clientIdStorage)
}

Expand Down
5 changes: 4 additions & 1 deletion Example/IntegrationTests/Pairing/PairingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,14 @@ final class PairingTests: XCTestCase {
let prefix = "🐶 Wallet: "
let (pairingClient, networkingInteractor, keychain, keyValueStorage) = makeClientDependencies(prefix: prefix)
let notifyLogger = ConsoleLogger(prefix: prefix + " [Notify]", loggingLevel: .debug)
let defaults = RuntimeKeyValueStorage()
walletPairingClient = pairingClient
let historyClient = HistoryClientFactory.create(
historyUrl: "https://history.walletconnect.com",
relayUrl: "wss://relay.walletconnect.com",
keychain: keychain
keyValueStorage: defaults,
keychain: keychain,
logger: notifyLogger
)
appAuthClient = AuthClientFactory.create(
metadata: AppMetadata(name: name, description: "", url: "", icons: [""]),
Expand Down
33 changes: 15 additions & 18 deletions Example/IntegrationTests/Push/NotifyTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,12 @@ final class NotifyTests: XCTestCase {
let notifyLogger = ConsoleLogger(prefix: prefix + " [Notify]", loggingLevel: .debug)
let pushClient = PushClientFactory.create(projectId: "",
pushHost: "echo.walletconnect.com",
keyValueStorage: keyValueStorage,
keychainStorage: keychain,
environment: .sandbox)
let keyserverURL = URL(string: "https://keys.walletconnect.com")!
let client = NotifyClientFactory.create(keyserverURL: keyserverURL,
let client = NotifyClientFactory.create(projectId: InputConfig.projectId,
keyserverURL: keyserverURL,
logger: notifyLogger,
keyValueStorage: keyValueStorage,
keychainStorage: keychain,
Expand All @@ -95,7 +97,7 @@ final class NotifyTests: XCTestCase {

walletNotifyClientA.subscriptionsPublisher
.sink { [unowned self] subscriptions in
guard let subscription = subscriptions.first else {return}
guard let subscription = subscriptions.first else { return }
Task(priority: .high) {
try await walletNotifyClientA.deleteSubscription(topic: subscription.topic)
expectation.fulfill()
Expand All @@ -114,17 +116,15 @@ final class NotifyTests: XCTestCase {

let clientB = makeWalletClient(prefix: "👐🏼 Wallet B: ")
clientB.subscriptionsPublisher.sink { subscriptions in
guard let subscription = subscriptions.first else { return }
Task(priority: .high) {
if !subscriptions.isEmpty {
expectation.fulfill()
}
try await clientB.deleteSubscription(topic: subscription.topic)
expectation.fulfill()
}
}.store(in: &publishers)

try! await walletNotifyClientA.register(account: account, domain: gmDappDomain, onSign: sign)
try! await walletNotifyClientA.subscribe(appDomain: gmDappDomain, account: account)

sleep(1)
try! await clientB.register(account: account, domain: gmDappDomain, onSign: sign)

wait(for: [expectation], timeout: InputConfig.defaultTimeout)
Expand All @@ -136,33 +136,30 @@ final class NotifyTests: XCTestCase {

let clientB = makeWalletClient(prefix: "👐🏼 Wallet B: ")
clientB.subscriptionsPublisher.sink { subscriptions in
guard let subscription = subscriptions.first else { return }
Task(priority: .high) {
if !subscriptions.isEmpty {
expectation.fulfill()
}
try await clientB.deleteSubscription(topic: subscription.topic)
expectation.fulfill()
}
}.store(in: &publishers)

try! await walletNotifyClientA.register(account: account, domain: gmDappDomain, onSign: sign)
try! await clientB.register(account: account, domain: gmDappDomain, onSign: sign)

sleep(1)

try! await walletNotifyClientA.subscribe(appDomain: gmDappDomain, account: account)

wait(for: [expectation], timeout: InputConfig.defaultTimeout)
}

func testWalletCreatesAndUpdatesSubscription() async {
let expectation = expectation(description: "expects to create and update notify subscription")
let updateScope: Set<String> = ["alerts"]
let updateScope: Set<String> = ["8529aae8-cb26-4d49-922e-eb099044bebe"]
expectation.assertForOverFulfill = false

var didUpdate = false
walletNotifyClientA.subscriptionsPublisher
.sink { [unowned self] subscriptions in
guard let subscription = subscriptions.first else {return}
let updatedScope = Set(subscription.scope.filter{ $0.value.enabled == true }.keys)
guard let subscription = subscriptions.first else { return }
let updatedScope = Set(subscription.scope.filter { $0.value.enabled == true }.keys)

if !didUpdate {
didUpdate = true
Expand All @@ -187,12 +184,12 @@ final class NotifyTests: XCTestCase {
func testNotifyServerSubscribeAndNotifies() async throws {
let subscribeExpectation = expectation(description: "creates notify subscription")
let messageExpectation = expectation(description: "receives a notify message")
let notifyMessage = NotifyMessage.stub()
let notifyMessage = NotifyMessage.stub(type: "8529aae8-cb26-4d49-922e-eb099044bebe")

var didNotify = false
walletNotifyClientA.subscriptionsPublisher
.sink { subscriptions in
guard let subscription = subscriptions.first else {return}
guard let subscription = subscriptions.first else { return }
let notifier = Publisher()
if !didNotify {
didNotify = true
Expand Down
6 changes: 3 additions & 3 deletions Example/IntegrationTests/Stubs/PushMessage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import Foundation
import WalletConnectNotify

extension NotifyMessage {
static func stub() -> NotifyMessage {
static func stub(type: String) -> NotifyMessage {
return NotifyMessage(
title: "swift_test",
body: "gm_hourly",
body: "body",
icon: "https://images.unsplash.com/photo-1581224463294-908316338239?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=250&q=80",
url: "https://web3inbox.com",
type: "private")
type: type)
}
}
6 changes: 3 additions & 3 deletions Example/RelayIntegrationTests/RelayClientEndToEndTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ final class RelayClientEndToEndTests: XCTestCase {
private var publishers = Set<AnyCancellable>()

func makeRelayClient(prefix: String) -> RelayClient {
let clientIdStorage = ClientIdStorage(keychain: KeychainStorageMock())
let keyValueStorage = RuntimeKeyValueStorage()
let logger = ConsoleLogger(prefix: prefix, loggingLevel: .debug)
let clientIdStorage = ClientIdStorage(defaults: keyValueStorage, keychain: KeychainStorageMock(), logger: logger)
let socketAuthenticator = ClientIdAuthenticator(
clientIdStorage: clientIdStorage,
url: InputConfig.relayUrl
Expand All @@ -43,15 +45,13 @@ final class RelayClientEndToEndTests: XCTestCase {
)
let socket = WebSocket(url: urlFactory.create(fallback: false))
let webSocketFactory = WebSocketFactoryMock(webSocket: socket)
let logger = ConsoleLogger(prefix: prefix, loggingLevel: .debug)
let dispatcher = Dispatcher(
socketFactory: webSocketFactory,
relayUrlFactory: urlFactory,
socketConnectionType: .manual,
logger: logger
)
let keychain = KeychainStorageMock()
let keyValueStorage = RuntimeKeyValueStorage()
let relayClient = RelayClientFactory.create(
relayHost: InputConfig.relayHost,
projectId: InputConfig.projectId,
Expand Down
21 changes: 21 additions & 0 deletions Example/WalletApp/Common/Extensions/Foundation/Sequence.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import Foundation

extension Sequence {
func sorted(
by firstPredicate: (Element, Element) -> Bool,
_ secondPredicate: (Element, Element) -> Bool,
_ otherPredicates: ((Element, Element) -> Bool)...
) -> [Element] {
return sorted(by:) { lhs, rhs in
if firstPredicate(lhs, rhs) { return true }
if firstPredicate(rhs, lhs) { return false }
if secondPredicate(lhs, rhs) { return true }
if secondPredicate(rhs, lhs) { return false }
for predicate in otherPredicates {
if predicate(lhs, rhs) { return true }
if predicate(rhs, lhs) { return false }
}
return false
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ typealias SubscriptionScope = [String: ScopeValue]

struct SubscriptionsViewModel: Identifiable {
let subscription: NotifySubscription
let messages: [NotifyMessageRecord]?

init(subscription: NotifySubscription, messages: [NotifyMessageRecord]? = nil) {
self.subscription = subscription
self.messages = messages
}

var id: String {
return subscription.topic
Expand Down Expand Up @@ -33,4 +39,12 @@ struct SubscriptionsViewModel: Identifiable {
var scope: SubscriptionScope {
return subscription.scope
}

var messagesCount: Int {
return messages?.count ?? 0
}

var hasMessage: Bool {
return messagesCount != 0
}
}
Loading

0 comments on commit 99e12a7

Please sign in to comment.