Skip to content

Commit

Permalink
Merge branch 'swiftformat/feature/pwn-629' into release/2.10.0
Browse files Browse the repository at this point in the history
# Conflicts:
#	p2p_wallet/Scenes/TabBar/TabBarCoordinator.swift
  • Loading branch information
bigearsenal committed Jan 2, 2024
2 parents 37a81b7 + 969809b commit 8f8eb17
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 140 deletions.
37 changes: 0 additions & 37 deletions p2p_wallet/Scenes/TabBar/CustomTabBar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,6 @@ import Combine
import UIKit

final class CustomTabBar: UITabBar {
private lazy var middleButton: UIButton! = {
let middleButton = UIButton()
middleButton.frame.size = CGSize(width: 60, height: 60)
middleButton.backgroundColor = .init(resource: .snow)
middleButton.layer.cornerRadius = 30
middleButton.setImage(UIImage(resource: .tabBarCenter), for: .normal)
middleButton.setImage(UIImage(resource: .tabBarCenter), for: .highlighted)
middleButton.imageView?.contentMode = .scaleAspectFit
middleButton.contentHorizontalAlignment = .fill
middleButton.contentVerticalAlignment = .fill
middleButton.addTarget(self, action: #selector(middleButtonAction), for: .touchUpInside)
addSubview(middleButton)
return middleButton
}()

private lazy var selectedView: UIView! = {
let selectedView = UIView()
selectedView.frame.size = CGSize(width: 36, height: 4)
Expand All @@ -40,22 +25,9 @@ final class CustomTabBar: UITabBar {
return 14
}

override var clipsToBounds: Bool {
didSet {
middleButton.clipsToBounds = false
}
}

private let middleButtonClickedSubject = PassthroughSubject<Void, Never>()
var middleButtonClicked: AnyPublisher<Void, Never> { middleButtonClickedSubject.eraseToAnyPublisher() }

override func layoutSubviews() {
super.layoutSubviews()

middleButton.center = CGPoint(
x: frame.width / 2,
y: frame.height / 2 - Self.additionalHeight - inset
)
updateSelectedViewPositionIfNeeded()

layer.shadowColor = UIColor(red: 0.043, green: 0.122, blue: 0.208, alpha: 0.1).cgColor
Expand Down Expand Up @@ -85,15 +57,6 @@ final class CustomTabBar: UITabBar {

// MARK: - Actions

@objc func middleButtonAction() {
middleButtonClickedSubject.send()
}

override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {
guard !clipsToBounds, !isHidden, alpha > 0 else { return nil }
return middleButton.frame.contains(point) ? middleButton : super.hitTest(point, with: event)
}

func updateSelectedViewPositionIfNeeded() {
guard let currentIndex = currentIndex else { return }
let buttons = subviews.compactMap { NSStringFromClass(type(of: $0)) == "UITabBarButton" ? $0 : nil }
Expand Down
44 changes: 7 additions & 37 deletions p2p_wallet/Scenes/TabBar/TabBarController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ final class TabBarController: UITabBarController {

// MARK: - Publishers

var middleButtonClicked: AnyPublisher<Void, Never> { customTabBar.middleButtonClicked }
private let homeTabClickedTwicelySubject = PassthroughSubject<Void, Never>()
var homeTabClickedTwicely: AnyPublisher<Void, Never> { homeTabClickedTwicelySubject.eraseToAnyPublisher() }
private let jupiterSwapClickedSubject = PassthroughSubject<Void, Never>()
Expand Down Expand Up @@ -265,28 +264,6 @@ final class TabBarController: UITabBarController {
.map { $0 == nil }
.assignWeak(to: \.isHidden, on: blurEffectView)
.store(in: &subscriptions)

// Crypto alert on/off
viewModel.transferAccountsPublisher
.removeDuplicates()
.receive(on: DispatchQueue.main)
.sink { [weak self] claimableTransferExist in
let image: ImageResource = claimableTransferExist ? .tabBarCryptoWithAlert : .tabBarCrypto
let selectedImage: ImageResource = claimableTransferExist ? .selectedTabBarCryptoWithAlert :
.tabBarCrypto
self?.viewControllers?[TabItem.crypto.rawValue].tabBarItem.image = .init(resource: image)
self?.viewControllers?[TabItem.crypto.rawValue].tabBarItem
.selectedImage = .init(resource: selectedImage)
}
.store(in: &subscriptions)

// Wallet balance
viewModel.walletBalancePublisher
.receive(on: DispatchQueue.main)
.sink { [weak self] balanceString in
self?.viewControllers?[TabItem.wallet.rawValue].tabBarItem.title = balanceString
}
.store(in: &subscriptions)
}
}

Expand All @@ -304,18 +281,15 @@ extension TabBarController: UITabBarControllerDelegate {
if let tabItem = TabItem(rawValue: selectedIndex) {
switch tabItem {
case .wallet:
viewModel.walletTapped()
viewModel.cryptoTapped()

if (viewController as! UINavigationController).viewControllers.count == 1,
self.selectedIndex == selectedIndex
{
homeTabClickedTwicelySubject.send()
}
case .crypto:
viewModel.cryptoTapped()
case .send:
viewModel.sendTapped()
return false
case .swap:
viewModel.swapTapped()
case .history:
viewModel.historyTapped()
case .settings:
Expand All @@ -335,11 +309,9 @@ private extension TabItem {
var image: ImageResource? {
switch self {
case .wallet:
return .tabBarWallet
case .crypto:
return .tabBarCrypto
case .send:
return nil
case .swap:
return .tabBarSwap
case .history:
return .tabBarHistory
case .settings:
Expand All @@ -350,11 +322,9 @@ private extension TabItem {
var displayTitle: String {
switch self {
case .wallet:
return ""
case .crypto:
return L10n.crypto
case .send:
return L10n.send
case .swap:
return L10n.swap
case .history:
return L10n.history
case .settings:
Expand Down
64 changes: 22 additions & 42 deletions p2p_wallet/Scenes/TabBar/TabBarCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,15 @@ final class TabBarCoordinator: Coordinator<Void> {
/// Start coordinator
override func start() -> AnyPublisher<Void, Never> {
// set up tabs
let firstTab = setUpHome()
let (secondTab, thirdTab) = setupCryptoAndHistory()
let secondTab = setUpSwap()
let (firstTab, thirdTab) = setupCryptoAndHistory()
let forthTab = setUpSettings()

// set viewcontrollers
tabBarController.setViewControllers(
[
firstTab,
secondTab,
UINavigationController(),
thirdTab,
forthTab,
],
Expand Down Expand Up @@ -110,7 +109,6 @@ final class TabBarCoordinator: Coordinator<Void> {
}
.store(in: &subscriptions)

listenToSendButton()
listenToWallet()
}

Expand Down Expand Up @@ -156,6 +154,26 @@ final class TabBarCoordinator: Coordinator<Void> {
return (cryptoNavigation, historyNavigation)
}

/// Set up Swap scene
private func setUpSwap() -> UIViewController {
let nc = UINavigationController()
let swapCoordinator = JupiterSwapCoordinator(
navigationController: nc,
params: JupiterSwapParameters(
dismissAfterCompletion: false,
openKeyboardOnStart: false,
source: .actionPanel,
hideTabBar: false
)
)
jupiterSwapTabCoordinator = swapCoordinator
// coordinate to homeCoordinator
coordinate(to: swapCoordinator)
.sink(receiveValue: {})
.store(in: &subscriptions)
return nc
}

/// Set up Settings scene
private func setUpSettings() -> UIViewController {
let settingsNavigation = UINavigationController()
Expand All @@ -166,44 +184,6 @@ final class TabBarCoordinator: Coordinator<Void> {
return settingsNavigation
}

/// Listen to Send Button
private func listenToSendButton() {
tabBarController.middleButtonClicked
.receive(on: RunLoop.main)
.compactMap { [weak self] in
self?.navigationControllerForSelectedTab()
}
.flatMap { [unowned self] navigationController -> AnyPublisher<SendResult, Never> in
self.coordinate(
to: SendCoordinator(
rootViewController: navigationController,
preChosenWallet: nil,
hideTabBar: true,
allowSwitchingMainAmountType: true
)
)
}
.receive(on: RunLoop.main)
.sink(receiveValue: { [weak self] result in
guard let navigationController = self?.navigationControllerForSelectedTab() else {
return
}
switch result {
case let .sent(model):
navigationController.popToRootViewController(animated: true)
self?.showSendTransactionStatus(navigationController: navigationController, model: model)
case let .wormhole(trx):
navigationController.popToRootViewController(animated: true)
self?.showUserAction(userAction: trx)
case .sentViaLink:
navigationController.popToRootViewController(animated: true)
case .cancelled:
break
}
})
.store(in: &subscriptions)
}

private func listenToWallet() {
userWalletManager.$wallet
.sink { [weak self] wallet in
Expand Down
24 changes: 2 additions & 22 deletions p2p_wallet/Scenes/TabBar/TabBarViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ final class TabBarViewModel {
analyticsManager.log(event: .mainScreenCryptoClick)
}

func sendTapped() {
analyticsManager.log(event: .mainScreenSendClick)
func swapTapped() {
analyticsManager.log(event: .mainScreenSwapBar)
}

func historyTapped() {
Expand Down Expand Up @@ -167,24 +167,4 @@ extension TabBarViewModel {
}
.eraseToAnyPublisher()
}

var walletBalancePublisher: AnyPublisher<String, Never> {
solanaAccountsService.statePublisher
.map { (state: AsyncValueState<[SolanaAccountsService.Account]>) -> String in
let equityValue: CurrencyAmount = state.value
.filter { $0.token.keyAppExtensions.isPositionOnWS ?? false }
.filter { $0.token.keyAppExtensions.calculationOfFinalBalanceOnWS ?? true }
.reduce(CurrencyAmount(usd: 0)) {
$0 + $1.amountInFiat
}
let formatter = CurrencyFormatter(
showSpacingAfterCurrencySymbol: false,
showSpacingAfterCurrencyGroup: false,
showSpacingAfterLessThanOperator: false
)
return formatter.string(amount: equityValue)
}
.receive(on: RunLoop.main)
.eraseToAnyPublisher()
}
}
3 changes: 1 addition & 2 deletions p2p_wallet/Scenes/TabBar/TabItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import UIKit

enum TabItem: Int, CaseIterable {
case wallet = 0
case crypto
case send
case swap
case history
case settings
}

0 comments on commit 8f8eb17

Please sign in to comment.