Skip to content

Commit

Permalink
Closes #413: Select payment token when recovering safe (#504)
Browse files Browse the repository at this point in the history
  • Loading branch information
elgatovital authored Dec 5, 2019
1 parent 6b0efc8 commit 06916a9
Show file tree
Hide file tree
Showing 10 changed files with 275 additions and 295 deletions.
1 change: 0 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,6 @@
android:screenOrientation="portrait"
android:theme="@style/GreyBackgroundTheme" />


<activity
android:name=".ui.safe.pairing.replace.Replace2FaRecoveryPhraseActivity"
android:screenOrientation="portrait"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,6 @@ class PairingSubmitActivity : ViewModelActivity<PairingSubmitContract>(), Confir
errorSnackbar(review_coordinator, throwable)
}


companion object {
private const val EXTRA_PAIRING_ACTION = "extra.parcelable.pairingAction"

Expand Down Expand Up @@ -218,7 +217,6 @@ class PairingSubmitActivity : ViewModelActivity<PairingSubmitContract>(), Confir
) =
Intent(context, PairingSubmitActivity::class.java).apply {
putExtra(EXTRA_PAIRING_ACTION, action)

putExtra(EXTRA_SAFE_TRANSACTION, safeTransaction)
putExtra(EXTRA_SIGNATURE_1, signature1.toString())
putExtra(EXTRA_SIGNATURE_2, signature2.toString())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import pm.gnosis.heimdall.reporting.ScreenId
import pm.gnosis.heimdall.ui.base.ViewModelActivity
import pm.gnosis.heimdall.ui.exceptions.LocalizedException
import pm.gnosis.heimdall.ui.safe.recover.safe.CheckSafeContract.CheckResult.*
import pm.gnosis.heimdall.ui.tokens.payment.PaymentTokensActivity
import pm.gnosis.heimdall.utils.setCompoundDrawableResource
import pm.gnosis.heimdall.utils.setCompoundDrawables
import pm.gnosis.model.Solidity
Expand Down Expand Up @@ -75,7 +76,9 @@ class CheckSafeActivity : ViewModelActivity<CheckSafeContract>() {

disposables += layout_check_safe_next.clicks()
.subscribeBy {
nextIntent?.let { startActivity(it) }
nextIntent?.let {
startActivity(PaymentTokensActivity.createIntent(context = this, safeAddress = currentAddress, hint = getString(R.string.choose_how_to_pay_recovery_fee), nextAction = it))
}
}

disposables += layout_check_safe_back_arrow.clicks().subscribeBy { onBackPressed() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ package pm.gnosis.heimdall.ui.safe.recover.safe

import android.content.Context
import android.content.Intent
import android.os.Bundle
import kotlinx.android.synthetic.main.layout_input_recovery_phrase.*
import pm.gnosis.heimdall.data.repositories.AccountsRepository
import pm.gnosis.heimdall.di.components.ViewComponent
import pm.gnosis.heimdall.reporting.ScreenId
import pm.gnosis.heimdall.ui.safe.main.SafeMainActivity
Expand Down Expand Up @@ -34,6 +32,7 @@ class RecoverSafeRecoveryPhraseActivity : InputRecoveryPhraseActivity<RecoverSaf
override fun inject(component: ViewComponent) = component.inject(this)

companion object {

fun createIntent(
context: Context,
safeAddress: Solidity.Address,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.jakewharton.rxbinding2.view.clicks
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.rxkotlin.plusAssign
import io.reactivex.rxkotlin.subscribeBy
import kotlinx.android.synthetic.main.layout_recovering_safe_submit.*
import pm.gnosis.heimdall.R
import pm.gnosis.heimdall.data.repositories.models.RecoveringSafe
Expand All @@ -19,14 +19,22 @@ import pm.gnosis.heimdall.reporting.EventTracker
import pm.gnosis.heimdall.reporting.ScreenId
import pm.gnosis.heimdall.ui.base.BaseFragment
import pm.gnosis.heimdall.ui.safe.main.SafeMainActivity
import pm.gnosis.heimdall.utils.InfoTipDialogBuilder
import pm.gnosis.heimdall.utils.errorSnackbar
import pm.gnosis.model.Solidity
import pm.gnosis.svalinn.common.utils.mapToResult
import pm.gnosis.svalinn.common.utils.subscribeForResult
import pm.gnosis.svalinn.common.utils.visible
import pm.gnosis.svalinn.common.utils.withArgs
import pm.gnosis.utils.asEthereumAddress
import pm.gnosis.utils.asEthereumAddressString
import javax.inject.Inject
import kotlinx.android.synthetic.main.include_transfer_summary_final.transfer_data_fees_error as feesError
import kotlinx.android.synthetic.main.include_transfer_summary_final.transfer_data_fees_info as feesInfo
import kotlinx.android.synthetic.main.include_transfer_summary_final.transfer_data_fees_value as feesValue
import kotlinx.android.synthetic.main.include_transfer_summary_final.transfer_data_safe_balance_after_value as balanceAfterValue
import kotlinx.android.synthetic.main.include_transfer_summary_final.transfer_data_safe_balance_before_value as balanceBeforeValue
import kotlinx.android.synthetic.main.layout_recovering_safe_submit.recover_safe_swipe_to_refresh as swipeToRefresh

class RecoveringSafeSubmitFragment : BaseFragment() {

Expand All @@ -45,65 +53,86 @@ class RecoveringSafeSubmitFragment : BaseFragment() {
@Inject
lateinit var eventTracker: EventTracker

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? =
inflater.inflate(R.layout.layout_recovering_safe_submit, container, false)
protected lateinit var safe: Solidity.Address

override fun onStart() {
super.onStart()
eventTracker.submit(Event.ScreenView(ScreenId.RECOVER_SAFE_REVIEW))
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View?
= inflater.inflate(R.layout.layout_recovering_safe_submit, container, false)

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

recover_safe_bottom_panel.disabled = true

safe = arguments?.getString(EXTRA_SAFE_ADDRESS)?.asEthereumAddress() ?: throw IllegalStateException("No safe address provided!")

layout_recovering_safe_submit_button.isEnabled = false
layout_recovering_safe_submit_button.visible(true)
layout_recovering_safe_submit_retry.isEnabled = false
layout_recovering_safe_submit_retry.visible(false)
val safeAddress = arguments?.getString(EXTRA_SAFE_ADDRESS)?.asEthereumAddress() ?: throw IllegalStateException("No safe address provided!")
addressHelper.populateAddressInfo(
layout_recovering_safe_submit_info_safe_address,
layout_recovering_safe_submit_info_safe_name,
layout_recovering_safe_submit_info_safe_image,
safeAddress
recover_safe_submit_info_safe_address,
recover_safe_submit_info_safe_name,
recover_safe_submit_info_safe_image,
safe
).forEach { disposables += it }

// Automatically load on start
disposables += layout_recovering_safe_submit_retry.clicks().startWith(Unit)
.doOnNext {
layout_recovering_safe_submit_retry.isEnabled = false
layout_recovering_safe_submit_button.isEnabled = false
swipeToRefresh.setOnRefreshListener {
loadExecuteInfo()
}

}
.switchMapSingle { viewModel.loadRecoveryExecuteInfo(safeAddress).mapToResult() }
.observeOn(AndroidSchedulers.mainThread())
.subscribeForResult(onNext = {
layout_recovering_safe_submit_data_balance_value.text = it.paymentToken.displayString(it.balance)
layout_recovering_safe_submit_data_fees_value.text = it.paymentToken.displayString(it.paymentAmount)
layout_recovering_safe_submit_data_fees_error.visible(!it.canSubmit)
layout_recovering_safe_submit_button.visible(it.canSubmit)
layout_recovering_safe_submit_button.isEnabled = it.canSubmit
layout_recovering_safe_submit_retry.visible(!it.canSubmit)
layout_recovering_safe_submit_retry.isEnabled = !it.canSubmit
}, onError = {
errorSnackbar(layout_recovering_safe_submit_button, it)
layout_recovering_safe_submit_button.visible(false)
layout_recovering_safe_submit_retry.isEnabled = true
layout_recovering_safe_submit_retry.visible(true)
})
feesInfo.setOnClickListener {
InfoTipDialogBuilder.build(context!!, R.layout.dialog_network_fee, R.string.ok).show()
}

disposables += layout_recovering_safe_submit_button.clicks()
}

override fun onStart() {
super.onStart()
eventTracker.submit(Event.ScreenView(ScreenId.RECOVER_SAFE_REVIEW))

disposables += recover_safe_bottom_panel.forwardClicks
.doOnNext {
layout_recovering_safe_submit_retry.isEnabled = false
layout_recovering_safe_submit_button.isEnabled = false
onLoading(true)
}
.switchMapSingle { viewModel.submitRecovery(safeAddress).mapToResult() }
.switchMapSingle { viewModel.submitRecovery(safe).mapToResult() }
.observeOn(AndroidSchedulers.mainThread())
.subscribeForResult(onNext = {
startActivity(SafeMainActivity.createIntent(context!!, it))
}, onError = {
errorSnackbar(layout_recovering_safe_submit_button, it)
layout_recovering_safe_submit_button.isEnabled = true
layout_recovering_safe_submit_retry.isEnabled = true
errorSnackbar(recover_safe_bottom_panel, it)
onLoading(false)
})
}

override fun onResume() {
super.onResume()
loadExecuteInfo()
}

private fun loadExecuteInfo() {
onLoading(true)
viewModel.loadRecoveryExecuteInfo(safe)
.observeOn(AndroidSchedulers.mainThread())
.subscribeBy(
{
onLoading(false)
errorSnackbar(recover_safe_bottom_panel, it)
},
{
balanceBeforeValue.text = it.paymentToken.displayString(it.balance)
balanceAfterValue.text = it.paymentToken.displayString(it.balance - it.paymentAmount)
feesValue.text = it.paymentToken.displayString(it.paymentAmount)
feesError.visible(!it.canSubmit)
recover_safe_bottom_panel.disabled = !it.canSubmit
onLoading(false)
}
)
}

private fun onLoading(isLoading: Boolean) {
recover_safe_bottom_panel.disabled = isLoading
recover_safe_progress_bar.visible(isLoading)
swipeToRefresh.isRefreshing = false
swipeToRefresh.isActivated = !isLoading
swipeToRefresh.isEnabled = !isLoading
}

companion object {
private const val EXTRA_SAFE_ADDRESS = "extra.string.safe_address"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import androidx.recyclerview.widget.DividerItemDecoration
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.google.android.material.snackbar.Snackbar
import io.reactivex.rxkotlin.plusAssign
import io.reactivex.rxkotlin.subscribeBy
import kotlinx.android.synthetic.main.layout_payment_tokens.*
import pm.gnosis.heimdall.R
import pm.gnosis.heimdall.data.repositories.models.SafeTransaction
Expand All @@ -18,6 +20,7 @@ import pm.gnosis.heimdall.ui.base.ViewModelActivity
import pm.gnosis.heimdall.utils.errorSnackbar
import pm.gnosis.heimdall.utils.weak
import pm.gnosis.model.Solidity
import pm.gnosis.svalinn.common.utils.visible
import pm.gnosis.utils.asEthereumAddress
import pm.gnosis.utils.asEthereumAddressString
import java.lang.ref.WeakReference
Expand All @@ -35,12 +38,15 @@ class PaymentTokensActivity : ViewModelActivity<PaymentTokensContract>() {

override fun screenId(): ScreenId = ScreenId.SELECT_PAYMENT_TOKEN

private var nextAction: Intent? = null

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
payment_tokens_recycler_view.layoutManager = LinearLayoutManager(this, RecyclerView.VERTICAL, false)
payment_tokens_recycler_view.addItemDecoration(DividerItemDecoration(this, RecyclerView.VERTICAL))
payment_tokens_recycler_view.adapter = adapter

nextAction = intent.getParcelableExtra<Intent?>(EXTRA_NEXT_ACTION)
val safe = intent.getStringExtra(EXTRA_SAFE_ADDRESS)?.let { it.asEthereumAddress()!! }
val transaction = intent.getParcelableExtra<SafeTransaction>(EXTRA_TRANSACTION)
val metricType = when {
Expand All @@ -56,6 +62,9 @@ class PaymentTokensActivity : ViewModelActivity<PaymentTokensContract>() {
state.viewAction?.let { performAction(it) }
})

val hint = intent.getStringExtra(EXTRA_HINT) ?: getString(R.string.this_payment_will_be_used)
payment_tokens_explainer_lbl.text = hint

payment_tokens_back_arrow.setOnClickListener { onBackPressed() }
payment_tokens_swipe_refresh.setOnRefreshListener { refreshList() }
payment_tokens_header_metric_lbl.text = getString(
Expand All @@ -66,6 +75,22 @@ class PaymentTokensActivity : ViewModelActivity<PaymentTokensContract>() {
R.string.fee
}
)

if (nextAction != null) {
payment_token_bottom_panel.visible(true)
viewModel.paymentToken.observe(this, Observer {
payment_token_bottom_panel.forwardLabel = getString(R.string.pay_with, it.symbol)
})
}
}

override fun onStart() {
super.onStart()
nextAction?.let { nextAction ->
disposables += payment_token_bottom_panel.forwardClicks.subscribeBy {
startActivity(nextAction)
}
}
}

private fun performAction(viewAction: PaymentTokensContract.ViewAction): Any =
Expand Down Expand Up @@ -95,11 +120,22 @@ class PaymentTokensActivity : ViewModelActivity<PaymentTokensContract>() {
private const val EXTRA_SAFE_ADDRESS = "extra.string.safe_address"
private const val EXTRA_TRANSACTION = "extra.parcelable.transaction"
private const val EXTRA_OWNER_COUNT = "extra.integer.owner_count"
fun createIntent(context: Context, safeAddress: Solidity.Address? = null, transaction: SafeTransaction? = null, ownerCount: Long? = null) =
private const val EXTRA_HINT = "extra.string.hint"
private const val EXTRA_NEXT_ACTION = "extra.parcelable.next_action"

fun createIntent(
context: Context,
safeAddress: Solidity.Address? = null,
transaction: SafeTransaction? = null,
ownerCount: Long? = null,
hint: String? = null,
nextAction: Intent? = null) =
Intent(context, PaymentTokensActivity::class.java).apply {
putExtra(EXTRA_SAFE_ADDRESS, safeAddress?.asEthereumAddressString())
putExtra(EXTRA_OWNER_COUNT, ownerCount)
putExtra(EXTRA_TRANSACTION, transaction)
putExtra(EXTRA_HINT, hint)
putExtra(EXTRA_NEXT_ACTION, nextAction)
}
}
}
14 changes: 13 additions & 1 deletion app/src/main/res/layout/layout_payment_tokens.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
android:layout_height="0dp"
app:layout_constraintTop_toBottomOf="@id/payment_tokens_title"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintBottom_toTopOf="@id/payment_token_bottom_panel"
app:layout_constraintStart_toStartOf="parent"
tools:background="@color/pale_grey_two">

Expand Down Expand Up @@ -144,5 +144,17 @@
android:background="@drawable/toolbar_dropshadow"
app:layout_constraintTop_toBottomOf="@+id/payment_tokens_title" />


<pm.gnosis.heimdall.views.TwoStepPanel
android:id="@+id/payment_token_bottom_panel"
android:layout_width="match_parent"
android:layout_height="46dp"
android:background="@drawable/two_step_panel"
android:visibility="gone"
app:backVisible="false"
app:forwardLabel="@string/pay_with"
app:layout_constraintBottom_toBottomOf="parent"
app:step="none" />

</androidx.constraintlayout.widget.ConstraintLayout>

Loading

0 comments on commit 06916a9

Please sign in to comment.