Skip to content

Commit e03d451

Browse files
committed
Merge branch 'develop' into trello.com/c/vawidi4o
# Conflicts: # Adamant/Modules/Account/AccountViewController/AccountViewController.swift
2 parents f143a45 + 2cc62de commit e03d451

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+357
-227
lines changed

Adamant.xcodeproj/project.pbxproj

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
557AC306287B10D8004699D7 /* SnapKit in Frameworks */ = {isa = PBXBuildFile; productRef = 557AC305287B10D8004699D7 /* SnapKit */; };
1919
55D1D84F287B78F200F94A4E /* SnapKit in Frameworks */ = {isa = PBXBuildFile; productRef = 55D1D84E287B78F200F94A4E /* SnapKit */; };
2020
55D1D851287B78FC00F94A4E /* SnapKit in Frameworks */ = {isa = PBXBuildFile; productRef = 55D1D850287B78FC00F94A4E /* SnapKit */; };
21-
6403F5DB2272389800D58779 /* BuildFile in Sources */ = {isa = PBXBuildFile; };
21+
6403F5DB2272389800D58779 /* (null) in Sources */ = {isa = PBXBuildFile; };
2222
6FB686162D3AAE8800CAB6DD /* AdamantWalletsKit in Frameworks */ = {isa = PBXBuildFile; productRef = 6FB686152D3AAE8800CAB6DD /* AdamantWalletsKit */; };
2323
9342F6C22A6A35E300A9B39F /* CommonKit in Frameworks */ = {isa = PBXBuildFile; productRef = 9342F6C12A6A35E300A9B39F /* CommonKit */; };
2424
937751A52A68B3320054BD65 /* CommonKit in Frameworks */ = {isa = PBXBuildFile; productRef = 937751A42A68B3320054BD65 /* CommonKit */; };
@@ -31,7 +31,7 @@
3131
A5241B70262DEDE1009FA43E /* Clibsodium in Frameworks */ = {isa = PBXBuildFile; productRef = A5241B6F262DEDE1009FA43E /* Clibsodium */; };
3232
A5241B77262DEDEF009FA43E /* Clibsodium in Frameworks */ = {isa = PBXBuildFile; productRef = A5241B76262DEDEF009FA43E /* Clibsodium */; };
3333
A5241B7E262DEDFE009FA43E /* Clibsodium in Frameworks */ = {isa = PBXBuildFile; productRef = A5241B7D262DEDFE009FA43E /* Clibsodium */; };
34-
A530B0D82842110D003F0210 /* BuildFile in Frameworks */ = {isa = PBXBuildFile; };
34+
A530B0D82842110D003F0210 /* (null) in Frameworks */ = {isa = PBXBuildFile; };
3535
A544F0D4262C9878001F1A6D /* Eureka in Frameworks */ = {isa = PBXBuildFile; productRef = A544F0D3262C9878001F1A6D /* Eureka */; };
3636
A57282CA262C94CD00C96FA8 /* DateToolsSwift in Frameworks */ = {isa = PBXBuildFile; productRef = A57282C9262C94CD00C96FA8 /* DateToolsSwift */; };
3737
A57282D1262C94DA00C96FA8 /* DateToolsSwift in Frameworks */ = {isa = PBXBuildFile; productRef = A57282D0262C94DA00C96FA8 /* DateToolsSwift */; };
@@ -249,8 +249,6 @@
249249
};
250250
D3A860F82DA1C1980007B599 /* NotificationsShared */ = {
251251
isa = PBXFileSystemSynchronizedRootGroup;
252-
exceptions = (
253-
);
254252
path = NotificationsShared;
255253
sourceTree = "<group>";
256254
};
@@ -317,7 +315,7 @@
317315
A5DBBABD262C7221004AC028 /* Clibsodium in Frameworks */,
318316
6FB686162D3AAE8800CAB6DD /* AdamantWalletsKit in Frameworks */,
319317
938F7D582955C1DA001915CA /* MessageKit in Frameworks */,
320-
A530B0D82842110D003F0210 /* BuildFile in Frameworks */,
318+
A530B0D82842110D003F0210 /* (null) in Frameworks */,
321319
4177E5E12A52DA7100C089FE /* AdvancedContextMenuKit in Frameworks */,
322320
A5D87BA3262CA01D00DC28F0 /* ProcedureKit in Frameworks */,
323321
A5C99E0E262C9E3A00F7B1B7 /* Reachability in Frameworks */,
@@ -669,12 +667,12 @@
669667
A57282C8262C94CD00C96FA8 /* XCRemoteSwiftPackageReference "DateTools" */,
670668
A544F0D2262C9878001F1A6D /* XCRemoteSwiftPackageReference "Eureka" */,
671669
A5F0A049262C9CA90009672A /* XCRemoteSwiftPackageReference "Swinject" */,
672-
A5C99E0C262C9E3A00F7B1B7 /* XCRemoteSwiftPackageReference "Reachability.swift" */,
670+
A5C99E0C262C9E3A00F7B1B7 /* XCRemoteSwiftPackageReference "Reachability" */,
673671
A5D87BA1262CA01D00DC28F0 /* XCRemoteSwiftPackageReference "ProcedureKit" */,
674672
A5AC8DFD262E0B030053A7E2 /* XCRemoteSwiftPackageReference "SipHash" */,
675673
3A8875ED27BBF38D00436195 /* XCRemoteSwiftPackageReference "Parchment" */,
676674
557AC304287B10D8004699D7 /* XCRemoteSwiftPackageReference "SnapKit" */,
677-
416F5EA2290162EB00EF0400 /* XCRemoteSwiftPackageReference "socket.io-client-swift" */,
675+
416F5EA2290162EB00EF0400 /* XCRemoteSwiftPackageReference "socket" */,
678676
938F7D562955C1DA001915CA /* XCRemoteSwiftPackageReference "MessageKit" */,
679677
4184F16F2A33044E00D7B8B9 /* XCRemoteSwiftPackageReference "firebase-ios-sdk" */,
680678
3AC76E3B2AB09118008042C4 /* XCRemoteSwiftPackageReference "Elegant-Emoji-Picker" */,
@@ -824,7 +822,7 @@
824822
isa = PBXSourcesBuildPhase;
825823
buildActionMask = 2147483647;
826824
files = (
827-
6403F5DB2272389800D58779 /* BuildFile in Sources */,
825+
6403F5DB2272389800D58779 /* (null) in Sources */,
828826
);
829827
runOnlyForDeploymentPostprocessing = 0;
830828
};
@@ -1367,7 +1365,7 @@
13671365
kind = branch;
13681366
};
13691367
};
1370-
416F5EA2290162EB00EF0400 /* XCRemoteSwiftPackageReference "socket.io-client-swift" */ = {
1368+
416F5EA2290162EB00EF0400 /* XCRemoteSwiftPackageReference "socket" */ = {
13711369
isa = XCRemoteSwiftPackageReference;
13721370
repositoryURL = "https://github.com/socketio/socket.io-client-swift";
13731371
requirement = {
@@ -1447,7 +1445,7 @@
14471445
minimumVersion = 1.2.2;
14481446
};
14491447
};
1450-
A5C99E0C262C9E3A00F7B1B7 /* XCRemoteSwiftPackageReference "Reachability.swift" */ = {
1448+
A5C99E0C262C9E3A00F7B1B7 /* XCRemoteSwiftPackageReference "Reachability" */ = {
14511449
isa = XCRemoteSwiftPackageReference;
14521450
repositoryURL = "https://github.com/ashleymills/Reachability.swift";
14531451
requirement = {
@@ -1526,7 +1524,7 @@
15261524
};
15271525
416F5EA3290162EB00EF0400 /* SocketIO */ = {
15281526
isa = XCSwiftPackageProductDependency;
1529-
package = 416F5EA2290162EB00EF0400 /* XCRemoteSwiftPackageReference "socket.io-client-swift" */;
1527+
package = 416F5EA2290162EB00EF0400 /* XCRemoteSwiftPackageReference "socket" */;
15301528
productName = SocketIO;
15311529
};
15321530
4177E5E02A52DA7100C089FE /* AdvancedContextMenuKit */ = {
@@ -1644,7 +1642,7 @@
16441642
};
16451643
A5C99E0D262C9E3A00F7B1B7 /* Reachability */ = {
16461644
isa = XCSwiftPackageProductDependency;
1647-
package = A5C99E0C262C9E3A00F7B1B7 /* XCRemoteSwiftPackageReference "Reachability.swift" */;
1645+
package = A5C99E0C262C9E3A00F7B1B7 /* XCRemoteSwiftPackageReference "Reachability" */;
16481646
productName = Reachability;
16491647
};
16501648
A5D87BA2262CA01D00DC28F0 /* ProcedureKit */ = {

Adamant/Modules/Account/AccountViewController/AccountViewController.swift

Lines changed: 21 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,10 @@ final class AccountViewController: FormViewController {
9292
}()
9393

9494
private var walletViewControllers: [WalletViewController] = []
95-
96-
private var currentWalletCoinID: String = ""
97-
private var currentSelectedWalletItem: WalletCollectionViewCell.Model? {
98-
walletsViewModel.state.wallets.first { wallet in
99-
wallet.coinID == currentWalletCoinID
100-
}
101-
}
95+
96+
private lazy var currentSelectedWallet: AccountWalletCellState? = {
97+
walletsViewModel.state.wallets.first(where: { $0.model.index == 0 })
98+
}()
10299

103100
private var initiated = false
104101

@@ -187,7 +184,6 @@ final class AccountViewController: FormViewController {
187184
guard let self = self else { return }
188185
self.setupWalletsVC()
189186
self.pagingViewController.reloadData()
190-
selectCurrentWallet()
191187
guard index >= 0 else { return }
192188
self.accountHeaderView.setWalletIcon(index == 0 ? .regular : .secret, badgeCount: index)
193189
}
@@ -206,14 +202,13 @@ final class AccountViewController: FormViewController {
206202
setupWalletsVC()
207203

208204
pagingViewController = PagingViewController()
209-
pagingViewController.register(UINib(nibName: "WalletCollectionViewCell", bundle: nil), for: WalletCollectionViewCell.Model.self)
205+
pagingViewController.register(UINib(nibName: "WalletCollectionViewCell", bundle: nil), for: AccountWalletCellState.self)
210206
pagingViewController.menuItemSize = .fixed(width: 110, height: 110)
211207
pagingViewController.indicatorColor = UIColor.adamant.primary
212208
pagingViewController.indicatorOptions = .visible(height: 2, zIndex: Int.max, spacing: UIEdgeInsets.zero, insets: UIEdgeInsets.zero)
213209
pagingViewController.dataSource = self
214210
pagingViewController.delegate = self
215-
selectCurrentWallet()
216-
211+
217212
accountHeaderView.walletViewContainer.addSubview(pagingViewController.view)
218213
pagingViewController.view.snp.makeConstraints {
219214
$0.directionalEdges.equalToSuperview()
@@ -225,17 +220,6 @@ final class AccountViewController: FormViewController {
225220

226221
pagingViewController.borderColor = UIColor.clear
227222

228-
walletsViewModel.$state
229-
.removeDuplicates()
230-
.debounce(for: .seconds(1) , scheduler: DispatchQueue.main)
231-
.receive(on: DispatchQueue.main)
232-
.sink { [weak self] _ in
233-
guard let self = self else { return }
234-
self.pagingViewController.reloadMenu()
235-
self.selectCurrentWallet()
236-
}
237-
.store(in: &notificationsSet)
238-
239223
setupSections()
240224

241225
// MARK: Notification Center
@@ -912,8 +896,6 @@ final class AccountViewController: FormViewController {
912896
let collectionView = self.pagingViewController.collectionView
913897
collectionView.reloadData()
914898
self.tableView.reloadData()
915-
916-
selectCurrentWallet()
917899
}
918900
.store(in: &notificationsSet)
919901
}
@@ -1018,34 +1000,26 @@ final class AccountViewController: FormViewController {
10181000
}
10191001

10201002
@objc private func handleRefresh(_ refreshControl: UIRefreshControl) {
1021-
let unavailableNodes: Set<NodeGroup> = Set(
1022-
NodeGroup.allCases.filter {
1023-
!(apiServiceCompose.get($0)?.hasSupportedNode ?? true)
1024-
}
1025-
)
1026-
1003+
guard let currencyNetwork = currentSelectedWallet?.model.currencyNetwork else { return }
1004+
1005+
let unavailableNodes: Set<NodeGroup> = Set(NodeGroup.allCases.filter {
1006+
!(apiServiceCompose.get($0)?.hasSupportedNode ?? true)
1007+
})
1008+
10271009
if unavailableNodes.contains(where: {
1028-
$0.name == currentSelectedWalletItem?.currencyNetwork
1010+
$0.name == currencyNetwork
10291011
}) {
10301012
dialogService.showWarning(
10311013
withMessage: ApiServiceError.noEndpointsAvailable(
1032-
nodeGroupName: currentSelectedWalletItem?.currencyNetwork ?? ""
1014+
nodeGroupName: currencyNetwork
10331015
).localizedDescription
10341016
)
10351017
}
1036-
1018+
10371019
Task { @MainActor in
1038-
accountService.update()
1039-
refreshControl.endRefreshing()
1040-
}
1041-
}
1042-
1043-
private func selectCurrentWallet() {
1044-
if let index = walletsViewModel.state.wallets.firstIndex(where: { $0.coinID == currentWalletCoinID }) {
1045-
pagingViewController.select(index: index, animated: false)
1046-
} else if let firstWalletID = walletsViewModel.state.wallets.first?.coinID {
1047-
currentWalletCoinID = firstWalletID
1020+
accountService.updateWithRefreshUI()
10481021
}
1022+
refreshControl.endRefreshing()
10491023
}
10501024
}
10511025

@@ -1126,7 +1100,7 @@ extension AccountViewController: PagingViewControllerDataSource, PagingViewContr
11261100
MainActor.assertIsolated()
11271101

11281102
return DispatchQueue.onMainThreadSyncSafe {
1129-
return walletsViewModel.state.wallets[safe: index] ?? WalletCollectionViewCell.Model.default
1103+
return walletsViewModel.state.wallets[safe: index] ?? AccountWalletCellState.default
11301104
}
11311105
}
11321106

@@ -1155,9 +1129,9 @@ extension AccountViewController: PagingViewControllerDataSource, PagingViewContr
11551129
didSelectItem pagingItem: PagingItem
11561130
) {
11571131
Task { @MainActor in
1158-
currentWalletCoinID = walletsViewModel.state.wallets.first(where: { wallet in
1159-
wallet.index == pagingItem.identifier
1160-
})?.coinID ?? ""
1132+
currentSelectedWallet = walletsViewModel.state.wallets.first(where: { wallet in
1133+
wallet.model.index == pagingItem.identifier
1134+
})
11611135
}
11621136
}
11631137

Adamant/Modules/Account/AccountViewController/AccountWallets/AccountWalletsState.swift

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,41 @@
66
// Copyright © 2025 Adamant. All rights reserved.
77
//
88

9-
struct AccountWalletsState: Equatable {
10-
var wallets: [WalletCollectionViewCell.Model]
9+
import CommonKit
10+
import Parchment
1111

12+
struct AccountWalletsState {
13+
var wallets: [AccountWalletCellState]
14+
1215
static let `default` = Self(wallets: [])
1316
}
17+
18+
struct AccountWalletCellState {
19+
@ObservableValue var model: WalletCollectionViewCellModel
20+
21+
init(model: WalletCollectionViewCellModel) {
22+
self.model = model
23+
}
24+
25+
static let `default` = Self(model: .default)
26+
}
27+
28+
extension AccountWalletCellState: Equatable {
29+
static func == (lhs: AccountWalletCellState, rhs: AccountWalletCellState) -> Bool {
30+
lhs.model == rhs.model
31+
}
32+
}
33+
34+
extension AccountWalletCellState: PagingItem{
35+
var identifier: Int { model.index }
36+
37+
func isBefore(item: PagingItem) -> Bool {
38+
guard let other = item as? Self else { return false }
39+
return self.model.index < other.model.index
40+
}
41+
42+
func isEqual(to item: PagingItem) -> Bool {
43+
guard let other = item as? Self else { return false }
44+
return self == other
45+
}
46+
}

Adamant/Modules/Account/AccountViewController/AccountWallets/AccountWalletsViewModel.swift

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ import Foundation
1212

1313
@MainActor
1414
final class AccountWalletsViewModel {
15-
@ObservableValue var state: AccountWalletsState = .default
16-
15+
var state: AccountWalletsState = .default
16+
1717
private let walletsStoreService: WalletStoreServiceProviderProtocol
1818
private var walletSubscriptions: Set<AnyCancellable> = []
1919
private var currentWalletPublisherSubscription: Set<AnyCancellable> = []
@@ -54,25 +54,29 @@ extension AccountWalletsViewModel {
5454

5555
func updateInfo(for wallet: WalletService) {
5656
let coreService = wallet.core
57-
if let index = state.wallets.firstIndex(where: { $0.coinID == coreService.tokenUniqueID }) {
58-
state.wallets[index].balance = coreService.wallet?.balance ?? 0
59-
state.wallets[index].isBalanceInitialized = coreService.wallet?.isBalanceInitialized ?? false
60-
state.wallets[index].notificationBadgeCount = coreService.wallet?.notifications ?? 0
57+
let tokenID = coreService.tokenUniqueID
58+
if let index = state.wallets.firstIndex(where: { $0.model.coinID == tokenID }) {
59+
let cellState = state.wallets[index]
60+
var currentModel = cellState.model
61+
currentModel.balance = coreService.wallet?.balance ?? 0
62+
currentModel.isBalanceInitialized = coreService.wallet?.isBalanceInitialized ?? false
63+
currentModel.notificationBadgeCount = coreService.wallet?.notifications ?? 0
64+
cellState.model = currentModel
65+
state.wallets[index] = cellState
6166
} else {
6267
let network = type(of: coreService).tokenNetworkSymbol
63-
64-
let model = WalletCollectionViewCell.Model(
68+
let newModel = WalletCollectionViewCellModel(
6569
index: state.wallets.count,
66-
coinID: coreService.tokenUniqueID,
70+
coinID: tokenID,
6771
currencySymbol: coreService.tokenSymbol,
6872
currencyImage: coreService.tokenLogo,
6973
currencyNetwork: network,
7074
isBalanceInitialized: coreService.wallet?.isBalanceInitialized ?? false,
7175
balance: coreService.wallet?.balance ?? 0,
7276
notificationBadgeCount: coreService.wallet?.notifications ?? 0
7377
)
74-
75-
state.wallets.append(model)
78+
let cellState = AccountWalletCellState(model: newModel)
79+
state.wallets.append(cellState)
7680
}
7781
}
7882
}

0 commit comments

Comments
 (0)