Skip to content

Commit

Permalink
fix memo (#283)
Browse files Browse the repository at this point in the history
* fix inputs

* update memo field and clients lib

* add file

* clean up

* addresss feedback

---------

Co-authored-by: Mike <[email protected]>
  • Loading branch information
mike-dydx and mike-dydx authored Oct 28, 2024
1 parent 4081de8 commit 8734148
Show file tree
Hide file tree
Showing 9 changed files with 5,817 additions and 4,305 deletions.
3 changes: 2 additions & 1 deletion PlatformUI/PlatformUI/Components/ComboBox/ComboBox.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,12 @@ public class ComboBoxModel: PlatformViewModel {
PlatformView(viewModel: self, parentStyle: parentStyle, styleKey: styleKey) { [weak self] style in
guard let self = self else { return AnyView(PlatformView.nilView) }

let main = VStack(alignment: .leading, spacing: 4) {
let main = VStack(alignment: .leading, spacing: 5) {
if let title = self.title {
Text(title)
.themeFont(fontSize: .smaller)
.themeColor(foreground: .textTertiary)

}

self.content?.createView(parentStyle: style)
Expand Down
9,749 changes: 5,562 additions & 4,187 deletions dydx/dydxPresenters/dydxPresenters/_Features/v4-native-client.js

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,8 @@ class dydxTransferInputCtaButtonViewPresenter: HostedViewPresenter<dydxTradeInpu
let payload: [String: Any] = [
"subaccountNumber": subaccountNumber,
"amount": amount,
"recipient": recipient
"recipient": recipient,
"memo": transferInput.memo as Any
]
if let paramsInJson = payload.jsonString {
CosmoJavascript.shared.call(functionName: "withdraw", paramsInJson: paramsInJson) { [weak self] result in
Expand All @@ -337,7 +338,8 @@ class dydxTransferInputCtaButtonViewPresenter: HostedViewPresenter<dydxTradeInpu
private func transferOutDYDX(amount: String, recipient: String, transferInput: TransferInput) {
let payload: [String: Any] = [
"amount": amount,
"recipient": recipient
"recipient": recipient,
"memo": transferInput.memo as Any
]
if let paramsInJson = payload.jsonString {
CosmoJavascript.shared.call(functionName: "transferNativeToken", paramsInJson: paramsInJson) { [weak self] result in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,6 @@ class dydxTransferOutViewPresenter: HostedViewPresenter<dydxTransferOutViewModel
override init() {
let viewModel = dydxTransferOutViewModel()

viewModel.chainsComboBox?.text = AbacusStateManager.shared.environment?.chainName
if let chainLogo = AbacusStateManager.shared.environment?.chainLogo, let url = URL(string: chainLogo) {
viewModel.chainsComboBox?.icon = PlatformIconViewModel(type: .url(url: url), size: CGSize(width: 32, height: 32))
}

validationPresenter.$viewModel.assign(to: &viewModel.$validationViewModel)
ctaButtonPresenter.$viewModel.assign(to: &viewModel.$ctaButton)

Expand All @@ -73,13 +68,21 @@ class dydxTransferOutViewPresenter: HostedViewPresenter<dydxTransferOutViewModel
}
}

viewModel.addressInput?.onEdited = { address in
AbacusStateManager.shared.transfer(input: address, type: .address)
}
viewModel.$addressInput
.debounce(for: .milliseconds(10), scheduler: DispatchQueue.main)
.removeDuplicates()
.sink(receiveValue: { address in
AbacusStateManager.shared.transfer(input: address, type: .address)
})
.store(in: &subscriptions)

viewModel.memoBox = .init { value in
AbacusStateManager.shared.transfer(input: value, type: .memo)
}
viewModel.memoBox.$text
.debounce(for: .milliseconds(10), scheduler: DispatchQueue.main)
.removeDuplicates()
.sink(receiveValue: { memo in
AbacusStateManager.shared.transfer(input: memo, type: .memo)
})
.store(in: &subscriptions)

self.viewModel = viewModel

Expand Down Expand Up @@ -157,10 +160,10 @@ class dydxTransferOutViewPresenter: HostedViewPresenter<dydxTransferOutViewModel
}
viewModel?.amountBox?.objectWillChange.send()

viewModel?.addressInput?.value = transferInput.address
viewModel?.addressInput = transferInput.address ?? ""

viewModel?.memoBox?.shouldDisplayWarningWhenEmpty = transferInput.token != dydxTokenConstants.usdcTokenKey
viewModel?.memoBox?.value = transferInput.memo
viewModel?.memoBox.shouldDisplayWarningWhenEmpty = transferInput.token != dydxTokenConstants.usdcTokenKey
viewModel?.memoBox.text = transferInput.memo ?? ""
}

private func updateChainsTokensViewModel() {
Expand All @@ -183,7 +186,6 @@ class dydxTransferOutViewPresenter: HostedViewPresenter<dydxTransferOutViewModel
Router.shared?.navigate(to: RoutingRequest(path: "/transfer/search", params: params), animated: true, completion: nil)
}
}
viewModel?.chainsComboBox = chainsComboBox
}

if tokens.count > 0 {
Expand Down
8 changes: 8 additions & 0 deletions dydx/dydxViews/dydxViews.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@
270BA8CF2A6F1470009212EA /* dydxDebugThemeViewerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 270BA8CE2A6F1470009212EA /* dydxDebugThemeViewerView.swift */; };
270E7E342A5F700B00136793 /* dydxOrderbookManagerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 270E7E332A5F700B00136793 /* dydxOrderbookManagerView.swift */; };
271010472BC7454B0037091A /* dydxCustomAmountViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 271010462BC7454B0037091A /* dydxCustomAmountViewModel.swift */; };
2718DF432CCC46D000C05DD8 /* dydxTitledContent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2718DF362CCC46CC00C05DD8 /* dydxTitledContent.swift */; };
272030182A7812B900D233B9 /* UINavigationController+SwipeBackNavigation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 272030172A7812B900D233B9 /* UINavigationController+SwipeBackNavigation.swift */; };
2728CE1B2BBCD2AB004C9323 /* dydxGainLossInputViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2728CE1A2BBCD2AB004C9323 /* dydxGainLossInputViewModel.swift */; };
2729123E2C06A775003F3EA0 /* Introspect in Frameworks */ = {isa = PBXBuildFile; productRef = 2729123D2C06A775003F3EA0 /* Introspect */; };
Expand Down Expand Up @@ -208,6 +209,7 @@
27C6E4C92BC8C30E00ED892A /* dydxCustomLimitPriceViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 27C6E4BC2BC8C30E00ED892A /* dydxCustomLimitPriceViewModel.swift */; };
27CDA3D42BBF1AD700FEAFFE /* dydxMultipleOrdersExistViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 27CDA3D32BBF1AD700FEAFFE /* dydxMultipleOrdersExistViewModel.swift */; };
27DBF3C92C4A05B9009EB2D6 /* dydxTitledNumberField.swift in Sources */ = {isa = PBXBuildFile; fileRef = 27DBF3C82C4A05B9009EB2D6 /* dydxTitledNumberField.swift */; };
27DFA53D2CCB1736005FCABB /* dydxTitledTextField.swift in Sources */ = {isa = PBXBuildFile; fileRef = 27DFA5302CCB1730005FCABB /* dydxTitledTextField.swift */; };
27E072D22C1A095C0034B963 /* dydxPortfolioPendingPositionsItemViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 27E072D12C1A095C0034B963 /* dydxPortfolioPendingPositionsItemViewModel.swift */; };
27E0736B2C20D27F0034B963 /* dydxCancelPendingIsolatedOrdersView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 27E0736A2C20D27F0034B963 /* dydxCancelPendingIsolatedOrdersView.swift */; };
27E3C3E82CA33673009AEFEC /* dydxMarketListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 27E3C3E72CA33673009AEFEC /* dydxMarketListView.swift */; };
Expand Down Expand Up @@ -554,6 +556,7 @@
270BA8CE2A6F1470009212EA /* dydxDebugThemeViewerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = dydxDebugThemeViewerView.swift; sourceTree = "<group>"; };
270E7E332A5F700B00136793 /* dydxOrderbookManagerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = dydxOrderbookManagerView.swift; sourceTree = "<group>"; };
271010462BC7454B0037091A /* dydxCustomAmountViewModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = dydxCustomAmountViewModel.swift; sourceTree = "<group>"; };
2718DF362CCC46CC00C05DD8 /* dydxTitledContent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = dydxTitledContent.swift; sourceTree = "<group>"; };
272030172A7812B900D233B9 /* UINavigationController+SwipeBackNavigation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UINavigationController+SwipeBackNavigation.swift"; sourceTree = "<group>"; };
2728CE1A2BBCD2AB004C9323 /* dydxGainLossInputViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = dydxGainLossInputViewModel.swift; sourceTree = "<group>"; };
2729F9E82C64093700769BA4 /* dydxMarketsBannerViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = dydxMarketsBannerViewModel.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -596,6 +599,7 @@
27C6E4BC2BC8C30E00ED892A /* dydxCustomLimitPriceViewModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = dydxCustomLimitPriceViewModel.swift; sourceTree = "<group>"; };
27CDA3D32BBF1AD700FEAFFE /* dydxMultipleOrdersExistViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = dydxMultipleOrdersExistViewModel.swift; sourceTree = "<group>"; };
27DBF3C82C4A05B9009EB2D6 /* dydxTitledNumberField.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = dydxTitledNumberField.swift; sourceTree = "<group>"; };
27DFA5302CCB1730005FCABB /* dydxTitledTextField.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = dydxTitledTextField.swift; sourceTree = "<group>"; };
27E072D12C1A095C0034B963 /* dydxPortfolioPendingPositionsItemViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = dydxPortfolioPendingPositionsItemViewModel.swift; sourceTree = "<group>"; };
27E0736A2C20D27F0034B963 /* dydxCancelPendingIsolatedOrdersView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = dydxCancelPendingIsolatedOrdersView.swift; sourceTree = "<group>"; };
27E3C3E72CA33673009AEFEC /* dydxMarketListView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = dydxMarketListView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1596,6 +1600,8 @@
27D276222C519C98002775F2 /* dydxComponents */ = {
isa = PBXGroup;
children = (
2718DF362CCC46CC00C05DD8 /* dydxTitledContent.swift */,
27DFA5302CCB1730005FCABB /* dydxTitledTextField.swift */,
27DBF3C82C4A05B9009EB2D6 /* dydxTitledNumberField.swift */,
273C2F372C496F4F00F8391F /* dydxSliderInputView.swift */,
276AF8C62C4AE85A001DD695 /* dydxSliderView.swift */,
Expand Down Expand Up @@ -2128,6 +2134,7 @@
02EFE86A28FF0DEE00DEBF69 /* MarginUsage.swift in Sources */,
27897DA22C94E71500196F21 /* ReceiptLoadingItemView.swift in Sources */,
64A4DB59296620B4008D8E20 /* dydxTradeInputTimeInForceView.swift in Sources */,
27DFA53D2CCB1736005FCABB /* dydxTitledTextField.swift in Sources */,
27ED365C2AD735A800C159F5 /* dydxSecurityView.swift in Sources */,
029CBE7728F608F400259C1D /* dydxMarketTradesView.swift in Sources */,
0238FC46296DA53F002E1C1A /* dydxOrderDetailsView.swift in Sources */,
Expand Down Expand Up @@ -2245,6 +2252,7 @@
027CB28529EEFF760069781A /* dydxTransferStatusView.swift in Sources */,
026382E928F0EE6B00F766FA /* dydxMarketPriceCandlesTypesView.swift in Sources */,
0238FF162976432D002E1C1A /* TradeInputViewModifier.swift in Sources */,
2718DF432CCC46D000C05DD8 /* dydxTitledContent.swift in Sources */,
277437792CACCA6A00F9A6B9 /* PlatformUI+Ext.swift in Sources */,
02FF0BCE29AE928700781EDA /* dydxWalletListView.swift in Sources */,
64A4DB61296620FF008D8E20 /* dydxTradeInputEditView.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//
// dydxTitledContent.swift
// dydxViews
//
// Created by Michael Maguire on 10/25/24.
//

import SwiftUI

struct dydxTitledContent<Content: View>: View {
let title: String
let content: Content

init(title: String, @ViewBuilder content: () -> Content) {
self.title = title
self.content = content()
}

@ViewBuilder
private var titleView: some View {
Text(title)
.themeColor(foreground: .textTertiary)
.themeFont(fontType: .base, fontSize: .smaller)
}

var body: some View {
VStack(alignment: .leading, spacing: 5) {
titleView
content
}
.padding(.vertical, 12)
.padding(.horizontal, 16)
.makeInput()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
//
// dydxTitledTextField.swift
// dydxViews
//
// Created by Michael Maguire on 10/24/24.
//

import SwiftUI
import dydxFormatter
import PlatformUI
import Utilities

/// Effectively a TextField which forces its input as a number
/// Supports dydx-style title and title accesory view
struct dydxTitledTextField: View {
let title: String
let placeholder: String
let isPasteEnabled: Bool
let isClearEnabled: Bool
@Binding var text: String

private static let inputFontType: ThemeFont.FontType = .base
private static let inputFontSize: ThemeFont.FontSize = .medium
private static let inputFontHeight: CGFloat = {
ThemeSettings.shared.themeConfig.themeFont.uiFont(of: inputFontType, fontSize: inputFontSize)?.lineHeight ?? 0
}()

init(title: String, placeholder: String, isPasteEnabled: Bool = false, isClearEnabled: Bool = true, text: Binding<String>) {
self.title = title
self.placeholder = placeholder
self.isPasteEnabled = isPasteEnabled
self.isClearEnabled = isClearEnabled
self._text = text
}

@ViewBuilder
private var titleView: some View {
Text(title)
.themeColor(foreground: .textTertiary)
.themeFont(fontType: .base, fontSize: .smaller)
}

private var textFieldView: some View {
TextField(text: $text) {
placeholderView
}
.themeColor(foreground: .textPrimary)
.themeFont(fontType: .base, fontSize: .medium)
.truncationMode(.middle)
}

@ViewBuilder
private var placeholderView: some View {
Text(placeholder)
.themeFont(fontType: .base, fontSize: .medium)
.themeColor(foreground: .textTertiary)
}

private var clearButton: some View {
let content = Image("icon_cancel", bundle: .dydxView)
.resizable()
.templateColor(.textSecondary)
.padding(.all, 10)
.frame(width: 32, height: 32)
.borderAndClip(style: .circle, borderColor: .layer6)
.wrappedViewModel

return PlatformButtonViewModel(content: content,
type: .iconType,
state: .secondary) {
self.text = ""
}
.createView()
}

private var pasteButton: some View {
let buttonContent = Text(DataLocalizer.localize(path: "APP.GENERAL.PASTE"))
.themeColor(foreground: .textSecondary)
.themeFont(fontSize: .small)
.wrappedViewModel

return PlatformButtonViewModel(content: buttonContent,
type: .defaultType(fillWidth: false, padding: .init(horizontal: 8, vertical: 6)),
state: .secondary ) {
self.text = UIPasteboard.general.string ?? ""
}
.createView()
.frame(height: Self.inputFontHeight)
}

var body: some View {
HStack(spacing: 0) {
VStack(alignment: .leading, spacing: 5) {
titleView
textFieldView
}
if isPasteEnabled && text.isEmpty {
Spacer()
pasteButton
} else if isClearEnabled && !text.isEmpty {
Spacer()
clearButton
}
}
.padding(.vertical, 12)
.padding(.horizontal, 16)
.makeInput()
}
}
Loading

0 comments on commit 8734148

Please sign in to comment.