2020-06-10 00:08:19 -07:00
|
|
|
package cash.z.ecc.android.sdk.demoapp.demos.getaddress
|
2019-10-21 03:17:07 -07:00
|
|
|
|
2020-08-13 18:08:01 -07:00
|
|
|
import android.os.Bundle
|
2019-10-21 03:17:07 -07:00
|
|
|
import android.view.LayoutInflater
|
2022-12-14 07:33:18 -08:00
|
|
|
import android.view.View
|
|
|
|
import androidx.lifecycle.Lifecycle
|
2021-10-21 13:05:02 -07:00
|
|
|
import androidx.lifecycle.lifecycleScope
|
2022-12-14 07:33:18 -08:00
|
|
|
import androidx.lifecycle.repeatOnLifecycle
|
2020-06-10 00:08:19 -07:00
|
|
|
import cash.z.ecc.android.sdk.demoapp.BaseDemoFragment
|
|
|
|
import cash.z.ecc.android.sdk.demoapp.databinding.FragmentGetAddressBinding
|
2021-09-04 04:05:41 -07:00
|
|
|
import cash.z.ecc.android.sdk.demoapp.ext.requireApplicationContext
|
2022-12-23 02:00:37 -08:00
|
|
|
import cash.z.ecc.android.sdk.demoapp.type.fromResources
|
2022-12-13 05:25:09 -08:00
|
|
|
import cash.z.ecc.android.sdk.demoapp.util.ProvideAddressBenchmarkTrace
|
2022-08-02 06:29:09 -07:00
|
|
|
import cash.z.ecc.android.sdk.model.ZcashNetwork
|
2020-09-11 00:16:46 -07:00
|
|
|
import cash.z.ecc.android.sdk.tool.DerivationTool
|
2022-08-04 10:09:19 -07:00
|
|
|
import cash.z.ecc.android.sdk.type.UnifiedFullViewingKey
|
2022-12-14 07:33:18 -08:00
|
|
|
import kotlinx.coroutines.flow.filterNotNull
|
2021-10-21 13:05:02 -07:00
|
|
|
import kotlinx.coroutines.launch
|
2019-10-21 03:17:07 -07:00
|
|
|
|
2020-02-27 00:25:07 -08:00
|
|
|
/**
|
|
|
|
* Displays the address associated with the seed defined by the default config. To modify the seed
|
|
|
|
* that is used, update the `DemoConfig.seedWords` value.
|
|
|
|
*/
|
2019-10-21 03:17:07 -07:00
|
|
|
class GetAddressFragment : BaseDemoFragment<FragmentGetAddressBinding>() {
|
|
|
|
|
2022-08-04 10:09:19 -07:00
|
|
|
private lateinit var viewingKey: UnifiedFullViewingKey
|
2019-10-21 03:17:07 -07:00
|
|
|
|
2020-09-11 00:16:46 -07:00
|
|
|
private fun displayAddress() {
|
2022-12-14 07:33:18 -08:00
|
|
|
viewLifecycleOwner.lifecycleScope.launch {
|
|
|
|
viewLifecycleOwner.repeatOnLifecycle(Lifecycle.State.STARTED) {
|
|
|
|
launch {
|
|
|
|
sharedViewModel.synchronizerFlow.filterNotNull().collect { synchronizer ->
|
|
|
|
binding.unifiedAddress.apply {
|
|
|
|
reportTraceEvent(ProvideAddressBenchmarkTrace.Event.UNIFIED_ADDRESS_START)
|
|
|
|
val uaddress = synchronizer.getUnifiedAddress()
|
|
|
|
reportTraceEvent(ProvideAddressBenchmarkTrace.Event.UNIFIED_ADDRESS_END)
|
|
|
|
text = uaddress
|
|
|
|
setOnClickListener { copyToClipboard(uaddress) }
|
|
|
|
}
|
|
|
|
binding.saplingAddress.apply {
|
|
|
|
reportTraceEvent(ProvideAddressBenchmarkTrace.Event.SAPLING_ADDRESS_START)
|
|
|
|
val sapling = synchronizer.getSaplingAddress()
|
|
|
|
reportTraceEvent(ProvideAddressBenchmarkTrace.Event.SAPLING_ADDRESS_END)
|
|
|
|
text = sapling
|
|
|
|
setOnClickListener { copyToClipboard(sapling) }
|
|
|
|
}
|
|
|
|
binding.transparentAddress.apply {
|
|
|
|
reportTraceEvent(ProvideAddressBenchmarkTrace.Event.TRANSPARENT_ADDRESS_START)
|
|
|
|
val transparent = synchronizer.getTransparentAddress()
|
|
|
|
reportTraceEvent(ProvideAddressBenchmarkTrace.Event.TRANSPARENT_ADDRESS_END)
|
|
|
|
text = transparent
|
|
|
|
setOnClickListener { copyToClipboard(transparent) }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-11-02 09:39:48 -07:00
|
|
|
}
|
2021-10-21 13:05:02 -07:00
|
|
|
}
|
2019-10-21 03:17:07 -07:00
|
|
|
}
|
|
|
|
|
2020-08-13 18:08:01 -07:00
|
|
|
//
|
|
|
|
// Android Lifecycle overrides
|
|
|
|
//
|
|
|
|
|
2021-09-04 04:05:41 -07:00
|
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
|
|
super.onCreate(savedInstanceState)
|
2022-12-13 05:25:09 -08:00
|
|
|
reportTraceEvent(ProvideAddressBenchmarkTrace.Event.ADDRESS_SCREEN_START)
|
2020-08-13 18:08:01 -07:00
|
|
|
}
|
|
|
|
|
2022-12-14 07:33:18 -08:00
|
|
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
|
|
|
super.onViewCreated(view, savedInstanceState)
|
|
|
|
|
2020-08-13 18:08:01 -07:00
|
|
|
displayAddress()
|
|
|
|
}
|
|
|
|
|
2022-12-13 05:25:09 -08:00
|
|
|
override fun onDestroy() {
|
|
|
|
super.onDestroy()
|
|
|
|
reportTraceEvent(ProvideAddressBenchmarkTrace.Event.ADDRESS_SCREEN_END)
|
|
|
|
}
|
|
|
|
|
2020-08-13 18:08:01 -07:00
|
|
|
//
|
|
|
|
// Base Fragment overrides
|
|
|
|
//
|
|
|
|
|
2020-02-25 23:43:27 -08:00
|
|
|
override fun onActionButtonClicked() {
|
2021-10-21 13:05:02 -07:00
|
|
|
viewLifecycleOwner.lifecycleScope.launch {
|
|
|
|
copyToClipboard(
|
2022-08-04 10:09:19 -07:00
|
|
|
DerivationTool.deriveUnifiedAddress(
|
|
|
|
viewingKey.encoding,
|
2021-10-21 13:05:02 -07:00
|
|
|
ZcashNetwork.fromResources(requireApplicationContext())
|
|
|
|
),
|
2022-08-04 10:09:19 -07:00
|
|
|
"Unified address copied to clipboard!"
|
2021-10-21 13:05:02 -07:00
|
|
|
)
|
|
|
|
}
|
2019-10-21 03:17:07 -07:00
|
|
|
}
|
2020-02-25 23:43:27 -08:00
|
|
|
|
2020-08-13 18:08:01 -07:00
|
|
|
override fun inflateBinding(layoutInflater: LayoutInflater): FragmentGetAddressBinding =
|
|
|
|
FragmentGetAddressBinding.inflate(layoutInflater)
|
2020-06-09 20:28:21 -07:00
|
|
|
}
|