Skip to content

Commit

Permalink
feat(network_wallet_services): AND-6799 Support Different PubKey Styl…
Browse files Browse the repository at this point in the history
…es (#4140)
  • Loading branch information
dtverdota-bc committed Nov 23, 2022
1 parent 65eb7f5 commit 50a0a0b
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 5 deletions.
Expand Up @@ -139,6 +139,8 @@ class DynamicSelfCustodyService(
txId: String,
network: String,
pubKey: String,
pubKeyStyle: PubKeyStyle,
pubKeyDescriptor: String,
timeZone: String,
locales: String,
fiatCurrency: String
Expand All @@ -149,8 +151,8 @@ class DynamicSelfCustodyService(
network = network,
pubKey = ActivityPubKeyInfo(
pubKey = pubKey,
style = PubKeyStyle.SINGLE,
descriptor = "legacy"
style = pubKeyStyle,
descriptor = pubKeyDescriptor
),
params = LocalisationParams(
timeZone = timeZone,
Expand Down
Expand Up @@ -83,6 +83,9 @@ import org.bitcoinj.core.LegacyAddress
override val index: Int
get() = addressIndex

override val pubKeyDescriptor
get() = BCH_PUBKEY_DESCRIPTOR

override val style: PubKeyStyle
get() = PubKeyStyle.EXTENDED

Expand Down Expand Up @@ -195,5 +198,7 @@ import org.bitcoinj.core.LegacyAddress
refreshTrigger = refreshTrigger,
addressResolver = addressResolver
)

const val BCH_PUBKEY_DESCRIPTOR = "p2pkh"
}
}
Expand Up @@ -112,6 +112,9 @@ import io.reactivex.rxjava3.core.Single
override val descriptor: Int
get() = MULTIPLE_ADDRESSES_DESCRIPTOR

override val pubKeyDescriptor
get() = BTC_PUBKEY_DESCRIPTOR

override val style: PubKeyStyle
get() = PubKeyStyle.EXTENDED

Expand Down Expand Up @@ -319,5 +322,7 @@ import io.reactivex.rxjava3.core.Single
)

private const val IMPORTED_ACCOUNT_NO_INDEX = Int.MAX_VALUE

private const val BTC_PUBKEY_DESCRIPTOR = "p2wpkh"
}
}
Expand Up @@ -17,6 +17,7 @@ data class CoinNetwork(
enum class NetworkType {
EVM,
BTC,
BCH,
XLM,
STX,
NOT_SUPPORTED
Expand Down
Expand Up @@ -7,6 +7,7 @@ import com.blockchain.componentlib.utils.TextValue
import com.blockchain.data.DataResource
import com.blockchain.data.map
import com.blockchain.data.updateDataWith
import com.blockchain.domain.wallet.PubKeyStyle
import com.blockchain.home.presentation.activity.common.toActivityComponent
import com.blockchain.home.presentation.activity.common.toStackedIcon
import com.blockchain.home.presentation.activity.detail.ActivityDetail
Expand All @@ -17,6 +18,7 @@ import com.blockchain.home.presentation.activity.detail.ActivityDetailViewState
import com.blockchain.home.presentation.dashboard.HomeNavEvent
import com.blockchain.unifiedcryptowallet.domain.activity.model.ActivityDetailGroups
import com.blockchain.unifiedcryptowallet.domain.activity.service.UnifiedActivityService
import com.blockchain.unifiedcryptowallet.domain.wallet.NetworkWalletService
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.Job
import kotlinx.coroutines.flow.collect
Expand All @@ -27,7 +29,8 @@ import kotlinx.coroutines.launch

class ActivityDetailViewModel(
private val activityTxId: String,
private val unifiedActivityService: UnifiedActivityService
private val unifiedActivityService: UnifiedActivityService,
private val networkWalletService: NetworkWalletService
) : MviViewModel<
ActivityDetailIntent<ActivityDetailGroups>,
ActivityDetailViewState,
Expand Down Expand Up @@ -86,10 +89,15 @@ class ActivityDetailViewModel(
is DataResource.Data -> {
with(summaryDataResource.data) {
// todo(othman) real values
val networkWalletGroup = networkWalletService.networkWalletGroup(network)
val pubKeyStyle = networkWalletGroup?.pubKeyStyle() ?: PubKeyStyle.SINGLE
val pubKeyDescriptor = networkWalletGroup?.pubKeyDescriptor() ?: "legacy"
unifiedActivityService.getActivityDetails(
txId = txId,
network = network,
pubKey = pubkey,
pubKeyStyle = pubKeyStyle,
pubKeyDescriptor = pubKeyDescriptor,
locales = "en-GB;q=1.0, en",
timeZone = "Europe/London"
)
Expand Down
Expand Up @@ -37,7 +37,8 @@ val homePresentationModule = module {
viewModel { (txId: String) ->
ActivityDetailViewModel(
activityTxId = txId,
unifiedActivityService = get()
unifiedActivityService = get(),
networkWalletService = get()
)
}

Expand Down
Expand Up @@ -2,6 +2,7 @@ package com.blockchain.unifiedcryptowallet.data.activity.datasource

import com.blockchain.api.selfcustody.activity.ActivityDetailGroupsDto
import com.blockchain.api.services.DynamicSelfCustodyService
import com.blockchain.domain.wallet.PubKeyStyle
import com.blockchain.preferences.CurrencyPrefs
import com.blockchain.store.Fetcher
import com.blockchain.store.KeyedStore
Expand All @@ -23,6 +24,8 @@ class ActivityDetailsStore(
txId = key.txId,
network = key.network,
pubKey = key.pubKey,
pubKeyStyle = key.pubKeyStyle,
pubKeyDescriptor = key.pubKeyDescriptor,
timeZone = key.timeZone,
locales = key.locales,
fiatCurrency = currencyPrefs.selectedFiatCurrency.networkTicker
Expand All @@ -40,6 +43,8 @@ class ActivityDetailsStore(
val txId: String,
val network: String,
val pubKey: String,
val pubKeyStyle: PubKeyStyle,
val pubKeyDescriptor: String,
val locales: String,
val timeZone: String
)
Expand Down
Expand Up @@ -6,6 +6,7 @@ import com.blockchain.api.services.ActivityWebSocketService
import com.blockchain.data.DataResource
import com.blockchain.data.FreshnessStrategy
import com.blockchain.data.FreshnessStrategy.Companion.withKey
import com.blockchain.domain.wallet.PubKeyStyle
import com.blockchain.preferences.CurrencyPrefs
import com.blockchain.store.mapData
import com.blockchain.unifiedcryptowallet.data.activity.datasource.ActivityDetailsStore
Expand Down Expand Up @@ -76,14 +77,16 @@ class UnifiedActivityRepository(
txId: String,
network: String,
pubKey: String,
pubKeyStyle: PubKeyStyle,
pubKeyDescriptor: String,
locales: String,
timeZone: String,
freshnessStrategy: FreshnessStrategy
): Flow<DataResource<ActivityDetailGroups>> {
return activityDetailsStore.stream(
freshnessStrategy.withKey(
ActivityDetailsStore.Key(
txId, network, pubKey, locales, timeZone
txId, network, pubKey, pubKeyStyle, pubKeyDescriptor, locales, timeZone
)
)
)
Expand Down
Expand Up @@ -2,6 +2,7 @@ package com.blockchain.unifiedcryptowallet.domain.activity.service

import com.blockchain.data.DataResource
import com.blockchain.data.FreshnessStrategy
import com.blockchain.domain.wallet.PubKeyStyle
import com.blockchain.unifiedcryptowallet.domain.activity.model.ActivityDetailGroups
import com.blockchain.unifiedcryptowallet.domain.activity.model.UnifiedActivityItem
import kotlinx.coroutines.flow.Flow
Expand All @@ -20,6 +21,8 @@ interface UnifiedActivityService {
txId: String,
network: String,
pubKey: String,
pubKeyStyle: PubKeyStyle,
pubKeyDescriptor: String,
locales: String,
timeZone: String,
freshnessStrategy: FreshnessStrategy = FreshnessStrategy.Cached(forceRefresh = true)
Expand Down
Expand Up @@ -34,12 +34,16 @@ interface NetworkWallet {
val style: PubKeyStyle
get() = PubKeyStyle.SINGLE

val pubKeyDescriptor: String
get() = LEGACY_DESCRIPTOR

suspend fun publicKey(): String

companion object {
const val DEFAULT_SINGLE_ACCOUNT_INDEX = 0
const val DEFAULT_ADDRESS_DESCRIPTOR = 0
const val MULTIPLE_ADDRESSES_DESCRIPTOR = 1
const val LEGACY_DESCRIPTOR = "legacy"
}
}

Expand Down Expand Up @@ -81,6 +85,10 @@ class NetworkWalletGroup(
return parentChainNetwork.publicKey()
}

fun pubKeyStyle(): PubKeyStyle = parentChainNetwork.style

fun pubKeyDescriptor(): String = parentChainNetwork.pubKeyDescriptor

fun getNetworkWallet(currency: Currency): NetworkWallet? {
return networkWallets.firstOrNull { it.currency.networkTicker == currency.networkTicker }
}
Expand Down

0 comments on commit 50a0a0b

Please sign in to comment.