Skip to content

Commit

Permalink
add hyperlink to receipt view
Browse files Browse the repository at this point in the history
  • Loading branch information
mike-dydx committed Mar 29, 2024
1 parent 9642cb1 commit 0d39e6c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,18 +75,32 @@ class dydxValidationViewPresenter: HostedViewPresenter<dydxValidationViewModel>,
let errorMessage = transferInput?.errorMessage
let firstBlockingError = errors.first { $0.type == ErrorType.error }
let firstWarning = errors.first { $0.type == ErrorType.warning }
viewModel?.hyperlink = .init(hyperlink: transferInput?.hyperlink)
if let firstBlockingError = firstBlockingError {
viewModel?.title = firstBlockingError.resources.title?.localizedString
viewModel?.text = firstBlockingError.resources.text?.localizedString
viewModel?.errorType = .error
if let hyperlinkText = firstBlockingError.linkText,
let link = firstBlockingError.link {
viewModel?.hyperlinkText = firstBlockingError.linkText
viewModel?.validationViewDescriptionHyperlinkAction = {
Router.shared?.navigate(to: URL(string: link), completion: nil)
}
}
if viewModel?.state == .hide {
viewModel?.state = .showError
}
} else if let firstWarning = firstWarning {
viewModel?.title = firstWarning.resources.title?.localizedString
viewModel?.text = firstWarning.resources.text?.localizedString
viewModel?.errorType = .warning
viewModel?.hyperlinkText = firstWarning.linkText
if let hyperlinkText = firstWarning.linkText,
let link = firstWarning.link {
viewModel?.hyperlinkText = firstWarning.linkText
viewModel?.validationViewDescriptionHyperlinkAction = {
Router.shared?.navigate(to: URL(string: link), completion: nil)
}
}
if viewModel?.state == .hide {
viewModel?.state = .showError
}
Expand All @@ -103,13 +117,3 @@ class dydxValidationViewPresenter: HostedViewPresenter<dydxValidationViewModel>,
}
}
}

extension dydxValidationViewModel.Hyperlink {
init?(hyperlink: TransferInputHyperlink?) {
if let text = hyperlink?.label, let url = hyperlink?.url {
self.init(text: text, url: url)
} else {
return nil
}
}
}
23 changes: 9 additions & 14 deletions dydx/dydxViews/dydxViews/_v4/Receipt/dydxValidationView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import SwiftUI
import PlatformUI
import Utilities
import RoutingKit

public class dydxValidationViewModel: PlatformViewModel {
public enum ErrorType {
Expand Down Expand Up @@ -39,22 +40,13 @@ public class dydxValidationViewModel: PlatformViewModel {
}
}

public struct Hyperlink {
public let text: String
public let url: String

public init(text: String, url: String) {
self.text = text
self.url = url
}
}

@Published public var title: String?
@Published public var text: String?
@Published public var state: State = .hide
@Published public var hyperlink: Hyperlink?
@Published public var hyperlinkText: String?
@Published public var errorType: ErrorType = .error
@Published public var receiptViewModel: dydxReceiptViewModel? = dydxReceiptViewModel()
@Published public var validationViewDescriptionHyperlinkAction: (() -> Void)?

public init() { }

Expand Down Expand Up @@ -124,18 +116,21 @@ public class dydxValidationViewModel: PlatformViewModel {
.frame(minWidth: 0)
case .showError:
ScrollView(showsIndicators: false) {
VStack(spacing: 8) {
VStack(alignment: .leading, spacing: 8) {
Text(self.text ?? "")
.themeFont(fontType: .base, fontSize: .medium)
.themeColor(foreground: .textTertiary)
Text(self.hyperlink?.text ?? "")
Text(DataLocalizer.localize(path: self.hyperlinkText ?? ""))
.themeFont(fontType: .base, fontSize: .medium)
.themeColor(foreground: .textSecondary)
.onTapGesture { [weak self] in
self?.validationViewDescriptionHyperlinkAction?()
}
}
}
.frame(height: 132)
}
}.animation(.default, value: self.state)
}.animation(.default)

)
}
Expand Down

0 comments on commit 0d39e6c

Please sign in to comment.