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

Refactoring receive #5423

Merged
merged 2 commits into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions UnstoppableWallet/UnstoppableWallet.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -2173,6 +2173,7 @@
ABC9A20D2DDF8736293DE5C5 /* CoinIndicatorViewItemFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABC9A76776AD840DBFAA1804 /* CoinIndicatorViewItemFactory.swift */; };
ABC9A20F6F7D5EA2A1A55A9E /* ContactLabelService.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABC9AB89F64056FFB98928E7 /* ContactLabelService.swift */; };
ABC9A220C97C81DC578AA3C7 /* ProposalValidator.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABC9AE997CF6814BA9EAA6BB /* ProposalValidator.swift */; };
ABC9A22690729B58621A1BBA /* InformedModifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABC9AC701F3F7FE0A21AFBF9 /* InformedModifier.swift */; };
ABC9A227648FF076E9518703 /* ContactBookHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABC9AE12A5E8B9FB24FFE42F /* ContactBookHelper.swift */; };
ABC9A231F63CDD5EC0BB71EF /* ActionSheetPresentationController.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABC9A9A18EECD26A7A93D972 /* ActionSheetPresentationController.swift */; };
ABC9A23C433DC06FB7791285 /* WCSignMessageRequestViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABC9A0576B804ABA38EF9843 /* WCSignMessageRequestViewModel.swift */; };
Expand Down Expand Up @@ -2318,6 +2319,7 @@
ABC9A62209E284513C33DFE2 /* MarketDiscoveryCategoryService.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABC9ADFD9DA59BD2FB21C51B /* MarketDiscoveryCategoryService.swift */; };
ABC9A62EF59AF658C1DAD36F /* SendAmountCautionService.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABC9A580220B9FD291A6496A /* SendAmountCautionService.swift */; };
ABC9A638E7EA1788D40FF929 /* FileManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABC9A8CE84FA36438BE4D6B5 /* FileManager.swift */; };
ABC9A639040A77968B5D86B8 /* InformedModifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABC9AC701F3F7FE0A21AFBF9 /* InformedModifier.swift */; };
ABC9A63B2AABC0414000DEC2 /* SendConfirmationViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABC9A3AB799024C8FC2C7DD8 /* SendConfirmationViewModel.swift */; };
ABC9A63EC83A82A76E67778B /* SendNftModule.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABC9A82A1E9AE6CC0E24756B /* SendNftModule.swift */; };
ABC9A6424F39E24F7198B9DF /* WCSignMessagePayload.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABC9AF628790F13411CB3D1C /* WCSignMessagePayload.swift */; };
Expand Down Expand Up @@ -4347,6 +4349,7 @@
ABC9AC4A19838CA08603E17B /* ContactBookService.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ContactBookService.swift; sourceTree = "<group>"; };
ABC9AC50307ABA3DF7034E1D /* BackupContact.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BackupContact.swift; sourceTree = "<group>"; };
ABC9AC6A0B950C0AABD5A93E /* SendEip1155Service.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SendEip1155Service.swift; sourceTree = "<group>"; };
ABC9AC701F3F7FE0A21AFBF9 /* InformedModifier.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = InformedModifier.swift; sourceTree = "<group>"; };
ABC9AC7983E4A81E421AB639 /* MarketCardTitleView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MarketCardTitleView.swift; sourceTree = "<group>"; };
ABC9AC8CCF3B57FDFC817356 /* ContactBookAddressService.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ContactBookAddressService.swift; sourceTree = "<group>"; };
ABC9ACC91C29905F8E7A2046 /* ActionSheetTapView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ActionSheetTapView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -5166,6 +5169,7 @@
ABC9A9B9B3A81581BA7E4082 /* AlertView.swift */,
ABC9A6EF6EB856EAAA8CFACB /* PrimaryCircleButtonStyle.swift */,
ABC9ABB793A6494225FF73B7 /* Alert.swift */,
ABC9AC701F3F7FE0A21AFBF9 /* InformedModifier.swift */,
);
path = SwiftUI;
sourceTree = "<group>";
Expand Down Expand Up @@ -10412,6 +10416,7 @@
ABC9AFBBB0042989EB4592E7 /* AlertView.swift in Sources */,
ABC9A57D1DA5481E44DEE8C0 /* PrimaryCircleButtonStyle.swift in Sources */,
ABC9AD8A956680AAC03DE7F1 /* Alert.swift in Sources */,
ABC9A22690729B58621A1BBA /* InformedModifier.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -11818,6 +11823,7 @@
ABC9A32EECAEB892927B996D /* AlertView.swift in Sources */,
ABC9AD530352E51084B1B4B7 /* PrimaryCircleButtonStyle.swift in Sources */,
ABC9A267A28122E3E6E3D5DC /* Alert.swift in Sources */,
ABC9A639040A77968B5D86B8 /* InformedModifier.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,43 +4,36 @@ class CexDepositViewItemFactory: IReceiveAddressViewItemFactory {
typealias Item = CexDepositService.Item

func viewItem(item: Item, amount _: String?) -> ReceiveAddressModule.ViewItem {
var sections = [[ReceiveAddressModule.Item]]()
let text = (item.memo == nil ? "" : "\("cex_deposit.warning_memo".localized)") + "deposit.warning".localized
let style = item.memo == nil ? HighlightedDescriptionBaseView.Style.yellow : .red

let description = ReceiveAddressModule.HighlightedDescription(
text: text,
style: style
)

var viewItems = [ReceiveAddressModule.Item]()
let qrItem = ReceiveAddressModule.QrItem(
address: item.address,
uri: nil,
networkName: item.networkName
)
viewItems.append(.qrItem(qrItem))
viewItems.append(.value(title: "cex_deposit.address".localized, value: item.address, copyable: false))

if let network = item.networkName {
viewItems.append(.value(title: "cex_deposit.network".localized, value: network, copyable: false))
}

if let memo = item.memo {
viewItems.append(.value(title: "cex_deposit.memo".localized, value: memo, copyable: true))
}

sections.append(viewItems)

let text = (item.memo == nil ? "" : "\("cex_deposit.warning_memo".localized)\n\n") + "deposit.warning".localized(item.coinCode)
let style = item.memo == nil ? HighlightedDescriptionBaseView.Style.yellow : .red

sections.append([.highlightedDescription(text: text, style: style)])

return .init(
copyValue: item.address,
sections: sections
highlightedDescription: description,
qrItem: qrItem,
amount: nil,
active: true,
memo: item.memo
)
}

func popup(item: Item) -> ReceiveAddressModule.PopupWarningItem? {
item.memo.map { _ in
.init(title: "cex_deposit.memo_warning.title".localized,
description: .init(text: "cex_deposit.memo_warning.description".localized, style: .red),
doneButtonTitle: "button.i_understand".localized)
doneButtonTitle: "button.i_understand".localized
)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ extension ReceiveAddressModule {

var title: String {
switch self {
case .amount: return "cex_deposit.set_amount".localized
case .amount: return "deposit.set_amount".localized
case .share: return "cex_deposit.share_address".localized
case .copy: return "cex_deposit.copy_address".localized
}
Expand All @@ -80,15 +80,17 @@ extension ReceiveAddressModule {

enum Item: Identifiable, Hashable {
case qrItem(QrItem)
case value(title: String, value: String, copyable: Bool)
case infoValue(title: String, value: String, infoTitle: String, infoDescription: String, style: HighlightedDescriptionBaseView.Style = .yellow)
case amount(value: String)
case status(value: String)
case memo(value: String)
case highlightedDescription(text: String, style: HighlightedDescriptionBaseView.Style = .yellow)

public var id: String {
switch self {
case let .qrItem(item): return "\(item.address)_\(item.networkName ?? "NA")"
case let .value(title, value, _): return title + value
case let .infoValue(title, value, _, _, _): return title + value
case let .amount(value): return value
case let .status(value): return value
case let .memo(value): return value
case let .highlightedDescription(text, _): return text
}
}
Expand All @@ -102,8 +104,17 @@ extension ReceiveAddressModule {
}
}

struct HighlightedDescription {
let text: String
let style: HighlightedDescriptionBaseView.Style
}

struct ViewItem {
let copyValue: String
let sections: [[Item]]
let highlightedDescription: HighlightedDescription
let qrItem: QrItem
let amount: String?
let active: Bool
let memo: String?
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ struct ReceiveAddressView<Service: IReceiveAddressService, Factory: IReceiveAddr
@State private var hasAppeared = false
@State private var warningAlertPopup: ReceiveAddressModule.PopupWarningItem?

@State private var infoPopup: AlertView.InfoDescription? = nil

@State private var shareText: String?
@State private var inputAmountPresented: Bool = false

Expand All @@ -25,14 +23,24 @@ struct ReceiveAddressView<Service: IReceiveAddressService, Factory: IReceiveAddr
ProgressView()
case let .completed(viewItem):
VStack(spacing: .margin12) {
ForEach(viewItem.sections, id: \.self) { items in
view(items: items)
HighlightedTextView(text: viewItem.highlightedDescription.text, style: viewItem.highlightedDescription.style)

ListSection {
qrView(item: viewItem.qrItem)
if let amount = viewItem.amount {
view(amount: amount)
}
if !viewItem.active {
notActive()
}
if let memo = viewItem.memo {
view(memo: memo)
}
}
}
.padding(EdgeInsets(top: .margin12, leading: .margin16, bottom: .margin32, trailing: .margin16))

Spacer()
.frame(height: 52)
Spacer().frame(height: 52)

LazyVGrid(columns: viewModel.actions.map { _ in GridItem(.flexible()) }, spacing: .margin16) {
ForEach(viewModel.actions, id: \.self) { action in
Expand All @@ -47,16 +55,14 @@ struct ReceiveAddressView<Service: IReceiveAddressService, Factory: IReceiveAddr
}
}
.onChange(of: viewModel.popup) {
print("Come on Change")
guard hasAppeared else { return }
print("Set Popup to VIEW")
warningAlertPopup = $0
}
.sheet(item: $shareText) { shareText in
ActivityView.view(activityItems: [shareText])
}
.alert("cex_deposit.enter_amount".localized, isPresented: $inputAmountPresented, actions: {
TextField("Amount", text: $inputText) // TODO: Can't check valid numbers in default alertview
.alert("deposit.enter_amount".localized, isPresented: $inputAmountPresented, actions: {
TextField("deposit.enter_amount".localized, text: $inputText) // TODO: Can't check valid numbers in default alertview
.keyboardType(.decimalPad)
Button("button.cancel".localized) {
updateAmount(success: false)
Expand All @@ -79,16 +85,6 @@ struct ReceiveAddressView<Service: IReceiveAddressService, Factory: IReceiveAddr
onDismiss: { warningAlertPopup = nil }
)
}
.bottomSheet(item: $infoPopup) { popup in
AlertView(
image: .info,
title: popup.title,
items: [
.description(text: popup.description),
],
onDismiss: { infoPopup = nil }
)
}
.onAppear {
guard !hasAppeared else { return }
hasAppeared = true
Expand Down Expand Up @@ -178,34 +174,56 @@ struct ReceiveAddressView<Service: IReceiveAddressService, Factory: IReceiveAddr
}
}

@ViewBuilder private func view(item: ReceiveAddressModule.Item) -> some View {
switch item {
case let .qrItem(item): qrView(item: item)
case let .value(title, value, _):
ListRow {
Text(title).textSubhead2()
Spacer()
Text(value).textSubhead1(color: .themeLeah)
}
case let .infoValue(title, value, infoTitle, infoDescription, style):
ClickableRow(action: {
infoPopup = AlertView.InfoDescription(title: infoTitle, description: infoDescription)
}) {
Text(title).textSubhead2()
Image("circle_information_20").themeIcon()
Spacer()
Text(value).textSubhead1(color: style.accentColor)
}
case let .highlightedDescription(text, style):
HighlightedTextView(text: text, style: style)
@ViewBuilder func view(amount: String) -> some View {
ListRow {
Text("deposit.amount".localized).textSubhead2()
Spacer()
Text(amount).textSubhead1(color: .themeLeah)
Button(action: {
inputText = ""
viewModel.set(amount: "")
}, label: {
Image("trash_20").renderingMode(.template)
})
.buttonStyle(SecondaryCircleButtonStyle(style: .default))
}
}

@ViewBuilder private func view(items: [ReceiveAddressModule.Item]) -> some View {
ListSection {
ForEach(items) { item in
view(item: item)
}
@ViewBuilder func notActive() -> some View {
ListRow {
Text("deposit.account".localized)
.textSubhead2()
.modifier(
Informed(description:
AlertView.InfoDescription(
title: "deposit.not_active.title".localized,
description: "deposit.not_active.tron_description".localized
)
))
Spacer()
Text("deposit.not_active".localized).textSubhead1(color: .themeYellow)
}
}

@ViewBuilder func view(memo: String) -> some View {
ListRow {
Text("cex_deposit.memo".localized)
.textSubhead2()
.modifier(
Informed(description:
AlertView.InfoDescription(
title: "cex_deposit.memo_warning.title".localized,
description: "cex_deposit.memo_warning.description".localized
)
))
Spacer()
Text(memo).textSubhead1(color: .themeLeah)
Button(action: {
CopyHelper.copyAndNotify(value: memo)
}, label: {
Image("copy_20").renderingMode(.template)
})
.buttonStyle(SecondaryCircleButtonStyle(style: .default))
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ class ReceiveAddressViewItemFactory: IReceiveAddressViewItemFactory {
typealias Item = ReceiveAddressService.Item

func viewItem(item: Item, amount: String?) -> ReceiveAddressModule.ViewItem {
var sections = [[ReceiveAddressModule.Item]]()

sections.append([.highlightedDescription(text: "deposit.warning".localized(item.coinCode), style: .yellow)])

var viewItems = [ReceiveAddressModule.Item]()
let description = ReceiveAddressModule.HighlightedDescription(
text: "deposit.warning".localized,
style: .yellow
)

var networkName = ""
if let derivation = item.token.type.derivation {
Expand Down Expand Up @@ -42,25 +41,24 @@ class ReceiveAddressViewItemFactory: IReceiveAddressViewItemFactory {
uri: uri,
networkName: networkName
)
viewItems.append(.qrItem(qrItem))
var amountString: String?
if let amount, let decimalValue = Decimal(string: amount) {
let coinValue = CoinValue(kind: .token(token: item.token), value: decimalValue)
amountString = coinValue.formattedFull
}

var active = true
if let address = item.address as? ActivatedDepositAddress, !address.isActive {
viewItems.append(
.infoValue(
title: "deposit.account".localized,
value: "deposit.not_active".localized,
infoTitle: "deposit.not_active.title".localized,
infoDescription: "deposit.not_active.tron_description".localized,
style: .yellow
)
)
active = false
}

sections.append(viewItems)

return .init(
copyValue: uri,
sections: sections
highlightedDescription: description,
qrItem: qrItem,
amount: amountString,
active: active,
memo: nil
)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import SwiftUI

struct Informed: ViewModifier {
private let description: AlertView.InfoDescription
@State private var descriptionPresented: Bool = false

init(description: AlertView.InfoDescription) {
self.description = description
}

func body(content: Content) -> some View {
HStack(spacing: .margin8) {
content

Button(action: {
descriptionPresented = true
}, label: {
Image("circle_information_20").renderingMode(.template)
})
.buttonStyle(SecondaryCircleButtonStyle(style: .transparent))
}
.bottomSheet(isPresented: $descriptionPresented) {
AlertView(
image: .info,
title: description.title,
items: [
.description(text: description.description),
],
onDismiss: { descriptionPresented = false }
)
}
}
}
Loading