Updated on 2026-08-14

This commit is contained in:
Tangem 2020-09-14 18:32:29 +03:00
parent 2064413949
commit 71a15f5114
7 changed files with 36 additions and 16 deletions

View file

@ -20,7 +20,7 @@ abstract class BaseStoreFragment(layoutId: Int) : Fragment(layoutId) {
abstract fun subscribeToStore()
private lateinit var mainView: View
protected lateinit var mainView: View
protected val storeSubscribersList = mutableListOf<StoreSubscriber<*>>()
override fun onCreate(savedInstanceState: Bundle?) {

View file

@ -30,14 +30,14 @@ class ReceiptReducer : SendInternalReducer {
val layoutType = determineLayoutType(amountState.mainCurrency.value, amountState.typeOfAmount)
val symbols = determineSymbols(wallet)
val showBlank = !sendState.isReadyToSend()
val result = state.copy(
visibleTypeOfReceipt = layoutType,
mainCurrencyType = sendState.amountState.mainCurrency,
mainLayoutIsVisible = sendState.isReadyToSend(),
fiat = createFiatType(converter, amountState, feeState, symbols),
crypto = createCryptoType(converter, amountState, feeState, symbols),
tokenFiat = createTokenFiatType(converter, amountState, feeState, symbols),
tokenCrypto = createTokenCryptoType(converter, amountState, feeState, symbols)
fiat = createFiatType(converter, amountState, feeState, symbols, showBlank),
crypto = createCryptoType(converter, amountState, feeState, symbols, showBlank),
tokenFiat = createTokenFiatType(converter, amountState, feeState, symbols, showBlank),
tokenCrypto = createTokenCryptoType(converter, amountState, feeState, symbols, showBlank)
)
return updateLastState(sendState.copy(receiptState = result), result)
}
@ -46,11 +46,16 @@ class ReceiptReducer : SendInternalReducer {
converter: CurrencyConverter,
amountState: AmountState,
feeState: FeeState,
symbols: ReceiptSymbols
symbols: ReceiptSymbols,
showBlank: Boolean
): ReceiptFiat {
val feeCrypto = feeState.getCurrentFee()
val feeFiat = converter.toFiat(feeCrypto)
if (showBlank) {
return ReceiptFiat("0", feeFiat.stripZeroPlainString(), feeFiat.stripZeroPlainString(), "0", symbols)
}
return if (feeState.feeIsIncluded) {
val amountFiat = converter.toFiat(amountState.amountToSendCrypto.minus(feeCrypto))
val totalFiat = converter.toFiat(amountState.amountToSendCrypto)
@ -79,10 +84,15 @@ class ReceiptReducer : SendInternalReducer {
converter: CurrencyConverter,
amountState: AmountState,
feeState: FeeState,
symbols: ReceiptSymbols
symbols: ReceiptSymbols,
showBlank: Boolean
): ReceiptCrypto {
val feeCrypto = feeState.getCurrentFee()
if (showBlank) {
return ReceiptCrypto("0", feeCrypto.stripZeroPlainString(), "0", converter.toFiat(feeCrypto).stripZeroPlainString(), "0", symbols)
}
if (feeState.feeIsIncluded) {
return ReceiptCrypto(
amountCrypto = amountState.amountToSendCrypto.minus(feeCrypto).stripZeroPlainString(),
@ -109,11 +119,17 @@ class ReceiptReducer : SendInternalReducer {
converter: CurrencyConverter,
amountState: AmountState,
feeState: FeeState,
symbols: ReceiptSymbols
symbols: ReceiptSymbols,
showBlank: Boolean
): ReceiptTokenFiat {
val feeCrypto = feeState.getCurrentFee()
val amountFiat = converter.toFiat(amountState.amountToSendCrypto)
val feeFiat = converter.toFiat(feeCrypto)
if (showBlank) {
return ReceiptTokenFiat("0", feeFiat.stripZeroPlainString(), "0", "0", "0", symbols)
}
return ReceiptTokenFiat(
amountFiat = amountFiat.stripZeroPlainString(),
feeFiat = feeFiat.stripZeroPlainString(),
@ -128,10 +144,15 @@ class ReceiptReducer : SendInternalReducer {
converter: CurrencyConverter,
amountState: AmountState,
feeState: FeeState,
symbols: ReceiptSymbols
symbols: ReceiptSymbols,
showBlank: Boolean
): ReceiptTokenCrypto {
val feeCrypto = feeState.getCurrentFee()
val totalFiat = converter.toFiat(amountState.amountToSendCrypto).plus(converter.toFiat(feeCrypto))
if (showBlank) {
return ReceiptTokenCrypto("0", feeCrypto.stripZeroPlainString(), "0", symbols)
}
return ReceiptTokenCrypto(
amountToken = amountState.amountToSendCrypto.stripZeroPlainString(),
feeCrypto = feeCrypto.stripZeroPlainString(),

View file

@ -14,7 +14,6 @@ data class ReceiptState(
val tokenFiat: ReceiptTokenFiat? = null,
val tokenCrypto: ReceiptTokenCrypto? = null,
val mainCurrencyType: Value<MainCurrencyType>? = null,
val mainLayoutIsVisible: Boolean = false,
) : StateType
data class ReceiptSymbols(

View file

@ -96,11 +96,13 @@ class SendFragment : BaseStoreFragment(R.layout.fragment_send) {
store.dispatch(ChangeAddressOrPayId(scannedCode))
store.dispatch(TruncateOrRestore(!etAddressOrPayId.isFocused))
view?.postDelayed(200) { store.dispatch(FeeAction.RequestFee) }
mainView.postDelayed(200) { store.dispatch(FeeAction.RequestFee) }
}
private fun setupAmountLayout() {
store.dispatch(SetMainCurrency(restoreMainCurrency()))
mainView.postDelayed(200) { store.dispatch(ReceiptAction.RefreshReceipt) }
tvAmountCurrency.setOnClickListener {
store.dispatch(ToggleMainCurrency)
store.dispatch(ReceiptAction.RefreshReceipt)
@ -142,7 +144,7 @@ class SendFragment : BaseStoreFragment(R.layout.fragment_send) {
val prevFocusChangeListener = etAmountToSend.onFocusChangeListener
etAmountToSend.setOnFocusChangeListener { v, hasFocus ->
prevFocusChangeListener.onFocusChange(v, hasFocus)
if (hasFocus && etAmountToSend.text?.toString() == "0") etAmountToSend.setText("")
// if (hasFocus && etAmountToSend.text?.toString() == "0") etAmountToSend.setText("")
if (!hasFocus && etAmountToSend.text?.toString() == "") etAmountToSend.setText("0")
}

View file

@ -162,7 +162,6 @@ class SendStateSubscriber(fragment: BaseStoreFragment) : FragmentStateSubscriber
val totalTokenLayout = fg.flTotalTokenCrypto as ViewGroup
fun getString(id: Int): String = mainLayout.context.getString(id)
mainLayout.show(state.mainLayoutIsVisible)
when (state.visibleTypeOfReceipt) {
ReceiptLayoutType.FIAT -> {
val receipt = state.fiat ?: return