Skip to content

Commit

Permalink
Merge pull request #437 from Adamant-im/develop
Browse files Browse the repository at this point in the history
Release 3.5.0
  • Loading branch information
just-software-dev authored Feb 4, 2024
2 parents 6a5c8d7 + b78409f commit a6a4017
Show file tree
Hide file tree
Showing 141 changed files with 1,971 additions and 1,060 deletions.
44 changes: 30 additions & 14 deletions Adamant.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions Adamant/Adamant.xcdatamodeld/Adamant.xcdatamodel/contents
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="21754" systemVersion="22E252" minimumToolsVersion="Automatic" sourceLanguage="Swift" userDefinedModelVersionIdentifier="">
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="22225" systemVersion="23B74" minimumToolsVersion="Automatic" sourceLanguage="Swift" userDefinedModelVersionIdentifier="">
<entity name="BaseAccount" representedClassName="BaseAccount" isAbstract="YES" syncable="YES">
<attribute name="address" attributeType="String"/>
<attribute name="avatar" optional="YES" attributeType="String"/>
Expand Down Expand Up @@ -49,7 +49,7 @@
<attribute name="recipientId" attributeType="String" defaultValueString=""/>
<attribute name="senderId" attributeType="String" defaultValueString=""/>
<attribute name="transactionId" attributeType="String" defaultValueString=""/>
<attribute name="transactionStatusRaw" attributeType="Integer 16" defaultValueString="0" usesScalarValueType="YES"/>
<attribute name="transactionStatusRaw" attributeType="String" defaultValueString=""/>
<uniquenessConstraints>
<uniquenessConstraint>
<constraint value="transactionId"/>
Expand All @@ -72,6 +72,7 @@
<attribute name="isReply" attributeType="Boolean" defaultValueString="NO" usesScalarValueType="YES"/>
<attribute name="richContent" optional="YES" attributeType="Transformable" valueTransformerName="NSSecureUnarchiveFromData" customClassName="[String:Any]"/>
<attribute name="richContentSerialized" optional="YES" attributeType="String"/>
<attribute name="richTransferHash" optional="YES" attributeType="String"/>
<attribute name="richType" attributeType="String"/>
<attribute name="transferStatusRaw" optional="YES" attributeType="Integer 16" usesScalarValueType="NO" customClassName="RichTransferStatus"/>
</entity>
Expand Down
67 changes: 46 additions & 21 deletions Adamant/App/DI/AppAssembly.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ struct AppAssembly: Assembly {
container.register(VisibleWalletsService.self) { r in
AdamantVisibleWalletsService(
securedStore: r.resolve(SecuredStore.self)!,
accountService: r.resolve(AccountService.self)!
accountService: r.resolve(AccountService.self)!,
walletsServiceCompose: r.resolve(WalletServiceCompose.self)!
)
}.inObjectScope(.container)

Expand Down Expand Up @@ -198,7 +199,8 @@ struct AppAssembly: Assembly {
apiService: r.resolve(ApiService.self)!,
adamantCore: r.resolve(AdamantCore.self)!,
dialogService: r.resolve(DialogService.self)!,
securedStore: r.resolve(SecuredStore.self)!
securedStore: r.resolve(SecuredStore.self)!,
walletServiceCompose: r.resolve(WalletServiceCompose.self)!
)
}.inObjectScope(.container).initCompleted { (r, c) in
Task { @MainActor in
Expand All @@ -207,9 +209,6 @@ struct AppAssembly: Assembly {
service.pushNotificationsTokenService = r.resolve(PushNotificationsTokenService.self)!
service.currencyInfoService = r.resolve(CurrencyInfoService.self)!
service.visibleWalletService = r.resolve(VisibleWalletsService.self)!
for case let wallet as SwinjectDependentService in service.wallets {
wallet.injectDependencies(from: container)
}
}
}

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

// MARK: CurrencyInfoService
container.register(CurrencyInfoService.self) { r in
AdamantCurrencyInfoService(securedStore: r.resolve(SecuredStore.self)!)
}.inObjectScope(.container).initCompleted { (r, c) in
guard let service = c as? AdamantCurrencyInfoService else { return }
service.accountService = r.resolve(AccountService.self)
}
AdamantCurrencyInfoService(
securedStore: r.resolve(SecuredStore.self)!,
walletServiceCompose: r.resolve(WalletServiceCompose.self)!
)
}.inObjectScope(.container)

// MARK: LanguageStorageProtocol
container.register(LanguageStorageProtocol.self) { r in
Expand Down Expand Up @@ -275,29 +274,24 @@ struct AppAssembly: Assembly {
adamantCore: r.resolve(AdamantCore.self)!,
accountsProvider: r.resolve(AccountsProvider.self)!,
transactionService: r.resolve(ChatTransactionService.self)!,
securedStore: r.resolve(SecuredStore.self)!
securedStore: r.resolve(SecuredStore.self)!,
walletServiceCompose: r.resolve(WalletServiceCompose.self)!
)
}.inObjectScope(.container)

// MARK: Chat Transaction Service
container.register(ChatTransactionService.self) { r in
AdamantChatTransactionService(
adamantCore: r.resolve(AdamantCore.self)!,
accountService: r.resolve(AccountService.self)!
walletServiceCompose: r.resolve(WalletServiceCompose.self)!
)
}.inObjectScope(.container)

// MARK: Rich transaction status service
container.register(TransactionStatusService.self) { r in
let accountService = r.resolve(AccountService.self)!

let richProviders = accountService.wallets
.compactMap { $0 as? RichMessageProviderWithStatusCheck }
.map { ($0.dynamicRichMessageType, $0) }

return AdamantTransactionStatusService(
AdamantTransactionStatusService(
coreDataStack: r.resolve(CoreDataStack.self)!,
richProviders: Dictionary(uniqueKeysWithValues: richProviders),
walletServiceCompose: r.resolve(WalletServiceCompose.self)!,
nodesStorage: r.resolve(NodesStorageProtocol.self)!
)
}.inObjectScope(.container)
Expand All @@ -308,7 +302,8 @@ struct AppAssembly: Assembly {
coreDataStack: r.resolve(CoreDataStack.self)!,
apiService: r.resolve(ApiService.self)!,
adamantCore: r.resolve(AdamantCore.self)!,
accountService: r.resolve(AccountService.self)!
accountService: r.resolve(AccountService.self)!,
walletServiceCompose: r.resolve(WalletServiceCompose.self)!
)
}.inObjectScope(.container)

Expand All @@ -326,5 +321,35 @@ struct AppAssembly: Assembly {
container.register(AddressConverterFactory.self) { _ in
AddressConverterFactory()
}.inObjectScope(.container)

// MARK: Wallet Service Compose
container.register(WalletServiceCompose.self) { r in
var wallets: [WalletCoreProtocol] = [
AdmWalletService(),
BtcWalletService(),
EthWalletService(),
LskWalletService(),
DogeWalletService(),
DashWalletService()
]

let erc20WalletServices = ERC20Token.supportedTokens.map {
ERC20WalletService(token: $0)
}

wallets.append(contentsOf: erc20WalletServices)

return AdamantWalletServiceCompose(
wallets: wallets,
coreDataStack: r.resolve(CoreDataStack.self)!
)
}.inObjectScope(.container).initCompleted { (_, c) in
Task { @MainActor in
guard let service = c as? AdamantWalletServiceCompose else { return }
for case let wallet as SwinjectDependentService in service.getWallets().map({ $0.core }) {
wallet.injectDependencies(from: container)
}
}
}
}
}
32 changes: 30 additions & 2 deletions Adamant/Helpers/Node+UI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ extension Node {
.joined(separator: " ")
case .offline:
return Strings.offline
case .notAllowed(let reason):
return [
reason.text,
version
]
.compactMap { $0 }
.joined(separator: " ")
case .none:
return nil
}
Expand Down Expand Up @@ -61,7 +68,7 @@ extension Node {
return .adamant.good
case .synchronizing:
return .adamant.alert
case .offline:
case .offline, .notAllowed:
return .adamant.danger
case .none:
return .adamant.inactive
Expand Down Expand Up @@ -124,6 +131,27 @@ private extension Node {
}

var heightString: String? {
height.map { "\($0)" }
height.map { "\(getFormattedHeight(from: $0))" }
}

var numberFormatter: NumberFormatter {
let numberFormatter = NumberFormatter()
numberFormatter.numberStyle = .decimal
numberFormatter.groupingSeparator = ","
return numberFormatter
}

func getFormattedHeight(from height: Int) -> String {
numberFormatter.string(from: Decimal(height)) ?? String(height)
}
}

extension Node {
static func stringToDouble(_ value: String?) -> Double? {
guard let minNodeVersion = value?.replacingOccurrences(of: ".", with: ""),
let versionNumber = Double(minNodeVersion)
else { return nil }

return versionNumber
}
}
26 changes: 26 additions & 0 deletions Adamant/Helpers/NodeGroup+Constants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,30 @@ public extension NodeGroup {
return DashWalletService.healthCheckParameters.normalUpdateInterval
}
}

var minNodeVersion: Double {
var minNodeVersion: String?
switch self {
case .adm:
minNodeVersion = AdmWalletService.minNodeVersion
case .btc:
minNodeVersion = BtcWalletService.minNodeVersion
case .eth:
minNodeVersion = EthWalletService.minNodeVersion
case .lskNode:
minNodeVersion = LskWalletService.minNodeVersion
case .lskService:
minNodeVersion = LskWalletService.minNodeVersion
case .doge:
minNodeVersion = DogeWalletService.minNodeVersion
case .dash:
minNodeVersion = DashWalletService.minNodeVersion
}

guard let versionNumber = Node.stringToDouble(minNodeVersion) else {
return .zero
}

return versionNumber
}
}
14 changes: 10 additions & 4 deletions Adamant/Models/CoreData/CoinTransaction+CoreDataClass.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,18 @@ public class CoinTransaction: NSManagedObject {

var transactionStatus: TransactionStatus? {
get {
TransactionStatus(rawValue: transactionStatusRaw)
let data = Data(transactionStatusRaw.utf8)
return try? JSONDecoder().decode(TransactionStatus.self, from: data)
}
set {
let raw = newValue?.rawValue ?? .zero
guard raw != transactionStatusRaw else { return }
transactionStatusRaw = newValue?.rawValue ?? .zero
guard let data = try? JSONEncoder().encode(newValue),
let raw = String(data: data, encoding: .utf8)
else {
transactionStatusRaw = ""
return
}

transactionStatusRaw = raw
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ extension CoinTransaction {
@NSManaged public var height: Int64
@NSManaged public var isConfirmed: Bool
@NSManaged public var blockchainType: String
@NSManaged public var transactionStatusRaw: Int16
@NSManaged public var transactionStatusRaw: String
}

extension CoinTransaction : Identifiable {
Expand Down
14 changes: 10 additions & 4 deletions Adamant/Models/CoreData/RichMessageTransaction+CoreDataClass.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,18 @@ public class RichMessageTransaction: ChatTransaction {

override var transactionStatus: TransactionStatus? {
get {
TransactionStatus(rawValue: transactionStatusRaw)
let data = Data(transactionStatusRaw.utf8)
return try? JSONDecoder().decode(TransactionStatus.self, from: data)
}
set {
let raw = newValue?.rawValue ?? .zero
guard raw != transactionStatusRaw else { return }
transactionStatusRaw = newValue?.rawValue ?? .zero
guard let data = try? JSONEncoder().encode(newValue),
let raw = String(data: data, encoding: .utf8)
else {
transactionStatusRaw = ""
return
}

transactionStatusRaw = raw
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ extension RichMessageTransaction {
return NSFetchRequest<RichMessageTransaction>(entityName: "RichMessageTransaction")
}

@NSManaged public var richTransferHash: String?
@NSManaged public var richContentSerialized: String?
@NSManaged public var richContent: [String: Any]?
@NSManaged public var richType: String?
Expand Down
49 changes: 47 additions & 2 deletions Adamant/Models/TransactionStatus.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,48 @@
import Foundation
import UIKit

enum TransactionStatus: Int16 {
enum InconsistentReason: Codable, Hashable {
case time
case duplicate
case unknown
case wrongTxHash
case wrongAmount
case senderCryptoAddressMismatch(String)
case recipientCryptoAddressMismatch(String)
case senderCryptoAddressUnavailable(String)
case recipientCryptoAddressUnavailable(String)

var localized: String {
switch self {
case .time:
return .localized("TransactionStatus.Inconsistent.WrongTimestamp", comment: "Transaction status: inconsistent wrong timestamp")
case .duplicate:
return .localized("TransactionStatus.Inconsistent.Duplicate", comment: "Transaction status: inconsistent duplicate")
case .unknown:
return .localized("TransactionStatus.Inconsistent.Unknown", comment: "Transaction status: inconsistent wrong unknown")
case .wrongTxHash:
return .localized("TransactionStatus.Inconsistent.WrongTxHash", comment: "Transaction status: inconsistent wrong hash")
case .wrongAmount:
return .localized("TransactionStatus.Inconsistent.WrongAmount", comment: "Transaction status: inconsistent wrong amount")
case .senderCryptoAddressMismatch(let coin):
return String.localizedStringWithFormat(.localized("TransactionStatus.Inconsistent.SenderCryptoAddressMismatch", comment: "Transaction status: inconsistent wrong mismatch"), coin)
case .recipientCryptoAddressMismatch(let coin):
return String.localizedStringWithFormat(.localized("TransactionStatus.Inconsistent.RecipientCryptoAddressMismatch", comment: "Transaction status: inconsistent wrong mismatch"), coin)
case .senderCryptoAddressUnavailable(let coin):
return String.localizedStringWithFormat(.localized("TransactionStatus.Inconsistent.SenderCryptoAddressUnavailable", comment: "Transaction status: inconsistent unable to retrieve"), coin)
case .recipientCryptoAddressUnavailable(let coin):
return String.localizedStringWithFormat(.localized("TransactionStatus.Inconsistent.RecipientCryptoAddressUnavailable", comment: "Transaction status: inconsistent unable to retrieve"), coin)
}
}
}

enum TransactionStatus: Codable, Equatable, Hashable {
case notInitiated
case pending
case success
case failed
case registered
case inconsistent
case inconsistent(InconsistentReason)
case noNetwork
case noNetworkFinal

Expand All @@ -36,3 +71,13 @@ enum TransactionStatus: Int16 {
}
}
}

extension TransactionStatus {
var isInconsistent: Bool {
if case .inconsistent = self {
return true
}

return false
}
}
3 changes: 2 additions & 1 deletion Adamant/Modules/Account/AccountFactory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ struct AccountFactory {
localAuth: assembler.resolve(LocalAuthentication.self)!,
avatarService: assembler.resolve(AvatarService.self)!,
currencyInfoService: assembler.resolve(CurrencyInfoService.self)!,
languageService: assembler.resolve(LanguageStorageProtocol.self)!
languageService: assembler.resolve(LanguageStorageProtocol.self)!,
walletServiceCompose: assembler.resolve(WalletServiceCompose.self)!
)
}
}
Loading

0 comments on commit a6a4017

Please sign in to comment.