Skip to content

Commit

Permalink
Merge pull request #452 from WalletConnect/#415-auth-instance
Browse files Browse the repository at this point in the history
[Auth] #415 auth instance
  • Loading branch information
llbartekll authored Aug 19, 2022
2 parents adf3328 + 213736c commit 8ddc520
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
26 changes: 26 additions & 0 deletions Sources/Auth/Auth.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import Foundation
import WalletConnectRelay
import Combine

public class Auth {

public static var instance: AuthClient = {
guard let config = Auth.config else {
fatalError("Error - you must call Auth.configure(_:) before accessing the shared instance.")
}
return AuthClientFactory.create(
metadata: config.metadata,
account: config.account,
relayClient: Relay.instance)
}()

private static var config: Config?

private init() { }

static public func configure(metadata: AppMetadata, account: Account?) {
Auth.config = Auth.Config(
metadata: metadata,
account: account)
}
}
8 changes: 8 additions & 0 deletions Sources/Auth/AuthConfig.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import Foundation

extension Auth {
struct Config {
let metadata: AppMetadata
let account: Account?
}
}
4 changes: 1 addition & 3 deletions Sources/Auth/Services/Wallet/WalletRequestSubscriber.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ class WalletRequestSubscriber {
self.logger = logger
self.address = address
self.messageFormatter = messageFormatter
if address != nil {
subscribeForRequest()
}
subscribeForRequest()
}

private func subscribeForRequest() {
Expand Down

0 comments on commit 8ddc520

Please sign in to comment.