Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Vip Support #7870

Merged
merged 1 commit into from
Jan 23, 2025
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
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ dependencies {
implementation 'com.github.horizontalsystems:ethereum-kit-android:0c770e3'
implementation 'com.github.horizontalsystems:blockchain-fee-rate-kit-android:1d3bd49'
implementation 'com.github.horizontalsystems:binance-chain-kit-android:c1509a2'
implementation 'com.github.horizontalsystems:market-kit-android:e4e90bd'
implementation 'com.github.horizontalsystems:market-kit-android:8c9fc42'
implementation 'com.github.horizontalsystems:solana-kit-android:ce738d8'
implementation 'com.github.horizontalsystems:tron-kit-android:dc3dca7'
// Zcash SDK
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ import io.horizontalsystems.bankwallet.modules.market.Value
import io.horizontalsystems.bankwallet.modules.market.favorites.WatchlistSorting
import io.horizontalsystems.bankwallet.modules.settings.appearance.AppIcon
import io.horizontalsystems.bankwallet.modules.settings.appearance.PriceChangeInterval
import io.horizontalsystems.bankwallet.modules.settings.security.autolock.AutoLockInterval
import io.horizontalsystems.bankwallet.modules.settings.privacy.tor.TorStatus
import io.horizontalsystems.bankwallet.modules.settings.security.autolock.AutoLockInterval
import io.horizontalsystems.bankwallet.modules.settings.terms.TermsModule
import io.horizontalsystems.bankwallet.modules.theme.ThemeType
import io.horizontalsystems.bankwallet.modules.transactions.FilterTransactionType
Expand Down Expand Up @@ -121,6 +121,7 @@ interface ILocalStorage {
val balanceTabButtonsEnabledFlow: StateFlow<Boolean>
var nonRecommendedAccountAlertDismissedAccounts: Set<String>
var personalSupportEnabled: Boolean
var vipSupportEnabled: Boolean
var hideSuspiciousTransactions: Boolean
var pinRandomized: Boolean
var utxoExpertModeEnabled: Boolean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class LocalStorageManager(
private val BALANCE_AUTO_HIDE_ENABLED = "balance_auto_hide_enabled"
private val NON_RECOMMENDED_ACCOUNT_ALERT_DISMISSED_ACCOUNTS = "non_recommended_account_alert_dismissed_accounts"
private val PERSONAL_SUPPORT_ENABLED = "personal_support_enabled"
private val VIP_SUPPORT_ENABLED = "vip_support_enabled"
private val APP_ID = "app_id"
private val APP_AUTO_LOCK_INTERVAL = "app_auto_lock_interval"
private val HIDE_SUSPICIOUS_TX = "hide_suspicious_tx"
Expand Down Expand Up @@ -485,6 +486,12 @@ class LocalStorageManager(
preferences.edit().putBoolean(PERSONAL_SUPPORT_ENABLED, enabled).apply()
}

override var vipSupportEnabled: Boolean
get() = preferences.getBoolean(VIP_SUPPORT_ENABLED, false)
set(enabled) {
preferences.edit().putBoolean(VIP_SUPPORT_ENABLED, enabled).apply()
}

override var hideSuspiciousTransactions: Boolean
get() = preferences.getBoolean(HIDE_SUSPICIOUS_TX, true)
set(value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,9 @@ class MarketKitWrapper(
fun requestPersonalSupport(username: String): Single<Response<Void>> =
requestWithAuthToken { marketKit.requestPersonalSupport(it, username) }

fun requestVipSupport(username: String): Single<Response<Void>> =
requestWithAuthToken { marketKit.requestVipSupport(it, username) }

// Stats

fun sendStats(stats: String, appVersion: String, appId: String?): Single<Unit> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ import androidx.compose.material.Icon
import androidx.compose.material.Surface
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
Expand All @@ -44,6 +48,7 @@ import io.horizontalsystems.bankwallet.modules.contacts.ContactsFragment
import io.horizontalsystems.bankwallet.modules.contacts.Mode
import io.horizontalsystems.bankwallet.modules.manageaccount.dialogs.BackupRequiredDialog
import io.horizontalsystems.bankwallet.modules.manageaccounts.ManageAccountsModule
import io.horizontalsystems.bankwallet.modules.settings.vipsupport.VipSupportBottomSheet
import io.horizontalsystems.bankwallet.modules.walletconnect.WCAccountTypeNotSupportedDialog
import io.horizontalsystems.bankwallet.modules.walletconnect.WCManager
import io.horizontalsystems.bankwallet.ui.compose.ComposeAppTheme
Expand All @@ -65,6 +70,7 @@ fun SettingsScreen(
navController: NavController,
viewModel: MainSettingsViewModel = viewModel(factory = MainSettingsModule.Factory()),
) {
var isVipSupportVisible by remember { mutableStateOf(false) }

Surface(color = ComposeAppTheme.colors.tyler) {
Column {
Expand All @@ -74,17 +80,27 @@ fun SettingsScreen(

Column(modifier = Modifier.verticalScroll(rememberScrollState())) {
Spacer(modifier = Modifier.height(12.dp))
SettingSections(viewModel, navController)
SettingSections(
viewModel = viewModel,
navController = navController,
openVipSupport = {
isVipSupportVisible = true
})
SettingsFooter(viewModel.appVersion, viewModel.companyWebPage)
}
}
VipSupportBottomSheet(
isBottomSheetVisible = isVipSupportVisible,
close = { isVipSupportVisible = false }
)
}
}

@Composable
private fun SettingSections(
viewModel: MainSettingsViewModel,
navController: NavController
navController: NavController,
openVipSupport: () -> Unit
) {
val uiState = viewModel.uiState
val context = LocalContext.current
Expand Down Expand Up @@ -328,9 +344,7 @@ private fun SettingSections(
HsSettingCell(
R.string.Settings_VipSupport,
R.drawable.ic_support_yellow_24,
onClick = {

}
onClick = openVipSupport
)
Divider(
thickness = 1.dp,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
package io.horizontalsystems.bankwallet.modules.settings.vipsupport

import android.widget.Toast
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.ModalBottomSheet
import androidx.compose.material3.rememberModalBottomSheetState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.focus.FocusRequester
import androidx.compose.ui.focus.focusRequester
import androidx.compose.ui.graphics.ColorFilter
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import androidx.lifecycle.viewmodel.compose.viewModel
import io.horizontalsystems.bankwallet.R
import io.horizontalsystems.bankwallet.ui.compose.ComposeAppTheme
import io.horizontalsystems.bankwallet.ui.compose.components.ButtonPrimaryDefault
import io.horizontalsystems.bankwallet.ui.compose.components.ButtonPrimaryYellow
import io.horizontalsystems.bankwallet.ui.compose.components.ButtonPrimaryYellowWithSpinner
import io.horizontalsystems.bankwallet.ui.compose.components.FormsInput
import io.horizontalsystems.bankwallet.ui.compose.components.InfoText
import io.horizontalsystems.bankwallet.ui.compose.components.VSpacer
import io.horizontalsystems.bankwallet.ui.extensions.BottomSheetHeader

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun VipSupportBottomSheet(
isBottomSheetVisible: Boolean,
close: () -> Unit
) {
val viewModel = viewModel<VipSupportViewModel>(factory = VipSupportModule.Factory())
val focusRequester = remember { FocusRequester() }
val modalBottomSheetState = rememberModalBottomSheetState()
val context = LocalContext.current
val uiState = viewModel.uiState

LaunchedEffect(uiState.showError) {
if (uiState.showError) {
Toast.makeText(context, R.string.Settings_PersonalSupport_Requestfailed, Toast.LENGTH_SHORT).show()
viewModel.errorShown()
}
}

if (isBottomSheetVisible) {
ModalBottomSheet(
onDismissRequest = {
close.invoke()
},
sheetState = modalBottomSheetState,
containerColor = ComposeAppTheme.colors.transparent
) {
BottomSheetHeader(
iconPainter = painterResource(R.drawable.prem_vip_support_24),
title = stringResource(R.string.Settings_VipSupport),
onCloseClick = close,
iconTint = ColorFilter.tint(ComposeAppTheme.colors.jacob)
) {
if (uiState.showRequestForm) {
InfoText(
text = stringResource(R.string.Settings_PersonalSupport_EnterTelegramAccountDescription),
)
FormsInput(
modifier = Modifier
.focusRequester(focusRequester)
.padding(horizontal = 16.dp, vertical = 12.dp),
hint = stringResource(R.string.Settings_PersonalSupport_UsernameHint),
onValueChange = viewModel::onUsernameChange
)
VSpacer(24.dp)
ButtonPrimaryYellowWithSpinner(
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 16.dp),
title = stringResource(R.string.Settings_PersonalSupport_Request),
showSpinner = uiState.showSpinner,
enabled = uiState.buttonEnabled,
onClick = {
viewModel.onRequestClicked()
}
)
VSpacer(24.dp)
} else {
InfoText(
text = stringResource(R.string.Settings_PersonalSupport_YouAlreadyRequestedSupportDescription),
paddingBottom = 32.dp
)
VSpacer(24.dp)
ButtonPrimaryYellow(
modifier = Modifier
.fillMaxWidth()
.padding(start = 16.dp, end = 16.dp),
title = stringResource(R.string.Settings_PersonalSupport_OpenTelegram),
onClick = {
context.packageManager.getLaunchIntentForPackage("org.telegram.messenger")
?.let {
context.startActivity(it)
}
},
)
VSpacer(16.dp)
ButtonPrimaryDefault(
modifier = Modifier
.fillMaxWidth()
.padding(start = 16.dp, end = 16.dp, bottom = 16.dp),
title = stringResource(R.string.Settings_PersonalSupport_NewRequest),
onClick = {
viewModel.showRequestForm()
},
)
VSpacer(24.dp)
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package io.horizontalsystems.bankwallet.modules.settings.vipsupport

import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.viewModelScope
import io.horizontalsystems.bankwallet.core.App
import io.horizontalsystems.bankwallet.core.ILocalStorage
import io.horizontalsystems.bankwallet.core.ViewModelUiState
import io.horizontalsystems.bankwallet.core.managers.MarketKitWrapper
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.rx2.await

class VipSupportViewModel(
private val marketKitWrapper: MarketKitWrapper,
private val localStorage: ILocalStorage,
) : ViewModelUiState<VipSupportModule.UiState>() {

private var contactName: String = ""
private var showError = false
private var showSpinner = false
private var buttonEnabled = false
private var showRequestForm = !localStorage.vipSupportEnabled

override fun createState() = VipSupportModule.UiState(
contactName = contactName,
showError = showError,
showSpinner = showSpinner,
buttonEnabled = buttonEnabled,
showRequestForm = showRequestForm
)

fun onUsernameChange(username: String) {
contactName = username
buttonEnabled = username.isNotEmpty()
emitState()
}

fun errorShown() {
showError = false
emitState()
}

fun onRequestClicked() {
showSpinner = true
buttonEnabled = false
emitState()

viewModelScope.launch(Dispatchers.IO) {
try {
val request = marketKitWrapper.requestVipSupport(contactName).await()
if (request.code() != 200) throw Exception("Error")
localStorage.vipSupportEnabled = true
showRequestForm = false
} catch (e: Throwable) {
showSpinner = false
buttonEnabled = true
showError = true
emitState()
return@launch
}
showSpinner = false
buttonEnabled = true
emitState()
}
}

fun showRequestForm() {
showRequestForm = true
emitState()
}

}

object VipSupportModule {
class Factory : ViewModelProvider.Factory {
@Suppress("UNCHECKED_CAST")
override fun <T : ViewModel> create(modelClass: Class<T>): T {
return VipSupportViewModel(App.marketKit, App.localStorage) as T
}
}

data class UiState(
val contactName: String,
val showError: Boolean = false,
val showSpinner: Boolean = false,
val buttonEnabled: Boolean = false,
val showRequestForm: Boolean = false,
)
}
Loading