Skip to content

Commit

Permalink
fix(bugs): AND-0000 Fix UiTour and BuyIntroFragment Host Crashes (#4233)
Browse files Browse the repository at this point in the history
  • Loading branch information
dtverdota-bc committed Dec 14, 2022
1 parent 0fd5dc7 commit f5f1e6d
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 9 deletions.
Expand Up @@ -9,7 +9,6 @@ import androidx.recyclerview.widget.LinearLayoutManager
import com.blockchain.analytics.Analytics
import com.blockchain.api.NabuApiException
import com.blockchain.api.NabuApiExceptionFactory
import com.blockchain.coincore.AssetAction
import com.blockchain.commonarch.presentation.base.trackProgress
import com.blockchain.componentlib.basic.ComposeGravities
import com.blockchain.componentlib.basic.ComposeTypographies
Expand Down Expand Up @@ -52,7 +51,6 @@ import retrofit2.HttpException

class BuyIntroFragment :
ViewPagerFragment(),
BuyPendingOrdersBottomSheet.Host,
HomeScreenFragment,
KycUpgradeNowSheet.Host {

Expand Down Expand Up @@ -327,10 +325,6 @@ class BuyIntroFragment :
fun newInstance() = BuyIntroFragment()
}

override fun startActivityRequested() {
navigator().performAssetActionFor(AssetAction.ViewActivity)
}

override fun onSheetClosed() {
// do nothing
}
Expand Down
Expand Up @@ -18,6 +18,7 @@ import info.blockchain.balance.AssetCatalogue
import info.blockchain.balance.AssetInfo
import piuk.blockchain.android.R
import piuk.blockchain.android.databinding.ActivityActionBinding
import piuk.blockchain.android.simplebuy.sheets.BuyPendingOrdersBottomSheet
import piuk.blockchain.android.ui.base.showFragment
import piuk.blockchain.android.ui.brokerage.BuySellFragment
import piuk.blockchain.android.ui.swap.SwapFragment
Expand All @@ -29,7 +30,8 @@ class ActionActivity :
BlockchainActivity(),
SlidingModalBottomDialog.Host,
UpsellHost,
SwapFragment.Host {
SwapFragment.Host,
BuyPendingOrdersBottomSheet.Host {

override val alwaysDisableScreenshots: Boolean
get() = false
Expand Down Expand Up @@ -127,6 +129,10 @@ class ActionActivity :
// do nothing
}

override fun startActivityRequested() {
finishWithResult(ActivityResult.ViewActivity)
}

private fun finishWithResult(result: ActivityResult) {
val intent = Intent()
when (result) {
Expand All @@ -136,6 +142,7 @@ class ActionActivity :
intent.putExtra(CRYPTO_TICKER, cryptoTicker)
}
ActivityResult.StartBuyIntro -> intent.putExtra(RESULT_START_BUY_INTRO, true)
ActivityResult.ViewActivity -> intent.putExtra(RESULT_VIEW_ACTIVITY, true)
}
setResult(RESULT_OK, intent)
finish()
Expand All @@ -146,6 +153,7 @@ class ActionActivity :
private const val RESULT_START_KYC = "RESULT_START_KYC"
private const val RESULT_START_RECEIVE = "RESULT_START_RECEIVE"
private const val RESULT_START_BUY_INTRO = "RESULT_START_BUY_INTRO"
private const val RESULT_VIEW_ACTIVITY = "RESULT_VIEW_ACTIVITY"
private const val CRYPTO_TICKER = "CRYPTO_TICKER"

private fun newIntent(context: Context, action: AssetAction, cryptoTicker: String? = null): Intent =
Expand All @@ -163,6 +171,7 @@ class ActionActivity :
object StartKyc : ActivityResult()
class StartReceive(val cryptoTicker: String? = null) : ActivityResult()
object StartBuyIntro : ActivityResult()
object ViewActivity : ActivityResult()
}

class BlockchainActivityResultContract : ActivityResultContract<ActivityArgs, ActivityResult?>() {
Expand Down
Expand Up @@ -14,6 +14,7 @@ class AssetActionsNavigationImpl(private val activity: ComponentActivity?) : Ass
ActionActivity.ActivityResult.StartKyc -> launchKyc()
is ActionActivity.ActivityResult.StartReceive -> launchReceive()
ActionActivity.ActivityResult.StartBuyIntro -> launchBuy()
ActionActivity.ActivityResult.ViewActivity -> launchViewActivity()
null -> {
}
}
Expand All @@ -31,6 +32,10 @@ class AssetActionsNavigationImpl(private val activity: ComponentActivity?) : Ass
KycNavHostActivity.start(activity!!, campaignType = CampaignType.None)
}

private fun launchViewActivity() {
actionsResultContract!!.launch(ActionActivity.ActivityArgs(AssetAction.ViewActivity))
}

override fun navigate(assetAction: AssetAction) {
return actionsResultContract!!.launch(ActionActivity.ActivityArgs(action = assetAction, null))
}
Expand Down
Expand Up @@ -198,6 +198,7 @@ class MainActivity :
ActionActivity.ActivityResult.StartKyc -> launchKyc(CampaignType.None)
is ActionActivity.ActivityResult.StartReceive -> launchReceive(cryptoTicker = it.cryptoTicker)
ActionActivity.ActivityResult.StartBuyIntro -> launchBuySell(BuySellViewType.TYPE_BUY)
ActionActivity.ActivityResult.ViewActivity -> performAssetActionFor(AssetAction.ViewActivity)
null -> {
}
}
Expand Down Expand Up @@ -1100,7 +1101,7 @@ class MainActivity :

private fun hideUiTour(onAnimationEnd: (() -> Unit)? = null) {
binding.uiTour.apply {
logHideUi()
logHideUi(this@MainActivity)

animate()
.alpha(0f)
Expand Down
Expand Up @@ -294,7 +294,7 @@ class UiTourView @JvmOverloads constructor(
}
)

fun logHideUi() {
fun logHideUi(host: UiTourView.Host) {
if (isEarnOnNavBar) {
host.analytics.logEvent(UiTourAnalytics.NewTourDismissed(newTourCurrentStep))
} else {
Expand Down

0 comments on commit f5f1e6d

Please sign in to comment.