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

[ABW-3723] Resource hiding/unhiding #1290

Merged
merged 41 commits into from
Aug 29, 2024
Merged

Conversation

matiasbzurovski
Copy link
Contributor

@matiasbzurovski matiasbzurovski commented Aug 20, 2024

Jira ticket: ABW-3723

Description

This PR allows to hide/unhide resources (fungible, non-fungible & pool units)

How to test

Play with your user as the demo video shows.

Video

Video

PR submission checklist

  • I have tested account to account transfer flow and have confirmed that it works


// MARK: - Helpers

private extension [AssetAddress] {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

personal preferences, I dislike extension [Element] syntax - since it makes it impossible to search for all Array extensions and all Dictionary extensions individually. But I think I'm the only one to dislike it and we are using it elsewhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually used to add extensions like this as extension Array where Element == XYZ before, would you prefer it that way?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I prefer that, but then we have fragmentation in the code base. I think this is the most common syntax we use, so maybe best stick to it

Copy link
Contributor

@CyonAlexRDX CyonAlexRDX left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent!


@ViewBuilder
private var fungibles: some SwiftUI.View {
if store.fungible.isEmpty {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

annoying that ResultBuilders does not support guard or otherwise return early :/
SE-0289 states

guard is provisionally ill-formed when it appears within a transformed function. Situations in which this statement may appear may be supported in the future, such as when the statement does not produce a partial result.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right, or ternary operators so that we could do something like this on the body:

store.fungibles.isEmpty ? empty : fungibles

and remove the conditional check inside var fungibles

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could put the if-else at the parent level, and let the fungibles var only be called when not empty. That would be pretty clean. I think it should be called emptyState though, not just empty. And I would make it a nested view, so you would use it with EmptyState() instead, it doesn't seem to use any variables.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well this is debatable. I prefer looking at the body and getting a clear and quick vision of what's going on. In my opinion it looks cleaner to see this:

LazyVStack(alignment: .leading, spacing: .large3) {
	Text(L10n.HiddenAssets.text)
		.textStyle(.body1HighImportance)
		.foregroundColor(.app.gray2)

	header(L10n.HiddenAssets.fungibles)
	fungibles

	header(L10n.HiddenAssets.nonFungibles)
	nonFungibles

	header(L10n.HiddenAssets.poolUnits)
	poolUnits
}

than this:

LazyVStack(alignment: .leading, spacing: .large3) {
	Text(L10n.HiddenAssets.text)
		.textStyle(.body1HighImportance)
		.foregroundColor(.app.gray2)

	header(L10n.HiddenAssets.fungibles)
	if store.fungibles.isEmpty {
		empty
	} else {
		fungibles
	}

	header(L10n.HiddenAssets.nonFungibles)
	if store.nonFungibles.isEmpty {
		empty
	} else {
		nonFungibles
	}

	header(L10n.HiddenAssets.poolUnits)
	if store.poolUnits.isEmpty {
		empty
	} else {
		poolUnits
	}
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, but the second option makes the variables cleaner. But my main point is that it is better to not hide the empty state, since that is in fact a top-level thing, I don't think it should be hidden.

@matiasbzurovski matiasbzurovski mentioned this pull request Aug 22, 2024
1 task
}

private func confirmation(with destinationStore: PresentationStoreOf<HideAsset.Destination>, store: StoreOf<HideAsset>) -> some View {
sheet(store: destinationStore.scope(state: \.confirmation, action: \.confirmation)) { _ in
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like you scope the destinationStore and then use the HideAsset store instead? What is going on here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I scope the destinationStore to tell when this ConfirmationView alert should be presented. Given the alert doesn't have a reducer (it is a plain SwiftUI view that have a closure for each button that can be tapped: confirm and cancel), we just need to handle the button tap on this reducer.

}

// MARK: - Destination
public struct Destination: DestinationReducer {
Copy link
Contributor

@kugel3 kugel3 Aug 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you try using the new style, where you just define something like:

extension HideAsset {
  @Reducer(state: .hashable, action: .equatable)
  enum Destination {
    case confirmation(ConfirmationAction)
  }
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how do you make the parent conform to FeatureReducer ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can do put @Reducer(state: .hashable, action: .equatable) on the Destination if that is what you have in mind? But it was a genuine question, it seems that it only will play nicely with FeatureReducer sometimes.

@@ -0,0 +1,120 @@
// MARK: - HideAsset
@Reducer
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the macro is causing issues when combined with FeatureReducer, feel free to skip the latter, and implement the needed actions etc manually.

@@ -11,6 +11,7 @@ public struct NonFungibleTokenDetails: Sendable, FeatureReducer {
public let ledgerState: AtLedgerState
public let stakeClaim: OnLedgerEntitiesClient.StakeClaim?
public let isClaimStakeEnabled: Bool
var hideAsset: HideAsset.State?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose this should also be public?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nothing needs to be public actually :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, but since the struct and all the other properties are public, this one should be as well. There is no reason for them to have different access levels, it only causes confusion.

Copy link
Contributor Author

@matiasbzurovski matiasbzurovski Aug 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO the confusion is caused by leaving the others public, and what we should do is actually remove the access modifier from those.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously we had separate modules for every feature, so everything had to be public. Now there is no technical reason for it, but we should at the very least be consistent within a feature.

@ViewBuilder
private var accounts: some SwiftUI.View {
if store.accounts.isEmpty {
empty
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, since the empty state is not specific to accounts, I don't think it needs to be part of var accounts

if isXrd {
await send(.internal(.setShouldShow(false)))
} else {
let isAlreadyHidden = await appPreferencesClient.isAssetHidden(asset: state.asset)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose you added this for the scenario when viewing the details of an asset from TX Review, but should we allows users to hide an asset from TX Review in the first place?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

according to my demo on Friday, yes

@matiasbzurovski matiasbzurovski merged commit 629b5e9 into main Aug 29, 2024
6 checks passed
@matiasbzurovski matiasbzurovski deleted the ABW-3723-resource-hiding branch August 29, 2024 14:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants