Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,25 @@ import android.os.Bundle
import android.view.Gravity
import android.view.View
import android.view.View.VISIBLE
import android.view.ViewGroup
import android.widget.ArrayAdapter
import android.widget.TextView
import androidx.appcompat.widget.ListPopupWindow
import androidx.core.content.ContextCompat
import androidx.core.util.Pair
import androidx.fragment.app.viewModels
import androidx.lifecycle.Observer
import androidx.lifecycle.lifecycleScope
import kotlinx.coroutines.Job
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import androidx.paging.PagedList
import androidx.recyclerview.widget.LinearLayoutManager
import android.widget.ArrayAdapter
import android.widget.TextView
import android.view.ViewGroup
import com.google.android.material.datepicker.MaterialDatePicker
import com.google.android.material.datepicker.CalendarConstraints
import com.google.android.material.datepicker.DateValidatorPointBackward
import com.google.android.material.datepicker.MaterialDatePicker
import com.timehop.stickyheadersrecyclerview.StickyRecyclerHeadersDecoration
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.Job
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import one.mixin.android.R
import one.mixin.android.databinding.FragmentAllOrdersBinding
import one.mixin.android.db.web3.vo.Web3TokenItem
Expand All @@ -38,8 +38,8 @@ import one.mixin.android.ui.home.web3.trade.OrderDetailFragment
import one.mixin.android.ui.wallet.adapter.OrderPagedAdapter
import one.mixin.android.util.analytics.AnalyticsTracker
import one.mixin.android.util.viewBinding
import one.mixin.android.widget.SpacesItemDecoration
import one.mixin.android.vo.route.OrderItem
import one.mixin.android.widget.SpacesItemDecoration

@AndroidEntryPoint
class AllOrdersFragment : BaseTransactionsFragment<PagedList<OrderItem>>(R.layout.fragment_all_orders) {
Expand Down
165 changes: 80 additions & 85 deletions app/src/main/java/one/mixin/android/ui/wallet/ClassicWalletFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@ import kotlinx.coroutines.withContext
import one.mixin.android.Constants
import one.mixin.android.R
import one.mixin.android.RxBus
import one.mixin.android.crypto.CryptoWalletHelper
import one.mixin.android.databinding.FragmentPrivacyWalletBinding
import one.mixin.android.databinding.ViewWalletFragmentHeaderBinding
import one.mixin.android.db.web3.vo.Web3TokenItem
import one.mixin.android.db.web3.vo.isImported
import one.mixin.android.db.web3.vo.isWatch
import one.mixin.android.event.QuoteColorEvent
import one.mixin.android.event.WalletRefreshedEvent
import one.mixin.android.extension.dp
import one.mixin.android.extension.dpToPx
import one.mixin.android.extension.mainThread
Expand Down Expand Up @@ -161,90 +163,46 @@ class ClassicWalletFragment : BaseFragment(R.layout.fragment_privacy_wallet), He
ViewWalletFragmentHeaderBinding.bind(layoutInflater.inflate(R.layout.view_wallet_fragment_header, coinsRv, false)).apply {
sendReceiveView.enableBuy()
sendReceiveView.buy.setOnClickListener {
lifecycleScope.launch {
val wallet = web3ViewModel.findWalletById(walletId)
val chainId = web3ViewModel.getAddresses(walletId).first().chainId
if (wallet?.isImported() == true && !wallet.hasLocalPrivateKey) {
ImportKeyBottomSheetDialogFragment.newInstance(
if (wallet.category == WalletCategory.IMPORTED_MNEMONIC.value) ImportKeyBottomSheetDialogFragment.PopupType.ImportMnemonicPhrase else ImportKeyBottomSheetDialogFragment.PopupType.ImportPrivateKey,
walletId = walletId, chainId = chainId
).showNow(parentFragmentManager, ImportKeyBottomSheetDialogFragment.TAG)
return@launch
}
WalletActivity.showBuy(requireActivity(), true, null, null, walletId)
}
WalletActivity.showBuy(requireActivity(), true, null, null, walletId)
}
sendReceiveView.send.setOnClickListener {
lifecycleScope.launch {
val wallet = web3ViewModel.findWalletById(walletId)
val chainId = web3ViewModel.getAddresses(walletId).first().chainId
if (wallet?.isImported() == true && !wallet.hasLocalPrivateKey) {
ImportKeyBottomSheetDialogFragment.newInstance(
if (wallet.category == WalletCategory.IMPORTED_MNEMONIC.value) ImportKeyBottomSheetDialogFragment.PopupType.ImportMnemonicPhrase else ImportKeyBottomSheetDialogFragment.PopupType.ImportPrivateKey,
walletId = walletId, chainId = chainId
).showNow(parentFragmentManager, ImportKeyBottomSheetDialogFragment.TAG)
return@launch
}
Web3TokenListBottomSheetDialogFragment.newInstance(walletId = walletId).apply {
setOnClickListener { token ->
this@ClassicWalletFragment.lifecycleScope.launch {
if (walletId.isEmpty()) {
toast(R.string.Data_error)
return@launch
}
val wallet = web3ViewModel.findWalletById(walletId)
val address = web3ViewModel.getAddressesByChainId(walletId, token.chainId)
if (address == null || wallet == null) {
toast(R.string.Data_error)
return@launch
}
val chain = web3ViewModel.web3TokenItemById(token.walletId, token.chainId) ?: return@launch
Timber.e("chain ${chain.name} ${token.chainId} ${chain.chainId}")
WalletActivity.navigateToWalletActivity(this@ClassicWalletFragment.requireActivity(), address.destination, token, chain, wallet)
Web3TokenListBottomSheetDialogFragment.newInstance(walletId = walletId).apply {
setOnClickListener { token ->
this@ClassicWalletFragment.lifecycleScope.launch {
if (walletId.isEmpty()) {
toast(R.string.Data_error)
return@launch
}
dismissNow()
val wallet = web3ViewModel.findWalletById(walletId)
val address = web3ViewModel.getAddressesByChainId(walletId, token.chainId)
if (address == null || wallet == null) {
toast(R.string.Data_error)
return@launch
}
val chain = web3ViewModel.web3TokenItemById(token.walletId, token.chainId) ?: return@launch
Timber.e("chain ${chain.name} ${token.chainId} ${chain.chainId}")
WalletActivity.navigateToWalletActivity(this@ClassicWalletFragment.requireActivity(), address.destination, token, chain, wallet)
}
}.show(parentFragmentManager, Web3TokenListBottomSheetDialogFragment.TAG)
}
dismissNow()
}
}.show(parentFragmentManager, Web3TokenListBottomSheetDialogFragment.TAG)
}
sendReceiveView.receive.setOnClickListener {
lifecycleScope.launch {
val wallet = web3ViewModel.findWalletById(walletId)
if (wallet?.isImported() == true && !wallet.hasLocalPrivateKey) {
val chainId = web3ViewModel.getAddresses(walletId).first().chainId
ImportKeyBottomSheetDialogFragment.newInstance(
if (wallet.category == WalletCategory.IMPORTED_MNEMONIC.value) ImportKeyBottomSheetDialogFragment.PopupType.ImportMnemonicPhrase else ImportKeyBottomSheetDialogFragment.PopupType.ImportPrivateKey,
walletId = walletId, chainId
).showNow(parentFragmentManager, ImportKeyBottomSheetDialogFragment.TAG)
return@launch
}
if (!Session.saltExported() && Session.isAnonymous()) {
if (!Session.saltExported() && Session.isAnonymous()) {
BackupMnemonicPhraseWarningBottomSheetDialogFragment.newInstance()
.apply {
laterCallback = {
showReceiveAssetList()
}
}
.show(parentFragmentManager, BackupMnemonicPhraseWarningBottomSheetDialogFragment.TAG)
} else {
showReceiveAssetList()
}
} else {
showReceiveAssetList()
}
}
sendReceiveView.swap.setOnClickListener {
lifecycleScope.launch {
val wallet = web3ViewModel.findWalletById(walletId)
if (wallet?.isImported() == true && !wallet.hasLocalPrivateKey) {
val chainId = web3ViewModel.getAddresses(walletId).first().chainId
ImportKeyBottomSheetDialogFragment.newInstance(
if (wallet.category == WalletCategory.IMPORTED_MNEMONIC.value) ImportKeyBottomSheetDialogFragment.PopupType.ImportMnemonicPhrase else ImportKeyBottomSheetDialogFragment.PopupType.ImportPrivateKey,
walletId = walletId, chainId = chainId
).showNow(parentFragmentManager, ImportKeyBottomSheetDialogFragment.TAG)
return@launch
}
AnalyticsTracker.trackTradeStart(TradeWallet.WEB3, TradeSource.WALLET_HOME)
SwapActivity.show(requireActivity(), inMixin = false, walletId = walletId)
}
AnalyticsTracker.trackTradeStart(TradeWallet.WEB3, TradeSource.WALLET_HOME)
SwapActivity.show(requireActivity(), inMixin = false, walletId = walletId)
}
}
_headBinding?.pendingView?.isVisible = false
Expand Down Expand Up @@ -282,25 +240,18 @@ class ClassicWalletFragment : BaseFragment(R.layout.fragment_privacy_wallet), He
}
_walletId.observe(viewLifecycleOwner) { id ->
if (id.isNotEmpty()) {
lifecycleScope.launch {
val wallet = web3ViewModel.findWalletById(id)
_headBinding?.sendReceiveView?.isVisible = wallet?.isWatch() == false
_headBinding?.watchLayout?.isVisible = wallet?.isWatch() == true

if (wallet?.isWatch() == true) {
val addresses = web3ViewModel.getAddressesGroupedByDestination(id)
if (addresses.isNotEmpty()) {
if (addresses.size == 1) {
val address = addresses.first().destination
_headBinding?.watchTv?.text = getString(R.string.watching_address, "${address.take(6)}..${address.takeLast(4)}")
} else {
_headBinding?.watchTv?.text = getString(R.string.watching_addresses, addresses.size)
}
}
}
}
updateWalletUI(id)
}
}

RxBus.listen(WalletRefreshedEvent::class.java)
.observeOn(AndroidSchedulers.mainThread())
.autoDispose(destroyScope)
.subscribe { event ->
if (event.walletId == walletId) {
updateWalletUI(walletId)
}
}

_headBinding?.web3PendingView?.observePendingCount(viewLifecycleOwner, pendingTxCountLiveData)
tokensLiveData.observe(viewLifecycleOwner, observer)
Expand Down Expand Up @@ -518,6 +469,50 @@ class ClassicWalletFragment : BaseFragment(R.layout.fragment_privacy_wallet), He
_headBinding?.pieItemContainer?.addView(item)
}

private fun updateWalletUI(id: String) {
lifecycleScope.launch {
val wallet = web3ViewModel.findWalletById(id)
val isWatch = wallet?.isWatch() == true
val isMissingKey = wallet?.isImported() == true && !wallet.hasLocalPrivateKey

_headBinding?.viewAnimator?.displayedChild = when {
isMissingKey -> 1
else -> 0
}

_headBinding?.watchLayout?.isVisible = isWatch

if (isMissingKey) {
val isMnemonic = wallet.category == WalletCategory.IMPORTED_MNEMONIC.value
_headBinding?.missingKeyView?.setMissingKey(isMnemonic) {
lifecycleScope.launch {
val chainId = web3ViewModel.getAddresses(id).firstOrNull()?.chainId
if (chainId != null) {
val mode = if (isMnemonic) {
WalletSecurityActivity.Mode.RE_IMPORT_MNEMONIC
} else {
WalletSecurityActivity.Mode.RE_IMPORT_PRIVATE_KEY
}
WalletSecurityActivity.show(requireActivity(), mode, walletId = id, chainId = chainId)
}
}
}
}

if (isWatch) {
val addresses = web3ViewModel.getAddressesGroupedByDestination(id)
if (addresses.isNotEmpty()) {
if (addresses.size == 1) {
val address = addresses.first().destination
_headBinding?.watchTv?.text = getString(R.string.watching_address, "${address.take(6)}..${address.takeLast(4)}")
} else {
_headBinding?.watchTv?.text = getString(R.string.watching_addresses, addresses.size)
}
}
}
}
}

private fun showReceiveAssetList() {
Web3TokenListBottomSheetDialogFragment.newInstance(walletId = walletId, TYPE_FROM_RECEIVE).apply {
setOnClickListener { token ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,8 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.compose.foundation.Image
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
Expand Down
Loading