Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(unified_activity): AND-6698 Unified Activity Websocket (#4092)
- Loading branch information
1 parent
086216b
commit 34bdc95
Showing
23 changed files
with
352 additions
and
3,683 deletions.
There are no files selected for viewing
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
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
39 changes: 0 additions & 39 deletions
39
blockchainApi/src/main/java/com/blockchain/api/selfcustody/ActivityRequest.kt
This file was deleted.
Oops, something went wrong.
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
27 changes: 27 additions & 0 deletions
27
blockchainApi/src/main/java/com/blockchain/api/selfcustody/activity/ActivityRequest.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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.blockchain.api.selfcustody.activity | ||
|
||
import com.blockchain.api.selfcustody.AuthInfo | ||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class ActivityRequest( | ||
@SerialName("auth") | ||
val auth: AuthInfo, | ||
@SerialName("params") | ||
val params: ActivityRequestParams, | ||
@SerialName("action") | ||
val action: String, | ||
@SerialName("channel") | ||
val channel: String | ||
) | ||
|
||
@Serializable | ||
data class ActivityRequestParams( | ||
@SerialName("timezoneIana") | ||
val timezone: String, | ||
@SerialName("fiatCurrency") | ||
val fiatCurrency: String, | ||
@SerialName("acceptLanguage") | ||
val acceptLanguage: String | ||
) |
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
7 changes: 7 additions & 0 deletions
7
blockchainApi/src/main/java/com/blockchain/api/services/ActivityCacheService.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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.blockchain.api.services | ||
|
||
import com.blockchain.api.selfcustody.activity.ActivityResponse | ||
|
||
interface ActivityCacheService { | ||
fun addOrUpdateActivityItems(items: ActivityResponse) | ||
} |
59 changes: 59 additions & 0 deletions
59
blockchainApi/src/main/java/com/blockchain/api/services/ActivityWebSocketService.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 |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package com.blockchain.api.services | ||
|
||
import com.blockchain.api.selfcustody.AuthInfo | ||
import com.blockchain.api.selfcustody.activity.ActivityRequest | ||
import com.blockchain.api.selfcustody.activity.ActivityRequestParams | ||
import com.blockchain.api.selfcustody.activity.ActivityResponse | ||
import com.blockchain.network.websocket.WebSocket | ||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.flow.collect | ||
import kotlinx.coroutines.launch | ||
import kotlinx.coroutines.rx3.asFlow | ||
|
||
class ActivityWebSocketService( | ||
private val webSocket: WebSocket<ActivityRequest, ActivityResponse>, | ||
private val activityCacheService: ActivityCacheService, | ||
private val credentials: SelfCustodyServiceAuthCredentials, | ||
private val wsScope: CoroutineScope | ||
) { | ||
private val authInfo: AuthInfo | ||
get() = AuthInfo( | ||
guidHash = credentials.hashedGuid, | ||
sharedKeyHash = credentials.hashedSharedKey, | ||
) | ||
|
||
fun open() { | ||
webSocket.open() | ||
} | ||
|
||
fun send(fiatCurrency: String, acceptLanguage: String, timeZone: String) { | ||
webSocket.send( | ||
ActivityRequest( | ||
auth = authInfo, | ||
params = ActivityRequestParams( | ||
timezone = timeZone, | ||
fiatCurrency = fiatCurrency, | ||
acceptLanguage = acceptLanguage // "en-GB;q=1.0, en" | ||
), | ||
action = UNIFIED_ACTIVITY_WS_ACTION, | ||
channel = UNIFIED_ACTIVITY_WS_CHANNEL | ||
) | ||
) | ||
} | ||
|
||
suspend fun subscribeToActivity() = wsScope.launch { | ||
webSocket.responses.asFlow() | ||
.collect { | ||
activityCacheService.addOrUpdateActivityItems(it) | ||
} | ||
} | ||
|
||
fun stop() { | ||
webSocket.close() | ||
} | ||
|
||
companion object { | ||
private const val UNIFIED_ACTIVITY_WS_ACTION = "subscribe" | ||
private const val UNIFIED_ACTIVITY_WS_CHANNEL = "activity" | ||
} | ||
} |
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.