-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add dydxVaultDepositWithdrawConfirmation View and Presenter (#243)
add checkbox and alert to confirmation screen
- Loading branch information
Showing
16 changed files
with
539 additions
and
65 deletions.
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
BlackjackSim/BlackjackSim.xcodeproj/project.xcworkspace/contents.xcworkspacedata
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
42 changes: 42 additions & 0 deletions
42
PlatformUI/PlatformUI/Components/Extensions/AttributedString+Ext.swift
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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// | ||
// AttributedString+Ext.swift | ||
// PlatformUI | ||
// | ||
// Created by Michael Maguire on 9/9/24. | ||
// | ||
|
||
import Utilities | ||
|
||
public extension AttributedString { | ||
init(text: String, | ||
// localizerPathKeys mapped to the action to be performed when tapped | ||
hyperlinks: [String: String], | ||
foreground: ThemeColor.SemanticColor = .textPrimary | ||
) { | ||
var text = text | ||
for (key, url) in hyperlinks { | ||
let hyperlinkText = DataLocalizer.localize(path: key) | ||
// markdown supported as of iOS 15! | ||
text = text.replacingOccurrences(of: hyperlinkText, with: "[\(hyperlinkText)](\(url))") | ||
} | ||
var attributedString = (try? AttributedString(markdown: text)) ?? AttributedString(text) | ||
.themeColor(foreground: foreground) | ||
for run in attributedString.runs { | ||
if let _ = run.link { | ||
attributedString[run.range].underlineStyle = .single | ||
attributedString[run.range].foregroundColor = foreground.color // Change to any desired color | ||
} | ||
} | ||
self = attributedString | ||
} | ||
|
||
init(localizerPathKey: String, | ||
params: [String: String]? = nil, | ||
// localizerPathKeys mapped to the action to be performed when tapped | ||
hyperlinks: [String: String], | ||
foreground: ThemeColor.SemanticColor = .textPrimary | ||
) { | ||
var localizedText = DataLocalizer.localize(path: localizerPathKey, params: params) | ||
self.init(text: localizedText, hyperlinks: hyperlinks, foreground: foreground) | ||
} | ||
} |
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
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
105 changes: 105 additions & 0 deletions
105
...rs/_v4/Vault/DepositsAndWithdrawals/dydxVaultDepositWithdrawConfirmationViewBuilder.swift
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 |
---|---|---|
@@ -0,0 +1,105 @@ | ||
// | ||
// dydxVaultDepositWithdrawConfirmationViewBuilder.swift | ||
// dydxPresenters | ||
// | ||
// Created by Michael Maguire on 9/6/24. | ||
// | ||
|
||
import Utilities | ||
import dydxViews | ||
import PlatformParticles | ||
import RoutingKit | ||
import ParticlesKit | ||
import PlatformUI | ||
import dydxStateManager | ||
import FloatingPanel | ||
import PlatformRouting | ||
import dydxFormatter | ||
|
||
public class dydxVaultDepositWithdrawConfirmationViewBuilder: NSObject, ObjectBuilderProtocol { | ||
public func build<T>() -> T? { | ||
let presenter = dydxVaultDepositWithdrawConfirmationViewPresenter() | ||
let view = presenter.viewModel?.createView() ?? PlatformViewModel().createView() | ||
let viewController = dydxVaultDepositWithdrawConfirmationViewController(presenter: presenter, view: view, configuration: .default) | ||
return viewController as? T | ||
} | ||
} | ||
|
||
private class dydxVaultDepositWithdrawConfirmationViewController: HostingViewController<PlatformView, dydxVaultDepositWithdrawConfirmationViewModel> { | ||
|
||
override public func arrive(to request: RoutingRequest?, animated: Bool) -> Bool { | ||
let presenter = presenter as? dydxVaultDepositWithdrawConfirmationViewPresenterProtocol | ||
if request?.path == "/vault/deposit_confirm" { | ||
presenter?.transferType = .deposit | ||
return true | ||
} else if request?.path == "/vault/withdraw_confirm" { | ||
presenter?.transferType = .withdraw | ||
return true | ||
} else { | ||
return false | ||
} | ||
} | ||
} | ||
|
||
private protocol dydxVaultDepositWithdrawConfirmationViewPresenterProtocol: HostedViewPresenterProtocol { | ||
var viewModel: dydxVaultDepositWithdrawConfirmationViewModel? { get } | ||
var transferType: VaultTransferType { get set } | ||
} | ||
|
||
private class dydxVaultDepositWithdrawConfirmationViewPresenter: HostedViewPresenter<dydxVaultDepositWithdrawConfirmationViewModel>, dydxVaultDepositWithdrawConfirmationViewPresenterProtocol { | ||
var transferType: VaultTransferType = .deposit { | ||
didSet { | ||
viewModel?.transferType = transferType | ||
} | ||
} | ||
|
||
override init() { | ||
|
||
super.init() | ||
|
||
let viewModel = dydxVaultDepositWithdrawConfirmationViewModel(transferType: transferType) | ||
|
||
viewModel.cancelAction = { | ||
Router.shared?.navigate(to: RoutingRequest(path: "/action/dismiss"), animated: true, completion: nil) | ||
} | ||
|
||
//TODO: replace | ||
viewModel.elevatedSlippageAmount = 4.20 | ||
viewModel.requiresAcknowledgeHighSlippage = true | ||
|
||
self.viewModel = viewModel | ||
} | ||
|
||
override func start() { | ||
super.start() | ||
|
||
//TODO: replace with real hooks from abacus | ||
update() | ||
} | ||
|
||
//TODO: replace with real data from abacus | ||
func update() { | ||
let crossFreeCollateralReceiptItem = dydxReceiptChangeItemView(title: DataLocalizer.localize(path: "APP.GENERAL.CROSS_FREE_COLLATERAL"), | ||
value: AmountChangeModel(before: AmountTextModel(amount: 30.01), | ||
after: AmountTextModel(amount: 30.02))) | ||
let yourVaultBalanceReceiptItem = dydxReceiptChangeItemView(title: DataLocalizer.localize(path: "APP.VAULTS.YOUR_VAULT_BALANCE"), | ||
value: AmountChangeModel(before: AmountTextModel(amount: 30.01), | ||
after: AmountTextModel(amount: 30.02))) | ||
let estSlippageReceiptItem = dydxReceiptChangeItemView(title: DataLocalizer.localize(path: "APP.VAULTS.EST_SLIPPAGE"), | ||
value: AmountChangeModel(before: AmountTextModel(amount: 30.01), | ||
after: AmountTextModel(amount: 30.02))) | ||
let expectedAmountReceivedItem = dydxReceiptChangeItemView(title: DataLocalizer.localize(path: "APP.WITHDRAW_MODAL.EXPECTED_AMOUNT_RECEIVED"), | ||
value: AmountChangeModel(before: AmountTextModel(amount: 30.01), | ||
after: AmountTextModel(amount: 30.02))) | ||
let crossMarginUsageItem = dydxReceiptChangeItemView(title: DataLocalizer.localize(path: "APP.GENERAL.CROSS_MARGIN_USAGE"), | ||
value: AmountChangeModel(before: AmountTextModel(amount: 30.01), | ||
after: AmountTextModel(amount: 30.02))) | ||
|
||
switch transferType { | ||
case .deposit: | ||
viewModel?.receiptItems = [crossFreeCollateralReceiptItem, crossMarginUsageItem, yourVaultBalanceReceiptItem] | ||
case .withdraw: | ||
viewModel?.receiptItems = [crossFreeCollateralReceiptItem, yourVaultBalanceReceiptItem, estSlippageReceiptItem, expectedAmountReceivedItem] | ||
} | ||
} | ||
} |
Oops, something went wrong.