Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sequential execution event #4710

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package one.mixin.android.tip.wc.internal

class WCFinishEvent(val nowInUtc: String)
57 changes: 40 additions & 17 deletions app/src/main/java/one/mixin/android/ui/home/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@ import com.microsoft.appcenter.AppCenter
import com.uber.autodispose.autoDispose
import dagger.hilt.android.AndroidEntryPoint
import io.reactivex.Maybe
import io.reactivex.Observable
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers
import io.reactivex.subjects.BehaviorSubject
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.delay
Expand Down Expand Up @@ -120,7 +122,9 @@ import one.mixin.android.tip.Tip
import one.mixin.android.tip.wc.WCErrorEvent
import one.mixin.android.tip.wc.WCEvent
import one.mixin.android.tip.wc.WalletConnect
import one.mixin.android.tip.wc.WalletConnect.RequestType
import one.mixin.android.tip.wc.WalletConnectV2
import one.mixin.android.tip.wc.internal.WCFinishEvent
import one.mixin.android.ui.common.BaseFragment
import one.mixin.android.ui.common.BatteryOptimizationDialogActivity
import one.mixin.android.ui.common.BlazeBaseActivity
Expand Down Expand Up @@ -309,28 +313,47 @@ class MainActivity : BlazeBaseActivity() {
.subscribe { e ->
handleTipEvent(e, deviceId)
}

val controlSubject = BehaviorSubject.createDefault(true)
RxBus.listen(WCEvent::class.java)
.autoDispose(destroyScope)
.subscribe { e ->
lifecycleScope.launch {
if (e is WCEvent.V2) {
if (e.requestType != WalletConnect.RequestType.Connect) {
val type = e.chainType ?: TYPE_ETH
if (type == TYPE_SOLANA && PropertyHelper.findValueByKey(SOLANA_ADDRESS, "").isBlank()) {
WalletUnlockBottomSheetDialogFragment.getInstance(type).showIfNotShowing((MixinApplication.get().topActivity as? AppCompatActivity)?.supportFragmentManager ?: supportFragmentManager, WalletUnlockBottomSheetDialogFragment.TAG)
} else if (PropertyHelper.findValueByKey(EVM_ADDRESS, "").isBlank()) {
WalletUnlockBottomSheetDialogFragment.getInstance(type).showIfNotShowing((MixinApplication.get().topActivity as? AppCompatActivity)?.supportFragmentManager ?: supportFragmentManager, WalletUnlockBottomSheetDialogFragment.TAG)
} else {
WalletConnectActivity.show(this@MainActivity, e)
.concatMap { e ->
controlSubject.filter { it }
.take(1)
.flatMap {
Observable.fromCallable {
lifecycleScope.launch {
if (e is WCEvent.V2) {
if (e.requestType != WalletConnect.RequestType.Connect) {
val type = e.chainType ?: TYPE_ETH
if (type == TYPE_SOLANA && PropertyHelper.findValueByKey(SOLANA_ADDRESS, "").isBlank()) {
WalletUnlockBottomSheetDialogFragment.getInstance(type).showIfNotShowing((MixinApplication.get().topActivity as? AppCompatActivity)?.supportFragmentManager ?: supportFragmentManager, WalletUnlockBottomSheetDialogFragment.TAG)
} else if (PropertyHelper.findValueByKey(EVM_ADDRESS, "").isBlank()) {
WalletUnlockBottomSheetDialogFragment.getInstance(type).showIfNotShowing((MixinApplication.get().topActivity as? AppCompatActivity)?.supportFragmentManager ?: supportFragmentManager, WalletUnlockBottomSheetDialogFragment.TAG)
} else {
WalletConnectActivity.show(this@MainActivity, e)
}
} else {
WalletConnectActivity.show(this@MainActivity, e)
}
} else {
WalletConnectActivity.show(this@MainActivity, e)
}
}
} else {
WalletConnectActivity.show(this@MainActivity, e)
// Intercept only SessionRequest
controlSubject.onNext(!(e is WCEvent.V2 && e.requestType == RequestType.SessionRequest))
}
} else {
WalletConnectActivity.show(this@MainActivity, e)
}
}
}
.autoDispose(destroyScope)
.subscribe()

RxBus.listen(WCFinishEvent::class.java)
.autoDispose(destroyScope)
.subscribe { finishEvent ->
Timber.e("WC finish: ${finishEvent.nowInUtc}")
controlSubject.onNext(true)
}

RxBus.listen(WCErrorEvent::class.java)
.autoDispose(destroyScope)
.subscribe {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@ import android.os.Bundle
import android.view.WindowManager
import dagger.hilt.android.AndroidEntryPoint
import one.mixin.android.R
import one.mixin.android.RxBus
import one.mixin.android.extension.getParcelableExtraCompat
import one.mixin.android.extension.nowInUtc
import one.mixin.android.tip.Tip
import one.mixin.android.tip.wc.WCError
import one.mixin.android.tip.wc.WCEvent
import one.mixin.android.tip.wc.WalletConnect
import one.mixin.android.tip.wc.WalletConnect.RequestType
import one.mixin.android.tip.wc.internal.WCFinishEvent
import one.mixin.android.ui.common.BaseActivity
import one.mixin.android.ui.common.QrScanBottomSheetDialogFragment
import timber.log.Timber
Expand Down Expand Up @@ -45,6 +48,11 @@ class WalletConnectActivity : BaseActivity() {
overridePendingTransition(R.anim.stay, R.anim.slide_out_bottom)
}

override fun onDestroy() {
super.onDestroy()
RxBus.publish(WCFinishEvent(nowInUtc()))
}

private fun handleIntent(intent: Intent) {
val event = intent.getParcelableExtraCompat(ARGS_WC_EVENT, WCEvent::class.java)
if (event != null) {
Expand Down
Loading