Skip to content

Commit

Permalink
Refactor fields for receive module take.2
Browse files Browse the repository at this point in the history
  • Loading branch information
ant013 committed Nov 29, 2023
1 parent d454296 commit a3d6e85
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 98 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,27 @@ 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)\n\n") + "deposit.warning".localized(item.coinCode)
let text = (item.memo == nil ? "" : "\("cex_deposit.warning_memo".localized)") + "deposit.warning".localized
let style = item.memo == nil ? HighlightedDescriptionBaseView.Style.yellow : .red

sections.append([.highlightedDescription(text: text, style: style)])
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))

if let memo = item.memo {
viewItems.append(.memo(value: memo))
}

sections.append(viewItems)

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

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 Down Expand Up @@ -104,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 @@ -23,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 @@ -44,16 +54,15 @@ struct ReceiveAddressView<Service: IReceiveAddressService, Factory: IReceiveAddr
PlaceholderViewNew(image: Image("sync_error_48"), text: "sync_error".localized)
}
}
.animation(.default) // , value: viewModel.state)
.onChange(of: viewModel.popup) {
guard hasAppeared else { return }
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 Down Expand Up @@ -165,69 +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 .amount(value):
ListRow {
Text("deposit.amount".localized).textSubhead2()
Spacer()
Text(value).textSubhead1(color: .themeLeah)

Button(action: {
inputText = ""
viewModel.set(amount: "")
}, label: {
Image("trash_20").renderingMode(.template)
})
.buttonStyle(SecondaryCircleButtonStyle(style: .default))
}
case let .status(value):
ListRow {
Text("deposit.account".localized)
.textSubhead2()
.modifier(Informed(description:
AlertView.InfoDescription(
@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 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(value).textSubhead1(color: .themeYellow)
}
case let .memo(value):
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(value).textSubhead1(color: .themeLeah)

Button(action: {
CopyHelper.copyAndNotify(value: value)
}, label: {
Image("copy_20").renderingMode(.template)
})
.buttonStyle(SecondaryCircleButtonStyle(style: .default))
}
case let .highlightedDescription(text, style):
HighlightedTextView(text: text, style: style)
Spacer()
Text("deposit.not_active".localized).textSubhead1(color: .themeYellow)
}
}

@ViewBuilder private func view(items: [ReceiveAddressModule.Item]) -> some View {
ListSection {
ForEach(items) { item in
view(item: item)
}
@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,26 +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)

if let formatted = coinValue.formattedFull {
viewItems.append(.amount(value: formatted))
}
amountString = coinValue.formattedFull
}

var active = true
if let address = item.address as? ActivatedDepositAddress, !address.isActive {
viewItems.append(
.status(value: "deposit.not_active".localized)
)
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
Expand Up @@ -367,6 +367,8 @@
"deposit.account" = "Account";

"deposit.amount" = "Amount";
"deposit.set_amount" = "Set Amount";
"deposit.enter_amount" = "Enter Amount";
"deposit.not_active" = "Not active";
"deposit.not_active.title" = "Not Active Address";
"deposit.not_active.tron_description" = "Newly created accounts on the TRON blockchain are inactive and cannot be queried or explored. They need to be activated.\n\nTransferring TRX or TRC-10 tokens to an inactive account address will activate the account. Activating a new account on the Tron chain requires a fee of 1 TRX";
Expand All @@ -375,7 +377,7 @@
"deposit.zcash.restore.already_own" = "Yes, I already own";
"deposit.zcash.restore.dont_have" = "No, I don’t have";

"deposit.warning" = "Send only %@ to this address. Sending other types of tokens to this address will result in their ultimate loss.";
"deposit.warning" = "Send only network-compatible tokens. Others will be lost.";

"receive_network_select.title" = "Network";
"receive_network_select.description" = "Choose a network and get an address to receive.";
Expand Down Expand Up @@ -1812,9 +1814,7 @@
"cex_deposit.network" = "Network";
"cex_deposit.memo" = "Memo (Tag)";
"cex_deposit.min_amount" = "Min. Amount";
"cex_deposit.warning_memo" = "Memo (tag) is required, or your will lose your coins.";
"cex_deposit.set_amount" = "Set Amount";
"cex_deposit.enter_amount" = "Enter Amount";
"cex_deposit.warning_memo" = "Provide required Memo (Tag) and send only network-compatible tokens. Others will be lost.";
"cex_deposit.copy_address" = "Copy";
"cex_deposit.share_address" = "Share";
"cex_deposit.failed" = "Failed to load deposit address. Please retry.";
Expand Down

0 comments on commit a3d6e85

Please sign in to comment.