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

Station settings photo verification UI component #203

2 changes: 1 addition & 1 deletion PresentationLayer/Constants/ColorEnum.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public enum ColorEnum: String {
case stationChipOnlineStateText
case favoriteHeart
case mapPin
case wxmWhite
case textWhite
case darkBg
case infoIndication
case trasnparentButtonBg
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ extension ClaimDeviceContainerViewModel {

let continueToPhotoVerificationAction: VoidCallback = { [weak self] in
self?.dismissAndNavigate(device: nil)
let route = PhotoIntroViewModel.getInitialRoute()
let route = PhotoIntroViewModel.getInitialRoute(images: [], isNewPhotoVerification: true)
DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) { // The only way found to avoid errors with navigation stack
Router.shared.navigateTo(route)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@ struct BoostsView: View {
HStack {
Text(title)
.font(.system(size: CGFloat(.normalFontSize), weight: .bold))
.foregroundColor(Color(colorEnum: .wxmWhite))
.foregroundColor(Color(colorEnum: .textWhite))
Spacer()

Text("+ \(rewards.toWXMTokenPrecisionString) \(StringConstants.wxmCurrency)")
.font(.system(size: CGFloat(.caption), weight: .medium))
.foregroundColor(Color(colorEnum: .wxmWhite))
.foregroundColor(Color(colorEnum: .textWhite))
}

HStack {
Text(description)
.font(.system(size: CGFloat(.caption)))
.foregroundColor(Color(colorEnum: .wxmWhite))
.foregroundColor(Color(colorEnum: .textWhite))

Spacer()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,34 @@ extension DeviceInfoViewModel.Field {
}
}

func titleFor(devie: DeviceDetails) -> String {
func titleFor(devie: DeviceDetails) -> (title: String, badge: String?) {
switch self {
case .name:
return LocalizableString.DeviceInfo.stationName.localized
return (LocalizableString.DeviceInfo.stationName.localized, nil)
case .frequency:
return LocalizableString.DeviceInfo.stationFrequency.localized
return (LocalizableString.DeviceInfo.stationFrequency.localized, nil)
case .reboot:
return LocalizableString.DeviceInfo.stationReboot.localized
return (LocalizableString.DeviceInfo.stationReboot.localized, nil)
case .maintenance:
#warning("TODO: Format when info is ready")
return LocalizableString.DeviceInfo.stationMaintenance("").localized
return (LocalizableString.DeviceInfo.stationMaintenance("").localized, nil)
case .remove:
return LocalizableString.DeviceInfo.stationRemove.localized
return (LocalizableString.DeviceInfo.stationRemove.localized, nil)
case .reconfigureWifi:
return LocalizableString.DeviceInfo.stationReconfigureWifi.localized
return (LocalizableString.DeviceInfo.stationReconfigureWifi.localized, nil)
case .stationLocation:
return LocalizableString.DeviceInfo.stationLocation.localized
return (LocalizableString.DeviceInfo.stationLocation.localized, nil)
case .rewardSplit:
return LocalizableString.RewardDetails.rewardSplit.localized
return (LocalizableString.RewardDetails.rewardSplit.localized, nil)
case .photos:
return LocalizableString.PhotoVerification.uploadPhotos.localized
return (LocalizableString.PhotoVerification.photoVerificationIntroTitle.localized, LocalizableString.new.localized)
}
}

func descriptionFor(device: DeviceDetails, for followState: UserDeviceFollowState?, deviceInfo: NetworkDevicesInfoResponse?) -> String {
func descriptionFor(device: DeviceDetails,
for followState: UserDeviceFollowState?,
deviceInfo: NetworkDevicesInfoResponse?,
photoVerificationState: PhotoVerificationStateView.State?) -> String {
switch self {
case .name:
return device.displayName
Expand Down Expand Up @@ -74,7 +77,20 @@ extension DeviceInfoViewModel.Field {
let count = rewardSplit.count
return LocalizableString.RewardDetails.rewardSplitDescription(count).localized
case .photos:
return LocalizableString.PhotoVerification.uploadPhotosDescription.localized
guard let photoVerificationState else {
return ""
}

switch photoVerificationState {
case .uploading:
return LocalizableString.DeviceInfo.photoVerificationUploadingDescription.localized
case .content(let photos, _):
if photos.isEmpty {
return LocalizableString.DeviceInfo.photoVerificationEmptyText.localized
}

return LocalizableString.DeviceInfo.photoVerificationWithPhotosDescription.localized
}
}
}

Expand Down Expand Up @@ -116,7 +132,9 @@ extension DeviceInfoViewModel.Field {
}

@MainActor
func buttonInfoFor(devie: DeviceDetails, followState: UserDeviceFollowState?) -> DeviceInfoButtonInfo? {
func buttonInfoFor(devie: DeviceDetails,
followState: UserDeviceFollowState?,
photoVerificationState: PhotoVerificationStateView.State?) -> DeviceInfoButtonInfo? {
switch self {
case .name:
return .init(icon: nil, title: LocalizableString.DeviceInfo.buttonChangeName.localized)
Expand All @@ -140,25 +158,23 @@ extension DeviceInfoViewModel.Field {
case .rewardSplit:
return nil
case .photos:
return .init(icon: nil, title: LocalizableString.PhotoVerification.letsTakeTheFirstPhoto.localized)
}
}

@MainActor
func customViewFor(deviceInfo: NetworkDevicesInfoResponse?) -> AnyView? {
switch self {
case .rewardSplit:
guard let rewardsplit = deviceInfo?.rewardSplit, rewardsplit.count > 0 else {
guard let photoVerificationState else {
return nil
}
let items = rewardsplit.map { split in
let userWallet = MainScreenViewModel.shared.userInfo?.wallet?.address
let isUserWallet = split.wallet == userWallet
return split.toSplitViewItem(showReward: false, isUserWallet: isUserWallet)

switch photoVerificationState {
case .content(let photos, _):
if photos.isEmpty {
return .init(icon: nil,
title: LocalizableString.DeviceInfo.photoVerificationStartButtonTitle.localized,
buttonStyle: .filled())

}

fallthrough
default:
return nil
}
return RewardsSplitView.WalletsListView(items: items).toAnyView
default:
return nil
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,24 @@ struct DeviceInfoRowView: View {

var body: some View {
VStack(spacing: CGFloat(.smallToMediumSpacing)) {
VStack(spacing: CGFloat(.minimumSpacing)) {
VStack(spacing: CGFloat(.smallSpacing)) {
HStack {
Text(row.title)
.foregroundColor(Color(colorEnum: .darkestBlue))
.font(.system(size: CGFloat(.mediumFontSize), weight: .bold))
Spacer()

Spacer()

if let badge = row.badge {
Text(badge.uppercased())
.foregroundColor(Color(colorEnum: .wxmPrimary))
.font(.system(size: CGFloat(.littleCaption), weight: .bold))
.padding(.horizontal, CGFloat(.smallSidePadding))
.padding(.vertical, CGFloat(.minimumPadding))
.background {
Capsule().fill(Color(colorEnum: .layer2))
}
}
}

HStack {
Expand Down Expand Up @@ -71,7 +83,6 @@ struct DeviceInfoRowView: View {

if let customView = row.customView {
customView
.padding(.top, CGFloat(.defaultSidePadding))
}
}
}
Expand All @@ -82,13 +93,15 @@ extension DeviceInfoRowView {
struct Row: Equatable {
static func == (lhs: DeviceInfoRowView.Row, rhs: DeviceInfoRowView.Row) -> Bool {
lhs.title == rhs.title &&
lhs.badge == rhs.badge &&
lhs.description == rhs.description &&
lhs.imageUrl == rhs.imageUrl &&
lhs.buttonInfo == rhs.buttonInfo &&
lhs.warning == rhs.warning
}

let title: String
var badge: String?
let description: AttributedString
let imageUrl: URL?
let buttonInfo: DeviceInfoButtonInfo?
Expand Down Expand Up @@ -154,6 +167,7 @@ private extension DeviceInfoRowView {
struct DeviceInfoRowView_Previews: PreviewProvider {
static var previews: some View {
DeviceInfoRowView(row: DeviceInfoRowView.Row(title: "TItle",
badge: "New",
description: "This is a **desription**".attributedMarkdown!,
imageUrl: URL(string: "https://i0.wp.com/weatherxm.com/wp-content/uploads/2023/12/Home-header-image-1200-x-1200-px-5.png?w=1200&ssl=1"),
buttonInfo: .init(icon: nil, title: "Button title"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ extension DeviceInfoViewModel {

static func heliumSections(for followState: UserDeviceFollowState?) -> [[Field]] {
if followState?.state == .owned {
return [[.name, .frequency, .reboot, .photos],
return [[.photos],
[.name, .frequency, .reboot],
[.stationLocation]]
}

Expand All @@ -47,7 +48,8 @@ extension DeviceInfoViewModel {

static func wifiSections(for followState: UserDeviceFollowState?) -> [[Field]] {
if followState?.state == .owned {
return [[.name, .photos],
return [[.name],
[.photos],
[.stationLocation]]
}

Expand Down
Loading