Skip to content

Commit

Permalink
feat(network_wallet_services): AND-6684 Move STX config from Firebase…
Browse files Browse the repository at this point in the history
… to Network Config (#4125)
  • Loading branch information
dtverdota-bc committed Nov 22, 2022
1 parent c3c888f commit 1bd5a82
Show file tree
Hide file tree
Showing 18 changed files with 140 additions and 242 deletions.

This file was deleted.

6 changes: 0 additions & 6 deletions blockchainApi/src/main/java/com/blockchain/api/koin.kt
Expand Up @@ -20,7 +20,6 @@ import com.blockchain.api.blockchainCard.BlockchainCardApi
import com.blockchain.api.blockchainCard.WalletHelperUrl
import com.blockchain.api.brokerage.BrokerageApi
import com.blockchain.api.coinnetworks.CoinNetworkApiInterface
import com.blockchain.api.coinnetworks.MockInterceptor
import com.blockchain.api.custodial.CustodialBalanceApi
import com.blockchain.api.dataremediation.DataRemediationApi
import com.blockchain.api.eligibility.EligibilityApi
Expand Down Expand Up @@ -165,13 +164,8 @@ val blockchainApiModule = module {
.build()
}

single {
MockInterceptor()
}

single(kotlinXCoinApiRetrofit) {
val builder: OkHttpClient.Builder = get()
builder.addInterceptor(get<MockInterceptor>())
get<OkHttpLoggingInterceptors>().forEach {
builder.addInterceptor(it)
}
Expand Down
Expand Up @@ -10,6 +10,7 @@ import com.blockchain.api.assetdiscovery.data.FiatAsset
import com.blockchain.api.assetdiscovery.data.UnsupportedAsset
import com.blockchain.api.coinnetworks.CoinNetworkApiInterface
import com.blockchain.api.coinnetworks.data.CoinNetworkDto
import com.blockchain.api.coinnetworks.data.CoinTypeDto
import com.blockchain.domain.wallet.NetworkType
import com.blockchain.outcome.Outcome
import com.blockchain.outcome.flatMap
Expand Down Expand Up @@ -134,6 +135,11 @@ class AssetDiscoveryApiService internal constructor(
response.networks.filter { it.type != NetworkType.NOT_SUPPORTED }
}

suspend fun allCoinTypes(): Outcome<Exception, List<CoinTypeDto>> =
coinNetworkApi.getCoinNetworks().map { response ->
response.types.filter { it.type != NetworkType.NOT_SUPPORTED }
}

suspend fun getL2AssetsForEVM(evmTickers: List<String>): Outcome<Exception, DynamicAssetList> =
api.getL2CurrenciesForL1()
.flatMap { dto ->
Expand Down
Expand Up @@ -10,6 +10,7 @@ import com.blockchain.coincore.impl.CryptoNonCustodialAccount
import com.blockchain.core.chains.dynamicselfcustody.domain.NonCustodialService
import com.blockchain.core.payload.PayloadDataManager
import com.blockchain.core.price.ExchangeRatesDataManager
import com.blockchain.domain.wallet.CoinType
import com.blockchain.outcome.Outcome
import com.blockchain.outcome.flatMap
import com.blockchain.outcome.getOrDefault
Expand All @@ -20,7 +21,6 @@ import com.blockchain.unifiedcryptowallet.domain.wallet.NetworkWallet
import com.blockchain.utils.rxSingleOutcome
import info.blockchain.balance.AssetInfo
import info.blockchain.balance.Money
import info.blockchain.wallet.dynamicselfcustody.CoinConfiguration
import info.blockchain.wallet.dynamicselfcustody.DynamicHDAccount
import info.blockchain.wallet.keys.SigningKey
import io.reactivex.rxjava3.core.Completable
Expand All @@ -34,15 +34,15 @@ import org.spongycastle.util.encoders.Hex
class DynamicNonCustodialAccount(
val payloadManager: PayloadDataManager,
assetInfo: AssetInfo,
coinConfiguration: CoinConfiguration,
coinType: CoinType,
override val addressResolver: AddressResolver,
private val nonCustodialService: NonCustodialService,
override val exchangeRates: ExchangeRatesDataManager,
override val label: String,
private val walletPreferences: WalletStatusPrefs
) : CryptoNonCustodialAccount(assetInfo), NetworkWallet {

private val internalAccount: DynamicHDAccount = payloadManager.getDynamicHdAccount(coinConfiguration)
private val internalAccount: DynamicHDAccount = payloadManager.getDynamicHdAccount(coinType)
?: throw IllegalStateException("Unsupported Coin Configuration!")

override val receiveAddress: Single<ReceiveAddress>
Expand Down
Expand Up @@ -26,12 +26,12 @@ internal class DynamicSelfCustodyAsset(

override fun loadNonCustodialAccounts(labels: DefaultLabels): Single<SingleAccountList> =
rxSingle {
selfCustodyService.getCoinConfigurationFor(currency)?.let { coinConfiguration ->
selfCustodyService.getCoinTypeFor(currency)?.let { coinType ->
listOf(
DynamicNonCustodialAccount(
payloadManager,
currency,
coinConfiguration,
coinType,
addressResolver,
selfCustodyService,
exchangeRates,
Expand Down
Expand Up @@ -18,6 +18,7 @@ enum class NetworkType {
EVM,
BTC,
XLM,
STX,
NOT_SUPPORTED
}

Expand Down
@@ -0,0 +1,10 @@
package com.blockchain.domain.wallet

import kotlinx.serialization.Serializable

@Serializable
data class CoinType(
val network: NetworkType,
val type: Int,
val purpose: Int
)
@@ -0,0 +1,35 @@
package com.blockchain.core.chains.dynamicselfcustody.data

import com.blockchain.api.coinnetworks.data.CoinTypeDto
import com.blockchain.api.services.AssetDiscoveryApiService
import com.blockchain.store.Fetcher
import com.blockchain.store.Store
import com.blockchain.store.impl.Freshness
import com.blockchain.store.impl.FreshnessMediator
import com.blockchain.store_caches_persistedjsonsqldelight.PersistedJsonSqlDelightStoreBuilder
import com.blockchain.storedatasource.FlushableDataSource
import kotlinx.serialization.builtins.ListSerializer

class CoinTypeStore(
private val discoveryService: AssetDiscoveryApiService
) : Store<List<CoinTypeDto>> by PersistedJsonSqlDelightStoreBuilder()
.build(
storeId = STORE_ID,
fetcher = Fetcher.ofOutcome(
mapper = {
discoveryService.allCoinTypes()
}
),
dataSerializer = ListSerializer(CoinTypeDto.serializer()),
mediator = FreshnessMediator(Freshness.DURATION_24_HOURS)
),
FlushableDataSource {

override fun invalidate() {
markAsStale()
}

companion object {
private const val STORE_ID = "CoinTypeStore"
}
}

0 comments on commit 1bd5a82

Please sign in to comment.