@@ -18,7 +18,6 @@ import com.getcode.manager.GiftCardManager
1818import com.getcode.manager.MnemonicManager
1919import com.getcode.manager.SessionManager
2020import com.getcode.manager.TopBarManager
21- import com.getcode.model.AppSetting
2221import com.getcode.model.BuyModuleFeature
2322import com.getcode.model.CodePayload
2423import com.getcode.model.Currency
@@ -62,17 +61,14 @@ import com.getcode.network.client.requestFirstKinAirdrop
6261import com.getcode.network.client.sendRemotely
6362import com.getcode.network.client.sendRequestToReceiveBill
6463import com.getcode.network.exchange.Exchange
65- import com.getcode.network.repository.AppSettings
6664import com.getcode.network.repository.AppSettingsRepository
6765import com.getcode.network.repository.BetaFlagsRepository
6866import com.getcode.network.repository.FeatureRepository
6967import com.getcode.network.repository.PaymentRepository
7068import com.getcode.network.repository.PrefRepository
7169import com.getcode.network.repository.ReceiveTransactionRepository
72- import com.getcode.network.repository.SendTransactionRepository
7370import com.getcode.network.repository.StatusRepository
7471import com.getcode.network.repository.hexEncodedString
75- import com.getcode.network.repository.replaceParam
7672import com.getcode.network.repository.toPublicKey
7773import com.getcode.solana.organizer.GiftCardAccount
7874import com.getcode.solana.organizer.Organizer
@@ -93,7 +89,6 @@ import com.getcode.view.BaseViewModel
9389import com.kik.kikx.models.ScannableKikCode
9490import dagger.hilt.android.lifecycle.HiltViewModel
9591import io.reactivex.rxjava3.core.Completable
96- import io.reactivex.rxjava3.disposables.Disposable
9792import io.reactivex.rxjava3.schedulers.Schedulers
9893import kotlinx.coroutines.CoroutineScope
9994import kotlinx.coroutines.Dispatchers
@@ -170,7 +165,6 @@ enum class RestrictionType {
170165@HiltViewModel
171166class HomeViewModel @Inject constructor(
172167 private val client : Client ,
173- private val sendTransactionRepository : SendTransactionRepository ,
174168 private val receiveTransactionRepository : ReceiveTransactionRepository ,
175169 private val paymentRepository : PaymentRepository ,
176170 private val balanceController : BalanceController ,
@@ -440,95 +434,86 @@ class HomeViewModel @Inject constructor(
440434 }
441435 },
442436 onTimeout = {
443- cancelSend()
437+ cancelSend(style = PresentationStyle . Slide )
444438 analytics.billTimeoutReached(
445439 bill.amount.kin,
446440 bill.amount.rate.currency,
447441 AnalyticsManager .BillPresentationStyle .Slide
448442 )
449443 },
450- onError = {
451- cancelSend(style = PresentationStyle .Slide )
452- }
444+ onError = { cancelSend(style = PresentationStyle .Slide ) },
445+ present = { data -> presentSend(data, bill, vibrate) }
453446 )
454-
455- presentSend(sendTransactionRepository.payloadData, bill, vibrate)
456447 }
457448
458- private fun presentSend (data : List <Byte >, bill : Bill , isVibrate : Boolean = false) =
459- viewModelScope.launch {
460- if (bill.didReceive) {
461- withContext(Dispatchers .Main ) {
462- uiFlow.update {
463- val billState = it.billState
464- it.copy(
465- billState = billState.copy(
466- valuation = PaymentValuation (
467- bill.amount
468- ),
469- )
470- )
471- }
472- }
473- }
474-
475- val style: PresentationStyle =
476- if (bill.didReceive) PresentationStyle .Pop else PresentationStyle .Slide
477-
478- withContext(Dispatchers .Main ) {
479- uiFlow.update {
480- val billState = it.billState
481- it.copy(
482- presentationStyle = style,
483- billState = billState.copy(
484- bill = Bill .Cash (
485- data = data,
486- amount = bill.amount,
487- didReceive = bill.didReceive
488- ),
489- valuation = PaymentValuation (bill.amount),
490- showToast = bill.didReceive
491- )
449+ private fun presentSend (data : List <Byte >, bill : Bill , isVibrate : Boolean = false) {
450+ if (bill.didReceive) {
451+ uiFlow.update {
452+ val billState = it.billState
453+ it.copy(
454+ billState = billState.copy(
455+ valuation = PaymentValuation (
456+ bill.amount
457+ ),
492458 )
493- }
459+ )
494460 }
461+ }
495462
496- if (style is PresentationStyle .Visible ) {
497- analytics.billShown(
498- bill.amountFloored.kin,
499- bill.amountFloored.rate.currency,
500- when (style) {
501- PresentationStyle .Pop -> AnalyticsManager .BillPresentationStyle .Pop
502- PresentationStyle .Slide -> AnalyticsManager .BillPresentationStyle .Slide
503- }
463+ val style: PresentationStyle =
464+ if (bill.didReceive) PresentationStyle .Pop else PresentationStyle .Slide
465+
466+ uiFlow.update {
467+ val billState = it.billState
468+ it.copy(
469+ presentationStyle = style,
470+ billState = billState.copy(
471+ bill = Bill .Cash (
472+ data = data,
473+ amount = bill.amount,
474+ didReceive = bill.didReceive
475+ ),
476+ valuation = PaymentValuation (bill.amount),
477+ showToast = bill.didReceive
504478 )
505- }
479+ )
480+ }
506481
507- if (isVibrate) {
508- vibrator.vibrate()
509- }
482+ if (style is PresentationStyle .Visible ) {
483+ analytics.billShown(
484+ bill.amountFloored.kin,
485+ bill.amountFloored.rate.currency,
486+ when (style) {
487+ PresentationStyle .Pop -> AnalyticsManager .BillPresentationStyle .Pop
488+ PresentationStyle .Slide -> AnalyticsManager .BillPresentationStyle .Slide
489+ }
490+ )
510491 }
511492
493+ if (isVibrate) {
494+ vibrator.vibrate()
495+ }
496+ }
497+
512498 fun cancelSend (style : PresentationStyle = PresentationStyle .Slide ) {
513499 cashLinkManager.cancelSend()
514500 BottomBarManager .clearByType(BottomBarManager .BottomBarMessageType .REMOTE_SEND )
515501
502+ val shown = showToastIfNeeded(style)
516503
517- viewModelScope.launch {
518- val shown = showToastIfNeeded(style)
519-
520- uiFlow.update {
521- it.copy(
522- presentationStyle = style,
523- billState = it.billState.copy(
524- bill = null ,
525- valuation = null ,
526- primaryAction = null ,
527- secondaryAction = null ,
528- )
504+ uiFlow.update {
505+ it.copy(
506+ presentationStyle = style,
507+ billState = it.billState.copy(
508+ bill = null ,
509+ valuation = null ,
510+ primaryAction = null ,
511+ secondaryAction = null ,
529512 )
530- }
513+ )
514+ }
531515
516+ viewModelScope.launch {
532517 historyController.fetchChats()
533518 balanceController.fetchBalanceSuspend()
534519
@@ -1325,7 +1310,7 @@ class HomeViewModel @Inject constructor(
13251310
13261311 private fun shareGiftCard () {
13271312 val giftCard = giftCardManager.createGiftCard()
1328- val amount = sendTransactionRepository.getAmount()
1313+ val amount = cashLinkManager.amount
13291314 var loadingIndicatorTimer: TimerTask ? = null
13301315
13311316 if (! networkObserver.isConnected) {
@@ -1335,7 +1320,7 @@ class HomeViewModel @Inject constructor(
13351320
13361321 client.sendRemotely(
13371322 amount = amount,
1338- rendezvousKey = sendTransactionRepository.getRendezvous() .publicKeyBytes.toPublicKey(),
1323+ rendezvousKey = cashLinkManager.rendezvous .publicKeyBytes.toPublicKey(),
13391324 giftCard = giftCard
13401325 )
13411326 .doOnSubscribe {
0 commit comments