From 35076e80bd8463ba4a65df51d41f4645d21b3c7c Mon Sep 17 00:00:00 2001 From: ant013 Date: Wed, 26 Jul 2023 16:40:19 +0600 Subject: [PATCH] Disable withdrawal buttons for binance account --- .../UnstoppableWallet/Models/AccountType.swift | 7 +++++++ UnstoppableWallet/UnstoppableWallet/Models/Cex.swift | 7 +++++++ .../Modules/Binance/BinanceCexProvider.swift | 2 +- .../Modules/Wallet/Views/WalletHeaderCell.swift | 6 ++++++ .../UnstoppableWallet/Modules/Wallet/WalletService.swift | 4 ++++ .../Modules/Wallet/WalletViewItemFactory.swift | 5 +++-- .../UnstoppableWallet/Modules/Wallet/WalletViewModel.swift | 3 ++- 7 files changed, 30 insertions(+), 4 deletions(-) diff --git a/UnstoppableWallet/UnstoppableWallet/Models/AccountType.swift b/UnstoppableWallet/UnstoppableWallet/Models/AccountType.swift index 44b50f5631..ea7d320532 100644 --- a/UnstoppableWallet/UnstoppableWallet/Models/AccountType.swift +++ b/UnstoppableWallet/UnstoppableWallet/Models/AccountType.swift @@ -151,6 +151,13 @@ enum AccountType { } } + var withdrawalAllowed: Bool { + switch self { + case .cex(cexAccount: let account): return account.cex.withdrawalAllowed + default: return true + } + } + var hideZeroBalances: Bool { switch self { case .evmAddress: return true diff --git a/UnstoppableWallet/UnstoppableWallet/Models/Cex.swift b/UnstoppableWallet/UnstoppableWallet/Models/Cex.swift index 7ad5fa7c15..5c0079e77b 100644 --- a/UnstoppableWallet/UnstoppableWallet/Models/Cex.swift +++ b/UnstoppableWallet/UnstoppableWallet/Models/Cex.swift @@ -23,6 +23,13 @@ enum Cex: String, CaseIterable { return "https://cdn.blocksdecoded.com/cex-icons/\(rawValue)@\(scale)x.png" } + var withdrawalAllowed: Bool { + switch self { + case .binance: return false + case .coinzix: return true + } + } + func restoreViewController(returnViewController: UIViewController?) -> UIViewController { switch self { case .binance: return RestoreBinanceModule.viewController(returnViewController: returnViewController) diff --git a/UnstoppableWallet/UnstoppableWallet/Modules/Binance/BinanceCexProvider.swift b/UnstoppableWallet/UnstoppableWallet/Modules/Binance/BinanceCexProvider.swift index fa65553c06..04251cc3cb 100644 --- a/UnstoppableWallet/UnstoppableWallet/Modules/Binance/BinanceCexProvider.swift +++ b/UnstoppableWallet/UnstoppableWallet/Modules/Binance/BinanceCexProvider.swift @@ -495,7 +495,7 @@ extension BinanceCexProvider: ICexAssetProvider { freeBalance: asset.free, lockedBalance: asset.locked, depositEnabled: asset.depositAllEnable, - withdrawEnabled: asset.withdrawAllEnable, + withdrawEnabled: false, depositNetworks: asset.networks.map { network in CexDepositNetworkRaw( id: network.network, diff --git a/UnstoppableWallet/UnstoppableWallet/Modules/Wallet/Views/WalletHeaderCell.swift b/UnstoppableWallet/UnstoppableWallet/Modules/Wallet/Views/WalletHeaderCell.swift index b9c68680d6..1fb32c16f4 100644 --- a/UnstoppableWallet/UnstoppableWallet/Modules/Wallet/Views/WalletHeaderCell.swift +++ b/UnstoppableWallet/UnstoppableWallet/Modules/Wallet/Views/WalletHeaderCell.swift @@ -69,6 +69,11 @@ class WalletHeaderCell: UITableViewCell { onDeposit?() } + var withdrawalEnabled: Bool { + get { withdrawButton.isEnabled } + set { withdrawButton.isEnabled = newValue } + } + var onTapAmount: (() -> ())? { get { amountView.onTapAmount } set { amountView.onTapAmount = newValue } @@ -82,6 +87,7 @@ class WalletHeaderCell: UITableViewCell { func bind(viewItem: WalletViewModel.HeaderViewItem) { amountView.set(amountText: viewItem.amount, expired: viewItem.amountExpired) amountView.set(convertedAmountText: viewItem.convertedValue, expired: viewItem.convertedValueExpired) + withdrawButton.isEnabled = viewItem.withdrawalAllowed } } diff --git a/UnstoppableWallet/UnstoppableWallet/Modules/Wallet/WalletService.swift b/UnstoppableWallet/UnstoppableWallet/Modules/Wallet/WalletService.swift index 7b91ffb033..05fcf08646 100644 --- a/UnstoppableWallet/UnstoppableWallet/Modules/Wallet/WalletService.swift +++ b/UnstoppableWallet/UnstoppableWallet/Modules/Wallet/WalletService.swift @@ -465,6 +465,10 @@ extension WalletService { accountManager.activeAccount?.cexAccount ?? false } + var withdrawalAllowed: Bool { + accountManager.activeAccount?.type.withdrawalAllowed ?? false + } + var lastCreatedAccount: Account? { accountManager.popLastCreatedAccount() } diff --git a/UnstoppableWallet/UnstoppableWallet/Modules/Wallet/WalletViewItemFactory.swift b/UnstoppableWallet/UnstoppableWallet/Modules/Wallet/WalletViewItemFactory.swift index e390b79438..73e316b628 100644 --- a/UnstoppableWallet/UnstoppableWallet/Modules/Wallet/WalletViewItemFactory.swift +++ b/UnstoppableWallet/UnstoppableWallet/Modules/Wallet/WalletViewItemFactory.swift @@ -183,7 +183,7 @@ extension WalletViewItemFactory { ) } - func headerViewItem(totalItem: WalletService.TotalItem, balanceHidden: Bool, cexAccount: Bool) -> WalletViewModel.HeaderViewItem { + func headerViewItem(totalItem: WalletService.TotalItem, balanceHidden: Bool, cexAccount: Bool, withdrawalAllowed: Bool) -> WalletViewModel.HeaderViewItem { let amount = balanceHidden ? "*****" : ValueFormatter.instance.formatShort(currencyValue: totalItem.currencyValue) let convertedValue: String @@ -200,7 +200,8 @@ extension WalletViewItemFactory { amountExpired: balanceHidden ? false : totalItem.expired, convertedValue: convertedValue, convertedValueExpired: balanceHidden ? false : totalItem.convertedValueExpired, - buttonsVisible: cexAccount + buttonsVisible: cexAccount, + withdrawalAllowed: withdrawalAllowed ) } diff --git a/UnstoppableWallet/UnstoppableWallet/Modules/Wallet/WalletViewModel.swift b/UnstoppableWallet/UnstoppableWallet/Modules/Wallet/WalletViewModel.swift index 8421e966be..be430f1ce2 100644 --- a/UnstoppableWallet/UnstoppableWallet/Modules/Wallet/WalletViewModel.swift +++ b/UnstoppableWallet/UnstoppableWallet/Modules/Wallet/WalletViewModel.swift @@ -105,7 +105,7 @@ class WalletViewModel { } private func sync(totalItem: WalletService.TotalItem?) { - headerViewItem = totalItem.map { factory.headerViewItem(totalItem: $0, balanceHidden: service.balanceHidden, cexAccount: service.cexAccount) } + headerViewItem = totalItem.map { factory.headerViewItem(totalItem: $0, balanceHidden: service.balanceHidden, cexAccount: service.cexAccount, withdrawalAllowed: service.withdrawalAllowed) } } private func sync(sortType: WalletModule.SortType, scrollToTop: Bool) { @@ -345,6 +345,7 @@ extension WalletViewModel { let convertedValue: String? let convertedValueExpired: Bool let buttonsVisible: Bool + let withdrawalAllowed: Bool } struct ControlViewItem {