Skip to content

Commit 9edfd96

Browse files
committed
Merge branch 'release/0.1.5'
2 parents 3316dd7 + f8a0da1 commit 9edfd96

37 files changed

+689
-387
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"images" : [
3+
{
4+
"idiom" : "universal",
5+
"filename" : "avatar_bots.png",
6+
"scale" : "1x"
7+
},
8+
{
9+
"idiom" : "universal",
10+
"scale" : "2x"
11+
},
12+
{
13+
"idiom" : "universal",
14+
"scale" : "3x"
15+
}
16+
],
17+
"info" : {
18+
"version" : 1,
19+
"author" : "xcode"
20+
}
21+
}
Loading

Adamant/Assets/knownContacts.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
{
33
"address": "U15423595369615486571",
44
"name": "ADAMANT Bounty Wallet",
5+
"avatar": "avatar_bots",
56
"messages": [
67
{
78
"key": "chats.welcome_message",
@@ -12,6 +13,7 @@
1213
{
1314
"address": "U7047165086065693428",
1415
"name": "ADAMANT ICO",
16+
"avatar": "avatar_bots",
1517
"messages": [
1618
{
1719
"key": "chats.preico_message",

Adamant/CoreData/ChatModels.xcdatamodeld/ChatModels.xcdatamodel/contents

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
</entity>
2626
<entity name="CoreDataAccount" representedClassName="CoreDataAccount" syncable="YES">
2727
<attribute name="address" optional="YES" attributeType="String" syncable="YES"/>
28+
<attribute name="avatar" optional="YES" attributeType="String" syncable="YES"/>
2829
<attribute name="knownMessages" optional="YES" attributeType="Transformable" customClassName="[String:String]" syncable="YES"/>
2930
<attribute name="name" optional="YES" attributeType="String" syncable="YES"/>
3031
<attribute name="publicKey" optional="YES" attributeType="String" syncable="YES"/>
@@ -38,7 +39,7 @@
3839
<element name="BaseTransaction" positionX="-9" positionY="99" width="128" height="180"/>
3940
<element name="Chatroom" positionX="-45" positionY="108" width="128" height="105"/>
4041
<element name="ChatTransaction" positionX="-18" positionY="27" width="128" height="105"/>
41-
<element name="CoreDataAccount" positionX="0" positionY="81" width="128" height="135"/>
42+
<element name="CoreDataAccount" positionX="0" positionY="81" width="128" height="150"/>
4243
<element name="TransferTransaction" positionX="-18" positionY="63" width="128" height="60"/>
4344
</elements>
4445
</model>

Adamant/CoreData/CoreDataAccount+CoreDataProperties.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@ extension CoreDataAccount {
1818
}
1919

2020
@NSManaged public var address: String?
21+
@NSManaged public var knownMessages: [String:String]?
2122
@NSManaged public var name: String?
2223
@NSManaged public var publicKey: String?
23-
@NSManaged public var knownMessages: [String:String]?
24+
@NSManaged public var avatar: String?
2425
@NSManaged public var chatroom: Chatroom?
2526
@NSManaged public var transfers: NSSet?
2627

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/AccountService.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,15 @@ protocol AccountService {
5353
///
5454
/// - Parameters:
5555
/// - passphrase: Your new unique passphrase
56-
/// - completionHandler: New logged account, if success, error if not.
57-
func createAccount(with passphrase: String, completionHandler: ((Account?, AdamantError?) -> Void)?)
56+
/// - completion: New logged account, if success, error if not.
57+
func createAccount(with passphrase: String, completion: ((Account?, AdamantError?) -> Void)?)
5858

5959
/// Login into Adamant using passphrase.
6060
///
6161
/// - Parameters:
6262
/// - passphrase: Your unique passphrase
63-
/// - loginCompletionHandler: Logged account if success, error if not.
64-
func login(with passphrase: String, completionHandler: ((Account?, AdamantError?) -> Void)?)
63+
/// - logincompletion: Logged account if success, error if not.
64+
func login(with passphrase: String, completion: ((Account?, AdamantError?) -> Void)?)
6565

6666
/// Logout (if logged in) and present authorization viewControllers modally. After login or cancel will dismiss modal window and then call a callback.
6767
///

Adamant/ServiceProtocols/ApiService.swift

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,33 +8,46 @@
88

99
import Foundation
1010

11+
enum ApiServiceResult<T> {
12+
case success(T)
13+
case failure(ApiServiceError)
14+
}
15+
16+
enum ApiServiceError: Error {
17+
case notLogged
18+
case accountNotFound
19+
case serverError(error: String)
20+
case internalError(message: String, error: Error?)
21+
case networkError(error: Error)
22+
}
23+
1124
protocol ApiService {
1225

1326
/// Default is async queue with .utilities priority.
1427
var defaultResponseDispatchQueue: DispatchQueue { get set }
1528

1629
// MARK: - Accounts
1730

18-
func newAccount(byPublicKey publicKey: String, completionHandler: @escaping (Account?, AdamantError?) -> Void)
19-
func getAccount(byPassphrase passphrase: String, completionHandler: @escaping (Account?, AdamantError?) -> Void)
20-
func getAccount(byPublicKey publicKey: String, completionHandler: @escaping (Account?, AdamantError?) -> Void)
21-
func getAccount(byAddress address: String, completionHandler: @escaping (Account?, AdamantError?) -> Void)
31+
func newAccount(byPublicKey publicKey: String, completion: @escaping (ApiServiceResult<Account>) -> Void)
32+
func getAccount(byPassphrase passphrase: String, completion: @escaping (ApiServiceResult<Account>) -> Void)
33+
func getAccount(byPublicKey publicKey: String, completion: @escaping (ApiServiceResult<Account>) -> Void)
34+
func getAccount(byAddress address: String, completion: @escaping (ApiServiceResult<Account>) -> Void)
2235

2336

2437
// MARK: - Keys
2538

26-
func getPublicKey(byAddress address: String, completionHandler: @escaping (String?, AdamantError?) -> Void)
39+
func getPublicKey(byAddress address: String, completion: @escaping (ApiServiceResult<String>) -> Void)
2740

2841

2942
// MARK: - Transactions
3043

31-
func getTransaction(id: UInt, completionHandler: @escaping (Transaction?, AdamantError?) -> Void)
32-
func getTransactions(forAccount: String, type: TransactionType, fromHeight: UInt?, completionHandler: @escaping ([Transaction]?, AdamantError?) -> Void)
44+
func getTransaction(id: UInt, completion: @escaping (ApiServiceResult<Transaction>) -> Void)
45+
func getTransactions(forAccount: String, type: TransactionType, fromHeight: UInt?, completion: @escaping (ApiServiceResult<[Transaction]>) -> Void)
3346

3447

3548
// MARK: - Funds
3649

37-
func transferFunds(sender: String, recipient: String, amount: UInt, keypair: Keypair, completionHandler: @escaping (Bool, AdamantError?) -> Void)
50+
func transferFunds(sender: String, recipient: String, amount: UInt, keypair: Keypair, completion: @escaping (ApiServiceResult<Bool>) -> Void)
3851

3952

4053
// MARK: - Chats
@@ -44,9 +57,9 @@ protocol ApiService {
4457
/// - Parameters:
4558
/// - account: Transactions for specified account
4659
/// - height: From this height. Minimal value is 1.
47-
func getChatTransactions(account: String, height: Int?, offset: Int?, completionHandler: @escaping ([Transaction]?, AdamantError?) -> Void)
60+
func getChatTransactions(account: String, height: Int?, offset: Int?, completion: @escaping (ApiServiceResult<[Transaction]>) -> Void)
4861

4962
/// Send text message
50-
/// - completionHandler: Contains processed transactionId, if success, or AdamantError, if fails.
51-
func sendMessage(senderId: String, recipientId: String, keypair: Keypair, message: String, nonce: String, completionHandler: @escaping (UInt?, AdamantError?) -> Void)
63+
/// - completion: Contains processed transactionId, if success, or AdamantError, if fails.
64+
func sendMessage(senderId: String, recipientId: String, keypair: Keypair, message: String, nonce: String, completion: @escaping (ApiServiceResult<UInt>) -> Void)
5265
}

Adamant/ServiceProtocols/DataProviders/AccountsProvider.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ protocol AccountsProvider {
2020
/// Search for fetched account, if not found, asks server for account.
2121
///
2222
/// - Returns: Account, if found, created in main viewContext
23-
func getAccount(byAddress address: String, completionHandler: @escaping (AccountsProviderResult) -> Void)
23+
func getAccount(byAddress address: String, completion: @escaping (AccountsProviderResult) -> Void)
2424

2525
/// Search for fetched account, if not found, asks server for account.
2626
///
2727
/// - Returns: Account, if found, created in main viewContext
28-
func getAccount(byPublicKey publicKey: String, completionHandler: @escaping (AccountsProviderResult) -> Void)
28+
func getAccount(byPublicKey publicKey: String, completion: @escaping (AccountsProviderResult) -> Void)
2929
}

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/DataProviders/TransfersProvider.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,5 @@ extension AdamantUserInfoKey {
4646
protocol TransfersProvider: DataProvider {
4747
func transfersController() -> NSFetchedResultsController<TransferTransaction>
4848

49-
func transferFunds(toAddress recipient: String, amount: Decimal, completionHandler: @escaping (TransfersProviderResult) -> Void)
49+
func transferFunds(toAddress recipient: String, amount: Decimal, completion: @escaping (TransfersProviderResult) -> Void)
5050
}

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/AdamantAccountService.swift

Lines changed: 45 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,11 @@ class AdamantAccountService: AccountService {
5656

5757
// MARK: - Login&Logout functions
5858
extension AdamantAccountService {
59-
func createAccount(with passphrase: String, completionHandler: ((Account?, AdamantError?) -> Void)?) {
59+
func createAccount(with passphrase: String, completion: ((Account?, AdamantError?) -> Void)?) {
6060
switch status {
6161
// Is logging in, return
6262
case .isLoggingIn:
63-
completionHandler?(nil, AdamantError(message: "Service is busy"))
63+
completion?(nil, AdamantError(message: "Service is busy"))
6464
return
6565

6666
// Logout first
@@ -74,32 +74,36 @@ extension AdamantAccountService {
7474

7575
status = .isLoggingIn
7676
guard let publicKey = adamantCore.createKeypairFor(passphrase: passphrase)?.publicKey else {
77-
completionHandler?(nil, AdamantError(message: "Can't create key for passphrase"))
77+
completion?(nil, AdamantError(message: "Can't create key for passphrase"))
7878
return
7979
}
8080

81-
self.apiService.getAccount(byPublicKey: publicKey, completionHandler: { (account, error) in
82-
if account != nil {
83-
self.login(with: passphrase, completionHandler: completionHandler)
84-
}
85-
86-
self.apiService.newAccount(byPublicKey: publicKey, completionHandler: { (account, error) in
87-
if let account = account {
88-
self.setLoggedInWith(account: account, passphrase: passphrase)
89-
completionHandler?(account, error)
90-
} else {
91-
self.status = .notLogged
92-
completionHandler?(nil, error)
81+
self.apiService.getAccount(byPublicKey: publicKey) { result in
82+
switch result {
83+
case .success(_):
84+
self.login(with: passphrase, completion: completion)
85+
86+
case .failure(_):
87+
self.apiService.newAccount(byPublicKey: publicKey) { result in
88+
switch result {
89+
case .success(let account):
90+
self.setLoggedInWith(account: account, passphrase: passphrase)
91+
completion?(account, nil)
92+
93+
case .failure(let error):
94+
self.status = .notLogged
95+
completion?(nil, AdamantError(message: String(describing: error), error: error))
96+
}
9397
}
94-
})
95-
})
98+
}
99+
}
96100
}
97101

98-
func login(with passphrase: String, completionHandler: ((Account?, AdamantError?) -> Void)?) {
102+
func login(with passphrase: String, completion: ((Account?, AdamantError?) -> Void)?) {
99103
switch status {
100104
// Is logging in, return
101105
case .isLoggingIn:
102-
completionHandler?(nil, AdamantError(message: "Service is busy"))
106+
completion?(nil, AdamantError(message: "Service is busy"))
103107
return
104108

105109
// Logout first
@@ -112,13 +116,15 @@ extension AdamantAccountService {
112116
}
113117

114118
status = .isLoggingIn
115-
self.apiService.getAccount(byPassphrase: passphrase) { (account, error) in
116-
if let account = account {
119+
self.apiService.getAccount(byPassphrase: passphrase) { result in
120+
switch result {
121+
case .success(let account):
117122
self.setLoggedInWith(account: account, passphrase: passphrase)
118-
completionHandler?(account, error)
119-
} else {
123+
completion?(account, nil)
124+
125+
case .failure(let error):
120126
self.status = .notLogged
121-
completionHandler?(nil, error)
127+
completion?(nil, AdamantError(message: String(describing: error), error: error))
122128
}
123129
}
124130
}
@@ -210,22 +216,23 @@ extension AdamantAccountService {
210216
return
211217
}
212218

213-
apiService.getAccount(byPublicKey: loggedAccount.publicKey) { (account, error) in
214-
guard let account = account else {
219+
apiService.getAccount(byPublicKey: loggedAccount.publicKey) { result in
220+
switch result {
221+
case .success(let account):
222+
var hasChanges = false
223+
224+
if loggedAccount.balance != account.balance { hasChanges = true }
225+
226+
if hasChanges {
227+
self.account = account
228+
NotificationCenter.default.post(name: Notification.Name.adamantAccountDataUpdated, object: nil)
229+
}
230+
231+
self.updating = false
232+
233+
case .failure(let error):
215234
print("Error update account: \(String(describing: error))")
216-
return
217235
}
218-
219-
var hasChanges = false
220-
221-
if loggedAccount.balance != account.balance { hasChanges = true }
222-
223-
if hasChanges {
224-
self.account = account
225-
NotificationCenter.default.post(name: Notification.Name.adamantAccountDataUpdated, object: nil)
226-
}
227-
228-
self.updating = false
229236
}
230237
}
231238
}

0 commit comments

Comments
 (0)