Skip to content

Commit e11fe24

Browse files
committed
fix: bill display after cashlinkmanager
Signed-off-by: Brandon McAnsh <git@bmcreations.dev>
1 parent ff3847c commit e11fe24

3 files changed

Lines changed: 75 additions & 79 deletions

File tree

api/src/main/java/com/getcode/network/repository/SendTransactionRepository.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ class SendTransactionRepository @Inject constructor(
2727
private lateinit var organizer: Organizer
2828
private lateinit var owner: Ed25519.KeyPair
2929
private lateinit var payload: CodePayload
30-
lateinit var payloadData: List<Byte>
30+
private lateinit var payloadData: List<Byte>
3131

3232
private lateinit var rendezvousKey: Ed25519.KeyPair
3333
private var receivingAccount: PublicKey? = null
3434

35-
fun init(amount: KinAmount, organizer: Organizer, owner: Ed25519.KeyPair) {
35+
fun init(amount: KinAmount, organizer: Organizer, owner: Ed25519.KeyPair): List<Byte> {
3636
this.amount = amount
3737
this.organizer = organizer
3838
this.owner = owner
@@ -46,6 +46,8 @@ class SendTransactionRepository @Inject constructor(
4646
this.payloadData = payload.codeData.toList()
4747
this.rendezvousKey = payload.rendezvous
4848
this.receivingAccount = null
49+
50+
return payloadData
4951
}
5052

5153
fun startTransaction(): Flowable<IntentMetadata> {

app/src/main/java/com/getcode/domain/CashLinkManager.kt

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.getcode.domain
22

3-
import com.getcode.analytics.AnalyticsManager
43
import com.getcode.ed25519.Ed25519
4+
import com.getcode.ed25519.Ed25519.KeyPair
55
import com.getcode.model.KinAmount
66
import com.getcode.network.repository.SendTransactionRepository
77
import com.getcode.solana.organizer.Organizer
@@ -20,17 +20,24 @@ class CashLinkManager @Inject constructor(
2020
private var billDismissTimer: TimerTask? = null
2121
private var sendTransactionDisposable: Disposable? = null
2222

23+
val amount: KinAmount
24+
get() = sendTransactionRepository.getAmount()
25+
26+
val rendezvous: KeyPair
27+
get() = sendTransactionRepository.getRendezvous()
28+
2329
fun awaitBillGrab(
2430
amount: KinAmount,
2531
organizer: Organizer,
2632
owner: Ed25519.KeyPair,
33+
present: (List<Byte>) -> Unit,
2734
onGrabbed: () -> Unit,
2835
onTimeout: () -> Unit,
2936
onError: (Throwable) -> Unit
3037
) {
3138
// this should not be in the view model
3239
sendTransactionDisposable?.dispose()
33-
sendTransactionRepository.init(amount, organizer, owner)
40+
val payload = sendTransactionRepository.init(amount, organizer, owner)
3441
sendTransactionDisposable =
3542
sendTransactionRepository.startTransaction()
3643
.subscribe({
@@ -41,10 +48,12 @@ class CashLinkManager @Inject constructor(
4148
})
4249

4350
presentSend(onTimeout)
51+
52+
present(payload)
4453
}
4554

4655
private fun presentSend(onTimeout: () -> Unit) {
47-
billDismissTimer?.cancel()
56+
cancelBillTimeout()
4857
billDismissTimer = Timer().schedule((1000 * 50).toLong()) {
4958
onTimeout()
5059
}

app/src/main/java/com/getcode/view/main/home/HomeViewModel.kt

Lines changed: 59 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import com.getcode.manager.GiftCardManager
1818
import com.getcode.manager.MnemonicManager
1919
import com.getcode.manager.SessionManager
2020
import com.getcode.manager.TopBarManager
21-
import com.getcode.model.AppSetting
2221
import com.getcode.model.BuyModuleFeature
2322
import com.getcode.model.CodePayload
2423
import com.getcode.model.Currency
@@ -62,17 +61,14 @@ import com.getcode.network.client.requestFirstKinAirdrop
6261
import com.getcode.network.client.sendRemotely
6362
import com.getcode.network.client.sendRequestToReceiveBill
6463
import com.getcode.network.exchange.Exchange
65-
import com.getcode.network.repository.AppSettings
6664
import com.getcode.network.repository.AppSettingsRepository
6765
import com.getcode.network.repository.BetaFlagsRepository
6866
import com.getcode.network.repository.FeatureRepository
6967
import com.getcode.network.repository.PaymentRepository
7068
import com.getcode.network.repository.PrefRepository
7169
import com.getcode.network.repository.ReceiveTransactionRepository
72-
import com.getcode.network.repository.SendTransactionRepository
7370
import com.getcode.network.repository.StatusRepository
7471
import com.getcode.network.repository.hexEncodedString
75-
import com.getcode.network.repository.replaceParam
7672
import com.getcode.network.repository.toPublicKey
7773
import com.getcode.solana.organizer.GiftCardAccount
7874
import com.getcode.solana.organizer.Organizer
@@ -93,7 +89,6 @@ import com.getcode.view.BaseViewModel
9389
import com.kik.kikx.models.ScannableKikCode
9490
import dagger.hilt.android.lifecycle.HiltViewModel
9591
import io.reactivex.rxjava3.core.Completable
96-
import io.reactivex.rxjava3.disposables.Disposable
9792
import io.reactivex.rxjava3.schedulers.Schedulers
9893
import kotlinx.coroutines.CoroutineScope
9994
import kotlinx.coroutines.Dispatchers
@@ -170,7 +165,6 @@ enum class RestrictionType {
170165
@HiltViewModel
171166
class 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

Comments
 (0)