Skip to content

Commit 212c7b4

Browse files
committed
[trello.com/c/kie7Tdnq] Improve secret wallet service
1 parent d3aef7f commit 212c7b4

File tree

6 files changed

+50
-46
lines changed

6 files changed

+50
-46
lines changed

Adamant.xcodeproj/project.pbxproj

+8-8
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@
189189
41E3C9CC2A0E20F500AF0985 /* AdamantCoinTools.swift in Sources */ = {isa = PBXBuildFile; fileRef = 41E3C9CB2A0E20F500AF0985 /* AdamantCoinTools.swift */; };
190190
4803FC9A2D6715AF00452D2C /* SecretWalletsFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4803FC992D6715AF00452D2C /* SecretWalletsFactory.swift */; };
191191
481558702D65A7660011B470 /* SecretWalletsService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4815586F2D65A7660011B470 /* SecretWalletsService.swift */; };
192-
481558722D65A7BD0011B470 /* AdamantSecretWalletsManagerProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 481558712D65A7BD0011B470 /* AdamantSecretWalletsManagerProtocol.swift */; };
192+
481558722D65A7BD0011B470 /* SecretWalletsManagerProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 481558712D65A7BD0011B470 /* SecretWalletsManagerProtocol.swift */; };
193193
48B6A8EB2D5738D800326EE8 /* WalletsStoreService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 48B6A8EA2D5738D800326EE8 /* WalletsStoreService.swift */; };
194194
48B6A8ED2D57390400326EE8 /* AdamantWalletsStoreService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 48B6A8EC2D57390400326EE8 /* AdamantWalletsStoreService.swift */; };
195195
48B6A8EF2D573A3C00326EE8 /* AdamantWalletStoreServiceProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 48B6A8EE2D573A3C00326EE8 /* AdamantWalletStoreServiceProvider.swift */; };
@@ -487,14 +487,14 @@
487487
AA8FFFC42D4C1174001D8576 /* NativeAdamantCoreTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = AA8FFFC32D4C1168001D8576 /* NativeAdamantCoreTests.swift */; };
488488
AA8FFFCA2D4E6435001D8576 /* CryptoSwift in Frameworks */ = {isa = PBXBuildFile; productRef = AA8FFFC92D4E6435001D8576 /* CryptoSwift */; };
489489
AA8FFFCC2D50D503001D8576 /* NodeOrigin+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = AA8FFFCB2D50D4F8001D8576 /* NodeOrigin+Extensions.swift */; };
490-
AA8FFFE32D513681001D8576 /* CustomFieldRow.swift in Sources */ = {isa = PBXBuildFile; fileRef = AA8FFFE22D513670001D8576 /* CustomFieldRow.swift */; };
491-
AA8FFFE52D513787001D8576 /* EdgeInsetTextField.swift in Sources */ = {isa = PBXBuildFile; fileRef = AA8FFFE42D513780001D8576 /* EdgeInsetTextField.swift */; };
492490
AA8FFFD52D50DCEF001D8576 /* dash_send_transation_response.json in Resources */ = {isa = PBXBuildFile; fileRef = AA8FFFD42D50DCE4001D8576 /* dash_send_transation_response.json */; };
493491
AA8FFFD72D50DD0E001D8576 /* Data+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = AA8FFFD62D50DD07001D8576 /* Data+Extensions.swift */; };
494492
AA8FFFD82D50DF63001D8576 /* dash_unspent_transaction_intergration_test.json in Resources */ = {isa = PBXBuildFile; fileRef = AA8FFFD22D50DC0C001D8576 /* dash_unspent_transaction_intergration_test.json */; };
495493
AA8FFFDA2D50DFB2001D8576 /* dash_unspent_transaction_unit_test.json in Resources */ = {isa = PBXBuildFile; fileRef = AA8FFFD92D50DFA3001D8576 /* dash_unspent_transaction_unit_test.json */; };
496494
AA8FFFDC2D50E079001D8576 /* dash_unverified_unspent_transactions.json in Resources */ = {isa = PBXBuildFile; fileRef = AA8FFFDB2D50E063001D8576 /* dash_unverified_unspent_transactions.json */; };
497495
AA8FFFE12D50E175001D8576 /* dash_send_transaction_unit_response.json in Resources */ = {isa = PBXBuildFile; fileRef = AA8FFFDF2D50E13F001D8576 /* dash_send_transaction_unit_response.json */; };
496+
AA8FFFE32D513681001D8576 /* CustomFieldRow.swift in Sources */ = {isa = PBXBuildFile; fileRef = AA8FFFE22D513670001D8576 /* CustomFieldRow.swift */; };
497+
AA8FFFE52D513787001D8576 /* EdgeInsetTextField.swift in Sources */ = {isa = PBXBuildFile; fileRef = AA8FFFE42D513780001D8576 /* EdgeInsetTextField.swift */; };
498498
AAB01CAD2D3AE44B007D6BF4 /* BitcoinKitTransactionFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = AAB01CAC2D3AE449007D6BF4 /* BitcoinKitTransactionFactory.swift */; };
499499
AAB01CAF2D3AECED007D6BF4 /* DogeWalletServiceTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = AAB01CAE2D3AECE6007D6BF4 /* DogeWalletServiceTests.swift */; };
500500
AAB01CB12D3AF01B007D6BF4 /* DogeApiServiceProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = AAB01CB02D3AF015007D6BF4 /* DogeApiServiceProtocol.swift */; };
@@ -921,7 +921,7 @@
921921
41E3C9CB2A0E20F500AF0985 /* AdamantCoinTools.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AdamantCoinTools.swift; sourceTree = "<group>"; };
922922
4803FC992D6715AF00452D2C /* SecretWalletsFactory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SecretWalletsFactory.swift; sourceTree = "<group>"; };
923923
4815586F2D65A7660011B470 /* SecretWalletsService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SecretWalletsService.swift; sourceTree = "<group>"; };
924-
481558712D65A7BD0011B470 /* AdamantSecretWalletsManagerProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AdamantSecretWalletsManagerProtocol.swift; sourceTree = "<group>"; };
924+
481558712D65A7BD0011B470 /* SecretWalletsManagerProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SecretWalletsManagerProtocol.swift; sourceTree = "<group>"; };
925925
48B6A8EA2D5738D800326EE8 /* WalletsStoreService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WalletsStoreService.swift; sourceTree = "<group>"; };
926926
48B6A8EC2D57390400326EE8 /* AdamantWalletsStoreService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AdamantWalletsStoreService.swift; sourceTree = "<group>"; };
927927
48B6A8EE2D573A3C00326EE8 /* AdamantWalletStoreServiceProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AdamantWalletStoreServiceProvider.swift; sourceTree = "<group>"; };
@@ -1187,14 +1187,14 @@
11871187
AA8FFFBF2D4AC00B001D8576 /* AdamantCoreMock.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AdamantCoreMock.swift; sourceTree = "<group>"; };
11881188
AA8FFFC32D4C1168001D8576 /* NativeAdamantCoreTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NativeAdamantCoreTests.swift; sourceTree = "<group>"; };
11891189
AA8FFFCB2D50D4F8001D8576 /* NodeOrigin+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NodeOrigin+Extensions.swift"; sourceTree = "<group>"; };
1190-
AA8FFFE22D513670001D8576 /* CustomFieldRow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomFieldRow.swift; sourceTree = "<group>"; };
1191-
AA8FFFE42D513780001D8576 /* EdgeInsetTextField.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EdgeInsetTextField.swift; sourceTree = "<group>"; };
11921190
AA8FFFD22D50DC0C001D8576 /* dash_unspent_transaction_intergration_test.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = dash_unspent_transaction_intergration_test.json; sourceTree = "<group>"; };
11931191
AA8FFFD42D50DCE4001D8576 /* dash_send_transation_response.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = dash_send_transation_response.json; sourceTree = "<group>"; };
11941192
AA8FFFD62D50DD07001D8576 /* Data+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Data+Extensions.swift"; sourceTree = "<group>"; };
11951193
AA8FFFD92D50DFA3001D8576 /* dash_unspent_transaction_unit_test.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = dash_unspent_transaction_unit_test.json; sourceTree = "<group>"; };
11961194
AA8FFFDB2D50E063001D8576 /* dash_unverified_unspent_transactions.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = dash_unverified_unspent_transactions.json; sourceTree = "<group>"; };
11971195
AA8FFFDF2D50E13F001D8576 /* dash_send_transaction_unit_response.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = dash_send_transaction_unit_response.json; sourceTree = "<group>"; };
1196+
AA8FFFE22D513670001D8576 /* CustomFieldRow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomFieldRow.swift; sourceTree = "<group>"; };
1197+
AA8FFFE42D513780001D8576 /* EdgeInsetTextField.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EdgeInsetTextField.swift; sourceTree = "<group>"; };
11981198
AAB01CAC2D3AE449007D6BF4 /* BitcoinKitTransactionFactory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BitcoinKitTransactionFactory.swift; sourceTree = "<group>"; };
11991199
AAB01CAE2D3AECE6007D6BF4 /* DogeWalletServiceTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DogeWalletServiceTests.swift; sourceTree = "<group>"; };
12001200
AAB01CB02D3AF015007D6BF4 /* DogeApiServiceProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DogeApiServiceProtocol.swift; sourceTree = "<group>"; };
@@ -2585,7 +2585,7 @@
25852585
E93D7ABD2052CEE1005D19DC /* NotificationsService.swift */,
25862586
E9215972206119FB0000CA5C /* ReachabilityMonitor.swift */,
25872587
9304F8C1292F895C00173F18 /* PushNotificationsTokenService.swift */,
2588-
481558712D65A7BD0011B470 /* AdamantSecretWalletsManagerProtocol.swift */,
2588+
481558712D65A7BD0011B470 /* SecretWalletsManagerProtocol.swift */,
25892589
41047B73294C61D10039E956 /* VisibleWalletsService.swift */,
25902590
48B6A8EA2D5738D800326EE8 /* WalletsStoreService.swift */,
25912591
4153045A29C09C6C000E4BEA /* IncreaseFeeService.swift */,
@@ -4000,7 +4000,7 @@
40004000
E98FC34420F920BD00032D65 /* UIFont+adamant.swift in Sources */,
40014001
644EC35720EFAAB700F40C73 /* DelegatesListViewController.swift in Sources */,
40024002
4153045B29C09C6C000E4BEA /* IncreaseFeeService.swift in Sources */,
4003-
481558722D65A7BD0011B470 /* AdamantSecretWalletsManagerProtocol.swift in Sources */,
4003+
481558722D65A7BD0011B470 /* SecretWalletsManagerProtocol.swift in Sources */,
40044004
E9C51EF12013F18000385EB7 /* NewChatViewController.swift in Sources */,
40054005
E9B4E1A8210F079E007E77FC /* DoubleDetailsTableViewCell.swift in Sources */,
40064006
E9502740202E257E002C1098 /* RepeaterService.swift in Sources */,

Adamant/App/DI/AppAssembly.swift

+8-8
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,6 @@ struct AppAssembly: MainThreadAssembly {
8282
)
8383
}.inObjectScope(.container)
8484

85-
container.register(WalletStoreServiceProviderProtocol.self) { r in
86-
AdamantWalletStoreServiceProvider(
87-
secretWalletsManager: r.resolve(AdamantSecretWalletsManagerProtocol.self)!
88-
)
89-
}.inObjectScope(.container)
90-
9185
// MARK: Secret Wallets
9286
container.register(SecretWalletsFactory.self) { r in
9387
SecretWalletsFactory(
@@ -97,12 +91,18 @@ struct AppAssembly: MainThreadAssembly {
9791
)
9892
}.inObjectScope(.container)
9993

100-
container.register(AdamantSecretWalletsManagerProtocol.self) { r in
94+
container.register(SecretWalletsManagerProtocol.self) { r in
10195
AdamantSecretWalletsManager(
10296
walletsStoreService: r.resolve(WalletStoreServiceProtocol.self)!,
10397
secretWalletsFactory: r.resolve(SecretWalletsFactory.self)!
10498
)
105-
}
99+
}.inObjectScope(.container)
100+
101+
container.register(WalletStoreServiceProviderProtocol.self) { r in
102+
AdamantWalletStoreServiceProvider(
103+
secretWalletsManager: r.resolve(SecretWalletsManagerProtocol.self)!
104+
)
105+
}.inObjectScope(.container)
106106

107107
// MARK: IncreaseFeeService
108108
container.register(IncreaseFeeService.self) { r in

Adamant/ServiceProtocols/AdamantSecretWalletsManagerProtocol.swift

-21
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//
2+
// SecretWalletsManagerProtocol.swift
3+
// Adamant
4+
//
5+
// Created by Dmitrij Meidus on 19.02.25.
6+
// Copyright © 2025 Adamant. All rights reserved.
7+
//
8+
9+
import CommonKit
10+
11+
protocol SecretWalletsManagerProtocol {
12+
var statePublisher: AnyObservable<SecretWalletsManagerStateProtocol> { get }
13+
14+
func createSecretWallet(withPassword password: String)
15+
func removeSecretWallet(at index: Int) -> WalletStoreServiceProtocol?
16+
func getCurrentWallet() -> WalletStoreServiceProtocol
17+
func getSecretWallets() -> [WalletStoreServiceProtocol]
18+
func activateSecretWallet(at index: Int)
19+
func activateDefaultWallet()
20+
}
21+
22+
protocol SecretWalletsManagerStateProtocol {
23+
var currentWallet: WalletStoreServiceProtocol { get set }
24+
var defaultWallet: WalletStoreServiceProtocol { get }
25+
var secretWallets: [WalletStoreServiceProtocol] { get set }
26+
}

Adamant/Services/DataProviders/AdamantWalletStoreServiceProvider.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ protocol WalletStoreServiceProviderProtocol: WalletStoreServiceProtocol {
1616
}
1717

1818
final class AdamantWalletStoreServiceProvider: WalletStoreServiceProviderProtocol {
19-
private let secretWalletsManager: AdamantSecretWalletsManagerProtocol
19+
private let secretWalletsManager: SecretWalletsManagerProtocol
2020

2121
private var cancellables = Set<AnyCancellable>()
2222

@@ -25,7 +25,7 @@ final class AdamantWalletStoreServiceProvider: WalletStoreServiceProviderProtoco
2525
$currentWallet.map { _ in () }.eraseToAnyPublisher()
2626
}
2727

28-
init(secretWalletsManager: AdamantSecretWalletsManagerProtocol) {
28+
init(secretWalletsManager: SecretWalletsManagerProtocol) {
2929
self.secretWalletsManager = secretWalletsManager
3030
self._currentWallet = ObservableValue(secretWalletsManager.getCurrentWallet())
3131

Adamant/Services/SecretWalletsService.swift

+6-7
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ import Swinject
1111
import CommonKit
1212

1313
extension AdamantSecretWalletsManager {
14-
struct State {
14+
struct State: SecretWalletsManagerStateProtocol {
1515
var currentWallet: WalletStoreServiceProtocol
1616
let defaultWallet: WalletStoreServiceProtocol
1717
var secretWallets: [WalletStoreServiceProtocol] = []
1818
}
1919
}
2020

21-
final class AdamantSecretWalletsManager: AdamantSecretWalletsManagerProtocol {
21+
final class AdamantSecretWalletsManager: SecretWalletsManagerProtocol {
2222
private let secretWalletsFactory: SecretWalletsFactory
2323
private let lock = NSLock()
2424

@@ -33,8 +33,8 @@ final class AdamantSecretWalletsManager: AdamantSecretWalletsManagerProtocol {
3333
self.secretWalletsFactory = secretWalletsFactory
3434
}
3535

36-
@ObservableValue private var state: State
37-
var statePublisher: AnyObservable<State> {
36+
@ObservableValue private var state: SecretWalletsManagerStateProtocol
37+
var statePublisher: AnyObservable<SecretWalletsManagerStateProtocol> {
3838
$state.eraseToAnyPublisher()
3939
}
4040

@@ -44,7 +44,6 @@ final class AdamantSecretWalletsManager: AdamantSecretWalletsManagerProtocol {
4444
lock.lock()
4545
defer { lock.unlock() }
4646
state.secretWallets.append(wallet)
47-
activateSecretWallet(at: state.secretWallets.count - 1)
4847
}
4948

5049
func removeSecretWallet(at index: Int) -> WalletStoreServiceProtocol? {
@@ -58,8 +57,8 @@ final class AdamantSecretWalletsManager: AdamantSecretWalletsManagerProtocol {
5857
state.currentWallet
5958
}
6059

61-
func getWallets() -> [WalletStoreServiceProtocol] {
62-
[state.currentWallet] + state.secretWallets
60+
func getSecretWallets() -> [WalletStoreServiceProtocol] {
61+
state.secretWallets
6362
}
6463

6564
func activateSecretWallet(at index: Int) {

0 commit comments

Comments
 (0)