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

Using different placeholder words in mnemonic #528

Merged
merged 44 commits into from
May 28, 2023

Conversation

CyonAlexRDX
Copy link
Contributor

@CyonAlexRDX CyonAlexRDX commented May 27, 2023

Before

Screenshot 2023-05-27 at 22 18 47

After

Screenshot 2023-05-28 at 08 34 37 Screenshot 2023-05-28 at 08 34 42

@CyonAlexRDX CyonAlexRDX requested a review from kugel3 May 27, 2023 20:19

// Update words
if delta > 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

Since this is all fed to SwiftUI, which should do diffing on each textview before any re-render, we will probably get the same performance if we just recalculate all the models whenever anything changes.

Copy link
Contributor

Choose a reason for hiding this comment

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

Or rather, we could skip wordcount and when they press increase the reducer will simply add a placeholder model value, if they press decrease we remove one. Or is there a particular reason to let the wordcount drive things?

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 use wordCount as the canonical source of truth, which is convenient. If we add UI which allows setting the WordCount directly, everything will just work. "Add more words" is a UI thing, what should happen is the wordCount enum should get a new value.

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 still make the word fields themselves the source of truth, and then put this delta logic in the computed setter of wordCount (rather than willSet of a stored property), with the getter being words.count. Small difference perhaps but it eliminates to possibility that they get out of sync.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed! and also fixed a cornercase bug, where user had inputted a valid mnemonic (e.g 12 words) and then increase word count by 3 => Import Mnemonic button was enabled, but should have been disabled.

@kugel3
Copy link
Contributor

kugel3 commented May 27, 2023

By the way, shouldn't we use the primary heading, on the left of the cells?

@CyonAlexRDX
Copy link
Contributor Author

@kugel3 i chose secondary because primary was so prominent, took over focus completely, but I can make it possible to pass in a font...

@kugel3
Copy link
Contributor

kugel3 commented May 27, 2023

Or just a boolean, "prominentHeadings: Bool = true" or something that just controls the foreground colors of both the headings,

Base automatically changed from ABW-ZYX_seed_phrase_row_accounts to main May 28, 2023 06:25
@@ -53,7 +53,7 @@ extension EditPersonaField {
public var body: some SwiftUI.View {
WithViewStore(store, observe: ViewState.init(state:), send: { .view($0) }) { viewStore in
AppTextField(
primaryHeading: viewStore.primaryHeading,
primaryHeading: .init(text: viewStore.primaryHeading),
Copy link
Contributor

Choose a reason for hiding this comment

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

I was thinking of prominence as a separate property, so that when it's omitted it doesn't affect the primaryHeading parameter, but if you prefer this way then sure.

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 did not wanna further increase property count in AppTextField. The whole thing is a mess anyway...

@@ -72,15 +70,17 @@ public struct ImportMnemonic: Sendable, FeatureReducer {
self.wordCount = wordCount
self.bip39Passphrase = bip39Passphrase

self.isAddRowButtonEnabled = wordCount != .twentyFour
self.isRemoveRowButtonEnabled = wordCount != .twelve

let isReadonlyMode = false
self.isReadonlyMode = isReadonlyMode
self.words = .init(
Copy link
Contributor

Choose a reason for hiding this comment

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

Couldn't this be initialised to[] and then it will be set when you set wordCount below?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

Comment on lines +18 to +19
public let indexToWord: [Word.Index: Word]
public let wordToIndex: [NonEmptyString: Word.Index]
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't the first one basically the same as the words property? And the second one could be computed, using firstIndex(of:), right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The first one is not ordered. I want an ordered set. I tried NonEmpty<OrderedDict, but that does not work because OrderedDict does not conform to Collection.

We have the two of them for fastest possible look up. We don't care about slightly more data, we care about performance. But it was many years ago (I lifted this in from some
Old repo of mine) since ago I wrote this code so yeah, there is room for improvements.

@kugel3
Copy link
Contributor

kugel3 commented May 28, 2023

The new words are perfect!

@CyonAlexRDX CyonAlexRDX merged commit 435968f into main May 28, 2023
@CyonAlexRDX CyonAlexRDX deleted the ABW-XYZ_unique_placeholder_words branch May 28, 2023 19:03
This pull request was closed.
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.

2 participants