Updated on 2026-08-14
This commit is contained in:
commit
12f55bb18b
10 changed files with 20 additions and 122 deletions
|
|
@ -11,7 +11,6 @@ import com.tangem.tap.features.disclaimer.ui.DisclaimerFragment
|
|||
import com.tangem.tap.features.home.HomeFragment
|
||||
import com.tangem.tap.features.send.ui.SendFragment
|
||||
import com.tangem.tap.features.wallet.ui.WalletFragment
|
||||
import com.tangem.tap.features.wallet.ui.topup.TopUpFragment
|
||||
import com.tangem.wallet.R
|
||||
|
||||
fun FragmentActivity.openFragment(screen: AppScreen, addToBackStack: Boolean = true) {
|
||||
|
|
@ -40,7 +39,6 @@ private fun fragmentFactory(screen: AppScreen): Fragment {
|
|||
return when (screen) {
|
||||
AppScreen.Home -> HomeFragment()
|
||||
AppScreen.Wallet -> WalletFragment()
|
||||
AppScreen.TopUp -> TopUpFragment()
|
||||
AppScreen.Send -> SendFragment()
|
||||
AppScreen.Details -> DetailsFragment()
|
||||
AppScreen.DetailsConfirm -> DetailsConfirmFragment()
|
||||
|
|
|
|||
|
|
@ -9,4 +9,4 @@ data class NavigationState(
|
|||
val activity: WeakReference<FragmentActivity>? = null
|
||||
) : StateType
|
||||
|
||||
enum class AppScreen { Home, Wallet, TopUp, Send, Details, DetailsConfirm, DetailsSecurity, Disclaimer }
|
||||
enum class AppScreen { Home, Wallet, Send, Details, DetailsConfirm, DetailsSecurity, Disclaimer }
|
||||
|
|
@ -10,20 +10,20 @@ import javax.crypto.spec.SecretKeySpec
|
|||
class TopUpHelper {
|
||||
|
||||
companion object {
|
||||
const val REDIRECT_URL = "https://success.tangem.com"
|
||||
// const val REDIRECT_URL = "https://success.tangem.com"
|
||||
|
||||
private const val BASE_URL = "https://buy.moonpay.io"
|
||||
private const val API_KEY_PATH = "?apiKey="
|
||||
private const val CURRENCY_PATH = "¤cyCode="
|
||||
private const val WALLET_ADDRESS_PATH = "&walletAddress="
|
||||
private const val REDIRECT_URL_PATH = "&redirectUrl="
|
||||
// private const val REDIRECT_URL_PATH = "&redirectUrl="
|
||||
private const val SIGNATURE_PATH = "&signature="
|
||||
|
||||
fun getUrl(cryptoCurrencyName: CryptoCurrencyName, walletAddress: String): String {
|
||||
val originalQuery = API_KEY_PATH + TapConfig.moonPayApiKey.urlEncode() +
|
||||
CURRENCY_PATH + cryptoCurrencyName.urlEncode() +
|
||||
WALLET_ADDRESS_PATH + walletAddress.urlEncode() +
|
||||
REDIRECT_URL_PATH + REDIRECT_URL.urlEncode()
|
||||
WALLET_ADDRESS_PATH + walletAddress.urlEncode()
|
||||
// REDIRECT_URL_PATH + REDIRECT_URL.urlEncode()
|
||||
val signature = createSignature(originalQuery, TapConfig.moonPayApiSecretKey)
|
||||
|
||||
return BASE_URL + originalQuery + SIGNATURE_PATH + signature.urlEncode()
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@ import com.tangem.tap.domain.extensions.minimalAmount
|
|||
import com.tangem.tap.features.send.redux.*
|
||||
import com.tangem.tap.features.send.redux.FeeAction.RequestFee
|
||||
import com.tangem.tap.features.send.redux.states.SendButtonState
|
||||
import com.tangem.tap.features.wallet.redux.WalletAction
|
||||
import com.tangem.tap.scope
|
||||
import com.tangem.tap.tangemSdk
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
|
|
@ -99,7 +98,6 @@ private fun sendTransaction(
|
|||
FirebaseAnalyticsHandler.triggerEvent(AnalyticsEvent.TRANSACTION_IS_SENT, card)
|
||||
dispatch(SendAction.SendSuccess)
|
||||
dispatch(GlobalAction.UpdateWalletSignedHashes(result.data.walletSignedHashes))
|
||||
dispatch(WalletAction.UpdateWallet)
|
||||
dispatch(NavigationAction.PopBackTo())
|
||||
}
|
||||
is Result.Failure -> {
|
||||
|
|
|
|||
|
|
@ -89,8 +89,6 @@ sealed class WalletAction : Action {
|
|||
object EmptyWallet : WalletAction()
|
||||
|
||||
sealed class TopUpAction : WalletAction() {
|
||||
data class TopUp(val context: Context, val toolbarColor: Int?) : TopUpAction()
|
||||
data class Start(val url: String, val redirectUrl: String) : TopUpAction()
|
||||
data class Finish(val topUpCompleted: Boolean) : TopUpAction()
|
||||
data class TopUp(val context: Context, val toolbarColor: Int) : TopUpAction()
|
||||
}
|
||||
}
|
||||
|
|
@ -2,6 +2,7 @@ package com.tangem.tap.features.wallet.redux
|
|||
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import androidx.browser.customtabs.CustomTabsIntent
|
||||
import androidx.core.content.ContextCompat
|
||||
import com.tangem.blockchain.common.*
|
||||
import com.tangem.blockchain.extensions.SimpleResult
|
||||
|
|
@ -34,7 +35,6 @@ import kotlinx.coroutines.launch
|
|||
import kotlinx.coroutines.withContext
|
||||
import org.rekotlin.Action
|
||||
import org.rekotlin.Middleware
|
||||
import timber.log.Timber
|
||||
|
||||
class WalletMiddleware {
|
||||
private val topUpMiddleware = TopUpMiddleware()
|
||||
|
|
@ -73,7 +73,9 @@ class WalletMiddleware {
|
|||
}
|
||||
}
|
||||
is WalletAction.UpdateWallet -> {
|
||||
scope.launch { store.state.globalState.tapWalletManager.updateWallet() }
|
||||
if (store.state.walletState.state == ProgressState.Done) {
|
||||
scope.launch { store.state.globalState.tapWalletManager.updateWallet() }
|
||||
}
|
||||
}
|
||||
is WalletAction.UpdateWallet.Success -> setupWalletUpdate(action.wallet)
|
||||
is WalletAction.LoadWallet.Success -> {
|
||||
|
|
@ -257,16 +259,10 @@ private class TopUpMiddleware {
|
|||
store.state.walletState.currencyData.currencySymbol!!,
|
||||
store.state.walletState.addressData!!.address
|
||||
)
|
||||
Timber.d(url)
|
||||
store.dispatch(WalletAction.TopUpAction.Start(url, TopUpHelper.REDIRECT_URL))
|
||||
store.dispatch(NavigationAction.NavigateTo(AppScreen.TopUp))
|
||||
}
|
||||
is WalletAction.TopUpAction.Start -> {
|
||||
|
||||
}
|
||||
is WalletAction.TopUpAction.Finish -> {
|
||||
if (action.topUpCompleted) store.dispatch(WalletAction.UpdateWallet)
|
||||
store.dispatch(NavigationAction.PopBackTo())
|
||||
val customTabsIntent = CustomTabsIntent.Builder()
|
||||
.setToolbarColor(action.toolbarColor)
|
||||
.build()
|
||||
customTabsIntent.launchUrl(action.context, Uri.parse(url));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -116,7 +116,11 @@ private fun internalReduce(action: Action, state: AppState): WalletState {
|
|||
),
|
||||
topUpState = TopUpState(false)
|
||||
)
|
||||
is WalletAction.UpdateWallet -> newState = newState.copy(updatingWallet = true)
|
||||
is WalletAction.UpdateWallet -> {
|
||||
if (store.state.walletState.state == ProgressState.Done) {
|
||||
newState = newState.copy(updatingWallet = true)
|
||||
}
|
||||
}
|
||||
is WalletAction.UpdateWallet.ScheduleUpdatingWallet ->
|
||||
newState = newState.copy(updatingWallet = true)
|
||||
is WalletAction.UpdateWallet.Success -> {
|
||||
|
|
@ -219,9 +223,6 @@ private fun internalReduce(action: Action, state: AppState): WalletState {
|
|||
private fun handleTopUpActions(action: WalletAction.TopUpAction, state: TopUpState): TopUpState {
|
||||
return when (action) {
|
||||
is WalletAction.TopUpAction.TopUp -> state
|
||||
is WalletAction.TopUpAction.Start ->
|
||||
state.copy(url = action.url, redirectUrl = action.redirectUrl)
|
||||
is WalletAction.TopUpAction.Finish -> state.copy(url = null)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -61,6 +61,7 @@ class WalletFragment : Fragment(R.layout.fragment_wallet), StoreSubscriber<Walle
|
|||
oldState.walletState == newState.walletState
|
||||
}.select { it.walletState }
|
||||
}
|
||||
store.dispatch(WalletAction.UpdateWallet)
|
||||
}
|
||||
|
||||
override fun onStop() {
|
||||
|
|
|
|||
|
|
@ -1,63 +0,0 @@
|
|||
package com.tangem.tap.features.wallet.ui.topup
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import androidx.activity.OnBackPressedCallback
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.transition.TransitionInflater
|
||||
import com.tangem.tap.common.redux.navigation.NavigationAction
|
||||
import com.tangem.tap.features.wallet.redux.WalletState
|
||||
import com.tangem.tap.store
|
||||
import com.tangem.wallet.R
|
||||
import kotlinx.android.synthetic.main.fragment_topup.*
|
||||
import org.rekotlin.StoreSubscriber
|
||||
|
||||
|
||||
class TopUpFragment : Fragment(R.layout.fragment_topup), StoreSubscriber<WalletState> {
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
activity?.onBackPressedDispatcher?.addCallback(this, object : OnBackPressedCallback(true) {
|
||||
override fun handleOnBackPressed() {
|
||||
store.dispatch(NavigationAction.PopBackTo())
|
||||
}
|
||||
})
|
||||
val inflater = TransitionInflater.from(requireContext())
|
||||
enterTransition = inflater.inflateTransition(R.transition.slide_right)
|
||||
exitTransition = inflater.inflateTransition(R.transition.fade)
|
||||
}
|
||||
|
||||
override fun onStart() {
|
||||
super.onStart()
|
||||
store.subscribe(this) { state ->
|
||||
state.skipRepeats { oldState, newState ->
|
||||
oldState.walletState == newState.walletState
|
||||
}.select { it.walletState }
|
||||
}
|
||||
}
|
||||
|
||||
override fun onStop() {
|
||||
super.onStop()
|
||||
store.unsubscribe(this)
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
web_view.settings.javaScriptEnabled = true
|
||||
|
||||
toolbar.setNavigationOnClickListener {
|
||||
store.dispatch(NavigationAction.PopBackTo())
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
override fun newState(state: WalletState) {
|
||||
if (activity == null) return
|
||||
|
||||
if (state.topUpState.url != null) {
|
||||
web_view.webViewClient = TopUpWebViewClient(progress_bar, state.topUpState.redirectUrl)
|
||||
web_view.loadUrl(state.topUpState.url)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,31 +0,0 @@
|
|||
package com.tangem.tap.features.wallet.ui.topup
|
||||
|
||||
import android.webkit.WebView
|
||||
import android.webkit.WebViewClient
|
||||
import android.widget.ProgressBar
|
||||
import com.tangem.tap.common.extensions.hide
|
||||
import com.tangem.tap.common.extensions.show
|
||||
import com.tangem.tap.features.wallet.redux.WalletAction
|
||||
import com.tangem.tap.store
|
||||
|
||||
class TopUpWebViewClient(
|
||||
private val progressBar: ProgressBar, private val redirectUrl: String?
|
||||
) : WebViewClient() {
|
||||
override fun shouldOverrideUrlLoading(view: WebView, url: String): Boolean {
|
||||
if (redirectUrl != null && url.contains(redirectUrl)) {
|
||||
store.dispatch(WalletAction.TopUpAction.Finish(true))
|
||||
return true
|
||||
}
|
||||
view.loadUrl(url)
|
||||
return true
|
||||
}
|
||||
|
||||
override fun onPageFinished(view: WebView, url: String) {
|
||||
super.onPageFinished(view, url)
|
||||
progressBar.hide()
|
||||
}
|
||||
|
||||
init {
|
||||
progressBar.show()
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue