Skip to content

Commit

Permalink
Update sample app to show usState of PAN (#134)
Browse files Browse the repository at this point in the history
* Update sample app to show usState of PAN

The change of adding `details` to `ElementState` by making
`ElementState` generic appears to be non-breaking becasue the compiler
did not complain before making this commit (i.e. before modify the
sample app).

* Have launch darkly block main thread for up to 1s

We're noticing in production that GoPuff Android apps are not respecting
dynamic feature flag values. We played around with this in dev and it
appeared that LDClient was reading the default VGS flag becuase we were
not giving it any time to fetch the latest feature flag values.

We're trying to be a bit descrite with this change because we don't
think it will cause any issues and we think GoPuff may overreact a bit
if they learn we're allowing Forage to block the main thread
  • Loading branch information
devinmorgan authored Dec 5, 2023
1 parent 440d709 commit c351e7a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ internal object LDManager {
internal fun initialize(app: Application, ldConfig: LDConfig) {
val contextKind = ContextKind.of(LDContextKind.SERVICE)
val context = LDContext.create(contextKind, LDContexts.ANDROID_CONTEXT)
client = LDClient.init(app, ldConfig, context, 0)
client = LDClient.init(app, ldConfig, context, 1)
}

internal fun getVaultProvider(logger: Log = Log.getSilentInstance()): VaultType {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,15 @@ class FlowTokenizeFragment : Fragment() {
val isComplete: TextView = binding.isComplete
val isEmpty: TextView = binding.isEmpty
val isValid: TextView = binding.isValid
val usState: TextView = binding.usState

fun setState() {
val state = foragePanEditText.getElementState()
isFocused.text = "isFocused: ${state.isFocused}"
isComplete.text = "isComplete: ${state.isComplete}"
isEmpty.text = "isEmpty: ${state.isEmpty}"
isValid.text = "isValid: ${state.isValid}"
usState.text = "usState: ${state.derivedCardInfo.usState?.abbreviation}"
}

foragePanEditText.setOnFocusEventListener { setState() }
Expand All @@ -77,6 +79,7 @@ class FlowTokenizeFragment : Fragment() {
isComplete.text = "isComplete: ${state.isComplete}"
isEmpty.text = "isEmpty: ${state.isEmpty}"
isValid.text = "isValid: ${state.isValid}"
usState.text = "usState: ${state.derivedCardInfo.usState?.abbreviation}"

viewModel.paymentMethod.observe(viewLifecycleOwner) {
when (it == null) {
Expand Down
17 changes: 16 additions & 1 deletion sample-app/src/main/res/layout/fragment_flow_tokenize.xml
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,21 @@
app:layout_constraintVertical_bias="0.0"
tools:text="isValid: false" />

<TextView
android:id="@+id/usState"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:textColor="@color/black"
android:textSize="18sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/isValid"
app:layout_constraintVertical_bias="0.0"
tools:text="usState: null" />

<TextView
android:id="@+id/errorResponse"
android:layout_width="0dp"
Expand All @@ -143,7 +158,7 @@
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/isValid"
app:layout_constraintTop_toBottomOf="@+id/usState"
app:layout_constraintVertical_bias="0.0"
tools:text="error: tok_sandbox_sYiPe9Q249qQ5wQyUPP5f7" />

Expand Down

0 comments on commit c351e7a

Please sign in to comment.