Skip to content

Commit

Permalink
disabled state for withdraw/deposit buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
mike-dydx committed Oct 17, 2024
1 parent 347048a commit 2d54349
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,6 @@ private class dydxVaultViewBuilderPresenter: HostedViewPresenter<dydxVaultViewMo

viewModel = dydxVaultViewModel()
viewModel?.vaultChart = dydxVaultChartViewModel()

viewModel?.depositAction = { Router.shared?.navigate(to: RoutingRequest(path: "/vault/deposit"), animated: true, completion: nil) }
viewModel?.withdrawAction = {
Router.shared?.navigate(to: RoutingRequest(path: "/vault/withdraw"), animated: true, completion: nil)
}
}

override func start() {
Expand All @@ -76,6 +71,18 @@ private class dydxVaultViewBuilderPresenter: HostedViewPresenter<dydxVaultViewMo
})
.store(in: &subscriptions)
}

AbacusStateManager.shared.state.onboarded
.sink { [weak self] onboarded in
if onboarded {
self?.viewModel?.depositAction = { Router.shared?.navigate(to: RoutingRequest(path: "/vault/deposit"), animated: true, completion: nil) }
self?.viewModel?.withdrawAction = { Router.shared?.navigate(to: RoutingRequest(path: "/vault/withdraw"), animated: true, completion: nil) }
} else {
self?.viewModel?.depositAction = nil
self?.viewModel?.withdrawAction = nil
}
}
.store(in: &subscriptions)
}

private func updateState(vault: Abacus.Vault?, assetMap: [String: Asset], marketMap: [String: PerpetualMarket]) {
Expand Down
40 changes: 18 additions & 22 deletions dydx/dydxViews/dydxViews/_v4/Vault/Landing/dydxVaultViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -265,34 +265,30 @@ private struct dydxVaultView: View {
// MARK: Floating Buttons
@ViewBuilder
private var withdrawButton: some View {
if let withdrawAction = viewModel.withdrawAction {
let content = Text(localizerPathKey: "APP.GENERAL.WITHDRAW")
.themeFont(fontType: .plus, fontSize: .medium)
.themeColor(foreground: .textPrimary)
.wrappedViewModel
let content = Text(localizerPathKey: "APP.GENERAL.WITHDRAW")
.themeFont(fontType: .plus, fontSize: .medium)
.themeColor(foreground: viewModel.withdrawAction == nil ? .textTertiary : .textPrimary)
.wrappedViewModel

PlatformButtonViewModel(content: content,
type: .defaultType(),
state: .secondary,
action: withdrawAction)
.createView()
}
PlatformButtonViewModel(content: content,
type: .defaultType(),
state: viewModel.withdrawAction == nil ? .disabled : .secondary,
action: { viewModel.withdrawAction?() })
.createView()
}

@ViewBuilder
private var depositButton: some View {
if let depositAction = viewModel.depositAction {
let content = Text(localizerPathKey: "APP.GENERAL.DEPOSIT")
.themeFont(fontType: .plus, fontSize: .medium)
.themeColor(foreground: .textPrimary)
.wrappedViewModel
let content = Text(localizerPathKey: "APP.GENERAL.DEPOSIT")
.themeFont(fontType: .plus, fontSize: .medium)
.themeColor(foreground: viewModel.depositAction == nil ? .textTertiary : .textPrimary)
.wrappedViewModel

PlatformButtonViewModel(content: content,
type: .defaultType(),
state: .primary,
action: depositAction)
.createView()
}
PlatformButtonViewModel(content: content,
type: .defaultType(),
state: viewModel.depositAction == nil ? .disabled : .primary,
action: { viewModel.depositAction?() })
.createView()
}

private var buttonStack: some View {
Expand Down

0 comments on commit 2d54349

Please sign in to comment.