From f961d641f918639fb9384abaeb0aca8a2eaba69d Mon Sep 17 00:00:00 2001 From: ant013 Date: Wed, 27 Sep 2023 19:07:33 +0400 Subject: [PATCH] Fix send/swap token list for zcash --- .../Core/Adapters/ZcashAdapter.swift | 21 +++++++++---------- .../Models/AdapterState.swift | 8 +++++++ .../Modules/Wallet/BalanceViewItem.swift | 1 + .../WalletTokenBalanceViewItemFactory.swift | 9 +++----- .../TokenList/WalletTokenListDataSource.swift | 2 +- .../WalletTokenListViewItemFactory.swift | 2 ++ .../TokenList/WalletTokenListViewModel.swift | 9 ++++---- .../Wallet/WalletViewItemFactory.swift | 4 +++- .../en.lproj/Localizable.strings | 1 + 9 files changed, 34 insertions(+), 23 deletions(-) diff --git a/UnstoppableWallet/UnstoppableWallet/Core/Adapters/ZcashAdapter.swift b/UnstoppableWallet/UnstoppableWallet/Core/Adapters/ZcashAdapter.swift index 155fc46c74..20221182e5 100644 --- a/UnstoppableWallet/UnstoppableWallet/Core/Adapters/ZcashAdapter.swift +++ b/UnstoppableWallet/UnstoppableWallet/Core/Adapters/ZcashAdapter.swift @@ -66,17 +66,12 @@ class ZcashAdapter { private(set) var syncing: Bool = true private func defaultFee(network: ZcashNetwork, height: Int? = nil) -> Zatoshi { - let fee: Zatoshi - if let lastBlockHeight = height { - fee = network.constants.defaultFee(for: lastBlockHeight) - } else { - fee = network.constants.defaultFee() - } - return fee + network.constants.defaultFee(for: height ?? BlockHeight.max) } private func defaultFeeDecimal(network: ZcashNetwork, height: Int? = nil) -> Decimal { - defaultFee(network: network, height: height).decimalValue.decimalValue + // todo update fee settings + fee// defaultFee(network: network, height: height).decimalValue.decimalValue } init(wallet: Wallet, restoreSettings: RestoreSettings) throws { @@ -87,7 +82,9 @@ class ZcashAdapter { } network = ZcashNetworkBuilder.network(for: .mainnet) - fee = network.constants.defaultFee().decimalValue.decimalValue + + // todo: update fee settings + fee = 10_000//network.constants.defaultFee().decimalValue.decimalValue token = wallet.token transactionSource = wallet.transactionSource @@ -190,7 +187,9 @@ class ZcashAdapter { available: shieldedVerified ) ) - self?.lastBlockHeight = try await synchronizer.latestHeight() + let height = try await synchronizer.latestHeight() + self?.lastBlockHeight = height + self?.lastBlockUpdatedSubject.onNext(()) self?.finishPrepare() @@ -828,7 +827,7 @@ enum ZCashAdapterState: Equatable { case let .downloadingSapling(progress): return .customSyncing(main: "balance.downloading_sapling".localized(progress), secondary: nil, progress: progress) case let .downloadingBlocks(progress, _): - let percentValue = ValueFormatter.instance.format(percentValue: Decimal(Double(progress)), showSign: false) + let percentValue = ValueFormatter.instance.format(percentValue: Decimal(Double(progress * 100)), showSign: false) return .customSyncing(main: "balance.downloading_blocks".localized, secondary: percentValue, progress: Int(progress * 100)) case let .scanningBlocks(number, lastBlock): return .customSyncing(main: "Scanning Blocks", secondary: "\(number)/\(lastBlock)", progress: nil) diff --git a/UnstoppableWallet/UnstoppableWallet/Models/AdapterState.swift b/UnstoppableWallet/UnstoppableWallet/Models/AdapterState.swift index 8e96f93e52..f05ae385c0 100644 --- a/UnstoppableWallet/UnstoppableWallet/Models/AdapterState.swift +++ b/UnstoppableWallet/UnstoppableWallet/Models/AdapterState.swift @@ -21,6 +21,14 @@ enum AdapterState { } } + func spendAllowed(beforeSync: Bool) -> Bool { + switch self { + case .synced: return true + case .syncing, .customSyncing: return beforeSync ? true : false + case .stopped, .notSynced: return false + } + } + } extension AdapterState: Equatable { diff --git a/UnstoppableWallet/UnstoppableWallet/Modules/Wallet/BalanceViewItem.swift b/UnstoppableWallet/UnstoppableWallet/Modules/Wallet/BalanceViewItem.swift index 6057997ecc..cc629f96da 100644 --- a/UnstoppableWallet/UnstoppableWallet/Modules/Wallet/BalanceViewItem.swift +++ b/UnstoppableWallet/UnstoppableWallet/Modules/Wallet/BalanceViewItem.swift @@ -17,6 +17,7 @@ struct BalanceTopViewItem { let syncSpinnerProgress: Int? let indefiniteSearchCircle: Bool let failedImageViewVisible: Bool + let sendEnabled: Bool let primaryValue: (text: String?, dimmed: Bool)? let secondaryInfo: BalanceSecondaryInfoViewItem diff --git a/UnstoppableWallet/UnstoppableWallet/Modules/Wallet/Token/DataSources/WalletTokenBalance/WalletTokenBalanceViewItemFactory.swift b/UnstoppableWallet/UnstoppableWallet/Modules/Wallet/Token/DataSources/WalletTokenBalance/WalletTokenBalanceViewItemFactory.swift index a7b25752d8..577304d5f2 100644 --- a/UnstoppableWallet/UnstoppableWallet/Modules/Wallet/Token/DataSources/WalletTokenBalance/WalletTokenBalanceViewItemFactory.swift +++ b/UnstoppableWallet/UnstoppableWallet/Modules/Wallet/Token/DataSources/WalletTokenBalance/WalletTokenBalanceViewItemFactory.swift @@ -18,12 +18,9 @@ class WalletTokenBalanceViewItemFactory { if item.watchAccount { buttons[.address] = .enabled } else { - let sendButtonState: ButtonState - switch item.state { - case .synced: sendButtonState = .enabled - case .syncing, .customSyncing: sendButtonState = item.balanceData.sendBeforeSync ? .enabled : .disabled - case .stopped, .notSynced: sendButtonState = .disabled - } + let sendButtonState: ButtonState = item + .state + .spendAllowed(beforeSync: item.balanceData.sendBeforeSync) ? .enabled : .disabled buttons[.send] = sendButtonState buttons[.receive] = .enabled diff --git a/UnstoppableWallet/UnstoppableWallet/Modules/Wallet/TokenList/WalletTokenListDataSource.swift b/UnstoppableWallet/UnstoppableWallet/Modules/Wallet/TokenList/WalletTokenListDataSource.swift index 381254ab34..81a02882c0 100644 --- a/UnstoppableWallet/UnstoppableWallet/Modules/Wallet/TokenList/WalletTokenListDataSource.swift +++ b/UnstoppableWallet/UnstoppableWallet/Modules/Wallet/TokenList/WalletTokenListDataSource.swift @@ -166,7 +166,7 @@ extension WalletTokenListDataSource: ISectionDataSource { } subscribe(disposeBag, viewModel.noConnectionErrorSignal) { HudHelper.instance.show(banner: .noInternet) } - subscribe(disposeBag, viewModel.showSyncingSignal) { HudHelper.instance.show(banner: .attention(string: "Wait for synchronization")) } + subscribe(disposeBag, viewModel.showSyncingSignal) { HudHelper.instance.show(banner: .attention(string: "wait_for_synchronization".localized)) } subscribe(disposeBag, viewModel.selectWalletSignal) { [weak self] in self?.onSelect(wallet: $0) } subscribe(disposeBag, viewModel.openSyncErrorSignal) { [weak self] in self?.openSyncError(wallet: $0, error: $1) } diff --git a/UnstoppableWallet/UnstoppableWallet/Modules/Wallet/TokenList/WalletTokenListViewItemFactory.swift b/UnstoppableWallet/UnstoppableWallet/Modules/Wallet/TokenList/WalletTokenListViewItemFactory.swift index ce6b087df8..4a503e2ade 100644 --- a/UnstoppableWallet/UnstoppableWallet/Modules/Wallet/TokenList/WalletTokenListViewItemFactory.swift +++ b/UnstoppableWallet/UnstoppableWallet/Modules/Wallet/TokenList/WalletTokenListViewItemFactory.swift @@ -9,6 +9,7 @@ class WalletTokenListViewItemFactory { private func topViewItem(item: WalletTokenListService.Item, balancePrimaryValue: BalancePrimaryValue) -> BalanceTopViewItem { let state = item.state + let sendEnabled = state.spendAllowed(beforeSync: item.balanceData.sendBeforeSync) return BalanceTopViewItem( isMainNet: item.isMainNet, @@ -19,6 +20,7 @@ class WalletTokenListViewItemFactory { syncSpinnerProgress: syncSpinnerProgress(state: state), indefiniteSearchCircle: indefiniteSearchCircle(state: state), failedImageViewVisible: failedImageViewVisible(state: state), + sendEnabled: sendEnabled, primaryValue: primaryValue(item: item, balancePrimaryValue: balancePrimaryValue), secondaryInfo: secondaryInfo(item: item, balancePrimaryValue: balancePrimaryValue) ) diff --git a/UnstoppableWallet/UnstoppableWallet/Modules/Wallet/TokenList/WalletTokenListViewModel.swift b/UnstoppableWallet/UnstoppableWallet/Modules/Wallet/TokenList/WalletTokenListViewModel.swift index f5145bfa7e..1fd3303de4 100644 --- a/UnstoppableWallet/UnstoppableWallet/Modules/Wallet/TokenList/WalletTokenListViewModel.swift +++ b/UnstoppableWallet/UnstoppableWallet/Modules/Wallet/TokenList/WalletTokenListViewModel.swift @@ -164,13 +164,14 @@ extension WalletTokenListViewModel { } func didSelect(item: BalanceViewItem) { - if item.topViewItem.indefiniteSearchCircle || item.topViewItem.syncSpinnerProgress != nil { + if item.topViewItem.failedImageViewVisible { + onTapFailedIcon(element: item.element) + return + } + if !item.topViewItem.sendEnabled { showSyncingRelay.accept(()) return } - if item.topViewItem.failedImageViewVisible { - onTapFailedIcon(element: item.element) - } else if let wallet = item.element.wallet { selectWalletRelay.accept(wallet) } diff --git a/UnstoppableWallet/UnstoppableWallet/Modules/Wallet/WalletViewItemFactory.swift b/UnstoppableWallet/UnstoppableWallet/Modules/Wallet/WalletViewItemFactory.swift index bcddb0eb6c..e656e0ab3e 100644 --- a/UnstoppableWallet/UnstoppableWallet/Modules/Wallet/WalletViewItemFactory.swift +++ b/UnstoppableWallet/UnstoppableWallet/Modules/Wallet/WalletViewItemFactory.swift @@ -9,6 +9,7 @@ class WalletViewItemFactory { private func topViewItem(item: WalletService.Item, balancePrimaryValue: BalancePrimaryValue, balanceHidden: Bool) -> BalanceTopViewItem { let state = item.state + let sendEnabled = state.spendAllowed(beforeSync: item.balanceData.sendBeforeSync) return BalanceTopViewItem( isMainNet: item.isMainNet, @@ -19,6 +20,7 @@ class WalletViewItemFactory { syncSpinnerProgress: syncSpinnerProgress(state: state), indefiniteSearchCircle: indefiniteSearchCircle(state: state), failedImageViewVisible: failedImageViewVisible(state: state), + sendEnabled: sendEnabled, primaryValue: balanceHidden ? nil : primaryValue(item: item, balancePrimaryValue: balancePrimaryValue), secondaryInfo: secondaryInfo(item: item, balancePrimaryValue: balancePrimaryValue, balanceHidden: balanceHidden) ) @@ -67,7 +69,7 @@ class WalletViewItemFactory { private func indefiniteSearchCircle(state: AdapterState) -> Bool { switch state { - case .customSyncing: return true + case .customSyncing(_, _, let progress): return progress == nil default: return false } } diff --git a/UnstoppableWallet/UnstoppableWallet/en.lproj/Localizable.strings b/UnstoppableWallet/UnstoppableWallet/en.lproj/Localizable.strings index 230b8dddd7..4e1d9975fa 100644 --- a/UnstoppableWallet/UnstoppableWallet/en.lproj/Localizable.strings +++ b/UnstoppableWallet/UnstoppableWallet/en.lproj/Localizable.strings @@ -298,6 +298,7 @@ Go to Settings - > %@ and allow access to the camera."; "balance.downloading_blocks" = "Downloading Blocks"; "balance.scanning_blocks" = "Scanning Blocks"; "balance.enhancing_transactions" = "Enhancing Transactions"; +"wait_for_synchronization" = "Wait for synchronization"; "balance.searching.count" = "%@ tx"; "balance.syncing_percent" = "Syncing... %@";