From dc15761675844e82cd3b82d8a9f21f48dc08fe05 Mon Sep 17 00:00:00 2001 From: antonijzelinskij Date: Mon, 23 Dec 2024 11:41:31 +0100 Subject: [PATCH 1/2] Small fixes --- feature-assets/build.gradle | 4 +- .../novacard/overview/NovaCardFragment.kt | 34 +++-- .../novacard/overview/NovaCardViewModel.kt | 49 ++++--- .../novacard/overview/di/NovaCardModule.kt | 26 ++-- .../webViewController/NovaCardEventHandler.kt | 17 --- .../webViewController/NovaCardJsCallback.kt | 42 ------ .../NovaCardWebPageProvider.kt | 74 ---------- .../NovaCardWebViewController.kt | 68 ++++----- .../WebViewCardCreationInterceptor.kt | 133 ------------------ .../interceptors/CardCreationInterceptor.kt | 68 +++++++++ .../interceptors/NovaCardInterceptor.kt | 65 +++++++++ .../interceptors/TopUpRequestInterceptor.kt | 128 +++++++++++++++++ 12 files changed, 355 insertions(+), 353 deletions(-) delete mode 100644 feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/novacard/overview/webViewController/NovaCardEventHandler.kt delete mode 100644 feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/novacard/overview/webViewController/NovaCardJsCallback.kt delete mode 100644 feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/novacard/overview/webViewController/NovaCardWebPageProvider.kt delete mode 100644 feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/novacard/overview/webViewController/WebViewCardCreationInterceptor.kt create mode 100644 feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/novacard/overview/webViewController/interceptors/CardCreationInterceptor.kt create mode 100644 feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/novacard/overview/webViewController/interceptors/NovaCardInterceptor.kt create mode 100644 feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/novacard/overview/webViewController/interceptors/TopUpRequestInterceptor.kt diff --git a/feature-assets/build.gradle b/feature-assets/build.gradle index c37febf8b5..a3fbe2ed0c 100644 --- a/feature-assets/build.gradle +++ b/feature-assets/build.gradle @@ -14,15 +14,13 @@ android { testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" - buildConfigField "String", "NOVA_CARD_WIDGET_ID", "\"0a51d3d5-05ca-4b93-9593-ebb8911d0fb2\"" + buildConfigField "String", "NOVA_CARD_WIDGET_ID", "\"4ce98182-ed76-4933-ba1b-b85e4a51d75a\"" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' - - buildConfigField "String", "NOVA_CARD_WIDGET_ID", "\"4ce98182-ed76-4933-ba1b-b85e4a51d75a\"" } } diff --git a/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/novacard/overview/NovaCardFragment.kt b/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/novacard/overview/NovaCardFragment.kt index 8ef1ba0218..3b50117cc3 100644 --- a/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/novacard/overview/NovaCardFragment.kt +++ b/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/novacard/overview/NovaCardFragment.kt @@ -9,9 +9,11 @@ import io.novafoundation.nova.common.utils.applyStatusBarInsets import io.novafoundation.nova.feature_assets.R import io.novafoundation.nova.feature_assets.di.AssetsFeatureApi import io.novafoundation.nova.feature_assets.di.AssetsFeatureComponent -import io.novafoundation.nova.feature_assets.presentation.novacard.overview.webViewController.NovaCardEventHandler import io.novafoundation.nova.feature_assets.presentation.novacard.overview.webViewController.NovaCardWebViewControllerFactory -import io.novafoundation.nova.feature_assets.presentation.novacard.overview.webViewController.OnCardCreatedListener +import io.novafoundation.nova.feature_assets.presentation.novacard.overview.webViewController.interceptors.CardCreationInterceptor +import io.novafoundation.nova.feature_assets.presentation.novacard.overview.webViewController.interceptors.CardCreationInterceptorFactory +import io.novafoundation.nova.feature_assets.presentation.novacard.overview.webViewController.interceptors.TopUpRequestInterceptor +import io.novafoundation.nova.feature_assets.presentation.novacard.overview.webViewController.interceptors.TopUpRequestInterceptorFactory import kotlinx.android.synthetic.main.fragment_nova_card.novaCardContainer import kotlinx.android.synthetic.main.fragment_nova_card.novaCardWebView import kotlinx.coroutines.flow.first @@ -19,11 +21,17 @@ import kotlinx.coroutines.launch import java.math.BigDecimal import javax.inject.Inject -class NovaCardFragment : BaseFragment(), NovaCardEventHandler, OnCardCreatedListener { +class NovaCardFragment : BaseFragment(), CardCreationInterceptor.Callback, TopUpRequestInterceptor.Callback { @Inject lateinit var novaCardWebViewControllerFactory: NovaCardWebViewControllerFactory + @Inject + lateinit var cardCreationInterceptorFactory: CardCreationInterceptorFactory + + @Inject + lateinit var topUpRequestInterceptorFactory: TopUpRequestInterceptorFactory + override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, @@ -46,11 +54,15 @@ class NovaCardFragment : BaseFragment(), NovaCardEventHandler override fun subscribe(viewModel: NovaCardViewModel) { viewModel.launch { + val interceptors = listOf( + cardCreationInterceptorFactory.create(this@NovaCardFragment), + topUpRequestInterceptorFactory.create(this@NovaCardFragment) + ) + val novaCardWebViewController = novaCardWebViewControllerFactory.create( fragment = this@NovaCardFragment, webView = novaCardWebView, - eventHandler = this@NovaCardFragment, - cardCreatedListener = this@NovaCardFragment, + interceptors = interceptors, setupConfig = viewModel.setupCardConfig.first(), scope = viewModel ) @@ -59,15 +71,15 @@ class NovaCardFragment : BaseFragment(), NovaCardEventHandler } } - override fun transactionStatusChanged(event: NovaCardEventHandler.TransactionStatus) { - viewModel.onTransactionStatusChanged(event) + override fun onCardCreated() { + viewModel.onCardCreated() } - override fun openTopUp(amount: BigDecimal, address: String) { - viewModel.openTopUp(amount, address) + override fun onCardTopUpCompleted(orderId: String) { + viewModel.onTopUpFinished(orderId) } - override fun onCardCreated() { - viewModel.onCardCreated() + override fun onTopUpStart(orderId: String, amount: BigDecimal, address: String) { + viewModel.openTopUp(orderId, amount, address) } } diff --git a/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/novacard/overview/NovaCardViewModel.kt b/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/novacard/overview/NovaCardViewModel.kt index d2290d1313..bc83cb89c6 100644 --- a/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/novacard/overview/NovaCardViewModel.kt +++ b/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/novacard/overview/NovaCardViewModel.kt @@ -1,7 +1,5 @@ package io.novafoundation.nova.feature_assets.presentation.novacard.overview -import android.util.Log -import io.novafoundation.nova.common.BuildConfig import io.novafoundation.nova.common.base.BaseViewModel import io.novafoundation.nova.common.utils.flowOf import io.novafoundation.nova.feature_account_api.domain.interfaces.AccountInteractor @@ -10,11 +8,9 @@ import io.novafoundation.nova.feature_assets.domain.novaCard.NovaCardState import io.novafoundation.nova.feature_assets.domain.novaCard.NovaCardInteractor import io.novafoundation.nova.feature_assets.presentation.AssetsRouter import io.novafoundation.nova.feature_assets.presentation.novacard.overview.model.CardSetupConfig -import io.novafoundation.nova.feature_assets.presentation.novacard.overview.webViewController.NovaCardEventHandler import io.novafoundation.nova.feature_assets.presentation.novacard.topup.TopUpCardPayload import io.novafoundation.nova.feature_wallet_api.presentation.model.toAssetPayload import io.novafoundation.nova.runtime.ext.ChainGeneses -import io.novafoundation.nova.runtime.ext.ChainIds import io.novafoundation.nova.runtime.ext.utilityAsset import io.novafoundation.nova.runtime.multiNetwork.ChainRegistry import io.novafoundation.nova.runtime.multiNetwork.chain.model.Chain @@ -30,6 +26,8 @@ class NovaCardViewModel( private val novaCardInteractor: NovaCardInteractor ) : BaseViewModel() { + private val openedOrderIds = mutableSetOf() + private val metaAccount = flowOf { accountInteractor.selectedMetaAccount() } private val topUpChain = flowOf { getTopUpChain() } @@ -52,32 +50,37 @@ class NovaCardViewModel( } } - fun onTransactionStatusChanged(event: NovaCardEventHandler.TransactionStatus) { - Log.d("NovaCardView", "onTransactionStatusChanged: $event") - } + fun openTopUp(orderId: String, amount: BigDecimal, address: String) { + if (orderId in openedOrderIds) return // Not handle same order twice + openedOrderIds.add(orderId) - fun openTopUp(amount: BigDecimal, address: String) = launch { - val payload = TopUpCardPayload( - amount = amount, - address = address, - asset = setupCardConfig.first().spendToken.toAssetPayload() - ) + launch { + val payload = TopUpCardPayload( + amount = amount, + address = address, + asset = setupCardConfig.first().spendToken.toAssetPayload() + ) - assetsRouter.openTopUpCard(payload) + assetsRouter.openTopUpCard(payload) + } } - fun onCardCreated() { - // No need to open/close timer dialog if card is already created - if (novaCardInteractor.isNovaCardCreated()) return + fun onTopUpFinished(orderId: String) { + openedOrderIds.remove(orderId) + makeCardCreated() + } - novaCardInteractor.setNovaCardState(NovaCardState.CREATED) + fun onCardCreated() { + makeCardCreated() } private suspend fun getTopUpChain(): Chain { - return if (BuildConfig.DEBUG) { - chainRegistry.getChain(ChainIds.ETHEREUM_SEPOLIA) - } else { - chainRegistry.getChain(ChainGeneses.POLKADOT) - } + return chainRegistry.getChain(ChainGeneses.POLKADOT) + } + + private fun makeCardCreated() { + if (novaCardInteractor.isNovaCardCreated()) return + + novaCardInteractor.setNovaCardState(NovaCardState.CREATED) } } diff --git a/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/novacard/overview/di/NovaCardModule.kt b/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/novacard/overview/di/NovaCardModule.kt index 1f5ec74860..7b967f0abf 100644 --- a/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/novacard/overview/di/NovaCardModule.kt +++ b/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/novacard/overview/di/NovaCardModule.kt @@ -19,7 +19,8 @@ import io.novafoundation.nova.feature_assets.domain.novaCard.NovaCardInteractor import io.novafoundation.nova.feature_assets.presentation.AssetsRouter import io.novafoundation.nova.feature_assets.presentation.novacard.overview.NovaCardViewModel import io.novafoundation.nova.feature_assets.presentation.novacard.overview.webViewController.NovaCardWebViewControllerFactory -import io.novafoundation.nova.feature_assets.presentation.novacard.overview.webViewController.WebViewCardCreationInterceptorFactory +import io.novafoundation.nova.feature_assets.presentation.novacard.overview.webViewController.interceptors.CardCreationInterceptorFactory +import io.novafoundation.nova.feature_assets.presentation.novacard.overview.webViewController.interceptors.TopUpRequestInterceptorFactory import io.novafoundation.nova.runtime.multiNetwork.ChainRegistry import okhttp3.OkHttpClient @@ -27,10 +28,19 @@ import okhttp3.OkHttpClient class NovaCardModule { @Provides - fun provideWebViewCardCreationInterceptorFactory( + fun provideCardCreationInterceptorFactory( gson: Gson, okHttpClient: OkHttpClient - ): WebViewCardCreationInterceptorFactory = WebViewCardCreationInterceptorFactory( + ): CardCreationInterceptorFactory = CardCreationInterceptorFactory( + gson = gson, + okHttpClient = okHttpClient + ) + + @Provides + fun provideTopUpRequestInterceptorFactory( + gson: Gson, + okHttpClient: OkHttpClient + ): TopUpRequestInterceptorFactory = TopUpRequestInterceptorFactory( gson = gson, okHttpClient = okHttpClient ) @@ -38,20 +48,16 @@ class NovaCardModule { @Provides fun provideNovaCardWebViewControllerFactory( systemCallExecutor: SystemCallExecutor, - permissionsAskerFactory: PermissionsAskerFactory, - appLinksProvider: AppLinksProvider, fileProvider: FileProvider, - gson: Gson, - webViewCardCreationInterceptorFactory: WebViewCardCreationInterceptorFactory + permissionsAskerFactory: PermissionsAskerFactory, + appLinksProvider: AppLinksProvider ): NovaCardWebViewControllerFactory { return NovaCardWebViewControllerFactory( systemCallExecutor, fileProvider, permissionsAskerFactory, appLinksProvider, - gson, - BuildConfig.NOVA_CARD_WIDGET_ID, - webViewCardCreationInterceptorFactory + BuildConfig.NOVA_CARD_WIDGET_ID ) } diff --git a/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/novacard/overview/webViewController/NovaCardEventHandler.kt b/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/novacard/overview/webViewController/NovaCardEventHandler.kt deleted file mode 100644 index e6656f704d..0000000000 --- a/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/novacard/overview/webViewController/NovaCardEventHandler.kt +++ /dev/null @@ -1,17 +0,0 @@ -package io.novafoundation.nova.feature_assets.presentation.novacard.overview.webViewController - -import java.math.BigDecimal - -interface NovaCardEventHandler { - - fun transactionStatusChanged(event: TransactionStatus) - - fun openTopUp(amount: BigDecimal, address: String) - - enum class TransactionStatus { - NEW, - PENDING, - COMPLETED, - UNKNOWN - } -} diff --git a/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/novacard/overview/webViewController/NovaCardJsCallback.kt b/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/novacard/overview/webViewController/NovaCardJsCallback.kt deleted file mode 100644 index 10938587aa..0000000000 --- a/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/novacard/overview/webViewController/NovaCardJsCallback.kt +++ /dev/null @@ -1,42 +0,0 @@ -package io.novafoundation.nova.feature_assets.presentation.novacard.overview.webViewController - -import android.webkit.JavascriptInterface -import com.google.gson.Gson -import io.novafoundation.nova.common.utils.fromJson -import java.math.BigDecimal - -class NovaCardJsCallback( - private val gson: Gson, - private val eventHandler: NovaCardEventHandler -) { - @JavascriptInterface - fun onStatusChange(data: String) { - runCatching { - val event = gson.fromJson(data) - - val transactionStatus = when (event.status) { - "new" -> NovaCardEventHandler.TransactionStatus.NEW - "pending" -> NovaCardEventHandler.TransactionStatus.PENDING - "completed" -> NovaCardEventHandler.TransactionStatus.COMPLETED - else -> NovaCardEventHandler.TransactionStatus.UNKNOWN - } - - eventHandler.transactionStatusChanged(transactionStatus) - } - } - - @JavascriptInterface - fun onSellTransferEnabled(data: String) { - runCatching { - val event = gson.fromJson(data) - - eventHandler.openTopUp(event.amount, event.address) - } - } -} - -// { id:"0c8302ebd6a635181", status:"completed", amount:"6.5579913810", network:"POLKADOT", fiat_amount:"25.00", currency:"DOT", fiat_currency:"EUR" } -private class StatusChangedEvent(val status: String) - -// { amount:"0.01336", currency:"BTC", network:"BITCOIN", address:"04d3911f3b6de0843", id:"03b22d25d523a5285", flow_id:"payout" } -private class SellTransferEnabledEvent(val address: String, val amount: BigDecimal) diff --git a/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/novacard/overview/webViewController/NovaCardWebPageProvider.kt b/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/novacard/overview/webViewController/NovaCardWebPageProvider.kt deleted file mode 100644 index ba37ba9366..0000000000 --- a/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/novacard/overview/webViewController/NovaCardWebPageProvider.kt +++ /dev/null @@ -1,74 +0,0 @@ -package io.novafoundation.nova.feature_assets.presentation.novacard.overview.webViewController - -import io.novafoundation.nova.common.BuildConfig -import io.novafoundation.nova.feature_assets.presentation.novacard.overview.model.CardSetupConfig - -class NovaCardWebPageProvider( - private val widgetId: String, - private val setupConfig: CardSetupConfig -) { - - private val containerId = "widget-container" - private val scriptUrl = getScriptUrl() - private val callbackName: String = "NovaCallback" - - fun getCallbackName() = callbackName - - fun getPage(): String { - return """ - - - - - - - - - -
- - - - - """.trimIndent() - } - - fun getJsScript(): String { - return """ - mercuryoWidget.run({ - widgetId: '$widgetId', - host: document.getElementById('$containerId'), - type: 'sell', - currency: '${setupConfig.spendToken.symbol.value}', - fiatCurrency: 'EUR', - paymentMethod: 'fiat_card_open', - theme: 'nova', - width: '100%', - height: window.innerHeight, - hideRefundAddress: true, - refundAddress: '${setupConfig.refundAddress}', - fixPaymentMethod: true, - showSpendCardDetails: true, - onStatusChange: data => { - $callbackName.onStatusChange(JSON.stringify(data)); - }, - onSellTransferEnabled: data => { - $callbackName.onSellTransferEnabled(JSON.stringify(data)); - } - }); - """.trimIndent() - } - - private fun getScriptUrl(): String { - if (BuildConfig.DEBUG) { - return "https://sandbox-exchange.mrcr.io/embed.2.0.js" - } else { - return "https://widget.mercuryo.io/embed.2.0.js" - } - } -} diff --git a/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/novacard/overview/webViewController/NovaCardWebViewController.kt b/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/novacard/overview/webViewController/NovaCardWebViewController.kt index caec4fa56a..194de03e02 100644 --- a/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/novacard/overview/webViewController/NovaCardWebViewController.kt +++ b/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/novacard/overview/webViewController/NovaCardWebViewController.kt @@ -9,13 +9,15 @@ import android.webkit.WebResourceResponse import android.webkit.WebView import android.webkit.WebViewClient import androidx.fragment.app.Fragment -import com.google.gson.Gson import io.novafoundation.nova.common.data.network.AppLinksProvider import io.novafoundation.nova.common.interfaces.FileProvider import io.novafoundation.nova.common.utils.permissions.PermissionsAskerFactory +import io.novafoundation.nova.common.utils.sha512 import io.novafoundation.nova.common.utils.systemCall.FilePickerSystemCall import io.novafoundation.nova.common.utils.systemCall.SystemCallExecutor import io.novafoundation.nova.feature_assets.presentation.novacard.overview.model.CardSetupConfig +import io.novafoundation.nova.feature_assets.presentation.novacard.overview.webViewController.interceptors.NovaCardInterceptor +import io.novasama.substrate_sdk_android.extensions.toHexString import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.launch @@ -24,21 +26,16 @@ class NovaCardWebViewControllerFactory( private val fileProvider: FileProvider, private val permissionsAskerFactory: PermissionsAskerFactory, private val appLinksProvider: AppLinksProvider, - private val gson: Gson, - private val widgetId: String, - private val webViewCardCreationInterceptorFactory: WebViewCardCreationInterceptorFactory + private val widgetId: String ) { fun create( fragment: Fragment, webView: WebView, - eventHandler: NovaCardEventHandler, - cardCreatedListener: OnCardCreatedListener, + interceptors: List, setupConfig: CardSetupConfig, scope: CoroutineScope, ): NovaCardWebViewController { - val jsCallback = NovaCardJsCallback(gson, eventHandler) - val pageProvider = NovaCardWebPageProvider(widgetId = widgetId, setupConfig) return NovaCardWebViewController( fragment = fragment, webView = webView, @@ -46,10 +43,10 @@ class NovaCardWebViewControllerFactory( appLinksProvider = appLinksProvider, permissionsAskerFactory = permissionsAskerFactory, systemCallExecutor = systemCallExecutor, - pageProvider = pageProvider, - novaCardJsCallback = jsCallback, - coroutineScope = scope, - cardCreationInterceptor = webViewCardCreationInterceptorFactory.create(cardCreatedListener) + setupConfig = setupConfig, + widgetId = widgetId, + interceptors = interceptors, + coroutineScope = scope ) } } @@ -61,33 +58,18 @@ class NovaCardWebViewController( private val appLinksProvider: AppLinksProvider, private val permissionsAskerFactory: PermissionsAskerFactory, private val systemCallExecutor: SystemCallExecutor, - private val pageProvider: NovaCardWebPageProvider, - private val novaCardJsCallback: NovaCardJsCallback, - private val coroutineScope: CoroutineScope, - private val cardCreationInterceptor: WebViewCardCreationInterceptor + private val setupConfig: CardSetupConfig, + private val widgetId: String, + private val interceptors: List, + private val coroutineScope: CoroutineScope ) { private val permissionsAsker = permissionsAskerFactory.create(fragment) private val webViewClient = object : WebViewClient() { - private var jsScriptWasCalled = false - - init { - cardCreationInterceptor.runPolling(coroutineScope) - } - - override fun onPageFinished(view: WebView, url: String) { - super.onPageFinished(view, url) - - if (!jsScriptWasCalled) { - jsScriptWasCalled = true - webView.evaluateJavascript(pageProvider.getJsScript(), null) - } - } - override fun shouldInterceptRequest(view: WebView, request: WebResourceRequest): WebResourceResponse? { - cardCreationInterceptor.intercept(request) + interceptors.firstOrNull { it.intercept(request) } return super.shouldInterceptRequest(view, request) } @@ -126,18 +108,24 @@ class NovaCardWebViewController( webSettings.allowContentAccess = true webSettings.useWideViewPort = true webSettings.displayZoomControls = false - webView.addJavascriptInterface(novaCardJsCallback, pageProvider.getCallbackName()) webView.webViewClient = webViewClient webView.webChromeClient = webChromeClient - webView.loadDataWithBaseURL( - appLinksProvider.novaCardWidgetUrl, - pageProvider.getPage(), - "text/html", - "UTF-8", - null - ) + val uri = Uri.parse(appLinksProvider.novaCardWidgetUrl).buildUpon() + .appendQueryParameter("widget_id", widgetId) + .appendQueryParameter("type", "sell") + .appendQueryParameter("currency", setupConfig.spendToken.symbol.value) + .appendQueryParameter("payment_method", "fiat_card_open") + .appendQueryParameter("fiat_currency", "EUR") + .appendQueryParameter("theme", "nova") + .appendQueryParameter("hide_refund_address", "true") + .appendQueryParameter("refund_address", setupConfig.refundAddress) + .appendQueryParameter("fix_payment_method", "true") + .appendQueryParameter("show_spend_card_details", "true") + .build() + + webView.loadUrl(uri.toString()) } } diff --git a/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/novacard/overview/webViewController/WebViewCardCreationInterceptor.kt b/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/novacard/overview/webViewController/WebViewCardCreationInterceptor.kt deleted file mode 100644 index 35af4defa0..0000000000 --- a/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/novacard/overview/webViewController/WebViewCardCreationInterceptor.kt +++ /dev/null @@ -1,133 +0,0 @@ -package io.novafoundation.nova.feature_assets.presentation.novacard.overview.webViewController - -import android.webkit.CookieManager -import android.webkit.WebResourceRequest -import com.google.gson.Gson -import com.google.gson.annotations.SerializedName -import io.novafoundation.nova.common.utils.fromJson -import io.novafoundation.nova.common.utils.inBackground -import io.novafoundation.nova.common.utils.onEachLatest -import io.novafoundation.nova.common.utils.readText -import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.delay -import kotlinx.coroutines.flow.MutableStateFlow -import kotlinx.coroutines.flow.launchIn -import okhttp3.OkHttpClient -import okhttp3.Request -import kotlin.time.Duration.Companion.milliseconds - -interface OnCardCreatedListener { - - fun onCardCreated() -} - -class WebViewCardCreationInterceptorFactory( - private val okHttpClient: OkHttpClient, - private val gson: Gson -) { - fun create(onCardCreatedListener: OnCardCreatedListener): WebViewCardCreationInterceptor { - return WebViewCardCreationInterceptor(okHttpClient, gson, onCardCreatedListener) - } -} - -class WebViewCardCreationInterceptor( - private val okHttpClient: OkHttpClient, - private val gson: Gson, - private val onCardCreatedListener: OnCardCreatedListener -) { - - private var interceptedCardRequest = MutableStateFlow(null) - - fun runPolling(coroutineScope: CoroutineScope) { - interceptedCardRequest.onEachLatest { request -> - if (request == null) return@onEachLatest - - for (i in 0..100) { - val cardWasSuccessfullyCreated = checkForCardCreation(request) - - if (cardWasSuccessfullyCreated) { - break - } - - delay(1000.milliseconds) - } - }.inBackground() - .launchIn(coroutineScope) - } - - /** - * @return true if the request was intercepted otherwise false - */ - fun intercept(request: WebResourceRequest): Boolean { - val url = request.url.toString() - - if (url.contains("https://api.mercuryo.io/v1.6/cards")) { // Specify your condition here - performOkHttpRequest(request) - return true - } - - return false - } - - private fun performOkHttpRequest(request: WebResourceRequest) { - try { - val okHttpRequestBuilder = Request.Builder().url(request.url.toString()) - - okHttpRequestBuilder.get() - - for ((key, value) in request.requestHeaders) { - okHttpRequestBuilder.addHeader(key, value) - } - - val cookieManager = CookieManager.getInstance() - val cookies = cookieManager.getCookie(request.url.toString()) - if (cookies != null) { - okHttpRequestBuilder.addHeader("Cookie", cookies) - } - - interceptedCardRequest.value = okHttpRequestBuilder - - checkForCardCreation(okHttpRequestBuilder) - } catch (e: Exception) { - e.printStackTrace() - } - } - - private fun checkForCardCreation(requestBuilder: Request.Builder): Boolean { - val cardSuccessfullyCreated = makeRequest(requestBuilder) - - if (cardSuccessfullyCreated) { - onCardCreatedListener.onCardCreated() - } - - return cardSuccessfullyCreated - } - - /** - * Notify onCardCreatedListener if data value contains mercurio cards - */ - private fun makeRequest(requestBuilder: Request.Builder): Boolean { - val okHttpResponse = okHttpClient.newCall(requestBuilder.build()).execute() - - if (okHttpResponse.isSuccessful) { - val responseBody = okHttpResponse.body - - val data = responseBody!!.byteStream().readText() - val cardsResponse = gson.fromJson(data) - val cards = cardsResponse.data - val containsMercurioCard = cards.any { it.issuedByMercurio } - - return containsMercurioCard - } - - return false - } -} - -/** - * The full response is: {"status":200,"total":1,"next":null,"prev":null,"data":[{"id":"0c82dafa12d352193","created_at":"2024-08-23 10:12:10","payment_system":"Mastercard","card_number":"************7907","card_expiration_month":"08","card_expiration_year":"2029","bank":null,"issued_by_mercuryo":true,"fiat_card_id":"0c82dab8d9d316059","fiat_card_status":"active"}]} - */ -private class CardsResponse(val data: List) { - - class Card(@SerializedName("issued_by_mercuryo") val issuedByMercurio: Boolean) -} diff --git a/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/novacard/overview/webViewController/interceptors/CardCreationInterceptor.kt b/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/novacard/overview/webViewController/interceptors/CardCreationInterceptor.kt new file mode 100644 index 0000000000..483c9770a5 --- /dev/null +++ b/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/novacard/overview/webViewController/interceptors/CardCreationInterceptor.kt @@ -0,0 +1,68 @@ +package io.novafoundation.nova.feature_assets.presentation.novacard.overview.webViewController.interceptors + +import android.webkit.WebResourceRequest +import android.webkit.WebResourceResponse +import com.google.gson.Gson +import com.google.gson.annotations.SerializedName +import okhttp3.OkHttpClient + +class CardCreationInterceptorFactory( + private val okHttpClient: OkHttpClient, + private val gson: Gson +) { + fun create(callback: CardCreationInterceptor.Callback): CardCreationInterceptor { + return CardCreationInterceptor(okHttpClient, gson, callback) + } +} + +class CardCreationInterceptor( + private val okHttpClient: OkHttpClient, + private val gson: Gson, + private val onCardCreatedListener: Callback +) : NovaCardInterceptor { + + interface Callback { + + fun onCardCreated() + } + + /** + * @return true if the request was intercepted otherwise false + */ + override fun intercept(request: WebResourceRequest): Boolean { + val url = request.url.toString() + + if (url.contains("https://api.mercuryo.io/v1.6/cards")) { // Specify your condition here + return performOkHttpRequest(request) + } + + return false + } + + private fun performOkHttpRequest(request: WebResourceRequest): Boolean { + val requestBuilder = request.toOkHttpRequestBuilder() + + return try { + val response = makeRequest(okHttpClient, requestBuilder) + val cardsResponse = gson.fromJson(response.body!!.string(), CardsResponse::class.java) + + if (cardsResponse.isCardCreated()) { + onCardCreatedListener.onCardCreated() + } + + true + } catch (e: Exception) { + false + } + } +} + +/** + * The full response is: {"status":200,"total":1,"next":null,"prev":null,"data":[{"id":"0c82dafa12d352193","created_at":"2024-08-23 10:12:10","payment_system":"Mastercard","card_number":"************7907","card_expiration_month":"08","card_expiration_year":"2029","bank":null,"issued_by_mercuryo":true,"fiat_card_id":"0c82dab8d9d316059","fiat_card_status":"active"}]} + */ +private class CardsResponse(val data: List) { + + class Card(@SerializedName("issued_by_mercuryo") val issuedByMercurio: Boolean) +} + +private fun CardsResponse.isCardCreated() = data.any { it.issuedByMercurio } diff --git a/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/novacard/overview/webViewController/interceptors/NovaCardInterceptor.kt b/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/novacard/overview/webViewController/interceptors/NovaCardInterceptor.kt new file mode 100644 index 0000000000..71708a1a46 --- /dev/null +++ b/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/novacard/overview/webViewController/interceptors/NovaCardInterceptor.kt @@ -0,0 +1,65 @@ +package io.novafoundation.nova.feature_assets.presentation.novacard.overview.webViewController.interceptors + +import android.webkit.CookieManager +import android.webkit.WebResourceRequest +import android.webkit.WebResourceResponse +import okhttp3.OkHttpClient +import okhttp3.Request +import okhttp3.Response + +interface NovaCardInterceptor { + + /** + * @return Make a request and return WebResourceResponse if the request was intercepted otherwise null + */ + fun intercept(request: WebResourceRequest): Boolean + +} + +fun makeRequest(okHttpClient: OkHttpClient, requestBuilder: Request.Builder): Response { + val okHttpResponse = okHttpClient.newCall(requestBuilder.build()).execute() + + if (okHttpResponse.isSuccessful) { + return okHttpResponse + } + + throw RuntimeException("Request failed with ${okHttpResponse.code} code: ${okHttpResponse.networkResponse?.body}") +} + +/** + * Pass body here since response inout stream may be already closed + */ +fun Response.toWebResourceResponse(): WebResourceResponse { + val contentType = this.header("Content-Type", null) + val charset = this.header("Content-Encoding", null) + val headers = this.headers.toMap() + val statusMessage = if (this.isSuccessful) "OK" else "Error" + + return WebResourceResponse( + contentType, + charset, + this.code, + statusMessage, + headers, + body?.byteStream() + ) +} + +fun WebResourceRequest.toOkHttpRequestBuilder(): Request.Builder { + val url = url.toString() + val okHttpRequestBuilder = Request.Builder().url(url) + + okHttpRequestBuilder.get() + + for ((key, value) in requestHeaders) { + okHttpRequestBuilder.addHeader(key, value) + } + + val cookieManager = CookieManager.getInstance() + val cookies = cookieManager.getCookie(url) + if (cookies != null) { + okHttpRequestBuilder.addHeader("Cookie", cookies) + } + + return okHttpRequestBuilder +} diff --git a/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/novacard/overview/webViewController/interceptors/TopUpRequestInterceptor.kt b/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/novacard/overview/webViewController/interceptors/TopUpRequestInterceptor.kt new file mode 100644 index 0000000000..d305f6cfbb --- /dev/null +++ b/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/novacard/overview/webViewController/interceptors/TopUpRequestInterceptor.kt @@ -0,0 +1,128 @@ +package io.novafoundation.nova.feature_assets.presentation.novacard.overview.webViewController.interceptors + +import android.webkit.WebResourceRequest +import com.google.gson.Gson +import java.math.BigDecimal +import okhttp3.OkHttpClient + +class TopUpRequestInterceptorFactory( + private val okHttpClient: OkHttpClient, + private val gson: Gson +) { + fun create(callback: TopUpRequestInterceptor.Callback): TopUpRequestInterceptor { + return TopUpRequestInterceptor(okHttpClient, gson, callback) + } +} + +class TopUpRequestInterceptor( + private val okHttpClient: OkHttpClient, + private val gson: Gson, + private val onCardCreatedListener: Callback +) : NovaCardInterceptor { + + interface Callback { + + fun onCardTopUpCompleted(orderId: String) + + fun onTopUpStart(orderId: String, amount: BigDecimal, address: String) + } + + override fun intercept(request: WebResourceRequest): Boolean { + val url = request.url.toString() + + val pattern = Regex("https://api\\.mercuryo\\.io/[a-zA-Z0-9.]+/widget/sell-request/([a-zA-Z0-9]+)/status.*") + + val matches = pattern.find(url) + + if (matches != null) { + val orderId = matches.groupValues[1] + return performOkHttpRequest(orderId, request) + } + + return false + } + + private fun performOkHttpRequest(orderId: String, request: WebResourceRequest): Boolean { + val requestBuilder = request.toOkHttpRequestBuilder() + + return try { + val response = makeRequest(okHttpClient, requestBuilder) + val topUpResponse = gson.fromJson(response.body!!.string(), TopUpResponse::class.java) + + when { + topUpResponse.isNew() -> onCardCreatedListener.onTopUpStart(orderId, topUpResponse.getAmount(), topUpResponse.getAddress()) + + topUpResponse.isCompleted() -> onCardCreatedListener.onCardTopUpCompleted(orderId) + } + + true + } catch (e: Exception) { + false + } + } +} + +/** + * { + * "status": 200, + * "data": { + * "status": "completed", // Status may be new, pending, completed + * "is_partially_paid": 0, + * "amounts": { + * "request": { + * "amount": "3.55", + * "currency": "DOT", + * "fiat_amount": "25.00", + * "fiat_currency": "EUR" + * }, + * "deposit": { + * "amount": "3.5544722879", + * "currency": "DOT", + * "fiat_amount": "28.00", + * "fiat_currency": "EUR" + * }, + * "payout": { + * "amount": "3.5544722879", + * "currency": "DOT", + * "fiat_amount": "24.98", + * "fiat_currency": "EUR" + * } + * }, + * "next": null, + * "deposit_transaction": { + * "id": "1gb8dnc28jds8ch", + * "address": "15AsDPtQ6rZdJgsLsEmQCahym5STRVBVaUYjWFiRRinMjYYaw", + * "url": "https://polkadot.subscan.io/extrinsic/0x178f96e1f8837a3dd75ff8b5a5d4422c5c0f7848fbf5c00e343f03b9466e408b" + * }, + * "address": "15AsDPtQ6rZdJgsLsEmQCahym5STRVBVaUYjWFiRRinMjYYaw", + * "fiat_card_id": "1gb8dnc28jds8ch" + * } + * } + */ +private class TopUpResponse(val data: Data) { + + class Data( + val status: String, + val amounts: Amounts, + val address: String + ) + + class Amounts(val request: Request) { + + class Request( + val amount: String, + ) + } +} + +private fun TopUpResponse.getAmount(): BigDecimal { + return data.amounts.request.amount.toBigDecimal() +} + +private fun TopUpResponse.getAddress(): String { + return data.address +} + +private fun TopUpResponse.isNew() = data.status == "new" + +private fun TopUpResponse.isCompleted() = data.status == "completed" From c4cf59600fdf4137ea73788027b867f137a8c05f Mon Sep 17 00:00:00 2001 From: antonijzelinskij Date: Tue, 24 Dec 2024 09:52:57 +0100 Subject: [PATCH 2/2] Implemented sell request checking --- .../novafoundation/nova/app/root/navigation/Navigator.kt | 4 ++++ app/src/main/res/navigation/nova_card_graph.xml | 9 +++++++++ .../nova/feature_assets/di/AssetsFeatureModule.kt | 1 - .../nova/feature_assets/presentation/AssetsRouter.kt | 2 ++ .../presentation/balance/list/BalanceListViewModel.kt | 1 - .../presentation/novacard/overview/NovaCardFragment.kt | 4 ++-- .../presentation/novacard/overview/NovaCardViewModel.kt | 2 +- .../webViewController/NovaCardWebViewController.kt | 2 -- .../interceptors/CardCreationInterceptor.kt | 1 - .../interceptors/NovaCardInterceptor.kt | 1 - .../interceptors/TopUpRequestInterceptor.kt | 4 ++-- .../presentation/novacard/topup/TopUpCardFragment.kt | 6 ++---- .../presentation/novacard/topup/TopUpCardViewModel.kt | 4 +--- .../presentation/novacard/topup/di/TopUpCardModule.kt | 1 - .../src/main/res/layout/fragment_top_up_card.xml | 1 - 15 files changed, 23 insertions(+), 20 deletions(-) diff --git a/app/src/main/java/io/novafoundation/nova/app/root/navigation/Navigator.kt b/app/src/main/java/io/novafoundation/nova/app/root/navigation/Navigator.kt index 45ca028ed6..39d5dbd027 100644 --- a/app/src/main/java/io/novafoundation/nova/app/root/navigation/Navigator.kt +++ b/app/src/main/java/io/novafoundation/nova/app/root/navigation/Navigator.kt @@ -434,6 +434,10 @@ class Navigator( navController?.navigate(R.id.action_open_topUpCard, TopUpCardFragment.getBundle(payload)) } + override fun closeTopUp() { + navController?.navigate(R.id.action_close_top_up_with_browser) + } + override fun finishSelectAndOpenSwapSetupAmount(swapSettingsPayload: SwapSettingsPayload) { navController?.navigate(R.id.action_finish_and_open_swap_settings, SwapMainSettingsFragment.getBundle(swapSettingsPayload)) } diff --git a/app/src/main/res/navigation/nova_card_graph.xml b/app/src/main/res/navigation/nova_card_graph.xml index d961f55d4d..4faeb1c2e9 100644 --- a/app/src/main/res/navigation/nova_card_graph.xml +++ b/app/src/main/res/navigation/nova_card_graph.xml @@ -36,6 +36,15 @@ app:useAdd="true" tools:layout="@layout/fragment_top_up_card"> + + (), CardCreationIntercep viewModel.onCardCreated() } - override fun onCardTopUpCompleted(orderId: String) { - viewModel.onTopUpFinished(orderId) + override fun onTopUpCompleted(orderId: String) { + viewModel.onTopUpCompleted(orderId) } override fun onTopUpStart(orderId: String, amount: BigDecimal, address: String) { diff --git a/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/novacard/overview/NovaCardViewModel.kt b/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/novacard/overview/NovaCardViewModel.kt index bc83cb89c6..6f483f5aab 100644 --- a/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/novacard/overview/NovaCardViewModel.kt +++ b/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/novacard/overview/NovaCardViewModel.kt @@ -65,7 +65,7 @@ class NovaCardViewModel( } } - fun onTopUpFinished(orderId: String) { + fun onTopUpCompleted(orderId: String) { openedOrderIds.remove(orderId) makeCardCreated() } diff --git a/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/novacard/overview/webViewController/NovaCardWebViewController.kt b/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/novacard/overview/webViewController/NovaCardWebViewController.kt index 194de03e02..7f8206f201 100644 --- a/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/novacard/overview/webViewController/NovaCardWebViewController.kt +++ b/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/novacard/overview/webViewController/NovaCardWebViewController.kt @@ -12,12 +12,10 @@ import androidx.fragment.app.Fragment import io.novafoundation.nova.common.data.network.AppLinksProvider import io.novafoundation.nova.common.interfaces.FileProvider import io.novafoundation.nova.common.utils.permissions.PermissionsAskerFactory -import io.novafoundation.nova.common.utils.sha512 import io.novafoundation.nova.common.utils.systemCall.FilePickerSystemCall import io.novafoundation.nova.common.utils.systemCall.SystemCallExecutor import io.novafoundation.nova.feature_assets.presentation.novacard.overview.model.CardSetupConfig import io.novafoundation.nova.feature_assets.presentation.novacard.overview.webViewController.interceptors.NovaCardInterceptor -import io.novasama.substrate_sdk_android.extensions.toHexString import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.launch diff --git a/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/novacard/overview/webViewController/interceptors/CardCreationInterceptor.kt b/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/novacard/overview/webViewController/interceptors/CardCreationInterceptor.kt index 483c9770a5..94385fe8ef 100644 --- a/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/novacard/overview/webViewController/interceptors/CardCreationInterceptor.kt +++ b/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/novacard/overview/webViewController/interceptors/CardCreationInterceptor.kt @@ -1,7 +1,6 @@ package io.novafoundation.nova.feature_assets.presentation.novacard.overview.webViewController.interceptors import android.webkit.WebResourceRequest -import android.webkit.WebResourceResponse import com.google.gson.Gson import com.google.gson.annotations.SerializedName import okhttp3.OkHttpClient diff --git a/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/novacard/overview/webViewController/interceptors/NovaCardInterceptor.kt b/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/novacard/overview/webViewController/interceptors/NovaCardInterceptor.kt index 71708a1a46..fe7516b163 100644 --- a/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/novacard/overview/webViewController/interceptors/NovaCardInterceptor.kt +++ b/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/novacard/overview/webViewController/interceptors/NovaCardInterceptor.kt @@ -13,7 +13,6 @@ interface NovaCardInterceptor { * @return Make a request and return WebResourceResponse if the request was intercepted otherwise null */ fun intercept(request: WebResourceRequest): Boolean - } fun makeRequest(okHttpClient: OkHttpClient, requestBuilder: Request.Builder): Response { diff --git a/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/novacard/overview/webViewController/interceptors/TopUpRequestInterceptor.kt b/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/novacard/overview/webViewController/interceptors/TopUpRequestInterceptor.kt index d305f6cfbb..53362eb748 100644 --- a/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/novacard/overview/webViewController/interceptors/TopUpRequestInterceptor.kt +++ b/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/novacard/overview/webViewController/interceptors/TopUpRequestInterceptor.kt @@ -22,7 +22,7 @@ class TopUpRequestInterceptor( interface Callback { - fun onCardTopUpCompleted(orderId: String) + fun onTopUpCompleted(orderId: String) fun onTopUpStart(orderId: String, amount: BigDecimal, address: String) } @@ -52,7 +52,7 @@ class TopUpRequestInterceptor( when { topUpResponse.isNew() -> onCardCreatedListener.onTopUpStart(orderId, topUpResponse.getAmount(), topUpResponse.getAddress()) - topUpResponse.isCompleted() -> onCardCreatedListener.onCardTopUpCompleted(orderId) + topUpResponse.isCompleted() -> onCardCreatedListener.onTopUpCompleted(orderId) } true diff --git a/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/novacard/topup/TopUpCardFragment.kt b/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/novacard/topup/TopUpCardFragment.kt index b6ebd25c84..a0e82f6f20 100644 --- a/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/novacard/topup/TopUpCardFragment.kt +++ b/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/novacard/topup/TopUpCardFragment.kt @@ -12,12 +12,8 @@ import io.novafoundation.nova.feature_account_api.presenatation.mixin.addressInp import io.novafoundation.nova.feature_assets.R import io.novafoundation.nova.feature_assets.di.AssetsFeatureApi import io.novafoundation.nova.feature_assets.di.AssetsFeatureComponent -import io.novafoundation.nova.feature_assets.presentation.send.common.fee.setupFeeLoading import io.novafoundation.nova.feature_wallet_api.presentation.mixin.amountChooser.setupAmountChooser -import io.novafoundation.nova.feature_wallet_api.presentation.mixin.fee.setupFeeLoading import io.novafoundation.nova.feature_wallet_api.presentation.mixin.fee.v2.setupFeeLoading -import kotlinx.android.synthetic.main.fragment_select_send.selectSendCrossChainFee -import kotlinx.android.synthetic.main.fragment_select_send.selectSendOriginFee import kotlinx.android.synthetic.main.fragment_top_up_card.topUpCardAmount import kotlinx.android.synthetic.main.fragment_top_up_card.topUpCardContainer import kotlinx.android.synthetic.main.fragment_top_up_card.topUpCardContinue @@ -48,6 +44,8 @@ class TopUpCardFragment : BaseFragment() { topUpCardContinue.prepareForProgress(viewLifecycleOwner) topUpCardContinue.setOnClickListener { viewModel.nextClicked() } + + onBackPressed { viewModel.backClicked() } } override fun inject() { diff --git a/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/novacard/topup/TopUpCardViewModel.kt b/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/novacard/topup/TopUpCardViewModel.kt index 7ad6107dd9..deebb3c91d 100644 --- a/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/novacard/topup/TopUpCardViewModel.kt +++ b/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/novacard/topup/TopUpCardViewModel.kt @@ -21,8 +21,6 @@ import io.novafoundation.nova.feature_assets.domain.send.SendInteractor import io.novafoundation.nova.feature_assets.presentation.AssetsRouter import io.novafoundation.nova.feature_assets.presentation.send.autoFixSendValidationPayload import io.novafoundation.nova.feature_assets.presentation.send.common.buildAssetTransfer -import io.novafoundation.nova.feature_assets.presentation.send.common.fee.TransferFeeDisplayFormatter -import io.novafoundation.nova.feature_assets.presentation.send.common.fee.createForTransfer import io.novafoundation.nova.feature_assets.presentation.send.mapAssetTransferValidationFailureToUI import io.novafoundation.nova.feature_wallet_api.data.network.blockhain.assets.tranfers.AssetTransfer import io.novafoundation.nova.feature_wallet_api.data.network.blockhain.assets.tranfers.AssetTransferPayload @@ -147,7 +145,7 @@ class TopUpCardViewModel( } fun backClicked() { - router.back() + router.closeTopUp() } private fun transferTokensAndFinishFlow(payload: AssetTransferPayload) = launch { diff --git a/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/novacard/topup/di/TopUpCardModule.kt b/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/novacard/topup/di/TopUpCardModule.kt index 5eb50f22b7..75c183e6f0 100644 --- a/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/novacard/topup/di/TopUpCardModule.kt +++ b/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/novacard/topup/di/TopUpCardModule.kt @@ -19,7 +19,6 @@ import io.novafoundation.nova.feature_assets.presentation.AssetsRouter import io.novafoundation.nova.feature_assets.presentation.novacard.topup.TopUpCardPayload import io.novafoundation.nova.feature_assets.presentation.novacard.topup.TopUpCardViewModel import io.novafoundation.nova.feature_wallet_api.presentation.mixin.amountChooser.AmountChooserMixin -import io.novafoundation.nova.feature_wallet_api.presentation.mixin.fee.FeeLoaderMixin import io.novafoundation.nova.feature_wallet_api.presentation.mixin.fee.v2.FeeLoaderMixinV2 import io.novafoundation.nova.runtime.multiNetwork.ChainRegistry diff --git a/feature-assets/src/main/res/layout/fragment_top_up_card.xml b/feature-assets/src/main/res/layout/fragment_top_up_card.xml index 43dbc78365..b5e41e1ec4 100644 --- a/feature-assets/src/main/res/layout/fragment_top_up_card.xml +++ b/feature-assets/src/main/res/layout/fragment_top_up_card.xml @@ -22,7 +22,6 @@ android:layout_height="wrap_content" android:layout_marginHorizontal="16dp" android:layout_marginTop="16dp" - android:layout_marginEnd="10dp" android:includeFontPadding="false" android:textColor="@color/text_primary" tools:text="@string/fragment_top_up_card_title" />