Skip to content

Commit

Permalink
Reuse pin element's context (#252)
Browse files Browse the repository at this point in the history
A small win that reduces the number of args vault submitters
must request. Since UI elements have a `context` associated
with them, we can use their context instead of needing to
drill down a distinct context param

Signed-off-by: Devin Morgan <[email protected]>
  • Loading branch information
devinmorgan authored Jun 13, 2024
1 parent 45abc1f commit a74a069
Show file tree
Hide file tree
Showing 8 changed files with 2 additions and 180 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.joinforage.forage.android.core.services.vault

import android.content.Context
import com.joinforage.forage.android.core.services.ForageConstants
import com.joinforage.forage.android.core.services.VaultType
import com.joinforage.forage.android.core.services.forageapi.encryptkey.EncryptionKeys
Expand Down Expand Up @@ -33,7 +32,6 @@ internal interface VaultSubmitter {
}

internal abstract class AbstractVaultSubmitter(
protected val context: Context,
protected val foragePinEditText: ForagePinElement,
protected val logger: Log
) : VaultSubmitter {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.joinforage.forage.android.ecom.services.vault.bt

import android.content.Context
import com.basistheory.android.service.BasisTheoryElements
import com.basistheory.android.service.ProxyRequest
import com.basistheory.android.view.TextElement
Expand All @@ -19,12 +18,10 @@ import com.joinforage.forage.android.core.ui.element.ForagePinElement
internal typealias BasisTheoryResponse = Result<Any?>

internal class BasisTheoryPinSubmitter(
context: Context,
foragePinEditText: ForagePinElement,
logger: Log,
private val buildVaultProvider: () -> BasisTheoryElements = { buildBt() }
) : AbstractVaultSubmitter(
context = context,
foragePinEditText = foragePinEditText,
logger = logger
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,18 @@ import org.json.JSONException
import kotlin.coroutines.suspendCoroutine

internal class VgsPinSubmitter(
context: Context,
foragePinEditText: ForagePinElement,
logger: Log,
private val buildVaultProvider: (context: Context) -> VGSCollect = { buildVGSCollect(context) }
private val buildVaultProvider: (context: Context) -> VGSCollect = { buildVGSCollect(foragePinEditText.context) }
) : AbstractVaultSubmitter(
context = context,
foragePinEditText = foragePinEditText,
logger = logger
) {
override val vaultType: VaultType = VaultType.VGS_VAULT_TYPE
override suspend fun submitProxyRequest(
vaultProxyRequest: VaultProxyRequest
): ForageApiResponse<String> = suspendCoroutine { continuation ->
val vgsCollect = buildVaultProvider(context)
val vgsCollect = buildVaultProvider(foragePinEditText.context)
vgsCollect.bindView(foragePinEditText.getTextElement() as VGSEditText)

vgsCollect.addOnResponseListeners(object : VgsCollectResponseListener {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ internal class BTVaultWrapper @JvmOverloads constructor(
foragePinElement: ForagePinElement,
logger: Log
): AbstractVaultSubmitter = BasisTheoryPinSubmitter(
foragePinElement.context,
foragePinElement,
logger
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ internal class VGSVaultWrapper @JvmOverloads constructor(
foragePinElement: ForagePinElement,
logger: Log
): AbstractVaultSubmitter = VgsPinSubmitter(
foragePinElement.context,
foragePinElement,
logger
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ class AbstractVaultSubmitterTest : MockServerSuite() {
`when`(mockForagePinEditText.getElementState()).thenReturn(state)

abstractVaultSubmitter = ConcreteVaultSubmitter(
context = mockContext,
foragePinEditText = mockForagePinEditText,
logger = mockLogger
)
Expand All @@ -91,7 +90,6 @@ class AbstractVaultSubmitterTest : MockServerSuite() {
@Test
fun `submit with successful vault proxy response returns Success`() = runTest {
val concreteSubmitter = object : ConcreteVaultSubmitter(
context = mockContext,
foragePinEditText = mockForagePinEditText,
logger = mockLogger
) {
Expand All @@ -110,7 +108,6 @@ class AbstractVaultSubmitterTest : MockServerSuite() {
@Test
fun `submit with failed proxy response returns Failure`() = runTest {
val concreteVaultSubmitter = object : ConcreteVaultSubmitter(
context = mockContext,
foragePinEditText = mockForagePinEditText,
logger = mockLogger
) {
Expand All @@ -129,7 +126,6 @@ class AbstractVaultSubmitterTest : MockServerSuite() {
@Test
fun `submit with missing vault token returns UnknownErrorApiResponse`() = runTest {
val concreteSubmitter = object : ConcreteVaultSubmitter(
context = mockContext,
foragePinEditText = mockForagePinEditText,
logger = mockLogger
) {
Expand Down Expand Up @@ -157,7 +153,6 @@ class AbstractVaultSubmitterTest : MockServerSuite() {
@Test
fun `grabs the correct vault token`() = runTest {
val basisTheorySubmitter = object : ConcreteVaultSubmitter(
context = mockContext,
foragePinEditText = mockForagePinEditText,
logger = mockLogger
) {
Expand All @@ -167,7 +162,6 @@ class AbstractVaultSubmitterTest : MockServerSuite() {
}

val vgsSubmitter = object : ConcreteVaultSubmitter(
context = mockContext,
foragePinEditText = mockForagePinEditText,
logger = mockLogger
) {
Expand All @@ -186,7 +180,6 @@ class AbstractVaultSubmitterTest : MockServerSuite() {
@Test
fun `success metrics event is reported`() = runTest {
val concreteVaultSubmitter = object : ConcreteVaultSubmitter(
context = mockContext,
foragePinEditText = mockForagePinEditText,
logger = mockLogger
) {
Expand Down Expand Up @@ -215,7 +208,6 @@ class AbstractVaultSubmitterTest : MockServerSuite() {
@Test
fun `failure metrics event is reported`() = runTest {
val concreteVaultSubmitter = object : ConcreteVaultSubmitter(
context = mockContext,
foragePinEditText = mockForagePinEditText,
logger = mockLogger
) {
Expand Down Expand Up @@ -256,11 +248,9 @@ class AbstractVaultSubmitterTest : MockServerSuite() {
}

internal open class ConcreteVaultSubmitter(
context: Context,
foragePinEditText: ForagePINEditText,
logger: Log
) : AbstractVaultSubmitter(
context = context,
foragePinEditText = foragePinEditText,
logger = logger
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ class BasisTheoryPinSubmitterTest() : MockServerSuite() {
mockBasisTheoryResponse(Result.success("success"))

submitter = BasisTheoryPinSubmitter(
context = mockContext,
foragePinEditText = mockForagePinEditText,
logger = mockLogger,
buildVaultProvider = { mockBasisTheory }
Expand Down

This file was deleted.

0 comments on commit a74a069

Please sign in to comment.