diff --git a/app/build.gradle b/app/build.gradle index c28376784a..8771cec1c3 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -93,7 +93,7 @@ dependencies { implementation 'com.google.android.play:core-ktx:1.8.1' coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.5' - implementation 'com.tangem:blockchain:develop-76' + implementation 'com.tangem:blockchain:develop-77' implementation 'com.tangem.tangem-sdk-kotlin:core:develop-142' implementation 'com.tangem.tangem-sdk-kotlin:android:develop-142' diff --git a/app/src/main/java/com/tangem/tap/domain/statePrinter/ScanResponseConverter.kt b/app/src/main/java/com/tangem/tap/domain/statePrinter/ScanResponseConverter.kt new file mode 100644 index 0000000000..f8597dc48b --- /dev/null +++ b/app/src/main/java/com/tangem/tap/domain/statePrinter/ScanResponseConverter.kt @@ -0,0 +1,46 @@ +package com.tangem.tap.domain.statePrinter + +import com.tangem.common.extensions.toHexString +import com.tangem.common.json.MoshiJsonConverter +import com.tangem.domain.redux.state.StringStateConverter +import com.tangem.tap.common.redux.AppState +import com.tangem.tap.store +import timber.log.Timber + +/** +[REDACTED_AUTHOR] + */ +class ScanResponseConverter : StringStateConverter { + private val converter = MoshiJsonConverter.INSTANCE + + override fun convert(stateHolder: AppState): String { + val scanResponse = stateHolder.globalState.scanResponse ?: return "NULL" + + val scanResponseMap = mutableMapOf() + val derivedKeysMap = mutableMapOf() + scanResponse.derivedKeys.forEach { (keyWalletPubKey, mapExPubKeys) -> + val exPubKeysMap = mapExPubKeys.entries.map { (derivationPath, exPubKey) -> + mapOf( + "derivationPath" to derivationPath.rawPath, + "extendedPublicKey" to mapOf( + "publicKey" to exPubKey.publicKey.toHexString(), + "chainCode" to exPubKey.chainCode.toHexString(), + ), + ) + } + derivedKeysMap[keyWalletPubKey.bytes.toHexString()] = exPubKeysMap + + } + scanResponseMap["derivedKeys"] = derivedKeysMap + + val json = converter.prettyPrint(scanResponseMap) + + return json + + } +} + +fun printScanResponseState() { + val stringState = ScanResponseConverter().convert(store.state) + Timber.d(stringState) +} \ No newline at end of file diff --git a/app/src/main/java/com/tangem/tap/domain/statePrinter/WalletStateConverter.kt b/app/src/main/java/com/tangem/tap/domain/statePrinter/WalletStateConverter.kt new file mode 100644 index 0000000000..07ac4886bb --- /dev/null +++ b/app/src/main/java/com/tangem/tap/domain/statePrinter/WalletStateConverter.kt @@ -0,0 +1,69 @@ +package com.tangem.tap.domain.statePrinter + +import com.tangem.blockchain.common.Wallet +import com.tangem.common.json.MoshiJsonConverter +import com.tangem.domain.redux.state.StringStateConverter +import com.tangem.tap.common.redux.AppState +import com.tangem.tap.store +import timber.log.Timber + +/** +[REDACTED_AUTHOR] + */ +class WalletStateConverter : StringStateConverter { + private val converter = MoshiJsonConverter.INSTANCE + + override fun convert(stateHolder: AppState): String { + val walletState = stateHolder.walletState + + val walletManagers = mutableListOf>() + walletState.walletManagers.forEach { + val wallet = it.wallet + + val walletManagerMap = mutableMapOf() + walletManagerMap["walletManager"] = mapOf( + "wallet" to convertWallet(it.wallet), + ) + + walletManagers.add(walletManagerMap) + } + val json = converter.prettyPrint(walletManagers) + return json + } + + private fun convertWallet(wallet: Wallet): MutableMap { + val walletMap = mutableMapOf() + val amounts = mutableMapOf() + wallet.amounts.forEach { (type, amount) -> + val amountMap = mapOf( + "value" to amount.value?.toPlainString(), + "currencySymbol" to amount.currencySymbol, + "decimals" to amount.decimals, + "type" to amount.type::class.java.simpleName, + ) + amounts[type::class.java.simpleName] = amountMap + } + + val publicKeyMap = mapOf( + "seedKey" to wallet.publicKey.seedKey, + "derivedKey" to wallet.publicKey.derivedKey, + "derivationPath" to wallet.publicKey.derivationPath?.rawPath, + "blockchainKey" to wallet.publicKey.blockchainKey, + ) + + walletMap["address"] = wallet.address + walletMap["blockchain"] = wallet.blockchain.name + walletMap["curve"] = wallet.blockchain.getSupportedCurves()[0].curve + walletMap["publicKey"] = publicKeyMap + walletMap["amounts"] = amounts + walletMap["addresses"] = wallet.addresses.toString() + walletMap["cardId"] = wallet.cardId + + return walletMap + } +} + +fun printWalletState() { + val stringState = WalletStateConverter().convert(store.state) + Timber.d(stringState) +} \ No newline at end of file diff --git a/app/src/main/java/com/tangem/tap/features/wallet/ui/WalletFragment.kt b/app/src/main/java/com/tangem/tap/features/wallet/ui/WalletFragment.kt index f06904cec2..f633010d0a 100644 --- a/app/src/main/java/com/tangem/tap/features/wallet/ui/WalletFragment.kt +++ b/app/src/main/java/com/tangem/tap/features/wallet/ui/WalletFragment.kt @@ -20,6 +20,8 @@ import com.tangem.tap.common.redux.global.GlobalAction import com.tangem.tap.common.redux.navigation.AppScreen import com.tangem.tap.common.redux.navigation.NavigationAction import com.tangem.tap.domain.configurable.warningMessage.WarningMessage +import com.tangem.tap.domain.statePrinter.printScanResponseState +import com.tangem.tap.domain.statePrinter.printWalletState import com.tangem.tap.domain.termsOfUse.CardTou import com.tangem.tap.features.details.redux.DetailsAction import com.tangem.tap.features.wallet.redux.* @@ -29,6 +31,7 @@ import com.tangem.tap.features.wallet.ui.wallet.MultiWalletView import com.tangem.tap.features.wallet.ui.wallet.SingleWalletView import com.tangem.tap.features.wallet.ui.wallet.WalletView import com.tangem.tap.store +import com.tangem.wallet.BuildConfig import com.tangem.wallet.R import com.tangem.wallet.databinding.FragmentWalletBinding import org.rekotlin.StoreSubscriber @@ -80,6 +83,16 @@ class WalletFragment : Fragment(R.layout.fragment_wallet), StoreSubscriber { +class AddCustomTokenActionStateConverter : StringActionConverter { private val jsonConverter: MoshiJsonConverter = MoshiJsonConverter.INSTANCE private var builder: StringBuilder = StringBuilder() - override fun print(action: Action, domainState: DomainState): String? { + override fun convert(action: Action, stateHolder: DomainState): String? { val action = (action as? AddCustomTokenAction) ?: return null - val state = domainState.addCustomTokensState + val state = stateHolder.addCustomTokensState val fieldConverter = FieldToJsonConverter(listOf( CustomTokenFieldId.ContractAddress, CustomTokenFieldId.Network, @@ -43,8 +43,6 @@ class AddCustomTokenStatePrinter : StatePrinter { + fun convert(stateHolder: StateHolder): String +} + +interface StringActionConverter { + fun convert(action: Action, stateHolder: StateHolder): String? +} \ No newline at end of file diff --git a/domain/src/main/java/com/tangem/domain/redux/state/StateObservables.kt b/domain/src/main/java/com/tangem/domain/redux/state/StateObservables.kt index 233bbaa618..2195ec8645 100644 --- a/domain/src/main/java/com/tangem/domain/redux/state/StateObservables.kt +++ b/domain/src/main/java/com/tangem/domain/redux/state/StateObservables.kt @@ -1,6 +1,6 @@ package com.tangem.domain.redux.state -import com.tangem.domain.features.addCustomToken.AddCustomTokenStatePrinter +import com.tangem.domain.features.addCustomToken.AddCustomTokenActionStateConverter import com.tangem.domain.features.addCustomToken.redux.AddCustomTokenAction import com.tangem.domain.redux.DomainState import org.rekotlin.Action @@ -20,17 +20,17 @@ internal fun observeReducedStates(reducedSates: List>) private fun logStates(reducedSates: List>) { reducedSates.forEach { - val printer = statePrinters.firstNotNullOfOrNull { entry -> + val converter = stateConverters.firstNotNullOfOrNull { entry -> if (entry.key.isAssignableFrom(it.first::class.java)) entry.value else null } ?: return@forEach - val messageToPrint = printer.print(it.first, it.second) ?: return@forEach + val messageToPrint = converter.convert(it.first, it.second) ?: return@forEach Timber.d(messageToPrint) } } // TODO: refactoring: mutate to factory -private val statePrinters = mutableMapOf( - AddCustomTokenAction::class.java to AddCustomTokenStatePrinter() +private val stateConverters = mutableMapOf( + AddCustomTokenAction::class.java to AddCustomTokenActionStateConverter() ) \ No newline at end of file diff --git a/domain/src/main/java/com/tangem/domain/redux/state/StatePrinter.kt b/domain/src/main/java/com/tangem/domain/redux/state/StatePrinter.kt deleted file mode 100644 index 8f617eea4d..0000000000 --- a/domain/src/main/java/com/tangem/domain/redux/state/StatePrinter.kt +++ /dev/null @@ -1,12 +0,0 @@ -package com.tangem.domain.redux.state - -import com.tangem.domain.redux.DomainState -import org.rekotlin.Action - -/** -[REDACTED_AUTHOR] - */ -interface StatePrinter { - fun print(action: Action, domainState: DomainState): String? - fun getStateObject(domainState: DomainState): S -} \ No newline at end of file