Skip to content

Commit

Permalink
Remove wallet Connect v1 files
Browse files Browse the repository at this point in the history
  • Loading branch information
ant013 committed Sep 6, 2023
1 parent cc3da42 commit c0b305f
Show file tree
Hide file tree
Showing 56 changed files with 921 additions and 2,672 deletions.
362 changes: 126 additions & 236 deletions UnstoppableWallet/UnstoppableWallet.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

17 changes: 7 additions & 10 deletions UnstoppableWallet/UnstoppableWallet/Core/App.swift
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,8 @@ class App {
let guidesManager: GuidesManager
let termsManager: TermsManager

let walletConnectSocketConnectionService: WalletConnectSocketConnectionService
let walletConnectSessionManager: WalletConnectSessionManager
let walletConnectV2SocketConnectionService: WalletConnectV2SocketConnectionService
let walletConnectV2SessionManager: WalletConnectV2SessionManager
let walletConnectManager: WalletConnectManager

let deepLinkManager: DeepLinkManager
Expand Down Expand Up @@ -269,8 +268,6 @@ class App {
guidesManager = GuidesManager(networkManager: networkManager)
termsManager = TermsManager(storage: StorageKit.LocalStorage.default)

let walletConnectSessionStorage = WalletConnectSessionStorage(dbPool: dbPool)
walletConnectSessionManager = WalletConnectSessionManager(storage: walletConnectSessionStorage, accountManager: accountManager, evmBlockchainManager: evmBlockchainManager)
walletConnectManager = WalletConnectManager(accountManager: accountManager, evmBlockchainManager: evmBlockchainManager)

let walletClientInfo = WalletConnectClientInfo(
Expand All @@ -282,15 +279,15 @@ class App {
icons: ["https://raw.githubusercontent.com/horizontalsystems/HS-Design/master/PressKit/UW-AppIcon-on-light.png"]
)

walletConnectV2SocketConnectionService = WalletConnectV2SocketConnectionService(reachabilityManager: reachabilityManager, logger: logger)
let walletConnectV2Service = WalletConnectV2Service(
connectionService: walletConnectV2SocketConnectionService,
walletConnectSocketConnectionService = WalletConnectSocketConnectionService(reachabilityManager: reachabilityManager, logger: logger)
let walletConnectService = WalletConnectService(
connectionService: walletConnectSocketConnectionService,
sessionRequestFilterManager: SessionRequestFilterManager(),
info: walletClientInfo,
logger: logger
)
let walletConnectV2SessionStorage = WalletConnectV2SessionStorage(dbPool: dbPool)
walletConnectV2SessionManager = WalletConnectV2SessionManager(service: walletConnectV2Service, storage: walletConnectV2SessionStorage, accountManager: accountManager, evmBlockchainManager: evmBlockchainManager, currentDateProvider: CurrentDateProvider())
let walletConnectSessionStorage = WalletConnectSessionStorage(dbPool: dbPool)
walletConnectSessionManager = WalletConnectSessionManager(service: walletConnectService, storage: walletConnectSessionStorage, accountManager: accountManager, evmBlockchainManager: evmBlockchainManager, currentDateProvider: CurrentDateProvider())

deepLinkManager = DeepLinkManager()
launchScreenManager = LaunchScreenManager(storage: StorageKit.LocalStorage.default)
Expand Down Expand Up @@ -321,7 +318,7 @@ class App {
deepLinkManager: deepLinkManager,
evmLabelManager: evmLabelManager,
balanceHiddenManager: balanceHiddenManager,
walletConnectV2SocketConnectionService: walletConnectV2SocketConnectionService,
walletConnectSocketConnectionService: walletConnectSocketConnectionService,
nftMetadataSyncer: nftMetadataSyncer
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class AppManager {
private let deepLinkManager: DeepLinkManager
private let evmLabelManager: EvmLabelManager
private let balanceHiddenManager: BalanceHiddenManager
private let walletConnectV2SocketConnectionService: WalletConnectV2SocketConnectionService
private let walletConnectSocketConnectionService: WalletConnectSocketConnectionService
private let nftMetadataSyncer: NftMetadataSyncer

private let didBecomeActiveSubject = PublishSubject<()>()
Expand All @@ -30,7 +30,7 @@ class AppManager {
appVersionManager: AppVersionManager, rateAppManager: RateAppManager,
logRecordManager: LogRecordManager,
deepLinkManager: DeepLinkManager, evmLabelManager: EvmLabelManager, balanceHiddenManager: BalanceHiddenManager,
walletConnectV2SocketConnectionService: WalletConnectV2SocketConnectionService, nftMetadataSyncer: NftMetadataSyncer
walletConnectSocketConnectionService: WalletConnectSocketConnectionService, nftMetadataSyncer: NftMetadataSyncer
) {
self.accountManager = accountManager
self.walletManager = walletManager
Expand All @@ -46,7 +46,7 @@ class AppManager {
self.deepLinkManager = deepLinkManager
self.evmLabelManager = evmLabelManager
self.balanceHiddenManager = balanceHiddenManager
self.walletConnectV2SocketConnectionService = walletConnectV2SocketConnectionService
self.walletConnectSocketConnectionService = walletConnectSocketConnectionService
self.nftMetadataSyncer = nftMetadataSyncer
}

Expand Down Expand Up @@ -85,7 +85,7 @@ extension AppManager {
debugBackgroundLogger?.logEnterBackground()

pinKit.didEnterBackground()
walletConnectV2SocketConnectionService.didEnterBackground()
walletConnectSocketConnectionService.didEnterBackground()
balanceHiddenManager.didEnterBackground()
}

Expand All @@ -99,7 +99,7 @@ extension AppManager {
keychainKit.handleForeground()
pinKit.willEnterForeground()
adapterManager.refresh()
walletConnectV2SocketConnectionService.willEnterForeground()
walletConnectSocketConnectionService.willEnterForeground()

nftMetadataSyncer.sync()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import WalletConnectSign
import WalletConnectPairing
import MarketKit

class WalletConnectV2SessionManager {
class WalletConnectSessionManager {
private let disposeBag = DisposeBag()

let service: WalletConnectV2Service
private let storage: WalletConnectV2SessionStorage
let service: WalletConnectService
private let storage: WalletConnectSessionStorage
private let accountManager: AccountManager
private let currentDateProvider: CurrentDateProvider
private let evmBlockchainManager: EvmBlockchainManager
Expand All @@ -19,7 +19,7 @@ class WalletConnectV2SessionManager {
private let pairingsRelay = BehaviorRelay<[WalletConnectPairing.Pairing]>(value: [])
private let sessionRequestReceivedRelay = PublishRelay<WalletConnectRequest>()

init(service: WalletConnectV2Service, storage: WalletConnectV2SessionStorage, accountManager: AccountManager, evmBlockchainManager: EvmBlockchainManager, currentDateProvider: CurrentDateProvider) {
init(service: WalletConnectService, storage: WalletConnectSessionStorage, accountManager: AccountManager, evmBlockchainManager: EvmBlockchainManager, currentDateProvider: CurrentDateProvider) {
self.service = service
self.storage = storage
self.accountManager = accountManager
Expand Down Expand Up @@ -50,7 +50,7 @@ class WalletConnectV2SessionManager {
}

private func handleDeleted(account: Account) {
storage.deleteSessionsV2(accountId: account.id)
storage.deleteSessions(accountId: account.id)
syncSessions()
syncPendingRequest()
}
Expand All @@ -66,7 +66,7 @@ class WalletConnectV2SessionManager {
}

let currentSessions = allSessions
let allDbSessions = storage.sessionsV2(accountId: nil)
let allDbSessions = storage.sessions(accountId: nil)
let dbTopics = allDbSessions.map {
$0.topic
}
Expand All @@ -81,9 +81,9 @@ class WalletConnectV2SessionManager {
}

storage.save(sessions: newSessions.map {
WalletConnectV2Session(accountId: accountId, topic: $0.topic)
WalletConnectSession(accountId: accountId, topic: $0.topic)
})
storage.deleteSessionV2(topics: deletedTopics)
storage.deleteSession(topics: deletedTopics)

sessionsRelay.accept(sessions(accountId: accountId, sessions: currentSessions))
activePendingRequestsRelay.accept(activePendingRequests)
Expand All @@ -93,7 +93,7 @@ class WalletConnectV2SessionManager {
guard let account = accountManager.activeAccount else {
return
}
let activeSessions = storage.sessionsV2(accountId: account.id)
let activeSessions = storage.sessions(accountId: account.id)

guard let chainId = Int(request.chainId.reference),
let blockchain = evmBlockchainManager.blockchain(chainId: chainId),
Expand All @@ -107,7 +107,7 @@ class WalletConnectV2SessionManager {
let chain = WalletConnectRequest.Chain(id: chainId, chainName: blockchain.name, address: address.eip55)
guard activeSessions.first(where: { session in session.topic == request.topic }) != nil,
let session = allSessions.first(where: { session in session.topic == request.topic }),
let request = try? WalletConnectV2RequestMapper.map(dAppName: session.peer.name, chain: chain, request: request) else {
let request = try? WalletConnectRequestMapper.map(dAppName: session.peer.name, chain: chain, request: request) else {
return
}

Expand All @@ -116,7 +116,7 @@ class WalletConnectV2SessionManager {

private func sessions(accountId: String, sessions: [WalletConnectSign.Session]?) -> [WalletConnectSign.Session] {
let sessions = sessions ?? allSessions
let dbSessions = storage.sessionsV2(accountId: accountId)
let dbSessions = storage.sessions(accountId: accountId)

let accountSessions = sessions.filter { session in
dbSessions.contains {
Expand Down Expand Up @@ -147,7 +147,7 @@ class WalletConnectV2SessionManager {

private func requests(accountId: String? = nil) -> [WalletConnectSign.Request] {
let allRequests = service.pendingRequests
let dbSessions = storage.sessionsV2(accountId: accountId)
let dbSessions = storage.sessions(accountId: accountId)

return allRequests.filter { request in
dbSessions.contains { session in
Expand All @@ -158,7 +158,7 @@ class WalletConnectV2SessionManager {

}

extension WalletConnectV2SessionManager {
extension WalletConnectSessionManager {

public var sessions: [WalletConnectSign.Session] {
guard let accountId = accountManager.activeAccount?.id else {
Expand All @@ -179,7 +179,7 @@ extension WalletConnectV2SessionManager {
}

public func deleteSession(topic: String) {
service.disconnect(topic: topic, reason: WalletConnectV2MainService.RejectionReason(code: 1, message: "Session Killed by User"))
service.disconnect(topic: topic, reason: WalletConnectMainService.RejectionReason(code: 1, message: "Session Killed by User"))
}

public var activePendingRequests: [WalletConnectSign.Request] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,18 +327,6 @@ class StorageMigrator {
}
}

migrator.registerMigration("createWalletConnectSessions") { db in
try db.create(table: WalletConnectSession.databaseTableName) { t in
t.column(WalletConnectSession.Columns.chainId.name, .integer).notNull()
t.column(WalletConnectSession.Columns.accountId.name, .text).notNull()
t.column(WalletConnectSession.Columns.session.name, .text).notNull()
t.column(WalletConnectSession.Columns.peerId.name, .text).notNull()
t.column(WalletConnectSession.Columns.peerMeta.name, .text).notNull()

t.primaryKey([WalletConnectSession.Columns.chainId.name, WalletConnectSession.Columns.accountId.name, WalletConnectSession.Columns.peerId.name], onConflict: .replace)
}
}

migrator.registerMigration("extractCoinsAndChangeCoinIds") { db in
// apply changes in database
try db.drop(table: CoinRecord_v19.databaseTableName)
Expand Down Expand Up @@ -532,11 +520,11 @@ class StorageMigrator {
}

migrator.registerMigration("createWalletConnectV2Sessions") { db in
try db.create(table: WalletConnectV2Session.databaseTableName) { t in
t.column(WalletConnectV2Session.Columns.accountId.name, .text).notNull()
t.column(WalletConnectV2Session.Columns.topic.name, .text).notNull()
try db.create(table: WalletConnectSession.databaseTableName) { t in
t.column(WalletConnectSession.Columns.accountId.name, .text).notNull()
t.column(WalletConnectSession.Columns.topic.name, .text).notNull()

t.primaryKey([WalletConnectV2Session.Columns.accountId.name, WalletConnectV2Session.Columns.topic.name], onConflict: .replace)
t.primaryKey([WalletConnectSession.Columns.accountId.name, WalletConnectSession.Columns.topic.name], onConflict: .replace)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,29 @@ class WalletConnectSessionStorage {

extension WalletConnectSessionStorage {

func sessions(accountId: String) -> [WalletConnectSession] {
func sessions(accountId: String?) -> [WalletConnectSession] {
try! dbPool.read { db in
try WalletConnectSession.filter(WalletConnectSession.Columns.accountId == accountId).fetchAll(db)
var request = WalletConnectSession.all()
if let accountId = accountId {
request = request.filter(WalletConnectSession.Columns.accountId == accountId)
}
return try request.fetchAll(db)
}
}

func session(peerId: String, accountId: String) -> WalletConnectSession? {
try! dbPool.read { db in
try WalletConnectSession.filter(WalletConnectSession.Columns.peerId == peerId && WalletConnectSession.Columns.accountId == accountId).fetchOne(db)
}
}

func save(session: WalletConnectSession) {
func save(sessions: [WalletConnectSession]) {
_ = try! dbPool.write { db in
try session.insert(db)
for session in sessions {
try session.insert(db)
}
}
}

func deleteSession(peerId: String) {
func deleteSession(topics: [String]) {
_ = try! dbPool.write { db in
try WalletConnectSession.filter(WalletConnectSession.Columns.peerId == peerId).deleteAll(db)
for topic in topics {
try WalletConnectSession.filter(WalletConnectSession.Columns.topic == topic).deleteAll(db)
}
}
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,31 +1,21 @@
import GRDB
import WalletConnectV1

class WalletConnectSession: Codable, FetchableRecord, PersistableRecord, TableRecord {
let chainId: Int
let accountId: String
let session: WCSession
let peerId: String
let peerMeta: WCPeerMeta
let topic: String

init(chainId: Int, accountId: String, session: WCSession, peerId: String, peerMeta: WCPeerMeta) {
self.chainId = chainId
init(accountId: String, topic: String) {
self.accountId = accountId
self.session = session
self.peerId = peerId
self.peerMeta = peerMeta
self.topic = topic
}

class var databaseTableName: String {
"wallet_connect_sessions"
"wallet_connect_sessions_v2"
}

enum Columns {
static let chainId = Column(CodingKeys.chainId)
static let accountId = Column(CodingKeys.accountId)
static let session = Column(CodingKeys.session)
static let peerId = Column(CodingKeys.peerId)
static let peerMeta = Column(CodingKeys.peerMeta)
static let topic = Column(CodingKeys.topic)
}

}

This file was deleted.

Loading

0 comments on commit c0b305f

Please sign in to comment.