-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix wallet select disambiguation cancellation crash (#362)
* Initial refactor ActivityResultSender to facilitate cancellations * More refactors to bring in line with best practices. * Ensure no crashing when cancelling connnection. * Close scenario after activity callback. * Add no wallet found error type to sealed class hierarchy * Start adding support for no wallet found error in ktx sample * Make sample app use new status
- Loading branch information
1 parent
79980a6
commit a843717
Showing
5 changed files
with
157 additions
and
93 deletions.
There are no files selected for viewing
32 changes: 30 additions & 2 deletions
32
...entlib-ktx/src/main/java/com/solana/mobilewalletadapter/clientlib/ActivityResultSender.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,35 @@ | ||
package com.solana.mobilewalletadapter.clientlib | ||
|
||
import android.content.Intent | ||
import androidx.activity.ComponentActivity | ||
import androidx.activity.result.ActivityResultLauncher | ||
import androidx.activity.result.contract.ActivityResultContracts | ||
import androidx.annotation.GuardedBy | ||
|
||
interface ActivityResultSender { | ||
fun launch(intent: Intent) | ||
class ActivityResultSender( | ||
rootActivity: ComponentActivity | ||
) { | ||
@GuardedBy("this") | ||
private var callback: (() -> Unit)? = null | ||
|
||
private val activityResultLauncher: ActivityResultLauncher<Intent> = | ||
rootActivity.registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { | ||
onActivityComplete() | ||
} | ||
|
||
fun startActivityForResult(intent: Intent, onActivityCompleteCallback: () -> Unit) { | ||
synchronized(this) { | ||
check(callback == null) { "Received an activity start request while another is pending" } | ||
callback = onActivityCompleteCallback | ||
} | ||
|
||
activityResultLauncher.launch(intent) | ||
} | ||
|
||
private fun onActivityComplete() { | ||
synchronized(this) { | ||
callback?.let { it() } | ||
callback = null | ||
} | ||
} | ||
} |
117 changes: 67 additions & 50 deletions
117
...ientlib-ktx/src/main/java/com/solana/mobilewalletadapter/clientlib/MobileWalletAdapter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.