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

MOB-452 : add cta button to submit trades #139

Merged
merged 9 commits into from
Apr 12, 2024

Conversation

mike-dydx
Copy link
Contributor

@mike-dydx mike-dydx commented Apr 10, 2024

Links (dYdX Internal Use Only)

Linear Ticket: MOB-452 : add cta button to submit trades

Figma Design: https://www.figma.com/file/mKevZOfE9nj6MZpiolKYW1/dYdX-%E2%80%BA-Mobile?type=design&node-id=5621-13681&mode=design&t=yQplL4xfSnUqF508-4


Description / Intuition

  • adds cta button to tl/sp screen
  • adds logic to display in-line errors with correct text
  • adds logic to enable/disable the button based on validation errors
  • hooks up new submit order action (note this is not working e2e because of v4 bug w/ collat checks)

Before/After Screenshots or Videos

Before After
Untitled.mov

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Refactoring or Technical Debt
  • Documentation update
  • Other (please describe: )

Copy link

linear bot commented Apr 10, 2024

self?.updateValidationErrors(errors)
.sink { [weak self] triggerOrdersInput, errors in
#if DEBUG
if let triggerOrdersInput {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will remove this in the future

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🐞

@mike-dydx mike-dydx requested a review from ruixhuang April 10, 2024 21:30
Comment on lines 135 to 160
private func update(triggerOrdersInput: TriggerOrdersInput?, errors: [ValidationError]) {

viewModel?.takeProfitStopLossInputAreaViewModel?.takeProfitAlert = nil
viewModel?.takeProfitStopLossInputAreaViewModel?.stopLossAlert = nil

for error in errors {
let alert = InlineAlertViewModel(.init(title: error.resources.title?.localized, body: error.resources.text?.localized, level: .error))
switch error.code {
case "TRIGGER_MUST_ABOVE_INDEX_PRICE":
print("mmm: \(error)")
if triggerOrdersInput?.stopLossOrder?.side == .buy {
viewModel?.takeProfitStopLossInputAreaViewModel?.stopLossAlert = alert
}
if triggerOrdersInput?.takeProfitOrder?.side == .sell {
viewModel?.takeProfitStopLossInputAreaViewModel?.takeProfitAlert = alert
}
case "TRIGGER_MUST_BELOW_INDEX_PRICE":
print("mmm: \(error)")
if triggerOrdersInput?.stopLossOrder?.side == .sell {
viewModel?.takeProfitStopLossInputAreaViewModel?.stopLossAlert = alert
}
if triggerOrdersInput?.takeProfitOrder?.side == .buy {
viewModel?.takeProfitStopLossInputAreaViewModel?.takeProfitAlert = alert
}
default:
print("mmm: ", error.code)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ruixhuang here is the error display logic

@mike-dydx mike-dydx enabled auto-merge (squash) April 12, 2024 01:09
if let error = errors.first {
viewModel?.submissionReadiness = .fixErrors(cta: error.resources.action?.localized)
} else if triggerOrdersInput?.takeProfitOrder?.price?.triggerPrice?.doubleValue == nil
&& triggerOrdersInput?.takeProfitOrder?.orderId == nil
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not doing this check on Android. It seems to ready for submission if there is no ValidationError.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

went over this with mulan today, without this check, the "Add triggers" button is enabled even with empty input. I don't think that is great UX, what do you think?

We discussed adding something to abacus like containsChanges to denote whether that button should be enabled or not, even with no errors

let alert = InlineAlertViewModel(.init(title: error.resources.title?.localized, body: error.resources.text?.localized, level: .error))
switch error.code {
case "TRIGGER_MUST_ABOVE_INDEX_PRICE":
print("mmm: \(error)")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI, the "error.fields" should now contains the TriggerOrdersInputField where the error occurs.. It's probably easier to check for that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 i will do that in a follow up PR

let buttonState: PlatformButtonState
switch submissionReadiness {
case .readyToSubmit:
buttonText = DataLocalizer.shared?.localize(path: "APP.TRADE.ADD_TRIGGERS", params: nil) ?? ""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'd also need an "Edit Trigger" in addition to "Add Trigger".

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will add

@mike-dydx mike-dydx merged commit 1fecc2e into develop Apr 12, 2024
2 checks passed
@mike-dydx mike-dydx deleted the mike/mob-452-add-cta-button-to-submit-trades branch April 12, 2024 02:12
mike-dydx added a commit that referenced this pull request Aug 20, 2024
* bump 1.6.36 -> 1.6.38

* some ui

* add label accessory to platform input, split out input views into view models

* clean up

* add cta button

* hook up button and button states

* abacus?

* clean up

* add case handling for USER_MAX_ORDERS
mike-dydx added a commit that referenced this pull request Aug 21, 2024
* bump 1.6.36 -> 1.6.38

* some ui

* add label accessory to platform input, split out input views into view models

* clean up

* add cta button

* hook up button and button states

* abacus?

* clean up

* add case handling for USER_MAX_ORDERS
mike-dydx added a commit that referenced this pull request Aug 21, 2024
* bump 1.6.36 -> 1.6.38

* some ui

* add label accessory to platform input, split out input views into view models

* clean up

* add cta button

* hook up button and button states

* abacus?

* clean up

* add case handling for USER_MAX_ORDERS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants