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

[ETH-677] Remove tap to switch for all tokens and remake view a bit #1623

Merged
merged 1 commit into from
Jan 11, 2024
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 @@ -105,8 +105,7 @@ final class CryptoCoordinator: Coordinator<CryptoResult> {
to: SendCoordinator(
rootViewController: navigationController,
preChosenWallet: nil,
hideTabBar: true,
allowSwitchingMainAmountType: true
hideTabBar: true
)
)
.receive(on: RunLoop.main)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,7 @@ class NewHistoryCoordinator: SmartCoordinator<Void> {
category: .solanaAddress,
attributes: [.funds]
),
preChosenAmount: transaction.baseCurrencyAmount,
allowSwitchingMainAmountType: false
preChosenAmount: transaction.baseCurrencyAmount
))
.sink { _ in }
.store(in: &subscriptions)
Expand Down
3 changes: 1 addition & 2 deletions p2p_wallet/Scenes/Main/NewHome/HomeCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,7 @@ final class HomeCoordinator: Coordinator<Void> {
to: SendCoordinator(
rootViewController: navigationController,
preChosenWallet: nil,
hideTabBar: true,
allowSwitchingMainAmountType: true
hideTabBar: true
)
)
.receive(on: RunLoop.main)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,7 @@ final class SellPendingCoordinator: Coordinator<SellPendingCoordinatorResult> {
),
preChosenAmount: transaction.baseCurrencyAmount,
hideTabBar: true,
flow: .sell,
allowSwitchingMainAmountType: false
flow: .sell
))
}
.sink { [weak self] res in
Expand Down
4 changes: 0 additions & 4 deletions p2p_wallet/Scenes/Main/Send/Input/SendInputCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ final class SendInputCoordinator: Coordinator<SendResult> {
private var subject = PassthroughSubject<SendResult, Never>()
private let flow: SendFlow
private let pushedWithoutRecipientSearchView: Bool
private let allowSwitchingMainAmountType: Bool

private let sendViaLinkSeed: String?

Expand All @@ -24,7 +23,6 @@ final class SendInputCoordinator: Coordinator<SendResult> {
navigationController: UINavigationController,
flow: SendFlow,
pushedWithoutRecipientSearchView: Bool = false,
allowSwitchingMainAmountType: Bool,
sendViaLinkSeed: String? = nil
) {
self.recipient = recipient
Expand All @@ -33,7 +31,6 @@ final class SendInputCoordinator: Coordinator<SendResult> {
self.navigationController = navigationController
self.flow = flow
self.pushedWithoutRecipientSearchView = pushedWithoutRecipientSearchView
self.allowSwitchingMainAmountType = allowSwitchingMainAmountType
self.sendViaLinkSeed = sendViaLinkSeed
}

Expand All @@ -43,7 +40,6 @@ final class SendInputCoordinator: Coordinator<SendResult> {
preChosenWallet: preChosenWallet,
preChosenAmount: preChosenAmount,
flow: flow,
allowSwitchingMainAmountType: allowSwitchingMainAmountType,
sendViaLinkSeed: sendViaLinkSeed
)
let view = SendInputView(viewModel: viewModel)
Expand Down
7 changes: 1 addition & 6 deletions p2p_wallet/Scenes/Main/Send/Input/SendInputView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -176,12 +176,8 @@ struct SendInputView: View {
animated: .default
)
}
Image(.arrowUpDown)
.renderingMode(.template)
.foregroundColor(Color(.rain))
.frame(width: 16, height: 16)
}
.padding(EdgeInsets(top: 21, leading: 24, bottom: 21, trailing: 12))
.padding(EdgeInsets(top: 21, leading: 24, bottom: 21, trailing: 24))
.background(RoundedRectangle(cornerRadius: 12).fill(Color(.snow)))
.frame(height: 90)
}
Expand Down Expand Up @@ -246,7 +242,6 @@ struct SendInputView_Previews: PreviewProvider {
preChosenWallet: nil,
preChosenAmount: nil,
flow: .send,
allowSwitchingMainAmountType: false,
sendViaLinkSeed: nil
)
)
Expand Down
25 changes: 0 additions & 25 deletions p2p_wallet/Scenes/Main/Send/Input/SendInputViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ final class SendInputViewModel: BaseViewModel, ObservableObject {
private let flow: SendFlow
private var wasMaxWarningToastShown: Bool = false
private let preChosenAmount: Double?
private let allowSwitchingMainAmountType: Bool

// MARK: - Dependencies

Expand All @@ -98,12 +97,10 @@ final class SendInputViewModel: BaseViewModel, ObservableObject {
preChosenWallet: SolanaAccount?,
preChosenAmount: Double?,
flow: SendFlow,
allowSwitchingMainAmountType: Bool,
sendViaLinkSeed: String?
) {
self.flow = flow
self.preChosenAmount = preChosenAmount
self.allowSwitchingMainAmountType = allowSwitchingMainAmountType

let repository = Resolver.resolve(SolanaAccountsService.self)
let wallets = repository.getWallets()
Expand Down Expand Up @@ -398,32 +395,10 @@ private extension SendInputViewModel {
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) { self?.openKeyboard() }
}
.store(in: &subscriptions)

$sourceWallet.eraseToAnyPublisher()
.sink { [weak self] currentWallet in
guard let self else { return }
if currentWallet.price == nil {
self.turnOffInputSwitch()
}
// else if
// currentWallet.isUsdcOrUsdt, currentWallet.price?.value == 1.0
// {
// self.turnOffInputSwitch()
// }
else {
self.inputAmountViewModel.isSwitchAvailable = self.allowSwitchingMainAmountType
}
}
.store(in: &subscriptions)
}
}

private extension SendInputViewModel {
func turnOffInputSwitch() {
inputAmountViewModel.mainAmountType = .token
inputAmountViewModel.isSwitchAvailable = false
}

func updateInputAmountView() {
guard currentState.amountInToken != .zero else {
inputAmountViewModel.isError = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ final class SendInputAmountViewModel: BaseViewModel, ObservableObject {
@Published var amountText: String = ""
@Published var amountTextColor: UIColor = .init(resource: .night)
@Published var mainTokenText = ""
@Published var mainAmountType: EnteredAmountType = Defaults.isTokenInputTypeChosen ? .token : .fiat
@Published var mainAmountType: EnteredAmountType = .token // Can't switch, can't remember Defaults.isTokenInputTypeChosen ? .token : .fiat
@Published var isMaxButtonVisible: Bool = true

@Published var secondaryAmountText = ""
Expand All @@ -53,7 +53,7 @@ final class SendInputAmountViewModel: BaseViewModel, ObservableObject {
@Published var amount: Amount?
@Published var isError: Bool = false
@Published var countAfterDecimalPoint: Int
@Published var isSwitchAvailable: Bool = true
@Published var isSwitchAvailable = false // Switch is cancelled

private let fiat: Fiat = Defaults.fiat
private var currentText: String?
Expand Down
12 changes: 3 additions & 9 deletions p2p_wallet/Scenes/Main/Send/SendСoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ final class SendCoordinator: Coordinator<SendResult> {
let preChosenWallet: SolanaAccount?
let preChosenRecipient: Recipient?
let preChosenAmount: Double?
let allowSwitchingMainAmountType: Bool

// MARK: - Initializer

Expand All @@ -47,16 +46,14 @@ final class SendCoordinator: Coordinator<SendResult> {
preChosenRecipient: Recipient? = nil,
preChosenAmount: Double? = nil,
hideTabBar: Bool = false,
flow: SendFlow = .send,
allowSwitchingMainAmountType: Bool
flow: SendFlow = .send
) {
self.rootViewController = rootViewController
self.preChosenWallet = preChosenWallet
self.preChosenRecipient = preChosenRecipient
self.preChosenAmount = preChosenAmount
self.hideTabBar = hideTabBar
self.flow = flow
self.allowSwitchingMainAmountType = allowSwitchingMainAmountType
super.init()
}

Expand Down Expand Up @@ -91,8 +88,7 @@ final class SendCoordinator: Coordinator<SendResult> {
preChosenAmount: preChosenAmount,
navigationController: rootViewController,
flow: flow,
pushedWithoutRecipientSearchView: true,
allowSwitchingMainAmountType: allowSwitchingMainAmountType
pushedWithoutRecipientSearchView: true
))
.sink { [weak self] result in
switch result {
Expand Down Expand Up @@ -120,8 +116,7 @@ final class SendCoordinator: Coordinator<SendResult> {
preChosenWallet: preChosenWallet,
preChosenAmount: preChosenAmount,
navigationController: rootViewController,
flow: flow,
allowSwitchingMainAmountType: allowSwitchingMainAmountType
flow: flow
))
}
.sink { [weak self] result in
Expand Down Expand Up @@ -228,7 +223,6 @@ final class SendCoordinator: Coordinator<SendResult> {
preChosenAmount: preChosenAmount,
navigationController: rootViewController,
flow: .sendViaLink,
allowSwitchingMainAmountType: true,
sendViaLinkSeed: seed
))
.sink { [weak self] result in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,7 @@ class AccountDetailsCoordinator: SmartCoordinator<AccountDetailsCoordinatorResul
let coordinator = SendCoordinator(
rootViewController: rootViewController,
preChosenWallet: account,
hideTabBar: true,
allowSwitchingMainAmountType: true
hideTabBar: true
)

coordinate(to: coordinator)
Expand Down
26 changes: 13 additions & 13 deletions p2p_wallet/UI/SwiftUI/SendSubviews/SendInputAmountView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -91,21 +91,21 @@ struct SendInputAmountView: View {
.accessibilityIdentifier("current-currency")
}

if isSwitchMainAmountTypeAvailable {
HStack(spacing: 2) {
Text(secondaryAmountText)
.secondaryStyle()
HStack(spacing: 2) {
Text(secondaryAmountText)
.secondaryStyle()

Text(secondaryCurrencyText)
.secondaryStyle()
Text(secondaryCurrencyText)
.secondaryStyle()

Spacer()
Spacer()

Text(L10n.tapToSwitchTo(secondaryCurrencyText))
.secondaryStyle()
.opacity(switchAreaOpacity)
.layoutPriority(1)
}
// if isSwitchMainAmountTypeAvailable {
// Text(L10n.tapToSwitchTo(secondaryCurrencyText))
// .secondaryStyle()
// .opacity(switchAreaOpacity)
// .layoutPriority(1)
// }
}
}
if isSwitchMainAmountTypeAvailable {
Expand All @@ -122,7 +122,7 @@ struct SendInputAmountView: View {
.frame(width: 24, height: 24)
}
}
.padding(EdgeInsets(top: 21, leading: 24, bottom: 21, trailing: 12))
.padding(EdgeInsets(top: 21, leading: 24, bottom: 21, trailing: 24))
.background(RoundedRectangle(cornerRadius: 12))
.foregroundColor(Color(.snow))
}
Expand Down
Loading