Skip to content

Commit

Permalink
[trello.com/c/b82n6AMp] adding cost when sending media/files
Browse files Browse the repository at this point in the history
  • Loading branch information
leonid174 committed Jan 10, 2025
1 parent 57d16ac commit 45d4b28
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 31 deletions.
9 changes: 9 additions & 0 deletions Adamant.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3070,6 +3070,7 @@
938F7D562955C1DA001915CA /* XCRemoteSwiftPackageReference "MessageKit" */,
4184F16F2A33044E00D7B8B9 /* XCRemoteSwiftPackageReference "firebase-ios-sdk" */,
3AC76E3B2AB09118008042C4 /* XCRemoteSwiftPackageReference "Elegant-Emoji-Picker" */,
84B761662D2E79A50022DCA9 /* XCRemoteSwiftPackageReference "PopupKit" */,
);
productRefGroup = E913C8EF1FFFA51D001A83F7 /* Products */;
projectDirPath = "";
Expand Down Expand Up @@ -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";
Expand Down
32 changes: 16 additions & 16 deletions Adamant.xcworkspace/xcshareddata/swiftpm/Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -105,17 +105,17 @@
"repositoryURL": "https://github.com/google/GoogleDataTransport.git",
"state": {
"branch": null,
"revision": "aae45a320fd0d11811820335b1eabc8753902a40",
"version": "9.2.5"
"revision": "a637d318ae7ae246b02d7305121275bc75ed5565",
"version": "9.4.0"
}
},
{
"package": "GoogleUtilities",
"repositoryURL": "https://github.com/google/GoogleUtilities.git",
"state": {
"branch": null,
"revision": "bc27fad73504f3d4af235de451f02ee22586ebd3",
"version": "7.12.1"
"revision": "57a1d307f42df690fdef2637f3e5b776da02aad6",
"version": "7.13.3"
}
},
{
Expand All @@ -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"
}
},
{
Expand All @@ -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"
}
},
{
Expand All @@ -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"
}
},
{
Expand All @@ -204,7 +204,7 @@
"repositoryURL": "https://github.com/rechsteiner/Parchment",
"state": {
"branch": "main",
"revision": "13aad3e9308e8a4e38cb579430dbf66465418777",
"revision": "dfb23ea5118ca8bfbc578065627fccf4ec4a362e",
"version": null
}
},
Expand All @@ -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"
}
},
{
Expand Down Expand Up @@ -276,7 +276,7 @@
"repositoryURL": "https://github.com/socketio/socket.io-client-swift",
"state": {
"branch": "master",
"revision": "175da8b5156f6b132436f0676cc84c2f6a766b6e",
"revision": "42da871d9369f290d6ec4930636c40672143905b",
"version": null
}
},
Expand All @@ -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"
}
},
{
Expand Down
1 change: 1 addition & 0 deletions Adamant/Modules/Chat/View/ChatViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -943,6 +943,7 @@ private extension ChatViewController {
func closeFileToolbarView() {
filesToolbarView.removeFromSuperview()
messageInputBar.invalidateIntrinsicContentSize()
viewModel.inputTextFileUpdated()
}

func didTapTransfer(id: String) {
Expand Down
42 changes: 27 additions & 15 deletions Adamant/Modules/Chat/ViewModel/ChatViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -938,6 +938,9 @@ final class ChatViewModel: NSObject {
}

filesPicked = oldFiles

inputTextFileUpdated()

case .failure(let error):
dialog.send(.alert(error.localizedDescription))
}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
17 changes: 17 additions & 0 deletions CommonKit/Sources/CommonKit/AdamantSecret.swift
Original file line number Diff line number Diff line change
@@ -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"
}

0 comments on commit 45d4b28

Please sign in to comment.