-
Notifications
You must be signed in to change notification settings - Fork 2
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
unopened isolated positions pt1 #191
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
7a3211c
hide/show target leverage for margin mode selection
mike-dydx 01dc417
fix adjust margin % horizontal sizings
mike-dydx 256fb41
remove unused files
mike-dydx 6b67bee
dismiss on success, update button state on submission
mike-dydx 809983c
multi-line receipt line item title
mike-dydx 9377c16
use localized error
mike-dydx 9ff9773
stubbed unopened isolated positions UI
mike-dydx 7a3bf31
wire up abacus data for unopened positions
mike-dydx a7c34cd
put back fixed size, clean up
mike-dydx 53f7695
hide keyboard when margin direction changes
mike-dydx 65bfd3b
remove max action
mike-dydx 2f1ec61
add local validation
mike-dydx d512b0c
update button state after validation
mike-dydx 7f1587f
remove alternate validation
mike-dydx b9bd080
clean up
mike-dydx de39f47
ui tweaks
mike-dydx File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -80,16 +80,13 @@ private class dydxAdjustMarginInputViewPresenter: HostedViewPresenter<dydxAdjust | |
viewModel.amount?.onEdited = { amount in | ||
AbacusStateManager.shared.adjustIsolatedMargin(input: amount, type: .amount) | ||
} | ||
viewModel.amount?.maxAction = { | ||
AbacusStateManager.shared.adjustIsolatedMargin(input: "1", type: .amountpercent) | ||
} | ||
|
||
ctaButtonPresenter.viewModel?.ctaAction = { [weak self] in | ||
self?.ctaButtonPresenter.viewModel?.ctaButtonState = .thinking | ||
AbacusStateManager.shared.commitAdjustIsolatedMargin { [weak self] (_, error, _) in | ||
self?.ctaButtonPresenter.viewModel?.ctaButtonState = .disabled() | ||
if let error = error { | ||
self?.viewModel?.submissionError = InlineAlertViewModel(.init(title: nil, body: error.message, level: .error)) | ||
self?.viewModel?.inlineAlert = InlineAlertViewModel(.init(title: nil, body: error.localizedMessage, level: .error)) | ||
return | ||
} else { | ||
Router.shared?.navigate(to: RoutingRequest(path: "/action/dismiss"), animated: true, completion: nil) | ||
|
@@ -120,15 +117,8 @@ private class dydxAdjustMarginInputViewPresenter: HostedViewPresenter<dydxAdjust | |
self?.updateState(market: market, assetMap: assetMap) | ||
self?.updateFields(input: input) | ||
self?.updateForMarginDirection(input: input) | ||
self?.updatePrePostValues(input: input) | ||
self?.updatePrePostValues(input: input, market: market) | ||
self?.updateLiquidationPrice(input: input, market: market) | ||
self?.updateButtonState(input: input) | ||
} | ||
.store(in: &subscriptions) | ||
|
||
AbacusStateManager.shared.state.adjustIsolatedMarginInput | ||
.sink { [weak self] _ in | ||
self?.viewModel?.submissionError = nil | ||
} | ||
.store(in: &subscriptions) | ||
} | ||
|
@@ -149,10 +139,65 @@ private class dydxAdjustMarginInputViewPresenter: HostedViewPresenter<dydxAdjust | |
} | ||
} | ||
|
||
private func updatePrePostValues(input: AdjustIsolatedMarginInput) { | ||
// TODO: move this to abacus | ||
/// locally validates the input | ||
/// - Parameter input: input to validate | ||
/// - Returns: the localization error string key if invalid input | ||
private func validate(input: AdjustIsolatedMarginInput, market: PerpetualMarket) -> String? { | ||
guard let amount = parser.asNumber(input.amount)?.doubleValue else { return nil } | ||
switch input.type { | ||
case IsolatedMarginAdjustmentType.add: | ||
if let crossFreeCollateral = input.summary?.crossFreeCollateral?.doubleValue, amount >= crossFreeCollateral { | ||
return "ERRORS.TRANSFER_MODAL.TRANSFER_MORE_THAN_FREE" | ||
} | ||
if let crossMarginUsageUpdated = input.summary?.crossMarginUsageUpdated?.doubleValue, crossMarginUsageUpdated > 1 { | ||
return "ERRORS.TRADE_BOX.INVALID_NEW_ACCOUNT_MARGIN_USAGE" | ||
} | ||
case IsolatedMarginAdjustmentType.remove: | ||
if let freeCollateral = input.summary?.crossFreeCollateral?.doubleValue, amount >= freeCollateral { | ||
return "ERRORS.TRANSFER_MODAL.TRANSFER_MORE_THAN_FREE" | ||
} | ||
if let positionMarginUpdated = input.summary?.positionMarginUpdated?.doubleValue, positionMarginUpdated < 0 { | ||
return "ERRORS.TRADE_BOX.INVALID_NEW_ACCOUNT_MARGIN_USAGE" | ||
} | ||
if let effectiveInitialMarginFraction = market.configs?.effectiveInitialMarginFraction?.doubleValue, effectiveInitialMarginFraction > 0 { | ||
let marketMaxLeverage = 1 / effectiveInitialMarginFraction | ||
if let positionLeverageUpdated = input.summary?.positionLeverageUpdated?.doubleValue, positionLeverageUpdated > marketMaxLeverage { | ||
return "ERRORS.TRADE_BOX_TITLE.INVALID_NEW_POSITION_LEVERAGE" | ||
} | ||
} | ||
default: | ||
break | ||
} | ||
|
||
return nil | ||
} | ||
|
||
private func clearPostValues() { | ||
for receipt in [viewModel?.amountReceipt, viewModel?.buttonReceipt] { | ||
for item in receipt?.receiptChangeItems ?? [] { | ||
item.value.after = nil | ||
} | ||
} | ||
} | ||
|
||
private func updatePrePostValues(input: AdjustIsolatedMarginInput, market: PerpetualMarket) { | ||
var crossReceiptItems = [dydxReceiptChangeItemView]() | ||
var positionReceiptItems = [dydxReceiptChangeItemView]() | ||
|
||
if let errorStringKey = validate(input: input, market: market) { | ||
clearPostValues() | ||
viewModel?.inlineAlert = InlineAlertViewModel(InlineAlertViewModel.Config( | ||
title: nil, | ||
body: DataLocalizer.localize(path: errorStringKey), | ||
level: .error)) | ||
ctaButtonPresenter.viewModel?.ctaButtonState = .disabled() | ||
return | ||
} else { | ||
ctaButtonPresenter.viewModel?.ctaButtonState = .enabled() | ||
viewModel?.inlineAlert = nil | ||
} | ||
|
||
let crossFreeCollateral: AmountTextModel = .init(amount: input.summary?.crossFreeCollateral, unit: .dollar) | ||
let crossFreeCollateralUpdated: AmountTextModel = .init(amount: input.summary?.crossFreeCollateralUpdated, unit: .dollar) | ||
let crossFreeCollateralChange: AmountChangeModel = .init( | ||
|
@@ -225,14 +270,6 @@ private class dydxAdjustMarginInputViewPresenter: HostedViewPresenter<dydxAdjust | |
} | ||
} | ||
|
||
private func updateButtonState(input: AdjustIsolatedMarginInput) { | ||
if parser.asNumber(input.amount)?.doubleValue ?? 0 > 0 { | ||
self.ctaButtonPresenter.viewModel?.ctaButtonState = .enabled() | ||
} else { | ||
self.ctaButtonPresenter.viewModel?.ctaButtonState = .disabled() | ||
} | ||
} | ||
|
||
Comment on lines
-228
to
-235
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this was moved to validate fxn |
||
private func updateFields(input: AdjustIsolatedMarginInput) { | ||
viewModel?.amount?.value = dydxFormatter.shared.raw(number: parser.asNumber(input.amount), digits: 2) | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
per corey's guidance, removing max button