Skip to content

Commit cf1d547

Browse files
committed
[trello.com/c/R42vd9hV] interim update
1 parent 404a2ab commit cf1d547

File tree

10 files changed

+145
-119
lines changed

10 files changed

+145
-119
lines changed

Adamant.xcodeproj/project.pbxproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1767,8 +1767,8 @@
17671767
6F1B8E7C2D4575B0004E902F /* AdmDialogService */ = {
17681768
isa = PBXGroup;
17691769
children = (
1770-
6F1B8E7D2D4575E0004E902F /* AdmDialogServiceExtension.swift */,
17711770
E9E7CD8E20026CD300DFC4DB /* AdamantDialogService.swift */,
1771+
6F1B8E7D2D4575E0004E902F /* AdmDialogServiceExtension.swift */,
17721772
);
17731773
path = AdmDialogService;
17741774
sourceTree = "<group>";

Adamant/Modules/AlertsFactory/AlertFactory.swift

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -9,42 +9,42 @@ import UIKit
99
import CommonKit
1010
import SafariServices
1111

12-
enum AlertFactory {
13-
@MainActor
14-
static func makeRenameAlert(
15-
titleFormat: String,
16-
placeholder: String,
17-
initialText: String?,
18-
onRename: @escaping (String) -> Void
19-
) -> UIAlertController {
20-
let alert = UIAlertController(
21-
title: titleFormat,
22-
message: nil,
23-
preferredStyle: .alert
24-
)
25-
alert.addTextField { textField in
26-
textField.placeholder = placeholder
27-
textField.autocapitalizationType = .words
28-
textField.text = initialText
29-
}
30-
31-
let renameAction = UIAlertAction(
32-
title: "Rename",
33-
style: .default
34-
) { _ in
35-
guard
36-
let textField = alert.textFields?.first,
37-
let newName = textField.text,
38-
!newName.isEmpty
39-
else { return }
40-
41-
onRename(newName)
42-
AlertPresenter.freeTokenAlertIfNeed()
43-
}
44-
45-
alert.addAction(renameAction)
46-
alert.addAction(UIAlertAction(title: "Cancel", style: .cancel))
47-
alert.modalPresentationStyle = .overFullScreen
48-
return alert
49-
}
50-
}
12+
//enum AlertFactory {
13+
// @MainActor
14+
// static func makeRenameAlert(
15+
// titleFormat: String,
16+
// placeholder: String,
17+
// initialText: String?,
18+
// onRename: @escaping (String) -> Void
19+
// ) -> UIAlertController {
20+
// let alert = UIAlertController(
21+
// title: titleFormat,
22+
// message: nil,
23+
// preferredStyle: .alert
24+
// )
25+
// alert.addTextField { textField in
26+
// textField.placeholder = placeholder
27+
// textField.autocapitalizationType = .words
28+
// textField.text = initialText
29+
// }
30+
//
31+
// let renameAction = UIAlertAction(
32+
// title: "Rename",
33+
// style: .default
34+
// ) { _ in
35+
// guard
36+
// let textField = alert.textFields?.first,
37+
// let newName = textField.text,
38+
// !newName.isEmpty
39+
// else { return }
40+
//
41+
// onRename(newName)
42+
// AlertPresenter.freeTokenAlertIfNeed()
43+
// }
44+
//
45+
// alert.addAction(renameAction)
46+
// alert.addAction(UIAlertAction(title: "Cancel", style: .cancel))
47+
// alert.modalPresentationStyle = .overFullScreen
48+
// return alert
49+
// }
50+
//}

Adamant/Modules/Chat/ChatFactory.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ struct ChatFactory {
6464
let dialogManager = ChatDialogManager(
6565
viewModel: viewModel,
6666
dialogService: dialogService,
67-
emojiService: emojiService
67+
emojiService: emojiService,
68+
accountService: accountService
6869
)
6970

7071
let wallets = walletServiceCompose.getWallets()
@@ -83,9 +84,9 @@ struct ChatFactory {
8384
sendTransaction: makeSendTransactionAction(
8485
viewModel: viewModel,
8586
screensFactory: screensFactory
86-
)
87+
),
88+
dialogManager: dialogManager
8789
)
88-
8990
viewController.setupDelegates(delegates)
9091
delegates.cell.setupDelegate(
9192
collection: viewController.messagesCollectionView,

Adamant/Modules/Chat/View/ChatViewController.swift

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ final class ChatViewController: MessagesViewController {
3232
private let admWalletService: WalletService?
3333
private let screensFactory: ScreensFactory
3434
private let chatSwipeManager: ChatSwipeManager
35-
35+
private let dialogManager: ChatDialogManager
3636
let viewModel: ChatViewModel
3737

3838
// MARK: Properties
@@ -92,7 +92,8 @@ final class ChatViewController: MessagesViewController {
9292
admWalletService: WalletService?,
9393
screensFactory: ScreensFactory,
9494
chatSwipeManager: ChatSwipeManager,
95-
sendTransaction: @escaping SendTransaction
95+
sendTransaction: @escaping SendTransaction,
96+
dialogManager: ChatDialogManager
9697
) {
9798
self.viewModel = viewModel
9899
self.storedObjects = storedObjects
@@ -101,6 +102,7 @@ final class ChatViewController: MessagesViewController {
101102
self.screensFactory = screensFactory
102103
self.sendTransaction = sendTransaction
103104
self.chatSwipeManager = chatSwipeManager
105+
self.dialogManager = dialogManager
104106
super.init(nibName: nil, bundle: nil)
105107

106108
inputBar.onAttachmentButtonTap = { [weak self] in
@@ -476,6 +478,11 @@ private extension ChatViewController {
476478
self?.didTapSelectText(text: text)
477479
}
478480
.store(in: &subscriptions)
481+
dialogManager.showBuyAndSellSubject
482+
.sink { [weak self] in
483+
self?.presentBuyAndSell()
484+
}
485+
.store(in: &subscriptions)
479486
}
480487
}
481488

@@ -1097,7 +1104,12 @@ extension ChatViewController {
10971104
viewModel.needToAnimateCellIndex = nil
10981105
}
10991106
}
1100-
1107+
extension ChatViewController {
1108+
func presentBuyAndSell() {
1109+
let buyAndSellVC = screensFactory.makeBuyAndSell()
1110+
navigationController?.pushViewController(buyAndSellVC, animated: true)
1111+
}
1112+
}
11011113
private let scrollDownButtonInset: CGFloat = 20
11021114
private let messagePadding: CGFloat = 12
11031115
private let filesToolbarViewHeight: CGFloat = 140

Adamant/Modules/Chat/View/Managers/ChatDialogManager.swift

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,26 @@ final class ChatDialogManager {
1919
private let viewModel: ChatViewModel
2020
private let dialogService: DialogService
2121
private let emojiService: EmojiService?
22+
private let accountService: AccountService
2223

2324
private var subscription: AnyCancellable?
2425
private lazy var contextMenu = AdvancedContextMenuManager()
2526

2627
typealias DidSelectEmojiAction = ((_ emoji: String, _ messageId: String) -> Void)?
2728
typealias ContextMenuAction = ((_ messageId: String) -> Void)?
2829

30+
let showBuyAndSellSubject = PassthroughSubject<Void, Never>()
31+
2932
init(
3033
viewModel: ChatViewModel,
3134
dialogService: DialogService,
32-
emojiService: EmojiService
35+
emojiService: EmojiService,
36+
accountService: AccountService
3337
) {
3438
self.viewModel = viewModel
3539
self.dialogService = dialogService
3640
self.emojiService = emojiService
41+
self.accountService = accountService
3742
subscription = viewModel.dialog.sink { [weak self] in self?.showDialog($0) }
3843
}
3944
}
@@ -243,18 +248,24 @@ private extension ChatDialogManager {
243248
func showRenameAlert() {
244249
guard let address = address else { return }
245250

246-
let alert = AlertFactory.makeRenameAlert(
247-
titleFormat: String(format: .adamant.chat.actionsBody, address),
248-
placeholder: .adamant.chat.name,
249-
initialText: viewModel.partnerName
250-
) { [weak viewModel] newName in
251-
viewModel?.setNewName(newName)
252-
}
251+
let alert = dialogService.makeRenameAlert(
252+
titleFormat:String(format: .adamant.chat.actionsBody, address),
253+
initialText: viewModel.partnerName,
254+
needToPresent: accountService.account?.isEnoughMoneyForTransaction,
255+
url: accountService.account?.address,
256+
showVC: { [weak self] in
257+
self?.showBuyAndSellSubject.send()
258+
},
259+
onRename: handleRename(newName:)
260+
)
253261

254262
dialogService.present(alert, animated: true) { [weak self] in
255263
self?.dialogService.selectAllTextFields(in: alert)
256264
}
257265
}
266+
private func handleRename(newName: String) {
267+
viewModel.setNewName(newName)
268+
}
258269
}
259270

260271
// MARK: Alert actions
@@ -329,19 +340,6 @@ private extension ChatDialogManager {
329340
}
330341
}
331342

332-
// func makeFreeTokensAlertAction() -> UIAlertAction {
333-
// .init(
334-
// title: String.adamant.chat.freeTokens,
335-
// style: .default
336-
// ) { [weak self] _ in
337-
// guard let self = self, let url = self.viewModel.freeTokensURL else { return }
338-
// let safari = SFSafariViewController(url: url)
339-
// safari.preferredControlTintColor = UIColor.adamant.primary
340-
// safari.modalPresentationStyle = .overFullScreen
341-
// self.dialogService.present(safari, animated: true, completion: nil)
342-
// }
343-
// }
344-
345343
func showAdmMenuAction(_ adm: AdamantAddress, partnerAddress: String) {
346344
let shareTypes: [AddressChatShareType] = adm.address == partnerAddress ? [.send] : [.chat, .send]
347345
let name = adm.name ?? adm.address

Adamant/Modules/ChatsList/ChatListViewController.swift

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1296,10 +1296,14 @@ extension ChatListViewController {
12961296
) { [weak self] _ in
12971297
guard let self = self else { return }
12981298

1299-
let alert = AlertFactory.makeRenameAlert(
1299+
let alert = dialogService.makeRenameAlert(
13001300
titleFormat: String(format: .adamant.chat.actionsBody, address),
1301-
placeholder: .adamant.chat.name,
1302-
initialText: self.addressBook.getName(for: address)
1301+
initialText: self.addressBook.getName(for: address),
1302+
needToPresent: accountService.account?.isEnoughMoneyForTransaction,
1303+
url: accountService.account?.address,
1304+
showVC: { [weak self] in
1305+
self?.presentBuyAndSell()
1306+
}
13031307
) { newName in
13041308
Task {
13051309
await self.addressBook.set(name: newName, for: address)
@@ -1513,3 +1517,9 @@ private extension StateEnum {
15131517
}
15141518
}
15151519
}
1520+
private extension ChatListViewController {
1521+
func presentBuyAndSell() {
1522+
let buyAndSellVC = screensFactory.makeBuyAndSell()
1523+
navigationController?.pushViewController(buyAndSellVC, animated: true)
1524+
}
1525+
}

Adamant/Modules/PartnerQR/PartnerQRFactory.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,12 @@ import CommonKit
1414
struct PartnerQRFactory {
1515
private let parent: Assembler
1616
private let assemblies = [PartnerQRAssembly()]
17-
1817
init(parent: Assembler) {
1918
self.parent = parent
2019
}
2120

2221
@MainActor
23-
func makeViewController(partner: CoreDataAccount) -> UIViewController {
22+
func makeViewController(partner: CoreDataAccount, screenFactory: ScreensFactory) -> UIViewController {
2423
let assembler = Assembler(assemblies, parent: parent)
2524

2625
let viewModel = {
@@ -29,7 +28,7 @@ struct PartnerQRFactory {
2928
return viewModel
3029
}
3130

32-
return UIHostingController(rootView: PartnerQRView(viewModel: viewModel, screenFactory: AdamantScreensFactory(assembler: parent)))
31+
return UIHostingController(rootView: PartnerQRView(viewModel: viewModel, screenFactory: screenFactory))
3332
}
3433
}
3534

Adamant/Modules/ScreensFactory/AdamantScreensFactory.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ struct AdamantScreensFactory: ScreensFactory {
9595
}
9696

9797
func makeBuyAndSell() -> UIViewController {
98-
admWalletFactory.makeBuyAndSellVC()
98+
admWalletFactory.makeBuyAndSellVC(screenFactory: self)
9999
}
100100

101101
func makeChatList() -> UIViewController {
@@ -195,7 +195,7 @@ struct AdamantScreensFactory: ScreensFactory {
195195
}
196196

197197
func makePartnerQR(partner: CoreDataAccount) -> UIViewController {
198-
partnerQRFactory.makeViewController(partner: partner)
198+
partnerQRFactory.makeViewController(partner: partner, screenFactory: self)
199199
}
200200

201201
func makeCoinsNodesList(context: CoinsNodesListContext) -> UIViewController {

Adamant/Modules/Wallets/Adamant/AdmWalletFactory.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,11 @@ struct AdmWalletFactory: WalletFactory {
7676
return controller
7777
}
7878

79-
func makeBuyAndSellVC() -> UIViewController {
79+
func makeBuyAndSellVC(screenFactory: ScreensFactory) -> UIViewController {
8080
let c = BuyAndSellViewController()
8181
c.accountService = assembler.resolve(AccountService.self)
8282
c.dialogService = assembler.resolve(DialogService.self)
83+
c.screenFactory = screenFactory
8384
return c
8485
}
8586
}

0 commit comments

Comments
 (0)