-
Notifications
You must be signed in to change notification settings - Fork 6
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
Update mobile connect flow and UI #1008
Changes from 1 commit
bb0708d
9508b28
53ae79c
dfa3603
73c075c
2e0da3b
67b9c8a
e6a77e1
d5536e9
e0aa548
3d1af37
b0c2275
6b03334
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
package com.babylon.wallet.android.data.dapp | ||
|
||
import com.babylon.wallet.android.domain.model.IncomingMessage.IncomingRequest | ||
import com.babylon.wallet.android.utils.AppEvent | ||
import com.babylon.wallet.android.utils.AppEventBus | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.MutableStateFlow | ||
import kotlinx.coroutines.flow.asSharedFlow | ||
|
@@ -17,24 +19,24 @@ interface IncomingRequestRepository { | |
|
||
suspend fun add(incomingRequest: IncomingRequest) | ||
|
||
suspend fun addFirst(incomingRequest: IncomingRequest) | ||
|
||
suspend fun requestHandled(requestId: String) | ||
|
||
suspend fun pauseIncomingRequests() | ||
|
||
suspend fun resumeIncomingRequests() | ||
|
||
fun getUnauthorizedRequest(requestId: String): IncomingRequest.UnauthorizedRequest? | ||
|
||
fun getTransactionWriteRequest(requestId: String): IncomingRequest.TransactionRequest? | ||
|
||
fun getAuthorizedRequest(requestId: String): IncomingRequest.AuthorizedRequest? | ||
Comment on lines
-26
to
-30
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Very nice that you removed those 👍 |
||
fun getRequest(requestId: String): IncomingRequest? | ||
|
||
fun removeAll() | ||
|
||
fun getAmountOfRequests(): Int | ||
} | ||
|
||
class IncomingRequestRepositoryImpl @Inject constructor() : IncomingRequestRepository { | ||
class IncomingRequestRepositoryImpl @Inject constructor( | ||
private val appEventBus: AppEventBus | ||
) : IncomingRequestRepository { | ||
|
||
private val requestQueue = LinkedList<QueueItem>() | ||
|
||
|
@@ -68,9 +70,36 @@ class IncomingRequestRepositoryImpl @Inject constructor() : IncomingRequestRepos | |
} | ||
} | ||
|
||
/** | ||
* There are two path of execution when using this method: | ||
* - there is high priority screen in the queue, so the incoming request is added below it, | ||
* taking priority over requests currently in the queue | ||
* - there is no high priority screen: request is added at the top of queue and if there other request currently handled, | ||
* we send a dismiss event for it so that UI can react and dismiss handling, without removing it from the queue. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "there is no high priority screen: request is added at the top of queue and if there other request currently handled, ..." here you mean that if wallet receives another high priority request while another non high priority is being handled then we dismiss it and so on... right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually what I am thinking is that the term But what if we use I would like to hear the opinion of others. Also any other word is welcome! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh now I think There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, whenever this method is used, request added with it is supposed to go on screen while current one is deferred. This does not apply if we are in flows like creating accounts or other flows marked as high priority. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
wait I think I lost it here, you mean we really dismiss the request in this case? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no, we never dimiss when using addMobileConnectRequest(). It is just that we don't process it immediately. Example: when mobile connect request (MCR) comes in and we are in the middle of some other dApp login, dapp login is deferred and MCR takes over. But when we are in a wallet doing something, like account creation (high priority flow), then request is delivered after that particular screen/flow is complete. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nice thank you |
||
* Dismissed request will be handled again when top priority one handling completes | ||
jakub-rdx marked this conversation as resolved.
Show resolved
Hide resolved
|
||
*/ | ||
override suspend fun addFirst(incomingRequest: IncomingRequest) { | ||
mutex.withLock { | ||
if (requestQueue.firstOrNull() is QueueItem.HighPriorityScreen) { | ||
requestQueue.add(1, QueueItem.RequestItem(incomingRequest)) | ||
} else { | ||
requestQueue.addFirst(QueueItem.RequestItem(incomingRequest)) | ||
_currentRequestToHandle.value?.let { | ||
Timber.d("🗂 Dismissing request with id ${it.interactionId}") | ||
appEventBus.sendEvent(AppEvent.DismissRequestHandling(it.interactionId)) | ||
} | ||
handleNextRequest() | ||
Timber.d( | ||
"🗂 new incoming request with id ${incomingRequest.interactionId} " + | ||
"added in list, so size now is ${getAmountOfRequests()}" | ||
) | ||
} | ||
} | ||
} | ||
|
||
override suspend fun requestHandled(requestId: String) { | ||
mutex.withLock { | ||
requestQueue.removeIf { it is QueueItem.RequestItem && it.incomingRequest.interactionId.toString() == requestId } | ||
requestQueue.removeIf { it is QueueItem.RequestItem && it.incomingRequest.interactionId == requestId } | ||
handleNextRequest() | ||
Timber.d("🗂 request $requestId handled so size of list is now: ${getAmountOfRequests()}") | ||
} | ||
|
@@ -83,9 +112,11 @@ class IncomingRequestRepositoryImpl @Inject constructor() : IncomingRequestRepos | |
return | ||
} | ||
|
||
// Put high priority item below any internal request | ||
// Put high priority item below any internal request and mobile connect requests | ||
val topQueueItem = requestQueue.peekFirst() | ||
if (topQueueItem is QueueItem.RequestItem && topQueueItem.incomingRequest.isInternal) { | ||
if (topQueueItem is QueueItem.RequestItem && | ||
(topQueueItem.incomingRequest.isInternal || topQueueItem.incomingRequest.isMobileConnectRequest) | ||
) { | ||
requestQueue.add(1, QueueItem.HighPriorityScreen) | ||
} else { | ||
requestQueue.addFirst(QueueItem.HighPriorityScreen) | ||
|
@@ -104,37 +135,14 @@ class IncomingRequestRepositoryImpl @Inject constructor() : IncomingRequestRepos | |
} | ||
} | ||
|
||
override fun getUnauthorizedRequest(requestId: String): IncomingRequest.UnauthorizedRequest? { | ||
override fun getRequest(requestId: String): IncomingRequest? { | ||
val queueItem = requestQueue.find { | ||
it is QueueItem.RequestItem && it.incomingRequest.interactionId.toString() == requestId && | ||
it.incomingRequest is IncomingRequest.UnauthorizedRequest | ||
it is QueueItem.RequestItem && it.incomingRequest.interactionId == requestId | ||
} | ||
if (queueItem == null) { | ||
Timber.w("Unauthorized request with id $requestId is null") | ||
Timber.w("Request with id $requestId is null") | ||
} | ||
return (queueItem as? QueueItem.RequestItem)?.incomingRequest as? IncomingRequest.UnauthorizedRequest | ||
} | ||
|
||
override fun getTransactionWriteRequest(requestId: String): IncomingRequest.TransactionRequest? { | ||
val queueItem = requestQueue.find { | ||
it is QueueItem.RequestItem && it.incomingRequest.interactionId.toString() == requestId && | ||
it.incomingRequest is IncomingRequest.TransactionRequest | ||
} | ||
if (queueItem == null) { | ||
Timber.w("Transaction request with id $requestId is null") | ||
} | ||
return (queueItem as? QueueItem.RequestItem)?.incomingRequest as? IncomingRequest.TransactionRequest | ||
} | ||
|
||
override fun getAuthorizedRequest(requestId: String): IncomingRequest.AuthorizedRequest? { | ||
val queueItem = requestQueue.find { | ||
it is QueueItem.RequestItem && it.incomingRequest.interactionId.toString() == requestId && | ||
it.incomingRequest is IncomingRequest.AuthorizedRequest | ||
} | ||
if (queueItem == null) { | ||
Timber.w("Authorized request with id $requestId is null") | ||
} | ||
return (queueItem as? QueueItem.RequestItem)?.incomingRequest as? IncomingRequest.AuthorizedRequest | ||
return (queueItem as? QueueItem.RequestItem)?.incomingRequest | ||
} | ||
|
||
override fun removeAll() { | ||
|
@@ -156,7 +164,7 @@ class IncomingRequestRepositoryImpl @Inject constructor() : IncomingRequestRepos | |
|
||
private sealed interface QueueItem { | ||
data object HighPriorityScreen : QueueItem | ||
|
||
data class RequestItem(val incomingRequest: IncomingRequest) : QueueItem | ||
data class MobileConnectItem(val incomingRequest: IncomingRequest) : QueueItem | ||
} | ||
} |
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice that you added this here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actually can someone explain me what does this line do? Because I see it in the line 103, too.
Does it "clear" the intent with an empty bundle?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it removes
data
from an intent, so deep link is not delivered 2nd time if you move app to background and open from recentThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When the app is moved to background and re-opened from recent neither
onCreate
noronNewIntent
should get called in normal circumstances, unless the app task has been closed by the OS? Is that the case or there are simple repro steps for the issue that this line fixes? I'm really curious about what is happening.