From c2fd96cd0c07f026f677a23028e7e82711e66259 Mon Sep 17 00:00:00 2001 From: EA Date: Fri, 4 Oct 2024 17:46:07 +0600 Subject: [PATCH] Merge CoinValue and TransactionValue into AppValue model --- .../TonConnectAPI/Generation/Package.swift | 2 +- UnstoppableWallet/TonConnectAPI/Package.swift | 9 +- .../Sources/TonConnectAPI/Client.swift | 19 +- .../Sources/TonConnectAPI/Types.swift | 47 ++++- .../project.pbxproj | 18 +- .../Evm/EvmTransactionConverter.swift | 80 ++++---- .../Adapters/Evm/EvmTransactionsAdapter.swift | 2 +- .../Core/Adapters/TonEventConverter.swift | 10 +- .../Tron/TronTransactionAdapter.swift | 2 +- .../Tron/TronTransactionConverter.swift | 20 +- .../Core/Ethereum/CoinService.swift | 16 +- .../Core/Fiat/BaseFiatService.swift | 22 +- .../Core/Fiat/FiatService.swift | 24 +-- .../AccountRestoreWarningManager.swift | 2 +- .../Core/Managers/TonKitManager.swift | 2 +- .../UnstoppableWallet/Models/AmountData.swift | 16 +- .../UnstoppableWallet/Models/AppValue.swift | 194 ++++++++++++++++++ .../UnstoppableWallet/Models/CoinValue.swift | 82 -------- ...inanceChainIncomingTransactionRecord.swift | 6 +- ...inanceChainOutgoingTransactionRecord.swift | 6 +- .../BinanceChainTransactionRecord.swift | 4 +- .../BitcoinIncomingTransactionRecord.swift | 8 +- .../BitcoinOutgoingTransactionRecord.swift | 8 +- .../Bitcoin/BitcoinTransactionRecord.swift | 4 +- .../Evm/ApproveTransactionRecord.swift | 6 +- .../Evm/ContractCallTransactionRecord.swift | 4 +- .../Evm/EvmIncomingTransactionRecord.swift | 12 +- .../Evm/EvmOutgoingTransactionRecord.swift | 6 +- .../Evm/EvmTransactionRecord.swift | 40 +--- ...xternalContractCallTransactionRecord.swift | 6 +- .../Evm/SwapTransactionRecord.swift | 10 +- .../Evm/UnknownSwapTransactionRecord.swift | 6 +- .../Ton/TonTransactionRecord.swift | 18 +- .../TransactionRecord.swift | 24 ++- .../Tron/TronApproveTransactionRecord.swift | 6 +- .../TronContractCallTransactionRecord.swift | 4 +- ...xternalContractCallTransactionRecord.swift | 6 +- .../Tron/TronIncomingTransactionRecord.swift | 6 +- .../Tron/TronOutgoingTransactionRecord.swift | 6 +- .../Tron/TronTransactionRecord.swift | 40 +--- .../Models/TransactionValue.swift | 135 ------------ .../Cex/CexDeposit/CexDepositService.swift | 11 +- .../CexWithdraw/CexAmountInputViewModel.swift | 2 +- .../Cex/CexWithdraw/CexCoinService.swift | 12 +- .../CexWithdraw/CexWithdrawViewModel.swift | 2 +- .../CexWithdrawConfirmViewModel.swift | 4 +- .../CoinSelect/CoinSelectViewModel.swift | 4 +- .../Fee/Eip1559/Eip1559EvmFeeViewModel.swift | 4 +- .../Fee/Legacy/LegacyEvmFeeViewModel.swift | 4 +- .../Main/Workers/TelegramUserHandler.swift | 4 +- .../Approve/MultiSwapApproveView.swift | 4 +- .../MultiSwap/MultiSwapQuotesView.swift | 2 +- .../MultiSwap/MultiSwapSendHandler.swift | 4 +- .../Modules/MultiSwap/MultiSwapView.swift | 2 +- ...aseUniswapMultiSwapConfirmationQuote.swift | 2 +- .../Providers/MultiSwapAllowanceHelper.swift | 24 +-- .../OneInchMultiSwapConfirmationQuote.swift | 2 +- ...orChainMultiSwapBtcConfirmationQuote.swift | 18 +- ...orChainMultiSwapEvmConfirmationQuote.swift | 18 +- .../MultiSwapTokenSelectViewModel.swift | 2 +- .../Modules/Nft/NftHeaderViewModel.swift | 2 +- .../Modules/Nft/NftService.swift | 6 +- .../Modules/Nft/NftViewModel.swift | 4 +- .../Overview/NftAssetOverviewViewModel.swift | 4 +- .../Activity/NftActivityViewModel.swift | 4 +- .../Assets/NftCollectionAssetsViewModel.swift | 4 +- .../NftCollectionOverviewViewModel.swift | 8 +- .../ResendBitcoin/ResendBitcoinService.swift | 10 +- .../ResendBitcoinViewModel.swift | 4 +- .../SendAmountCautionViewModel.swift | 4 +- .../Confirmation/SendConfirmationModule.swift | 8 +- .../SendConfirmationViewModel.swift | 4 +- .../Modules/Send/Fee/SendFeeService.swift | 4 +- .../SendBinanceFeeWarningViewModel.swift | 4 +- .../Binance/SendBinanceFactory.swift | 8 +- .../Bitcoin/SendBitcoinFactory.swift | 24 +-- .../Platforms/Zcash/SendZcashFactory.swift | 8 +- .../SendAvailableBalanceViewModel.swift | 4 +- .../SendEvmTransactionViewModel.swift | 14 +- .../Modules/SendNew/BaseSendBtcData.swift | 4 +- .../Modules/SendNew/BaseSendEvmData.swift | 2 +- .../Modules/SendNew/BinanceSendHandler.swift | 4 +- .../Modules/SendNew/BitcoinFeeData.swift | 4 +- .../Modules/SendNew/BitcoinSendHandler.swift | 4 +- .../Modules/SendNew/EvmDecoration.swift | 8 +- .../Modules/SendNew/EvmFeeData.swift | 4 +- .../FeeSettings/FeeSettingsViewHelper.swift | 6 +- .../SendNew/OutputSelectorViewModel2.swift | 16 +- .../Modules/SendNew/PreSendView.swift | 2 +- .../Modules/SendNew/SendField.swift | 36 ++-- .../Modules/SendNew/TonSendHandler.swift | 10 +- .../Modules/SendNew/TronSendData.swift | 18 +- .../Modules/SendNew/ZcashSendHandler.swift | 4 +- .../SendTronConfirmationViewModel.swift | 10 +- .../Adapters/OneInch/OneInchService.swift | 2 +- .../Adapters/OneInch/OneInchViewModel.swift | 6 +- .../Adapters/Uniswap/SwapViewItemHelper.swift | 8 +- .../Adapters/Uniswap/UniswapService.swift | 2 +- .../Adapters/Uniswap/UniswapViewModel.swift | 6 +- .../Adapters/UniswapV3/UniswapV3Service.swift | 2 +- .../UniswapV3/UniswapV3ViewModel.swift | 6 +- .../Swap/Allowance/SwapAllowanceService.swift | 4 +- .../Allowance/SwapAllowanceViewModel.swift | 2 +- .../SwapPendingAllowanceService.swift | 4 +- .../Swap/CoinCard/SwapCoinCardViewModel.swift | 4 +- .../Modules/Swap/SwapModule.swift | 4 +- .../Modules/TonConnect/TonConnect.swift | 2 +- .../TonConnectConnectViewModel.swift | 2 +- .../TonConnect/TonConnectManager.swift | 2 +- .../TonConnect/TonConnectSendHandler.swift | 34 +-- .../TonConnect/TonConnectSessionCrypto.swift | 2 +- .../TransactionInfoViewItemFactory.swift | 184 ++++++++--------- .../BaseTransactionsService.swift | 4 +- .../TransactionsViewItemFactory.swift | 48 ++--- .../ReceiveAddressViewItemFactory.swift | 4 +- .../Modules/Wallet/WalletService.swift | 6 +- .../Wallet/WalletViewItemFactory.swift | 2 +- .../UserInterface/ValueFormatter.swift | 8 - 118 files changed, 803 insertions(+), 868 deletions(-) create mode 100644 UnstoppableWallet/UnstoppableWallet/Models/AppValue.swift delete mode 100644 UnstoppableWallet/UnstoppableWallet/Models/CoinValue.swift delete mode 100644 UnstoppableWallet/UnstoppableWallet/Models/TransactionValue.swift diff --git a/UnstoppableWallet/TonConnectAPI/Generation/Package.swift b/UnstoppableWallet/TonConnectAPI/Generation/Package.swift index 9e16fe7893..9be09751e8 100644 --- a/UnstoppableWallet/TonConnectAPI/Generation/Package.swift +++ b/UnstoppableWallet/TonConnectAPI/Generation/Package.swift @@ -6,7 +6,7 @@ import PackageDescription let package = Package( name: "TonAPI", platforms: [ - .macOS(.v12), .iOS(.v13) + .macOS(.v12), .iOS(.v13), ], dependencies: [ .package(url: "https://github.com/apple/swift-openapi-generator", .upToNextMinor(from: "0.3.0")), diff --git a/UnstoppableWallet/TonConnectAPI/Package.swift b/UnstoppableWallet/TonConnectAPI/Package.swift index 315fe29e01..39dbf735d1 100644 --- a/UnstoppableWallet/TonConnectAPI/Package.swift +++ b/UnstoppableWallet/TonConnectAPI/Package.swift @@ -6,10 +6,10 @@ import PackageDescription let package = Package( name: "TonConnectAPI", platforms: [ - .macOS(.v12), .iOS(.v13) + .macOS(.v12), .iOS(.v13), ], products: [ - .library(name: "TonConnectAPI", targets: ["TonConnectAPI"]) + .library(name: "TonConnectAPI", targets: ["TonConnectAPI"]), ], dependencies: [ .package(url: "https://github.com/apple/swift-openapi-runtime", .upToNextMinor(from: "0.3.0")), @@ -20,10 +20,9 @@ let package = Package( .product( name: "OpenAPIRuntime", package: "swift-openapi-runtime" - ) + ), ], path: "Sources", - sources: ["TonConnectAPI"] - ) + sources: ["TonConnectAPI"]), ] ) diff --git a/UnstoppableWallet/TonConnectAPI/Sources/TonConnectAPI/Client.swift b/UnstoppableWallet/TonConnectAPI/Sources/TonConnectAPI/Client.swift index 986555708e..4212617dcd 100644 --- a/UnstoppableWallet/TonConnectAPI/Sources/TonConnectAPI/Client.swift +++ b/UnstoppableWallet/TonConnectAPI/Sources/TonConnectAPI/Client.swift @@ -1,15 +1,16 @@ // Generated by swift-openapi-generator, do not modify. @_spi(Generated) import OpenAPIRuntime #if os(Linux) -@preconcurrency import struct Foundation.URL -@preconcurrency import struct Foundation.Data -@preconcurrency import struct Foundation.Date + @preconcurrency import struct Foundation.Data + @preconcurrency import struct Foundation.Date + @preconcurrency import struct Foundation.URL #else -import struct Foundation.URL -import struct Foundation.Data -import struct Foundation.Date + import struct Foundation.Data + import struct Foundation.Date + import struct Foundation.URL #endif import HTTPTypes + public struct Client: APIProtocol { /// The underlying HTTP client. private let client: UniversalClient @@ -27,13 +28,14 @@ public struct Client: APIProtocol { transport: any ClientTransport, middlewares: [any ClientMiddleware] = [] ) { - self.client = .init( + client = .init( serverURL: serverURL, configuration: configuration, transport: transport, middlewares: middlewares ) } + private var converter: Converter { client.converter } /// - Remark: HTTP `GET /events`. /// - Remark: Generated from `#/paths//events/get(events)`. @@ -84,6 +86,7 @@ public struct Client: APIProtocol { } ) } + /// - Remark: HTTP `POST /message`. /// - Remark: Generated from `#/paths//message/post(message)`. public func message(_ input: Operations.message.Input) async throws -> Operations.message.Output { @@ -158,7 +161,7 @@ public struct Client: APIProtocol { } else { throw converter.makeUnexpectedContentTypeError(contentType: contentType) } - return .`default`(statusCode: response.status.code, .init(body: body)) + return .default(statusCode: response.status.code, .init(body: body)) } } ) diff --git a/UnstoppableWallet/TonConnectAPI/Sources/TonConnectAPI/Types.swift b/UnstoppableWallet/TonConnectAPI/Sources/TonConnectAPI/Types.swift index e230c90f9d..9afe9e9139 100644 --- a/UnstoppableWallet/TonConnectAPI/Sources/TonConnectAPI/Types.swift +++ b/UnstoppableWallet/TonConnectAPI/Sources/TonConnectAPI/Types.swift @@ -1,13 +1,13 @@ // Generated by swift-openapi-generator, do not modify. @_spi(Generated) import OpenAPIRuntime #if os(Linux) -@preconcurrency import struct Foundation.URL -@preconcurrency import struct Foundation.Data -@preconcurrency import struct Foundation.Date + @preconcurrency import struct Foundation.Data + @preconcurrency import struct Foundation.Date + @preconcurrency import struct Foundation.URL #else -import struct Foundation.URL -import struct Foundation.Data -import struct Foundation.Date + import struct Foundation.Data + import struct Foundation.Date + import struct Foundation.URL #endif /// A type that performs HTTP operations defined by the OpenAPI document. public protocol APIProtocol: Sendable { @@ -18,16 +18,17 @@ public protocol APIProtocol: Sendable { /// - Remark: Generated from `#/paths//message/post(message)`. func message(_ input: Operations.message.Input) async throws -> Operations.message.Output } + /// Convenience overloads for operation inputs. -extension APIProtocol { +public extension APIProtocol { /// - Remark: HTTP `GET /events`. /// - Remark: Generated from `#/paths//events/get(events)`. - public func events(query: Operations.events.Input.Query, headers: Operations.events.Input.Headers = .init()) + func events(query: Operations.events.Input.Query, headers: Operations.events.Input.Headers = .init()) async throws -> Operations.events.Output { try await events(Operations.events.Input(query: query, headers: headers)) } /// - Remark: HTTP `POST /message`. /// - Remark: Generated from `#/paths//message/post(message)`. - public func message( + func message( query: Operations.message.Input.Query, headers: Operations.message.Input.Headers = .init(), body: Operations.message.Input.Body @@ -35,12 +36,14 @@ extension APIProtocol { try await message(Operations.message.Input(query: query, headers: headers, body: body)) } } + /// Server URLs defined in the OpenAPI document. public enum Servers { public static func server1() throws -> Foundation.URL { try Foundation.URL(validatingOpenAPIServerURL: "https://bridge.tonapi.io/bridge") } } + /// Types generated from the components section of the OpenAPI document. public enum Components { /// Types generated from the `#/components/schemas` section of the OpenAPI document. @@ -52,6 +55,7 @@ public enum Components { /// - Remark: Generated from `#/components/parameters/toParameter`. public typealias toParameter = [Swift.String] } + /// Types generated from the `#/components/requestBodies` section of the OpenAPI document. public enum RequestBodies {} /// Types generated from the `#/components/responses` section of the OpenAPI document. @@ -74,11 +78,13 @@ public enum Components { self.message = message self.statusCode = statusCode } + public enum CodingKeys: String, CodingKey { case message case statusCode } } + /// - Remark: Generated from `#/components/responses/Response/content/application\/json`. case json(Components.Responses.Response.Body.jsonPayload) /// The associated value of the enum case if `self` is `.json`. @@ -93,6 +99,7 @@ public enum Components { } } } + /// Received HTTP response body public var body: Components.Responses.Response.Body /// Creates a new `Response`. @@ -102,9 +109,11 @@ public enum Components { public init(body: Components.Responses.Response.Body) { self.body = body } } } + /// Types generated from the `#/components/headers` section of the OpenAPI document. public enum Headers {} } + /// API operations, with input and output types, generated from `#/paths` in the OpenAPI document. public enum Operations { /// - Remark: HTTP `GET /events`. @@ -128,6 +137,7 @@ public enum Operations { self.last_event_id = last_event_id } } + public var query: Operations.events.Input.Query /// - Remark: Generated from `#/paths/events/GET/header`. public struct Headers: Sendable, Hashable { @@ -141,6 +151,7 @@ public enum Operations { .defaultValues() ) { self.accept = accept } } + public var headers: Operations.events.Input.Headers /// Creates a new `Input`. /// @@ -152,6 +163,7 @@ public enum Operations { self.headers = headers } } + @frozen public enum Output: Sendable, Hashable { public struct Ok: Sendable, Hashable { /// - Remark: Generated from `#/paths/events/GET/responses/200/content`. @@ -170,6 +182,7 @@ public enum Operations { } } } + /// Received HTTP response body public var body: Operations.events.Output.Ok.Body /// Creates a new `Ok`. @@ -178,6 +191,7 @@ public enum Operations { /// - body: Received HTTP response body public init(body: Operations.events.Output.Ok.Body) { self.body = body } } + /// OK /// /// - Remark: Generated from `#/paths//events/get(events)/responses/200`. @@ -196,11 +210,13 @@ public enum Operations { } } } + /// Undocumented response. /// /// A response with a code that is not documented in the OpenAPI document. case undocumented(statusCode: Swift.Int, OpenAPIRuntime.UndocumentedPayload) } + @frozen public enum AcceptableContentType: AcceptableProtocol { case text_event_hyphen_stream case other(Swift.String) @@ -210,15 +226,18 @@ public enum Operations { default: self = .other(rawValue) } } + public var rawValue: Swift.String { switch self { case let .other(string): return string case .text_event_hyphen_stream: return "text/event-stream" } } + public static var allCases: [Self] { [.text_event_hyphen_stream] } } } + /// - Remark: HTTP `POST /message`. /// - Remark: Generated from `#/paths//message/post(message)`. public enum message { @@ -244,6 +263,7 @@ public enum Operations { self.ttl = ttl } } + public var query: Operations.message.Input.Query /// - Remark: Generated from `#/paths/message/POST/header`. public struct Headers: Sendable, Hashable { @@ -257,12 +277,14 @@ public enum Operations { .defaultValues() ) { self.accept = accept } } + public var headers: Operations.message.Input.Headers /// - Remark: Generated from `#/paths/message/POST/requestBody`. @frozen public enum Body: Sendable, Hashable { /// - Remark: Generated from `#/paths/message/POST/requestBody/content/text\/plain`. case plainText(OpenAPIRuntime.HTTPBody) } + public var body: Operations.message.Input.Body /// Creates a new `Input`. /// @@ -280,6 +302,7 @@ public enum Operations { self.body = body } } + @frozen public enum Output: Sendable, Hashable { /// OK /// @@ -299,6 +322,7 @@ public enum Operations { } } } + /// OK /// /// - Remark: Generated from `#/paths//message/post(message)/responses/default`. @@ -312,12 +336,13 @@ public enum Operations { public var `default`: Components.Responses.Response { get throws { switch self { - case let .`default`(_, response): return response + case let .default(_, response): return response default: try throwUnexpectedResponseStatus(expectedStatus: "default", response: self) } } } } + @frozen public enum AcceptableContentType: AcceptableProtocol { case json case other(Swift.String) @@ -327,12 +352,14 @@ public enum Operations { default: self = .other(rawValue) } } + public var rawValue: Swift.String { switch self { case let .other(string): return string case .json: return "application/json" } } + public static var allCases: [Self] { [.json] } } } diff --git a/UnstoppableWallet/UnstoppableWallet.xcodeproj/project.pbxproj b/UnstoppableWallet/UnstoppableWallet.xcodeproj/project.pbxproj index 55a67a4de7..f786eba3b3 100644 --- a/UnstoppableWallet/UnstoppableWallet.xcodeproj/project.pbxproj +++ b/UnstoppableWallet/UnstoppableWallet.xcodeproj/project.pbxproj @@ -155,7 +155,6 @@ 11B3518BEA8865CADA5DA684 /* LaunchScreenManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11B35BEEC0AB0B09C7E4209A /* LaunchScreenManager.swift */; }; 11B3518C9B837CB6C740AABB /* CreatePasscodeModule.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11B352951AD68524C33022C0 /* CreatePasscodeModule.swift */; }; 11B3518F3962FEA97AE6C7CD /* ValueFormatter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11B357A5569EAC7D20CD40B2 /* ValueFormatter.swift */; }; - 11B351909FE0FA637B5B1EC5 /* CoinValue.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11B3513A7417C236F56E5383 /* CoinValue.swift */; }; 11B35191E1A9626DF75D6A51 /* MarkdownViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11B359B9C1E0BB4D32599695 /* MarkdownViewModel.swift */; }; 11B35193A8E75B6D6117FBC7 /* View.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11B352978EC570F59F442BD5 /* View.swift */; }; 11B3519760CB3D8D8C97F689 /* NftContractMetadata.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11B35758E84DE8577A481571 /* NftContractMetadata.swift */; }; @@ -704,7 +703,6 @@ 11B3582D43032F1F2DAEE0E8 /* BalanceHiddenManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11B352FBA1B29357E0120055 /* BalanceHiddenManager.swift */; }; 11B35830E8C818E413DEAAFC /* RecipientAndSlippageMultiSwapSettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11B3599833F166185872A3AC /* RecipientAndSlippageMultiSwapSettingsView.swift */; }; 11B35831AF48B09CE3349E5C /* BalanceCoinIconHolder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11B3560C1FC3F73833FA4439 /* BalanceCoinIconHolder.swift */; }; - 11B358362F756E91646878D0 /* CoinValue.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11B3513A7417C236F56E5383 /* CoinValue.swift */; }; 11B35837076F6B350DFA89E7 /* NftDatabaseStorage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11B35A47AB0887477EDB200C /* NftDatabaseStorage.swift */; }; 11B3583BA552486FB2141F63 /* BtcBlockchainSettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11B352782BB83C4E447092DB /* BtcBlockchainSettingsView.swift */; }; 11B3583C1A73A11974ADAEBB /* EvmNftAdapter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11B35C2397749C5654830540 /* EvmNftAdapter.swift */; }; @@ -1561,7 +1559,7 @@ 2FA5D7C2BEF5739328BA8239 /* TimeLockDataSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2FA5D18B213209DFBB374FE1 /* TimeLockDataSource.swift */; }; 2FA5D7C86A2A55B906953B76 /* EvmSendSettingsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2FA5DA566BEA92F07EDD6916 /* EvmSendSettingsViewController.swift */; }; 2FA5D7CC1617FDF8D2EAFB56 /* SendFeeSettingsAmountCautionViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2FA5D8546E264BEEE654D17B /* SendFeeSettingsAmountCautionViewModel.swift */; }; - 2FA5D7CDF884D2655E066C3E /* TransactionValue.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2FA5DD7B706142D9572E7109 /* TransactionValue.swift */; }; + 2FA5D7CDF884D2655E066C3E /* AppValue.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2FA5DD7B706142D9572E7109 /* AppValue.swift */; }; 2FA5D7DC6E8D68CD487D0825 /* LogRecordManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2FA5D690E78A4568F9FD9554 /* LogRecordManager.swift */; }; 2FA5D7E8805931F9F566668E /* SendEvmCautionsFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2FA5DD57DA8B88537341459E /* SendEvmCautionsFactory.swift */; }; 2FA5D7FD72BD25A4BE7F92D2 /* FeeRateDataSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2FA5D96E9E6A97A7A3FCC5F3 /* FeeRateDataSource.swift */; }; @@ -1606,7 +1604,7 @@ 2FA5DDDE9097C0CD9C0F5BD5 /* EvmFeeModule.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2FA5DB7583D1E1C05C68D4B2 /* EvmFeeModule.swift */; }; 2FA5DE0C343661BC10D2767F /* EvmFeeViewItemFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2FA5DCD7797C13645F3D5F8A /* EvmFeeViewItemFactory.swift */; }; 2FA5DE1153742388007774D3 /* EvmRollupGasDataService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2FA5D924ED6978DD47365B51 /* EvmRollupGasDataService.swift */; }; - 2FA5DE1250DA9D85CD9BF1A3 /* TransactionValue.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2FA5DD7B706142D9572E7109 /* TransactionValue.swift */; }; + 2FA5DE1250DA9D85CD9BF1A3 /* AppValue.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2FA5DD7B706142D9572E7109 /* AppValue.swift */; }; 2FA5DE2D347DBC660830CB41 /* NonceDataSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2FA5D99D617E26CCA419BDD5 /* NonceDataSource.swift */; }; 2FA5DE46C61524144F406FDB /* TimeLockService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2FA5D83BF9F54843ABBA4A5F /* TimeLockService.swift */; }; 2FA5DE68EF4783154A53CCEB /* TransactionInfoService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2FA5D2FB94B5545387375AA3 /* TransactionInfoService.swift */; }; @@ -3254,7 +3252,6 @@ 11B3512EF5B66B852F5E05FB /* BarPageControl.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BarPageControl.swift; sourceTree = ""; }; 11B3513049D27CB1FA264600 /* MnemonicPhraseCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MnemonicPhraseCell.swift; sourceTree = ""; }; 11B35136653741E9703E61DE /* WalletTokenListViewModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WalletTokenListViewModel.swift; sourceTree = ""; }; - 11B3513A7417C236F56E5383 /* CoinValue.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CoinValue.swift; sourceTree = ""; }; 11B35140CD5BF8B1C26A6278 /* MultiSwapButtonState.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MultiSwapButtonState.swift; sourceTree = ""; }; 11B351436E090F4C05243103 /* NftCollectionOverviewViewModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NftCollectionOverviewViewModel.swift; sourceTree = ""; }; 11B351454D8FE8FEDA2C1EC9 /* ScanQrBlurView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ScanQrBlurView.swift; sourceTree = ""; }; @@ -4019,7 +4016,7 @@ 2FA5DD13ED115F4177BE09AB /* ContractCreationTransactionRecord.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ContractCreationTransactionRecord.swift; sourceTree = ""; }; 2FA5DD29DAF03BC6C13B0076 /* EvmTransactionConverter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EvmTransactionConverter.swift; sourceTree = ""; }; 2FA5DD57DA8B88537341459E /* SendEvmCautionsFactory.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SendEvmCautionsFactory.swift; sourceTree = ""; }; - 2FA5DD7B706142D9572E7109 /* TransactionValue.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TransactionValue.swift; sourceTree = ""; }; + 2FA5DD7B706142D9572E7109 /* AppValue.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppValue.swift; sourceTree = ""; }; 2FA5DDCA755F1439B51E12E5 /* EvmFeeService.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EvmFeeService.swift; sourceTree = ""; }; 2FA5DE28AF115C592B9EAD13 /* LegacyEvmFeeViewModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LegacyEvmFeeViewModel.swift; sourceTree = ""; }; 2FA5DE3FC4EA4B42BC982C9A /* BitcoinIncomingTransactionRecord.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BitcoinIncomingTransactionRecord.swift; sourceTree = ""; }; @@ -5775,8 +5772,7 @@ 11B35BDEB703708795B71C4E /* BalanceData.swift */, 11B35D2FC6A2DABFE73D1025 /* EnabledWalletCache.swift */, 11B351E61AB3FB570A4F7C66 /* Wallet.swift */, - 11B3513A7417C236F56E5383 /* CoinValue.swift */, - 2FA5DD7B706142D9572E7109 /* TransactionValue.swift */, + 2FA5DD7B706142D9572E7109 /* AppValue.swift */, 11B3595BAA550B6BEC8C3F72 /* LaunchScreen.swift */, 11B35B451378835F7F060012 /* NftPriceRecord.swift */, 11B359852B313E849499BC19 /* NftAssetRecord.swift */, @@ -9759,8 +9755,7 @@ D3384D522C0703B400515664 /* PriceChangeModeManager.swift in Sources */, D389BC532C0DEF2200724504 /* MarketAdvancedSearchResultsViewModel.swift in Sources */, 11B350388CD7F33B10BD3F4B /* AdapterFactory.swift in Sources */, - 11B358362F756E91646878D0 /* CoinValue.swift in Sources */, - 2FA5D7CDF884D2655E066C3E /* TransactionValue.swift in Sources */, + 2FA5D7CDF884D2655E066C3E /* AppValue.swift in Sources */, 58AAA3F0AFD0D0F5FCD24DEF /* SelectorButton.swift in Sources */, D05E969B2A26278D002CCD71 /* TronApproveTransactionRecord.swift in Sources */, D30D7E622CAACCF300B8CAA7 /* TonConnectSendView.swift in Sources */, @@ -11237,8 +11232,7 @@ 11B3580B9C21B55ACC07B043 /* AdapterManager.swift in Sources */, D30D7E632CAACCF300B8CAA7 /* TonConnectSendView.swift in Sources */, 11B35F25D1209C6DB33ADA55 /* AdapterFactory.swift in Sources */, - 11B351909FE0FA637B5B1EC5 /* CoinValue.swift in Sources */, - 2FA5DE1250DA9D85CD9BF1A3 /* TransactionValue.swift in Sources */, + 2FA5DE1250DA9D85CD9BF1A3 /* AppValue.swift in Sources */, 58AAA72230207B253E2153EA /* SelectorButton.swift in Sources */, D36DE0E4272FD887000BC916 /* OneInchService.swift in Sources */, D05E969A2A26278D002CCD71 /* TronApproveTransactionRecord.swift in Sources */, diff --git a/UnstoppableWallet/UnstoppableWallet/Core/Adapters/Evm/EvmTransactionConverter.swift b/UnstoppableWallet/UnstoppableWallet/Core/Adapters/Evm/EvmTransactionConverter.swift index fbff54d4e1..5d1665c2fb 100644 --- a/UnstoppableWallet/UnstoppableWallet/Core/Adapters/Evm/EvmTransactionConverter.swift +++ b/UnstoppableWallet/UnstoppableWallet/Core/Adapters/Evm/EvmTransactionConverter.swift @@ -34,49 +34,49 @@ class EvmTransactionConverter { return Decimal(sign: sign, exponent: -decimals, significand: significand) } - private func baseCoinValue(value: BigUInt, sign: FloatingPointSign) -> TransactionValue { + private func baseAppValue(value: BigUInt, sign: FloatingPointSign) -> AppValue { let amount = convertAmount(amount: value, decimals: baseToken.decimals, sign: sign) - return .coinValue(token: baseToken, value: amount) + return AppValue(token: baseToken, value: amount) } - private func eip20Value(tokenAddress: EvmKit.Address, value: BigUInt, sign: FloatingPointSign, tokenInfo: Eip20Kit.TokenInfo?) -> TransactionValue { + private func eip20Value(tokenAddress: EvmKit.Address, value: BigUInt, sign: FloatingPointSign, tokenInfo: Eip20Kit.TokenInfo?) -> AppValue { let query = TokenQuery(blockchainType: evmKitWrapper.blockchainType, tokenType: .eip20(address: tokenAddress.hex)) if let token = try? coinManager.token(query: query) { let value = convertAmount(amount: value, decimals: token.decimals, sign: sign) - return .coinValue(token: token, value: value) + return AppValue(token: token, value: value) } else if let tokenInfo { let value = convertAmount(amount: value, decimals: tokenInfo.tokenDecimal, sign: sign) - return .tokenValue(tokenName: tokenInfo.tokenName, tokenCode: tokenInfo.tokenSymbol, tokenDecimals: tokenInfo.tokenDecimal, value: value) + return AppValue(tokenName: tokenInfo.tokenName, tokenCode: tokenInfo.tokenSymbol, tokenDecimals: tokenInfo.tokenDecimal, value: value) } - return .rawValue(value: value) + return AppValue(value: convertAmount(amount: value, decimals: 0, sign: sign)) } private func convertToAmount(token: SwapDecoration.Token, amount: SwapDecoration.Amount, sign: FloatingPointSign) -> SwapTransactionRecord.Amount { switch amount { - case let .exact(value): return .exact(value: convertToTransactionValue(token: token, value: value, sign: sign)) - case let .extremum(value): return .extremum(value: convertToTransactionValue(token: token, value: value, sign: sign)) + case let .exact(value): return .exact(value: convertToAppValue(token: token, value: value, sign: sign)) + case let .extremum(value): return .extremum(value: convertToAppValue(token: token, value: value, sign: sign)) } } - private func convertToTransactionValue(token: SwapDecoration.Token, value: BigUInt, sign: FloatingPointSign) -> TransactionValue { + private func convertToAppValue(token: SwapDecoration.Token, value: BigUInt, sign: FloatingPointSign) -> AppValue { switch token { - case .evmCoin: return baseCoinValue(value: value, sign: sign) + case .evmCoin: return baseAppValue(value: value, sign: sign) case let .eip20Coin(tokenAddress, tokenInfo): return eip20Value(tokenAddress: tokenAddress, value: value, sign: sign, tokenInfo: tokenInfo) } } private func convertToAmount(token: OneInchDecoration.Token, amount: OneInchDecoration.Amount, sign: FloatingPointSign) -> SwapTransactionRecord.Amount { switch amount { - case let .exact(value): return .exact(value: convertToTransactionValue(token: token, value: value, sign: sign)) - case let .extremum(value): return .extremum(value: convertToTransactionValue(token: token, value: value, sign: sign)) + case let .exact(value): return .exact(value: convertToAppValue(token: token, value: value, sign: sign)) + case let .extremum(value): return .extremum(value: convertToAppValue(token: token, value: value, sign: sign)) } } - private func convertToTransactionValue(token: OneInchDecoration.Token, value: BigUInt, sign: FloatingPointSign) -> TransactionValue { + private func convertToAppValue(token: OneInchDecoration.Token, value: BigUInt, sign: FloatingPointSign) -> AppValue { switch token { - case .evmCoin: return baseCoinValue(value: value, sign: sign) + case .evmCoin: return baseAppValue(value: value, sign: sign) case let .eip20Coin(tokenAddress, tokenInfo): return eip20Value(tokenAddress: tokenAddress, value: value, sign: sign, tokenInfo: tokenInfo) } } @@ -103,11 +103,11 @@ class EvmTransactionConverter { incomingEip721Transfers.map { transfer in ContractCallTransactionRecord.TransferEvent( address: transfer.from.eip55, - value: .nftValue( + value: AppValue( nftUid: .evm(blockchainType: source.blockchainType, contractAddress: transfer.contractAddress.hex, tokenId: transfer.tokenId.description), - value: 1, tokenName: transfer.tokenInfo?.tokenName, - tokenSymbol: transfer.tokenInfo?.tokenSymbol + tokenSymbol: transfer.tokenInfo?.tokenSymbol, + value: 1 ) ) } @@ -117,11 +117,11 @@ class EvmTransactionConverter { outgoingEip721Transfers.map { transfer in ContractCallTransactionRecord.TransferEvent( address: transfer.to.eip55, - value: .nftValue( + value: AppValue( nftUid: .evm(blockchainType: source.blockchainType, contractAddress: transfer.contractAddress.hex, tokenId: transfer.tokenId.description), - value: -1, tokenName: transfer.tokenInfo?.tokenName, - tokenSymbol: transfer.tokenInfo?.tokenSymbol + tokenSymbol: transfer.tokenInfo?.tokenSymbol, + value: -1 ) ) } @@ -131,11 +131,11 @@ class EvmTransactionConverter { incomingEip1155Transfers.map { transfer in ContractCallTransactionRecord.TransferEvent( address: transfer.from.eip55, - value: .nftValue( + value: AppValue( nftUid: .evm(blockchainType: source.blockchainType, contractAddress: transfer.contractAddress.hex, tokenId: transfer.tokenId.description), - value: convertAmount(amount: transfer.value, decimals: 0, sign: .plus), tokenName: transfer.tokenInfo?.tokenName, - tokenSymbol: transfer.tokenInfo?.tokenSymbol + tokenSymbol: transfer.tokenInfo?.tokenSymbol, + value: convertAmount(amount: transfer.value, decimals: 0, sign: .plus) ) ) } @@ -145,11 +145,11 @@ class EvmTransactionConverter { outgoingEip1155Transfers.map { transfer in ContractCallTransactionRecord.TransferEvent( address: transfer.to.eip55, - value: .nftValue( + value: AppValue( nftUid: .evm(blockchainType: source.blockchainType, contractAddress: transfer.contractAddress.hex, tokenId: transfer.tokenId.description), - value: convertAmount(amount: transfer.value, decimals: 0, sign: .minus), tokenName: transfer.tokenInfo?.tokenName, - tokenSymbol: transfer.tokenInfo?.tokenSymbol + tokenSymbol: transfer.tokenInfo?.tokenSymbol, + value: convertAmount(amount: transfer.value, decimals: 0, sign: .minus) ) ) } @@ -159,7 +159,7 @@ class EvmTransactionConverter { internalTransactions.map { internalTransaction in ContractCallTransactionRecord.TransferEvent( address: internalTransaction.from.eip55, - value: baseCoinValue(value: internalTransaction.value, sign: .plus) + value: baseAppValue(value: internalTransaction.value, sign: .plus) ) } } @@ -171,7 +171,7 @@ class EvmTransactionConverter { let event = ContractCallTransactionRecord.TransferEvent( address: contractAddress.eip55, - value: baseCoinValue(value: value, sign: .minus) + value: baseAppValue(value: value, sign: .minus) ) return [event] @@ -196,7 +196,7 @@ extension EvmTransactionConverter { transaction: transaction, baseToken: baseToken, from: decoration.from.eip55, - value: baseCoinValue(value: decoration.value, sign: .plus) + value: baseAppValue(value: decoration.value, sign: .plus) ) case let decoration as OutgoingDecoration: @@ -205,7 +205,7 @@ extension EvmTransactionConverter { transaction: transaction, baseToken: baseToken, to: decoration.to.eip55, - value: baseCoinValue(value: decoration.value, sign: .minus), + value: baseAppValue(value: decoration.value, sign: .minus), sentToSelf: decoration.sentToSelf ) @@ -245,7 +245,7 @@ extension EvmTransactionConverter { transaction: transaction, baseToken: baseToken, exchangeAddress: decoration.contractAddress.eip55, - amountIn: .exact(value: convertToTransactionValue(token: decoration.tokenIn, value: decoration.amountIn, sign: .minus)), + amountIn: .exact(value: convertToAppValue(token: decoration.tokenIn, value: decoration.amountIn, sign: .minus)), amountOut: convertToAmount(token: decoration.tokenOut, amount: decoration.amountOut, sign: .plus), recipient: decoration.recipient?.eip55 ) @@ -256,7 +256,7 @@ extension EvmTransactionConverter { transaction: transaction, baseToken: baseToken, exchangeAddress: decoration.contractAddress.eip55, - amountIn: .exact(value: convertToTransactionValue(token: decoration.tokenIn, value: decoration.amountIn, sign: .minus)), + amountIn: .exact(value: convertToAppValue(token: decoration.tokenIn, value: decoration.amountIn, sign: .minus)), amountOut: decoration.tokenOut.map { convertToAmount(token: $0, amount: decoration.amountOut, sign: .plus) }, recipient: nil ) @@ -267,8 +267,8 @@ extension EvmTransactionConverter { transaction: transaction, baseToken: baseToken, exchangeAddress: decoration.contractAddress.eip55, - valueIn: decoration.tokenAmountIn.map { convertToTransactionValue(token: $0.token, value: $0.value, sign: .minus) }, - valueOut: decoration.tokenAmountOut.map { convertToTransactionValue(token: $0.token, value: $0.value, sign: .plus) } + valueIn: decoration.tokenAmountIn.map { convertToAppValue(token: $0.token, value: $0.value, sign: .minus) }, + valueOut: decoration.tokenAmountOut.map { convertToAppValue(token: $0.token, value: $0.value, sign: .plus) } ) case let decoration as Eip721SafeTransferFromDecoration: @@ -277,11 +277,11 @@ extension EvmTransactionConverter { transaction: transaction, baseToken: baseToken, to: decoration.to.eip55, - value: .nftValue( + value: AppValue( nftUid: .evm(blockchainType: source.blockchainType, contractAddress: decoration.contractAddress.hex, tokenId: decoration.tokenId.description), - value: convertAmount(amount: 1, decimals: 0, sign: .minus), tokenName: decoration.tokenInfo?.tokenName, - tokenSymbol: decoration.tokenInfo?.tokenSymbol + tokenSymbol: decoration.tokenInfo?.tokenSymbol, + value: convertAmount(amount: 1, decimals: 0, sign: .minus) ), sentToSelf: decoration.sentToSelf ) @@ -292,11 +292,11 @@ extension EvmTransactionConverter { transaction: transaction, baseToken: baseToken, to: decoration.to.eip55, - value: .nftValue( + value: AppValue( nftUid: .evm(blockchainType: source.blockchainType, contractAddress: decoration.contractAddress.hex, tokenId: decoration.tokenId.description), - value: convertAmount(amount: decoration.value, decimals: 0, sign: .minus), tokenName: decoration.tokenInfo?.tokenName, - tokenSymbol: decoration.tokenInfo?.tokenSymbol + tokenSymbol: decoration.tokenInfo?.tokenSymbol, + value: convertAmount(amount: decoration.value, decimals: 0, sign: .minus) ), sentToSelf: decoration.sentToSelf ) diff --git a/UnstoppableWallet/UnstoppableWallet/Core/Adapters/Evm/EvmTransactionsAdapter.swift b/UnstoppableWallet/UnstoppableWallet/Core/Adapters/Evm/EvmTransactionsAdapter.swift index 0e4839a05e..31db210b9a 100644 --- a/UnstoppableWallet/UnstoppableWallet/Core/Adapters/Evm/EvmTransactionsAdapter.swift +++ b/UnstoppableWallet/UnstoppableWallet/Core/Adapters/Evm/EvmTransactionsAdapter.swift @@ -97,7 +97,7 @@ extension EvmTransactionsAdapter: ITransactionsAdapter { } func transactionsSingle(from: TransactionRecord?, token: MarketKit.Token?, filter: TransactionTypeFilter, address: String?, limit: Int) -> Single<[TransactionRecord]> { - evmKit.transactionsSingle(tagQueries: [tagQuery(token: token, filter: filter, address: address?.lowercased())], fromHash: from.flatMap { $0.transactionHash.hs.hexData }, limit: limit) + evmKit.transactionsSingle(tagQueries: [tagQuery(token: token, filter: filter, address: address?.lowercased())], fromHash: from.flatMap(\.transactionHash.hs.hexData), limit: limit) .map { [weak self] transactions -> [TransactionRecord] in transactions.compactMap { self?.transactionConverter.transactionRecord(fromTransaction: $0) } } diff --git a/UnstoppableWallet/UnstoppableWallet/Core/Adapters/TonEventConverter.swift b/UnstoppableWallet/UnstoppableWallet/Core/Adapters/TonEventConverter.swift index e6abd07589..da49ace890 100644 --- a/UnstoppableWallet/UnstoppableWallet/Core/Adapters/TonEventConverter.swift +++ b/UnstoppableWallet/UnstoppableWallet/Core/Adapters/TonEventConverter.swift @@ -25,20 +25,20 @@ class TonEventConverter { return Decimal(sign: sign, exponent: -decimals, significand: significand) } - private func tonValue(value: BigUInt, sign: FloatingPointSign) -> TransactionValue { + private func tonValue(value: BigUInt, sign: FloatingPointSign) -> AppValue { let amount = convertAmount(amount: value, decimals: baseToken.decimals, sign: sign) - return .coinValue(token: baseToken, value: amount) + return AppValue(token: baseToken, value: amount) } - private func jettonValue(jetton: Jetton, value: BigUInt, sign: FloatingPointSign) -> TransactionValue { + private func jettonValue(jetton: Jetton, value: BigUInt, sign: FloatingPointSign) -> AppValue { let query = TokenQuery(blockchainType: .ton, tokenType: .jetton(address: jetton.address.toString(testOnly: TonKitManager.isTestNet, bounceable: true))) if let token = try? coinManager.token(query: query) { let value = convertAmount(amount: value, decimals: token.decimals, sign: sign) - return .coinValue(token: token, value: value) + return AppValue(token: token, value: value) } else { let value = convertAmount(amount: value, decimals: jetton.decimals, sign: sign) - return .jettonValue(jetton: jetton, value: value) + return AppValue(jetton: jetton, value: value) } } diff --git a/UnstoppableWallet/UnstoppableWallet/Core/Adapters/Tron/TronTransactionAdapter.swift b/UnstoppableWallet/UnstoppableWallet/Core/Adapters/Tron/TronTransactionAdapter.swift index 689a8c96e7..2de836d92c 100644 --- a/UnstoppableWallet/UnstoppableWallet/Core/Adapters/Tron/TronTransactionAdapter.swift +++ b/UnstoppableWallet/UnstoppableWallet/Core/Adapters/Tron/TronTransactionAdapter.swift @@ -100,7 +100,7 @@ extension TronTransactionsAdapter: ITransactionsAdapter { func transactionsSingle(from: TransactionRecord?, token: MarketKit.Token?, filter: TransactionTypeFilter, address: String?, limit: Int) -> Single<[TransactionRecord]> { let address = address.flatMap { try? TronKit.Address(address: $0) }?.hex - let transactions = tronKit.transactions(tagQueries: [tagQuery(token: token, filter: filter, address: address)], fromHash: from.flatMap { $0.transactionHash.hs.hexData }, limit: limit) + let transactions = tronKit.transactions(tagQueries: [tagQuery(token: token, filter: filter, address: address)], fromHash: from.flatMap(\.transactionHash.hs.hexData), limit: limit) return Single.just(transactions.compactMap { transactionConverter.transactionRecord(fromTransaction: $0) }) } diff --git a/UnstoppableWallet/UnstoppableWallet/Core/Adapters/Tron/TronTransactionConverter.swift b/UnstoppableWallet/UnstoppableWallet/Core/Adapters/Tron/TronTransactionConverter.swift index 05c4ea7a8c..5e215d9e4b 100644 --- a/UnstoppableWallet/UnstoppableWallet/Core/Adapters/Tron/TronTransactionConverter.swift +++ b/UnstoppableWallet/UnstoppableWallet/Core/Adapters/Tron/TronTransactionConverter.swift @@ -30,23 +30,23 @@ class TronTransactionConverter { return Decimal(sign: sign, exponent: -decimals, significand: significand) } - private func baseCoinValue(value: Int, sign: FloatingPointSign) -> TransactionValue { + private func baseAppValue(value: Int, sign: FloatingPointSign) -> AppValue { let amount = convertAmount(amount: BigUInt(value), decimals: baseToken.decimals, sign: sign) - return .coinValue(token: baseToken, value: amount) + return AppValue(token: baseToken, value: amount) } - private func eip20Value(tokenAddress: TronKit.Address, value: BigUInt, sign: FloatingPointSign, tokenInfo: TokenInfo?) -> TransactionValue { + private func eip20Value(tokenAddress: TronKit.Address, value: BigUInt, sign: FloatingPointSign, tokenInfo: TokenInfo?) -> AppValue { let query = TokenQuery(blockchainType: .tron, tokenType: .eip20(address: tokenAddress.base58)) if let token = try? coinManager.token(query: query) { let value = convertAmount(amount: value, decimals: token.decimals, sign: sign) - return .coinValue(token: token, value: value) + return AppValue(token: token, value: value) } else if let tokenInfo { let value = convertAmount(amount: value, decimals: tokenInfo.tokenDecimal, sign: sign) - return .tokenValue(tokenName: tokenInfo.tokenName, tokenCode: tokenInfo.tokenSymbol, tokenDecimals: tokenInfo.tokenDecimal, value: value) + return AppValue(tokenName: tokenInfo.tokenName, tokenCode: tokenInfo.tokenSymbol, tokenDecimals: tokenInfo.tokenDecimal, value: value) } - return .rawValue(value: value) + return AppValue(value: convertAmount(amount: value, decimals: 0, sign: sign)) } private func transferEvents(incomingTrc20Transfers: [Trc20TransferEvent]) -> [TronContractCallTransactionRecord.TransferEvent] { @@ -71,7 +71,7 @@ class TronTransactionConverter { internalTransactions.map { internalTransaction in TronContractCallTransactionRecord.TransferEvent( address: internalTransaction.from.base58, - value: baseCoinValue(value: internalTransaction.value, sign: .plus) + value: baseAppValue(value: internalTransaction.value, sign: .plus) ) } } @@ -83,7 +83,7 @@ class TronTransactionConverter { let event = TronContractCallTransactionRecord.TransferEvent( address: contractAddress.base58, - value: baseCoinValue(value: value, sign: .minus) + value: baseAppValue(value: value, sign: .minus) ) return [event] @@ -104,7 +104,7 @@ extension TronTransactionConverter { transaction: transaction, baseToken: baseToken, from: transfer.ownerAddress.base58, - value: baseCoinValue(value: transfer.amount, sign: .plus), + value: baseAppValue(value: transfer.amount, sign: .plus), spam: transfer.amount < 10 ) } else { @@ -113,7 +113,7 @@ extension TronTransactionConverter { transaction: transaction, baseToken: baseToken, to: transfer.toAddress.base58, - value: baseCoinValue(value: transfer.amount, sign: .minus), + value: baseAppValue(value: transfer.amount, sign: .minus), sentToSelf: transfer.toAddress == tronKit.address ) } diff --git a/UnstoppableWallet/UnstoppableWallet/Core/Ethereum/CoinService.swift b/UnstoppableWallet/UnstoppableWallet/Core/Ethereum/CoinService.swift index d646d99767..ec74838fae 100644 --- a/UnstoppableWallet/UnstoppableWallet/Core/Ethereum/CoinService.swift +++ b/UnstoppableWallet/UnstoppableWallet/Core/Ethereum/CoinService.swift @@ -5,8 +5,8 @@ import MarketKit protocol ICoinService { var rate: CurrencyValue? { get } - func coinValue(value: BigUInt) -> CoinValue - func coinValue(value: Decimal) -> CoinValue + func appValue(value: BigUInt) -> AppValue + func appValue(value: Decimal) -> AppValue func monetaryValue(value: BigUInt) -> Decimal func fractionalMonetaryValue(value: Decimal) -> BigUInt func amountData(value: Decimal, sign: FloatingPointSign) -> AmountData @@ -34,18 +34,18 @@ extension CoinService: ICoinService { } } - func coinValue(value: BigUInt) -> CoinValue { + func appValue(value: BigUInt) -> AppValue { let decimalValue = Decimal(bigUInt: value, decimals: token.decimals) ?? 0 - return coinValue(value: decimalValue) + return appValue(value: decimalValue) } - func coinValue(value: Decimal) -> CoinValue { - CoinValue(kind: .token(token: token), value: value) + func appValue(value: Decimal) -> AppValue { + AppValue(token: token, value: value) } // Example: Dollar, Bitcoin, Ether, etc func monetaryValue(value: BigUInt) -> Decimal { - coinValue(value: value).value + appValue(value: value).value } // Example: Cent, Satoshi, GWei, etc @@ -55,7 +55,7 @@ extension CoinService: ICoinService { func amountData(value: Decimal, sign: FloatingPointSign) -> AmountData { AmountData( - coinValue: CoinValue(kind: .token(token: token), value: Decimal(sign: sign, exponent: value.exponent, significand: value.significand)), + appValue: AppValue(token: token, value: Decimal(sign: sign, exponent: value.exponent, significand: value.significand)), currencyValue: rate.map { CurrencyValue(currency: $0.currency, value: $0.value * value) } diff --git a/UnstoppableWallet/UnstoppableWallet/Core/Fiat/BaseFiatService.swift b/UnstoppableWallet/UnstoppableWallet/Core/Fiat/BaseFiatService.swift index 8edca7e4ff..bab92464aa 100644 --- a/UnstoppableWallet/UnstoppableWallet/Core/Fiat/BaseFiatService.swift +++ b/UnstoppableWallet/UnstoppableWallet/Core/Fiat/BaseFiatService.swift @@ -14,8 +14,8 @@ class BaseFiatService { private var price: Decimal? - private var coinValueKind: CoinValue.Kind? - var token: Token? { coinValueKind?.token } + private var appValueKind: AppValue.Kind? + var token: Token? { appValueKind?.token } private let updatedSubject = PassthroughSubject() @@ -64,23 +64,21 @@ class BaseFiatService { extension BaseFiatService { func set(token: Token?) { - set(coinValueKind: token.flatMap { .token(token: $0) }) + set(appValueKind: token.flatMap { .token(token: $0) }) } - func set(coinValueKind: CoinValue.Kind?) { - self.coinValueKind = coinValueKind + func set(appValueKind: AppValue.Kind?) { + self.appValueKind = appValueKind cancellables = Set() var fetching = true - if let coinValueKind { - switch coinValueKind { + if let appValueKind { + switch appValueKind { case let .token(token): fetchRate(coin: token.coin, subscribe: !token.isCustom) - case let .coin(coin, _): - fetchRate(coin: coin, subscribe: false) - case let .cexAsset(cexAsset): - if let coin = cexAsset.coin { + default: + if let coin = appValueKind.coin { fetchRate(coin: coin, subscribe: false) } else { fetching = false @@ -105,7 +103,7 @@ extension BaseFiatService { } private func coinAmountInfo(amount: Decimal) -> AmountInfo? { - coinValueKind.map { .coinValue(coinValue: CoinValue(kind: $0, value: amount)) } + appValueKind.map { .appValue(appValue: AppValue(kind: $0, value: amount)) } } private func amountInfo(amount: Decimal, type: AmountTypeSwitchService.AmountType) -> AmountInfo? { diff --git a/UnstoppableWallet/UnstoppableWallet/Core/Fiat/FiatService.swift b/UnstoppableWallet/UnstoppableWallet/Core/Fiat/FiatService.swift index 6eeee5fc98..269e50a54e 100644 --- a/UnstoppableWallet/UnstoppableWallet/Core/Fiat/FiatService.swift +++ b/UnstoppableWallet/UnstoppableWallet/Core/Fiat/FiatService.swift @@ -13,8 +13,8 @@ class FiatService { private let currencyManager: CurrencyManager private let marketKit: MarketKit.Kit - private var coinValueKind: CoinValue.Kind? - var token: Token? { coinValueKind?.token } + private var appValueKind: AppValue.Kind? + var token: Token? { appValueKind?.token } private var price: Decimal? { didSet { @@ -85,8 +85,8 @@ class FiatService { private func sync() { queue.async { - if let coinValueKind = self.coinValueKind { - let coinAmountInfo: AmountInfo = .coinValue(coinValue: CoinValue(kind: coinValueKind, value: self.coinAmount)) + if let appValueKind = self.appValueKind { + let coinAmountInfo: AmountInfo = .appValue(appValue: AppValue(kind: appValueKind, value: self.coinAmount)) let currencyAmountInfo: AmountInfo? = self.currencyAmount.map { .currencyValue(currencyValue: CurrencyValue(currency: self.currency, value: $0)) } switch self.switchService.amountType { @@ -157,23 +157,21 @@ extension FiatService { } func set(token: Token?) { - set(coinValueKind: token.flatMap { .token(token: $0) }) + set(appValueKind: token.flatMap { .token(token: $0) }) } - func set(coinValueKind: CoinValue.Kind?) { - self.coinValueKind = coinValueKind + func set(appValueKind: AppValue.Kind?) { + self.appValueKind = appValueKind cancellables = Set() var fetching = true - if let coinValueKind { - switch coinValueKind { + if let appValueKind { + switch appValueKind { case let .token(token): fetchRate(coin: token.coin, subscribe: !token.isCustom) - case let .coin(coin, _): - fetchRate(coin: coin, subscribe: false) - case let .cexAsset(cexAsset): - if let coin = cexAsset.coin { + default: + if let coin = appValueKind.coin { fetchRate(coin: coin, subscribe: false) } else { fetching = false diff --git a/UnstoppableWallet/UnstoppableWallet/Core/Managers/AccountRestoreWarningManager.swift b/UnstoppableWallet/UnstoppableWallet/Core/Managers/AccountRestoreWarningManager.swift index f192e8c959..3dd102506c 100644 --- a/UnstoppableWallet/UnstoppableWallet/Core/Managers/AccountRestoreWarningManager.swift +++ b/UnstoppableWallet/UnstoppableWallet/Core/Managers/AccountRestoreWarningManager.swift @@ -1,5 +1,5 @@ -import Foundation import Combine +import Foundation class AccountRestoreWarningManager { private let accountManager: AccountManager diff --git a/UnstoppableWallet/UnstoppableWallet/Core/Managers/TonKitManager.swift b/UnstoppableWallet/UnstoppableWallet/Core/Managers/TonKitManager.swift index 4f609cac6b..9a894e1664 100644 --- a/UnstoppableWallet/UnstoppableWallet/Core/Managers/TonKitManager.swift +++ b/UnstoppableWallet/UnstoppableWallet/Core/Managers/TonKitManager.swift @@ -68,7 +68,7 @@ class TonKitManager { if restoreState.shouldRestore || account.watchAccount, !restoreState.initialRestored { jettonBalanceCancellable = tonKit.jettonBalanceMapPublisher .sink { [weak self, restoreStateManager] in - self?.handle(jettons: $0.values.map { $0.jetton }, account: account) + self?.handle(jettons: $0.values.map(\.jetton), account: account) restoreStateManager.setInitialRestored(account: account, blockchainType: .ton) diff --git a/UnstoppableWallet/UnstoppableWallet/Models/AmountData.swift b/UnstoppableWallet/UnstoppableWallet/Models/AmountData.swift index e86f8c584b..0c3076358a 100644 --- a/UnstoppableWallet/UnstoppableWallet/Models/AmountData.swift +++ b/UnstoppableWallet/UnstoppableWallet/Models/AmountData.swift @@ -4,13 +4,13 @@ import RxSwift import UIKit enum AmountInfo { - case coinValue(coinValue: CoinValue) + case appValue(appValue: AppValue) case currencyValue(currencyValue: CurrencyValue) var formattedFull: String? { switch self { - case let .coinValue(coinValue): - return coinValue.formattedFull + case let .appValue(appValue): + return appValue.formattedFull() case let .currencyValue(currencyValue): return currencyValue.formattedFull } @@ -19,26 +19,26 @@ enum AmountInfo { var value: Decimal { switch self { case let .currencyValue(currencyValue): return currencyValue.value - case let .coinValue(coinValue): return coinValue.value + case let .appValue(appValue): return appValue.value } } var decimal: Int { switch self { case let .currencyValue(currencyValue): return currencyValue.currency.decimal - case let .coinValue(coinValue): return coinValue.decimals + case let .appValue(appValue): return appValue.decimals ?? 0 } } } struct AmountData { - let coinValue: CoinValue + let appValue: AppValue let currencyValue: CurrencyValue? var formattedFull: String { var parts = [String]() - if let formatted = coinValue.formattedFull { + if let formatted = appValue.formattedFull() { parts.append(formatted) } @@ -52,7 +52,7 @@ struct AmountData { var formattedShort: String { var result = "" - if let formatted = ValueFormatter.instance.formatShort(coinValue: coinValue) { + if let formatted = appValue.formattedShort() { result += formatted } diff --git a/UnstoppableWallet/UnstoppableWallet/Models/AppValue.swift b/UnstoppableWallet/UnstoppableWallet/Models/AppValue.swift new file mode 100644 index 0000000000..71155562a1 --- /dev/null +++ b/UnstoppableWallet/UnstoppableWallet/Models/AppValue.swift @@ -0,0 +1,194 @@ +import Foundation +import MarketKit +import TonKit + +struct AppValue { + let kind: Kind + let value: Decimal + + init(kind: Kind, value: Decimal) { + self.kind = kind + self.value = value + } + + init(token: Token, value: Decimal) { + kind = .token(token: token) + self.value = value + } + + init(tokenName: String, tokenCode: String, tokenDecimals: Int, value: Decimal) { + kind = .eip20Token(tokenName: tokenName, tokenCode: tokenCode, tokenDecimals: tokenDecimals) + self.value = value + } + + init(jetton: Jetton, value: Decimal) { + kind = .jetton(jetton: jetton) + self.value = value + } + + init(nftUid: NftUid, tokenName: String?, tokenSymbol: String?, value: Decimal) { + kind = .nft(nftUid: nftUid, tokenName: tokenName, tokenSymbol: tokenSymbol) + self.value = value + } + + init(cexAsset: CexAsset, value: Decimal) { + kind = .cexAsset(cexAsset: cexAsset) + self.value = value + } + + init(value: Decimal) { + kind = .raw + self.value = value + } + + var token: Token? { + kind.token + } + + var coin: Coin? { + kind.coin + } + + var name: String { + switch kind { + case let .token(token): return token.coin.name + case let .coin(coin, _): return coin.name + case let .eip20Token(tokenName, _, _): return tokenName + case let .jetton(jetton): return jetton.name + case let .nft(nftUid, tokenName, _): return tokenName.map { "\($0) #\(nftUid.tokenId)" } ?? "#\(nftUid.tokenId)" + case let .cexAsset(cexAsset): return cexAsset.coinName + case .raw: return "" + } + } + + var code: String { + switch kind { + case let .token(token): return token.coin.code + case let .coin(coin, _): return coin.code + case let .eip20Token(_, tokenCode, _): return tokenCode + case let .jetton(jetton): return jetton.symbol + case let .nft(_, _, tokenSymbol): return tokenSymbol ?? "NFT" + case let .cexAsset(cexAsset): return cexAsset.coinCode + case .raw: return "" + } + } + + var decimals: Int? { + switch kind { + case let .token(token): return token.decimals + case let .coin(_, decimals): return decimals + case let .eip20Token(_, _, tokenDecimals): return tokenDecimals + case let .jetton(jetton): return jetton.decimals + case .nft: return nil + case .cexAsset: return CexAsset.decimals + case .raw: return nil + } + } + + var isMaxValue: Bool { + decimals.map { value.isMaxValue(decimals: $0) } ?? false + } + + var tokenProtocol: TokenProtocol? { + switch kind { + case let .token(token): return token.type.tokenProtocol + case .eip20Token: return .eip20 + case .jetton: return .jetton + default: return nil + } + } + + var nftUid: NftUid? { + switch kind { + case let .nft(nftUid, _, _): return nftUid + default: return nil + } + } + + var zeroValue: Bool { + value == 0 + } + + var abs: AppValue { + AppValue(kind: kind, value: value.magnitude) + } + + var negative: AppValue { + AppValue(kind: kind, value: Decimal(sign: .minus, exponent: value.exponent, significand: value.significand)) + } + + var infinity: String { + "∞ \(code)" + } + + func formattedFull(signType: ValueFormatter.SignType = .never) -> String? { + switch kind { + case let .token(token): return ValueFormatter.instance.formatFull(value: value, decimalCount: token.decimals, symbol: code, signType: signType) + case let .coin(_, decimals): return ValueFormatter.instance.formatFull(value: value, decimalCount: decimals, symbol: code, signType: signType) + case let .eip20Token(_, _, tokenDecimals): return ValueFormatter.instance.formatFull(value: value, decimalCount: tokenDecimals, symbol: code, signType: signType) + case let .jetton(jetton): return ValueFormatter.instance.formatFull(value: value, decimalCount: jetton.decimals, symbol: code, signType: signType) + case .nft: return "\(value.sign == .plus ? "+" : "")\(value) \(code)" + case .cexAsset: return ValueFormatter.instance.formatFull(value: value, decimalCount: CexAsset.decimals, symbol: code, signType: signType) + case .raw: return nil + } + } + + func formattedShort(signType: ValueFormatter.SignType = .never) -> String? { + switch kind { + case let .token(token): return ValueFormatter.instance.formatShort(value: value, decimalCount: token.decimals, symbol: code, signType: signType) + case let .coin(_, decimals): return ValueFormatter.instance.formatShort(value: value, decimalCount: decimals, symbol: code, signType: signType) + case let .eip20Token(_, _, tokenDecimals): return ValueFormatter.instance.formatShort(value: value, decimalCount: tokenDecimals, symbol: code, signType: signType) + case let .jetton(jetton): return ValueFormatter.instance.formatShort(value: value, decimalCount: jetton.decimals, symbol: code, signType: signType) + case .nft: return "\(value.sign == .plus ? "+" : "")\(value) \(code)" + case .cexAsset: return ValueFormatter.instance.formatShort(value: value, decimalCount: CexAsset.decimals, symbol: code, signType: signType) + case .raw: return nil + } + } +} + +extension AppValue { + enum Kind: Equatable { + case token(token: Token) + case coin(coin: Coin, decimals: Int) + case eip20Token(tokenName: String, tokenCode: String, tokenDecimals: Int) + case jetton(jetton: Jetton) + case nft(nftUid: NftUid, tokenName: String?, tokenSymbol: String?) + case cexAsset(cexAsset: CexAsset) + case raw + + var token: Token? { + switch self { + case let .token(token): return token + default: return nil + } + } + + var coin: Coin? { + switch self { + case let .token(token): return token.coin + case let .coin(coin, _): return coin + case let .cexAsset(cexAsset): return cexAsset.coin + default: return nil + } + } + + static func == (lhs: Kind, rhs: Kind) -> Bool { + switch (lhs, rhs) { + case let (.token(lhsToken), .token(rhsToken)): return lhsToken == rhsToken + case let (.coin(lhsCoin, lhsDecimals), .coin(rhsCoin, rhsDecimals)): return lhsCoin == rhsCoin && lhsDecimals == rhsDecimals + case let (.eip20Token(lhsTokenName, lhsTokenCode, lhsTokenDecimals), .eip20Token(rhsTokenName, rhsTokenCode, rhsTokenDecimals)): return lhsTokenName == rhsTokenName && lhsTokenCode == rhsTokenCode && lhsTokenDecimals == rhsTokenDecimals + case let (.jetton(lhsJetton), .jetton(rhsJetton)): return lhsJetton == rhsJetton + case let (.nft(lhsNftUid, _, _), .nft(rhsNftUid, _, _)): return lhsNftUid == rhsNftUid + case let (.cexAsset(lhsCexAsset), .cexAsset(rhsCexAsset)): return lhsCexAsset == rhsCexAsset + case (.raw, .raw): return true + default: return false + } + } + } +} + +extension AppValue: Equatable { + static func == (lhs: AppValue, rhs: AppValue) -> Bool { + lhs.kind == rhs.kind && lhs.value == rhs.value + } +} diff --git a/UnstoppableWallet/UnstoppableWallet/Models/CoinValue.swift b/UnstoppableWallet/UnstoppableWallet/Models/CoinValue.swift deleted file mode 100644 index 8d40bd57a2..0000000000 --- a/UnstoppableWallet/UnstoppableWallet/Models/CoinValue.swift +++ /dev/null @@ -1,82 +0,0 @@ -import BigInt -import Foundation -import MarketKit - -struct CoinValue { - let kind: Kind - let value: Decimal - - var isMaxValue: Bool { - value.isMaxValue(decimals: kind.decimals) - } - - var abs: CoinValue { - CoinValue(kind: kind, value: value.magnitude) - } - - var symbol: String { - kind.symbol - } - - var decimals: Int { - kind.decimals - } - - var formattedFull: String? { - ValueFormatter.instance.formatFull(coinValue: self) - } - - var formattedShort: String? { - ValueFormatter.instance.formatShort(coinValue: self) - } - - var infinity: String { - "∞ \(kind.symbol)" - } -} - -extension CoinValue { - enum Kind: Equatable { - case token(token: Token) - case coin(coin: Coin, decimals: Int) - case cexAsset(cexAsset: CexAsset) - - var token: Token? { - switch self { - case let .token(token): return token - case .coin, .cexAsset: return nil - } - } - - var decimals: Int { - switch self { - case let .token(token): return token.decimals - case let .coin(_, decimals): return decimals - case .cexAsset: return CexAsset.decimals - } - } - - var symbol: String { - switch self { - case let .token(token): return token.coin.code - case let .coin(coin, _): return coin.code - case let .cexAsset(cexAsset): return cexAsset.coinCode - } - } - - static func == (lhs: Kind, rhs: Kind) -> Bool { - switch (lhs, rhs) { - case let (.token(lhsToken), .token(rhsToken)): return lhsToken == rhsToken - case let (.coin(lhsCoin, lhsDecimals), .coin(rhsCoin, rhsDecimals)): return lhsCoin == rhsCoin && lhsDecimals == rhsDecimals - case let (.cexAsset(lhsCexAsset), .cexAsset(rhsCexAsset)): return lhsCexAsset == rhsCexAsset - default: return false - } - } - } -} - -extension CoinValue: Equatable { - public static func == (lhs: CoinValue, rhs: CoinValue) -> Bool { - lhs.kind == rhs.kind && lhs.value == rhs.value - } -} diff --git a/UnstoppableWallet/UnstoppableWallet/Models/TransactionRecords/BinanceChain/BinanceChainIncomingTransactionRecord.swift b/UnstoppableWallet/UnstoppableWallet/Models/TransactionRecords/BinanceChain/BinanceChainIncomingTransactionRecord.swift index c2a6c9dda2..7364a22ac6 100644 --- a/UnstoppableWallet/UnstoppableWallet/Models/TransactionRecords/BinanceChain/BinanceChainIncomingTransactionRecord.swift +++ b/UnstoppableWallet/UnstoppableWallet/Models/TransactionRecords/BinanceChain/BinanceChainIncomingTransactionRecord.swift @@ -2,17 +2,17 @@ import BinanceChainKit import MarketKit class BinanceChainIncomingTransactionRecord: BinanceChainTransactionRecord { - let value: TransactionValue + let value: AppValue let from: String init(source: TransactionSource, transaction: TransactionInfo, feeToken: Token, token: Token) { - value = .coinValue(token: token, value: transaction.amount) + value = AppValue(token: token, value: transaction.amount) from = transaction.from super.init(source: source, transaction: transaction, feeToken: feeToken) } - override var mainValue: TransactionValue? { + override var mainValue: AppValue? { value } } diff --git a/UnstoppableWallet/UnstoppableWallet/Models/TransactionRecords/BinanceChain/BinanceChainOutgoingTransactionRecord.swift b/UnstoppableWallet/UnstoppableWallet/Models/TransactionRecords/BinanceChain/BinanceChainOutgoingTransactionRecord.swift index ee93eafab4..f4333c1f19 100644 --- a/UnstoppableWallet/UnstoppableWallet/Models/TransactionRecords/BinanceChain/BinanceChainOutgoingTransactionRecord.swift +++ b/UnstoppableWallet/UnstoppableWallet/Models/TransactionRecords/BinanceChain/BinanceChainOutgoingTransactionRecord.swift @@ -3,19 +3,19 @@ import Foundation import MarketKit class BinanceChainOutgoingTransactionRecord: BinanceChainTransactionRecord { - let value: TransactionValue + let value: AppValue let to: String let sentToSelf: Bool init(source: TransactionSource, transaction: TransactionInfo, feeToken: Token, token: Token, sentToSelf: Bool) { - value = .coinValue(token: token, value: Decimal(sign: .minus, exponent: transaction.amount.exponent, significand: transaction.amount.significand)) + value = AppValue(token: token, value: Decimal(sign: .minus, exponent: transaction.amount.exponent, significand: transaction.amount.significand)) to = transaction.to self.sentToSelf = sentToSelf super.init(source: source, transaction: transaction, feeToken: feeToken) } - override var mainValue: TransactionValue? { + override var mainValue: AppValue? { value } } diff --git a/UnstoppableWallet/UnstoppableWallet/Models/TransactionRecords/BinanceChain/BinanceChainTransactionRecord.swift b/UnstoppableWallet/UnstoppableWallet/Models/TransactionRecords/BinanceChain/BinanceChainTransactionRecord.swift index 275ec18c05..d876a7c432 100644 --- a/UnstoppableWallet/UnstoppableWallet/Models/TransactionRecords/BinanceChain/BinanceChainTransactionRecord.swift +++ b/UnstoppableWallet/UnstoppableWallet/Models/TransactionRecords/BinanceChain/BinanceChainTransactionRecord.swift @@ -2,11 +2,11 @@ import BinanceChainKit import MarketKit class BinanceChainTransactionRecord: TransactionRecord { - let fee: TransactionValue + let fee: AppValue let memo: String? init(source: TransactionSource, transaction: TransactionInfo, feeToken: Token) { - fee = .coinValue(token: feeToken, value: BinanceAdapter.transferFee) + fee = AppValue(token: feeToken, value: BinanceAdapter.transferFee) memo = transaction.memo super.init( diff --git a/UnstoppableWallet/UnstoppableWallet/Models/TransactionRecords/Bitcoin/BitcoinIncomingTransactionRecord.swift b/UnstoppableWallet/UnstoppableWallet/Models/TransactionRecords/Bitcoin/BitcoinIncomingTransactionRecord.swift index c474576001..f61ddb76ff 100644 --- a/UnstoppableWallet/UnstoppableWallet/Models/TransactionRecords/Bitcoin/BitcoinIncomingTransactionRecord.swift +++ b/UnstoppableWallet/UnstoppableWallet/Models/TransactionRecords/Bitcoin/BitcoinIncomingTransactionRecord.swift @@ -2,14 +2,14 @@ import Foundation import MarketKit class BitcoinIncomingTransactionRecord: BitcoinTransactionRecord { - let value: TransactionValue + let value: AppValue let from: String? init(token: Token, source: TransactionSource, uid: String, transactionHash: String, transactionIndex: Int, blockHeight: Int?, confirmationsThreshold: Int?, date: Date, fee: Decimal?, failed: Bool, lockInfo: TransactionLockInfo?, conflictingHash: String?, showRawTransaction: Bool, amount: Decimal, from: String?, memo: String? = nil) { - value = .coinValue(token: token, value: amount) + value = AppValue(token: token, value: amount) self.from = from super.init( @@ -20,7 +20,7 @@ class BitcoinIncomingTransactionRecord: BitcoinTransactionRecord { blockHeight: blockHeight, confirmationsThreshold: confirmationsThreshold, date: date, - fee: fee.flatMap { .coinValue(token: token, value: $0) }, + fee: fee.flatMap { AppValue(token: token, value: $0) }, failed: failed, lockInfo: lockInfo, conflictingHash: conflictingHash, @@ -29,7 +29,7 @@ class BitcoinIncomingTransactionRecord: BitcoinTransactionRecord { ) } - override var mainValue: TransactionValue? { + override var mainValue: AppValue? { value } } diff --git a/UnstoppableWallet/UnstoppableWallet/Models/TransactionRecords/Bitcoin/BitcoinOutgoingTransactionRecord.swift b/UnstoppableWallet/UnstoppableWallet/Models/TransactionRecords/Bitcoin/BitcoinOutgoingTransactionRecord.swift index d2d07b9307..7c1e223faf 100644 --- a/UnstoppableWallet/UnstoppableWallet/Models/TransactionRecords/Bitcoin/BitcoinOutgoingTransactionRecord.swift +++ b/UnstoppableWallet/UnstoppableWallet/Models/TransactionRecords/Bitcoin/BitcoinOutgoingTransactionRecord.swift @@ -2,7 +2,7 @@ import Foundation import MarketKit class BitcoinOutgoingTransactionRecord: BitcoinTransactionRecord { - let value: TransactionValue + let value: AppValue let to: String? let sentToSelf: Bool let replaceable: Bool @@ -11,7 +11,7 @@ class BitcoinOutgoingTransactionRecord: BitcoinTransactionRecord { lockInfo: TransactionLockInfo?, conflictingHash: String?, showRawTransaction: Bool, amount: Decimal, to: String?, sentToSelf: Bool, memo: String? = nil, replaceable: Bool) { - value = .coinValue(token: token, value: Decimal(sign: .minus, exponent: amount.exponent, significand: amount.significand)) + value = AppValue(token: token, value: Decimal(sign: .minus, exponent: amount.exponent, significand: amount.significand)) self.to = to self.sentToSelf = sentToSelf self.replaceable = replaceable @@ -24,7 +24,7 @@ class BitcoinOutgoingTransactionRecord: BitcoinTransactionRecord { blockHeight: blockHeight, confirmationsThreshold: confirmationsThreshold, date: date, - fee: fee.flatMap { .coinValue(token: token, value: $0) }, + fee: fee.flatMap { AppValue(token: token, value: $0) }, failed: failed, lockInfo: lockInfo, conflictingHash: conflictingHash, @@ -33,7 +33,7 @@ class BitcoinOutgoingTransactionRecord: BitcoinTransactionRecord { ) } - override var mainValue: TransactionValue? { + override var mainValue: AppValue? { value } } diff --git a/UnstoppableWallet/UnstoppableWallet/Models/TransactionRecords/Bitcoin/BitcoinTransactionRecord.swift b/UnstoppableWallet/UnstoppableWallet/Models/TransactionRecords/Bitcoin/BitcoinTransactionRecord.swift index b595a3f3c5..d2574e5c40 100644 --- a/UnstoppableWallet/UnstoppableWallet/Models/TransactionRecords/Bitcoin/BitcoinTransactionRecord.swift +++ b/UnstoppableWallet/UnstoppableWallet/Models/TransactionRecords/Bitcoin/BitcoinTransactionRecord.swift @@ -3,12 +3,12 @@ import MarketKit class BitcoinTransactionRecord: TransactionRecord { let lockInfo: TransactionLockInfo? - let fee: TransactionValue? + let fee: AppValue? let conflictingHash: String? let showRawTransaction: Bool let memo: String? - init(source: TransactionSource, uid: String, transactionHash: String, transactionIndex: Int, blockHeight: Int?, confirmationsThreshold: Int?, date: Date, fee: TransactionValue?, failed: Bool, + init(source: TransactionSource, uid: String, transactionHash: String, transactionIndex: Int, blockHeight: Int?, confirmationsThreshold: Int?, date: Date, fee: AppValue?, failed: Bool, lockInfo: TransactionLockInfo?, conflictingHash: String?, showRawTransaction: Bool, memo: String?) { self.lockInfo = lockInfo diff --git a/UnstoppableWallet/UnstoppableWallet/Models/TransactionRecords/Evm/ApproveTransactionRecord.swift b/UnstoppableWallet/UnstoppableWallet/Models/TransactionRecords/Evm/ApproveTransactionRecord.swift index cbaa73a1ce..d07628288a 100644 --- a/UnstoppableWallet/UnstoppableWallet/Models/TransactionRecords/Evm/ApproveTransactionRecord.swift +++ b/UnstoppableWallet/UnstoppableWallet/Models/TransactionRecords/Evm/ApproveTransactionRecord.swift @@ -4,16 +4,16 @@ import MarketKit class ApproveTransactionRecord: EvmTransactionRecord { let spender: String - let value: TransactionValue + let value: AppValue - init(source: TransactionSource, transaction: Transaction, baseToken: Token, spender: String, value: TransactionValue) { + init(source: TransactionSource, transaction: Transaction, baseToken: Token, spender: String, value: AppValue) { self.spender = spender self.value = value super.init(source: source, transaction: transaction, baseToken: baseToken, ownTransaction: true) } - override var mainValue: TransactionValue? { + override var mainValue: AppValue? { value } } diff --git a/UnstoppableWallet/UnstoppableWallet/Models/TransactionRecords/Evm/ContractCallTransactionRecord.swift b/UnstoppableWallet/UnstoppableWallet/Models/TransactionRecords/Evm/ContractCallTransactionRecord.swift index a037fdaadd..db742da47e 100644 --- a/UnstoppableWallet/UnstoppableWallet/Models/TransactionRecords/Evm/ContractCallTransactionRecord.swift +++ b/UnstoppableWallet/UnstoppableWallet/Models/TransactionRecords/Evm/ContractCallTransactionRecord.swift @@ -19,11 +19,11 @@ class ContractCallTransactionRecord: EvmTransactionRecord { super.init(source: source, transaction: transaction, baseToken: baseToken, ownTransaction: true) } - var combinedValues: ([TransactionValue], [TransactionValue]) { + var combinedValues: ([AppValue], [AppValue]) { combined(incomingEvents: incomingEvents, outgoingEvents: outgoingEvents) } - override var mainValue: TransactionValue? { + override var mainValue: AppValue? { let (incomingValues, outgoingValues) = combinedValues if incomingValues.count == 1, outgoingValues.isEmpty { diff --git a/UnstoppableWallet/UnstoppableWallet/Models/TransactionRecords/Evm/EvmIncomingTransactionRecord.swift b/UnstoppableWallet/UnstoppableWallet/Models/TransactionRecords/Evm/EvmIncomingTransactionRecord.swift index 7ce4c61f09..30309f6c80 100644 --- a/UnstoppableWallet/UnstoppableWallet/Models/TransactionRecords/Evm/EvmIncomingTransactionRecord.swift +++ b/UnstoppableWallet/UnstoppableWallet/Models/TransactionRecords/Evm/EvmIncomingTransactionRecord.swift @@ -4,17 +4,17 @@ import MarketKit class EvmIncomingTransactionRecord: EvmTransactionRecord { let from: String - let value: TransactionValue + let value: AppValue - init(source: TransactionSource, transaction: Transaction, baseToken: Token, from: String, value: TransactionValue) { + init(source: TransactionSource, transaction: Transaction, baseToken: Token, from: String, value: AppValue) { self.from = from self.value = value let spam: Bool - switch value { - case let .coinValue(_, value): - spam = value == 0 + switch value.kind { + case .token: + spam = value.value == 0 default: spam = false } @@ -22,7 +22,7 @@ class EvmIncomingTransactionRecord: EvmTransactionRecord { super.init(source: source, transaction: transaction, baseToken: baseToken, ownTransaction: false, spam: spam) } - override var mainValue: TransactionValue? { + override var mainValue: AppValue? { value } } diff --git a/UnstoppableWallet/UnstoppableWallet/Models/TransactionRecords/Evm/EvmOutgoingTransactionRecord.swift b/UnstoppableWallet/UnstoppableWallet/Models/TransactionRecords/Evm/EvmOutgoingTransactionRecord.swift index a866d1c689..8f5c103772 100644 --- a/UnstoppableWallet/UnstoppableWallet/Models/TransactionRecords/Evm/EvmOutgoingTransactionRecord.swift +++ b/UnstoppableWallet/UnstoppableWallet/Models/TransactionRecords/Evm/EvmOutgoingTransactionRecord.swift @@ -4,10 +4,10 @@ import MarketKit class EvmOutgoingTransactionRecord: EvmTransactionRecord { let to: String - let value: TransactionValue + let value: AppValue let sentToSelf: Bool - init(source: TransactionSource, transaction: Transaction, baseToken: Token, to: String, value: TransactionValue, sentToSelf: Bool) { + init(source: TransactionSource, transaction: Transaction, baseToken: Token, to: String, value: AppValue, sentToSelf: Bool) { self.to = to self.value = value self.sentToSelf = sentToSelf @@ -15,7 +15,7 @@ class EvmOutgoingTransactionRecord: EvmTransactionRecord { super.init(source: source, transaction: transaction, baseToken: baseToken, ownTransaction: true) } - override var mainValue: TransactionValue? { + override var mainValue: AppValue? { value } } diff --git a/UnstoppableWallet/UnstoppableWallet/Models/TransactionRecords/Evm/EvmTransactionRecord.swift b/UnstoppableWallet/UnstoppableWallet/Models/TransactionRecords/Evm/EvmTransactionRecord.swift index c5dadc61bb..55d736af05 100644 --- a/UnstoppableWallet/UnstoppableWallet/Models/TransactionRecords/Evm/EvmTransactionRecord.swift +++ b/UnstoppableWallet/UnstoppableWallet/Models/TransactionRecords/Evm/EvmTransactionRecord.swift @@ -5,7 +5,7 @@ import MarketKit class EvmTransactionRecord: TransactionRecord { let transaction: Transaction let ownTransaction: Bool - let fee: TransactionValue? + let fee: AppValue? init(source: TransactionSource, transaction: Transaction, baseToken: Token, ownTransaction: Bool, spam: Bool = false) { self.transaction = transaction @@ -14,7 +14,7 @@ class EvmTransactionRecord: TransactionRecord { if let feeAmount = transaction.gasUsed ?? transaction.gasLimit, let gasPrice = transaction.gasPrice { let feeDecimal = Decimal(sign: .plus, exponent: -baseToken.decimals, significand: Decimal(feeAmount) * Decimal(gasPrice)) - fee = .coinValue(token: baseToken, value: feeDecimal) + fee = AppValue(token: baseToken, value: feeDecimal) } else { fee = nil } @@ -32,39 +32,19 @@ class EvmTransactionRecord: TransactionRecord { ) } - private func sameType(_ value: TransactionValue, _ value2: TransactionValue) -> Bool { - switch (value, value2) { - case let (.coinValue(lhsToken, _), .coinValue(rhsToken, _)): return lhsToken == rhsToken - case let (.tokenValue(lhsTokenName, lhsTokenCode, lhsTokenDecimals, _), .tokenValue(rhsTokenName, rhsTokenCode, rhsTokenDecimals, _)): return lhsTokenName == rhsTokenName && lhsTokenCode == rhsTokenCode && lhsTokenDecimals == rhsTokenDecimals - case let (.nftValue(lhsNftUid, _, _, _), .nftValue(rhsNftUid, _, _, _)): return lhsNftUid == rhsNftUid - default: return false - } - } - - func combined(incomingEvents: [TransferEvent], outgoingEvents: [TransferEvent]) -> ([TransactionValue], [TransactionValue]) { + func combined(incomingEvents: [TransferEvent], outgoingEvents: [TransferEvent]) -> ([AppValue], [AppValue]) { let values = (incomingEvents + outgoingEvents).map(\.value) - var resultIncoming = [TransactionValue]() - var resultOutgoing = [TransactionValue]() + var resultIncoming = [AppValue]() + var resultOutgoing = [AppValue]() for value in values { - if (resultIncoming + resultOutgoing).contains(where: { sameType(value, $0) }) { + if (resultIncoming + resultOutgoing).contains(where: { value.kind == $0.kind }) { continue } - let sameTypeValues = values.filter { sameType(value, $0) } - let totalValue = sameTypeValues.map { $0.decimalValue ?? 0 }.reduce(0, +) - let resultValue: TransactionValue - - switch value { - case let .coinValue(token, _): - resultValue = .coinValue(token: token, value: totalValue) - case let .tokenValue(tokenName, tokenCode, tokenDecimals, _): - resultValue = .tokenValue(tokenName: tokenName, tokenCode: tokenCode, tokenDecimals: tokenDecimals, value: totalValue) - case let .nftValue(nftUid, _, tokenName, tokenSymbol): - resultValue = .nftValue(nftUid: nftUid, value: totalValue, tokenName: tokenName, tokenSymbol: tokenSymbol) - default: - resultValue = value - } + let sameTypeValues = values.filter { value.kind == $0.kind } + let totalValue = sameTypeValues.map(\.value).reduce(0, +) + let resultValue = AppValue(kind: value.kind, value: totalValue) if totalValue > 0 { resultIncoming.append(resultValue) @@ -80,6 +60,6 @@ class EvmTransactionRecord: TransactionRecord { extension EvmTransactionRecord { struct TransferEvent { let address: String - let value: TransactionValue + let value: AppValue } } diff --git a/UnstoppableWallet/UnstoppableWallet/Models/TransactionRecords/Evm/ExternalContractCallTransactionRecord.swift b/UnstoppableWallet/UnstoppableWallet/Models/TransactionRecords/Evm/ExternalContractCallTransactionRecord.swift index 26adf92b24..af22fd4972 100644 --- a/UnstoppableWallet/UnstoppableWallet/Models/TransactionRecords/Evm/ExternalContractCallTransactionRecord.swift +++ b/UnstoppableWallet/UnstoppableWallet/Models/TransactionRecords/Evm/ExternalContractCallTransactionRecord.swift @@ -10,16 +10,16 @@ class ExternalContractCallTransactionRecord: EvmTransactionRecord { self.incomingEvents = incomingEvents self.outgoingEvents = outgoingEvents - let spam = TransactionRecord.isSpam(transactionValues: (incomingEvents + outgoingEvents).map(\.value)) + let spam = TransactionRecord.isSpam(appValues: (incomingEvents + outgoingEvents).map(\.value)) super.init(source: source, transaction: transaction, baseToken: baseToken, ownTransaction: false, spam: spam) } - var combinedValues: ([TransactionValue], [TransactionValue]) { + var combinedValues: ([AppValue], [AppValue]) { combined(incomingEvents: incomingEvents, outgoingEvents: outgoingEvents) } - override var mainValue: TransactionValue? { + override var mainValue: AppValue? { let (incomingValues, outgoingValues) = combinedValues if incomingValues.count == 1, outgoingValues.isEmpty { diff --git a/UnstoppableWallet/UnstoppableWallet/Models/TransactionRecords/Evm/SwapTransactionRecord.swift b/UnstoppableWallet/UnstoppableWallet/Models/TransactionRecords/Evm/SwapTransactionRecord.swift index bb62483729..21abd64b7e 100644 --- a/UnstoppableWallet/UnstoppableWallet/Models/TransactionRecords/Evm/SwapTransactionRecord.swift +++ b/UnstoppableWallet/UnstoppableWallet/Models/TransactionRecords/Evm/SwapTransactionRecord.swift @@ -18,21 +18,21 @@ class SwapTransactionRecord: EvmTransactionRecord { super.init(source: source, transaction: transaction, baseToken: baseToken, ownTransaction: true) } - var valueIn: TransactionValue { + var valueIn: AppValue { amountIn.value } - var valueOut: TransactionValue? { + var valueOut: AppValue? { amountOut?.value } } extension SwapTransactionRecord { enum Amount { - case exact(value: TransactionValue) - case extremum(value: TransactionValue) + case exact(value: AppValue) + case extremum(value: AppValue) - var value: TransactionValue { + var value: AppValue { switch self { case let .exact(value): return value case let .extremum(value): return value diff --git a/UnstoppableWallet/UnstoppableWallet/Models/TransactionRecords/Evm/UnknownSwapTransactionRecord.swift b/UnstoppableWallet/UnstoppableWallet/Models/TransactionRecords/Evm/UnknownSwapTransactionRecord.swift index 0f6a088315..f4566a03f6 100644 --- a/UnstoppableWallet/UnstoppableWallet/Models/TransactionRecords/Evm/UnknownSwapTransactionRecord.swift +++ b/UnstoppableWallet/UnstoppableWallet/Models/TransactionRecords/Evm/UnknownSwapTransactionRecord.swift @@ -4,10 +4,10 @@ import MarketKit class UnknownSwapTransactionRecord: EvmTransactionRecord { let exchangeAddress: String - let valueIn: TransactionValue? - let valueOut: TransactionValue? + let valueIn: AppValue? + let valueOut: AppValue? - init(source: TransactionSource, transaction: Transaction, baseToken: Token, exchangeAddress: String, valueIn: TransactionValue?, valueOut: TransactionValue?) { + init(source: TransactionSource, transaction: Transaction, baseToken: Token, exchangeAddress: String, valueIn: AppValue?, valueOut: AppValue?) { self.exchangeAddress = exchangeAddress self.valueIn = valueIn self.valueOut = valueOut diff --git a/UnstoppableWallet/UnstoppableWallet/Models/TransactionRecords/Ton/TonTransactionRecord.swift b/UnstoppableWallet/UnstoppableWallet/Models/TransactionRecords/Ton/TonTransactionRecord.swift index afc4070274..9e29050760 100644 --- a/UnstoppableWallet/UnstoppableWallet/Models/TransactionRecords/Ton/TonTransactionRecord.swift +++ b/UnstoppableWallet/UnstoppableWallet/Models/TransactionRecords/Ton/TonTransactionRecord.swift @@ -6,13 +6,13 @@ import TonSwift class TonTransactionRecord: TransactionRecord { let lt: Int64 let inProgress: Bool - let fee: TransactionValue? + let fee: AppValue? let actions: [Action] init(source: TransactionSource, event: Event, baseToken: Token, actions: [Action]) { lt = event.lt inProgress = event.inProgress - fee = .coinValue(token: baseToken, value: TonAdapter.amount(kitAmount: abs(event.extra))) + fee = AppValue(token: baseToken, value: TonAdapter.amount(kitAmount: abs(event.extra))) self.actions = actions super.init( @@ -32,7 +32,7 @@ class TonTransactionRecord: TransactionRecord { inProgress ? .pending : .completed } - override var mainValue: TransactionValue? { + override var mainValue: AppValue? { if actions.count == 1, let action = actions.first { switch action.type { case let .send(value, _, _, _): return value @@ -54,13 +54,13 @@ extension TonTransactionRecord { let status: TransactionStatus enum `Type` { - case send(value: TransactionValue, to: String, sentToSelf: Bool, comment: String?) - case receive(value: TransactionValue, from: String, comment: String?) - case burn(value: TransactionValue) - case mint(value: TransactionValue) - case swap(routerName: String?, routerAddress: String, valueIn: TransactionValue, valueOut: TransactionValue) + case send(value: AppValue, to: String, sentToSelf: Bool, comment: String?) + case receive(value: AppValue, from: String, comment: String?) + case burn(value: AppValue) + case mint(value: AppValue) + case swap(routerName: String?, routerAddress: String, valueIn: AppValue, valueOut: AppValue) case contractDeploy(interfaces: [String]) - case contractCall(address: String, value: TransactionValue, operation: String) + case contractCall(address: String, value: AppValue, operation: String) case unsupported(type: String) } } diff --git a/UnstoppableWallet/UnstoppableWallet/Models/TransactionRecords/TransactionRecord.swift b/UnstoppableWallet/UnstoppableWallet/Models/TransactionRecords/TransactionRecord.swift index 171b927210..6de5c7e408 100644 --- a/UnstoppableWallet/UnstoppableWallet/Models/TransactionRecords/TransactionRecord.swift +++ b/UnstoppableWallet/UnstoppableWallet/Models/TransactionRecords/TransactionRecord.swift @@ -44,16 +44,18 @@ class TransactionRecord { nil } - open var mainValue: TransactionValue? { + open var mainValue: AppValue? { nil } - static func isSpam(transactionValues: [TransactionValue]) -> Bool { - for value in transactionValues { - switch value { - case let .coinValue(token, value): - let stableCoinUids = ["tether", "usd-coin", "dai", "binance-usd", "binance-peg-busd", "stasis-eurs"] + static func isSpam(appValues: [AppValue]) -> Bool { + let stableCoinUids = ["tether", "usd-coin", "dai", "binance-usd", "binance-peg-busd", "stasis-eurs"] + for appValue in appValues { + let value = appValue.value + + switch appValue.kind { + case let .token(token): if stableCoinUids.contains(token.coin.uid) { if value > 0.01 { return false @@ -61,7 +63,15 @@ class TransactionRecord { } else if value > 0 { return false } - case let .nftValue(_, value, _, _): + case let .coin(coin, _): + if stableCoinUids.contains(coin.uid) { + if value > 0.01 { + return false + } + } else if value > 0 { + return false + } + case .nft: if value > 0 { return false } diff --git a/UnstoppableWallet/UnstoppableWallet/Models/TransactionRecords/Tron/TronApproveTransactionRecord.swift b/UnstoppableWallet/UnstoppableWallet/Models/TransactionRecords/Tron/TronApproveTransactionRecord.swift index 062b53eb4d..60c29f7f76 100644 --- a/UnstoppableWallet/UnstoppableWallet/Models/TransactionRecords/Tron/TronApproveTransactionRecord.swift +++ b/UnstoppableWallet/UnstoppableWallet/Models/TransactionRecords/Tron/TronApproveTransactionRecord.swift @@ -4,16 +4,16 @@ import TronKit class TronApproveTransactionRecord: TronTransactionRecord { let spender: String - let value: TransactionValue + let value: AppValue - init(source: TransactionSource, transaction: Transaction, baseToken: Token, spender: String, value: TransactionValue) { + init(source: TransactionSource, transaction: Transaction, baseToken: Token, spender: String, value: AppValue) { self.spender = spender self.value = value super.init(source: source, transaction: transaction, baseToken: baseToken, ownTransaction: true) } - override var mainValue: TransactionValue? { + override var mainValue: AppValue? { value } } diff --git a/UnstoppableWallet/UnstoppableWallet/Models/TransactionRecords/Tron/TronContractCallTransactionRecord.swift b/UnstoppableWallet/UnstoppableWallet/Models/TransactionRecords/Tron/TronContractCallTransactionRecord.swift index fe6f199deb..93e06f3fe9 100644 --- a/UnstoppableWallet/UnstoppableWallet/Models/TransactionRecords/Tron/TronContractCallTransactionRecord.swift +++ b/UnstoppableWallet/UnstoppableWallet/Models/TransactionRecords/Tron/TronContractCallTransactionRecord.swift @@ -19,11 +19,11 @@ class TronContractCallTransactionRecord: TronTransactionRecord { super.init(source: source, transaction: transaction, baseToken: baseToken, ownTransaction: true) } - var combinedValues: ([TransactionValue], [TransactionValue]) { + var combinedValues: ([AppValue], [AppValue]) { combined(incomingEvents: incomingEvents, outgoingEvents: outgoingEvents) } - override var mainValue: TransactionValue? { + override var mainValue: AppValue? { let (incomingValues, outgoingValues) = combinedValues if incomingValues.count == 1, outgoingValues.isEmpty { diff --git a/UnstoppableWallet/UnstoppableWallet/Models/TransactionRecords/Tron/TronExternalContractCallTransactionRecord.swift b/UnstoppableWallet/UnstoppableWallet/Models/TransactionRecords/Tron/TronExternalContractCallTransactionRecord.swift index 3817d11f4d..c2ec4a3eff 100644 --- a/UnstoppableWallet/UnstoppableWallet/Models/TransactionRecords/Tron/TronExternalContractCallTransactionRecord.swift +++ b/UnstoppableWallet/UnstoppableWallet/Models/TransactionRecords/Tron/TronExternalContractCallTransactionRecord.swift @@ -10,16 +10,16 @@ class TronExternalContractCallTransactionRecord: TronTransactionRecord { self.incomingEvents = incomingEvents self.outgoingEvents = outgoingEvents - let spam = TransactionRecord.isSpam(transactionValues: (incomingEvents + outgoingEvents).map(\.value)) + let spam = TransactionRecord.isSpam(appValues: (incomingEvents + outgoingEvents).map(\.value)) super.init(source: source, transaction: transaction, baseToken: baseToken, ownTransaction: false, spam: spam) } - var combinedValues: ([TransactionValue], [TransactionValue]) { + var combinedValues: ([AppValue], [AppValue]) { combined(incomingEvents: incomingEvents, outgoingEvents: outgoingEvents) } - override var mainValue: TransactionValue? { + override var mainValue: AppValue? { let (incomingValues, outgoingValues) = combinedValues if incomingValues.count == 1, outgoingValues.isEmpty { diff --git a/UnstoppableWallet/UnstoppableWallet/Models/TransactionRecords/Tron/TronIncomingTransactionRecord.swift b/UnstoppableWallet/UnstoppableWallet/Models/TransactionRecords/Tron/TronIncomingTransactionRecord.swift index aac07d8050..d353c53186 100644 --- a/UnstoppableWallet/UnstoppableWallet/Models/TransactionRecords/Tron/TronIncomingTransactionRecord.swift +++ b/UnstoppableWallet/UnstoppableWallet/Models/TransactionRecords/Tron/TronIncomingTransactionRecord.swift @@ -4,16 +4,16 @@ import TronKit class TronIncomingTransactionRecord: TronTransactionRecord { let from: String - let value: TransactionValue + let value: AppValue - init(source: TransactionSource, transaction: Transaction, baseToken: Token, from: String, value: TransactionValue, spam: Bool = false) { + init(source: TransactionSource, transaction: Transaction, baseToken: Token, from: String, value: AppValue, spam: Bool = false) { self.from = from self.value = value super.init(source: source, transaction: transaction, baseToken: baseToken, ownTransaction: false, spam: spam) } - override var mainValue: TransactionValue? { + override var mainValue: AppValue? { value } } diff --git a/UnstoppableWallet/UnstoppableWallet/Models/TransactionRecords/Tron/TronOutgoingTransactionRecord.swift b/UnstoppableWallet/UnstoppableWallet/Models/TransactionRecords/Tron/TronOutgoingTransactionRecord.swift index ac8ee09b3e..998ade1c50 100644 --- a/UnstoppableWallet/UnstoppableWallet/Models/TransactionRecords/Tron/TronOutgoingTransactionRecord.swift +++ b/UnstoppableWallet/UnstoppableWallet/Models/TransactionRecords/Tron/TronOutgoingTransactionRecord.swift @@ -4,10 +4,10 @@ import TronKit class TronOutgoingTransactionRecord: TronTransactionRecord { let to: String - let value: TransactionValue + let value: AppValue let sentToSelf: Bool - init(source: TransactionSource, transaction: Transaction, baseToken: Token, to: String, value: TransactionValue, sentToSelf: Bool) { + init(source: TransactionSource, transaction: Transaction, baseToken: Token, to: String, value: AppValue, sentToSelf: Bool) { self.to = to self.value = value self.sentToSelf = sentToSelf @@ -15,7 +15,7 @@ class TronOutgoingTransactionRecord: TronTransactionRecord { super.init(source: source, transaction: transaction, baseToken: baseToken, ownTransaction: true) } - override var mainValue: TransactionValue? { + override var mainValue: AppValue? { value } } diff --git a/UnstoppableWallet/UnstoppableWallet/Models/TransactionRecords/Tron/TronTransactionRecord.swift b/UnstoppableWallet/UnstoppableWallet/Models/TransactionRecords/Tron/TronTransactionRecord.swift index a8c1fc88cc..5902dbb288 100644 --- a/UnstoppableWallet/UnstoppableWallet/Models/TransactionRecords/Tron/TronTransactionRecord.swift +++ b/UnstoppableWallet/UnstoppableWallet/Models/TransactionRecords/Tron/TronTransactionRecord.swift @@ -6,7 +6,7 @@ class TronTransactionRecord: TransactionRecord { let transaction: Transaction let confirmed: Bool let ownTransaction: Bool - let fee: TransactionValue? + let fee: AppValue? init(source: TransactionSource, transaction: Transaction, baseToken: Token, ownTransaction: Bool, spam: Bool = false) { self.transaction = transaction @@ -16,7 +16,7 @@ class TronTransactionRecord: TransactionRecord { if let feeAmount = transaction.fee { let feeDecimal = Decimal(sign: .plus, exponent: -baseToken.decimals, significand: Decimal(feeAmount)) - fee = .coinValue(token: baseToken, value: feeDecimal) + fee = AppValue(token: baseToken, value: feeDecimal) } else { fee = nil } @@ -34,39 +34,19 @@ class TronTransactionRecord: TransactionRecord { ) } - private func sameType(_ value: TransactionValue, _ value2: TransactionValue) -> Bool { - switch (value, value2) { - case let (.coinValue(lhsToken, _), .coinValue(rhsToken, _)): return lhsToken == rhsToken - case let (.tokenValue(lhsTokenName, lhsTokenCode, lhsTokenDecimals, _), .tokenValue(rhsTokenName, rhsTokenCode, rhsTokenDecimals, _)): return lhsTokenName == rhsTokenName && lhsTokenCode == rhsTokenCode && lhsTokenDecimals == rhsTokenDecimals - case let (.nftValue(lhsNftUid, _, _, _), .nftValue(rhsNftUid, _, _, _)): return lhsNftUid == rhsNftUid - default: return false - } - } - - func combined(incomingEvents: [TransferEvent], outgoingEvents: [TransferEvent]) -> ([TransactionValue], [TransactionValue]) { + func combined(incomingEvents: [TransferEvent], outgoingEvents: [TransferEvent]) -> ([AppValue], [AppValue]) { let values = (incomingEvents + outgoingEvents).map(\.value) - var resultIncoming = [TransactionValue]() - var resultOutgoing = [TransactionValue]() + var resultIncoming = [AppValue]() + var resultOutgoing = [AppValue]() for value in values { - if (resultIncoming + resultOutgoing).contains(where: { sameType(value, $0) }) { + if (resultIncoming + resultOutgoing).contains(where: { value.kind == $0.kind }) { continue } - let sameTypeValues = values.filter { sameType(value, $0) } - let totalValue = sameTypeValues.map { $0.decimalValue ?? 0 }.reduce(0, +) - let resultValue: TransactionValue - - switch value { - case let .coinValue(token, _): - resultValue = .coinValue(token: token, value: totalValue) - case let .tokenValue(tokenName, tokenCode, tokenDecimals, _): - resultValue = .tokenValue(tokenName: tokenName, tokenCode: tokenCode, tokenDecimals: tokenDecimals, value: totalValue) - case let .nftValue(nftUid, _, tokenName, tokenSymbol): - resultValue = .nftValue(nftUid: nftUid, value: totalValue, tokenName: tokenName, tokenSymbol: tokenSymbol) - default: - resultValue = value - } + let sameTypeValues = values.filter { value.kind == $0.kind } + let totalValue = sameTypeValues.map(\.value).reduce(0, +) + let resultValue = AppValue(kind: value.kind, value: totalValue) if totalValue > 0 { resultIncoming.append(resultValue) @@ -94,6 +74,6 @@ class TronTransactionRecord: TransactionRecord { extension TronTransactionRecord { struct TransferEvent { let address: String - let value: TransactionValue + let value: AppValue } } diff --git a/UnstoppableWallet/UnstoppableWallet/Models/TransactionValue.swift b/UnstoppableWallet/UnstoppableWallet/Models/TransactionValue.swift deleted file mode 100644 index 8746873b33..0000000000 --- a/UnstoppableWallet/UnstoppableWallet/Models/TransactionValue.swift +++ /dev/null @@ -1,135 +0,0 @@ -import BigInt -import Foundation -import MarketKit -import TonKit - -enum TransactionValue { - case coinValue(token: Token, value: Decimal) - case tokenValue(tokenName: String, tokenCode: String, tokenDecimals: Int, value: Decimal) - case jettonValue(jetton: Jetton, value: Decimal) - case nftValue(nftUid: NftUid, value: Decimal, tokenName: String?, tokenSymbol: String?) - case rawValue(value: BigUInt) - - var fullName: String { - switch self { - case let .coinValue(token, _): return token.coin.name - case let .tokenValue(tokenName, _, _, _): return tokenName - case let .jettonValue(jetton, _): return jetton.name - case let .nftValue(nftUid, _, tokenName, _): return tokenName.map { "\($0) #\(nftUid.tokenId)" } ?? "#\(nftUid.tokenId)" - case .rawValue: return "" - } - } - - var coinCode: String { - switch self { - case let .coinValue(token, _): return token.coin.code - case let .tokenValue(_, tokenCode, _, _): return tokenCode - case let .jettonValue(jetton, _): return jetton.symbol - case let .nftValue(_, _, _, tokenSymbol): return tokenSymbol ?? "NFT" - case .rawValue: return "" - } - } - - var coin: Coin? { - switch self { - case let .coinValue(token, _): return token.coin - default: return nil - } - } - - var token: Token? { - switch self { - case let .coinValue(token, _): return token - default: return nil - } - } - - var tokenProtocol: TokenProtocol? { - switch self { - case let .coinValue(token, _): return token.type.tokenProtocol - case .tokenValue: return .eip20 - case .jettonValue: return .jetton - case .nftValue: return nil - case .rawValue: return nil - } - } - - var nftUid: NftUid? { - switch self { - case let .nftValue(nftUid, _, _, _): return nftUid - default: return nil - } - } - - var decimalValue: Decimal? { - switch self { - case let .coinValue(_, value): return value - case let .tokenValue(_, _, _, value): return value - case let .jettonValue(_, value): return value - case let .nftValue(_, value, _, _): return value - case .rawValue: return nil - } - } - - var zeroValue: Bool { - switch self { - case let .coinValue(_, value): return value == 0 - case let .tokenValue(_, _, _, value): return value == 0 - case let .jettonValue(_, value): return value == 0 - case let .nftValue(_, value, _, _): return value == 0 - case let .rawValue(value): return value == 0 - } - } - - public var isMaxValue: Bool { - switch self { - case let .coinValue(token, value): return value.isMaxValue(decimals: token.decimals) - case let .tokenValue(_, _, tokenDecimals, value): return value.isMaxValue(decimals: tokenDecimals) - case let .jettonValue(jetton, value): return value.isMaxValue(decimals: jetton.decimals) - default: return false - } - } - - func formattedFull(signType: ValueFormatter.SignType = .never) -> String? { - switch self { - case let .coinValue(token, value): - return ValueFormatter.instance.formatFull(value: value, decimalCount: token.decimals, symbol: token.coin.code, signType: signType) - case let .tokenValue(_, tokenCode, tokenDecimals, value): - return ValueFormatter.instance.formatFull(value: value, decimalCount: tokenDecimals, symbol: tokenCode, signType: signType) - case let .jettonValue(jetton, value): - return ValueFormatter.instance.formatFull(value: value, decimalCount: jetton.decimals, symbol: jetton.symbol, signType: signType) - case let .nftValue(_, value, _, tokenSymbol): - return "\(value.sign == .plus ? "+" : "")\(value) \(tokenSymbol ?? "NFT")" - case .rawValue: - return nil - } - } - - func formattedShort(signType: ValueFormatter.SignType = .never) -> String? { - switch self { - case let .coinValue(token, value): - return ValueFormatter.instance.formatShort(value: value, decimalCount: token.decimals, symbol: token.coin.code, signType: signType) - case let .tokenValue(_, tokenCode, tokenDecimals, value): - return ValueFormatter.instance.formatShort(value: value, decimalCount: tokenDecimals, symbol: tokenCode, signType: signType) - case let .jettonValue(jetton, value): - return ValueFormatter.instance.formatShort(value: value, decimalCount: jetton.decimals, symbol: jetton.symbol, signType: signType) - case let .nftValue(_, value, _, tokenSymbol): - return "\(value.sign == .plus ? "+" : "")\(value) \(tokenSymbol ?? "NFT")" - case .rawValue: - return nil - } - } -} - -extension TransactionValue: Equatable { - static func == (lhs: TransactionValue, rhs: TransactionValue) -> Bool { - switch (lhs, rhs) { - case let (.coinValue(lhsToken, lhsValue), .coinValue(rhsToken, rhsValue)): return lhsToken == rhsToken && lhsValue == rhsValue - case let (.tokenValue(lhsTokenName, lhsTokenCode, lhsTokenDecimals, lhsValue), .tokenValue(rhsTokenName, rhsTokenCode, rhsTokenDecimals, rhsValue)): return lhsTokenName == rhsTokenName && lhsTokenCode == rhsTokenCode && lhsTokenDecimals == rhsTokenDecimals && lhsValue == rhsValue - case let (.jettonValue(lhsJetton, lhsValue), .jettonValue(rhsJetton, rhsValue)): return lhsJetton == rhsJetton && lhsValue == rhsValue - case let (.nftValue(lhsNftUid, lhsValue, _, _), .nftValue(rhsNftUid, rhsValue, _, _)): return lhsNftUid == rhsNftUid && lhsValue == rhsValue - case let (.rawValue(lhsValue), .rawValue(rhsValue)): return lhsValue == rhsValue - default: return false - } - } -} diff --git a/UnstoppableWallet/UnstoppableWallet/Modules/Cex/CexDeposit/CexDepositService.swift b/UnstoppableWallet/UnstoppableWallet/Modules/Cex/CexDeposit/CexDepositService.swift index bd689ac21f..6451c5e4b6 100644 --- a/UnstoppableWallet/UnstoppableWallet/Modules/Cex/CexDeposit/CexDepositService.swift +++ b/UnstoppableWallet/UnstoppableWallet/Modules/Cex/CexDeposit/CexDepositService.swift @@ -31,15 +31,12 @@ class CexDepositService { do { let (address, memo) = try await provider.deposit(id: cexAsset.id, network: network?.id) - let minAmount = network.flatMap { network -> CoinValue? in + let minAmount = network.flatMap { network -> AppValue? in guard network.minAmount > 0 else { return nil } - return CoinValue( - kind: .cexAsset(cexAsset: cexAsset), - value: network.minAmount - ) + return AppValue(cexAsset: cexAsset, value: network.minAmount) } let item = DexReceiveAddress( @@ -89,9 +86,9 @@ extension CexDepositService { let address: String let memo: String? let networkName: String? - let minAmount: CoinValue? + let minAmount: AppValue? - init(address: String, coinCode: String, imageUrl: String?, memo: String?, networkName: String?, minAmount: CoinValue?) { + init(address: String, coinCode: String, imageUrl: String?, memo: String?, networkName: String?, minAmount: AppValue?) { self.address = address self.memo = memo self.networkName = networkName diff --git a/UnstoppableWallet/UnstoppableWallet/Modules/Cex/CexWithdraw/CexAmountInputViewModel.swift b/UnstoppableWallet/UnstoppableWallet/Modules/Cex/CexWithdraw/CexAmountInputViewModel.swift index 9bafbdb1f2..605e3382b5 100644 --- a/UnstoppableWallet/UnstoppableWallet/Modules/Cex/CexWithdraw/CexAmountInputViewModel.swift +++ b/UnstoppableWallet/UnstoppableWallet/Modules/Cex/CexWithdraw/CexAmountInputViewModel.swift @@ -26,7 +26,7 @@ class CexAmountInputViewModel: AmountInputViewModel { private func sync(cexAsset: CexAsset) { queue.async { [weak self] in self?.coinDecimals = CexAsset.decimals - self?.fiatService.set(coinValueKind: .cexAsset(cexAsset: cexAsset)) + self?.fiatService.set(appValueKind: .cexAsset(cexAsset: cexAsset)) self?.updateMaxEnabled() } } diff --git a/UnstoppableWallet/UnstoppableWallet/Modules/Cex/CexWithdraw/CexCoinService.swift b/UnstoppableWallet/UnstoppableWallet/Modules/Cex/CexWithdraw/CexCoinService.swift index e38507fca3..cff13da462 100644 --- a/UnstoppableWallet/UnstoppableWallet/Modules/Cex/CexWithdraw/CexCoinService.swift +++ b/UnstoppableWallet/UnstoppableWallet/Modules/Cex/CexWithdraw/CexCoinService.swift @@ -28,18 +28,18 @@ extension CexCoinService: ICoinService { } } - func coinValue(value: BigUInt) -> CoinValue { + func appValue(value: BigUInt) -> AppValue { let decimalValue = Decimal(bigUInt: value, decimals: CexAsset.decimals) ?? 0 - return coinValue(value: decimalValue) + return appValue(value: decimalValue) } - func coinValue(value: Decimal) -> CoinValue { - CoinValue(kind: .cexAsset(cexAsset: cexAsset), value: value) + func appValue(value: Decimal) -> AppValue { + AppValue(cexAsset: cexAsset, value: value) } // Example: Dollar, Bitcoin, Ether, etc func monetaryValue(value: BigUInt) -> Decimal { - coinValue(value: value).value + appValue(value: value).value } // Example: Cent, Satoshi, GWei, etc @@ -49,7 +49,7 @@ extension CexCoinService: ICoinService { func amountData(value: Decimal, sign: FloatingPointSign) -> AmountData { AmountData( - coinValue: coinValue(value: Decimal(sign: sign, exponent: value.exponent, significand: value.significand)), + appValue: appValue(value: Decimal(sign: sign, exponent: value.exponent, significand: value.significand)), currencyValue: rate.map { CurrencyValue(currency: $0.currency, value: $0.value * value) } diff --git a/UnstoppableWallet/UnstoppableWallet/Modules/Cex/CexWithdraw/CexWithdrawViewModel.swift b/UnstoppableWallet/UnstoppableWallet/Modules/Cex/CexWithdraw/CexWithdrawViewModel.swift index b80a24bd8f..2a0e8f3e0c 100644 --- a/UnstoppableWallet/UnstoppableWallet/Modules/Cex/CexWithdraw/CexWithdrawViewModel.swift +++ b/UnstoppableWallet/UnstoppableWallet/Modules/Cex/CexWithdraw/CexWithdrawViewModel.swift @@ -45,7 +45,7 @@ class CexWithdrawViewModel { let feeAmountData = coinService.amountData(value: fee, sign: .plus) self.fee = FeeAmount( - coinAmount: ValueFormatter.instance.formatFull(coinValue: feeAmountData.coinValue) ?? "n/a".localized, + coinAmount: feeAmountData.appValue.formattedFull() ?? "n/a".localized, currencyAmount: feeAmountData.currencyValue.flatMap { ValueFormatter.instance.formatFull(currencyValue: $0) } ) } diff --git a/UnstoppableWallet/UnstoppableWallet/Modules/Cex/CexWithdrawConfirm/CexWithdrawConfirmViewModel.swift b/UnstoppableWallet/UnstoppableWallet/Modules/Cex/CexWithdrawConfirm/CexWithdrawConfirmViewModel.swift index 2901d99db6..1ca5d74ef3 100644 --- a/UnstoppableWallet/UnstoppableWallet/Modules/Cex/CexWithdrawConfirm/CexWithdrawConfirmViewModel.swift +++ b/UnstoppableWallet/UnstoppableWallet/Modules/Cex/CexWithdrawConfirm/CexWithdrawConfirmViewModel.swift @@ -53,7 +53,7 @@ class CexWithdrawConfirmViewModel { SectionViewItem(viewItems: [ .feeValue( title: "cex_withdraw.fee".localized, - coinAmount: ValueFormatter.instance.formatFull(coinValue: feeData.coinValue) ?? "n/a".localized, + coinAmount: feeData.appValue.formattedFull() ?? "n/a".localized, currencyAmount: feeData.currencyValue.flatMap { ValueFormatter.instance.formatFull(currencyValue: $0) } ), ]) @@ -71,7 +71,7 @@ class CexWithdrawConfirmViewModel { title: "cex_withdraw_confirm.you_withdraw".localized, iconUrl: service.cexAsset.coin?.imageUrl, iconPlaceholderImageName: "placeholder_circle_32", - coinAmount: ValueFormatter.instance.formatFull(coinValue: amountData.coinValue) ?? "n/a".localized, + coinAmount: amountData.appValue.formattedFull() ?? "n/a".localized, currencyAmount: amountData.currencyValue.flatMap { ValueFormatter.instance.formatFull(currencyValue: $0) }, type: .neutral ), diff --git a/UnstoppableWallet/UnstoppableWallet/Modules/CoinSelect/CoinSelectViewModel.swift b/UnstoppableWallet/UnstoppableWallet/Modules/CoinSelect/CoinSelectViewModel.swift index 3680e935e9..17c9951372 100644 --- a/UnstoppableWallet/UnstoppableWallet/Modules/CoinSelect/CoinSelectViewModel.swift +++ b/UnstoppableWallet/UnstoppableWallet/Modules/CoinSelect/CoinSelectViewModel.swift @@ -20,8 +20,8 @@ class CoinSelectViewModel { private func sync(items: [CoinSelectService.Item]) { let viewItems = items.map { item -> ViewItem in let formatted = item.balance - .flatMap { CoinValue(kind: .token(token: item.token), value: $0) } - .flatMap { ValueFormatter.instance.formatShort(coinValue: $0) } + .flatMap { AppValue(token: item.token, value: $0) } + .flatMap { $0.formattedShort() } let fiatFormatted = item.rate .flatMap { rate in item.balance.map { $0 * rate } } diff --git a/UnstoppableWallet/UnstoppableWallet/Modules/EvmSendSettings/Fee/Eip1559/Eip1559EvmFeeViewModel.swift b/UnstoppableWallet/UnstoppableWallet/Modules/EvmSendSettings/Fee/Eip1559/Eip1559EvmFeeViewModel.swift index 7ac84af46d..9098280366 100644 --- a/UnstoppableWallet/UnstoppableWallet/Modules/EvmSendSettings/Fee/Eip1559/Eip1559EvmFeeViewModel.swift +++ b/UnstoppableWallet/UnstoppableWallet/Modules/EvmSendSettings/Fee/Eip1559/Eip1559EvmFeeViewModel.swift @@ -72,9 +72,9 @@ class Eip1559EvmFeeViewModel { let gasData = fallibleTransaction.data.gasData let amountData = coinService.amountData(value: gasData.estimatedFee) let tilda = gasData.isSurcharged - if fallibleTransaction.errors.isEmpty, let coinValue = amountData.coinValue.formattedFull { + if fallibleTransaction.errors.isEmpty, let appValue = amountData.appValue.formattedFull() { feeValue = .regular( - text: "\(tilda ? "~" : "")\(coinValue)", + text: "\(tilda ? "~" : "")\(appValue)", secondaryText: amountData.currencyValue?.formattedFull.map { "\(tilda ? "~" : "")\($0)" } ) } else { diff --git a/UnstoppableWallet/UnstoppableWallet/Modules/EvmSendSettings/Fee/Legacy/LegacyEvmFeeViewModel.swift b/UnstoppableWallet/UnstoppableWallet/Modules/EvmSendSettings/Fee/Legacy/LegacyEvmFeeViewModel.swift index 89019d7e8e..574f66618c 100644 --- a/UnstoppableWallet/UnstoppableWallet/Modules/EvmSendSettings/Fee/Legacy/LegacyEvmFeeViewModel.swift +++ b/UnstoppableWallet/UnstoppableWallet/Modules/EvmSendSettings/Fee/Legacy/LegacyEvmFeeViewModel.swift @@ -80,9 +80,9 @@ class LegacyEvmFeeViewModel { let gasData = fallibleTransaction.data.gasData let amountData = coinService.amountData(value: gasData.estimatedFee) let tilda = gasData.isSurcharged - if fallibleTransaction.errors.isEmpty, let coinValue = amountData.coinValue.formattedFull { + if fallibleTransaction.errors.isEmpty, let appValue = amountData.appValue.formattedFull() { feeValue = .regular( - text: "\(tilda ? "~" : "")\(coinValue)", + text: "\(tilda ? "~" : "")\(appValue)", secondaryText: amountData.currencyValue?.formattedFull.map { "\(tilda ? "~" : "")\($0)" } ) } else { diff --git a/UnstoppableWallet/UnstoppableWallet/Modules/Main/Workers/TelegramUserHandler.swift b/UnstoppableWallet/UnstoppableWallet/Modules/Main/Workers/TelegramUserHandler.swift index d17d49be93..75096c7953 100644 --- a/UnstoppableWallet/UnstoppableWallet/Modules/Main/Workers/TelegramUserHandler.swift +++ b/UnstoppableWallet/UnstoppableWallet/Modules/Main/Workers/TelegramUserHandler.swift @@ -16,7 +16,7 @@ class TelegramUserHandler { extension TelegramUserHandler: IEventHandler { @MainActor - func handle(source: StatPage, event: Any, eventType: EventHandler.EventType) async throws { + func handle(source _: StatPage, event: Any, eventType: EventHandler.EventType) async throws { if eventType.contains(.deepLink), let event = event as? DeepLinkManager.DeepLink { guard case let .referral(userId, referralCode) = event else { throw EventHandler.HandleError.noSuitableHandler @@ -39,5 +39,5 @@ extension TelegramUserHandler { } struct EmptyResponse: ImmutableMappable { - init(map: Map) throws {} + init(map _: Map) throws {} } diff --git a/UnstoppableWallet/UnstoppableWallet/Modules/MultiSwap/Approve/MultiSwapApproveView.swift b/UnstoppableWallet/UnstoppableWallet/Modules/MultiSwap/Approve/MultiSwapApproveView.swift index 8eee8a02bd..bbff13fbf8 100644 --- a/UnstoppableWallet/UnstoppableWallet/Modules/MultiSwap/Approve/MultiSwapApproveView.swift +++ b/UnstoppableWallet/UnstoppableWallet/Modules/MultiSwap/Approve/MultiSwapApproveView.swift @@ -32,8 +32,8 @@ struct MultiSwapApproveView: View { ClickableRow(action: { viewModel.set(unlimitedAmount: false) }) { - let coinValue = CoinValue(kind: .token(token: viewModel.token), value: viewModel.amount) - let amountString = ValueFormatter.instance.formatFull(coinValue: coinValue) ?? "" + let appValue = AppValue(token: viewModel.token, value: viewModel.amount) + let amountString = appValue.formattedFull() ?? "" row(text: amountString, selected: !viewModel.unlimitedAmount) } ClickableRow(action: { diff --git a/UnstoppableWallet/UnstoppableWallet/Modules/MultiSwap/MultiSwapQuotesView.swift b/UnstoppableWallet/UnstoppableWallet/Modules/MultiSwap/MultiSwapQuotesView.swift index 333410df55..ef4dabfce7 100644 --- a/UnstoppableWallet/UnstoppableWallet/Modules/MultiSwap/MultiSwapQuotesView.swift +++ b/UnstoppableWallet/UnstoppableWallet/Modules/MultiSwap/MultiSwapQuotesView.swift @@ -67,7 +67,7 @@ struct MultiSwapQuotesView: View { return nil } - return ValueFormatter.instance.formatFull(coinValue: CoinValue(kind: .token(token: tokenOut), value: quote.quote.amountOut)) + return AppValue(token: tokenOut, value: quote.quote.amountOut).formattedFull() } private func quoteCurrencyValue(quote: MultiSwapViewModel.Quote) -> String? { diff --git a/UnstoppableWallet/UnstoppableWallet/Modules/MultiSwap/MultiSwapSendHandler.swift b/UnstoppableWallet/UnstoppableWallet/Modules/MultiSwap/MultiSwapSendHandler.swift index 8a70001001..52bc276a67 100644 --- a/UnstoppableWallet/UnstoppableWallet/Modules/MultiSwap/MultiSwapSendHandler.swift +++ b/UnstoppableWallet/UnstoppableWallet/Modules/MultiSwap/MultiSwapSendHandler.swift @@ -99,14 +99,14 @@ extension MultiSwapSendHandler { .amount( title: "swap.you_pay".localized, token: tokenIn, - coinValueType: .regular(coinValue: CoinValue(kind: .token(token: tokenIn), value: amountIn)), + appValueType: .regular(appValue: AppValue(token: tokenIn, value: amountIn)), currencyValue: rates[tokenIn.coin.uid].map { CurrencyValue(currency: currency, value: amountIn * $0) }, type: .neutral ), .amount( title: "swap.you_get".localized, token: tokenOut, - coinValueType: .regular(coinValue: CoinValue(kind: .token(token: tokenOut), value: quote.amountOut)), + appValueType: .regular(appValue: AppValue(token: tokenOut, value: quote.amountOut)), currencyValue: rates[tokenOut.coin.uid].map { CurrencyValue(currency: currency, value: quote.amountOut * $0) }, type: .incoming ), diff --git a/UnstoppableWallet/UnstoppableWallet/Modules/MultiSwap/MultiSwapView.swift b/UnstoppableWallet/UnstoppableWallet/Modules/MultiSwap/MultiSwapView.swift index 2e5e8db7a7..4355033304 100644 --- a/UnstoppableWallet/UnstoppableWallet/Modules/MultiSwap/MultiSwapView.swift +++ b/UnstoppableWallet/UnstoppableWallet/Modules/MultiSwap/MultiSwapView.swift @@ -505,7 +505,7 @@ struct MultiSwapView: View { return nil } - return ValueFormatter.instance.formatFull(coinValue: CoinValue(kind: .token(token: tokenIn), value: availableBalance)) + return AppValue(token: tokenIn, value: availableBalance).formattedFull() } private func buttonState() -> (String, PrimaryButtonStyle.Style, Bool, Bool, MultiSwapPreSwapStep?) { diff --git a/UnstoppableWallet/UnstoppableWallet/Modules/MultiSwap/Providers/BaseUniswapMultiSwapConfirmationQuote.swift b/UnstoppableWallet/UnstoppableWallet/Modules/MultiSwap/Providers/BaseUniswapMultiSwapConfirmationQuote.swift index 3a14455519..30c217050f 100644 --- a/UnstoppableWallet/UnstoppableWallet/Modules/MultiSwap/Providers/BaseUniswapMultiSwapConfirmationQuote.swift +++ b/UnstoppableWallet/UnstoppableWallet/Modules/MultiSwap/Providers/BaseUniswapMultiSwapConfirmationQuote.swift @@ -76,7 +76,7 @@ class BaseUniswapMultiSwapConfirmationQuote: BaseEvmMultiSwapConfirmationQuote { .value( title: "swap.confirmation.minimum_received".localized, description: nil, - coinValue: CoinValue(kind: .token(token: tokenOut), value: minAmountOut), + appValue: AppValue(token: tokenOut, value: minAmountOut), currencyValue: tokenOutRate.map { CurrencyValue(currency: currency, value: minAmountOut * $0) }, formatFull: true ) diff --git a/UnstoppableWallet/UnstoppableWallet/Modules/MultiSwap/Providers/MultiSwapAllowanceHelper.swift b/UnstoppableWallet/UnstoppableWallet/Modules/MultiSwap/Providers/MultiSwapAllowanceHelper.swift index 9daa9fdcbe..c578a97f7c 100644 --- a/UnstoppableWallet/UnstoppableWallet/Modules/MultiSwap/Providers/MultiSwapAllowanceHelper.swift +++ b/UnstoppableWallet/UnstoppableWallet/Modules/MultiSwap/Providers/MultiSwapAllowanceHelper.swift @@ -35,7 +35,7 @@ class MultiSwapAllowanceHelper { if pendingAllowance == 0 { return .pendingRevoke } else { - return .pendingAllowance(amount: CoinValue(kind: .token(token: token), value: pendingAllowance)) + return .pendingAllowance(appValue: AppValue(token: token, value: pendingAllowance)) } } @@ -45,7 +45,7 @@ class MultiSwapAllowanceHelper { return .allowed } else { return .notEnough( - amount: CoinValue(kind: .token(token: token), value: allowance), + appValue: AppValue(token: token, value: allowance), spenderAddress: spenderAddress, revokeRequired: allowance > 0 && mustBeRevoked(token: token) ) @@ -57,8 +57,8 @@ class MultiSwapAllowanceHelper { private func pendingAllowance(pendingTransactions: [TransactionRecord], spenderAddress: EvmKit.Address) -> Decimal? { for transaction in pendingTransactions { - if let record = transaction as? ApproveTransactionRecord, record.spender == spenderAddress.eip55, let value = record.value.decimalValue { - return value + if let record = transaction as? ApproveTransactionRecord, record.spender == spenderAddress.eip55 { + return record.value.value } } @@ -79,9 +79,9 @@ class MultiSwapAllowanceHelper { extension MultiSwapAllowanceHelper { enum AllowanceState { case notRequired - case pendingAllowance(amount: CoinValue) + case pendingAllowance(appValue: AppValue) case pendingRevoke - case notEnough(amount: CoinValue, spenderAddress: EvmKit.Address, revokeRequired: Bool) + case notEnough(appValue: AppValue, spenderAddress: EvmKit.Address, revokeRequired: Bool) case allowed case unknown @@ -99,9 +99,9 @@ extension MultiSwapAllowanceHelper { var cautions = [CautionNew]() switch self { - case let .notEnough(amount, _, revokeRequired): + case let .notEnough(appValue, _, revokeRequired): if revokeRequired { - cautions.append(.init(text: "swap.revoke_warning".localized(ValueFormatter.instance.formatShort(coinValue: amount) ?? ""), type: .warning)) + cautions.append(.init(text: "swap.revoke_warning".localized(appValue.formattedShort() ?? ""), type: .warning)) } default: () } @@ -113,8 +113,8 @@ extension MultiSwapAllowanceHelper { var fields = [MultiSwapMainField]() switch self { - case let .notEnough(amount, _, _): - if let formatted = ValueFormatter.instance.formatShort(coinValue: amount) { + case let .notEnough(appValue, _, _): + if let formatted = appValue.formattedShort() { fields.append( MultiSwapMainField( title: "swap.allowance".localized, @@ -124,8 +124,8 @@ extension MultiSwapAllowanceHelper { ) ) } - case let .pendingAllowance(amount): - if let formatted = ValueFormatter.instance.formatShort(coinValue: amount) { + case let .pendingAllowance(appValue): + if let formatted = appValue.formattedShort() { fields.append( MultiSwapMainField( title: "swap.pending_allowance".localized, diff --git a/UnstoppableWallet/UnstoppableWallet/Modules/MultiSwap/Providers/OneInchMultiSwapConfirmationQuote.swift b/UnstoppableWallet/UnstoppableWallet/Modules/MultiSwap/Providers/OneInchMultiSwapConfirmationQuote.swift index 6cee0088f6..6349d88b1c 100644 --- a/UnstoppableWallet/UnstoppableWallet/Modules/MultiSwap/Providers/OneInchMultiSwapConfirmationQuote.swift +++ b/UnstoppableWallet/UnstoppableWallet/Modules/MultiSwap/Providers/OneInchMultiSwapConfirmationQuote.swift @@ -73,7 +73,7 @@ class OneInchMultiSwapConfirmationQuote: BaseEvmMultiSwapConfirmationQuote { .value( title: "swap.confirmation.minimum_received".localized, description: nil, - coinValue: CoinValue(kind: .token(token: tokenOut), value: minAmountOut), + appValue: AppValue(token: tokenOut, value: minAmountOut), currencyValue: tokenOutRate.map { CurrencyValue(currency: currency, value: minAmountOut * $0) }, formatFull: true ) diff --git a/UnstoppableWallet/UnstoppableWallet/Modules/MultiSwap/Providers/ThorChainMultiSwapBtcConfirmationQuote.swift b/UnstoppableWallet/UnstoppableWallet/Modules/MultiSwap/Providers/ThorChainMultiSwapBtcConfirmationQuote.swift index db3901cb32..ba305962a3 100644 --- a/UnstoppableWallet/UnstoppableWallet/Modules/MultiSwap/Providers/ThorChainMultiSwapBtcConfirmationQuote.swift +++ b/UnstoppableWallet/UnstoppableWallet/Modules/MultiSwap/Providers/ThorChainMultiSwapBtcConfirmationQuote.swift @@ -67,18 +67,6 @@ class ThorChainMultiSwapBtcConfirmationQuote: BaseSendBtcData, IMultiSwapConfirm ) } -// let minAmountOut = amountOut * (1 - slippage / 100) -// -// fields.append( -// .value( -// title: "swap.confirmation.minimum_received".localized, -// description: nil, -// coinValue: CoinValue(kind: .token(token: tokenOut), value: minAmountOut), -// currencyValue: tokenOutRate.map { CurrencyValue(currency: currency, value: minAmountOut * $0) }, -// formatFull: true -// ) -// ) - return fields } @@ -92,7 +80,7 @@ class ThorChainMultiSwapBtcConfirmationQuote: BaseSendBtcData, IMultiSwapConfirm .value( title: "swap.affiliate_fee".localized, description: nil, - coinValue: CoinValue(kind: .token(token: tokenOut), value: swapQuote.affiliateFee), + appValue: AppValue(token: tokenOut, value: swapQuote.affiliateFee), currencyValue: tokenOutRate.map { CurrencyValue(currency: currency, value: swapQuote.affiliateFee * $0) }, formatFull: true ) @@ -104,7 +92,7 @@ class ThorChainMultiSwapBtcConfirmationQuote: BaseSendBtcData, IMultiSwapConfirm .value( title: "swap.liquidity_fee".localized, description: nil, - coinValue: CoinValue(kind: .token(token: tokenOut), value: swapQuote.liquidityFee), + appValue: AppValue(token: tokenOut, value: swapQuote.liquidityFee), currencyValue: tokenOutRate.map { CurrencyValue(currency: currency, value: swapQuote.liquidityFee * $0) }, formatFull: true ) @@ -116,7 +104,7 @@ class ThorChainMultiSwapBtcConfirmationQuote: BaseSendBtcData, IMultiSwapConfirm .value( title: "swap.outbound_fee".localized, description: nil, - coinValue: CoinValue(kind: .token(token: tokenOut), value: swapQuote.outboundFee), + appValue: AppValue(token: tokenOut, value: swapQuote.outboundFee), currencyValue: tokenOutRate.map { CurrencyValue(currency: currency, value: swapQuote.outboundFee * $0) }, diff --git a/UnstoppableWallet/UnstoppableWallet/Modules/MultiSwap/Providers/ThorChainMultiSwapEvmConfirmationQuote.swift b/UnstoppableWallet/UnstoppableWallet/Modules/MultiSwap/Providers/ThorChainMultiSwapEvmConfirmationQuote.swift index 1fa65cdcdd..5a636a2e34 100644 --- a/UnstoppableWallet/UnstoppableWallet/Modules/MultiSwap/Providers/ThorChainMultiSwapEvmConfirmationQuote.swift +++ b/UnstoppableWallet/UnstoppableWallet/Modules/MultiSwap/Providers/ThorChainMultiSwapEvmConfirmationQuote.swift @@ -61,18 +61,6 @@ class ThorChainMultiSwapEvmConfirmationQuote: BaseEvmMultiSwapConfirmationQuote ) } -// let minAmountOut = amountOut * (1 - slippage / 100) -// -// fields.append( -// .value( -// title: "swap.confirmation.minimum_received".localized, -// description: nil, -// coinValue: CoinValue(kind: .token(token: tokenOut), value: minAmountOut), -// currencyValue: tokenOutRate.map { CurrencyValue(currency: currency, value: minAmountOut * $0) }, -// formatFull: true -// ) -// ) - return fields } @@ -110,7 +98,7 @@ class ThorChainMultiSwapEvmConfirmationQuote: BaseEvmMultiSwapConfirmationQuote .value( title: "swap.affiliate_fee".localized, description: nil, - coinValue: CoinValue(kind: .token(token: tokenOut), value: swapQuote.affiliateFee), + appValue: AppValue(token: tokenOut, value: swapQuote.affiliateFee), currencyValue: tokenOutRate.map { CurrencyValue(currency: currency, value: swapQuote.affiliateFee * $0) }, formatFull: true ) @@ -122,7 +110,7 @@ class ThorChainMultiSwapEvmConfirmationQuote: BaseEvmMultiSwapConfirmationQuote .value( title: "swap.liquidity_fee".localized, description: nil, - coinValue: CoinValue(kind: .token(token: tokenOut), value: swapQuote.liquidityFee), + appValue: AppValue(token: tokenOut, value: swapQuote.liquidityFee), currencyValue: tokenOutRate.map { CurrencyValue(currency: currency, value: swapQuote.liquidityFee * $0) }, formatFull: true ) @@ -134,7 +122,7 @@ class ThorChainMultiSwapEvmConfirmationQuote: BaseEvmMultiSwapConfirmationQuote .value( title: "swap.outbound_fee".localized, description: nil, - coinValue: CoinValue(kind: .token(token: tokenOut), value: swapQuote.outboundFee), + appValue: AppValue(token: tokenOut, value: swapQuote.outboundFee), currencyValue: tokenOutRate.map { CurrencyValue(currency: currency, value: swapQuote.outboundFee * $0) }, diff --git a/UnstoppableWallet/UnstoppableWallet/Modules/MultiSwap/TokenSelect/MultiSwapTokenSelectViewModel.swift b/UnstoppableWallet/UnstoppableWallet/Modules/MultiSwap/TokenSelect/MultiSwapTokenSelectViewModel.swift index 4051e0e683..16ed714d41 100644 --- a/UnstoppableWallet/UnstoppableWallet/Modules/MultiSwap/TokenSelect/MultiSwapTokenSelectViewModel.swift +++ b/UnstoppableWallet/UnstoppableWallet/Modules/MultiSwap/TokenSelect/MultiSwapTokenSelectViewModel.swift @@ -210,7 +210,7 @@ class MultiSwapTokenSelectViewModel: ObservableObject { var fiatBalanceString: String? if let balance = balances[token] { - balanceString = ValueFormatter.instance.formatShort(coinValue: CoinValue(kind: .token(token: token), value: balance)) + balanceString = AppValue(token: token, value: balance).formattedShort() if let fiatBalance = fiatBalances[token] { fiatBalanceString = ValueFormatter.instance.formatShort(currency: currency, value: fiatBalance) diff --git a/UnstoppableWallet/UnstoppableWallet/Modules/Nft/NftHeaderViewModel.swift b/UnstoppableWallet/UnstoppableWallet/Modules/Nft/NftHeaderViewModel.swift index b61736b346..ba77095b29 100644 --- a/UnstoppableWallet/UnstoppableWallet/Modules/Nft/NftHeaderViewModel.swift +++ b/UnstoppableWallet/UnstoppableWallet/Modules/Nft/NftHeaderViewModel.swift @@ -27,7 +27,7 @@ class NftHeaderViewModel { let convertedValue: String if balanceHidden { convertedValue = BalanceHiddenManager.placeholder - } else if let value = totalItem.convertedValue, let formattedValue = ValueFormatter.instance.formatShort(coinValue: value) { + } else if let value = totalItem.convertedValue, let formattedValue = value.formattedShort() { convertedValue = "≈ \(formattedValue)" } else { convertedValue = "---" diff --git a/UnstoppableWallet/UnstoppableWallet/Modules/Nft/NftService.swift b/UnstoppableWallet/UnstoppableWallet/Modules/Nft/NftService.swift index 93a3b9ee15..9fa3095863 100644 --- a/UnstoppableWallet/UnstoppableWallet/Modules/Nft/NftService.swift +++ b/UnstoppableWallet/UnstoppableWallet/Modules/Nft/NftService.swift @@ -239,11 +239,11 @@ class NftService { } } - var convertedValue: CoinValue? + var convertedValue: AppValue? var convertedValueExpired = false if let conversionToken = balanceConversionManager.conversionToken, let priceItem = coinPriceService.item(coinUid: conversionToken.coin.uid) { - convertedValue = CoinValue(kind: .token(token: conversionToken), value: total / priceItem.price.value) + convertedValue = AppValue(token: conversionToken, value: total / priceItem.price.value) convertedValueExpired = priceItem.expired } @@ -360,7 +360,7 @@ extension NftService { struct TotalItem { let currencyValue: CurrencyValue let expired: Bool - let convertedValue: CoinValue? + let convertedValue: AppValue? let convertedValueExpired: Bool } diff --git a/UnstoppableWallet/UnstoppableWallet/Modules/Nft/NftViewModel.swift b/UnstoppableWallet/UnstoppableWallet/Modules/Nft/NftViewModel.swift index 7305bd86f8..22d5f028f0 100644 --- a/UnstoppableWallet/UnstoppableWallet/Modules/Nft/NftViewModel.swift +++ b/UnstoppableWallet/UnstoppableWallet/Modules/Nft/NftViewModel.swift @@ -43,8 +43,8 @@ class NftViewModel { var fiatPrice: String? if let price = assetItem.price { - let coinValue = CoinValue(kind: .token(token: price.token), value: price.value) - if let value = ValueFormatter.instance.formatShort(coinValue: coinValue) { + let appValue = AppValue(token: price.token, value: price.value) + if let value = appValue.formattedShort() { coinPrice = value } diff --git a/UnstoppableWallet/UnstoppableWallet/Modules/NftAsset/Overview/NftAssetOverviewViewModel.swift b/UnstoppableWallet/UnstoppableWallet/Modules/NftAsset/Overview/NftAssetOverviewViewModel.swift index 6254f4bbce..3365ac66b3 100644 --- a/UnstoppableWallet/UnstoppableWallet/Modules/NftAsset/Overview/NftAssetOverviewViewModel.swift +++ b/UnstoppableWallet/UnstoppableWallet/Modules/NftAsset/Overview/NftAssetOverviewViewModel.swift @@ -93,8 +93,8 @@ class NftAssetOverviewViewModel { private func coinValue(priceItem: NftAssetOverviewService.PriceItem) -> String { let price = priceItem.nftPrice - let coinValue = CoinValue(kind: .token(token: price.token), value: price.value) - return ValueFormatter.instance.formatShort(coinValue: coinValue) ?? "---" + let appValue = AppValue(token: price.token, value: price.value) + return appValue.formattedShort() ?? "---" } private func fiatValue(priceItem: NftAssetOverviewService.PriceItem) -> String { diff --git a/UnstoppableWallet/UnstoppableWallet/Modules/NftCollection/Activity/NftActivityViewModel.swift b/UnstoppableWallet/UnstoppableWallet/Modules/NftCollection/Activity/NftActivityViewModel.swift index 1b2102f8fb..691f082c62 100644 --- a/UnstoppableWallet/UnstoppableWallet/Modules/NftCollection/Activity/NftActivityViewModel.swift +++ b/UnstoppableWallet/UnstoppableWallet/Modules/NftCollection/Activity/NftActivityViewModel.swift @@ -67,8 +67,8 @@ class NftActivityViewModel { var fiatPrice: String? if let price = event.price { - let coinValue = CoinValue(kind: .token(token: price.token), value: price.value) - if let value = ValueFormatter.instance.formatShort(coinValue: coinValue) { + let appValue = AppValue(token: price.token, value: price.value) + if let value = appValue.formattedShort() { coinPrice = value } diff --git a/UnstoppableWallet/UnstoppableWallet/Modules/NftCollection/Assets/NftCollectionAssetsViewModel.swift b/UnstoppableWallet/UnstoppableWallet/Modules/NftCollection/Assets/NftCollectionAssetsViewModel.swift index 17c103fa46..b315a26a39 100644 --- a/UnstoppableWallet/UnstoppableWallet/Modules/NftCollection/Assets/NftCollectionAssetsViewModel.swift +++ b/UnstoppableWallet/UnstoppableWallet/Modules/NftCollection/Assets/NftCollectionAssetsViewModel.swift @@ -48,8 +48,8 @@ class NftCollectionAssetsViewModel { var fiatPrice: String? if let price = item.price { - let coinValue = CoinValue(kind: .token(token: price.token), value: price.value) - if let value = ValueFormatter.instance.formatShort(coinValue: coinValue) { + let appValue = AppValue(token: price.token, value: price.value) + if let value = appValue.formattedShort() { coinPrice = value } diff --git a/UnstoppableWallet/UnstoppableWallet/Modules/NftCollection/Overview/NftCollectionOverviewViewModel.swift b/UnstoppableWallet/UnstoppableWallet/Modules/NftCollection/Overview/NftCollectionOverviewViewModel.swift index 74c94b1d35..6d083b2993 100644 --- a/UnstoppableWallet/UnstoppableWallet/Modules/NftCollection/Overview/NftCollectionOverviewViewModel.swift +++ b/UnstoppableWallet/UnstoppableWallet/Modules/NftCollection/Overview/NftCollectionOverviewViewModel.swift @@ -132,8 +132,8 @@ class NftCollectionOverviewViewModel { } let averageValue: String? = collection.averagePrice1d.flatMap { - let coinValue = CoinValue(kind: .token(token: $0.token), value: $0.value) - return ValueFormatter.instance.formatShort(coinValue: coinValue) + let appValue = AppValue(token: $0.token, value: $0.value) + return appValue.formattedShort() } let additional = averageValue.map { "~\($0) per NFT" } @@ -158,8 +158,8 @@ class NftCollectionOverviewViewModel { return nil } - let coinValue = CoinValue(kind: .token(token: price.token), value: price.value) - return ValueFormatter.instance.formatShort(coinValue: coinValue) + let appValue = AppValue(token: price.token, value: price.value) + return appValue.formattedShort() } } diff --git a/UnstoppableWallet/UnstoppableWallet/Modules/ResendBitcoin/ResendBitcoinService.swift b/UnstoppableWallet/UnstoppableWallet/Modules/ResendBitcoin/ResendBitcoinService.swift index 4a02b791a5..bf9e7820d0 100644 --- a/UnstoppableWallet/UnstoppableWallet/Modules/ResendBitcoin/ResendBitcoinService.swift +++ b/UnstoppableWallet/UnstoppableWallet/Modules/ResendBitcoin/ResendBitcoinService.swift @@ -59,9 +59,9 @@ class ResendBitcoinService { var items = [ISendConfirmationViewItemNew]() - if let address = record.to, case let .coinValue(_, value) = record.value { + if let address = record.to { items.append( - SendConfirmationAmountViewItem(coinValue: .init(kind: .token(token: token), value: value), currencyValue: currencyValue(coinAmount: value), receiver: Address(raw: address), sentToSelf: record.sentToSelf) + SendConfirmationAmountViewItem(appValue: record.value, currencyValue: currencyValue(coinAmount: record.value.value), receiver: Address(raw: address), sentToSelf: record.sentToSelf) ) } @@ -73,12 +73,12 @@ class ResendBitcoinService { items.append(SendConfirmationLockUntilViewItem(lockValue: HodlerPlugin.LockTimeInterval.title(lockTimeInterval: lockInfo.lockTimeInterval))) } - if case let .coinValue(_, feeValue) = record.fee { + if let fee = record.fee { items.append( - SendConfirmationFeeViewItem(coinValue: .init(kind: .token(token: token), value: feeValue), currencyValue: currencyValue(coinAmount: feeValue)) + SendConfirmationFeeViewItem(appValue: fee, currencyValue: currencyValue(coinAmount: fee.value)) ) - if let recommendedFee, feeValue < recommendedFee { + if let recommendedFee, fee.value < recommendedFee { caution = TitledCaution(title: "fee_settings.warning.risk_of_getting_stuck".localized, text: "fee_settings.warning.risk_of_getting_stuck.info".localized, type: .warning) } else { caution = nil diff --git a/UnstoppableWallet/UnstoppableWallet/Modules/ResendBitcoin/ResendBitcoinViewModel.swift b/UnstoppableWallet/UnstoppableWallet/Modules/ResendBitcoin/ResendBitcoinViewModel.swift index 9a30bc303b..dc6be638dc 100644 --- a/UnstoppableWallet/UnstoppableWallet/Modules/ResendBitcoin/ResendBitcoinViewModel.swift +++ b/UnstoppableWallet/UnstoppableWallet/Modules/ResendBitcoin/ResendBitcoinViewModel.swift @@ -65,7 +65,7 @@ class ResendBitcoinViewModel { .amount( title: "send.confirmation.you_send".localized, token: service.token, - coinAmount: ValueFormatter.instance.formatFull(coinValue: item.coinValue) ?? "n/a".localized, + coinAmount: item.appValue.formattedFull() ?? "n/a".localized, currencyAmount: item.currencyValue.flatMap { ValueFormatter.instance.formatFull(currencyValue: $0) }, type: .neutral ) @@ -105,7 +105,7 @@ class ResendBitcoinViewModel { secondaryViewItems.append( .fee( title: "send.confirmation.fee".localized, - coinAmount: ValueFormatter.instance.formatFull(coinValue: item.coinValue) ?? "", + coinAmount: item.appValue.formattedFull() ?? "", currencyAmount: item.currencyValue.flatMap { ValueFormatter.instance.formatFull(currencyValue: $0) } ) ) diff --git a/UnstoppableWallet/UnstoppableWallet/Modules/Send/AmountCaution/SendAmountCautionViewModel.swift b/UnstoppableWallet/UnstoppableWallet/Modules/Send/AmountCaution/SendAmountCautionViewModel.swift index 3b559e9fc6..7fa5522e47 100644 --- a/UnstoppableWallet/UnstoppableWallet/Modules/Send/AmountCaution/SendAmountCautionViewModel.swift +++ b/UnstoppableWallet/UnstoppableWallet/Modules/Send/AmountCaution/SendAmountCautionViewModel.swift @@ -37,8 +37,8 @@ class SendAmountCautionViewModel { switch switchService.amountType { case .coin: - let coinValue = CoinValue(kind: .token(token: coinService.token), value: amountCaution.value) - amountInfo = .coinValue(coinValue: coinValue) + let appValue = AppValue(token: coinService.token, value: amountCaution.value) + amountInfo = .appValue(appValue: appValue) case .currency: if let rateValue = coinService.rate { let currencyValue = CurrencyValue(currency: rateValue.currency, value: amountCaution.value * rateValue.value) diff --git a/UnstoppableWallet/UnstoppableWallet/Modules/Send/Confirmation/SendConfirmationModule.swift b/UnstoppableWallet/UnstoppableWallet/Modules/Send/Confirmation/SendConfirmationModule.swift index 983a1be05b..f90e27e87e 100644 --- a/UnstoppableWallet/UnstoppableWallet/Modules/Send/Confirmation/SendConfirmationModule.swift +++ b/UnstoppableWallet/UnstoppableWallet/Modules/Send/Confirmation/SendConfirmationModule.swift @@ -2,14 +2,14 @@ protocol ISendConfirmationViewItemNew {} struct SendConfirmationAmountViewItem: ISendConfirmationViewItemNew { - let coinValue: CoinValue + let appValue: AppValue let currencyValue: CurrencyValue? let receiver: Address let isAccount: Bool let sentToSelf: Bool - init(coinValue: CoinValue, currencyValue: CurrencyValue?, receiver: Address, isAccount: Bool = false, sentToSelf: Bool = false) { - self.coinValue = coinValue + init(appValue: AppValue, currencyValue: CurrencyValue?, receiver: Address, isAccount: Bool = false, sentToSelf: Bool = false) { + self.appValue = appValue self.currencyValue = currencyValue self.receiver = receiver self.isAccount = isAccount @@ -18,7 +18,7 @@ struct SendConfirmationAmountViewItem: ISendConfirmationViewItemNew { } struct SendConfirmationFeeViewItem: ISendConfirmationViewItemNew { - let coinValue: CoinValue + let appValue: AppValue let currencyValue: CurrencyValue? } diff --git a/UnstoppableWallet/UnstoppableWallet/Modules/Send/Confirmation/SendConfirmationViewModel.swift b/UnstoppableWallet/UnstoppableWallet/Modules/Send/Confirmation/SendConfirmationViewModel.swift index 7b473eeda4..5577288f08 100644 --- a/UnstoppableWallet/UnstoppableWallet/Modules/Send/Confirmation/SendConfirmationViewModel.swift +++ b/UnstoppableWallet/UnstoppableWallet/Modules/Send/Confirmation/SendConfirmationViewModel.swift @@ -43,7 +43,7 @@ class SendConfirmationViewModel { .amount( title: "send.confirmation.you_send".localized, token: service.token, - coinAmount: ValueFormatter.instance.formatFull(coinValue: item.coinValue) ?? "n/a".localized, + coinAmount: item.appValue.formattedFull() ?? "n/a".localized, currencyAmount: item.currencyValue.flatMap { ValueFormatter.instance.formatFull(currencyValue: $0) }, type: .neutral ) @@ -80,7 +80,7 @@ class SendConfirmationViewModel { ) ) case let item as SendConfirmationFeeViewItem: - let value = [ValueFormatter.instance.formatFull(coinValue: item.coinValue), item.currencyValue.flatMap { ValueFormatter.instance.formatFull(currencyValue: $0) }] + let value = [item.appValue.formattedFull(), item.currencyValue.flatMap { ValueFormatter.instance.formatFull(currencyValue: $0) }] .compactMap { $0 } .joined(separator: " | ") diff --git a/UnstoppableWallet/UnstoppableWallet/Modules/Send/Fee/SendFeeService.swift b/UnstoppableWallet/UnstoppableWallet/Modules/Send/Fee/SendFeeService.swift index 98e6712db7..d6bbc7db4e 100644 --- a/UnstoppableWallet/UnstoppableWallet/Modules/Send/Fee/SendFeeService.swift +++ b/UnstoppableWallet/UnstoppableWallet/Modules/Send/Fee/SendFeeService.swift @@ -56,8 +56,8 @@ class SendFeeService { } private func amountInfo(value: Decimal) -> AmountInfo { - let coinValue = CoinValue(kind: .token(token: feeToken), value: value) - return AmountInfo.coinValue(coinValue: coinValue) + let appValue = AppValue(token: feeToken, value: value) + return .appValue(appValue: appValue) } private func sync(primaryInfo: FiatService.PrimaryInfo? = nil, secondaryInfo: AmountInfo? = nil) { diff --git a/UnstoppableWallet/UnstoppableWallet/Modules/Send/Platforms/Binance/FeeWarning/SendBinanceFeeWarningViewModel.swift b/UnstoppableWallet/UnstoppableWallet/Modules/Send/Platforms/Binance/FeeWarning/SendBinanceFeeWarningViewModel.swift index bcacb6c29c..e674d63b47 100644 --- a/UnstoppableWallet/UnstoppableWallet/Modules/Send/Platforms/Binance/FeeWarning/SendBinanceFeeWarningViewModel.swift +++ b/UnstoppableWallet/UnstoppableWallet/Modules/Send/Platforms/Binance/FeeWarning/SendBinanceFeeWarningViewModel.swift @@ -7,8 +7,8 @@ class SendBinanceFeeWarningViewModel { init(adapter: ISendBinanceAdapter, coinCode: String, feeToken: Token) { if adapter.fee > adapter.availableBinanceBalance { - let fee = CoinValue(kind: .token(token: feeToken), value: adapter.fee) - let feeString = ValueFormatter.instance.formatFull(coinValue: fee) ?? "" + let fee = AppValue(token: feeToken, value: adapter.fee) + let feeString = fee.formattedFull() ?? "" let text = "send.token.insufficient_fee_alert".localized(coinCode, feeToken.blockchain.name, feeToken.coin.name, feeString) cautionRelay.accept(TitledCaution(title: "fee_settings.errors.insufficient_balance".localized, text: text, type: .error)) diff --git a/UnstoppableWallet/UnstoppableWallet/Modules/Send/Platforms/Binance/SendBinanceFactory.swift b/UnstoppableWallet/UnstoppableWallet/Modules/Send/Platforms/Binance/SendBinanceFactory.swift index 13e98dff47..a799304bcc 100644 --- a/UnstoppableWallet/UnstoppableWallet/Modules/Send/Platforms/Binance/SendBinanceFactory.swift +++ b/UnstoppableWallet/UnstoppableWallet/Modules/Send/Platforms/Binance/SendBinanceFactory.swift @@ -28,16 +28,16 @@ class SendBinanceFactory: BaseSendFactory { throw ConfirmationError.noAddress } - let (coinValue, currencyValue) = try values(fiatService: fiatService) - let (feeCoinValue, feeCurrencyValue) = try values(fiatService: feeFiatService) + let (appValue, currencyValue) = try values(fiatService: fiatService) + let (feeAppValue, feeCurrencyValue) = try values(fiatService: feeFiatService) - viewItems.append(SendConfirmationAmountViewItem(coinValue: coinValue, currencyValue: currencyValue, receiver: address)) + viewItems.append(SendConfirmationAmountViewItem(appValue: appValue, currencyValue: currencyValue, receiver: address)) if let memo = memoService.memo, !memo.isEmpty { viewItems.append(SendConfirmationMemoViewItem(memo: memo)) } - viewItems.append(SendConfirmationFeeViewItem(coinValue: feeCoinValue, currencyValue: feeCurrencyValue)) + viewItems.append(SendConfirmationFeeViewItem(appValue: feeAppValue, currencyValue: feeCurrencyValue)) return viewItems } diff --git a/UnstoppableWallet/UnstoppableWallet/Modules/Send/Platforms/Bitcoin/SendBitcoinFactory.swift b/UnstoppableWallet/UnstoppableWallet/Modules/Send/Platforms/Bitcoin/SendBitcoinFactory.swift index f9897b852c..a0db588d0d 100644 --- a/UnstoppableWallet/UnstoppableWallet/Modules/Send/Platforms/Bitcoin/SendBitcoinFactory.swift +++ b/UnstoppableWallet/UnstoppableWallet/Modules/Send/Platforms/Bitcoin/SendBitcoinFactory.swift @@ -16,42 +16,40 @@ protocol ISendOutputSelectorFactory { } class BaseSendFactory { - func values(fiatService: FiatService) throws -> (CoinValue, CurrencyValue?) { + func values(fiatService: FiatService) throws -> (AppValue, CurrencyValue?) { guard let token = fiatService.token else { throw ConfirmationError.noCoin } - var coinValue: CoinValue? + var appValue: AppValue? var currencyValue: CurrencyValue? switch fiatService.primaryInfo { case let .amount(value): - coinValue = CoinValue(kind: .token(token: token), value: value) + appValue = AppValue(token: token, value: value) case let .amountInfo(info): guard let info else { throw ConfirmationError.noAmount } switch info { - case let .coinValue(value): coinValue = value + case let .appValue(value): appValue = value case let .currencyValue(value): currencyValue = value } } if let info = fiatService.secondaryAmountInfo { switch info { - case let .coinValue(value): coinValue = value + case let .appValue(value): appValue = value case let .currencyValue(value): currencyValue = value } } - guard let coinValue else { + guard let appValue else { throw ConfirmationError.noAmount } - let negativeCoinValue = CoinValue(kind: coinValue.kind, value: Decimal(sign: .minus, exponent: coinValue.value.exponent, significand: coinValue.value.significand)) - - return (negativeCoinValue, currencyValue) + return (appValue.negative, currencyValue) } } @@ -97,16 +95,16 @@ class SendBitcoinFactory: BaseSendFactory { throw ConfirmationError.noAddress } - let (coinValue, currencyValue) = try values(fiatService: fiatService) - let (feeCoinValue, feeCurrencyValue) = try values(fiatService: feeFiatService) + let (appValue, currencyValue) = try values(fiatService: fiatService) + let (feeAppValue, feeCurrencyValue) = try values(fiatService: feeFiatService) - viewItems.append(SendConfirmationAmountViewItem(coinValue: coinValue, currencyValue: currencyValue, receiver: address)) + viewItems.append(SendConfirmationAmountViewItem(appValue: appValue, currencyValue: currencyValue, receiver: address)) if memoService.isAvailable, let memo = memoService.memo, !memo.isEmpty { viewItems.append(SendConfirmationMemoViewItem(memo: memo)) } - viewItems.append(SendConfirmationFeeViewItem(coinValue: feeCoinValue, currencyValue: feeCurrencyValue)) + viewItems.append(SendConfirmationFeeViewItem(appValue: feeAppValue, currencyValue: feeCurrencyValue)) if !App.shared.btcBlockchainManager.transactionRbfEnabled(blockchainType: token.blockchainType) { viewItems.append(SendConfirmationDisabledRbfViewItem()) diff --git a/UnstoppableWallet/UnstoppableWallet/Modules/Send/Platforms/Zcash/SendZcashFactory.swift b/UnstoppableWallet/UnstoppableWallet/Modules/Send/Platforms/Zcash/SendZcashFactory.swift index e07d770df1..dd1fcc1f16 100644 --- a/UnstoppableWallet/UnstoppableWallet/Modules/Send/Platforms/Zcash/SendZcashFactory.swift +++ b/UnstoppableWallet/UnstoppableWallet/Modules/Send/Platforms/Zcash/SendZcashFactory.swift @@ -28,16 +28,16 @@ class SendZcashFactory: BaseSendFactory { throw ConfirmationError.noAddress } - let (coinValue, currencyValue) = try values(fiatService: fiatService) - let (feeCoinValue, feeCurrencyValue) = try values(fiatService: feeFiatService) + let (appValue, currencyValue) = try values(fiatService: fiatService) + let (feeAppValue, feeCurrencyValue) = try values(fiatService: feeFiatService) - viewItems.append(SendConfirmationAmountViewItem(coinValue: coinValue, currencyValue: currencyValue, receiver: address)) + viewItems.append(SendConfirmationAmountViewItem(appValue: appValue, currencyValue: currencyValue, receiver: address)) if memoService.isAvailable, let memo = memoService.memo, !memo.isEmpty { viewItems.append(SendConfirmationMemoViewItem(memo: memo)) } - viewItems.append(SendConfirmationFeeViewItem(coinValue: feeCoinValue, currencyValue: feeCurrencyValue)) + viewItems.append(SendConfirmationFeeViewItem(appValue: feeAppValue, currencyValue: feeCurrencyValue)) return viewItems } diff --git a/UnstoppableWallet/UnstoppableWallet/Modules/SendEvm/SendAvailableBalanceViewModel.swift b/UnstoppableWallet/UnstoppableWallet/Modules/SendEvm/SendAvailableBalanceViewModel.swift index 1497d284ec..7c8c6c4630 100644 --- a/UnstoppableWallet/UnstoppableWallet/Modules/SendEvm/SendAvailableBalanceViewModel.swift +++ b/UnstoppableWallet/UnstoppableWallet/Modules/SendEvm/SendAvailableBalanceViewModel.swift @@ -64,8 +64,8 @@ class SendAvailableBalanceViewModel { let currencyValue = CurrencyValue(currency: rate.currency, value: availableBalance * rate.value) value = ValueFormatter.instance.formatFull(currencyValue: currencyValue) } else { - let coinValue = coinService.coinValue(value: availableBalance) - value = ValueFormatter.instance.formatFull(coinValue: coinValue) + let appValue = coinService.appValue(value: availableBalance) + value = appValue.formattedFull() } viewStateRelay.accept(.loaded(value: value)) diff --git a/UnstoppableWallet/UnstoppableWallet/Modules/SendEvmTransaction/SendEvmTransactionViewModel.swift b/UnstoppableWallet/UnstoppableWallet/Modules/SendEvmTransaction/SendEvmTransactionViewModel.swift index 7da1b9bfe3..7b59654a6e 100644 --- a/UnstoppableWallet/UnstoppableWallet/Modules/SendEvmTransaction/SendEvmTransactionViewModel.swift +++ b/UnstoppableWallet/UnstoppableWallet/Modules/SendEvmTransaction/SendEvmTransactionViewModel.swift @@ -220,20 +220,20 @@ class SendEvmTransactionViewModel { } private func amountViewItem(title: String, coinService: CoinService, amountData: AmountData, type: AmountType) -> ViewItem { - let value = amountData.coinValue + let appValue = amountData.appValue return .amount( title: title, token: coinService.token, - coinAmount: value.isMaxValue ? value.infinity : value.formattedFull ?? "n/a".localized, - currencyAmount: value.isMaxValue ? nil : amountData.currencyValue.flatMap { ValueFormatter.instance.formatFull(currencyValue: $0) }, + coinAmount: appValue.isMaxValue ? appValue.infinity : appValue.formattedFull() ?? "n/a".localized, + currencyAmount: appValue.isMaxValue ? nil : amountData.currencyValue.flatMap { ValueFormatter.instance.formatFull(currencyValue: $0) }, type: type ) } private func estimatedAmountViewItem(title: String, coinService: CoinService, value: Decimal, type: AmountType) -> ViewItem { let amountData = coinService.amountData(value: value, sign: type.sign) - let coinAmount = ValueFormatter.instance.formatFull(coinValue: amountData.coinValue) ?? "n/a".localized + let coinAmount = amountData.appValue.formattedFull() ?? "n/a".localized return .amount( title: title, @@ -266,7 +266,7 @@ class SendEvmTransactionViewModel { return .doubleAmount( title: title, - coinAmount: ValueFormatter.instance.formatFull(coinValue: amountData.coinValue) ?? "n/a".localized, + coinAmount: amountData.appValue.formattedFull() ?? "n/a".localized, currencyAmount: amountData.currencyValue.flatMap { ValueFormatter.instance.formatFull(currencyValue: $0) } ) } @@ -602,8 +602,8 @@ class SendEvmTransactionViewModel { let executionPrice = amountTo / amountFrom let reverted = amountTo < amountFrom - let coinValue = CoinValue(kind: .token(token: reverted ? tokenFrom : tokenTo), value: reverted ? 1 / executionPrice : executionPrice) - let fullValue = ValueFormatter.instance.formatFull(coinValue: coinValue).map { "1 " + [(reverted ? tokenTo : tokenFrom).coin.code, $0].joined(separator: " = ") } ?? "" + let appValue = AppValue(token: reverted ? tokenFrom : tokenTo, value: reverted ? 1 / executionPrice : executionPrice) + let fullValue = appValue.formattedFull().map { "1 " + [(reverted ? tokenTo : tokenFrom).coin.code, $0].joined(separator: " = ") } ?? "" return .value(title: "swap.price".localized, value: fullValue, type: .regular) } return nil diff --git a/UnstoppableWallet/UnstoppableWallet/Modules/SendNew/BaseSendBtcData.swift b/UnstoppableWallet/UnstoppableWallet/Modules/SendNew/BaseSendBtcData.swift index 36f64fe022..8bf31a4d13 100644 --- a/UnstoppableWallet/UnstoppableWallet/Modules/SendNew/BaseSendBtcData.swift +++ b/UnstoppableWallet/UnstoppableWallet/Modules/SendNew/BaseSendBtcData.swift @@ -17,7 +17,7 @@ class BaseSendBtcData { } return AmountData( - coinValue: CoinValue(kind: .token(token: feeToken), value: fee), + appValue: AppValue(token: feeToken, value: fee), currencyValue: feeTokenRate.map { CurrencyValue(currency: currency, value: fee * $0) } ) } @@ -29,7 +29,7 @@ class BaseSendBtcData { .value( title: "fee_settings.network_fee".localized, description: .init(title: "fee_settings.network_fee".localized, description: "fee_settings.network_fee.info".localized), - coinValue: amountData?.coinValue, + appValue: amountData?.appValue, currencyValue: amountData?.currencyValue, formatFull: true ), diff --git a/UnstoppableWallet/UnstoppableWallet/Modules/SendNew/BaseSendEvmData.swift b/UnstoppableWallet/UnstoppableWallet/Modules/SendNew/BaseSendEvmData.swift index 8c54953c85..78dbd21968 100644 --- a/UnstoppableWallet/UnstoppableWallet/Modules/SendNew/BaseSendEvmData.swift +++ b/UnstoppableWallet/UnstoppableWallet/Modules/SendNew/BaseSendEvmData.swift @@ -20,7 +20,7 @@ class BaseSendEvmData { .value( title: "fee_settings.network_fee".localized, description: .init(title: "fee_settings.network_fee".localized, description: "fee_settings.network_fee.info".localized), - coinValue: amountData?.coinValue, + appValue: amountData?.appValue, currencyValue: amountData?.currencyValue, formatFull: true ), diff --git a/UnstoppableWallet/UnstoppableWallet/Modules/SendNew/BinanceSendHandler.swift b/UnstoppableWallet/UnstoppableWallet/Modules/SendNew/BinanceSendHandler.swift index eae9cedbc3..975a2b1ecb 100644 --- a/UnstoppableWallet/UnstoppableWallet/Modules/SendNew/BinanceSendHandler.swift +++ b/UnstoppableWallet/UnstoppableWallet/Modules/SendNew/BinanceSendHandler.swift @@ -76,7 +76,7 @@ extension BinanceSendHandler { .amount( title: "send.confirmation.you_send".localized, token: token, - coinValueType: .regular(coinValue: CoinValue(kind: .token(token: token), value: amount)), + appValueType: .regular(appValue: AppValue(token: token, value: amount)), currencyValue: rates[token.coin.uid].map { CurrencyValue(currency: currency, value: $0 * amount) }, type: .neutral ), @@ -97,7 +97,7 @@ extension BinanceSendHandler { .value( title: "fee_settings.network_fee".localized, description: .init(title: "fee_settings.network_fee".localized, description: "fee_settings.network_fee.info".localized), - coinValue: CoinValue(kind: .token(token: baseToken), value: fee), + appValue: AppValue(token: baseToken, value: fee), currencyValue: rates[baseToken.coin.uid].map { CurrencyValue(currency: currency, value: fee * $0) }, formatFull: true ), diff --git a/UnstoppableWallet/UnstoppableWallet/Modules/SendNew/BitcoinFeeData.swift b/UnstoppableWallet/UnstoppableWallet/Modules/SendNew/BitcoinFeeData.swift index b1f94135e5..39714422ca 100644 --- a/UnstoppableWallet/UnstoppableWallet/Modules/SendNew/BitcoinFeeData.swift +++ b/UnstoppableWallet/UnstoppableWallet/Modules/SendNew/BitcoinFeeData.swift @@ -11,9 +11,9 @@ struct BitcoinFeeData { } func amountData(feeToken: Token, currency: Currency, feeTokenRate: Decimal?) -> AmountData? { - let coinValue = CoinValue(kind: .token(token: feeToken), value: fee) + let appValue = AppValue(token: feeToken, value: fee) let currencyValue = feeTokenRate.map { CurrencyValue(currency: currency, value: fee * $0) } - return AmountData(coinValue: coinValue, currencyValue: currencyValue) + return AmountData(appValue: appValue, currencyValue: currencyValue) } } diff --git a/UnstoppableWallet/UnstoppableWallet/Modules/SendNew/BitcoinSendHandler.swift b/UnstoppableWallet/UnstoppableWallet/Modules/SendNew/BitcoinSendHandler.swift index d31f1a5324..05c7a0d16e 100644 --- a/UnstoppableWallet/UnstoppableWallet/Modules/SendNew/BitcoinSendHandler.swift +++ b/UnstoppableWallet/UnstoppableWallet/Modules/SendNew/BitcoinSendHandler.swift @@ -106,7 +106,7 @@ extension BitcoinSendHandler { } let decimalValue = baseToken.decimalValue(value: value) - let coinValue = CoinValue(kind: .token(token: baseToken), value: -decimalValue) + let appValue = AppValue(token: baseToken, value: -decimalValue) let rate = rates[baseToken.coin.uid] return [ @@ -114,7 +114,7 @@ extension BitcoinSendHandler { .amount( title: "send.confirmation.you_send".localized, token: baseToken, - coinValueType: .regular(coinValue: coinValue), + appValueType: .regular(appValue: appValue), currencyValue: rate.map { CurrencyValue(currency: currency, value: $0 * decimalValue) }, type: .neutral ), diff --git a/UnstoppableWallet/UnstoppableWallet/Modules/SendNew/EvmDecoration.swift b/UnstoppableWallet/UnstoppableWallet/Modules/SendNew/EvmDecoration.swift index aead9eec8e..437a3de0c4 100644 --- a/UnstoppableWallet/UnstoppableWallet/Modules/SendNew/EvmDecoration.swift +++ b/UnstoppableWallet/UnstoppableWallet/Modules/SendNew/EvmDecoration.swift @@ -56,7 +56,7 @@ struct EvmDecoration { amountField = .amount( title: "approve.confirmation.you_revoke".localized, token: token, - coinValueType: .withoutAmount(kind: .token(token: token)), + appValueType: .withoutAmount(code: token.coin.code), currencyValue: nil, type: .neutral ) @@ -109,13 +109,13 @@ struct EvmDecoration { } private func amountField(title: String, token: Token, value: Decimal, currency: Currency, rate: Decimal?, type: SendField.AmountType) -> SendField { - let coinValue = CoinValue(kind: .token(token: token), value: Decimal(sign: type.sign, exponent: value.exponent, significand: value.significand)) + let appValue = AppValue(token: token, value: Decimal(sign: type.sign, exponent: value.exponent, significand: value.significand)) return .amount( title: title, token: token, - coinValueType: coinValue.isMaxValue ? .infinity(kind: coinValue.kind) : .regular(coinValue: coinValue), - currencyValue: coinValue.isMaxValue ? nil : rate.map { CurrencyValue(currency: currency, value: $0 * value) }, + appValueType: appValue.isMaxValue ? .infinity(code: appValue.code) : .regular(appValue: appValue), + currencyValue: appValue.isMaxValue ? nil : rate.map { CurrencyValue(currency: currency, value: $0 * value) }, type: type ) } diff --git a/UnstoppableWallet/UnstoppableWallet/Modules/SendNew/EvmFeeData.swift b/UnstoppableWallet/UnstoppableWallet/Modules/SendNew/EvmFeeData.swift index c4578733df..9126d5998d 100644 --- a/UnstoppableWallet/UnstoppableWallet/Modules/SendNew/EvmFeeData.swift +++ b/UnstoppableWallet/UnstoppableWallet/Modules/SendNew/EvmFeeData.swift @@ -48,10 +48,10 @@ struct EvmFeeData { } private func amountData(amount: Decimal, feeToken: Token, currency: Currency, feeTokenRate: Decimal?) -> AmountData? { - let coinValue = CoinValue(kind: .token(token: feeToken), value: amount) + let appValue = AppValue(token: feeToken, value: amount) let currencyValue = feeTokenRate.map { CurrencyValue(currency: currency, value: amount * $0) } - return AmountData(coinValue: coinValue, currencyValue: currencyValue) + return AmountData(appValue: appValue, currencyValue: currencyValue) } private func l1FeeValue(feeToken: Token) -> Decimal? { diff --git a/UnstoppableWallet/UnstoppableWallet/Modules/SendNew/FeeSettings/FeeSettingsViewHelper.swift b/UnstoppableWallet/UnstoppableWallet/Modules/SendNew/FeeSettings/FeeSettingsViewHelper.swift index 591e9581c3..b2af406903 100644 --- a/UnstoppableWallet/UnstoppableWallet/Modules/SendNew/FeeSettings/FeeSettingsViewHelper.swift +++ b/UnstoppableWallet/UnstoppableWallet/Modules/SendNew/FeeSettings/FeeSettingsViewHelper.swift @@ -16,7 +16,7 @@ class FeeSettingsViewHelper { } let l2Value = FeeSettings.FeeValue.value( - primary: ValueFormatter.instance.formatShort(coinValue: l2AmountData.coinValue) ?? "", + primary: l2AmountData.appValue.formattedShort() ?? "", secondary: l2AmountData.currencyValue.flatMap { ValueFormatter.instance.formatShort(currencyValue: $0) } ?? "n/a".localized ) @@ -24,7 +24,7 @@ class FeeSettingsViewHelper { if let l1AmountData = evmFeeData.l1AmountData(feeToken: feeToken, currency: currency, feeTokenRate: feeTokenRate) { l1Value = FeeSettings.FeeValue.value( - primary: ValueFormatter.instance.formatShort(coinValue: l1AmountData.coinValue) ?? "", + primary: l1AmountData.appValue.formattedShort() ?? "", secondary: l1AmountData.currencyValue.flatMap { ValueFormatter.instance.formatShort(currencyValue: $0) } ?? "n/a".localized ) } @@ -44,7 +44,7 @@ class FeeSettingsViewHelper { } return .value( - primary: ValueFormatter.instance.formatShort(coinValue: amountData.coinValue) ?? "", + primary: amountData.appValue.formattedShort() ?? "", secondary: amountData.currencyValue.flatMap { ValueFormatter.instance.formatShort(currencyValue: $0) } ?? "n/a".localized ) } diff --git a/UnstoppableWallet/UnstoppableWallet/Modules/SendNew/OutputSelectorViewModel2.swift b/UnstoppableWallet/UnstoppableWallet/Modules/SendNew/OutputSelectorViewModel2.swift index 126f38509e..b83516a276 100644 --- a/UnstoppableWallet/UnstoppableWallet/Modules/SendNew/OutputSelectorViewModel2.swift +++ b/UnstoppableWallet/UnstoppableWallet/Modules/SendNew/OutputSelectorViewModel2.swift @@ -48,19 +48,19 @@ class OutputSelectorViewModel2: ObservableObject { outputsViewItems = all.map { viewItem(unspentOutput: $0) } allSelected = all.count == selectedSet.count - let coinValue = coinValue(satoshiValue: handler.availableBalance) + let appValue = appValue(satoshiValue: handler.availableBalance) let currencyValue = rate.flatMap { - CurrencyValue(currency: App.shared.currencyManager.baseCurrency, value: coinValue.value * $0) + CurrencyValue(currency: App.shared.currencyManager.baseCurrency, value: appValue.value * $0) } - availableBalanceCoinValue = coinValue.formattedFull ?? "n/a".localized + availableBalanceCoinValue = appValue.formattedFull() ?? "n/a".localized availableBalanceFiatValue = currencyValue.flatMap(\.formattedFull) } private func viewItem(unspentOutput: UnspentOutputInfo) -> OutputViewItem { - let coinValue = coinValue(satoshiValue: unspentOutput.value) + let appValue = appValue(satoshiValue: unspentOutput.value) let currencyValue = rate.flatMap { - CurrencyValue(currency: App.shared.currencyManager.baseCurrency, value: coinValue.value * $0) + CurrencyValue(currency: App.shared.currencyManager.baseCurrency, value: appValue.value * $0) } return OutputViewItem( @@ -68,15 +68,15 @@ class OutputSelectorViewModel2: ObservableObject { transactionHash: unspentOutput.transactionHash, date: DateHelper.instance.formatShortDateOnly(date: Date(timeIntervalSince1970: TimeInterval(unspentOutput.timestamp))), address: unspentOutput.address?.shortened ?? "n/a".localized, - coinValue: coinValue.formattedFull ?? "n/a".localized, + coinValue: appValue.formattedFull() ?? "n/a".localized, fiatValue: currencyValue.flatMap(\.formattedFull) ) } - private func coinValue(satoshiValue: Int) -> CoinValue { + private func appValue(satoshiValue: Int) -> AppValue { let coinRate = pow(10, handler.token.decimals) let decimalValue = Decimal(satoshiValue) / coinRate - return CoinValue(kind: .token(token: handler.token), value: decimalValue) + return AppValue(token: handler.token, value: decimalValue) } } diff --git a/UnstoppableWallet/UnstoppableWallet/Modules/SendNew/PreSendView.swift b/UnstoppableWallet/UnstoppableWallet/Modules/SendNew/PreSendView.swift index 5a02cf3eaf..6018ae2d64 100644 --- a/UnstoppableWallet/UnstoppableWallet/Modules/SendNew/PreSendView.swift +++ b/UnstoppableWallet/UnstoppableWallet/Modules/SendNew/PreSendView.swift @@ -249,7 +249,7 @@ struct PreSendView: View { return nil } - return ValueFormatter.instance.formatFull(coinValue: CoinValue(kind: .token(token: viewModel.token), value: availableBalance)) + return AppValue(token: viewModel.token, value: availableBalance).formattedFull() } private func buttonState() -> (String, Bool, Bool) { diff --git a/UnstoppableWallet/UnstoppableWallet/Modules/SendNew/SendField.swift b/UnstoppableWallet/UnstoppableWallet/Modules/SendNew/SendField.swift index 8e648322b9..2e22c6cd14 100644 --- a/UnstoppableWallet/UnstoppableWallet/Modules/SendNew/SendField.swift +++ b/UnstoppableWallet/UnstoppableWallet/Modules/SendNew/SendField.swift @@ -4,8 +4,8 @@ import MarketKit import SwiftUI enum SendField { - case amount(title: String, token: Token, coinValueType: CoinValueType, currencyValue: CurrencyValue?, type: AmountType) - case value(title: String, description: ActionSheetView.InfoDescription?, coinValue: CoinValue?, currencyValue: CurrencyValue?, formatFull: Bool) + case amount(title: String, token: Token, appValueType: AppValueType, currencyValue: CurrencyValue?, type: AmountType) + case value(title: String, description: ActionSheetView.InfoDescription?, appValue: AppValue?, currencyValue: CurrencyValue?, formatFull: Bool) case doubleValue(title: String, description: ActionSheetView.InfoDescription?, value1: String, value2: String?) case levelValue(title: String, value: String, level: ValueLevel) case address(title: String, value: String, blockchainType: BlockchainType) @@ -14,7 +14,7 @@ enum SendField { @ViewBuilder var listRow: some View { switch self { - case let .amount(title, token, coinValueType, currencyValue, type): + case let .amount(title, token, appValueType, currencyValue, type): ListRow { CoinIconView(coin: token.coin) @@ -27,7 +27,7 @@ enum SendField { Spacer() VStack(alignment: .trailing, spacing: 1) { - if let formatted = coinValueType.formatted(full: true) { + if let formatted = appValueType.formattedFull { Text(formatted) .textSubhead1(color: type.color) .multilineTextAlignment(.trailing) @@ -45,7 +45,7 @@ enum SendField { } } } - case let .value(title, description, coinValue, currencyValue, formatFull): + case let .value(title, description, appValue, currencyValue, formatFull): ListRow(padding: EdgeInsets(top: .margin12, leading: description == nil ? .margin16 : 0, bottom: .margin12, trailing: .margin16)) { if let description { Text(title) @@ -59,7 +59,7 @@ enum SendField { Spacer() VStack(alignment: .trailing, spacing: 1) { - if let formatted = (formatFull ? coinValue?.formattedFull : coinValue?.formattedShort) { + if let formatted = (formatFull ? appValue?.formattedFull() : appValue?.formattedShort()) { Text(formatted) .textSubhead1(color: .themeLeah) .multilineTextAlignment(.trailing) @@ -142,18 +142,26 @@ enum SendField { } } - enum CoinValueType { - case regular(coinValue: CoinValue) - case infinity(kind: CoinValue.Kind) - case withoutAmount(kind: CoinValue.Kind) + enum AppValueType { + case regular(appValue: AppValue) + case infinity(code: String) + case withoutAmount(code: String) - func formatted(full: Bool = false) -> String? { + private func formatted(full: Bool) -> String? { switch self { - case let .regular(coinValue): return full ? ValueFormatter.instance.formatFull(coinValue: coinValue) : ValueFormatter.instance.formatShort(coinValue: coinValue) - case let .infinity(kind): return "∞ \(kind.symbol)" - case let .withoutAmount(kind): return "\(kind.symbol)" + case let .regular(appValue): return full ? appValue.formattedFull() : appValue.formattedShort() + case let .infinity(code): return "∞ \(code)" + case let .withoutAmount(code): return "\(code)" } } + + var formattedFull: String? { + formatted(full: true) + } + + var formattedShort: String? { + formatted(full: false) + } } enum AmountType { diff --git a/UnstoppableWallet/UnstoppableWallet/Modules/SendNew/TonSendHandler.swift b/UnstoppableWallet/UnstoppableWallet/Modules/SendNew/TonSendHandler.swift index 83cf6d93d9..57b47befec 100644 --- a/UnstoppableWallet/UnstoppableWallet/Modules/SendNew/TonSendHandler.swift +++ b/UnstoppableWallet/UnstoppableWallet/Modules/SendNew/TonSendHandler.swift @@ -141,8 +141,8 @@ extension TonSendHandler { if let tonError = transactionError as? TonSendHandler.TransactionError { switch tonError { case let .insufficientTonBalance(balance): - let coinValue = CoinValue(kind: .token(token: feeToken), value: balance) - let balanceString = ValueFormatter.instance.formatShort(coinValue: coinValue) + let appValue = AppValue(token: feeToken, value: balance) + let balanceString = appValue.formattedShort() title = "fee_settings.errors.insufficient_balance".localized text = "fee_settings.errors.insufficient_balance.info".localized(balanceString ?? "") @@ -170,7 +170,7 @@ extension TonSendHandler { .amount( title: "send.confirmation.you_send".localized, token: token, - coinValueType: .regular(coinValue: CoinValue(kind: .token(token: token), value: amount)), + appValueType: .regular(appValue: AppValue(token: token, value: amount)), currencyValue: rates[token.coin.uid].map { CurrencyValue(currency: currency, value: $0 * amount) }, type: .neutral ), @@ -195,14 +195,14 @@ extension TonSendHandler { var viewItems = [SendField]() if let fee { - let coinValue = CoinValue(kind: .token(token: feeToken), value: fee) + let appValue = AppValue(token: feeToken, value: fee) let currencyValue = feeTokenRate.map { CurrencyValue(currency: currency, value: fee * $0) } viewItems.append( .value( title: "fee_settings.network_fee".localized, description: .init(title: "fee_settings.network_fee".localized, description: "fee_settings.network_fee.info".localized), - coinValue: coinValue, + appValue: appValue, currencyValue: currencyValue, formatFull: true ) diff --git a/UnstoppableWallet/UnstoppableWallet/Modules/SendNew/TronSendData.swift b/UnstoppableWallet/UnstoppableWallet/Modules/SendNew/TronSendData.swift index 89733f2f3d..0b501e52c9 100644 --- a/UnstoppableWallet/UnstoppableWallet/Modules/SendNew/TronSendData.swift +++ b/UnstoppableWallet/UnstoppableWallet/Modules/SendNew/TronSendData.swift @@ -41,14 +41,14 @@ class TronSendData: ISendData { if let totalFees { let decimalAmount = Decimal(totalFees) / pow(10, baseToken.decimals) - let coinValue = CoinValue(kind: .token(token: baseToken), value: decimalAmount) + let appValue = AppValue(token: baseToken, value: decimalAmount) let currencyValue = feeTokenRate.map { CurrencyValue(currency: currency, value: decimalAmount * $0) } viewItems.append( .value( title: "fee_settings.network_fee".localized, description: .init(title: "fee_settings.network_fee".localized, description: "fee_settings.network_fee.info".localized), - coinValue: coinValue, + appValue: appValue, currencyValue: currencyValue, formatFull: true ) @@ -63,14 +63,14 @@ class TronSendData: ISendData { switch fee { case let .accountActivation(amount): let decimalAmount = Decimal(amount) / pow(10, baseToken.decimals) - let coinValue = CoinValue(kind: .token(token: baseToken), value: decimalAmount) + let appValue = AppValue(token: baseToken, value: decimalAmount) let currencyValue = feeTokenRate.map { CurrencyValue(currency: currency, value: decimalAmount * $0) } viewItems.append( .value( title: "tron.send.activation_fee".localized, description: .init(title: "tron.send.activation_fee".localized, description: "tron.send.activation_fee.info".localized), - coinValue: coinValue, + appValue: appValue, currencyValue: currencyValue, formatFull: true ) @@ -131,14 +131,14 @@ class TronSendData: ISendData { } private func sendFields(to: TronKit.Address, value: Decimal, currency: Currency, rate: Decimal?) -> [[SendField]] { - let coinValue = CoinValue(kind: .token(token: token), value: Decimal(sign: .plus, exponent: value.exponent, significand: value.significand)) + let appValue = AppValue(token: token, value: Decimal(sign: .plus, exponent: value.exponent, significand: value.significand)) return [[ .amount( title: "send.confirmation.you_send".localized, token: token, - coinValueType: coinValue.isMaxValue ? .infinity(kind: coinValue.kind) : .regular(coinValue: coinValue), - currencyValue: coinValue.isMaxValue ? nil : rate.map { CurrencyValue(currency: currency, value: $0 * value) }, + appValueType: appValue.isMaxValue ? .infinity(code: appValue.code) : .regular(appValue: appValue), + currencyValue: appValue.isMaxValue ? nil : rate.map { CurrencyValue(currency: currency, value: $0 * value) }, type: .neutral ), .address( @@ -156,8 +156,8 @@ class TronSendData: ISendData { if let tronError = transactionError as? TronSendHandler.TransactionError { switch tronError { case let .insufficientBalance(balance): - let coinValue = CoinValue(kind: .token(token: feeToken), value: balance.toDecimal(decimals: feeToken.decimals) ?? 0) - let balanceString = ValueFormatter.instance.formatShort(coinValue: coinValue) + let appValue = AppValue(token: feeToken, value: balance.toDecimal(decimals: feeToken.decimals) ?? 0) + let balanceString = appValue.formattedShort() title = "fee_settings.errors.insufficient_balance".localized text = "fee_settings.errors.insufficient_balance.info".localized(balanceString ?? "") diff --git a/UnstoppableWallet/UnstoppableWallet/Modules/SendNew/ZcashSendHandler.swift b/UnstoppableWallet/UnstoppableWallet/Modules/SendNew/ZcashSendHandler.swift index 87d0b0c4e9..3e67fa14bc 100644 --- a/UnstoppableWallet/UnstoppableWallet/Modules/SendNew/ZcashSendHandler.swift +++ b/UnstoppableWallet/UnstoppableWallet/Modules/SendNew/ZcashSendHandler.swift @@ -79,7 +79,7 @@ extension ZcashSendHandler { .amount( title: "send.confirmation.you_send".localized, token: token, - coinValueType: .regular(coinValue: CoinValue(kind: .token(token: token), value: amount)), + appValueType: .regular(appValue: AppValue(token: token, value: amount)), currencyValue: rates[token.coin.uid].map { CurrencyValue(currency: currency, value: $0 * amount) }, type: .neutral ), @@ -100,7 +100,7 @@ extension ZcashSendHandler { .value( title: "fee_settings.network_fee".localized, description: .init(title: "fee_settings.network_fee".localized, description: "fee_settings.network_fee.info".localized), - coinValue: CoinValue(kind: .token(token: baseToken), value: fee), + appValue: AppValue(token: baseToken, value: fee), currencyValue: rates[baseToken.coin.uid].map { CurrencyValue(currency: currency, value: fee * $0) }, formatFull: true ), diff --git a/UnstoppableWallet/UnstoppableWallet/Modules/SendTron/Confirmation/SendTronConfirmationViewModel.swift b/UnstoppableWallet/UnstoppableWallet/Modules/SendTron/Confirmation/SendTronConfirmationViewModel.swift index 3c3c804a09..1d79c2f067 100644 --- a/UnstoppableWallet/UnstoppableWallet/Modules/SendTron/Confirmation/SendTronConfirmationViewModel.swift +++ b/UnstoppableWallet/UnstoppableWallet/Modules/SendTron/Confirmation/SendTronConfirmationViewModel.swift @@ -58,8 +58,8 @@ class SendTronConfirmationViewModel { if let tronError = error as? SendTronConfirmationService.TransactionError { switch tronError { case let .insufficientBalance(balance): - let coinValue = coinServiceFactory.baseCoinService.coinValue(value: balance) - let balanceString = ValueFormatter.instance.formatShort(coinValue: coinValue) + let appValue = coinServiceFactory.baseCoinService.appValue(value: balance) + let balanceString = appValue.formattedShort() return TitledCaution( title: "fee_settings.errors.insufficient_balance".localized, @@ -121,7 +121,7 @@ class SendTronConfirmationViewModel { TronFeeViewItem( title: "tron.send.activation_fee".localized, info: "tron.send.activation_fee.info".localized, - value1: ValueFormatter.instance.formatShort(coinValue: amountData.coinValue) ?? "n/a".localized, + value1: amountData.appValue.formattedShort() ?? "n/a".localized, value2: amountData.currencyValue.flatMap { ValueFormatter.instance.formatShort(currencyValue: $0) }, value2IsSecondary: true ) @@ -194,7 +194,7 @@ class SendTronConfirmationViewModel { .amount( title: title, token: coinService.token, - coinAmount: ValueFormatter.instance.formatFull(coinValue: amountData.coinValue) ?? "n/a".localized, + coinAmount: amountData.appValue.formattedFull() ?? "n/a".localized, currencyAmount: amountData.currencyValue.flatMap { ValueFormatter.instance.formatFull(currencyValue: $0) }, @@ -204,7 +204,7 @@ class SendTronConfirmationViewModel { private func estimatedAmountViewItem(title: String, coinService: CoinService, value: Decimal, type: AmountType) -> ViewItem { let amountData = coinService.amountData(value: value, sign: type.sign) - let coinAmount = ValueFormatter.instance.formatFull(coinValue: amountData.coinValue) ?? "n/a".localized + let coinAmount = amountData.appValue.formattedFull() ?? "n/a".localized return .amount( title: title, diff --git a/UnstoppableWallet/UnstoppableWallet/Modules/Swap/Adapters/OneInch/OneInchService.swift b/UnstoppableWallet/UnstoppableWallet/Modules/Swap/Adapters/OneInch/OneInchService.swift index a19cc6d6a1..df2cd1d9fe 100644 --- a/UnstoppableWallet/UnstoppableWallet/Modules/Swap/Adapters/OneInch/OneInchService.swift +++ b/UnstoppableWallet/UnstoppableWallet/Modules/Swap/Adapters/OneInch/OneInchService.swift @@ -104,7 +104,7 @@ class OneInchService { syncState() } - private func checkAllowanceError(allowance: CoinValue) -> Error? { + private func checkAllowanceError(allowance: AppValue) -> Error? { guard let balanceIn, balanceIn >= tradeService.amountIn, tradeService.amountIn > allowance.value diff --git a/UnstoppableWallet/UnstoppableWallet/Modules/Swap/Adapters/OneInch/OneInchViewModel.swift b/UnstoppableWallet/UnstoppableWallet/Modules/Swap/Adapters/OneInch/OneInchViewModel.swift index db8ebc61d2..c346864ae4 100644 --- a/UnstoppableWallet/UnstoppableWallet/Modules/Swap/Adapters/OneInch/OneInchViewModel.swift +++ b/UnstoppableWallet/UnstoppableWallet/Modules/Swap/Adapters/OneInch/OneInchViewModel.swift @@ -84,8 +84,8 @@ class OneInchViewModel { return } - let coinValue = CoinValue(kind: .token(token: token), value: balance) - availableBalanceRelay.accept(ValueFormatter.instance.formatFull(coinValue: coinValue)) + let appValue = AppValue(token: token, value: balance) + availableBalanceRelay.accept(appValue.formattedFull()) } private func sync(state: OneInchTradeService.State) { @@ -159,7 +159,7 @@ class OneInchViewModel { for error in service.errors { if let allowance = (error as? SwapModule.SwapError)?.revokeAllowance { - revokeWarning = "swap.revoke_warning".localized(ValueFormatter.instance.formatFull(coinValue: allowance) ?? "n/a".localized) + revokeWarning = "swap.revoke_warning".localized(allowance.formattedFull() ?? "n/a".localized) } } if case .pending = pendingAllowanceService.state { diff --git a/UnstoppableWallet/UnstoppableWallet/Modules/Swap/Adapters/Uniswap/SwapViewItemHelper.swift b/UnstoppableWallet/UnstoppableWallet/Modules/Swap/Adapters/Uniswap/SwapViewItemHelper.swift index 47501ae613..5e45538df8 100644 --- a/UnstoppableWallet/UnstoppableWallet/Modules/Swap/Adapters/Uniswap/SwapViewItemHelper.swift +++ b/UnstoppableWallet/UnstoppableWallet/Modules/Swap/Adapters/Uniswap/SwapViewItemHelper.swift @@ -13,8 +13,8 @@ class SwapViewItemHelper { let baseCoins = needToInvert ? (tokenOut, tokenIn) : (tokenIn, tokenOut) let quoteCoins = needToInvert ? (tokenIn, tokenOut) : (tokenOut, tokenIn) - let first = PriceCoinValue(baseCoin: baseCoins.0.coin, quoteCoinValue: CoinValue(kind: .token(token: quoteCoins.0), value: prices.0)) - let second = PriceCoinValue(baseCoin: baseCoins.1.coin, quoteCoinValue: CoinValue(kind: .token(token: quoteCoins.1), value: prices.1)) + let first = PriceCoinValue(baseCoin: baseCoins.0.coin, quoteAppValue: AppValue(token: quoteCoins.0, value: prices.0)) + let second = PriceCoinValue(baseCoin: baseCoins.1.coin, quoteAppValue: AppValue(token: quoteCoins.1, value: prices.1)) return (first.formattedFull, second.formattedFull) } @@ -43,10 +43,10 @@ class SwapViewItemHelper { extension SwapViewItemHelper { struct PriceCoinValue { let baseCoin: Coin - let quoteCoinValue: CoinValue + let quoteAppValue: AppValue var formattedFull: String { - ValueFormatter.instance.formatFull(coinValue: quoteCoinValue).map { "1 " + [baseCoin.code, $0].joined(separator: " = ") } ?? "" + quoteAppValue.formattedFull().map { "1 " + [baseCoin.code, $0].joined(separator: " = ") } ?? "" } } } diff --git a/UnstoppableWallet/UnstoppableWallet/Modules/Swap/Adapters/Uniswap/UniswapService.swift b/UnstoppableWallet/UnstoppableWallet/Modules/Swap/Adapters/Uniswap/UniswapService.swift index 776232b90a..00c6815844 100644 --- a/UnstoppableWallet/UnstoppableWallet/Modules/Swap/Adapters/Uniswap/UniswapService.swift +++ b/UnstoppableWallet/UnstoppableWallet/Modules/Swap/Adapters/Uniswap/UniswapService.swift @@ -104,7 +104,7 @@ class UniswapService { syncState() } - private func checkAllowanceError(allowance: CoinValue) -> Error? { + private func checkAllowanceError(allowance: AppValue) -> Error? { guard let balanceIn, balanceIn >= tradeService.amountIn, tradeService.amountIn > allowance.value diff --git a/UnstoppableWallet/UnstoppableWallet/Modules/Swap/Adapters/Uniswap/UniswapViewModel.swift b/UnstoppableWallet/UnstoppableWallet/Modules/Swap/Adapters/Uniswap/UniswapViewModel.swift index cedbcc70d9..ca65857d2b 100644 --- a/UnstoppableWallet/UnstoppableWallet/Modules/Swap/Adapters/Uniswap/UniswapViewModel.swift +++ b/UnstoppableWallet/UnstoppableWallet/Modules/Swap/Adapters/Uniswap/UniswapViewModel.swift @@ -97,8 +97,8 @@ class UniswapViewModel { return } - let coinValue = CoinValue(kind: .token(token: token), value: balance) - availableBalanceRelay.accept(ValueFormatter.instance.formatFull(coinValue: coinValue)) + let appValue = AppValue(token: token, value: balance) + availableBalanceRelay.accept(appValue.formattedFull()) } private func sync(errors: [Error]? = nil) { @@ -177,7 +177,7 @@ class UniswapViewModel { for error in service.errors { if let allowance = (error as? SwapModule.SwapError)?.revokeAllowance { - revokeWarning = "swap.revoke_warning".localized(ValueFormatter.instance.formatFull(coinValue: allowance) ?? "n/a".localized) + revokeWarning = "swap.revoke_warning".localized(allowance.formattedFull() ?? "n/a".localized) } } if case .pending = pendingAllowanceService.state { diff --git a/UnstoppableWallet/UnstoppableWallet/Modules/Swap/Adapters/UniswapV3/UniswapV3Service.swift b/UnstoppableWallet/UnstoppableWallet/Modules/Swap/Adapters/UniswapV3/UniswapV3Service.swift index 524e38da23..6a30ef2c8b 100644 --- a/UnstoppableWallet/UnstoppableWallet/Modules/Swap/Adapters/UniswapV3/UniswapV3Service.swift +++ b/UnstoppableWallet/UnstoppableWallet/Modules/Swap/Adapters/UniswapV3/UniswapV3Service.swift @@ -104,7 +104,7 @@ class UniswapV3Service { syncState() } - private func checkAllowanceError(allowance: CoinValue) -> Error? { + private func checkAllowanceError(allowance: AppValue) -> Error? { guard let balanceIn, balanceIn >= tradeService.amountIn, tradeService.amountIn > allowance.value diff --git a/UnstoppableWallet/UnstoppableWallet/Modules/Swap/Adapters/UniswapV3/UniswapV3ViewModel.swift b/UnstoppableWallet/UnstoppableWallet/Modules/Swap/Adapters/UniswapV3/UniswapV3ViewModel.swift index ed204099ec..3931af49ec 100644 --- a/UnstoppableWallet/UnstoppableWallet/Modules/Swap/Adapters/UniswapV3/UniswapV3ViewModel.swift +++ b/UnstoppableWallet/UnstoppableWallet/Modules/Swap/Adapters/UniswapV3/UniswapV3ViewModel.swift @@ -98,8 +98,8 @@ class UniswapV3ViewModel { return } - let coinValue = CoinValue(kind: .token(token: token), value: balance) - availableBalanceRelay.accept(ValueFormatter.instance.formatFull(coinValue: coinValue)) + let appValue = AppValue(token: token, value: balance) + availableBalanceRelay.accept(appValue.formattedFull()) } private func sync(errors: [Error]? = nil) { @@ -181,7 +181,7 @@ class UniswapV3ViewModel { for error in service.errors { if let allowance = (error as? SwapModule.SwapError)?.revokeAllowance { - revokeWarning = "swap.revoke_warning".localized(ValueFormatter.instance.formatFull(coinValue: allowance) ?? "n/a".localized) + revokeWarning = "swap.revoke_warning".localized(allowance.formattedFull() ?? "n/a".localized) } } if case .pending = pendingAllowanceService.state { diff --git a/UnstoppableWallet/UnstoppableWallet/Modules/Swap/Allowance/SwapAllowanceService.swift b/UnstoppableWallet/UnstoppableWallet/Modules/Swap/Allowance/SwapAllowanceService.swift index 2f87cd3907..f2ff6fc1c7 100644 --- a/UnstoppableWallet/UnstoppableWallet/Modules/Swap/Allowance/SwapAllowanceService.swift +++ b/UnstoppableWallet/UnstoppableWallet/Modules/Swap/Allowance/SwapAllowanceService.swift @@ -52,7 +52,7 @@ class SwapAllowanceService { .allowanceSingle(spenderAddress: spenderAddress, defaultBlockParameter: .latest) .subscribeOn(ConcurrentDispatchQueueScheduler(qos: .userInitiated)) .subscribe(onSuccess: { [weak self] allowance in - self?.state = .ready(allowance: CoinValue(kind: .token(token: token), value: allowance)) + self?.state = .ready(allowance: AppValue(token: token, value: allowance)) }, onError: { [weak self] error in self?.state = .notReady(error: error) }) @@ -92,7 +92,7 @@ extension SwapAllowanceService { extension SwapAllowanceService { enum State: Equatable { case loading - case ready(allowance: CoinValue) + case ready(allowance: AppValue) case notReady(error: Error) static func == (lhs: State, rhs: State) -> Bool { diff --git a/UnstoppableWallet/UnstoppableWallet/Modules/Swap/Allowance/SwapAllowanceViewModel.swift b/UnstoppableWallet/UnstoppableWallet/Modules/Swap/Allowance/SwapAllowanceViewModel.swift index 121e2047b8..e2a86c7b7c 100644 --- a/UnstoppableWallet/UnstoppableWallet/Modules/Swap/Allowance/SwapAllowanceViewModel.swift +++ b/UnstoppableWallet/UnstoppableWallet/Modules/Swap/Allowance/SwapAllowanceViewModel.swift @@ -69,7 +69,7 @@ class SwapAllowanceViewModel { switch state { case let .ready(allowance): - return isInsufficientAllowance ? ValueFormatter.instance.formatFull(coinValue: allowance) : nil + return isInsufficientAllowance ? allowance.formattedFull() : nil default: return nil } } diff --git a/UnstoppableWallet/UnstoppableWallet/Modules/Swap/Allowance/SwapPendingAllowanceService.swift b/UnstoppableWallet/UnstoppableWallet/Modules/Swap/Allowance/SwapPendingAllowanceService.swift index 54971ba6c4..4fd08a685a 100644 --- a/UnstoppableWallet/UnstoppableWallet/Modules/Swap/Allowance/SwapPendingAllowanceService.swift +++ b/UnstoppableWallet/UnstoppableWallet/Modules/Swap/Allowance/SwapPendingAllowanceService.swift @@ -76,8 +76,8 @@ extension SwapPendingAllowanceService { } for transaction in adapter.pendingTransactions { - if let approve = transaction as? ApproveTransactionRecord, let value = approve.value.decimalValue { - pendingAllowance = value + if let approve = transaction as? ApproveTransactionRecord { + pendingAllowance = approve.value.value } } diff --git a/UnstoppableWallet/UnstoppableWallet/Modules/Swap/CoinCard/SwapCoinCardViewModel.swift b/UnstoppableWallet/UnstoppableWallet/Modules/Swap/CoinCard/SwapCoinCardViewModel.swift index 10709dde3f..6a40a57f5c 100644 --- a/UnstoppableWallet/UnstoppableWallet/Modules/Swap/CoinCard/SwapCoinCardViewModel.swift +++ b/UnstoppableWallet/UnstoppableWallet/Modules/Swap/CoinCard/SwapCoinCardViewModel.swift @@ -69,8 +69,8 @@ class SwapCoinCardViewModel { return } - let coinValue = CoinValue(kind: .token(token: token), value: balance) - balanceRelay.accept(ValueFormatter.instance.formatFull(coinValue: coinValue)) + let appValue = AppValue(token: token, value: balance) + balanceRelay.accept(appValue.formattedFull()) } private func sync(error: Error?) { diff --git a/UnstoppableWallet/UnstoppableWallet/Modules/Swap/SwapModule.swift b/UnstoppableWallet/UnstoppableWallet/Modules/Swap/SwapModule.swift index 6c0885c3a6..a3719f7104 100644 --- a/UnstoppableWallet/UnstoppableWallet/Modules/Swap/SwapModule.swift +++ b/UnstoppableWallet/UnstoppableWallet/Modules/Swap/SwapModule.swift @@ -123,7 +123,7 @@ extension SwapModule { case noBalanceIn case insufficientBalanceIn case insufficientAllowance - case needRevokeAllowance(allowance: CoinValue) + case needRevokeAllowance(allowance: AppValue) static func == (lhs: SwapError, rhs: SwapError) -> Bool { switch (lhs, rhs) { @@ -135,7 +135,7 @@ extension SwapModule { } } - var revokeAllowance: CoinValue? { + var revokeAllowance: AppValue? { switch self { case let .needRevokeAllowance(allowance): return allowance default: return nil diff --git a/UnstoppableWallet/UnstoppableWallet/Modules/TonConnect/TonConnect.swift b/UnstoppableWallet/UnstoppableWallet/Modules/TonConnect/TonConnect.swift index 1ec04ab6c0..cf93b9ff19 100644 --- a/UnstoppableWallet/UnstoppableWallet/Modules/TonConnect/TonConnect.swift +++ b/UnstoppableWallet/UnstoppableWallet/Modules/TonConnect/TonConnect.swift @@ -258,7 +258,7 @@ extension TonConnect.Network: CellCodable { } static func loadFrom(slice: Slice) throws -> TonConnect.Network { - return try slice.tryLoad { s in + try slice.tryLoad { s in let rawValue = try Int16(s.loadInt(bits: .rawValueLength)) guard let network = TonConnect.Network(rawValue: rawValue) else { throw TonSwift.TonError.custom("Invalid network code") diff --git a/UnstoppableWallet/UnstoppableWallet/Modules/TonConnect/TonConnectConnectViewModel.swift b/UnstoppableWallet/UnstoppableWallet/Modules/TonConnect/TonConnectConnectViewModel.swift index 60da447207..ff0c0b9487 100644 --- a/UnstoppableWallet/UnstoppableWallet/Modules/TonConnect/TonConnectConnectViewModel.swift +++ b/UnstoppableWallet/UnstoppableWallet/Modules/TonConnect/TonConnectConnectViewModel.swift @@ -17,7 +17,7 @@ class TonConnectConnectViewModel: ObservableObject { parameters = config.parameters manifest = config.manifest - eligibleAccounts = accountManager.accounts.filter { $0.type.supportsTonConnect }.sorted { $0.name < $1.name } + eligibleAccounts = accountManager.accounts.filter(\.type.supportsTonConnect).sorted { $0.name < $1.name } if let activeAccount = accountManager.activeAccount, eligibleAccounts.contains(activeAccount) { account = activeAccount diff --git a/UnstoppableWallet/UnstoppableWallet/Modules/TonConnect/TonConnectManager.swift b/UnstoppableWallet/UnstoppableWallet/Modules/TonConnect/TonConnectManager.swift index 6e004c7fc9..4b0115d3fc 100644 --- a/UnstoppableWallet/UnstoppableWallet/Modules/TonConnect/TonConnectManager.swift +++ b/UnstoppableWallet/UnstoppableWallet/Modules/TonConnect/TonConnectManager.swift @@ -78,7 +78,7 @@ class TonConnectManager { // print("Apps: \(tonConnectApps.map { $0.manifest.name })") let task = Task { [storage, tonConnectApps] in - let ids = tonConnectApps.map { $0.keyPair.publicKey.hexString }.joined(separator: ",") + let ids = tonConnectApps.map(\.keyPair.publicKey.hexString).joined(separator: ",") // print("IDS: \(ids)") diff --git a/UnstoppableWallet/UnstoppableWallet/Modules/TonConnect/TonConnectSendHandler.swift b/UnstoppableWallet/UnstoppableWallet/Modules/TonConnect/TonConnectSendHandler.swift index 9ce5a6c6b5..3346a125dc 100644 --- a/UnstoppableWallet/UnstoppableWallet/Modules/TonConnect/TonConnectSendHandler.swift +++ b/UnstoppableWallet/UnstoppableWallet/Modules/TonConnect/TonConnectSendHandler.swift @@ -107,8 +107,8 @@ extension TonConnectSendHandler { if let tonError = transactionError as? TonConnectSendHandler.TransactionError { switch tonError { case let .insufficientTonBalance(balance): - let coinValue = CoinValue(kind: .token(token: feeToken), value: balance) - let balanceString = ValueFormatter.instance.formatShort(coinValue: coinValue) + let appValue = AppValue(token: feeToken, value: balance) + let balanceString = appValue.formattedShort() title = "fee_settings.errors.insufficient_balance".localized text = "fee_settings.errors.insufficient_balance.info".localized(balanceString ?? "") @@ -140,13 +140,13 @@ extension TonConnectSendHandler { switch action.type { case let .send(value, to, _, comment): - if let token = value.token, let decimalValue = value.decimalValue { + if let token = value.token { fields = [ .amount( title: "send.confirmation.you_send".localized, token: token, - coinValueType: .regular(coinValue: CoinValue(kind: .token(token: token), value: decimalValue)), - currencyValue: rates[token.coin.uid].map { CurrencyValue(currency: currency, value: $0 * decimalValue) }, + appValueType: .regular(appValue: AppValue(token: token, value: value.value)), + currencyValue: rates[token.coin.uid].map { CurrencyValue(currency: currency, value: $0 * value.value) }, type: .outgoing ), .address( @@ -164,13 +164,13 @@ extension TonConnectSendHandler { } case let .receive(value, from, comment): - if let token = value.token, let decimalValue = value.decimalValue { + if let token = value.token { fields = [ .amount( title: "send.confirmation.you_receive".localized, token: token, - coinValueType: .regular(coinValue: CoinValue(kind: .token(token: token), value: decimalValue)), - currencyValue: rates[token.coin.uid].map { CurrencyValue(currency: currency, value: $0 * decimalValue) }, + appValueType: .regular(appValue: AppValue(token: token, value: value.value)), + currencyValue: rates[token.coin.uid].map { CurrencyValue(currency: currency, value: $0 * value.value) }, type: .incoming ), .address( @@ -194,28 +194,28 @@ extension TonConnectSendHandler { fields = [.levelValue(title: "send.confirmation.action".localized, value: "Mint", level: .regular)] case let .swap(_, _, valueIn, valueOut): - if let tokenIn = valueIn.token, let decimalValueIn = valueIn.decimalValue, let tokenOut = valueOut.token, let decimalValueOut = valueOut.decimalValue { + if let tokenIn = valueIn.token, let tokenOut = valueOut.token { fields = [ .amount( title: "swap.you_pay".localized, token: tokenIn, - coinValueType: .regular(coinValue: CoinValue(kind: .token(token: tokenIn), value: decimalValueIn)), - currencyValue: rates[tokenIn.coin.uid].map { CurrencyValue(currency: currency, value: decimalValueIn * $0) }, + appValueType: .regular(appValue: AppValue(token: tokenIn, value: valueIn.value)), + currencyValue: rates[tokenIn.coin.uid].map { CurrencyValue(currency: currency, value: valueIn.value * $0) }, type: .neutral ), .amount( title: "swap.you_get".localized, token: tokenOut, - coinValueType: .regular(coinValue: CoinValue(kind: .token(token: tokenOut), value: decimalValueOut)), - currencyValue: rates[tokenOut.coin.uid].map { CurrencyValue(currency: currency, value: decimalValueOut * $0) }, + appValueType: .regular(appValue: AppValue(token: tokenOut, value: valueOut.value)), + currencyValue: rates[tokenOut.coin.uid].map { CurrencyValue(currency: currency, value: valueOut.value * $0) }, type: .incoming ), .price( title: "swap.price".localized, tokenA: tokenIn, tokenB: tokenOut, - amountA: decimalValueIn, - amountB: decimalValueOut + amountA: valueIn.value, + amountB: valueOut.value ), ] } else { @@ -251,14 +251,14 @@ extension TonConnectSendHandler { var viewItems = [SendField]() if let fee { - let coinValue = CoinValue(kind: .token(token: feeToken), value: fee) + let appValue = AppValue(token: feeToken, value: fee) let currencyValue = feeTokenRate.map { CurrencyValue(currency: currency, value: fee * $0) } viewItems.append( .value( title: "fee_settings.network_fee".localized, description: .init(title: "fee_settings.network_fee".localized, description: "fee_settings.network_fee.info".localized), - coinValue: coinValue, + appValue: appValue, currencyValue: currencyValue, formatFull: true ) diff --git a/UnstoppableWallet/UnstoppableWallet/Modules/TonConnect/TonConnectSessionCrypto.swift b/UnstoppableWallet/UnstoppableWallet/Modules/TonConnect/TonConnectSessionCrypto.swift index 553509d0ee..b56c3edd6e 100644 --- a/UnstoppableWallet/UnstoppableWallet/Modules/TonConnect/TonConnectSessionCrypto.swift +++ b/UnstoppableWallet/UnstoppableWallet/Modules/TonConnect/TonConnectSessionCrypto.swift @@ -49,7 +49,7 @@ public struct TonConnectSessionCrypto { private extension TonConnectSessionCrypto { func createNonce() throws -> Data { - return try TweetNacl.NaclUtil.secureRandomData(count: .nonceLength) + try TweetNacl.NaclUtil.secureRandomData(count: .nonceLength) } } diff --git a/UnstoppableWallet/UnstoppableWallet/Modules/TransactionInfo/TransactionInfoViewItemFactory.swift b/UnstoppableWallet/UnstoppableWallet/Modules/TransactionInfo/TransactionInfoViewItemFactory.swift index b7a35f9979..17793eb3b7 100644 --- a/UnstoppableWallet/UnstoppableWallet/Modules/TransactionInfo/TransactionInfoViewItemFactory.swift +++ b/UnstoppableWallet/UnstoppableWallet/Modules/TransactionInfo/TransactionInfoViewItemFactory.swift @@ -17,21 +17,21 @@ class TransactionInfoViewItemFactory { self.contactLabelService = contactLabelService } - private func amount(source: TransactionSource, title: String, subtitle: String?, transactionValue: TransactionValue, rate: CurrencyValue?, type: AmountType, balanceHidden: Bool) -> TransactionInfoModule.ViewItem { - let iconUrl = transactionValue.coin?.imageUrl - let iconAlternativeUrl = transactionValue.coin?.image - let iconPlaceholderImageName = source.blockchainType.placeholderImageName(tokenProtocol: transactionValue.tokenProtocol) + private func amount(source: TransactionSource, title: String, subtitle: String?, appValue: AppValue, rate: CurrencyValue?, type: AmountType, balanceHidden: Bool) -> TransactionInfoModule.ViewItem { + let iconUrl = appValue.coin?.imageUrl + let iconAlternativeUrl = appValue.coin?.image + let iconPlaceholderImageName = source.blockchainType.placeholderImageName(tokenProtocol: appValue.tokenProtocol) - let coin = transactionValue.token.flatMap { $0.isCustom ? nil : $0.coin } + let coin = appValue.token.flatMap { $0.isCustom ? nil : $0.coin } - if transactionValue.isMaxValue { + if appValue.isMaxValue { return .amount( title: title, subtitle: subtitle, iconUrl: iconUrl, iconAlternativeUrl: iconAlternativeUrl, iconPlaceholderImageName: iconPlaceholderImageName, - coinAmount: balanceHidden ? BalanceHiddenManager.placeholder : "∞ \(transactionValue.coinCode)", + coinAmount: balanceHidden ? BalanceHiddenManager.placeholder : "∞ \(appValue.code)", currencyAmount: balanceHidden ? BalanceHiddenManager.placeholder : "transactions.value.unlimited".localized, type: type, coin: coin @@ -39,8 +39,8 @@ class TransactionInfoViewItemFactory { } else { var currencyValue: CurrencyValue? - if let rate, let value = transactionValue.decimalValue { - currencyValue = CurrencyValue(currency: rate.currency, value: rate.value * value) + if let rate { + currencyValue = CurrencyValue(currency: rate.currency, value: rate.value * appValue.value) } return .amount( @@ -49,7 +49,7 @@ class TransactionInfoViewItemFactory { iconUrl: iconUrl, iconAlternativeUrl: iconAlternativeUrl, iconPlaceholderImageName: iconPlaceholderImageName, - coinAmount: balanceHidden ? BalanceHiddenManager.placeholder : transactionValue.formattedFull(signType: type.signType) ?? "n/a".localized, + coinAmount: balanceHidden ? BalanceHiddenManager.placeholder : appValue.formattedFull(signType: type.signType) ?? "n/a".localized, currencyAmount: balanceHidden ? BalanceHiddenManager.placeholder : currencyValue.flatMap { ValueFormatter.instance.formatFull(currencyValue: $0) }, type: type, coin: coin @@ -57,26 +57,26 @@ class TransactionInfoViewItemFactory { } } - private func nftAmount(source _: TransactionSource, transactionValue: TransactionValue, type: AmountType, metadata: NftAssetBriefMetadata?, balanceHidden: Bool) -> TransactionInfoModule.ViewItem { + private func nftAmount(source _: TransactionSource, appValue: AppValue, type: AmountType, metadata: NftAssetBriefMetadata?, balanceHidden: Bool) -> TransactionInfoModule.ViewItem { .nftAmount( iconUrl: metadata?.previewImageUrl, iconPlaceholderImageName: "placeholder_nft_32", - nftAmount: balanceHidden ? BalanceHiddenManager.placeholder : transactionValue.formattedFull(signType: type.signType) ?? "n/a".localized, + nftAmount: balanceHidden ? BalanceHiddenManager.placeholder : appValue.formattedFull(signType: type.signType) ?? "n/a".localized, type: type, providerCollectionUid: metadata?.providerCollectionUid, nftUid: metadata?.nftUid ) } - private func feeString(transactionValue: TransactionValue, rate: CurrencyValue?) -> String { + private func feeString(appValue: AppValue, rate: CurrencyValue?) -> String { var parts = [String]() - if let formattedCoinValue = transactionValue.formattedFull() { + if let formattedCoinValue = appValue.formattedFull() { parts.append(formattedCoinValue) } - if let rate, case let .coinValue(_, value) = transactionValue { - if let formattedCurrencyValue = ValueFormatter.instance.formatFull(currency: rate.currency, value: rate.value * value) { + if let rate { + if let formattedCurrencyValue = ValueFormatter.instance.formatFull(currency: rate.currency, value: rate.value * appValue.value) { parts.append(formattedCurrencyValue) } } @@ -84,20 +84,18 @@ class TransactionInfoViewItemFactory { return parts.joined(separator: " | ") } - private func priceString(valueIn: TransactionValue, valueOut: TransactionValue, coinPriceIn: CurrencyValue?) -> String? { - guard case let .coinValue(valueInToken, valueInDecimal) = valueIn, - case let .coinValue(valueOutToken, valueOutDecimal) = valueOut - else { + private func priceString(valueIn: AppValue, valueOut: AppValue, coinPriceIn: CurrencyValue?) -> String? { + guard let coinIn = valueIn.coin, let coinOut = valueOut.coin else { return nil } - var priceDecimal = valueInDecimal.magnitude / valueOutDecimal.magnitude + var priceDecimal = valueIn.value.magnitude / valueOut.value.magnitude if priceReversed { priceDecimal = 1 / priceDecimal } - let symbolOut = priceReversed ? valueInToken.coin.code : valueOutToken.coin.code - let symbolIn = priceReversed ? valueOutToken.coin.code : valueInToken.coin.code + let symbolOut = priceReversed ? coinIn.code : coinOut.code + let symbolIn = priceReversed ? coinOut.code : coinIn.code let price = ValueFormatter.instance.formatFull(value: priceDecimal, decimalCount: priceDecimal.decimalCount, symbol: symbolIn) ?? "" let rate = coinPriceIn.map { CurrencyValue(currency: $0.currency, value: abs((priceReversed ? 1 : priceDecimal) * $0.value)) } let rateFormatted = rate.flatMap { ValueFormatter.instance.formatFull(currencyValue: $0).map { " (\($0))" } } ?? "" @@ -131,25 +129,25 @@ class TransactionInfoViewItemFactory { } } - private func fullBadge(transactionValue: TransactionValue) -> String? { - switch transactionValue { - case let .coinValue(token, _): + private func fullBadge(appValue: AppValue) -> String? { + switch appValue.kind { + case let .token(token): return token.fullBadge - case let .tokenValue(tokenName, _, _, _): + case let .eip20Token(tokenName, _, _): return tokenName default: return nil } } - private func sendSection(source: TransactionSource, transactionValue: TransactionValue, to: String?, rates: [Coin: CurrencyValue], nftMetadata: [NftUid: NftAssetBriefMetadata] = [:], sentToSelf: Bool = false, balanceHidden: Bool) -> [TransactionInfoModule.ViewItem] { + private func sendSection(source: TransactionSource, appValue: AppValue, to: String?, rates: [Coin: CurrencyValue], nftMetadata: [NftUid: NftAssetBriefMetadata] = [:], sentToSelf: Bool = false, balanceHidden: Bool) -> [TransactionInfoModule.ViewItem] { var viewItems = [TransactionInfoModule.ViewItem]() let burn = to == zeroAddress var rateViewItem: TransactionInfoModule.ViewItem? - switch transactionValue { - case let .nftValue(nftUid, _, tokenName, _): + switch appValue.kind { + case let .nft(nftUid, tokenName, _): viewItems.append( .actionTitle( iconName: burn ? "flame_24" : "arrow_medium_2_up_right_24", @@ -162,28 +160,28 @@ class TransactionInfoViewItemFactory { viewItems.append( nftAmount( source: source, - transactionValue: transactionValue, - type: type(value: transactionValue, condition: sentToSelf, .neutral, .outgoing), + appValue: appValue, + type: type(appValue: appValue, condition: sentToSelf, .neutral, .outgoing), metadata: nftMetadata[nftUid], balanceHidden: balanceHidden ) ) default: - let rate = transactionValue.coin.flatMap { rates[$0] } + let rate = appValue.coin.flatMap { rates[$0] } viewItems.append( amount( source: source, title: burn ? "transactions.burn".localized : "transactions.send".localized, - subtitle: fullBadge(transactionValue: transactionValue), - transactionValue: transactionValue, + subtitle: fullBadge(appValue: appValue), + appValue: appValue, rate: rate, - type: type(value: transactionValue, condition: sentToSelf, .neutral, .outgoing), + type: type(appValue: appValue, condition: sentToSelf, .neutral, .outgoing), balanceHidden: balanceHidden ) ) - rateViewItem = .rate(value: rateString(currencyValue: rate, coinCode: transactionValue.coin?.code)) + rateViewItem = .rate(value: rateString(currencyValue: rate, coinCode: appValue.coin?.code)) } if !burn, let to { @@ -204,22 +202,22 @@ class TransactionInfoViewItemFactory { return viewItems } - private func type(value: TransactionValue, condition: Bool = true, _ trueType: AmountType, _ falseType: AmountType? = nil) -> AmountType { - guard !value.zeroValue else { + private func type(appValue: AppValue, condition: Bool = true, _ trueType: AmountType, _ falseType: AmountType? = nil) -> AmountType { + guard !appValue.zeroValue else { return .neutral } return condition ? trueType : (falseType ?? trueType) } - private func receiveSection(source: TransactionSource, transactionValue: TransactionValue, from: String?, rates: [Coin: CurrencyValue], nftMetadata: [NftUid: NftAssetBriefMetadata] = [:], memo: String? = nil, status: TransactionStatus? = nil, balanceHidden: Bool) -> [TransactionInfoModule.ViewItem] { + private func receiveSection(source: TransactionSource, appValue: AppValue, from: String?, rates: [Coin: CurrencyValue], nftMetadata: [NftUid: NftAssetBriefMetadata] = [:], memo: String? = nil, status: TransactionStatus? = nil, balanceHidden: Bool) -> [TransactionInfoModule.ViewItem] { var viewItems = [TransactionInfoModule.ViewItem]() let mint = from == zeroAddress var rateViewItem: TransactionInfoModule.ViewItem? - switch transactionValue { - case let .nftValue(nftUid, _, tokenName, _): + switch appValue.kind { + case let .nft(nftUid, tokenName, _): viewItems.append( .actionTitle( iconName: "arrow_medium_2_down_left_24", @@ -231,28 +229,28 @@ class TransactionInfoViewItemFactory { viewItems.append( nftAmount( source: source, - transactionValue: transactionValue, - type: type(value: transactionValue, .incoming), + appValue: appValue, + type: type(appValue: appValue, .incoming), metadata: nftMetadata[nftUid], balanceHidden: balanceHidden ) ) default: - let rate = transactionValue.coin.flatMap { rates[$0] } + let rate = appValue.coin.flatMap { rates[$0] } viewItems.append( amount( source: source, title: mint ? "transactions.mint".localized : "transactions.receive".localized, - subtitle: fullBadge(transactionValue: transactionValue), - transactionValue: transactionValue, + subtitle: fullBadge(appValue: appValue), + appValue: appValue, rate: rate, - type: type(value: transactionValue, .incoming), + type: type(appValue: appValue, .incoming), balanceHidden: balanceHidden ) ) - rateViewItem = .rate(value: rateString(currencyValue: rate, coinCode: transactionValue.coin?.code)) + rateViewItem = .rate(value: rateString(currencyValue: rate, coinCode: appValue.coin?.code)) } if !mint, let from { @@ -301,7 +299,7 @@ class TransactionInfoViewItemFactory { } func items(item: TransactionInfoService.Item, balanceHidden: Bool) -> [TransactionInfoModule.SectionViewItem] { - func _rate(_ value: TransactionValue) -> CurrencyValue? { + func _rate(_ value: AppValue) -> CurrencyValue? { value.coin.flatMap { item.rates[$0] } } @@ -322,23 +320,23 @@ class TransactionInfoViewItemFactory { ])) case let record as EvmOutgoingTransactionRecord: - sections.append(.init(sendSection(source: record.source, transactionValue: record.value, to: record.to, rates: item.rates, nftMetadata: item.nftMetadata, sentToSelf: record.sentToSelf, balanceHidden: balanceHidden))) + sections.append(.init(sendSection(source: record.source, appValue: record.value, to: record.to, rates: item.rates, nftMetadata: item.nftMetadata, sentToSelf: record.sentToSelf, balanceHidden: balanceHidden))) if record.sentToSelf { sections.append(.init([.sentToSelf])) } case let record as EvmIncomingTransactionRecord: - sections.append(.init(receiveSection(source: record.source, transactionValue: record.value, from: record.from, rates: item.rates, balanceHidden: balanceHidden))) + sections.append(.init(receiveSection(source: record.source, appValue: record.value, from: record.from, rates: item.rates, balanceHidden: balanceHidden))) case let record as ApproveTransactionRecord: - let transactionValue = record.value - let rate = _rate(transactionValue) + let appValue = record.value + let rate = _rate(appValue) let contactData = contactLabelService.contactData(for: record.spender) let valueTitle = contactData.name == nil ? evmLabelManager.addressLabel(address: record.spender) : nil var viewItems: [TransactionInfoModule.ViewItem] = [ - amount(source: record.source, title: "transactions.approve".localized, subtitle: fullBadge(transactionValue: transactionValue), transactionValue: transactionValue, rate: rate, type: .neutral, balanceHidden: balanceHidden), + amount(source: record.source, title: "transactions.approve".localized, subtitle: fullBadge(appValue: appValue), appValue: appValue, rate: rate, type: .neutral, balanceHidden: balanceHidden), .spender(value: record.spender, valueTitle: valueTitle, contactAddress: contactData.contactAddress), ] @@ -346,17 +344,17 @@ class TransactionInfoViewItemFactory { viewItems.append(.contactName(name: name)) } - viewItems.append(.rate(value: rateString(currencyValue: rate, coinCode: transactionValue.coin?.code))) + viewItems.append(.rate(value: rateString(currencyValue: rate, coinCode: appValue.coin?.code))) sections.append(.init(viewItems)) case let record as SwapTransactionRecord: var amountViewItems: [TransactionInfoModule.ViewItem] = [ - amount(source: record.source, title: youPayString(status: status), subtitle: fullBadge(transactionValue: record.valueIn), transactionValue: record.valueIn, rate: _rate(record.valueIn), type: type(value: record.valueIn, .outgoing), balanceHidden: balanceHidden), + amount(source: record.source, title: youPayString(status: status), subtitle: fullBadge(appValue: record.valueIn), appValue: record.valueIn, rate: _rate(record.valueIn), type: type(appValue: record.valueIn, .outgoing), balanceHidden: balanceHidden), ] if let valueOut = record.valueOut { - amountViewItems.append(amount(source: record.source, title: youGetString(status: status), subtitle: fullBadge(transactionValue: valueOut), transactionValue: valueOut, rate: _rate(valueOut), type: type(value: valueOut, condition: record.recipient == nil, .incoming, .outgoing), balanceHidden: balanceHidden)) + amountViewItems.append(amount(source: record.source, title: youGetString(status: status), subtitle: fullBadge(appValue: valueOut), appValue: valueOut, rate: _rate(valueOut), type: type(appValue: valueOut, condition: record.recipient == nil, .incoming, .outgoing), balanceHidden: balanceHidden)) } sections.append(.init(amountViewItems)) @@ -396,13 +394,13 @@ class TransactionInfoViewItemFactory { if let valueIn = record.valueIn { amountViewItems.append( - amount(source: record.source, title: youPayString(status: status), subtitle: fullBadge(transactionValue: valueIn), transactionValue: valueIn, rate: _rate(valueIn), type: type(value: valueIn, .outgoing), balanceHidden: balanceHidden) + amount(source: record.source, title: youPayString(status: status), subtitle: fullBadge(appValue: valueIn), appValue: valueIn, rate: _rate(valueIn), type: type(appValue: valueIn, .outgoing), balanceHidden: balanceHidden) ) } if let valueOut = record.valueOut { amountViewItems.append( - amount(source: record.source, title: youGetString(status: status), subtitle: fullBadge(transactionValue: valueOut), transactionValue: valueOut, rate: _rate(valueOut), type: type(value: valueOut, .incoming), balanceHidden: balanceHidden) + amount(source: record.source, title: youGetString(status: status), subtitle: fullBadge(appValue: valueOut), appValue: valueOut, rate: _rate(valueOut), type: type(appValue: valueOut, .incoming), balanceHidden: balanceHidden) ) } @@ -432,40 +430,40 @@ class TransactionInfoViewItemFactory { ])) for event in record.outgoingEvents { - sections.append(.init(sendSection(source: record.source, transactionValue: event.value, to: event.address, rates: item.rates, nftMetadata: item.nftMetadata, balanceHidden: balanceHidden))) + sections.append(.init(sendSection(source: record.source, appValue: event.value, to: event.address, rates: item.rates, nftMetadata: item.nftMetadata, balanceHidden: balanceHidden))) } for event in record.incomingEvents { - sections.append(.init(receiveSection(source: record.source, transactionValue: event.value, from: event.address, rates: item.rates, nftMetadata: item.nftMetadata, balanceHidden: balanceHidden))) + sections.append(.init(receiveSection(source: record.source, appValue: event.value, from: event.address, rates: item.rates, nftMetadata: item.nftMetadata, balanceHidden: balanceHidden))) } case let record as ExternalContractCallTransactionRecord: for event in record.outgoingEvents { - sections.append(.init(sendSection(source: record.source, transactionValue: event.value, to: event.address, rates: item.rates, nftMetadata: item.nftMetadata, balanceHidden: balanceHidden))) + sections.append(.init(sendSection(source: record.source, appValue: event.value, to: event.address, rates: item.rates, nftMetadata: item.nftMetadata, balanceHidden: balanceHidden))) } for event in record.incomingEvents { - sections.append(.init(receiveSection(source: record.source, transactionValue: event.value, from: event.address, rates: item.rates, nftMetadata: item.nftMetadata, balanceHidden: balanceHidden))) + sections.append(.init(receiveSection(source: record.source, appValue: event.value, from: event.address, rates: item.rates, nftMetadata: item.nftMetadata, balanceHidden: balanceHidden))) } case let record as TronIncomingTransactionRecord: - sections.append(.init(receiveSection(source: record.source, transactionValue: record.value, from: record.from, rates: item.rates, balanceHidden: balanceHidden))) + sections.append(.init(receiveSection(source: record.source, appValue: record.value, from: record.from, rates: item.rates, balanceHidden: balanceHidden))) case let record as TronOutgoingTransactionRecord: - sections.append(.init(sendSection(source: record.source, transactionValue: record.value, to: record.to, rates: item.rates, nftMetadata: item.nftMetadata, sentToSelf: record.sentToSelf, balanceHidden: balanceHidden))) + sections.append(.init(sendSection(source: record.source, appValue: record.value, to: record.to, rates: item.rates, nftMetadata: item.nftMetadata, sentToSelf: record.sentToSelf, balanceHidden: balanceHidden))) if record.sentToSelf { sections.append(.init([.sentToSelf])) } case let record as TronApproveTransactionRecord: - let transactionValue = record.value - let rate = _rate(transactionValue) + let appValue = record.value + let rate = _rate(appValue) let contactData = contactLabelService.contactData(for: record.spender) let valueTitle = contactData.name == nil ? evmLabelManager.addressLabel(address: record.spender) : nil var viewItems: [TransactionInfoModule.ViewItem] = [ - amount(source: record.source, title: "transactions.approve".localized, subtitle: fullBadge(transactionValue: transactionValue), transactionValue: transactionValue, rate: rate, type: .neutral, balanceHidden: balanceHidden), + amount(source: record.source, title: "transactions.approve".localized, subtitle: fullBadge(appValue: appValue), appValue: appValue, rate: rate, type: .neutral, balanceHidden: balanceHidden), .spender(value: record.spender, valueTitle: valueTitle, contactAddress: contactData.contactAddress), ] @@ -473,7 +471,7 @@ class TransactionInfoViewItemFactory { viewItems.append(.contactName(name: name)) } - viewItems.append(.rate(value: rateString(currencyValue: rate, coinCode: transactionValue.coin?.code))) + viewItems.append(.rate(value: rateString(currencyValue: rate, coinCode: appValue.coin?.code))) sections.append(.init(viewItems)) @@ -483,20 +481,20 @@ class TransactionInfoViewItemFactory { ])) for event in record.outgoingEvents { - sections.append(.init(sendSection(source: record.source, transactionValue: event.value, to: event.address, rates: item.rates, nftMetadata: item.nftMetadata, balanceHidden: balanceHidden))) + sections.append(.init(sendSection(source: record.source, appValue: event.value, to: event.address, rates: item.rates, nftMetadata: item.nftMetadata, balanceHidden: balanceHidden))) } for event in record.incomingEvents { - sections.append(.init(receiveSection(source: record.source, transactionValue: event.value, from: event.address, rates: item.rates, nftMetadata: item.nftMetadata, balanceHidden: balanceHidden))) + sections.append(.init(receiveSection(source: record.source, appValue: event.value, from: event.address, rates: item.rates, nftMetadata: item.nftMetadata, balanceHidden: balanceHidden))) } case let record as TronExternalContractCallTransactionRecord: for event in record.outgoingEvents { - sections.append(.init(sendSection(source: record.source, transactionValue: event.value, to: event.address, rates: item.rates, nftMetadata: item.nftMetadata, balanceHidden: balanceHidden))) + sections.append(.init(sendSection(source: record.source, appValue: event.value, to: event.address, rates: item.rates, nftMetadata: item.nftMetadata, balanceHidden: balanceHidden))) } for event in record.incomingEvents { - sections.append(.init(receiveSection(source: record.source, transactionValue: event.value, from: event.address, rates: item.rates, nftMetadata: item.nftMetadata, balanceHidden: balanceHidden))) + sections.append(.init(receiveSection(source: record.source, appValue: event.value, from: event.address, rates: item.rates, nftMetadata: item.nftMetadata, balanceHidden: balanceHidden))) } case let record as TronTransactionRecord: @@ -505,7 +503,7 @@ class TransactionInfoViewItemFactory { ])) case let record as BitcoinIncomingTransactionRecord: - sections.append(.init(receiveSection(source: record.source, transactionValue: record.value, from: record.from, rates: item.rates, balanceHidden: balanceHidden))) + sections.append(.init(receiveSection(source: record.source, appValue: record.value, from: record.from, rates: item.rates, balanceHidden: balanceHidden))) let additionalViewItems = bitcoinViewItems(record: record, lastBlockInfo: item.lastBlockInfo) if !additionalViewItems.isEmpty { @@ -513,7 +511,7 @@ class TransactionInfoViewItemFactory { } case let record as BitcoinOutgoingTransactionRecord: - sections.append(.init(sendSection(source: record.source, transactionValue: record.value, to: record.to, rates: item.rates, sentToSelf: record.sentToSelf, balanceHidden: balanceHidden))) + sections.append(.init(sendSection(source: record.source, appValue: record.value, to: record.to, rates: item.rates, sentToSelf: record.sentToSelf, balanceHidden: balanceHidden))) var additionalViewItems = bitcoinViewItems(record: record, lastBlockInfo: item.lastBlockInfo) @@ -526,7 +524,7 @@ class TransactionInfoViewItemFactory { } if let fee = record.fee { - feeViewItem = .fee(title: "tx_info.fee".localized, value: feeString(transactionValue: fee, rate: _rate(fee))) + feeViewItem = .fee(title: "tx_info.fee".localized, value: feeString(appValue: fee, rate: _rate(fee))) } if actionEnabled, record.replaceable { @@ -537,14 +535,14 @@ class TransactionInfoViewItemFactory { } case let record as BinanceChainIncomingTransactionRecord: - sections.append(.init(receiveSection(source: record.source, transactionValue: record.value, from: record.from, rates: item.rates, balanceHidden: balanceHidden))) + sections.append(.init(receiveSection(source: record.source, appValue: record.value, from: record.from, rates: item.rates, balanceHidden: balanceHidden))) if let memo = record.memo, !memo.isEmpty { sections.append(.init([.memo(text: memo)])) } case let record as BinanceChainOutgoingTransactionRecord: - sections.append(.init(sendSection(source: record.source, transactionValue: record.value, to: record.to, rates: item.rates, sentToSelf: record.sentToSelf, balanceHidden: balanceHidden))) + sections.append(.init(sendSection(source: record.source, appValue: record.value, to: record.to, rates: item.rates, sentToSelf: record.sentToSelf, balanceHidden: balanceHidden))) var additionalViewItems = [TransactionInfoModule.ViewItem]() @@ -560,7 +558,7 @@ class TransactionInfoViewItemFactory { sections.append(.init(additionalViewItems)) } - feeViewItem = .fee(title: "tx_info.fee".localized, value: feeString(transactionValue: record.fee, rate: _rate(record.fee))) + feeViewItem = .fee(title: "tx_info.fee".localized, value: feeString(appValue: record.fee, rate: _rate(record.fee))) case let record as TonTransactionRecord: for action in record.actions { @@ -568,7 +566,7 @@ class TransactionInfoViewItemFactory { switch action.type { case let .send(value, to, sentToSelf, comment): - viewItems = sendSection(source: record.source, transactionValue: value, to: to, rates: item.rates, sentToSelf: sentToSelf, balanceHidden: balanceHidden) + viewItems = sendSection(source: record.source, appValue: value, to: to, rates: item.rates, sentToSelf: sentToSelf, balanceHidden: balanceHidden) if let comment { viewItems.append(.memo(text: comment)) @@ -579,22 +577,22 @@ class TransactionInfoViewItemFactory { } case let .receive(value, from, comment): - viewItems = receiveSection(source: record.source, transactionValue: value, from: from, rates: item.rates, balanceHidden: balanceHidden) + viewItems = receiveSection(source: record.source, appValue: value, from: from, rates: item.rates, balanceHidden: balanceHidden) if let comment { viewItems.append(.memo(text: comment)) } case let .burn(value): - viewItems = sendSection(source: record.source, transactionValue: value, to: zeroAddress, rates: item.rates, balanceHidden: balanceHidden) + viewItems = sendSection(source: record.source, appValue: value, to: zeroAddress, rates: item.rates, balanceHidden: balanceHidden) case let .mint(value): - viewItems = receiveSection(source: record.source, transactionValue: value, from: zeroAddress, rates: item.rates, balanceHidden: balanceHidden) + viewItems = receiveSection(source: record.source, appValue: value, from: zeroAddress, rates: item.rates, balanceHidden: balanceHidden) case let .swap(routerName, routerAddress, valueIn, valueOut): viewItems = [ - amount(source: record.source, title: youPayString(status: status), subtitle: fullBadge(transactionValue: valueIn), transactionValue: valueIn, rate: _rate(valueIn), type: type(value: valueIn, .outgoing), balanceHidden: balanceHidden), - amount(source: record.source, title: youGetString(status: status), subtitle: fullBadge(transactionValue: valueOut), transactionValue: valueOut, rate: _rate(valueOut), type: type(value: valueOut, .incoming), balanceHidden: balanceHidden), + amount(source: record.source, title: youPayString(status: status), subtitle: fullBadge(appValue: valueIn), appValue: valueIn, rate: _rate(valueIn), type: type(appValue: valueIn, .outgoing), balanceHidden: balanceHidden), + amount(source: record.source, title: youGetString(status: status), subtitle: fullBadge(appValue: valueOut), appValue: valueOut, rate: _rate(valueOut), type: type(appValue: valueOut, .incoming), balanceHidden: balanceHidden), .service(value: routerName ?? routerAddress.shortened), ] @@ -610,10 +608,10 @@ class TransactionInfoViewItemFactory { case let .contractCall(address, value, operation): viewItems = [ .actionTitle(iconName: record.source.blockchainType.iconPlain32, iconDimmed: false, title: "transactions.contract_call".localized, subTitle: operation), - .to(value: address, valueTitle: nil, contactAddress: nil) + .to(value: address, valueTitle: nil, contactAddress: nil), ] - viewItems.append(contentsOf: sendSection(source: record.source, transactionValue: value, to: nil, rates: item.rates, balanceHidden: balanceHidden)) + viewItems.append(contentsOf: sendSection(source: record.source, appValue: value, to: nil, rates: item.rates, balanceHidden: balanceHidden)) case let .unsupported(type): viewItems = [.fee(title: "Action", value: type)] @@ -628,7 +626,7 @@ class TransactionInfoViewItemFactory { sections.append(.init(viewItems)) } - feeViewItem = record.fee.map { .fee(title: "tx_info.fee".localized, value: feeString(transactionValue: $0, rate: _rate($0))) } + feeViewItem = record.fee.map { .fee(title: "tx_info.fee".localized, value: feeString(appValue: $0, rate: _rate($0))) } default: () } @@ -638,7 +636,7 @@ class TransactionInfoViewItemFactory { .status(status: status), ] - if let evmRecord = record as? EvmTransactionRecord, evmRecord.ownTransaction, let transactionValue = evmRecord.fee { + if let evmRecord = record as? EvmTransactionRecord, evmRecord.ownTransaction, let appValue = evmRecord.fee { let title: String switch status { case .pending: title = "tx_info.fee.estimated".localized @@ -647,11 +645,11 @@ class TransactionInfoViewItemFactory { feeViewItem = .fee( title: title, - value: feeString(transactionValue: transactionValue, rate: _rate(transactionValue)) + value: feeString(appValue: appValue, rate: _rate(appValue)) ) } - if let tronRecord = record as? TronTransactionRecord, tronRecord.ownTransaction, let transactionValue = tronRecord.fee { + if let tronRecord = record as? TronTransactionRecord, tronRecord.ownTransaction, let appValue = tronRecord.fee { let title: String switch status { case .pending: title = "tx_info.fee.estimated".localized @@ -660,7 +658,7 @@ class TransactionInfoViewItemFactory { feeViewItem = .fee( title: title, - value: feeString(transactionValue: transactionValue, rate: _rate(transactionValue)) + value: feeString(appValue: appValue, rate: _rate(appValue)) ) } diff --git a/UnstoppableWallet/UnstoppableWallet/Modules/Transactions/BaseTransactionsService.swift b/UnstoppableWallet/UnstoppableWallet/Modules/Transactions/BaseTransactionsService.swift index 47e88d4224..b75c4aeefa 100644 --- a/UnstoppableWallet/UnstoppableWallet/Modules/Transactions/BaseTransactionsService.swift +++ b/UnstoppableWallet/UnstoppableWallet/Modules/Transactions/BaseTransactionsService.swift @@ -253,11 +253,11 @@ class BaseTransactionsService { } private func currencyValue(record: TransactionRecord, rate: CurrencyValue?) -> CurrencyValue? { - guard let rate, let decimalValue = record.mainValue?.decimalValue else { + guard let rate, let mainValue = record.mainValue else { return nil } - return CurrencyValue(currency: rate.currency, value: decimalValue * rate.value) + return CurrencyValue(currency: rate.currency, value: mainValue.value * rate.value) } private func _reportItemData() { diff --git a/UnstoppableWallet/UnstoppableWallet/Modules/Transactions/TransactionsViewItemFactory.swift b/UnstoppableWallet/UnstoppableWallet/Modules/Transactions/TransactionsViewItemFactory.swift index 188655a693..b509a53d22 100644 --- a/UnstoppableWallet/UnstoppableWallet/Modules/Transactions/TransactionsViewItemFactory.swift +++ b/UnstoppableWallet/UnstoppableWallet/Modules/Transactions/TransactionsViewItemFactory.swift @@ -25,8 +25,8 @@ class TransactionsViewItemFactory { contactLabelService.contactData(for: address, blockchainType: blockchainType).name ?? evmLabelManager.mapped(address: address) } - private func coinString(from transactionValue: TransactionValue, signType: ValueFormatter.SignType = .always) -> String { - guard let value = transactionValue.formattedShort(signType: signType) else { + private func coinString(from appValue: AppValue, signType: ValueFormatter.SignType = .always) -> String { + guard let value = appValue.formattedShort(signType: signType) else { return "n/a".localized } @@ -37,7 +37,7 @@ class TransactionsViewItemFactory { ValueFormatter.instance.formatShort(currencyValue: currencyValue) ?? "" } - private func type(value: TransactionValue, condition: Bool = true, _ trueType: BaseTransactionsViewModel.ValueType, _ falseType: BaseTransactionsViewModel.ValueType? = nil) -> BaseTransactionsViewModel.ValueType { + private func type(value: AppValue, condition: Bool = true, _ trueType: BaseTransactionsViewModel.ValueType, _ falseType: BaseTransactionsViewModel.ValueType? = nil) -> BaseTransactionsViewModel.ValueType { guard !value.zeroValue else { return .neutral } @@ -45,9 +45,9 @@ class TransactionsViewItemFactory { return condition ? trueType : (falseType ?? trueType) } - private func singleValueSecondaryValue(value: TransactionValue, currencyValue: CurrencyValue?, nftMetadata: [NftUid: NftAssetBriefMetadata]) -> BaseTransactionsViewModel.Value? { - switch value { - case let .nftValue(nftUid, _, tokenName, _): + private func singleValueSecondaryValue(value: AppValue, currencyValue: CurrencyValue?, nftMetadata: [NftUid: NftAssetBriefMetadata]) -> BaseTransactionsViewModel.Value? { + switch value.kind { + case let .nft(nftUid, tokenName, _): let text = nftMetadata[nftUid]?.name ?? tokenName.map { "\($0) #\(nftUid.tokenId)" } ?? "#\(nftUid.tokenId)" return BaseTransactionsViewModel.Value(text: text, type: .secondary) default: @@ -55,9 +55,9 @@ class TransactionsViewItemFactory { } } - private func singleValueIconType(source: TransactionSource, value: TransactionValue, nftMetadata: [NftUid: NftAssetBriefMetadata] = [:]) -> BaseTransactionsViewModel.IconType { - switch value { - case let .nftValue(nftUid, _, _, _): + private func singleValueIconType(source: TransactionSource, value: AppValue, nftMetadata: [NftUid: NftAssetBriefMetadata] = [:]) -> BaseTransactionsViewModel.IconType { + switch value.kind { + case let .nft(nftUid, _, _): return .icon( url: nftMetadata[nftUid]?.previewImageUrl, alternativeUrl: nil, @@ -72,7 +72,7 @@ class TransactionsViewItemFactory { } } - private func doubleValueIconType(source: TransactionSource, primaryValue: TransactionValue?, secondaryValue: TransactionValue?, nftMetadata: [NftUid: NftAssetBriefMetadata] = [:]) -> BaseTransactionsViewModel.IconType { + private func doubleValueIconType(source: TransactionSource, primaryValue: AppValue?, secondaryValue: AppValue?, nftMetadata: [NftUid: NftAssetBriefMetadata] = [:]) -> BaseTransactionsViewModel.IconType { let frontType: TransactionImageComponent.ImageType let frontUrl: String? var frontAlternativeUrl: String? @@ -83,8 +83,8 @@ class TransactionsViewItemFactory { let backPlaceholder: String if let primaryValue { - switch primaryValue { - case let .nftValue(nftUid, _, _, _): + switch primaryValue.kind { + case let .nft(nftUid, _, _): frontType = .squircle frontUrl = nftMetadata[nftUid]?.previewImageUrl frontPlaceholder = "placeholder_nft_32" @@ -101,8 +101,8 @@ class TransactionsViewItemFactory { } if let secondaryValue { - switch secondaryValue { - case let .nftValue(nftUid, _, _, _): + switch secondaryValue.kind { + case let .nft(nftUid, _, _): backType = .squircle backUrl = nftMetadata[nftUid]?.previewImageUrl backPlaceholder = "placeholder_nft_32" @@ -130,7 +130,7 @@ class TransactionsViewItemFactory { ) } - private func iconType(source: TransactionSource, incomingValues: [TransactionValue], outgoingValues: [TransactionValue], nftMetadata: [NftUid: NftAssetBriefMetadata]) -> BaseTransactionsViewModel.IconType { + private func iconType(source: TransactionSource, incomingValues: [AppValue], outgoingValues: [AppValue], nftMetadata: [NftUid: NftAssetBriefMetadata]) -> BaseTransactionsViewModel.IconType { if incomingValues.count == 1, outgoingValues.isEmpty { return singleValueIconType(source: source, value: incomingValues[0], nftMetadata: nftMetadata) } else if incomingValues.isEmpty, outgoingValues.count == 1 { @@ -142,7 +142,7 @@ class TransactionsViewItemFactory { } } - private func values(incomingValues: [TransactionValue], outgoingValues: [TransactionValue], currencyValue: CurrencyValue?, nftMetadata: [NftUid: NftAssetBriefMetadata]) -> (BaseTransactionsViewModel.Value?, BaseTransactionsViewModel.Value?) { + private func values(incomingValues: [AppValue], outgoingValues: [AppValue], currencyValue: CurrencyValue?, nftMetadata: [NftUid: NftAssetBriefMetadata]) -> (BaseTransactionsViewModel.Value?, BaseTransactionsViewModel.Value?) { var primaryValue: BaseTransactionsViewModel.Value? var secondaryValue: BaseTransactionsViewModel.Value? @@ -155,24 +155,24 @@ class TransactionsViewItemFactory { primaryValue = BaseTransactionsViewModel.Value(text: coinString(from: outgoingValue), type: type(value: outgoingValue, .outgoing)) secondaryValue = singleValueSecondaryValue(value: outgoingValue, currencyValue: currencyValue, nftMetadata: nftMetadata) } else if !incomingValues.isEmpty, outgoingValues.isEmpty { - let coinCodes = incomingValues.map(\.coinCode).joined(separator: ", ") + let coinCodes = incomingValues.map(\.code).joined(separator: ", ") primaryValue = BaseTransactionsViewModel.Value(text: coinCodes, type: .incoming) secondaryValue = BaseTransactionsViewModel.Value(text: "transactions.multiple".localized, type: .secondary) } else if incomingValues.isEmpty, !outgoingValues.isEmpty { - let coinCodes = outgoingValues.map(\.coinCode).joined(separator: ", ") + let coinCodes = outgoingValues.map(\.code).joined(separator: ", ") primaryValue = BaseTransactionsViewModel.Value(text: coinCodes, type: .outgoing) secondaryValue = BaseTransactionsViewModel.Value(text: "transactions.multiple".localized, type: .secondary) } else { if incomingValues.count == 1 { primaryValue = BaseTransactionsViewModel.Value(text: coinString(from: incomingValues[0]), type: type(value: incomingValues[0], .incoming)) } else { - let incomingCoinCodes = incomingValues.map(\.coinCode).joined(separator: ", ") + let incomingCoinCodes = incomingValues.map(\.code).joined(separator: ", ") primaryValue = BaseTransactionsViewModel.Value(text: incomingCoinCodes, type: .incoming) } if outgoingValues.count == 1 { secondaryValue = BaseTransactionsViewModel.Value(text: coinString(from: outgoingValues[0]), type: type(value: outgoingValues[0], .outgoing)) } else { - let outgoingCoinCodes = outgoingValues.map(\.coinCode).joined(separator: ", ") + let outgoingCoinCodes = outgoingValues.map(\.code).joined(separator: ", ") secondaryValue = BaseTransactionsViewModel.Value(text: outgoingCoinCodes, type: .outgoing) } } @@ -241,7 +241,7 @@ class TransactionsViewItemFactory { subTitle = mapped(address: record.spender, blockchainType: item.record.source.blockchainType) if record.value.isMaxValue { - primaryValue = BaseTransactionsViewModel.Value(text: "∞ \(record.value.coinCode)", type: .neutral) + primaryValue = BaseTransactionsViewModel.Value(text: "∞ \(record.value.code)", type: .neutral) secondaryValue = BaseTransactionsViewModel.Value(text: "transactions.value.unlimited".localized, type: .secondary) } else { primaryValue = BaseTransactionsViewModel.Value(text: coinString(from: record.value, signType: .never), type: .neutral) @@ -367,7 +367,7 @@ class TransactionsViewItemFactory { subTitle = mapped(address: record.spender, blockchainType: item.record.source.blockchainType) if record.value.isMaxValue { - primaryValue = BaseTransactionsViewModel.Value(text: "∞ \(record.value.coinCode)", type: .neutral) + primaryValue = BaseTransactionsViewModel.Value(text: "∞ \(record.value.code)", type: .neutral) secondaryValue = BaseTransactionsViewModel.Value(text: "transactions.value.unlimited".localized, type: .secondary) } else { primaryValue = BaseTransactionsViewModel.Value(text: coinString(from: record.value, signType: .never), type: .neutral) @@ -437,7 +437,7 @@ class TransactionsViewItemFactory { case let .burn(value): iconType = singleValueIconType(source: record.source, value: value) title = "transactions.burn".localized - subTitle = value.fullName + subTitle = value.name primaryValue = BaseTransactionsViewModel.Value(text: coinString(from: value), type: type(value: value, .outgoing)) if let currencyValue = item.currencyValue { @@ -446,7 +446,7 @@ class TransactionsViewItemFactory { case let .mint(value): iconType = singleValueIconType(source: record.source, value: value) title = "transactions.mint".localized - subTitle = value.fullName + subTitle = value.name primaryValue = BaseTransactionsViewModel.Value(text: coinString(from: value), type: type(value: value, .incoming)) if let currencyValue = item.currencyValue { diff --git a/UnstoppableWallet/UnstoppableWallet/Modules/Wallet/Receive/Address/ReceiveAddressViewItemFactory.swift b/UnstoppableWallet/UnstoppableWallet/Modules/Wallet/Receive/Address/ReceiveAddressViewItemFactory.swift index 4fba72fb5d..246008b443 100644 --- a/UnstoppableWallet/UnstoppableWallet/Modules/Wallet/Receive/Address/ReceiveAddressViewItemFactory.swift +++ b/UnstoppableWallet/UnstoppableWallet/Modules/Wallet/Receive/Address/ReceiveAddressViewItemFactory.swift @@ -53,8 +53,8 @@ class ReceiveAddressViewItemFactory: IReceiveAddressViewItemFactory { ) var amountString: String? if let amount, let decimalValue = Decimal(string: amount) { - let coinValue = CoinValue(kind: .token(token: item.token), value: decimalValue) - amountString = coinValue.formattedFull + let appValue = AppValue(token: item.token, value: decimalValue) + amountString = appValue.formattedFull() } var active = true diff --git a/UnstoppableWallet/UnstoppableWallet/Modules/Wallet/WalletService.swift b/UnstoppableWallet/UnstoppableWallet/Modules/Wallet/WalletService.swift index 41242cb697..b2df4f3f2d 100644 --- a/UnstoppableWallet/UnstoppableWallet/Modules/Wallet/WalletService.swift +++ b/UnstoppableWallet/UnstoppableWallet/Modules/Wallet/WalletService.swift @@ -262,11 +262,11 @@ class WalletService { } } - var convertedValue: CoinValue? + var convertedValue: AppValue? var convertedValueExpired = false if let conversionToken = balanceConversionManager.conversionToken, let priceItem = coinPriceService.item(coinUid: conversionToken.coin.uid) { - convertedValue = CoinValue(kind: .token(token: conversionToken), value: total / priceItem.price.value) + convertedValue = AppValue(token: conversionToken, value: total / priceItem.price.value) convertedValueExpired = priceItem.expired } @@ -566,7 +566,7 @@ extension WalletService { struct TotalItem { let currencyValue: CurrencyValue let expired: Bool - let convertedValue: CoinValue? + let convertedValue: AppValue? let convertedValueExpired: Bool } } diff --git a/UnstoppableWallet/UnstoppableWallet/Modules/Wallet/WalletViewItemFactory.swift b/UnstoppableWallet/UnstoppableWallet/Modules/Wallet/WalletViewItemFactory.swift index e8292c11a5..331349658e 100644 --- a/UnstoppableWallet/UnstoppableWallet/Modules/Wallet/WalletViewItemFactory.swift +++ b/UnstoppableWallet/UnstoppableWallet/Modules/Wallet/WalletViewItemFactory.swift @@ -170,7 +170,7 @@ extension WalletViewItemFactory { let convertedValue: String if balanceHidden { convertedValue = BalanceHiddenManager.placeholder - } else if let value = totalItem.convertedValue, let formattedValue = ValueFormatter.instance.formatShort(coinValue: value) { + } else if let value = totalItem.convertedValue, let formattedValue = value.formattedShort() { convertedValue = "≈ \(formattedValue)" } else { convertedValue = "---" diff --git a/UnstoppableWallet/UnstoppableWallet/UserInterface/ValueFormatter.swift b/UnstoppableWallet/UnstoppableWallet/UserInterface/ValueFormatter.swift index 234d9285fc..93730880d1 100644 --- a/UnstoppableWallet/UnstoppableWallet/UserInterface/ValueFormatter.swift +++ b/UnstoppableWallet/UnstoppableWallet/UserInterface/ValueFormatter.swift @@ -241,14 +241,6 @@ extension ValueFormatter { return decorated(string: string, symbol: symbol, signType: signType, signValue: value) } - func formatShort(coinValue: CoinValue, showCode: Bool = true, signType: SignType = .never) -> String? { - formatShort(value: coinValue.value, decimalCount: coinValue.decimals, symbol: showCode ? coinValue.symbol : nil, signType: signType) - } - - func formatFull(coinValue: CoinValue, showCode: Bool = true, signType: SignType = .never) -> String? { - formatFull(value: coinValue.value, decimalCount: coinValue.decimals, symbol: showCode ? coinValue.symbol : nil, signType: signType) - } - func formatShort(currency: Currency, value: Decimal, signType: SignType = .never) -> String? { let (transformedValue, digits, suffix, tooSmall) = transformedShort(value: value)