From b1b4e96d0e9223d415a900ccb8e584f82e36ad2e Mon Sep 17 00:00:00 2001 From: Rafael Date: Fri, 24 Jan 2025 14:42:03 +0600 Subject: [PATCH] Open created vip support group on click --- app/build.gradle | 2 +- .../bankwallet/core/Interfaces.kt | 2 +- .../core/managers/LocalStorageManager.kt | 10 ++++---- .../core/managers/MarketKitWrapper.kt | 2 +- .../vipsupport/VipSupportBottomSheet.kt | 8 +++--- .../vipsupport/VipSupportViewModel.kt | 25 +++++++++++-------- 6 files changed, 26 insertions(+), 23 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 1a2a95c452..a94caed195 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -288,7 +288,7 @@ dependencies { implementation 'com.github.horizontalsystems:ethereum-kit-android:201296c' 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:8c9fc42' + implementation 'com.github.horizontalsystems:market-kit-android:0ea65ac' implementation 'com.github.horizontalsystems:solana-kit-android:ce738d8' implementation 'com.github.horizontalsystems:tron-kit-android:dc3dca7' // Zcash SDK diff --git a/app/src/main/java/io/horizontalsystems/bankwallet/core/Interfaces.kt b/app/src/main/java/io/horizontalsystems/bankwallet/core/Interfaces.kt index 2946557d19..885dbc3869 100644 --- a/app/src/main/java/io/horizontalsystems/bankwallet/core/Interfaces.kt +++ b/app/src/main/java/io/horizontalsystems/bankwallet/core/Interfaces.kt @@ -121,7 +121,7 @@ interface ILocalStorage { val balanceTabButtonsEnabledFlow: StateFlow var nonRecommendedAccountAlertDismissedAccounts: Set var personalSupportEnabled: Boolean - var vipSupportEnabled: Boolean + var vipSupportLink: String? var hideSuspiciousTransactions: Boolean var pinRandomized: Boolean var utxoExpertModeEnabled: Boolean diff --git a/app/src/main/java/io/horizontalsystems/bankwallet/core/managers/LocalStorageManager.kt b/app/src/main/java/io/horizontalsystems/bankwallet/core/managers/LocalStorageManager.kt index b8c30a1920..0a9943aa96 100644 --- a/app/src/main/java/io/horizontalsystems/bankwallet/core/managers/LocalStorageManager.kt +++ b/app/src/main/java/io/horizontalsystems/bankwallet/core/managers/LocalStorageManager.kt @@ -77,7 +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 VIP_SUPPORT_LINK = "vip_support_link" private val APP_ID = "app_id" private val APP_AUTO_LOCK_INTERVAL = "app_auto_lock_interval" private val HIDE_SUSPICIOUS_TX = "hide_suspicious_tx" @@ -486,10 +486,10 @@ 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 vipSupportLink: String? + get() = preferences.getString(VIP_SUPPORT_LINK, null) + set(link) { + preferences.edit().putString(VIP_SUPPORT_LINK, link).apply() } override var hideSuspiciousTransactions: Boolean diff --git a/app/src/main/java/io/horizontalsystems/bankwallet/core/managers/MarketKitWrapper.kt b/app/src/main/java/io/horizontalsystems/bankwallet/core/managers/MarketKitWrapper.kt index 5534d66ba5..f3abd738c8 100644 --- a/app/src/main/java/io/horizontalsystems/bankwallet/core/managers/MarketKitWrapper.kt +++ b/app/src/main/java/io/horizontalsystems/bankwallet/core/managers/MarketKitWrapper.kt @@ -278,7 +278,7 @@ class MarketKitWrapper( fun requestPersonalSupport(username: String): Single> = requestWithAuthToken { marketKit.requestPersonalSupport(it, username) } - fun requestVipSupport(username: String): Single> = + fun requestVipSupport(username: String): Single> = requestWithAuthToken { marketKit.requestVipSupport(it, username) } // Stats diff --git a/app/src/main/java/io/horizontalsystems/bankwallet/modules/settings/vipsupport/VipSupportBottomSheet.kt b/app/src/main/java/io/horizontalsystems/bankwallet/modules/settings/vipsupport/VipSupportBottomSheet.kt index 1f6b6d3e69..accf5a1523 100644 --- a/app/src/main/java/io/horizontalsystems/bankwallet/modules/settings/vipsupport/VipSupportBottomSheet.kt +++ b/app/src/main/java/io/horizontalsystems/bankwallet/modules/settings/vipsupport/VipSupportBottomSheet.kt @@ -27,6 +27,7 @@ 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 +import io.horizontalsystems.bankwallet.ui.helpers.LinkHelper @OptIn(ExperimentalMaterial3Api::class) @Composable @@ -61,7 +62,7 @@ fun VipSupportBottomSheet( onCloseClick = close, iconTint = ColorFilter.tint(ComposeAppTheme.colors.jacob) ) { - if (uiState.showRequestForm) { + if (uiState.vipSupportLink == null) { InfoText( text = stringResource(R.string.Settings_PersonalSupport_EnterTelegramAccountDescription), ) @@ -97,10 +98,7 @@ fun VipSupportBottomSheet( .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) - } + LinkHelper.openLinkInAppBrowser(context, uiState.vipSupportLink) }, ) VSpacer(16.dp) diff --git a/app/src/main/java/io/horizontalsystems/bankwallet/modules/settings/vipsupport/VipSupportViewModel.kt b/app/src/main/java/io/horizontalsystems/bankwallet/modules/settings/vipsupport/VipSupportViewModel.kt index 3199fa05a6..589fafdb1b 100644 --- a/app/src/main/java/io/horizontalsystems/bankwallet/modules/settings/vipsupport/VipSupportViewModel.kt +++ b/app/src/main/java/io/horizontalsystems/bankwallet/modules/settings/vipsupport/VipSupportViewModel.kt @@ -20,14 +20,14 @@ class VipSupportViewModel( private var showError = false private var showSpinner = false private var buttonEnabled = false - private var showRequestForm = !localStorage.vipSupportEnabled + private var telegramGroupLink: String? = localStorage.vipSupportLink override fun createState() = VipSupportModule.UiState( contactName = contactName, showError = showError, showSpinner = showSpinner, buttonEnabled = buttonEnabled, - showRequestForm = showRequestForm + vipSupportLink = telegramGroupLink ) fun onUsernameChange(username: String) { @@ -49,9 +49,16 @@ class VipSupportViewModel( viewModelScope.launch(Dispatchers.IO) { try { val request = marketKitWrapper.requestVipSupport(contactName).await() - if (request.code() != 200) throw Exception("Error") - localStorage.vipSupportEnabled = true - showRequestForm = false + val groupLink = request["group_link"] + if (groupLink == null) { + throw Exception("Error") + } else { + localStorage.vipSupportLink = groupLink + telegramGroupLink = groupLink + showSpinner = false + buttonEnabled = true + emitState() + } } catch (e: Throwable) { showSpinner = false buttonEnabled = true @@ -59,14 +66,12 @@ class VipSupportViewModel( emitState() return@launch } - showSpinner = false - buttonEnabled = true - emitState() } } fun showRequestForm() { - showRequestForm = true + telegramGroupLink = null + localStorage.vipSupportLink = null emitState() } @@ -85,6 +90,6 @@ object VipSupportModule { val showError: Boolean = false, val showSpinner: Boolean = false, val buttonEnabled: Boolean = false, - val showRequestForm: Boolean = false, + val vipSupportLink: String? = null, ) } \ No newline at end of file