Skip to content

Commit

Permalink
Merge branch 'develop' into features/IOS-8424_receive_notification
Browse files Browse the repository at this point in the history
  • Loading branch information
fedorov-d committed Nov 26, 2024
2 parents d042b4e + d456c11 commit 7b1fc8f
Show file tree
Hide file tree
Showing 111 changed files with 2,537 additions and 556 deletions.
6 changes: 5 additions & 1 deletion BlockchainSdk/Blockchains/Stellar/StellarSdk+.swift
Original file line number Diff line number Diff line change
Expand Up @@ -205,12 +205,16 @@ extension HorizonRequestError {
return message
case .rateLimitExceeded(let message, _):
return message
case .requestFailed(let message):
case .requestFailed(let message, _):
return message
case .staleHistory(let message, _):
return message
case .unauthorized(let message):
return message
case .duplicate(let message, _):
return message
case .timeout(let message, _):
return message
}
}

Expand Down
6 changes: 6 additions & 0 deletions BlockchainSdk/Common/Utils/EthereumUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,19 @@
import Foundation
import BigInt
import TangemFoundation
import TangemSdk

public enum EthereumUtils {
public static func parseEthereumDecimal(_ string: String, decimalsCount: Int) -> Decimal? {
guard let data = asciiHexToData(string.removeHexPrefix()) else {
return nil
}

guard decimalsCount <= Int(Int16.max) else {
Log.debug("\(#fileID): Unable to parse Ethereum decimal value from string '\(string)'; Can't represent the value of \(decimalsCount) as Int16")
return nil
}

// ERC-20 standard defines balanceOf function as returning uint256. Don't accept anything else.
let uint256Size = 32

Expand Down
95 changes: 95 additions & 0 deletions Modules/TangemFoundation/Helpers/LoadingResult.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
//
// LoadingResult.swift
// TangemApp
//
// Created by Sergey Balashov on 21.11.2024.
// Copyright © 2024 Tangem AG. All rights reserved.
//

import Foundation

/// LoadingResult to wrap the loading process
/// Can be used in two ways
/// - `LoadingResult<Value, Never>` with two possible option `loading` and `value`
/// - `LoadingResult<Value, Error>` with three possible option `loading` / `value` / `error`
public enum LoadingResult<Success, Failure: Error> {
case success(Success)
case failure(Failure)
case loading
}

// MARK: - Initialization

public extension LoadingResult {
static func result(_ result: Result<Success, Failure>) -> LoadingResult {
switch result {
case .success(let value): .success(value)
case .failure(let error): .failure(error)
}
}
}

// MARK: - Calculated

public extension LoadingResult {
var isLoading: Bool {
switch self {
case .loading: true
case .success, .failure: false
}
}

var value: Success? {
switch self {
case .success(let value): value
case .loading, .failure: nil
}
}

var error: Failure? {
switch self {
case .failure(let error): error
case .loading, .success: nil
}
}

func get() throws -> Success {
switch self {
case .success(let success): return success
case .failure(let failure): throw failure
case .loading: throw LoadingResultError.loadingInProcess
}
}
}

// MARK: - Equatable

extension LoadingResult: Equatable where Success: Equatable, Failure: Equatable {}

// MARK: - Hashable

extension LoadingResult: Hashable where Success: Hashable, Failure: Hashable {}

// MARK: - Mapping

public extension LoadingResult {
func mapValue<T>(_ transform: (Success) throws -> T) rethrows -> LoadingResult<T, Failure> {
switch self {
case .loading: .loading
case .success(let value): .success(try transform(value))
case .failure(let error): .failure(error)
}
}
}

// MARK: - Error

public enum LoadingResultError: LocalizedError {
case loadingInProcess

public var errorDescription: String? {
switch self {
case .loadingInProcess: "Loading in process"
}
}
}
2 changes: 1 addition & 1 deletion Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -200,4 +200,4 @@ SPEC CHECKSUMS:

PODFILE CHECKSUM: 641a395bff5e1baffc9490794e9787a869d13eb7

COCOAPODS: 1.15.2
COCOAPODS: 1.16.2
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,15 @@ extension CommonExpressModulesFactory: ExpressModulesFactory {
expressRefundedTokenHandler: expressRefundedTokenHandler
)

return pendingExpressTransactionsManager
let pendingOnrampTransactionsManager = CommonPendingOnrampTransactionsManager(
userWalletId: userWalletModel.userWalletId.stringValue,
walletModel: initialWalletModel
)

return CompoundPendingTransactionsManager(
first: pendingExpressTransactionsManager,
second: pendingOnrampTransactionsManager
)
}
}

Expand Down
19 changes: 19 additions & 0 deletions Tangem/App/Models/Express/PendingExpressTransaction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,22 @@ struct PendingExpressTransaction: Equatable {
let transactionRecord: ExpressPendingTransactionRecord
let statuses: [PendingExpressTransactionStatus]
}

extension PendingExpressTransaction {
var pendingTransaction: PendingTransaction {
PendingTransaction(
type: .swap(
source: transactionRecord.sourceTokenTxInfo,
destination: transactionRecord.destinationTokenTxInfo
),
expressTransactionId: transactionRecord.expressTransactionId,
externalTxId: transactionRecord.externalTxId,
externalTxURL: transactionRecord.externalTxURL,
provider: transactionRecord.provider,
date: transactionRecord.date,
transactionStatus: transactionRecord.transactionStatus,
refundedTokenItem: transactionRecord.refundedTokenItem,
statuses: statuses
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,15 @@ struct MarketsTokenDetailsMapper {
}

extension MarketsTokenDetailsMapper {
enum MapperError: Error {
enum MapperError: LocalizedError {
case missingAllTimePriceChangeValue

var errorDescription: String? {
let description = switch self {
case .missingAllTimePriceChangeValue:
"Missing all time price change value"
}
return "MapperError: " + description
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,18 @@ extension MarketsTokenHistoryChartMapper {
// MARK: - Auxiliary types

extension MarketsTokenHistoryChartMapper {
enum ParsingError: Error {
enum ParsingError: LocalizedError {
case notEnoughData
case timeStampParsingFailed

var errorDescription: String? {
let description = switch self {
case .notEnoughData:
"Not enough data"
case .timeStampParsingFailed:
"Timestamp parsing failed"
}
return "ParsingError: " + description
}
}
}
40 changes: 40 additions & 0 deletions Tangem/App/Models/Onramp/PendingOnrampTransaction.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//
// PendingOnrampTransaction.swift
// TangemApp
//
// Created by Aleksei Muraveinik on 21.11.24.
// Copyright © 2024 Tangem AG. All rights reserved.
//

import Foundation

struct PendingOnrampTransaction: Equatable {
let transactionRecord: OnrampPendingTransactionRecord
let statuses: [PendingExpressTransactionStatus]
}

extension PendingOnrampTransaction: Identifiable {
var id: String {
transactionRecord.id
}
}

extension PendingOnrampTransaction {
var pendingTransaction: PendingTransaction {
PendingTransaction(
type: .onramp(
sourceAmount: transactionRecord.fromAmount,
sourceCurrencySymbol: transactionRecord.fromCurrencyCode,
destination: transactionRecord.destinationTokenTxInfo
),
expressTransactionId: transactionRecord.expressTransactionId,
externalTxId: transactionRecord.externalTxId,
externalTxURL: transactionRecord.externalTxURL,
provider: transactionRecord.provider,
date: transactionRecord.date,
transactionStatus: transactionRecord.transactionStatus,
refundedTokenItem: nil,
statuses: statuses
)
}
}
19 changes: 19 additions & 0 deletions Tangem/App/Models/Onramp/SentOnrampTransactionData.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//
// SentOnrampTransactionData.swift
// Tangem
//
// Created by Aleksei Muraveinik on 20.11.24.
// Copyright © 2024 Tangem AG. All rights reserved.
//

import TangemExpress

struct SentOnrampTransactionData {
let txId: String
let provider: ExpressProvider
let destinationTokenItem: TokenItem
let date: Date
let fromAmount: Decimal
let fromCurrencyCode: String
let externalTxId: String
}
2 changes: 2 additions & 0 deletions Tangem/App/Services/Analytics/Analytics+Event.swift
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,8 @@ extension Analytics {
case tokenNoticeNetworkUnreachable = "[Token] Notice - Network Unreachable"
case tokenNoticeNotEnoughFee = "[Token] Notice - Not Enough Fee"
case tokenNoticeActionInactive = "[Token] Notice - Action Inactive"
case walletPromoButtonClicked = "[Main Screen] Note Promo Button"
case walletPromoAppear = "[Main Screen] Notice - Note Promo"

// MARK: - BlockchainSdk exceptions

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import Combine
import TangemExpress

protocol PendingExpressTransactionsManager: AnyObject {
var pendingTransactions: [PendingExpressTransaction] { get }
var pendingTransactionsPublisher: AnyPublisher<[PendingExpressTransaction], Never> { get }
var pendingTransactions: [PendingTransaction] { get }
var pendingTransactionsPublisher: AnyPublisher<[PendingTransaction], Never> { get }

func hideTransaction(with id: String)
}
Expand Down Expand Up @@ -246,12 +246,14 @@ class CommonPendingExpressTransactionsManager {
}

extension CommonPendingExpressTransactionsManager: PendingExpressTransactionsManager {
var pendingTransactions: [PendingExpressTransaction] {
transactionsInProgressSubject.value
var pendingTransactions: [PendingTransaction] {
transactionsInProgressSubject.value.map(\.pendingTransaction)
}

var pendingTransactionsPublisher: AnyPublisher<[PendingExpressTransaction], Never> {
transactionsInProgressSubject.eraseToAnyPublisher()
var pendingTransactionsPublisher: AnyPublisher<[PendingTransaction], Never> {
transactionsInProgressSubject
.map { $0.map(\.pendingTransaction) }
.eraseToAnyPublisher()
}

func hideTransaction(with id: String) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,15 +210,6 @@ extension ExpressNotificationEvent: NotificationEvent {
}
}

var isWithLoader: Bool {
switch self {
case .refreshRequired:
return true
default:
return false
}
}

var removingOnFullLoadingState: Bool {
switch self {
case .noDestinationTokens, .refreshRequired, .verificationRequired, .cexOperationFailed, .refunded:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,30 +249,6 @@ class ExpressNotificationManager {
}
}

extension ExpressAPIError {
var localizedTitle: String {
switch errorCode {
case .exchangeNotPossibleError:
Localization.warningExpressPairUnavailableTitle
default:
Localization.warningExpressRefreshRequiredTitle
}
}

var localizedMessage: String {
switch errorCode {
case .exchangeInternalError:
return Localization.expressErrorSwapUnavailable(errorCode.rawValue)
case .exchangeProviderNotActiveError, .exchangeProviderNotAvailableError, .exchangeProviderProviderInternalError:
return Localization.expressErrorSwapPairUnavailable(errorCode.rawValue)
case .exchangeNotPossibleError:
return Localization.warningExpressPairUnavailableMessage(errorCode.rawValue)
default:
return Localization.expressErrorCode(errorCode.localizedDescription)
}
}
}

extension ExpressNotificationManager: NotificationManager {
var notificationInputs: [NotificationViewInput] {
notificationInputsSubject.value
Expand Down
Loading

0 comments on commit 7b1fc8f

Please sign in to comment.