Updated on 2026-08-14

This commit is contained in:
Tangem 2020-12-02 17:09:28 +03:00
parent db314577a0
commit 86c103c40b
10 changed files with 50 additions and 15 deletions

View file

@ -100,7 +100,10 @@ class TapWalletManager {
val secondCardId = TwinsHelper.getTwinsCardId(data.card.cardId)
val cardNumber = TwinsHelper.getTwinCardNumber(data.card.cardId)
if (secondCardId != null && cardNumber != null) {
store.dispatch(WalletAction.TwinsAction.SetTwinCard(secondCardId, cardNumber))
store.dispatch(WalletAction.TwinsAction.SetTwinCard(
secondCardId, cardNumber,
configManager?.config?.isCreatingTwinCardsAllowed ?: false
))
}
}
loadData(data)

View file

@ -11,6 +11,7 @@ data class Config(
val moonPayApiSecretKey: String = "sk_test_V8w4M19LbDjjYOt170s0tGuvXAgyEb1C",
val isWalletPayIdEnabled: Boolean = true,
val isTopUpEnabled: Boolean = false,
val isCreatingTwinCardsAllowed: Boolean = false
)
class ConfigManager(
@ -38,6 +39,7 @@ class ConfigManager(
when (name) {
isWalletPayIdEnabled -> config = config.copy(isWalletPayIdEnabled = false)
isTopUpEnabled -> config = config.copy(isTopUpEnabled = false)
isCreatingTwinCardsAllowed -> config = config.copy(isCreatingTwinCardsAllowed = false)
}
}
@ -45,6 +47,8 @@ class ConfigManager(
when (name) {
isWalletPayIdEnabled -> config = config.copy(isWalletPayIdEnabled = defaultConfig.isWalletPayIdEnabled)
isTopUpEnabled -> config = config.copy(isTopUpEnabled = defaultConfig.isTopUpEnabled)
isCreatingTwinCardsAllowed -> config =
config.copy(isCreatingTwinCardsAllowed = defaultConfig.isCreatingTwinCardsAllowed)
}
}
@ -60,6 +64,10 @@ class ConfigManager(
config = config.copy(isTopUpEnabled = newValue)
defaultConfig = defaultConfig.copy(isTopUpEnabled = newValue)
}
isCreatingTwinCardsAllowed -> {
config = config.copy(isCreatingTwinCardsAllowed = newValue)
defaultConfig = defaultConfig.copy(isCreatingTwinCardsAllowed = newValue)
}
}
}
@ -83,6 +91,7 @@ class ConfigManager(
companion object {
const val isWalletPayIdEnabled = "isWalletPayIdEnabled"
const val isTopUpEnabled = "useTopUp"
const val isCreatingTwinCardsAllowed = "isCreatingTwinCardsAllowed"
const val coinMarketCapKey = "coinMarketCapKey"
const val moonPayApiKey = "moonPayApiKey"
const val moonPayApiSecretKey = "moonPayApiSecretKey"

View file

@ -18,6 +18,7 @@ sealed class DetailsAction : Action {
val card: Card,
val scanNoteResponse: ScanNoteResponse,
val wallet: Wallet?,
val isCreatingTwinWalletAllowed: Boolean?,
val fiatCurrencyName: FiatCurrencyName,
val fiatCurrencies: List<FiatCurrencyName>? = null,
) : DetailsAction()

View file

@ -10,7 +10,6 @@ import com.tangem.tap.domain.TwinsHelper
import com.tangem.tap.domain.extensions.toSendableAmounts
import com.tangem.tap.features.details.redux.twins.CreateTwinWalletReducer
import com.tangem.tap.features.details.redux.twins.CreateTwinWalletState
import com.tangem.wallet.BuildConfig
import org.rekotlin.Action
import java.util.*
@ -62,7 +61,7 @@ private fun handlePrepareScreen(action: DetailsAction.PrepareScreen, state: Deta
twinCardNumber = TwinsHelper.getTwinCardNumber(action.card.cardId),
createTwinWallet = null,
showAlert = false,
allowRecreatingWallet = BuildConfig.DEBUG
allowRecreatingWallet = action.isCreatingTwinWalletAllowed
)
} else {
null

View file

@ -94,11 +94,14 @@ sealed class WalletAction : Action {
data class TopUp(val context: Context, val toolbarColor: Int) : TopUpAction()
}
data class ChangeSelectedAddress(val type: AddressType): WalletAction()
data class ChangeSelectedAddress(val type: AddressType) : WalletAction()
sealed class TwinsAction : WalletAction() {
object ShowOnboarding : TwinsAction()
object SetOnboardingShown : TwinsAction()
data class SetTwinCard(val secondCardId: String, val number: TwinCardNumber) : TwinsAction()
data class SetTwinCard(
val secondCardId: String, val number: TwinCardNumber,
val isCreatingTwinCardsAllowed: Boolean
) : TwinsAction()
}
}

View file

@ -34,12 +34,17 @@ private fun internalReduce(action: Action, state: AppState): WalletState {
when (action) {
is WalletAction.ResetState -> newState = WalletState()
is WalletAction.EmptyWallet -> newState = newState.copy(
state = ProgressState.Done,
currencyData = BalanceWidgetData(BalanceStatus.EmptyCard),
mainButton = WalletMainButton.CreateWalletButton(true),
topUpState = TopUpState(false)
)
is WalletAction.EmptyWallet -> {
val creatingWalletAllowed = !(newState.twinCardsState != null &&
newState.twinCardsState?.isCreatingTwinCardsAllowed != true)
newState = newState.copy(
state = ProgressState.Done,
currencyData = BalanceWidgetData(BalanceStatus.EmptyCard),
mainButton = WalletMainButton.CreateWalletButton(creatingWalletAllowed),
topUpState = TopUpState(false)
)
}
is WalletAction.LoadData.Failure -> {
when (action.error) {
is TapError.NoInternetConnection -> {
@ -224,13 +229,18 @@ private fun internalReduce(action: Action, state: AppState): WalletState {
twinCardsState = TwinCardsState(
secondCardId = action.secondCardId,
cardNumber = action.number,
newState.twinCardsState?.showTwinOnboarding ?: false)
showTwinOnboarding = newState.twinCardsState?.showTwinOnboarding
?: false,
isCreatingTwinCardsAllowed = action.isCreatingTwinCardsAllowed
)
)
}
is WalletAction.TwinsAction.ShowOnboarding -> {
newState = newState.copy(
twinCardsState = newState.twinCardsState?.copy(showTwinOnboarding = true)
?: TwinCardsState(null, null, true)
?: TwinCardsState(null, null,
showTwinOnboarding = true,
isCreatingTwinCardsAllowed = false)
)
}
is WalletAction.TwinsAction.SetOnboardingShown -> {

View file

@ -105,5 +105,6 @@ data class TopUpState(
data class TwinCardsState(
val secondCardId: String?,
val cardNumber: TwinCardNumber?,
val showTwinOnboarding: Boolean
val showTwinOnboarding: Boolean,
val isCreatingTwinCardsAllowed: Boolean
)

View file

@ -101,7 +101,7 @@ class WalletFragment : Fragment(R.layout.fragment_wallet), StoreSubscriber<Walle
}
tv_twin_card_number.text = getString(R.string.wallet_twins_chip_format, number)
}
if (state.twinCardsState?.cardNumber == null){
if (state.twinCardsState?.cardNumber == null) {
tv_twin_card_number.hide()
iv_twin_card.hide()
}
@ -308,6 +308,7 @@ class WalletFragment : Fragment(R.layout.fragment_wallet), StoreSubscriber<Walle
store.dispatch(DetailsAction.PrepareScreen(
scanNoteResponse.card, scanNoteResponse,
store.state.walletState.wallet,
store.state.globalState.configManager?.config?.isCreatingTwinCardsAllowed,
store.state.globalState.appCurrency
))
store.dispatch(NavigationAction.NavigateTo(AppScreen.Details))