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-3821] Pre Authorization general UI #1371

Merged
merged 67 commits into from
Nov 6, 2024
Merged

Conversation

matiasbzurovski
Copy link
Contributor

@matiasbzurovski matiasbzurovski commented Oct 21, 2024

JIRA ticket: ABW-3821
JIRA ticket: ABW-3823

Description

Adds PreAuthorizationReview, as well as logic to present it from the given dApp interaction.

How to review

The first thing I would do is go over TransactionReview & TransactionReview+View. No additional behavior has been added to this flow, but you will see a lot of code has been migrated into the new InteractionReview.Sections. This module contains the shared components among TransactionReview and PreAuthorizationReview.

Once the "common code" refactoring has been reviewed, I'd review the new code over PreAuthorizationReview & PreAuthorizationReview+View.

@matiasbzurovski matiasbzurovski changed the title Pre Authorization UI skeleton [ABW-3821] Pre Authorization general UI Oct 30, 2024
@matiasbzurovski matiasbzurovski marked this pull request as ready for review October 30, 2024 15:00
import SwiftUI

// MARK: - TransactionReviewAccounts
struct TransactionReviewAccounts: Sendable, FeatureReducer {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved into InteractionReview/Sections/Accounts/Accounts.swift

@@ -1,22 +0,0 @@
struct UnknownDappComponents: FeatureReducer, Sendable {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Reducer deleted since it is now a plain vanilla SwiftUI view, located in InteractionReview/Destinations/UnknownDappComponents/UnknownDappComponents.swift

import SwiftUI

// MARK: - TransactionReviewProofs.View
extension TransactionReviewProofs {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved into InteractionReview/Sections/Proofs/Proofs.swift

import SwiftUI

// MARK: - TransactionReviewRawTransaction.View
extension TransactionReviewRawTransaction {
Copy link
Contributor Author

@matiasbzurovski matiasbzurovski Nov 4, 2024

Choose a reason for hiding this comment

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

Unused view, deleted

Copy link
Contributor

@GhenadieVP GhenadieVP left a comment

Choose a reason for hiding this comment

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

Looks very good overall 💪, there might be some other places were we could remove the duplications between Transaction and Pre-Auth.

Copy link
Contributor

@GhenadieVP GhenadieVP left a comment

Choose a reason for hiding this comment

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

LGTM, well done!

/// - `56:02 minutes` / `1:23 minute`
/// - `34 seconds` / `1 second`
func formatTime(seconds: Int) -> String {
typealias S = L10n.PreAuthorizationReview.TimeFormat
Copy link
Contributor

Choose a reason for hiding this comment

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

I would probably not have this formatting logic inside a view, can we move it to Sargon and expose a function?

Copy link
Contributor

Choose a reason for hiding this comment

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

or just move it from view layer and add some unit tests?

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 didn't add it in Sargon because it uses localisation strings. However, it does make sense to include unit tests for it, will add.

extension InteractionReview {
enum DisplayMode: Sendable, Hashable {
case detailed
case raw(String)
Copy link
Contributor

Choose a reason for hiding this comment

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

can we use something more structured than String? Don't we have some UnvalidatedManifest type or something? Maybe we can create a new type or some typealias at least.

I would also put a one line doc on both cases and probably give raw a label: case raw(manifest: ...).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We cannot use UnvalidatedManifest since in TransactionReview we are dealing with a TransactionManifest (to which we append the fee & guarantees configurations done at this view), while at PreAuthroizationReview we deal with a SubintentManifest.

I will add the raw label, but I think adding a type around the String is an overkill, since this is enum is just internally to display the RawManifestView.

// MARK: - InteractionReview.Accounts
extension InteractionReview {
@Reducer
struct Accounts: Sendable, FeatureReducer {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd prefer if we could avoid calling reducers the same thing as models, makes searches (or possible find replace all) tricker, can it be called AccountsSection or similar? I dont feel too strongly about this though, so feel free to ignore

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'd prefer sticking as it is. The find & replace is already pretty bad on Xcode, meaning that even if we name it AccountsSection, it will still break if we have other AccountsSections anywhere else. When I just renamed the send case to submitTransaction, Xcode wanted to update tests that were doing viewStore.send().

Then, keeping it short-named and enclosed under InteractionReview namespace makes it easier to follow IMO.

@@ -131,6 +134,9 @@ extension DappToWalletInteraction {
// transactions
case .send:
0
// preAuthorization
Copy link
Contributor

Choose a reason for hiding this comment

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

I would probably rename send to submitTransaction or similar. We now have subintent and then having just send looks weird. send was short for sendTransasction - and sendTransaction I've always disliked, I think it should be called submitTransaction and then we can call subintent signSubintent perhaps - because we actually do NOT submit the signed subintent, the Dapp does.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

100% agree (always disliked send as well). Updating

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.

Bravo, well done! I've not tested it locally.

I left some remarks, nothing too important, mostly code cosmetics..

@matiasbzurovski matiasbzurovski merged commit 4887e80 into main Nov 6, 2024
6 checks passed
@matiasbzurovski matiasbzurovski deleted the ABW-3821-pre-auth-ui branch November 6, 2024 11:19
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