Skip to content
Merged
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
50 changes: 23 additions & 27 deletions app/src/main/java/com/getcode/view/main/home/HomeViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -640,8 +640,8 @@ class HomeViewModel @Inject constructor(
}.onFailure { error ->
error.printStackTrace()
TopBarManager.showMessage(
"Payment Failed",
"This payment request could not be paid at this time. Please try again later."
resources.getString(R.string.error_title_payment_failed),
resources.getString(R.string.error_description_payment_failed),
)
uiFlow.update { uiModel ->
uiModel.copy(
Expand All @@ -659,47 +659,43 @@ class HomeViewModel @Inject constructor(
}
}

fun cancelPayment(rejected: Boolean, ignoreRedirect: Boolean = false) {
private fun cancelPayment(rejected: Boolean, ignoreRedirect: Boolean = false) {
val bill = uiFlow.value.billState.bill ?: return
val amount = bill.amount
val request = bill.metadata.request

analytics.requestHidden(amount = amount)

if (rejected) {
if (!ignoreRedirect) {
request?.cancelUrl?.let {
viewModelScope.launch {
_eventFlow.emit(HomeEvent.OpenUrl(it))
}
}
}
} else {
showToast(amount, isDeposit = false)

if (!ignoreRedirect) {
request?.successUrl?.let {
viewModelScope.launch {
_eventFlow.emit(HomeEvent.OpenUrl(it))
}
}
}
}

uiFlow.update {
it.copy(
presentationStyle = PresentationStyle.Hidden,
presentationStyle = PresentationStyle.Slide,
billState = it.billState.copy(
bill = null,
showToast = false,
paymentConfirmation = null,
loginConfirmation = null,
toast = null,
valuation = null,
hideBillButtons = false,
)
)
}

viewModelScope.launch {
delay(300)
if (rejected) {
if (!ignoreRedirect) {
request?.cancelUrl?.let {
_eventFlow.emit(HomeEvent.OpenUrl(it))
}
}
} else {
showToast(amount, isDeposit = false)

if (!ignoreRedirect) {
request?.successUrl?.let {
_eventFlow.emit(HomeEvent.OpenUrl(it))
}
}
}
}
}

fun rejectPayment(ignoreRedirect: Boolean = false) {
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
<string name="deleteAccount_title_wontDo">What deleting won\'t do</string>
<string name="error_description_alreadyCollected">This Kin was already collected by someone else.</string>
<string name="error_description_alreadyCollectedBySomeone">This Kin was already collected by someone.</string>
<string name="error_description_payment_failed">This payment request could not be paid at this time. Please try again later.</string>
<string name="error_description_cameraAccessRequired">Please allow access to the camera in Settings to use Code.</string>
<string name="error_description_codeTimedOut">Please re-enter your phone number and try again.</string>
<string name="error_description_contactsAccessRequired">Please allow access to the contacts in Settings to send invites.</string>
Expand All @@ -87,6 +88,7 @@
<string name="error_description_tooManyAccounts">You can only create so many new accounts each day.</string>
<string name="error_title_alreadyCollected">Kin Already Collected</string>
<string name="error_title_alreadyCollectedBySomeone">Kin Already Collected</string>
<string name="error_title_payment_failed">Payment Failed</string>
<string name="error_title_cameraAccessRequired">Camera Access Required</string>
<string name="error_title_codeTimedOut">Verification Code Timed Out</string>
<string name="error_title_contactsAccessRequired">Contacts Access Required</string>
Expand Down