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

Create ForageVaultWrapper #144

Merged

Conversation

dleis612
Copy link
Contributor

@dleis612 dleis612 commented Dec 29, 2023

What

Add a 3rd VaultWrapper called the ForageVaultWrapper that will be used to accept PINs and interface with the Forage vault.

Why

More information can be found in the ticket.

Demo

ForageVaultWrapper
Screenshot 2023-12-29 at 3 09 09 PM

VGSVaultWrapper
Screenshot 2023-12-29 at 3 10 12 PM

BTVaultWrapper
Screenshot 2023-12-29 at 3 18 27 PM

@dleis612
Copy link
Contributor Author

@devinmorgan it seems to me that the onFocusChangeListener seems to be working correctly, but I recall we had to add some special handling for this case in the ForagePANEditText class. Do you think this is an issue here too?

Copy link
Contributor

@devinmorgan devinmorgan left a comment

Choose a reason for hiding this comment

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

Nice work so far, Danny. My understanding is that you said there's still a bit of work you wanted to do in this PR so I'll wait to approve until you take it out of Draft. Cheers!

@@ -96,7 +97,7 @@ internal class VGSVaultWrapper @JvmOverloads constructor(
// up into separate focus and blur listeners. This requires
// that we pass a single listener to VGS on init that uses
// mutable references to listeners so that setting the focus
// would not remove the blur listener and vice versea
// would not remove the blur listener and vice versa
Copy link
Contributor

Choose a reason for hiding this comment

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

omg embarrassing - thank you for catching and fixing!

override fun getForageTextElement(): EditText {
throw RuntimeException("Unimplemented for this vault!")
}

Copy link
Contributor

Choose a reason for hiding this comment

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

No action required right now but the work we're doing here is surfacing that we probably have some tech debt around the relationship between VaultWrapper and ForagePINEdiText that we'll want to pay down at some point.

That we don't want BTVaultWrapper or VGSVaultWrapper to implement getForageTextElement, indicates that we should not be making getForageTextElement an abstract method on the VaultWrapper class. VaultWrapper already declares getTextElement and getVGSEditText as abstract methods even though they too really should not be living on VaultWrapper since they are specific to BT / VGS wrappers. After poking around the code, it's clear that ForagePINEditText is implemented in a way that expects all vaults expose a getTextElement and getVGSEditText. ForagePINEditTexts dependency on these methods means the fix won't be trivial and so we should probably defer paying this debt down to a later ticket.

One way that I can see to fix this delema is to create an abstraction over the underlying editable text field that BT, VGS, and Forage expose so that there is a unified way of calling things like:

  • getUnderlyingView()
  • clearText()
  • etc

But anyhow, my next step is to make a Linear ticket to capture this and share the link here once I do. But, like a said before, I think what you're doing here is fine and won't break or block anything.

override val manager: PinElementStateManager = PinElementStateManager.forEmptyInput()

init {
context.obtainStyledAttributes(attrs, R.styleable.ForagePINEditText, defStyleAttr, 0)

Check warning

Code scanning / Android Lint

Mismatched Styleable/Custom View Name Warning

By convention, the custom view (ForageVaultWrapper) and the declare-styleable (ForagePINEditText) should have the same name (various editor features rely on this convention)
override val manager: PinElementStateManager = PinElementStateManager.forEmptyInput()

init {
context.obtainStyledAttributes(attrs, R.styleable.ForagePINEditText, defStyleAttr, 0)

Check warning

Code scanning / Android Lint

Mismatched Styleable/Custom View Name Warning

By convention, the custom view (ForageVaultWrapper) and the declare-styleable (ForagePINEditText) should have the same name (various editor features rely on this convention)

fun parseStyles(context: Context, attrs: AttributeSet?): ParsedStyles {
val defaultRadius = resources.getDimension(R.dimen.default_horizontal_field)
val typedArray: TypedArray = context.obtainStyledAttributes(attrs, R.styleable.ForagePINEditText)

Check warning

Code scanning / Android Lint

Mismatched Styleable/Custom View Name Warning

By convention, the custom view (VaultWrapper) and the declare-styleable (ForagePINEditText) should have the same name (various editor features rely on this convention)
@dleis612 dleis612 marked this pull request as ready for review January 3, 2024 16:43
Copy link
Contributor

@devinmorgan devinmorgan left a comment

Choose a reason for hiding this comment

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

Nice work on this PR Danny! Thanks for your patience with me in the review process. Exciting progress so far!

Copy link
Contributor

Choose a reason for hiding this comment

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

Nice strategy for separating the PIN validation logic from the PIN rendering logic!

Copy link
Contributor

@devinmorgan devinmorgan Jan 5, 2024

Choose a reason for hiding this comment

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

Introducing the data class ParsedStyles definitely made it easier to read the render logic inside ForageVaultWrapper - good idea!

Curious why we put ParsedStyles inside of VaultWrapper instead of keeping it local to ForageVaultWrapper? From what I can tell, this ParsedStyles does not seem to be used by BTVaultWrapper or VGSVaultWrapper and wanted to better understand.

At any rate, where ParsedStyles and it's related logic lives should not hold up merging in this me PR as it's internal code that we can revisit at any point

@devinmorgan
Copy link
Contributor

@devinmorgan it seems to me that the onFocusChangeListener seems to be working correctly, but I recall we had to add some special handling for this case in the ForagePANEditText class. Do you think this is an issue here too?

@dleis612 - really thoughtful concern you bring up here!

You're right that we did some special handling in the past. I suspect that this will not be an issue in our case here because we're using a android.widget.EditText for as the PIN input. The problem in the past seems particular to com.google.android.material.textfield.TextInputEditText, which we were using in the ForagePANEditText.

👆 is just my best guess. In the worst case if we notice a similar problem, I think we can address it then. Lmk whether this is a productive response to your question though

@dleis612 dleis612 merged commit a4a94d1 into main Jan 8, 2024
3 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants