Skip to content

Commit c920615

Browse files
committed
Merge branch 'develop' into feature/Localization
# Conflicts: # Adamant/Stories/Chats/ChatViewController.swift
2 parents 805d3a1 + e5fa92a commit c920615

File tree

8 files changed

+40
-18
lines changed

8 files changed

+40
-18
lines changed

Adamant/Info.plist

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
<key>CFBundlePackageType</key>
1818
<string>APPL</string>
1919
<key>CFBundleShortVersionString</key>
20-
<string>0.1.4</string>
20+
<string>0.1.5</string>
2121
<key>CFBundleVersion</key>
22-
<string>5</string>
22+
<string>6</string>
2323
<key>LSRequiresIPhoneOS</key>
2424
<true/>
2525
<key>UIAppFonts</key>

Adamant/Models/ChatType.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88

99
import Foundation
1010

11+
/// - messageExpensive: Old message type, with 0.005 transaction fee
12+
/// - message: new and main message type, with 0.001 transaction fee
1113
enum ChatType: Int, Codable {
12-
case message = 0
14+
case messageOld = 0
15+
case message = 1
1316
}

Adamant/ServiceProtocols/DataProviders/ChatsProvider.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ enum ChatsProviderResult {
1717
enum ChatsProviderError: Error {
1818
case notLogged
1919
case messageNotValid(ValidateMessageResult)
20+
case notEnoughtMoneyToSend
2021
case serverError(Error)
2122
case accountNotFound(String)
2223
case dependencyError(String)

Adamant/ServiceProtocols/FeeCalculator.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@
99
import Foundation
1010

1111
protocol FeeCalculator {
12-
func estimatedFeeFor(message: String) -> UInt
12+
func estimatedFeeFor(message: AdamantMessage) -> UInt
1313
func estimatedFeeFor(transfer: UInt) -> UInt
1414
}

Adamant/Services/ApiService/AdamantApi+Chats.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ extension AdamantApiService.ApiCommands {
2020
extension AdamantApiService {
2121
func getChatTransactions(account: String, height: Int?, offset: Int?, completion: @escaping (ApiServiceResult<[Transaction]>) -> Void) {
2222
// MARK: 1. Prepare params
23-
var queryItems: [URLQueryItem] = [URLQueryItem(name: "isIn", value: account)]
23+
var queryItems: [URLQueryItem] = [URLQueryItem(name: "isIn", value: account),
24+
URLQueryItem(name: "orderBy", value: "timestamp:desc")]
2425
if let height = height, height > 0 { queryItems.append(URLQueryItem(name: "fromHeight", value: String(height))) }
2526
if let offset = offset { queryItems.append(URLQueryItem(name: "offset", value: String(offset))) }
2627

Adamant/Services/DataProviders/AdamantChatsProvider.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class AdamantChatsProvider: ChatsProvider {
1616
var stack: CoreDataStack!
1717
var adamantCore: AdamantCore!
1818
var accountsProvider: AccountsProvider!
19+
var feeCalculator: FeeCalculator!
1920

2021
// MARK: Properties
2122
private(set) var state: State = .empty
@@ -154,6 +155,11 @@ extension AdamantChatsProvider {
154155
return
155156
}
156157

158+
guard loggedAccount.balance >= feeCalculator.estimatedFeeFor(message: message) else {
159+
completion(.error(.notEnoughtMoneyToSend))
160+
return
161+
}
162+
157163
switch validateMessage(message) {
158164
case .isValid:
159165
break

Adamant/Services/HardFeeCalculator.swift

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@
99
import Foundation
1010

1111
class HardFeeCalculator: FeeCalculator {
12-
func estimatedFeeFor(message: String) -> UInt {
13-
return AdamantUtilities.from(double: ceil(Double(message.count) / 255.0) * 0.005)
12+
func estimatedFeeFor(message: AdamantMessage) -> UInt {
13+
switch message {
14+
case .text(let text):
15+
return AdamantUtilities.from(double: ceil(Double(text.count) / 255.0) * 0.001)
16+
}
1417
}
1518

1619
func estimatedFeeFor(transfer: UInt) -> UInt {
1720
return AdamantUtilities.from(double: 0.5)
1821
}
19-
20-
2122
}

Adamant/Stories/Chats/ChatViewController.swift

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@ import CoreData
1313
// MARK: - Localization
1414
extension String.adamantLocalized {
1515
struct chat {
16-
static let estimatedFeeFormat = NSLocalizedString("chat.estimatedFee", comment: "Estimated fee: %f")
16+
static let estimatedFeeFormat = NSLocalizedString("chat.estimated-fee", comment: "Estimated fee: %f")
1717

1818
static let messageIsEmpty = NSLocalizedString("chat.message-is-empty", comment: "Notify user that message cannot be empty")
19-
static let messageTooLong = NSLocalizedString("chat.message-too-long", comment: "Message is too long alert")
19+
static let messageTooLong = NSLocalizedString("chat.message-too-long", comment: "Message is too long")
20+
static let notEnoughMoney = NSLocalizedString("chat.not-enough", comment: "You don't have enough money to send a message.")
2021

2122
static let internalErrorFormat = NSLocalizedString("chat.internal-error-format", comment: "Internal error: %@")
2223
static let serverErrorFormat = NSLocalizedString("chat.server-error-format", comment: "Remote server error: %@")
@@ -137,7 +138,7 @@ class ChatViewController: MessagesViewController {
137138

138139
if let delegate = delegate, let address = chatroom.partner?.address, let message = delegate.getPreservedMessageFor(address: address, thenRemoveIt: true) {
139140
messageInputBar.inputTextView.text = message
140-
setEstimatedFee(feeCalculator.estimatedFeeFor(message: message))
141+
setEstimatedFee(feeCalculator.estimatedFeeFor(message: AdamantMessage.text(message)))
141142
}
142143
}
143144

@@ -359,11 +360,20 @@ extension ChatViewController: MessageInputBarDelegate {
359360
case .error(let error):
360361
let message: String
361362
switch error {
362-
case .accountNotFound(let account): message = String.localizedStringWithFormat(String.adamantLocalized.chat.internalErrorFormat, "Account not found: \(account)")
363-
case .dependencyError(let error): message = String.localizedStringWithFormat(String.adamantLocalized.chat.internalErrorFormat, error)
364-
case .internalError(let error): message = String.localizedStringWithFormat(String.adamantLocalized.chat.internalErrorFormat, String(describing: error))
365-
case .notLogged: message = String.localizedStringWithFormat(String.adamantLocalized.chat.internalErrorFormat, "User not logged")
366-
case .serverError(let error): message = String.localizedStringWithFormat(String.adamantLocalized.chat.serverErrorFormat, String(describing: error))
363+
case .accountNotFound(let account):
364+
message = String.localizedStringWithFormat(String.adamantLocalized.chat.internalErrorFormat, "Account not found: \(account)")
365+
case .dependencyError(let error):
366+
message = String.localizedStringWithFormat(String.adamantLocalized.chat.internalErrorFormat, error)
367+
case .internalError(let error):
368+
message = String.localizedStringWithFormat(String.adamantLocalized.chat.internalErrorFormat, String(describing: error))
369+
case .notLogged:
370+
message = String.localizedStringWithFormat(String.adamantLocalized.chat.internalErrorFormat, "User not logged")
371+
case .serverError(let error):
372+
message = String.localizedStringWithFormat(String.adamantLocalized.chat.serverErrorFormat, String(describing: error))
373+
374+
case .notEnoughtMoneyToSend:
375+
message = String.adamantLocalized.chat.notEnoughMoney
376+
367377
case .messageNotValid(let problem):
368378
switch problem {
369379
case .tooLong:
@@ -388,7 +398,7 @@ extension ChatViewController: MessageInputBarDelegate {
388398

389399
func messageInputBar(_ inputBar: MessageInputBar, textViewTextDidChangeTo text: String) {
390400
if text.count > 0 {
391-
let fee = feeCalculator.estimatedFeeFor(message: text)
401+
let fee = feeCalculator.estimatedFeeFor(message: .text(text))
392402
setEstimatedFee(fee)
393403
} else {
394404
setEstimatedFee(0)

0 commit comments

Comments
 (0)