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

Cards redirect api 2 #1743

Open
wants to merge 2 commits into
base: base-nova-card
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down
9 changes: 9 additions & 0 deletions app/src/main/res/navigation/nova_card_graph.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@
app:useAdd="true"
tools:layout="@layout/fragment_top_up_card">

<action
android:id="@+id/action_close_top_up_with_browser"
app:enterAnim="@anim/fragment_open_enter"
app:exitAnim="@anim/fragment_open_exit"
app:popEnterAnim="@anim/fragment_close_enter"
app:popExitAnim="@anim/fragment_close_exit"
app:popUpTo="@id/novaCardFragment"
app:popUpToInclusive="true" />

<action
android:id="@+id/action_finish_top_up_flow"
app:destination="@id/waitingForTopUpCardFragment"
Expand Down
4 changes: 1 addition & 3 deletions feature-assets/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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\""
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import io.novafoundation.nova.feature_assets.domain.WalletInteractor
import io.novafoundation.nova.feature_assets.domain.WalletInteractorImpl
import io.novafoundation.nova.feature_assets.domain.assets.ExternalBalancesInteractor
import io.novafoundation.nova.feature_assets.domain.assets.RealExternalBalancesInteractor
import io.novafoundation.nova.feature_assets.domain.assets.search.AssetSearchInteractor
import io.novafoundation.nova.feature_assets.domain.novaCard.NovaCardInteractor
import io.novafoundation.nova.feature_assets.domain.novaCard.RealNovaCardInteractor
import io.novafoundation.nova.feature_assets.domain.assets.search.AssetSearchInteractorFactory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ interface AssetsRouter {

fun openTopUpCard(payload: TopUpCardPayload)

fun closeTopUp()

fun finishSelectAndOpenSwapSetupAmount(swapSettingsPayload: SwapSettingsPayload)

fun openStaking()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import io.novafoundation.nova.common.utils.flowOf
import io.novafoundation.nova.common.utils.formatting.format
import io.novafoundation.nova.common.utils.formatting.formatAsPercentage
import io.novafoundation.nova.common.utils.formatting.spannable.SpannableFormatter
import io.novafoundation.nova.common.utils.formatting.toAmountWithFraction
import io.novafoundation.nova.common.utils.inBackground
import io.novafoundation.nova.common.utils.toSpannable
import io.novafoundation.nova.feature_account_api.domain.interfaces.SelectedAccountUseCase
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,29 @@ 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
import kotlinx.coroutines.launch
import java.math.BigDecimal
import javax.inject.Inject

class NovaCardFragment : BaseFragment<NovaCardViewModel>(), NovaCardEventHandler, OnCardCreatedListener {
class NovaCardFragment : BaseFragment<NovaCardViewModel>(), 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?,
Expand All @@ -46,11 +54,15 @@ class NovaCardFragment : BaseFragment<NovaCardViewModel>(), 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
)
Expand All @@ -59,15 +71,15 @@ class NovaCardFragment : BaseFragment<NovaCardViewModel>(), 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 onTopUpCompleted(orderId: String) {
viewModel.onTopUpCompleted(orderId)
}

override fun onCardCreated() {
viewModel.onCardCreated()
override fun onTopUpStart(orderId: String, amount: BigDecimal, address: String) {
viewModel.openTopUp(orderId, amount, address)
}
}
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -30,6 +26,8 @@ class NovaCardViewModel(
private val novaCardInteractor: NovaCardInteractor
) : BaseViewModel() {

private val openedOrderIds = mutableSetOf<String>()

private val metaAccount = flowOf { accountInteractor.selectedMetaAccount() }

private val topUpChain = flowOf { getTopUpChain() }
Expand All @@ -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 onTopUpCompleted(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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,39 +19,45 @@ 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

@Module(includes = [ViewModelModule::class])
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
)

@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
)
}

Expand Down

This file was deleted.

This file was deleted.

Loading
Loading