|
|
|
@ -46,6 +46,8 @@ class TokensViewController: UIViewController { |
|
|
|
|
tableView.register(FungibleTokenViewCell.self) |
|
|
|
|
tableView.register(EthTokenViewCell.self) |
|
|
|
|
tableView.register(NonFungibleTokenViewCell.self) |
|
|
|
|
tableView.register(ServerTableViewCell.self) |
|
|
|
|
|
|
|
|
|
tableView.registerHeaderFooterView(TableViewSectionHeader.self) |
|
|
|
|
tableView.registerHeaderFooterView(ShowAddHideTokensView.self) |
|
|
|
|
tableView.registerHeaderFooterView(ActiveWalletSessionView.self) |
|
|
|
@ -354,9 +356,13 @@ class TokensViewController: UIViewController { |
|
|
|
|
private func contractsForCollectiblesFromViewModel() -> [AlphaWallet.Address] { |
|
|
|
|
var contractsForCollectibles = [AlphaWallet.Address]() |
|
|
|
|
for i in (0..<viewModel.numberOfItems()) { |
|
|
|
|
let token = viewModel.item(for: i, section: 0) |
|
|
|
|
switch viewModel.item(for: i, section: 0) { |
|
|
|
|
case .rpcServer: |
|
|
|
|
break |
|
|
|
|
case .tokenObject(let token): |
|
|
|
|
contractsForCollectibles.append(token.contractAddress) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return contractsForCollectibles |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -398,9 +404,14 @@ extension TokensViewController: StatefulViewController { |
|
|
|
|
extension TokensViewController: UITableViewDelegate { |
|
|
|
|
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { |
|
|
|
|
tableView.deselectRow(at: indexPath, animated: true) |
|
|
|
|
let token = viewModel.item(for: indexPath.row, section: indexPath.section) |
|
|
|
|
|
|
|
|
|
switch viewModel.item(for: indexPath.row, section: indexPath.section) { |
|
|
|
|
case .rpcServer: |
|
|
|
|
break |
|
|
|
|
case .tokenObject(let token): |
|
|
|
|
delegate?.didSelect(token: token, in: self) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//Hide the footer |
|
|
|
|
func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat { |
|
|
|
@ -462,7 +473,14 @@ extension TokensViewController: UITableViewDataSource { |
|
|
|
|
case .addHideToken, .filters, .activeWalletSession: |
|
|
|
|
return UITableViewCell() |
|
|
|
|
case .tokens: |
|
|
|
|
let token = viewModel.item(for: indexPath.row, section: indexPath.section) |
|
|
|
|
switch viewModel.item(for: indexPath.row, section: indexPath.section) { |
|
|
|
|
case .rpcServer(let server): |
|
|
|
|
let isTopSeparatorHidden = indexPath.row != 0 && indexPath.section != 0 |
|
|
|
|
let cell: ServerTableViewCell = tableView.dequeueReusableCell(for: indexPath) |
|
|
|
|
cell.configure(viewModel: TokenListServerTableViewCellViewModel(server: server, isTopSeparatorHidden: isTopSeparatorHidden)) |
|
|
|
|
|
|
|
|
|
return cell |
|
|
|
|
case .tokenObject(let token): |
|
|
|
|
let server = token.server |
|
|
|
|
let session = sessions[server] |
|
|
|
|
|
|
|
|
@ -496,6 +514,7 @@ extension TokensViewController: UITableViewDataSource { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { |
|
|
|
|
switch sections[section] { |
|
|
|
@ -520,10 +539,14 @@ extension TokensViewController: UITableViewDataSource { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private func trailingSwipeActionsConfiguration(forRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? { |
|
|
|
|
switch viewModel.item(for: indexPath.row, section: indexPath.section) { |
|
|
|
|
case .rpcServer: |
|
|
|
|
return nil |
|
|
|
|
case .tokenObject(let token): |
|
|
|
|
let title = R.string.localizable.walletsHideTokenTitle() |
|
|
|
|
let hideAction = UIContextualAction(style: .destructive, title: title) { [weak self] (_, _, completionHandler) in |
|
|
|
|
guard let strongSelf = self else { return } |
|
|
|
|
let token = strongSelf.viewModel.item(for: indexPath.row, section: indexPath.section) |
|
|
|
|
|
|
|
|
|
strongSelf.delegate?.didHide(token: token, in: strongSelf) |
|
|
|
|
|
|
|
|
|
let didHideToken = strongSelf.viewModel.markTokenHidden(token: token) |
|
|
|
@ -543,6 +566,7 @@ extension TokensViewController: UITableViewDataSource { |
|
|
|
|
|
|
|
|
|
return configuration |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
extension TokensViewController: SegmentedControlDelegate { |
|
|
|
@ -588,13 +612,18 @@ extension TokensViewController: UICollectionViewDataSource { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { |
|
|
|
|
let token = viewModel.item(for: indexPath.row, section: indexPath.section) |
|
|
|
|
switch viewModel.item(for: indexPath.row, section: indexPath.section) { |
|
|
|
|
case .rpcServer: |
|
|
|
|
return UICollectionViewCell() |
|
|
|
|
case .tokenObject(let token): |
|
|
|
|
let server = token.server |
|
|
|
|
let session = sessions[server] |
|
|
|
|
let cell: OpenSeaNonFungibleTokenViewCell = collectionView.dequeueReusableCell(for: indexPath) |
|
|
|
|
|
|
|
|
|
cell.configure(viewModel: .init(config: session.config, token: token, forWallet: account, assetDefinitionStore: assetDefinitionStore, eventsDataStore: eventsDataStore)) |
|
|
|
|
return cell |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView { |
|
|
|
|
let header: CollectiblesCollectionViewHeader = collectionView.dequeueReusableSupplementaryView(ofKind: kind, for: indexPath) |
|
|
|
@ -606,9 +635,14 @@ extension TokensViewController: UICollectionViewDataSource { |
|
|
|
|
extension TokensViewController: UICollectionViewDelegate { |
|
|
|
|
public func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { |
|
|
|
|
collectiblesCollectionView.deselectItem(at: indexPath, animated: true) |
|
|
|
|
let token = viewModel.item(for: indexPath.item, section: indexPath.section) |
|
|
|
|
|
|
|
|
|
switch viewModel.item(for: indexPath.item, section: indexPath.section) { |
|
|
|
|
case .rpcServer: |
|
|
|
|
break |
|
|
|
|
case .tokenObject(let token): |
|
|
|
|
delegate?.didSelect(token: token, in: self) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
extension TokensViewController: UISearchResultsUpdating { |
|
|
|
@ -666,20 +700,13 @@ extension TokensViewController { |
|
|
|
|
navigationItem.hidesSearchBarWhenScrolling = true |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private func fixTableViewBackgroundColor() { |
|
|
|
|
let v = UIView() |
|
|
|
|
v.backgroundColor = viewModel.backgroundColor |
|
|
|
|
tableView.backgroundView?.backgroundColor = viewModel.backgroundColor |
|
|
|
|
tableView.backgroundView = v |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private func fixNavigationBarAndStatusBarBackgroundColorForiOS13Dot1() { |
|
|
|
|
view.superview?.backgroundColor = viewModel.backgroundColor |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private func setupFilteringWithKeyword() { |
|
|
|
|
wireUpSearchController() |
|
|
|
|
fixTableViewBackgroundColor() |
|
|
|
|
TokensViewController.functional.fixTableViewBackgroundColor(tableView: tableView, backgroundColor: viewModel.backgroundColor) |
|
|
|
|
doNotDimTableViewToReuseTableForFilteringResult() |
|
|
|
|
makeSwitchToAnotherTabWorkWhileFiltering() |
|
|
|
|
} |
|
|
|
@ -710,12 +737,15 @@ extension TokensViewController: ShowAddHideTokensViewDelegate { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
extension UIBarButtonItem { |
|
|
|
|
static func qrCodeBarButton(_ target: AnyObject, selector: Selector) -> UIBarButtonItem { |
|
|
|
|
return .init(image: R.image.qr_code_icon(), style: .plain, target: target, action: selector) |
|
|
|
|
} |
|
|
|
|
extension TokensViewController { |
|
|
|
|
class functional {} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static func addBarButton(_ target: AnyObject, selector: Selector) -> UIBarButtonItem { |
|
|
|
|
return .init(image: R.image.add_hide_tokens(), style: .plain, target: target, action: selector) |
|
|
|
|
extension TokensViewController.functional { |
|
|
|
|
static func fixTableViewBackgroundColor(tableView: UITableView, backgroundColor: UIColor) { |
|
|
|
|
let v = UIView() |
|
|
|
|
v.backgroundColor = backgroundColor |
|
|
|
|
tableView.backgroundView?.backgroundColor = backgroundColor |
|
|
|
|
tableView.backgroundView = v |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|