Skip to content

Commit a6a4017

Browse files
Merge pull request #437 from Adamant-im/develop
Release 3.5.0
2 parents 6a5c8d7 + b78409f commit a6a4017

File tree

141 files changed

+1971
-1060
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

141 files changed

+1971
-1060
lines changed

Adamant.xcodeproj/project.pbxproj

Lines changed: 30 additions & 14 deletions
Large diffs are not rendered by default.

Adamant/Adamant.xcdatamodeld/Adamant.xcdatamodel/contents

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2-
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="21754" systemVersion="22E252" minimumToolsVersion="Automatic" sourceLanguage="Swift" userDefinedModelVersionIdentifier="">
2+
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="22225" systemVersion="23B74" minimumToolsVersion="Automatic" sourceLanguage="Swift" userDefinedModelVersionIdentifier="">
33
<entity name="BaseAccount" representedClassName="BaseAccount" isAbstract="YES" syncable="YES">
44
<attribute name="address" attributeType="String"/>
55
<attribute name="avatar" optional="YES" attributeType="String"/>
@@ -49,7 +49,7 @@
4949
<attribute name="recipientId" attributeType="String" defaultValueString=""/>
5050
<attribute name="senderId" attributeType="String" defaultValueString=""/>
5151
<attribute name="transactionId" attributeType="String" defaultValueString=""/>
52-
<attribute name="transactionStatusRaw" attributeType="Integer 16" defaultValueString="0" usesScalarValueType="YES"/>
52+
<attribute name="transactionStatusRaw" attributeType="String" defaultValueString=""/>
5353
<uniquenessConstraints>
5454
<uniquenessConstraint>
5555
<constraint value="transactionId"/>
@@ -72,6 +72,7 @@
7272
<attribute name="isReply" attributeType="Boolean" defaultValueString="NO" usesScalarValueType="YES"/>
7373
<attribute name="richContent" optional="YES" attributeType="Transformable" valueTransformerName="NSSecureUnarchiveFromData" customClassName="[String:Any]"/>
7474
<attribute name="richContentSerialized" optional="YES" attributeType="String"/>
75+
<attribute name="richTransferHash" optional="YES" attributeType="String"/>
7576
<attribute name="richType" attributeType="String"/>
7677
<attribute name="transferStatusRaw" optional="YES" attributeType="Integer 16" usesScalarValueType="NO" customClassName="RichTransferStatus"/>
7778
</entity>

Adamant/App/DI/AppAssembly.swift

Lines changed: 46 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ struct AppAssembly: Assembly {
5151
container.register(VisibleWalletsService.self) { r in
5252
AdamantVisibleWalletsService(
5353
securedStore: r.resolve(SecuredStore.self)!,
54-
accountService: r.resolve(AccountService.self)!
54+
accountService: r.resolve(AccountService.self)!,
55+
walletsServiceCompose: r.resolve(WalletServiceCompose.self)!
5556
)
5657
}.inObjectScope(.container)
5758

@@ -198,7 +199,8 @@ struct AppAssembly: Assembly {
198199
apiService: r.resolve(ApiService.self)!,
199200
adamantCore: r.resolve(AdamantCore.self)!,
200201
dialogService: r.resolve(DialogService.self)!,
201-
securedStore: r.resolve(SecuredStore.self)!
202+
securedStore: r.resolve(SecuredStore.self)!,
203+
walletServiceCompose: r.resolve(WalletServiceCompose.self)!
202204
)
203205
}.inObjectScope(.container).initCompleted { (r, c) in
204206
Task { @MainActor in
@@ -207,9 +209,6 @@ struct AppAssembly: Assembly {
207209
service.pushNotificationsTokenService = r.resolve(PushNotificationsTokenService.self)!
208210
service.currencyInfoService = r.resolve(CurrencyInfoService.self)!
209211
service.visibleWalletService = r.resolve(VisibleWalletsService.self)!
210-
for case let wallet as SwinjectDependentService in service.wallets {
211-
wallet.injectDependencies(from: container)
212-
}
213212
}
214213
}
215214

@@ -225,11 +224,11 @@ struct AppAssembly: Assembly {
225224

226225
// MARK: CurrencyInfoService
227226
container.register(CurrencyInfoService.self) { r in
228-
AdamantCurrencyInfoService(securedStore: r.resolve(SecuredStore.self)!)
229-
}.inObjectScope(.container).initCompleted { (r, c) in
230-
guard let service = c as? AdamantCurrencyInfoService else { return }
231-
service.accountService = r.resolve(AccountService.self)
232-
}
227+
AdamantCurrencyInfoService(
228+
securedStore: r.resolve(SecuredStore.self)!,
229+
walletServiceCompose: r.resolve(WalletServiceCompose.self)!
230+
)
231+
}.inObjectScope(.container)
233232

234233
// MARK: LanguageStorageProtocol
235234
container.register(LanguageStorageProtocol.self) { r in
@@ -275,29 +274,24 @@ struct AppAssembly: Assembly {
275274
adamantCore: r.resolve(AdamantCore.self)!,
276275
accountsProvider: r.resolve(AccountsProvider.self)!,
277276
transactionService: r.resolve(ChatTransactionService.self)!,
278-
securedStore: r.resolve(SecuredStore.self)!
277+
securedStore: r.resolve(SecuredStore.self)!,
278+
walletServiceCompose: r.resolve(WalletServiceCompose.self)!
279279
)
280280
}.inObjectScope(.container)
281281

282282
// MARK: Chat Transaction Service
283283
container.register(ChatTransactionService.self) { r in
284284
AdamantChatTransactionService(
285285
adamantCore: r.resolve(AdamantCore.self)!,
286-
accountService: r.resolve(AccountService.self)!
286+
walletServiceCompose: r.resolve(WalletServiceCompose.self)!
287287
)
288288
}.inObjectScope(.container)
289289

290290
// MARK: Rich transaction status service
291291
container.register(TransactionStatusService.self) { r in
292-
let accountService = r.resolve(AccountService.self)!
293-
294-
let richProviders = accountService.wallets
295-
.compactMap { $0 as? RichMessageProviderWithStatusCheck }
296-
.map { ($0.dynamicRichMessageType, $0) }
297-
298-
return AdamantTransactionStatusService(
292+
AdamantTransactionStatusService(
299293
coreDataStack: r.resolve(CoreDataStack.self)!,
300-
richProviders: Dictionary(uniqueKeysWithValues: richProviders),
294+
walletServiceCompose: r.resolve(WalletServiceCompose.self)!,
301295
nodesStorage: r.resolve(NodesStorageProtocol.self)!
302296
)
303297
}.inObjectScope(.container)
@@ -308,7 +302,8 @@ struct AppAssembly: Assembly {
308302
coreDataStack: r.resolve(CoreDataStack.self)!,
309303
apiService: r.resolve(ApiService.self)!,
310304
adamantCore: r.resolve(AdamantCore.self)!,
311-
accountService: r.resolve(AccountService.self)!
305+
accountService: r.resolve(AccountService.self)!,
306+
walletServiceCompose: r.resolve(WalletServiceCompose.self)!
312307
)
313308
}.inObjectScope(.container)
314309

@@ -326,5 +321,35 @@ struct AppAssembly: Assembly {
326321
container.register(AddressConverterFactory.self) { _ in
327322
AddressConverterFactory()
328323
}.inObjectScope(.container)
324+
325+
// MARK: Wallet Service Compose
326+
container.register(WalletServiceCompose.self) { r in
327+
var wallets: [WalletCoreProtocol] = [
328+
AdmWalletService(),
329+
BtcWalletService(),
330+
EthWalletService(),
331+
LskWalletService(),
332+
DogeWalletService(),
333+
DashWalletService()
334+
]
335+
336+
let erc20WalletServices = ERC20Token.supportedTokens.map {
337+
ERC20WalletService(token: $0)
338+
}
339+
340+
wallets.append(contentsOf: erc20WalletServices)
341+
342+
return AdamantWalletServiceCompose(
343+
wallets: wallets,
344+
coreDataStack: r.resolve(CoreDataStack.self)!
345+
)
346+
}.inObjectScope(.container).initCompleted { (_, c) in
347+
Task { @MainActor in
348+
guard let service = c as? AdamantWalletServiceCompose else { return }
349+
for case let wallet as SwinjectDependentService in service.getWallets().map({ $0.core }) {
350+
wallet.injectDependencies(from: container)
351+
}
352+
}
353+
}
329354
}
330355
}

Adamant/Helpers/Node+UI.swift

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@ extension Node {
3232
.joined(separator: " ")
3333
case .offline:
3434
return Strings.offline
35+
case .notAllowed(let reason):
36+
return [
37+
reason.text,
38+
version
39+
]
40+
.compactMap { $0 }
41+
.joined(separator: " ")
3542
case .none:
3643
return nil
3744
}
@@ -61,7 +68,7 @@ extension Node {
6168
return .adamant.good
6269
case .synchronizing:
6370
return .adamant.alert
64-
case .offline:
71+
case .offline, .notAllowed:
6572
return .adamant.danger
6673
case .none:
6774
return .adamant.inactive
@@ -124,6 +131,27 @@ private extension Node {
124131
}
125132

126133
var heightString: String? {
127-
height.map { "\($0)" }
134+
height.map { "\(getFormattedHeight(from: $0))" }
135+
}
136+
137+
var numberFormatter: NumberFormatter {
138+
let numberFormatter = NumberFormatter()
139+
numberFormatter.numberStyle = .decimal
140+
numberFormatter.groupingSeparator = ","
141+
return numberFormatter
142+
}
143+
144+
func getFormattedHeight(from height: Int) -> String {
145+
numberFormatter.string(from: Decimal(height)) ?? String(height)
146+
}
147+
}
148+
149+
extension Node {
150+
static func stringToDouble(_ value: String?) -> Double? {
151+
guard let minNodeVersion = value?.replacingOccurrences(of: ".", with: ""),
152+
let versionNumber = Double(minNodeVersion)
153+
else { return nil }
154+
155+
return versionNumber
128156
}
129157
}

Adamant/Helpers/NodeGroup+Constants.swift

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,30 @@ public extension NodeGroup {
8484
return DashWalletService.healthCheckParameters.normalUpdateInterval
8585
}
8686
}
87+
88+
var minNodeVersion: Double {
89+
var minNodeVersion: String?
90+
switch self {
91+
case .adm:
92+
minNodeVersion = AdmWalletService.minNodeVersion
93+
case .btc:
94+
minNodeVersion = BtcWalletService.minNodeVersion
95+
case .eth:
96+
minNodeVersion = EthWalletService.minNodeVersion
97+
case .lskNode:
98+
minNodeVersion = LskWalletService.minNodeVersion
99+
case .lskService:
100+
minNodeVersion = LskWalletService.minNodeVersion
101+
case .doge:
102+
minNodeVersion = DogeWalletService.minNodeVersion
103+
case .dash:
104+
minNodeVersion = DashWalletService.minNodeVersion
105+
}
106+
107+
guard let versionNumber = Node.stringToDouble(minNodeVersion) else {
108+
return .zero
109+
}
110+
111+
return versionNumber
112+
}
87113
}

Adamant/Models/CoreData/CoinTransaction+CoreDataClass.swift

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,18 @@ public class CoinTransaction: NSManagedObject {
1616

1717
var transactionStatus: TransactionStatus? {
1818
get {
19-
TransactionStatus(rawValue: transactionStatusRaw)
19+
let data = Data(transactionStatusRaw.utf8)
20+
return try? JSONDecoder().decode(TransactionStatus.self, from: data)
2021
}
2122
set {
22-
let raw = newValue?.rawValue ?? .zero
23-
guard raw != transactionStatusRaw else { return }
24-
transactionStatusRaw = newValue?.rawValue ?? .zero
23+
guard let data = try? JSONEncoder().encode(newValue),
24+
let raw = String(data: data, encoding: .utf8)
25+
else {
26+
transactionStatusRaw = ""
27+
return
28+
}
29+
30+
transactionStatusRaw = raw
2531
}
2632
}
2733
}

Adamant/Models/CoreData/CoinTransaction+CoreDataProperties.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ extension CoinTransaction {
2929
@NSManaged public var height: Int64
3030
@NSManaged public var isConfirmed: Bool
3131
@NSManaged public var blockchainType: String
32-
@NSManaged public var transactionStatusRaw: Int16
32+
@NSManaged public var transactionStatusRaw: String
3333
}
3434

3535
extension CoinTransaction : Identifiable {

Adamant/Models/CoreData/RichMessageTransaction+CoreDataClass.swift

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,18 @@ public class RichMessageTransaction: ChatTransaction {
2121

2222
override var transactionStatus: TransactionStatus? {
2323
get {
24-
TransactionStatus(rawValue: transactionStatusRaw)
24+
let data = Data(transactionStatusRaw.utf8)
25+
return try? JSONDecoder().decode(TransactionStatus.self, from: data)
2526
}
2627
set {
27-
let raw = newValue?.rawValue ?? .zero
28-
guard raw != transactionStatusRaw else { return }
29-
transactionStatusRaw = newValue?.rawValue ?? .zero
28+
guard let data = try? JSONEncoder().encode(newValue),
29+
let raw = String(data: data, encoding: .utf8)
30+
else {
31+
transactionStatusRaw = ""
32+
return
33+
}
34+
35+
transactionStatusRaw = raw
3036
}
3137
}
3238

Adamant/Models/CoreData/RichMessageTransaction+CoreDataProperties.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ extension RichMessageTransaction {
1717
return NSFetchRequest<RichMessageTransaction>(entityName: "RichMessageTransaction")
1818
}
1919

20+
@NSManaged public var richTransferHash: String?
2021
@NSManaged public var richContentSerialized: String?
2122
@NSManaged public var richContent: [String: Any]?
2223
@NSManaged public var richType: String?

Adamant/Models/TransactionStatus.swift

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,48 @@
99
import Foundation
1010
import UIKit
1111

12-
enum TransactionStatus: Int16 {
12+
enum InconsistentReason: Codable, Hashable {
13+
case time
14+
case duplicate
15+
case unknown
16+
case wrongTxHash
17+
case wrongAmount
18+
case senderCryptoAddressMismatch(String)
19+
case recipientCryptoAddressMismatch(String)
20+
case senderCryptoAddressUnavailable(String)
21+
case recipientCryptoAddressUnavailable(String)
22+
23+
var localized: String {
24+
switch self {
25+
case .time:
26+
return .localized("TransactionStatus.Inconsistent.WrongTimestamp", comment: "Transaction status: inconsistent wrong timestamp")
27+
case .duplicate:
28+
return .localized("TransactionStatus.Inconsistent.Duplicate", comment: "Transaction status: inconsistent duplicate")
29+
case .unknown:
30+
return .localized("TransactionStatus.Inconsistent.Unknown", comment: "Transaction status: inconsistent wrong unknown")
31+
case .wrongTxHash:
32+
return .localized("TransactionStatus.Inconsistent.WrongTxHash", comment: "Transaction status: inconsistent wrong hash")
33+
case .wrongAmount:
34+
return .localized("TransactionStatus.Inconsistent.WrongAmount", comment: "Transaction status: inconsistent wrong amount")
35+
case .senderCryptoAddressMismatch(let coin):
36+
return String.localizedStringWithFormat(.localized("TransactionStatus.Inconsistent.SenderCryptoAddressMismatch", comment: "Transaction status: inconsistent wrong mismatch"), coin)
37+
case .recipientCryptoAddressMismatch(let coin):
38+
return String.localizedStringWithFormat(.localized("TransactionStatus.Inconsistent.RecipientCryptoAddressMismatch", comment: "Transaction status: inconsistent wrong mismatch"), coin)
39+
case .senderCryptoAddressUnavailable(let coin):
40+
return String.localizedStringWithFormat(.localized("TransactionStatus.Inconsistent.SenderCryptoAddressUnavailable", comment: "Transaction status: inconsistent unable to retrieve"), coin)
41+
case .recipientCryptoAddressUnavailable(let coin):
42+
return String.localizedStringWithFormat(.localized("TransactionStatus.Inconsistent.RecipientCryptoAddressUnavailable", comment: "Transaction status: inconsistent unable to retrieve"), coin)
43+
}
44+
}
45+
}
46+
47+
enum TransactionStatus: Codable, Equatable, Hashable {
1348
case notInitiated
1449
case pending
1550
case success
1651
case failed
1752
case registered
18-
case inconsistent
53+
case inconsistent(InconsistentReason)
1954
case noNetwork
2055
case noNetworkFinal
2156

@@ -36,3 +71,13 @@ enum TransactionStatus: Int16 {
3671
}
3772
}
3873
}
74+
75+
extension TransactionStatus {
76+
var isInconsistent: Bool {
77+
if case .inconsistent = self {
78+
return true
79+
}
80+
81+
return false
82+
}
83+
}

Adamant/Modules/Account/AccountFactory.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ struct AccountFactory {
2323
localAuth: assembler.resolve(LocalAuthentication.self)!,
2424
avatarService: assembler.resolve(AvatarService.self)!,
2525
currencyInfoService: assembler.resolve(CurrencyInfoService.self)!,
26-
languageService: assembler.resolve(LanguageStorageProtocol.self)!
26+
languageService: assembler.resolve(LanguageStorageProtocol.self)!,
27+
walletServiceCompose: assembler.resolve(WalletServiceCompose.self)!
2728
)
2829
}
2930
}

0 commit comments

Comments
 (0)