Skip to content

Commit

Permalink
chore: move internal buy kin flow behind a beta flag
Browse files Browse the repository at this point in the history
Signed-off-by: Brandon McAnsh <git@bmcreations.dev>
  • Loading branch information
bmc08gt committed Aug 6, 2024
1 parent d240be7 commit 72ff125
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 96 deletions.
1 change: 1 addition & 0 deletions api/src/main/java/com/getcode/model/PrefBool.kt
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ sealed class PrefsBool(val value: String) {
data object TIPS_CHAT_ENABLED: PrefsBool("tips_chat_enabled"), BetaFlag
data object TIPS_CHAT_CASH_ENABLED: PrefsBool("tips_chat_cash_enabled"), BetaFlag
data object BALANCE_CURRENCY_SELECTION_ENABLED: PrefsBool("balance_currency_enabled"), BetaFlag
data object KADO_WEBVIEW_ENABLED : PrefsBool("kado_inapp_enabled"), BetaFlag
}

val APP_SETTINGS: List<AppSetting> = listOf(PrefsBool.CAMERA_START_BY_DEFAULT, PrefsBool.REQUIRE_BIOMETRICS)
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ data class BetaOptions(
val tipsChatEnabled: Boolean,
val tipsChatCashEnabled: Boolean,
val balanceCurrencySelectionEnabled: Boolean,
val kadoWebViewEnabled: Boolean,
) {
companion object {
// Default states for various beta flags in app.
Expand All @@ -33,7 +34,8 @@ data class BetaOptions(
tipsEnabled = false,
tipsChatEnabled = false,
tipsChatCashEnabled = false,
balanceCurrencySelectionEnabled = true
balanceCurrencySelectionEnabled = true,
kadoWebViewEnabled = false,
)
}
}
Expand Down Expand Up @@ -68,6 +70,7 @@ class BetaFlagsRepository @Inject constructor(
observeBetaFlag(PrefsBool.TIPS_CHAT_CASH_ENABLED, default = defaults.tipsChatCashEnabled),
observeBetaFlag(PrefsBool.BALANCE_CURRENCY_SELECTION_ENABLED, defaults.balanceCurrencySelectionEnabled),
observeBetaFlag(PrefsBool.DISPLAY_ERRORS, default = defaults.displayErrors),
observeBetaFlag(PrefsBool.KADO_WEBVIEW_ENABLED, default = defaults.kadoWebViewEnabled)
) {
BetaOptions(
showNetworkDropOff = it[0],
Expand All @@ -82,6 +85,7 @@ class BetaFlagsRepository @Inject constructor(
tipsChatCashEnabled = it[9],
balanceCurrencySelectionEnabled = it[10],
displayErrors = it[11],
kadoWebViewEnabled = it[12],
)
}
}
Expand Down
32 changes: 20 additions & 12 deletions app/src/main/java/com/getcode/view/main/account/BetaFlagsScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ fun BetaFlagsScreen(
val titleResId: Int,
val subtitleText: String,
val dataState: Boolean,
val onChange: (Boolean) -> Unit
val onChange: (Boolean) -> Unit = { value ->
viewModel.dispatchEvent(BetaFlagsViewModel.Event.Toggle(flag, value))
}
)

val state by viewModel.stateFlow.collectAsState()
Expand All @@ -43,67 +45,73 @@ fun BetaFlagsScreen(
R.string.beta_vibrate_on_scan,
stringResource(R.string.beta_vibrate_on_scan_description),
state.isVibrateOnScan
) { viewModel.dispatchEvent(BetaFlagsViewModel.Event.SetVibrateOnScan(it)) },
),
BetaFeature(
PrefsBool.SHOW_CONNECTIVITY_STATUS,
R.string.beta_network_dropoff,
stringResource(R.string.beta_network_connectivity_description),
state.showNetworkDropOff
) { viewModel.dispatchEvent(BetaFlagsViewModel.Event.ShowNetworkDropOff(it)) },
),
BetaFeature(
PrefsBool.BUCKET_DEBUGGER_ENABLED,
R.string.beta_bucket_debugger,
stringResource(R.string.beta_bucket_debugger_description),
state.canViewBuckets
) { viewModel.dispatchEvent(BetaFlagsViewModel.Event.UseDebugBuckets(it)) },
),
BetaFeature(
PrefsBool.BALANCE_CURRENCY_SELECTION_ENABLED,
R.string.beta_balance_currency,
stringResource(R.string.beta_balance_currency_description),
state.currencySelectionBalanceEnabled
) { viewModel.dispatchEvent(BetaFlagsViewModel.Event.EnableCurrencySelectionInBalance(it)) },
),
BetaFeature(
PrefsBool.GIVE_REQUESTS_ENABLED,
R.string.beta_give_requests_mode,
stringResource(id = R.string.beta_give_requests_description),
state.giveRequestsEnabled
) { viewModel.dispatchEvent(BetaFlagsViewModel.Event.EnableGiveRequests(it)) },
),
BetaFeature(
PrefsBool.BUY_MODULE_ENABLED,
R.string.beta_buy_kin,
stringResource(id = R.string.beta_buy_kin_description),
state.buyKinEnabled
) { viewModel.dispatchEvent(BetaFlagsViewModel.Event.EnableBuyKin(it)) },
),
BetaFeature(
PrefsBool.CHAT_UNSUB_ENABLED,
R.string.beta_chat_unsub,
stringResource(id = R.string.beta_chat_unsub_description),
state.chatUnsubEnabled,
) { viewModel.dispatchEvent(BetaFlagsViewModel.Event.EnableChatUnsubscribe(it)) },
),
BetaFeature(
PrefsBool.TIPS_ENABLED,
R.string.beta_tipcard,
stringResource(id = R.string.beta_tipcard_description),
state.tipsEnabled,
) { viewModel.dispatchEvent(BetaFlagsViewModel.Event.EnableTipCard(it)) },
),
BetaFeature(
PrefsBool.TIPS_CHAT_ENABLED,
R.string.beta_tipchats,
stringResource(id = R.string.beta_tipchats_description),
state.tipsChatEnabled,
) { viewModel.dispatchEvent(BetaFlagsViewModel.Event.EnableTipChats(it)) },
),
BetaFeature(
PrefsBool.TIPS_CHAT_CASH_ENABLED,
R.string.beta_tipchats_cash,
stringResource(id = R.string.beta_tipchats_cash_description),
state.tipsChatCashEnabled,
) { viewModel.dispatchEvent(BetaFlagsViewModel.Event.EnableTipsChatCash(it)) },
),
BetaFeature(
PrefsBool.KADO_WEBVIEW_ENABLED,
R.string.beta_kado_webview,
stringResource(id = R.string.beta_kado_webview_description),
state.kadoWebViewEnabled,
),
BetaFeature(
PrefsBool.DISPLAY_ERRORS,
R.string.beta_display_errors,
"",
state.displayErrors,
) { viewModel.dispatchEvent(BetaFlagsViewModel.Event.ShowErrors(it)) }
)
).filter { state.canMutate(it.flag) }

LazyColumn {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import com.getcode.utils.ErrorUtils
import com.getcode.view.BaseViewModel2
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.filterIsInstance
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import javax.inject.Inject
Expand All @@ -34,22 +35,12 @@ class BetaFlagsViewModel @Inject constructor(
val tipsEnabled: Boolean = false,
val tipsChatEnabled: Boolean = false,
val tipsChatCashEnabled: Boolean = false,
val kadoWebViewEnabled: Boolean = false,
)

sealed interface Event {
data class UpdateSettings(val settings: BetaOptions) : Event

data class ShowErrors(val display: Boolean) : Event
data class EnableCurrencySelectionInBalance(val enabled: Boolean): Event
data class ShowNetworkDropOff(val show: Boolean) : Event
data class SetVibrateOnScan(val vibrate: Boolean) : Event
data class UseDebugBuckets(val enabled: Boolean) : Event
data class EnableGiveRequests(val enabled: Boolean) : Event
data class EnableBuyKin(val enabled: Boolean) : Event
data class EnableTipCard(val enabled: Boolean) : Event
data class EnableChatUnsubscribe(val enabled: Boolean) : Event
data class EnableTipChats(val enabled: Boolean) : Event
data class EnableTipsChatCash(val enabled: Boolean) : Event
data class Toggle(val setting: PrefsBool, val state: Boolean): Event
}

init {
Expand All @@ -61,65 +52,12 @@ class BetaFlagsViewModel @Inject constructor(


eventFlow
.onEach { event ->
when (event) {
is Event.EnableBuyKin -> prefRepository.set(
PrefsBool.BUY_MODULE_ENABLED,
event.enabled
)

is Event.EnableChatUnsubscribe -> prefRepository.set(
PrefsBool.CHAT_UNSUB_ENABLED,
event.enabled
)

is Event.EnableGiveRequests -> prefRepository.set(
PrefsBool.GIVE_REQUESTS_ENABLED,
event.enabled
)

is Event.EnableTipCard -> prefRepository.set(
PrefsBool.TIPS_ENABLED,
event.enabled
)

is Event.EnableTipChats -> prefRepository.set(
PrefsBool.TIPS_CHAT_ENABLED,
event.enabled
)

is Event.EnableTipsChatCash -> prefRepository.set(
PrefsBool.TIPS_CHAT_CASH_ENABLED,
event.enabled
)

is Event.EnableCurrencySelectionInBalance -> prefRepository.set(
PrefsBool.BALANCE_CURRENCY_SELECTION_ENABLED,
event.enabled
)

is Event.SetVibrateOnScan -> prefRepository.set(
PrefsBool.VIBRATE_ON_SCAN,
event.vibrate
)

is Event.ShowErrors -> {
prefRepository.set(PrefsBool.DISPLAY_ERRORS, event.display)
ErrorUtils.setDisplayErrors(event.display)
}

is Event.ShowNetworkDropOff -> prefRepository.set(
PrefsBool.SHOW_CONNECTIVITY_STATUS,
event.show
)

is Event.UseDebugBuckets -> prefRepository.set(
PrefsBool.BUCKET_DEBUGGER_ENABLED,
event.enabled
)

is Event.UpdateSettings -> Unit
}
.filterIsInstance<Event.Toggle>()
.onEach {
prefRepository.set(
it.setting,
it.state
)
}.launchIn(viewModelScope)
}

Expand All @@ -140,21 +78,12 @@ class BetaFlagsViewModel @Inject constructor(
tipsEnabled = tipsEnabled,
tipsChatEnabled = tipsChatEnabled,
tipsChatCashEnabled = tipsChatCashEnabled,
kadoWebViewEnabled = kadoWebViewEnabled,
)
}
}

is Event.EnableBuyKin,
is Event.EnableTipCard,
is Event.EnableGiveRequests,
is Event.ShowNetworkDropOff,
is Event.UseDebugBuckets,
is Event.EnableCurrencySelectionInBalance,
is Event.SetVibrateOnScan,
is Event.EnableChatUnsubscribe,
is Event.EnableTipChats,
is Event.EnableTipsChatCash,
is Event.ShowErrors -> { state -> state }
is Event.Toggle -> { state -> state }
}
}
}
Expand Down
14 changes: 13 additions & 1 deletion app/src/main/java/com/getcode/view/main/getKin/BuyKinScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalUriHandler
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.hilt.navigation.compose.hiltViewModel
import com.getcode.LocalBetaFlags
import com.getcode.LocalNetworkObserver
import com.getcode.R
import com.getcode.navigation.core.LocalCodeNavigator
Expand All @@ -30,7 +32,9 @@ import com.getcode.ui.components.Row
import com.getcode.util.showNetworkError
import com.getcode.utils.ErrorUtils
import com.getcode.view.main.giveKin.AmountArea
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlin.time.Duration.Companion.seconds

@Composable
fun BuyKinScreen(
Expand All @@ -43,6 +47,8 @@ fun BuyKinScreen(
val dataState by viewModel.state.collectAsState()
val networkObserver = LocalNetworkObserver.current
val networkState by networkObserver.state.collectAsState()
val betaFlags = LocalBetaFlags.current
val uriHandler = LocalUriHandler.current

Column(
modifier = Modifier
Expand Down Expand Up @@ -118,7 +124,13 @@ fun BuyKinScreen(

composeScope.launch {
viewModel.initiatePurchase()?.let {
navigator.push(KadoWebScreen(it))
if (betaFlags.kadoWebViewEnabled) {
navigator.push(KadoWebScreen(it))
} else {
uriHandler.openUri(it)
delay(1.seconds)
onRedirected()
}
}
}
},
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings-universal.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<string translatable="false" name="beta_tipchats">Tip Chats</string>
<string translatable="false" name="beta_tipchats_cash">Tip Chats Cash</string>
<string translatable="false" name="beta_balance_currency">Currency Selection in Balance</string>
<string translatable="false" name="beta_kado_webview">Buy Kin Internally</string>
<string translatable="false" name="beta_display_errors">Show Errors</string>
<string name="beta_bucket_debugger_description" translatable="false">If enabled, you\'ll gain the ability to tap the balance on the Balance screen to inspect individual bucket balances.</string>
<string name="beta_network_connectivity_description" translatable="false">If enabled, a \"No Connection\" badge will show on the scan screen when no internet is detected.</string>
Expand All @@ -35,6 +36,7 @@
<string name="beta_tipcard_description" translatable="false">If enabled, you\'ll gain the ability to share a tip card.</string>
<string name="beta_tipchats_description" translatable="false">If enabled, you\'ll gain the ability to chat with tippers.</string>
<string name="beta_tipchats_cash_description" translatable="false">If enabled, you\'ll gain the ability to send Kin in Tip Chats.</string>
<string name="beta_kado_webview_description" translatable="false">If enabled, the Buy Kin flow will open in an internal WebView.</string>
<string name="subtitle_remoteSendText" translatable="false">%1$s %2$s</string>
<string name="beta_resetTooltips" translatable="false">Reset Tooltips</string>

Expand Down

0 comments on commit 72ff125

Please sign in to comment.