Skip to content

Commit

Permalink
Merge pull request #469 from Adamant-im/develop
Browse files Browse the repository at this point in the history
Release 3.6.0
  • Loading branch information
StanislavDevIOS authored Mar 13, 2024
2 parents a6a4017 + 9e4d308 commit c187d78
Show file tree
Hide file tree
Showing 154 changed files with 2,752 additions and 822 deletions.
52 changes: 38 additions & 14 deletions Adamant.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion 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="22225" systemVersion="23B74" minimumToolsVersion="Automatic" sourceLanguage="Swift" userDefinedModelVersionIdentifier="">
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="22225" systemVersion="23B81" 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 @@ -46,6 +46,7 @@
<attribute name="height" attributeType="Integer 64" defaultValueString="0" usesScalarValueType="YES"/>
<attribute name="isConfirmed" attributeType="Boolean" defaultValueString="NO" usesScalarValueType="YES"/>
<attribute name="isOutgoing" attributeType="Boolean" defaultValueString="NO" usesScalarValueType="YES"/>
<attribute name="nonceRaw" optional="YES" attributeType="String"/>
<attribute name="recipientId" attributeType="String" defaultValueString=""/>
<attribute name="senderId" attributeType="String" defaultValueString=""/>
<attribute name="transactionId" attributeType="String" defaultValueString=""/>
Expand Down
5 changes: 5 additions & 0 deletions Adamant/App/DI/AppAssembly.swift
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,11 @@ struct AppAssembly: Assembly {
AddressConverterFactory()
}.inObjectScope(.container)

// MARK: Chat Preservation
container.register(ChatPreservationProtocol.self) { _ in
ChatPreservation()
}.inObjectScope(.container)

// MARK: Wallet Service Compose
container.register(WalletServiceCompose.self) { r in
var wallets: [WalletCoreProtocol] = [
Expand Down
108 changes: 108 additions & 0 deletions Adamant/Helpers/ADM+JsonDecode.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
//
// ADM+Decode.swift
// Adamant
//
// Created by Stanislav Jelezoglo on 30.01.2024.
// Copyright © 2024 Adamant. All rights reserved.
//

import Foundation

struct JSONCodingKeys: CodingKey {
var stringValue: String

init?(stringValue: String) {
self.stringValue = stringValue
}

var intValue: Int?

init?(intValue: Int) {
self.init(stringValue: "\(intValue)")
self.intValue = intValue
}
}

extension KeyedDecodingContainer {
func decode(forKey key: K) throws -> Data {
if let stringValue = try? decode(String.self, forKey: key) {
return Data(stringValue.utf8)
} else if (try? decode(Dictionary<String, Any>.self, forKey: key)) != nil {
let container = try self.nestedContainer(keyedBy: JSONCodingKeys.self, forKey: key)
let dictionary = try container.decode([String: Any].self)
return try JSONSerialization.data(withJSONObject: dictionary, options: [])
}

return Data()
}

func decode(_ type: Dictionary<String, Any>.Type, forKey key: K) throws -> [String: Any] {
let container = try self.nestedContainer(keyedBy: JSONCodingKeys.self, forKey: key)
return try container.decode(type)
}

func decodeIfPresent(_ type: Dictionary<String, Any>.Type, forKey key: K) throws -> [String: Any]? {
guard contains(key) else {
return nil
}
return try decode(type, forKey: key)
}

func decode(_ type: Array<Any>.Type, forKey key: K) throws -> [Any] {
var container = try self.nestedUnkeyedContainer(forKey: key)
return try container.decode(type)
}

func decodeIfPresent(_ type: Array<Any>.Type, forKey key: K) throws -> [Any]? {
guard contains(key) else {
return nil
}
return try decode(type, forKey: key)
}

func decode(_ type: Dictionary<String, Any>.Type) throws -> [String: Any] {
var dictionary: [String: Any] = [:]

for key in allKeys {
if let boolValue = try? decode(Bool.self, forKey: key) {
dictionary[key.stringValue] = boolValue
} else if let stringValue = try? decode(String.self, forKey: key) {
dictionary[key.stringValue] = stringValue
} else if let intValue = try? decode(Int.self, forKey: key) {
dictionary[key.stringValue] = intValue
} else if let doubleValue = try? decode(Double.self, forKey: key) {
dictionary[key.stringValue] = doubleValue
} else if let nestedDictionary = try? decode(Dictionary<String, Any>.self, forKey: key) {
dictionary[key.stringValue] = nestedDictionary
} else if let nestedArray = try? decode(Array<Any>.self, forKey: key) {
dictionary[key.stringValue] = nestedArray
}
}
return dictionary
}
}

extension UnkeyedDecodingContainer {
mutating func decode(_ type: Array<Any>.Type) throws -> [Any] {
var array: [Any] = []
while isAtEnd == false {
if let value = try? decode(Bool.self) {
array.append(value)
} else if let value = try? decode(Double.self) {
array.append(value)
} else if let value = try? decode(String.self) {
array.append(value)
} else if let nestedDictionary = try? decode(Dictionary<String, Any>.self) {
array.append(nestedDictionary)
} else if let nestedArray = try? decode(Array<Any>.self) {
array.append(nestedArray)
}
}
return array
}

mutating func decode(_ type: Dictionary<String, Any>.Type) throws -> [String: Any] {
let nestedContainer = try self.nestedContainer(keyedBy: JSONCodingKeys.self)
return try nestedContainer.decode(type)
}
}
18 changes: 11 additions & 7 deletions Adamant/Helpers/Node+UI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,22 @@ import CommonKit
import UIKit

extension Node {
func statusString(showVersion: Bool) -> String? {
func statusString(showVersion: Bool, includeVersionTitle: Bool = true) -> String? {
guard isEnabled else { return Strings.disabled }

switch connectionStatus {
case .allowed:
return [
pingString,
showVersion ? versionString : nil,
showVersion ? versionString(includeVersionTitle: includeVersionTitle) : nil,
heightString
]
.compactMap { $0 }
.joined(separator: " ")
case .synchronizing:
return [
Strings.synchronizing,
showVersion ? versionString : nil,
showVersion ? versionString(includeVersionTitle: includeVersionTitle) : nil,
heightString
]
.compactMap { $0 }
Expand Down Expand Up @@ -121,10 +121,6 @@ private extension Node {
}
}

var versionString: String? {
version.map { "(\(Strings.version): \($0))" }
}

var pingString: String? {
guard let ping = ping else { return nil }
return "\(Strings.ping): \(Int(ping * 1000)) \(Strings.milliseconds)"
Expand All @@ -144,6 +140,14 @@ private extension Node {
func getFormattedHeight(from height: Int) -> String {
numberFormatter.string(from: Decimal(height)) ?? String(height)
}

func versionString(includeVersionTitle: Bool) -> String? {
guard includeVersionTitle else {
return version.map { "(\($0))" }
}

return version.map { "(v\($0))" }
}
}

extension Node {
Expand Down
2 changes: 2 additions & 0 deletions Adamant/Helpers/String+localized.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ extension String.adamant {
static var noInternetNotificationBoby: String {
String.localized("Shared.NoInternet.Body", comment: "Shared alert notification: body message for no internet connection.")
}
static var noInternetTransferBody: String { String.localized("Shared.Transfer.NoInternet.Body", comment: "Shared alert notification: body message for no internet connection.")
}

static var emailErrorMessageTitle: String {
String.localized("Error.Mail.Title", comment: "Error messge title for support email")
Expand Down
4 changes: 4 additions & 0 deletions Adamant/Models/BaseBtcTransaction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ class BaseBtcTransaction: TransactionDetails {

var blockHeight: UInt64?

var nonceRaw: String? {
nil
}

required init(txId: String, dateValue: Date?, blockValue: String?, senderAddress: String, recipientAddress: String, amountValue: Decimal, feeValue: Decimal?, confirmationsValue: String?, isOutgoing: Bool, transactionStatus: TransactionStatus?) {
self.txId = txId
self.dateValue = dateValue
Expand Down
10 changes: 4 additions & 6 deletions Adamant/Models/CoreData/Chatroom+CoreDataClass.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,13 @@ public class Chatroom: NSManagedObject {
@MainActor func getName(addressBookService: AddressBookService) -> String? {
guard let partner = partner else { return nil }
let result: String?
if let title = title {
if let address = partner.address,
let name = addressBookService.getName(for: address) {
result = name
} else if let title = title {
result = title
} else if let name = partner.name {
result = name
} else if
let address = partner.address,
let name = addressBookService.getName(for: address)
{
result = name
} else {
result = partner.address
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ extension CoinTransaction {
@NSManaged public var isConfirmed: Bool
@NSManaged public var blockchainType: String
@NSManaged public var transactionStatusRaw: String
@NSManaged public var nonceRaw: String?
}

extension CoinTransaction : Identifiable {
Expand Down
8 changes: 8 additions & 0 deletions Adamant/Models/EthTransaction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ struct EthTransaction {
let blockNumber: String?
let currencySymbol: String

var nonce: Int?
var isOutgoing: Bool = false
}

Expand Down Expand Up @@ -161,6 +162,12 @@ extension EthTransaction: TransactionDetails {
var blockHeight: UInt64? {
return nil
}

var nonceRaw: String? {
guard let nonce = nonce else { return nil }

return String(nonce)
}
}

// MARK: - From EthereumTransaction
Expand Down Expand Up @@ -221,6 +228,7 @@ extension CodableTransaction {
receiptStatus: receiptStatus,
blockNumber: blockNumber,
currencySymbol: token?.symbol ?? EthWalletService.currencySymbol,
nonce: Int(nonce),
isOutgoing: isOutgoing
)
}
Expand Down
9 changes: 9 additions & 0 deletions Adamant/Models/NodeWithGroup.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,13 @@ extension NodeGroup {
return AdmWalletService.tokenNetworkSymbol
}
}

var includeVersionTitle: Bool {
switch self {
case .btc, .lskNode, .lskService, .doge, .adm:
return true
case .eth, .dash:
return false
}
}
}
29 changes: 29 additions & 0 deletions Adamant/Models/RPCResponseModel.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//
// RPCResponseModel.swift
// Adamant
//
// Created by Stanislav Jelezoglo on 29.01.2024.
// Copyright © 2024 Adamant. All rights reserved.
//

import Foundation

struct RPCResponseModel: Codable {
let id: String
let result: Data

private enum CodingKeys: String, CodingKey {
case id
case result
}

init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
id = try container.decode(String.self, forKey: .id)
result = try container.decode(forKey: .result)
}

func serialize<Response: Decodable>() -> Response? {
try? JSONDecoder().decode(Response.self, from: result)
}
}
54 changes: 54 additions & 0 deletions Adamant/Models/RpcRequestModel.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
//
// RpcRequestModel.swift
// Adamant
//
// Created by Stanislav Jelezoglo on 31.01.2024.
// Copyright © 2024 Adamant. All rights reserved.
//

import Foundation

struct RpcRequest: Encodable {
let method: String
let id: String
let params: [Parameter]
let jsonrpc: String = "2.0"

init(method: String, id: String, params: [Parameter]) {
self.method = method
self.id = id
self.params = params
}

init(method: String, params: [Parameter]) {
self.method = method
self.id = method
self.params = params
}

init(method: String) {
self.method = method
self.id = method
self.params = []
}
}

extension RpcRequest {
enum Parameter {
case string(String)
case bool(Bool)
}
}

extension RpcRequest.Parameter: Encodable {
func encode(to encoder: Encoder) throws {
var container = encoder.singleValueContainer()

switch self {
case let .string(value):
try container.encode(value)
case let .bool(value):
try container.encode(value)
}
}
}
7 changes: 6 additions & 1 deletion Adamant/Models/SimpleTransactionDetails.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ struct SimpleTransactionDetails: AdamantTransactionDetails, Hashable {
var showToChat: Bool?
var chatRoom: Chatroom?

var nonceRaw: String?

init(
defaultCurrencySymbol: String? = nil,
txId: String,
Expand All @@ -52,7 +54,8 @@ struct SimpleTransactionDetails: AdamantTransactionDetails, Hashable {
blockValue: String? = nil,
isOutgoing: Bool,
transactionStatus: TransactionStatus? = nil,
partnerName: String? = nil
partnerName: String? = nil,
nonceRaw: String?
) {
self.defaultCurrencySymbol = defaultCurrencySymbol
self.txId = txId
Expand All @@ -66,6 +69,7 @@ struct SimpleTransactionDetails: AdamantTransactionDetails, Hashable {
self.isOutgoing = isOutgoing
self.transactionStatus = transactionStatus
self.partnerName = partnerName
self.nonceRaw = nonceRaw
}

init(_ transaction: TransactionDetails) {
Expand All @@ -80,6 +84,7 @@ struct SimpleTransactionDetails: AdamantTransactionDetails, Hashable {
self.blockValue = transaction.blockValue
self.isOutgoing = transaction.isOutgoing
self.transactionStatus = transaction.transactionStatus
self.nonceRaw = transaction.nonceRaw
}

init(_ transaction: TransferTransaction) {
Expand Down
Loading

0 comments on commit c187d78

Please sign in to comment.