From 45d4b28fe6e9bed21e730a36b1e6c56c2828dfec Mon Sep 17 00:00:00 2001 From: Leonid Vilner Date: Fri, 10 Jan 2025 22:35:16 +0800 Subject: [PATCH] [trello.com/c/b82n6AMp] adding cost when sending media/files --- Adamant.xcodeproj/project.pbxproj | 9 ++++ .../xcshareddata/swiftpm/Package.resolved | 32 +++++++------- .../Chat/View/ChatViewController.swift | 1 + .../Chat/ViewModel/ChatViewModel.swift | 42 ++++++++++++------- .../Sources/CommonKit/AdamantSecret.swift | 17 ++++++++ 5 files changed, 70 insertions(+), 31 deletions(-) create mode 100644 CommonKit/Sources/CommonKit/AdamantSecret.swift diff --git a/Adamant.xcodeproj/project.pbxproj b/Adamant.xcodeproj/project.pbxproj index 19cfcd91d..65627120a 100644 --- a/Adamant.xcodeproj/project.pbxproj +++ b/Adamant.xcodeproj/project.pbxproj @@ -3070,6 +3070,7 @@ 938F7D562955C1DA001915CA /* XCRemoteSwiftPackageReference "MessageKit" */, 4184F16F2A33044E00D7B8B9 /* XCRemoteSwiftPackageReference "firebase-ios-sdk" */, 3AC76E3B2AB09118008042C4 /* XCRemoteSwiftPackageReference "Elegant-Emoji-Picker" */, + 84B761662D2E79A50022DCA9 /* XCRemoteSwiftPackageReference "PopupKit" */, ); productRefGroup = E913C8EF1FFFA51D001A83F7 /* Products */; projectDirPath = ""; @@ -4422,6 +4423,14 @@ minimumVersion = 5.0.0; }; }; + 84B761662D2E79A50022DCA9 /* XCRemoteSwiftPackageReference "PopupKit" */ = { + isa = XCRemoteSwiftPackageReference; + repositoryURL = "https://github.com/Pointwelve/PopupKit"; + requirement = { + kind = upToNextMajorVersion; + minimumVersion = 3.1.1; + }; + }; 938F7D562955C1DA001915CA /* XCRemoteSwiftPackageReference "MessageKit" */ = { isa = XCRemoteSwiftPackageReference; repositoryURL = "https://github.com/MessageKit/MessageKit.git"; diff --git a/Adamant.xcworkspace/xcshareddata/swiftpm/Package.resolved b/Adamant.xcworkspace/xcshareddata/swiftpm/Package.resolved index 5828488fd..ff7b1d3e3 100644 --- a/Adamant.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/Adamant.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -105,8 +105,8 @@ "repositoryURL": "https://github.com/google/GoogleDataTransport.git", "state": { "branch": null, - "revision": "aae45a320fd0d11811820335b1eabc8753902a40", - "version": "9.2.5" + "revision": "a637d318ae7ae246b02d7305121275bc75ed5565", + "version": "9.4.0" } }, { @@ -114,8 +114,8 @@ "repositoryURL": "https://github.com/google/GoogleUtilities.git", "state": { "branch": null, - "revision": "bc27fad73504f3d4af235de451f02ee22586ebd3", - "version": "7.12.1" + "revision": "57a1d307f42df690fdef2637f3e5b776da02aad6", + "version": "7.13.3" } }, { @@ -141,8 +141,8 @@ "repositoryURL": "https://github.com/nathantannar4/InputBarAccessoryView", "state": { "branch": null, - "revision": "17ced92a5dccb36512b408b6276353631d7cbe57", - "version": "6.3.0" + "revision": "c7acd5fa32e54cd7a44ad7eb9a7730da35b54c95", + "version": "6.5.1" } }, { @@ -159,8 +159,8 @@ "repositoryURL": "https://github.com/firebase/leveldb.git", "state": { "branch": null, - "revision": "9d108e9112aa1d65ce508facf804674546116d9c", - "version": "1.22.3" + "revision": "a0bc79961d7be727d258d33d5a6b2f1023270ba1", + "version": "1.22.5" } }, { @@ -177,8 +177,8 @@ "repositoryURL": "https://github.com/MessageKit/MessageKit.git", "state": { "branch": null, - "revision": "1993e8e90d4e9a61b8d9bc8ceb733964ce943376", - "version": "4.2.0" + "revision": "b024c1287ac30fb6ea2ee07169e6193efc11d972", + "version": "4.3.0" } }, { @@ -204,7 +204,7 @@ "repositoryURL": "https://github.com/rechsteiner/Parchment", "state": { "branch": "main", - "revision": "13aad3e9308e8a4e38cb579430dbf66465418777", + "revision": "dfb23ea5118ca8bfbc578065627fccf4ec4a362e", "version": null } }, @@ -222,8 +222,8 @@ "repositoryURL": "https://github.com/google/promises.git", "state": { "branch": null, - "revision": "e70e889c0196c76d22759eb50d6a0270ca9f1d9e", - "version": "2.3.1" + "revision": "540318ecedd63d883069ae7f1ed811a2df00b6ac", + "version": "2.4.0" } }, { @@ -276,7 +276,7 @@ "repositoryURL": "https://github.com/socketio/socket.io-client-swift", "state": { "branch": "master", - "revision": "175da8b5156f6b132436f0676cc84c2f6a766b6e", + "revision": "42da871d9369f290d6ec4930636c40672143905b", "version": null } }, @@ -285,8 +285,8 @@ "repositoryURL": "https://github.com/daltoniam/Starscream", "state": { "branch": null, - "revision": "ac6c0fc9da221873e01bd1a0d4818498a71eef33", - "version": "4.0.6" + "revision": "c6bfd1af48efcc9a9ad203665db12375ba6b145a", + "version": "4.0.8" } }, { diff --git a/Adamant/Modules/Chat/View/ChatViewController.swift b/Adamant/Modules/Chat/View/ChatViewController.swift index b309fc4d0..d519625a5 100644 --- a/Adamant/Modules/Chat/View/ChatViewController.swift +++ b/Adamant/Modules/Chat/View/ChatViewController.swift @@ -943,6 +943,7 @@ private extension ChatViewController { func closeFileToolbarView() { filesToolbarView.removeFromSuperview() messageInputBar.invalidateIntrinsicContentSize() + viewModel.inputTextFileUpdated() } func didTapTransfer(id: String) { diff --git a/Adamant/Modules/Chat/ViewModel/ChatViewModel.swift b/Adamant/Modules/Chat/ViewModel/ChatViewModel.swift index 202505026..ddbfce93b 100644 --- a/Adamant/Modules/Chat/ViewModel/ChatViewModel.swift +++ b/Adamant/Modules/Chat/ViewModel/ChatViewModel.swift @@ -938,6 +938,9 @@ final class ChatViewModel: NSObject { } filesPicked = oldFiles + + inputTextFileUpdated() + case .failure(let error): dialog.send(.alert(error.localizedDescription)) } @@ -1060,6 +1063,29 @@ extension ChatViewModel { self?.dateHeaderHidden = true } } + + func inputTextFileUpdated() { + + guard !inputText.isEmpty || filesPicked != nil else { + fee = "" + return + } + + var filesText: String = "" + + if let filesPicked { + filesText = filesPicked.map{ + ($0.name ?? "") + ($0.extenstion ?? "") + }.joined(separator: "") + } + + let feeString = AdamantBalanceFormat.full.format( + AdamantMessage.text(inputText + filesText).fee, + withCurrencySymbol: AdmWalletService.currencySymbol + ) + + fee = "~\(feeString)" + } } extension ChatViewModel: NSFetchedResultsControllerDelegate { @@ -1095,7 +1121,7 @@ private extension ChatViewModel { func setupObservers() { $inputText .removeDuplicates() - .sink { [weak self] _ in self?.inputTextUpdated() } + .sink { [weak self] _ in self?.inputTextFileUpdated() } .store(in: &subscriptions) chatFileService.updateFileFields @@ -1429,20 +1455,6 @@ private extension ChatViewModel { } } - func inputTextUpdated() { - guard !inputText.isEmpty else { - fee = "" - return - } - - let feeString = AdamantBalanceFormat.full.format( - AdamantMessage.text(inputText).fee, - withCurrencySymbol: AdmWalletService.currencySymbol - ) - - fee = "~\(feeString)" - } - func updatePartnerInformation() { guard let publicKey = chatroom?.partner?.publicKey else { return diff --git a/CommonKit/Sources/CommonKit/AdamantSecret.swift b/CommonKit/Sources/CommonKit/AdamantSecret.swift new file mode 100644 index 000000000..ef810ecb2 --- /dev/null +++ b/CommonKit/Sources/CommonKit/AdamantSecret.swift @@ -0,0 +1,17 @@ +// +// File.swift +// CommonKit +// +// Created by Leonid Vilner on 08.01.2025. +// + +import Foundation + +enum AdamantSecret { + // MARK: App data + static let appIdentifierPrefix = "J2L77FMN46" + + // MARK: Keychain + static let oldKeychainPass = "tertherherh" + static let keychainValuePassword = "wergwergwerg" +}