Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix send/swap token list for zcash #5277

Merged
merged 1 commit into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 8 additions & 0 deletions UnstoppableWallet/UnstoppableWallet/Models/AdapterState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)
)
Expand Down Expand Up @@ -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
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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... %@";
Expand Down