Skip to content

Commit

Permalink
update sdk to remove SmileID.setEnvironment() (#426)
Browse files Browse the repository at this point in the history
  • Loading branch information
jumaallan authored Aug 1, 2024
1 parent 5690a57 commit 7507cc8
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 32 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
#### Fixed
* Job status history full data parsing causing a crash during polling

### Changed
* Removed `SmileID.setEnvironment()` since the API Keys are no longer shared between environments

## 10.2.3

* Handle invalid resource IDs
Expand Down
16 changes: 1 addition & 15 deletions lib/src/main/java/com/smileidentity/SmileID.kt
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ object SmileID {

internal var allowOfflineMode: Boolean = false
private set

var callbackUrl: String = ""
private set

Expand Down Expand Up @@ -176,21 +177,6 @@ object SmileID {
initialize(context, config, useSandbox, enableCrashReporting, okHttpClient)
}

/**
* Switches the SDK between the sandbox and production API at runtime. Please note that if the
* environment is switched while you or the SDK is in the middle of a job (i.e. polling job
* status), this may cause API errors.
*
* @param useSandbox Whether to use the sandbox environment. If false, uses production
*/
@JvmStatic
fun setEnvironment(useSandbox: Boolean) {
SmileID.useSandbox = useSandbox
val url = if (useSandbox) config.sandboxBaseUrl else config.prodBaseUrl
retrofit = retrofit.newBuilder().baseUrl(url).build()
api = retrofit.create(SmileIDService::class.java)
}

/**
* The callback mechanism allows for asynchronous job requests and responses.
* While the job_status API can be polled to get a result, a better method is to set up a
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ private fun TopBar(
actions = {
FilterChip(
selected = uiState.isProduction,
onClick = viewModel::toggleEnvironment,
onClick = {},
label = { Text(stringResource(id = uiState.environmentName)) },
colors = filterChipColors(
selectedContainerColor = MaterialTheme.colorScheme.tertiary,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,22 +170,6 @@ class MainScreenViewModel : ViewModel() {
}
}

/**
* Cancel any polling, switch the environment, and then restart polling (the auth request
* will automatically pick up the correct environment)
*/
fun toggleEnvironment() {
pendingJobCountJob.cancel()
backgroundJobsPollingJob.cancel()

SmileID.setEnvironment(!SmileID.useSandbox)

pendingJobCountJob = createPendingJobCountPoller()
backgroundJobsPollingJob = createBackgroundJobsPoller()

_uiState.update { it.copy(isProduction = !SmileID.useSandbox) }
}

fun onHomeSelected() {
_uiState.update {
it.copy(
Expand Down

0 comments on commit 7507cc8

Please sign in to comment.