[#285] Apply ktlint to demo-app
In the process of refactoring the Gradle scripts, ktlint now is applied to all Gradle modules. The demo-app hadn't been linted before, so this applies a series of minor autocorrections to this module.
This commit is contained in:
parent
07d02e6cea
commit
283718de94
|
@ -1,18 +1,17 @@
|
|||
package cash.z.ecc.android.sdk.sample.demoapp
|
||||
|
||||
import androidx.test.platform.app.InstrumentationRegistry
|
||||
import cash.z.ecc.android.sdk.Initializer
|
||||
import cash.z.ecc.android.sdk.Synchronizer
|
||||
import cash.z.ecc.android.sdk.entity.isFailure
|
||||
import cash.z.ecc.android.sdk.transaction.*
|
||||
import cash.z.ecc.android.sdk.ext.*
|
||||
import cash.z.ecc.android.sdk.ext.TroubleshootingTwig
|
||||
import cash.z.ecc.android.sdk.ext.Twig
|
||||
import cash.z.ecc.android.sdk.ext.ZcashSdk
|
||||
import cash.z.ecc.android.sdk.jni.RustBackend
|
||||
import cash.z.ecc.android.sdk.service.LightWalletGrpcService
|
||||
import kotlinx.coroutines.cancel
|
||||
import cash.z.ecc.android.sdk.transaction.PagedTransactionRepository
|
||||
import cash.z.ecc.android.sdk.transaction.WalletTransactionEncoder
|
||||
import kotlinx.coroutines.flow.collect
|
||||
import kotlinx.coroutines.flow.first
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import org.junit.Assert.*
|
||||
import org.junit.BeforeClass
|
||||
import org.junit.Ignore
|
||||
import org.junit.Test
|
||||
|
@ -45,8 +44,7 @@ class SampleCodeTest {
|
|||
// log(entropy.asSeedPhrase())
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
// ///////////////////////////////////////////////////
|
||||
// Derive Extended Spending Key
|
||||
@Test fun deriveSpendingKey() {
|
||||
val spendingKeys = RustBackend().deriveSpendingKeys(seed)
|
||||
|
@ -54,7 +52,7 @@ class SampleCodeTest {
|
|||
log("Spending Key: ${spendingKeys?.get(0)}")
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
// ///////////////////////////////////////////////////
|
||||
// Get Address
|
||||
@Test fun getAddress() = runBlocking {
|
||||
val address = synchronizer.getAddress()
|
||||
|
@ -62,10 +60,9 @@ class SampleCodeTest {
|
|||
log("Address: $address")
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
// ///////////////////////////////////////////////////
|
||||
// Derive address from Extended Full Viewing Key
|
||||
@Test fun getAddressFromViewingKey() {
|
||||
|
||||
}
|
||||
|
||||
// ///////////////////////////////////////////////////
|
||||
|
@ -91,13 +88,11 @@ class SampleCodeTest {
|
|||
// ///////////////////////////////////////////////////
|
||||
// Query account outgoing transactions
|
||||
@Test fun queryOutgoingTransactions() {
|
||||
|
||||
}
|
||||
|
||||
// ///////////////////////////////////////////////////
|
||||
// Query account incoming transactions
|
||||
@Test fun queryIncomingTransactions() {
|
||||
|
||||
}
|
||||
|
||||
// ///////////////////////////////////////////////////
|
||||
|
@ -131,10 +126,9 @@ class SampleCodeTest {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////
|
||||
// /////////////////////////////////////////////////////
|
||||
// Utility Functions
|
||||
//////////////////////////////////////////////////////
|
||||
// ////////////////////////////////////////////////////
|
||||
|
||||
companion object {
|
||||
private val seed = "Insert seed for testing".toByteArray()
|
||||
|
|
|
@ -12,8 +12,6 @@ import androidx.fragment.app.Fragment
|
|||
import androidx.fragment.app.activityViewModels
|
||||
import androidx.viewbinding.ViewBinding
|
||||
import cash.z.ecc.android.sdk.demoapp.util.mainActivity
|
||||
import cash.z.ecc.android.sdk.ext.TroubleshootingTwig
|
||||
import cash.z.ecc.android.sdk.ext.Twig
|
||||
import com.google.android.material.snackbar.Snackbar
|
||||
|
||||
abstract class BaseDemoFragment<T : ViewBinding> : Fragment() {
|
||||
|
@ -24,11 +22,11 @@ abstract class BaseDemoFragment<T : ViewBinding> : Fragment() {
|
|||
* synchronizer because it wraps the service.
|
||||
*/
|
||||
val lightwalletService get() = mainActivity()?.lightwalletService
|
||||
|
||||
|
||||
// contains view information provided by the user
|
||||
val sharedViewModel: SharedViewModel by activityViewModels()
|
||||
lateinit var binding: T
|
||||
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup?,
|
||||
|
|
|
@ -24,7 +24,9 @@ import cash.z.ecc.android.sdk.type.ZcashNetwork
|
|||
import com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||
import com.google.android.material.navigation.NavigationView
|
||||
|
||||
class MainActivity : AppCompatActivity(), ClipboardManager.OnPrimaryClipChangedListener,
|
||||
class MainActivity :
|
||||
AppCompatActivity(),
|
||||
ClipboardManager.OnPrimaryClipChangedListener,
|
||||
DrawerLayout.DrawerListener {
|
||||
private lateinit var appBarConfiguration: AppBarConfiguration
|
||||
private lateinit var clipboard: ClipboardManager
|
||||
|
@ -38,7 +40,7 @@ class MainActivity : AppCompatActivity(), ClipboardManager.OnPrimaryClipChangedL
|
|||
* automatically sync with the server.
|
||||
*/
|
||||
var lightwalletService: LightWalletService? = null
|
||||
private set
|
||||
private set
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
@ -62,7 +64,8 @@ class MainActivity : AppCompatActivity(), ClipboardManager.OnPrimaryClipChangedL
|
|||
R.id.nav_home, R.id.nav_address, R.id.nav_balance, R.id.nav_block, R.id.nav_private_key,
|
||||
R.id.nav_latest_height, R.id.nav_block_range,
|
||||
R.id.nav_transactions, R.id.nav_utxos, R.id.nav_send
|
||||
), drawerLayout
|
||||
),
|
||||
drawerLayout
|
||||
)
|
||||
setupActionBarWithNavController(navController, appBarConfiguration)
|
||||
navView.setupWithNavController(navController)
|
||||
|
@ -97,7 +100,6 @@ class MainActivity : AppCompatActivity(), ClipboardManager.OnPrimaryClipChangedL
|
|||
return navController.navigateUp(appBarConfiguration) || super.onSupportNavigateUp()
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Private functions
|
||||
//
|
||||
|
@ -113,7 +115,6 @@ class MainActivity : AppCompatActivity(), ClipboardManager.OnPrimaryClipChangedL
|
|||
fabListener?.onActionButtonClicked()
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Helpers
|
||||
//
|
||||
|
@ -143,7 +144,6 @@ class MainActivity : AppCompatActivity(), ClipboardManager.OnPrimaryClipChangedL
|
|||
getSystemService<InputMethodManager>()?.hideSoftInputFromWindow(windowToken, 0)
|
||||
}
|
||||
|
||||
|
||||
/* DrawerListener implementation */
|
||||
|
||||
override fun onDrawerStateChanged(newState: Int) {
|
||||
|
|
|
@ -29,6 +29,6 @@ class SharedViewModel : ViewModel() {
|
|||
return try {
|
||||
Mnemonics.MnemonicCode(phrase).validate()
|
||||
true
|
||||
} catch (t: Throwable){ false }
|
||||
} catch (t: Throwable) { false }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,7 +6,6 @@ import android.os.Handler
|
|||
import android.os.Looper
|
||||
import android.os.StrictMode
|
||||
|
||||
|
||||
object StrictModeHelper {
|
||||
|
||||
fun enableStrictMode() {
|
||||
|
|
|
@ -60,7 +60,6 @@ class GetAddressFragment : BaseDemoFragment<FragmentGetAddressBinding>() {
|
|||
displayAddress()
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Base Fragment overrides
|
||||
//
|
||||
|
@ -74,5 +73,4 @@ class GetAddressFragment : BaseDemoFragment<FragmentGetAddressBinding>() {
|
|||
|
||||
override fun inflateBinding(layoutInflater: LayoutInflater): FragmentGetAddressBinding =
|
||||
FragmentGetAddressBinding.inflate(layoutInflater)
|
||||
|
||||
}
|
||||
|
|
|
@ -2,14 +2,12 @@ package cash.z.ecc.android.sdk.demoapp.demos.getbalance
|
|||
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import cash.z.ecc.android.bip39.Mnemonics
|
||||
import cash.z.ecc.android.bip39.toSeed
|
||||
import cash.z.ecc.android.sdk.Initializer
|
||||
import cash.z.ecc.android.sdk.Synchronizer
|
||||
import cash.z.ecc.android.sdk.block.CompactBlockProcessor
|
||||
import cash.z.ecc.android.sdk.demoapp.App
|
||||
import cash.z.ecc.android.sdk.demoapp.BaseDemoFragment
|
||||
import cash.z.ecc.android.sdk.demoapp.databinding.FragmentGetBalanceBinding
|
||||
import cash.z.ecc.android.sdk.demoapp.ext.requireApplicationContext
|
||||
|
@ -48,12 +46,12 @@ class GetBalanceFragment : BaseDemoFragment<FragmentGetBalanceBinding>() {
|
|||
val viewingKey = DerivationTool.deriveUnifiedViewingKeys(seed, ZcashNetwork.fromResources(requireApplicationContext())).first()
|
||||
|
||||
// using the ViewingKey to initialize
|
||||
Initializer(requireApplicationContext()) {
|
||||
it.setNetwork(ZcashNetwork.fromResources(requireApplicationContext()))
|
||||
it.importWallet(viewingKey, network = ZcashNetwork.fromResources(requireApplicationContext()))
|
||||
}.let { initializer ->
|
||||
synchronizer = Synchronizer(initializer)
|
||||
}
|
||||
Initializer(requireApplicationContext()) {
|
||||
it.setNetwork(ZcashNetwork.fromResources(requireApplicationContext()))
|
||||
it.importWallet(viewingKey, network = ZcashNetwork.fromResources(requireApplicationContext()))
|
||||
}.let { initializer ->
|
||||
synchronizer = Synchronizer(initializer)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
|
@ -71,14 +69,12 @@ class GetBalanceFragment : BaseDemoFragment<FragmentGetBalanceBinding>() {
|
|||
}
|
||||
|
||||
private fun onBalance(balance: WalletBalance) {
|
||||
binding.textBalance.text = """
|
||||
binding.textBalance.text = """
|
||||
Available balance: ${balance.availableZatoshi.convertZatoshiToZecString(12)}
|
||||
Total balance: ${balance.totalZatoshi.convertZatoshiToZecString(12)}
|
||||
""".trimIndent()
|
||||
|
||||
""".trimIndent()
|
||||
}
|
||||
|
||||
|
||||
private fun onStatus(status: Synchronizer.Status) {
|
||||
binding.textStatus.text = "Status: $status"
|
||||
if (WalletBalance().none()) {
|
||||
|
@ -97,9 +93,10 @@ class GetBalanceFragment : BaseDemoFragment<FragmentGetBalanceBinding>() {
|
|||
/**
|
||||
* Extension function which checks if the balance has been updated or its -1
|
||||
*/
|
||||
private fun WalletBalance.none(): Boolean{
|
||||
if(synchronizer.saplingBalances.value.totalZatoshi == -1L
|
||||
&& synchronizer.saplingBalances.value.availableZatoshi == -1L) return true
|
||||
private fun WalletBalance.none(): Boolean {
|
||||
if (synchronizer.saplingBalances.value.totalZatoshi == -1L &&
|
||||
synchronizer.saplingBalances.value.availableZatoshi == -1L
|
||||
) return true
|
||||
return false
|
||||
}
|
||||
|
||||
|
|
|
@ -52,7 +52,6 @@ class GetBlockFragment : BaseDemoFragment<FragmentGetBlockBinding>() {
|
|||
onApply()
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Android Lifecycle overrides
|
||||
//
|
||||
|
@ -68,7 +67,6 @@ class GetBlockFragment : BaseDemoFragment<FragmentGetBlockBinding>() {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Base Fragment overrides
|
||||
//
|
||||
|
|
|
@ -28,41 +28,43 @@ class GetBlockRangeFragment : BaseDemoFragment<FragmentGetBlockRangeBinding>() {
|
|||
|
||||
// Note: This is a demo so we won't worry about iterating efficiently over these blocks
|
||||
|
||||
binding.textInfo.text = Html.fromHtml(blocks?.run {
|
||||
val count = size
|
||||
val emptyCount = count { it.vtxCount == 0 }
|
||||
val maxTxs = maxByOrNull { it.vtxCount }
|
||||
val maxIns = maxByOrNull { block ->
|
||||
block.vtxList.maxOfOrNull { it.spendsCount } ?: -1
|
||||
}
|
||||
val maxInTx = maxIns?.vtxList?.maxByOrNull { it.spendsCount }
|
||||
val maxOuts = maxByOrNull { block ->
|
||||
block.vtxList.maxOfOrNull { it.outputsCount } ?: -1
|
||||
}
|
||||
val maxOutTx = maxOuts?.vtxList?.maxByOrNull { it.outputsCount }
|
||||
val txCount = sumBy { it.vtxCount }
|
||||
val outCount = sumBy { block -> block.vtxList.sumBy { it.outputsCount } }
|
||||
val inCount = sumBy { block -> block.vtxList.sumBy { it.spendsCount } }
|
||||
binding.textInfo.text = Html.fromHtml(
|
||||
blocks?.run {
|
||||
val count = size
|
||||
val emptyCount = count { it.vtxCount == 0 }
|
||||
val maxTxs = maxByOrNull { it.vtxCount }
|
||||
val maxIns = maxByOrNull { block ->
|
||||
block.vtxList.maxOfOrNull { it.spendsCount } ?: -1
|
||||
}
|
||||
val maxInTx = maxIns?.vtxList?.maxByOrNull { it.spendsCount }
|
||||
val maxOuts = maxByOrNull { block ->
|
||||
block.vtxList.maxOfOrNull { it.outputsCount } ?: -1
|
||||
}
|
||||
val maxOutTx = maxOuts?.vtxList?.maxByOrNull { it.outputsCount }
|
||||
val txCount = sumBy { it.vtxCount }
|
||||
val outCount = sumBy { block -> block.vtxList.sumBy { it.outputsCount } }
|
||||
val inCount = sumBy { block -> block.vtxList.sumBy { it.spendsCount } }
|
||||
|
||||
val processTime = System.currentTimeMillis() - start - fetchDelta
|
||||
"""
|
||||
val processTime = System.currentTimeMillis() - start - fetchDelta
|
||||
"""
|
||||
<b>total blocks:</b> ${count.withCommas()}
|
||||
<br/><b>fetch time:</b> ${if (fetchDelta > 1000) "%.2f sec".format(fetchDelta/1000.0) else "%d ms".format(fetchDelta)}
|
||||
<br/><b>process time:</b> ${if (processTime > 1000) "%.2f sec".format(processTime/1000.0) else "%d ms".format(processTime)}
|
||||
<br/><b>fetch time:</b> ${if (fetchDelta > 1000) "%.2f sec".format(fetchDelta / 1000.0) else "%d ms".format(fetchDelta)}
|
||||
<br/><b>process time:</b> ${if (processTime > 1000) "%.2f sec".format(processTime / 1000.0) else "%d ms".format(processTime)}
|
||||
<br/><b>block time range:</b> ${first().time.toRelativeTime(requireApplicationContext())}<br/>   to ${last().time.toRelativeTime(requireApplicationContext())}
|
||||
<br/><b>total empty blocks:</b> ${emptyCount.withCommas()}
|
||||
<br/><b>total TXs:</b> ${txCount.withCommas()}
|
||||
<br/><b>total outputs:</b> ${outCount.withCommas()}
|
||||
<br/><b>total inputs:</b> ${inCount.withCommas()}
|
||||
<br/><b>avg TXs/block:</b> ${"%.1f".format(txCount/count.toDouble())}
|
||||
<br/><b>avg TXs (excluding empty blocks):</b> ${"%.1f".format(txCount.toDouble()/(count - emptyCount))}
|
||||
<br/><b>avg OUTs [per block / per TX]:</b> ${"%.1f / %.1f".format(outCount.toDouble()/(count - emptyCount), outCount.toDouble()/txCount)}
|
||||
<br/><b>avg INs [per block / per TX]:</b> ${"%.1f / %.1f".format(inCount.toDouble()/(count - emptyCount), inCount.toDouble()/txCount)}
|
||||
<br/><b>most shielded TXs:</b> ${if (maxTxs==null) "none" else "${maxTxs.vtxCount} in block ${maxTxs.height.withCommas()}"}
|
||||
<br/><b>most shielded INs:</b> ${if (maxInTx==null) "none" else "${maxInTx.spendsCount} in block ${maxIns?.height.withCommas()} at tx index ${maxInTx.index}"}
|
||||
<br/><b>most shielded OUTs:</b> ${if (maxOutTx==null) "none" else "${maxOutTx?.outputsCount} in block ${maxOuts?.height.withCommas()} at tx index ${maxOutTx?.index}"}
|
||||
""".trimIndent()
|
||||
} ?: "No blocks found in that range.")
|
||||
<br/><b>avg TXs/block:</b> ${"%.1f".format(txCount / count.toDouble())}
|
||||
<br/><b>avg TXs (excluding empty blocks):</b> ${"%.1f".format(txCount.toDouble() / (count - emptyCount))}
|
||||
<br/><b>avg OUTs [per block / per TX]:</b> ${"%.1f / %.1f".format(outCount.toDouble() / (count - emptyCount), outCount.toDouble() / txCount)}
|
||||
<br/><b>avg INs [per block / per TX]:</b> ${"%.1f / %.1f".format(inCount.toDouble() / (count - emptyCount), inCount.toDouble() / txCount)}
|
||||
<br/><b>most shielded TXs:</b> ${if (maxTxs == null) "none" else "${maxTxs.vtxCount} in block ${maxTxs.height.withCommas()}"}
|
||||
<br/><b>most shielded INs:</b> ${if (maxInTx == null) "none" else "${maxInTx.spendsCount} in block ${maxIns?.height.withCommas()} at tx index ${maxInTx.index}"}
|
||||
<br/><b>most shielded OUTs:</b> ${if (maxOutTx == null) "none" else "${maxOutTx?.outputsCount} in block ${maxOuts?.height.withCommas()} at tx index ${maxOutTx?.index}"}
|
||||
""".trimIndent()
|
||||
} ?: "No blocks found in that range."
|
||||
)
|
||||
}
|
||||
|
||||
private fun onApply(_unused: View) {
|
||||
|
@ -93,7 +95,6 @@ class GetBlockRangeFragment : BaseDemoFragment<FragmentGetBlockRangeBinding>() {
|
|||
binding.textInfo.text = "Error: $message"
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Android Lifecycle overrides
|
||||
//
|
||||
|
@ -103,7 +104,6 @@ class GetBlockRangeFragment : BaseDemoFragment<FragmentGetBlockRangeBinding>() {
|
|||
binding.buttonApply.setOnClickListener(::onApply)
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Base Fragment overrides
|
||||
//
|
||||
|
@ -114,5 +114,4 @@ class GetBlockRangeFragment : BaseDemoFragment<FragmentGetBlockRangeBinding>() {
|
|||
override fun onActionButtonClicked() {
|
||||
super.onActionButtonClicked()
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -18,7 +18,6 @@ class GetLatestHeightFragment : BaseDemoFragment<FragmentGetLatestHeightBinding>
|
|||
binding.textInfo.text = lightwalletService?.getLatestBlockHeight().toString()
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Android Lifecycle overrides
|
||||
//
|
||||
|
@ -28,7 +27,6 @@ class GetLatestHeightFragment : BaseDemoFragment<FragmentGetLatestHeightBinding>
|
|||
displayLatestHeight()
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Base Fragment overrides
|
||||
//
|
||||
|
|
|
@ -37,7 +37,7 @@ class GetPrivateKeyFragment : BaseDemoFragment<FragmentGetPrivateKeyBinding>() {
|
|||
private fun displayKeys() {
|
||||
// derive the keys from the seed:
|
||||
// demonstrate deriving spending keys for five accounts but only take the first one
|
||||
val spendingKey = DerivationTool.deriveSpendingKeys(seed, ZcashNetwork.fromResources(requireApplicationContext()),5).first()
|
||||
val spendingKey = DerivationTool.deriveSpendingKeys(seed, ZcashNetwork.fromResources(requireApplicationContext()), 5).first()
|
||||
|
||||
// derive the key that allows you to view but not spend transactions
|
||||
val viewingKey = DerivationTool.deriveViewingKey(spendingKey, ZcashNetwork.fromResources(requireApplicationContext()))
|
||||
|
@ -46,7 +46,6 @@ class GetPrivateKeyFragment : BaseDemoFragment<FragmentGetPrivateKeyBinding>() {
|
|||
binding.textInfo.setText("Spending Key:\n$spendingKey\n\nViewing Key:\n$viewingKey")
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Android Lifecycle overrides
|
||||
//
|
||||
|
@ -61,7 +60,6 @@ class GetPrivateKeyFragment : BaseDemoFragment<FragmentGetPrivateKeyBinding>() {
|
|||
displayKeys()
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Base Fragment overrides
|
||||
//
|
||||
|
@ -75,5 +73,4 @@ class GetPrivateKeyFragment : BaseDemoFragment<FragmentGetPrivateKeyBinding>() {
|
|||
|
||||
override fun inflateBinding(layoutInflater: LayoutInflater): FragmentGetPrivateKeyBinding =
|
||||
FragmentGetPrivateKeyBinding.inflate(layoutInflater)
|
||||
|
||||
}
|
||||
|
|
|
@ -5,17 +5,11 @@ import android.graphics.Color
|
|||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.fragment.app.activityViewModels
|
||||
import androidx.fragment.app.viewModels
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import cash.z.ecc.android.sdk.demoapp.App
|
||||
import cash.z.ecc.android.sdk.demoapp.BaseDemoFragment
|
||||
import cash.z.ecc.android.sdk.demoapp.SharedViewModel
|
||||
import cash.z.ecc.android.sdk.demoapp.databinding.FragmentHomeBinding
|
||||
import cash.z.ecc.android.sdk.demoapp.util.mainActivity
|
||||
import cash.z.ecc.android.sdk.ext.twig
|
||||
import kotlinx.coroutines.flow.collect
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
|
@ -121,4 +115,3 @@ class HomeFragment : BaseDemoFragment<FragmentHomeBinding>() {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,9 +1,5 @@
|
|||
package cash.z.ecc.android.sdk.demoapp.demos.home
|
||||
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.ViewModel
|
||||
|
||||
class HomeViewModel : ViewModel() {
|
||||
|
||||
}
|
||||
class HomeViewModel : ViewModel()
|
||||
|
|
|
@ -8,11 +8,9 @@ import androidx.recyclerview.widget.LinearLayoutManager
|
|||
import cash.z.ecc.android.bip39.Mnemonics
|
||||
import cash.z.ecc.android.bip39.toSeed
|
||||
import cash.z.ecc.android.sdk.Initializer
|
||||
import cash.z.ecc.android.sdk.SdkSynchronizer
|
||||
import cash.z.ecc.android.sdk.Synchronizer
|
||||
import cash.z.ecc.android.sdk.block.CompactBlockProcessor
|
||||
import cash.z.ecc.android.sdk.db.entity.ConfirmedTransaction
|
||||
import cash.z.ecc.android.sdk.demoapp.App
|
||||
import cash.z.ecc.android.sdk.demoapp.BaseDemoFragment
|
||||
import cash.z.ecc.android.sdk.demoapp.databinding.FragmentListTransactionsBinding
|
||||
import cash.z.ecc.android.sdk.demoapp.ext.requireApplicationContext
|
||||
|
@ -37,7 +35,6 @@ class ListTransactionsFragment : BaseDemoFragment<FragmentListTransactionsBindin
|
|||
private var status: Synchronizer.Status? = null
|
||||
private val isSynced get() = status == Synchronizer.Status.SYNCED
|
||||
|
||||
|
||||
/**
|
||||
* Initialize the required values that would normally live outside the demo but are repeated
|
||||
* here for completeness so that each demo file can serve as a standalone example.
|
||||
|
@ -73,7 +70,6 @@ class ListTransactionsFragment : BaseDemoFragment<FragmentListTransactionsBindin
|
|||
synchronizer.clearedTransactions.collectWith(lifecycleScope, ::onTransactionsUpdated)
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Change listeners
|
||||
//
|
||||
|
@ -107,7 +103,7 @@ class ListTransactionsFragment : BaseDemoFragment<FragmentListTransactionsBindin
|
|||
visibility = View.VISIBLE
|
||||
text =
|
||||
"No transactions found. Try to either change the seed words " +
|
||||
"or send funds to this address (tap the FAB to copy it):\n\n $address"
|
||||
"or send funds to this address (tap the FAB to copy it):\n\n $address"
|
||||
} else {
|
||||
visibility = View.INVISIBLE
|
||||
text = ""
|
||||
|
@ -116,7 +112,6 @@ class ListTransactionsFragment : BaseDemoFragment<FragmentListTransactionsBindin
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Android Lifecycle overrides
|
||||
//
|
||||
|
@ -138,7 +133,6 @@ class ListTransactionsFragment : BaseDemoFragment<FragmentListTransactionsBindin
|
|||
monitorChanges()
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Base Fragment overrides
|
||||
//
|
||||
|
@ -149,5 +143,4 @@ class ListTransactionsFragment : BaseDemoFragment<FragmentListTransactionsBindin
|
|||
|
||||
override fun inflateBinding(layoutInflater: LayoutInflater): FragmentListTransactionsBinding =
|
||||
FragmentListTransactionsBinding.inflate(layoutInflater)
|
||||
|
||||
}
|
||||
|
|
|
@ -4,8 +4,8 @@ import android.view.LayoutInflater
|
|||
import android.view.ViewGroup
|
||||
import androidx.recyclerview.widget.DiffUtil
|
||||
import androidx.recyclerview.widget.ListAdapter
|
||||
import cash.z.ecc.android.sdk.demoapp.R
|
||||
import cash.z.ecc.android.sdk.db.entity.ConfirmedTransaction
|
||||
import cash.z.ecc.android.sdk.demoapp.R
|
||||
|
||||
/**
|
||||
* Simple adapter implementation that knows how to bind a recyclerview to ClearedTransactions.
|
||||
|
@ -36,5 +36,4 @@ class TransactionAdapter<T : ConfirmedTransaction> :
|
|||
holder: TransactionViewHolder<T>,
|
||||
position: Int
|
||||
) = holder.bindTo(getItem(position))
|
||||
|
||||
}
|
||||
|
|
|
@ -1,19 +1,15 @@
|
|||
package cash.z.ecc.android.sdk.demoapp.demos.listtransactions
|
||||
|
||||
import android.content.res.ColorStateList
|
||||
import android.view.View
|
||||
import android.widget.ImageView
|
||||
import android.widget.TextView
|
||||
import androidx.annotation.ColorRes
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.content.res.ResourcesCompat
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import cash.z.ecc.android.sdk.db.entity.ConfirmedTransaction
|
||||
import cash.z.ecc.android.sdk.demoapp.App
|
||||
import cash.z.ecc.android.sdk.demoapp.R
|
||||
import cash.z.ecc.android.sdk.ext.convertZatoshiToZecString
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.*
|
||||
import java.util.Locale
|
||||
|
||||
/**
|
||||
* Simple view holder for displaying confirmed transactions in the recyclerview.
|
||||
|
|
|
@ -12,7 +12,6 @@ import cash.z.ecc.android.sdk.SdkSynchronizer
|
|||
import cash.z.ecc.android.sdk.Synchronizer
|
||||
import cash.z.ecc.android.sdk.block.CompactBlockProcessor
|
||||
import cash.z.ecc.android.sdk.db.entity.ConfirmedTransaction
|
||||
import cash.z.ecc.android.sdk.demoapp.App
|
||||
import cash.z.ecc.android.sdk.demoapp.BaseDemoFragment
|
||||
import cash.z.ecc.android.sdk.demoapp.DemoConstants
|
||||
import cash.z.ecc.android.sdk.demoapp.databinding.FragmentListUtxosBinding
|
||||
|
@ -28,7 +27,6 @@ import kotlinx.coroutines.delay
|
|||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
|
||||
|
||||
/**
|
||||
* ===============================================================================================
|
||||
* NOTE: this is still a WIP because t-addrs are not officially supported by the SDK yet
|
||||
|
@ -159,7 +157,6 @@ class ListUtxosFragment : BaseDemoFragment<FragmentListUtxosBinding>() {
|
|||
binding.inputAddress.setText(DerivationTool.deriveTransparentAddress(seed, ZcashNetwork.fromResources(requireApplicationContext())))
|
||||
}
|
||||
|
||||
|
||||
var initialCount: Int = 0
|
||||
var finalCount: Int = 0
|
||||
fun resetInBackground() {
|
||||
|
@ -193,12 +190,11 @@ class ListUtxosFragment : BaseDemoFragment<FragmentListUtxosBinding>() {
|
|||
adapter = UtxoAdapter()
|
||||
binding.recyclerTransactions.adapter = adapter
|
||||
// lifecycleScope.launch {
|
||||
//// address = synchronizer.getAddress()
|
||||
// // address = synchronizer.getAddress()
|
||||
// synchronizer.receivedTransactions.onEach {
|
||||
// onTransactionsUpdated(it)
|
||||
// }.launchIn(this)
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
private fun startSynchronizer() {
|
||||
|
|
|
@ -36,5 +36,4 @@ class UtxoAdapter<T : ConfirmedTransaction> :
|
|||
holder: UtxoViewHolder<T>,
|
||||
position: Int
|
||||
) = holder.bindTo(getItem(position))
|
||||
|
||||
}
|
||||
|
|
|
@ -3,11 +3,11 @@ package cash.z.ecc.android.sdk.demoapp.demos.listutxos
|
|||
import android.view.View
|
||||
import android.widget.TextView
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import cash.z.ecc.android.sdk.demoapp.R
|
||||
import cash.z.ecc.android.sdk.db.entity.ConfirmedTransaction
|
||||
import cash.z.ecc.android.sdk.demoapp.R
|
||||
import cash.z.ecc.android.sdk.ext.convertZatoshiToZecString
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.*
|
||||
import java.util.Locale
|
||||
|
||||
/**
|
||||
* Simple view holder for displaying confirmed transactions in the recyclerview.
|
||||
|
|
|
@ -10,14 +10,25 @@ import cash.z.ecc.android.bip39.toSeed
|
|||
import cash.z.ecc.android.sdk.Initializer
|
||||
import cash.z.ecc.android.sdk.Synchronizer
|
||||
import cash.z.ecc.android.sdk.block.CompactBlockProcessor
|
||||
import cash.z.ecc.android.sdk.db.entity.*
|
||||
import cash.z.ecc.android.sdk.db.entity.PendingTransaction
|
||||
import cash.z.ecc.android.sdk.db.entity.isCreated
|
||||
import cash.z.ecc.android.sdk.db.entity.isCreating
|
||||
import cash.z.ecc.android.sdk.db.entity.isFailedEncoding
|
||||
import cash.z.ecc.android.sdk.db.entity.isFailedSubmit
|
||||
import cash.z.ecc.android.sdk.db.entity.isMined
|
||||
import cash.z.ecc.android.sdk.db.entity.isSubmitSuccess
|
||||
import cash.z.ecc.android.sdk.demoapp.BaseDemoFragment
|
||||
import cash.z.ecc.android.sdk.demoapp.DemoConstants
|
||||
import cash.z.ecc.android.sdk.demoapp.databinding.FragmentSendBinding
|
||||
import cash.z.ecc.android.sdk.demoapp.ext.requireApplicationContext
|
||||
import cash.z.ecc.android.sdk.demoapp.util.fromResources
|
||||
import cash.z.ecc.android.sdk.demoapp.util.mainActivity
|
||||
import cash.z.ecc.android.sdk.ext.*
|
||||
import cash.z.ecc.android.sdk.ext.Twig
|
||||
import cash.z.ecc.android.sdk.ext.collectWith
|
||||
import cash.z.ecc.android.sdk.ext.convertZatoshiToZecString
|
||||
import cash.z.ecc.android.sdk.ext.convertZecToZatoshi
|
||||
import cash.z.ecc.android.sdk.ext.toZecString
|
||||
import cash.z.ecc.android.sdk.ext.twig
|
||||
import cash.z.ecc.android.sdk.tool.DerivationTool
|
||||
import cash.z.ecc.android.sdk.type.WalletBalance
|
||||
import cash.z.ecc.android.sdk.type.ZcashNetwork
|
||||
|
@ -40,7 +51,6 @@ class SendFragment : BaseDemoFragment<FragmentSendBinding>() {
|
|||
// but since this is a demo, we'll derive it on the fly
|
||||
private lateinit var spendingKey: String
|
||||
|
||||
|
||||
/**
|
||||
* Initialize the required values that would normally live outside the demo but are repeated
|
||||
* here for completeness so that each demo file can serve as a standalone example.
|
||||
|
@ -83,7 +93,6 @@ class SendFragment : BaseDemoFragment<FragmentSendBinding>() {
|
|||
onUpdateSendButton()
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Private functions
|
||||
//
|
||||
|
@ -105,7 +114,6 @@ class SendFragment : BaseDemoFragment<FragmentSendBinding>() {
|
|||
synchronizer.saplingBalances.collectWith(lifecycleScope, ::onBalance)
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Change listeners
|
||||
//
|
||||
|
@ -198,7 +206,6 @@ class SendFragment : BaseDemoFragment<FragmentSendBinding>() {
|
|||
binding.textInfo.text = "Active Transaction:"
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Android Lifecycle overrides
|
||||
//
|
||||
|
@ -226,5 +233,4 @@ class SendFragment : BaseDemoFragment<FragmentSendBinding>() {
|
|||
|
||||
override fun inflateBinding(layoutInflater: LayoutInflater): FragmentSendBinding =
|
||||
FragmentSendBinding.inflate(layoutInflater)
|
||||
|
||||
}
|
||||
|
|
|
@ -3,7 +3,6 @@ package cash.z.ecc.android.sdk.demoapp.util
|
|||
import android.content.Context
|
||||
import android.text.format.DateUtils
|
||||
import androidx.fragment.app.Fragment
|
||||
import cash.z.ecc.android.sdk.demoapp.App
|
||||
import cash.z.ecc.android.sdk.demoapp.MainActivity
|
||||
import cash.z.wallet.sdk.rpc.CompactFormats
|
||||
|
||||
|
@ -11,10 +10,8 @@ import cash.z.wallet.sdk.rpc.CompactFormats
|
|||
* Lazy extensions to make demo life easier.
|
||||
*/
|
||||
|
||||
|
||||
fun Fragment.mainActivity() = context as? MainActivity
|
||||
|
||||
|
||||
/**
|
||||
* Add locale-specific commas to a number, if it exists.
|
||||
*/
|
||||
|
@ -34,7 +31,6 @@ fun Int?.toRelativeTime(context: Context) =
|
|||
).toString()
|
||||
} ?: "Unknown"
|
||||
|
||||
|
||||
fun List<CompactFormats.CompactTx>?.toHtml() =
|
||||
this.takeUnless { it.isNullOrEmpty() }?.let { txs ->
|
||||
buildString {
|
||||
|
@ -42,4 +38,3 @@ fun List<CompactFormats.CompactTx>?.toHtml() =
|
|||
txs.forEach { append("<br/><b> tx${it.index}:</b> ${it.spendsCount} / ${it.outputsCount}") }
|
||||
}
|
||||
} ?: ""
|
||||
|
||||
|
|
|
@ -4,5 +4,8 @@ import android.content.Context
|
|||
import cash.z.ecc.android.sdk.demoapp.R
|
||||
import cash.z.ecc.android.sdk.type.ZcashNetwork
|
||||
|
||||
fun ZcashNetwork.Companion.fromResources(context: Context) = ZcashNetwork.valueOf(context.getString(
|
||||
R.string.network_name))
|
||||
fun ZcashNetwork.Companion.fromResources(context: Context) = ZcashNetwork.valueOf(
|
||||
context.getString(
|
||||
R.string.network_name
|
||||
)
|
||||
)
|
||||
|
|
|
@ -1,19 +1,17 @@
|
|||
package cash.z.ecc.android.sdk.demoapp.util
|
||||
|
||||
import android.content.Context
|
||||
import cash.z.ecc.android.sdk.demoapp.App
|
||||
|
||||
|
||||
@Deprecated(
|
||||
message = "Do not use this! It is insecure and only intended for demo purposes to " +
|
||||
"show how to bridge to an existing key storage mechanism. Instead, use the Android " +
|
||||
"Keystore system or a 3rd party library that leverages it."
|
||||
"show how to bridge to an existing key storage mechanism. Instead, use the Android " +
|
||||
"Keystore system or a 3rd party library that leverages it."
|
||||
)
|
||||
class SampleStorage(context: Context) {
|
||||
|
||||
private val prefs =
|
||||
context.applicationContext.getSharedPreferences("ExtremelyInsecureStorage", Context.MODE_PRIVATE)
|
||||
|
||||
|
||||
fun saveSensitiveString(key: String, value: String) {
|
||||
prefs.edit().putString(key, value).apply()
|
||||
}
|
||||
|
@ -54,8 +52,8 @@ class SampleStorageBridge(context: Context) {
|
|||
return this
|
||||
}
|
||||
|
||||
val seed: ByteArray get() = delegate.loadSensitiveBytes(KEY_SEED)!!
|
||||
val key get() = delegate.loadSensitiveString(KEY_PK)!!
|
||||
val seed: ByteArray get() = delegate.loadSensitiveBytes(KEY_SEED)!!
|
||||
val key get() = delegate.loadSensitiveString(KEY_PK)!!
|
||||
|
||||
companion object {
|
||||
private const val KEY_SEED = "cash.z.ecc.android.sdk.demoapp.SEED"
|
||||
|
|
|
@ -6,7 +6,7 @@ import cash.z.ecc.android.bip39.Mnemonics.MnemonicCode
|
|||
import cash.z.ecc.android.bip39.Mnemonics.WordCount
|
||||
import cash.z.ecc.android.bip39.toEntropy
|
||||
import cash.z.ecc.android.bip39.toSeed
|
||||
import java.util.*
|
||||
import java.util.Locale
|
||||
|
||||
/**
|
||||
* A sample implementation of a plugin for handling Mnemonic phrases. Any library can easily be
|
||||
|
|
|
@ -11,4 +11,4 @@ object DemoConstants {
|
|||
// corresponds to seed: urban kind wise collect social marble riot primary craft lucky head cause syrup odor artist decorate rhythm phone style benefit portion bus truck top
|
||||
val toAddress: String =
|
||||
"zs1lcdmue7rewgvzh3jd09sfvwq3sumu6hkhpk53q94kcneuffjkdg9e3tyxrugkmpza5c3c5e6eqh"
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue