Skip to content

Commit

Permalink
Disable withdrawal buttons for binance account
Browse files Browse the repository at this point in the history
  • Loading branch information
ant013 committed Jul 26, 2023
1 parent d45d9b3 commit 35076e8
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 4 deletions.
7 changes: 7 additions & 0 deletions UnstoppableWallet/UnstoppableWallet/Models/AccountType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions UnstoppableWallet/UnstoppableWallet/Models/Cex.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand All @@ -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
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,10 @@ extension WalletService {
accountManager.activeAccount?.cexAccount ?? false
}

var withdrawalAllowed: Bool {
accountManager.activeAccount?.type.withdrawalAllowed ?? false
}

var lastCreatedAccount: Account? {
accountManager.popLastCreatedAccount()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -200,7 +200,8 @@ extension WalletViewItemFactory {
amountExpired: balanceHidden ? false : totalItem.expired,
convertedValue: convertedValue,
convertedValueExpired: balanceHidden ? false : totalItem.convertedValueExpired,
buttonsVisible: cexAccount
buttonsVisible: cexAccount,
withdrawalAllowed: withdrawalAllowed
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -345,6 +345,7 @@ extension WalletViewModel {
let convertedValue: String?
let convertedValueExpired: Bool
let buttonsVisible: Bool
let withdrawalAllowed: Bool
}

struct ControlViewItem {
Expand Down

0 comments on commit 35076e8

Please sign in to comment.