Skip to content

Commit

Permalink
Merge pull request #664 from alexandrVakhtinTari/bugs/fixes_parceble_bug
Browse files Browse the repository at this point in the history
fix: fixed yat parceble bugs
  • Loading branch information
alexandrVakhtinTari authored Nov 4, 2021
2 parents 22d84b8 + 60ee17d commit 65cc68b
Show file tree
Hide file tree
Showing 11 changed files with 99 additions and 45 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ dependencies {
// sentry - crash analytics
regularImplementation 'io.sentry:sentry-android:5.0.1'

implementation "com.github.yat-labs:yat-lib-android:0.1.20"
implementation "com.github.yat-labs:yat-lib-android:0.1.22"

// test
testImplementation 'junit:junit:4.13.2'
Expand Down
3 changes: 1 addition & 2 deletions app/src/main/java/com/tari/android/wallet/model/Contact.kt
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,13 @@ package com.tari.android.wallet.model

import android.os.Parcel
import android.os.Parcelable
import java.io.Serializable

/**
* Contact is a user with an alias.
*
* @author The Tari Development Team
*/
class Contact() : User(), Serializable {
class Contact() : User(), Parcelable {

var alias: String = ""

Expand Down
3 changes: 1 addition & 2 deletions app/src/main/java/com/tari/android/wallet/model/User.kt
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,13 @@ package com.tari.android.wallet.model

import android.os.Parcel
import android.os.Parcelable
import java.io.Serializable

/**
* User with a wallet.
*
* @author The Tari Development Team
*/
open class User() : Parcelable, Serializable {
open class User() : Parcelable {

var publicKey = PublicKey()

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,36 @@
package com.tari.android.wallet.ui.fragment.send.common

import android.os.Parcel
import android.os.Parcelable
import com.tari.android.wallet.model.MicroTari
import com.tari.android.wallet.model.User
import java.io.Serializable

data class TransactionData(val recipientUser: User?, val amount: MicroTari?, val note: String?) : Serializable
data class TransactionData(val recipientUser: User?, val amount: MicroTari?, val note: String?) : Parcelable {

constructor(parcel: Parcel) : this(
parcel.readParcelable(User::class.java.classLoader),
parcel.readParcelable(MicroTari::class.java.classLoader),
parcel.readString()
) {
}

override fun writeToParcel(parcel: Parcel, flags: Int) {
parcel.writeParcelable(recipientUser, flags)
parcel.writeParcelable(amount, flags)
parcel.writeString(note)
}

override fun describeContents(): Int {
return 0
}

companion object CREATOR : Parcelable.Creator<TransactionData> {
override fun createFromParcel(parcel: Parcel): TransactionData {
return TransactionData(parcel)
}

override fun newArray(size: Int): Array<TransactionData?> {
return arrayOfNulls(size)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import com.tari.android.wallet.R.string.*
import com.tari.android.wallet.databinding.FragmentFinalizeSendTxBinding
import com.tari.android.wallet.di.DiContainer.appComponent
import com.tari.android.wallet.event.EventBus
import com.tari.android.wallet.extension.observeOnLoad
import com.tari.android.wallet.model.*
import com.tari.android.wallet.network.NetworkConnectionState
import com.tari.android.wallet.ui.common.CommonFragment
Expand Down Expand Up @@ -90,8 +91,17 @@ class FinalizeSendTxFragment : CommonFragment<FragmentFinalizeSendTxBinding, Fin
val viewModel: FinalizeSendTxViewModel by viewModels()
bindViewModel(viewModel)

viewModel.transactionData = requireArguments().getSerializable(FinalizeSendTxViewModel.transactionDataKey) as TransactionData
viewModel.transactionData = requireArguments().getParcelable(FinalizeSendTxViewModel.transactionDataKey)!!
setupUi()
subscribeUI()
}

private fun subscribeUI() = with(viewModel) {
observeOnLoad(txFailureReason)
observeOnLoad(sentTxId)
observeOnLoad(currentStep)
observeOnLoad(finishedSending)
observeOnLoad(torConnected)
}

override fun onStart() {
Expand Down Expand Up @@ -343,7 +353,7 @@ class FinalizeSendTxFragment : CommonFragment<FragmentFinalizeSendTxBinding, Fin
fun create(transactionData: TransactionData): FinalizeSendTxFragment {
return FinalizeSendTxFragment().apply {
arguments = Bundle().apply {
putSerializable(FinalizeSendTxViewModel.transactionDataKey, transactionData)
putParcelable(FinalizeSendTxViewModel.transactionDataKey, transactionData)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class FinalizeSendTxViewModel : CommonViewModel() {
var sentTxId: MutableLiveData<TxId> = MutableLiveData()
var txFailureReason: MutableLiveData<TxFailureReason> = MutableLiveData()
var torConnected: SingleLiveEvent<Unit> = SingleLiveEvent()
var finishedSending: SingleLiveEvent<Unit> = SingleLiveEvent()

/**
* Both send methods have to fail to arrive at the judgement that the send has failed.
Expand Down Expand Up @@ -154,6 +155,7 @@ class FinalizeSendTxViewModel : CommonViewModel() {
// progress state
switchToNextProgressStateOnProgressAnimComplete = true
EventBus.unsubscribe(this)
finishedSending.postValue(Unit)
} else {
directSendHasFailed = true
checkForCombinedFailure()
Expand All @@ -172,6 +174,7 @@ class FinalizeSendTxViewModel : CommonViewModel() {
// progress state
switchToNextProgressStateOnProgressAnimComplete = true
EventBus.unsubscribe(this)
finishedSending.postValue(Unit)
} else {
storeAndForwardHasFailed = true
checkForCombinedFailure()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package com.tari.android.wallet.ui.fragment.send.finalize

import android.os.Bundle
import androidx.activity.viewModels
import com.google.gson.Gson
import com.tari.android.wallet.extension.observe
import com.tari.android.wallet.extension.observeOnLoad
import com.tari.android.wallet.ui.fragment.send.activity.SendTariActivity
import com.tari.android.wallet.ui.fragment.send.common.TransactionData
import yat.android.ui.transactions.outcoming.TransactionState
Expand All @@ -15,21 +17,32 @@ class YatFinalizeSendTxActivity : YatLibOutcomingTransactionActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

viewModel.transactionData = intent.getSerializableExtra(FinalizeSendTxViewModel.transactionDataKey) as TransactionData
val gson = intent.getStringExtra(FinalizeSendTxViewModel.transactionDataKey)!!
val entity = Gson().fromJson(gson, TransactionData::class.java)

viewModel.transactionData = entity
subscribeOnUI()
}

private fun subscribeOnUI() = with(viewModel) {
observe(txFailureReason) {
setTransactionState(TransactionState.Failed)
SendTariActivity.instance.get()?.onSendTxFailure(viewModel.transactionData, it)
}
observe(txFailureReason) { setTransactionState(TransactionState.Failed) }

observe(torConnected) { viewModel.sendTari() }

observe(finishedSending) { setTransactionState(TransactionState.Complete) }

observe(sentTxId) {
setTransactionState(TransactionState.Complete)
observeOnLoad(sentTxId)
observeOnLoad(currentStep)
}

override fun onStop() {
super.onStop()
viewModel.sentTxId.value?.let {
SendTariActivity.instance.get()?.onSendTxSuccessful(it, viewModel.transactionData)
}

observe(torConnected) { viewModel.sendTari() }
viewModel.txFailureReason.value?.let {
SendTariActivity.instance.get()?.onSendTxFailure(viewModel.transactionData, it)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -338,9 +338,14 @@ internal class TxListViewModel() : CommonViewModel() {
_txSendSuccessful.postValue(Unit)

viewModelScope.launch(Dispatchers.IO) {
val tx = walletService.getWithError { error, wallet -> wallet.getPendingOutboundTxById(txId, error) }
pendingOutboundTxs.add(tx)
_listUpdateTrigger.postValue(Unit)
val error = WalletError()
val tx = walletService.getPendingOutboundTxById(txId, error)
if (error.code == WalletErrorCode.NO_ERROR) {
pendingOutboundTxs.add(tx)
_listUpdateTrigger.postValue(Unit)
} else {
refreshAllData()
}
}

refreshBalance(true)
Expand Down
6 changes: 4 additions & 2 deletions app/src/main/java/com/tari/android/wallet/yat/YatAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.app.Activity
import android.app.ActivityOptions
import android.content.Context
import android.content.Intent
import com.google.gson.Gson
import com.orhanobut.logger.Logger
import com.tari.android.wallet.BuildConfig
import com.tari.android.wallet.data.sharedPrefs.SharedPrefsRepository
Expand Down Expand Up @@ -39,8 +40,9 @@ class YatAdapter(
val data = YatLibOutcomingTransactionData(transactionData.amount!!.tariValue.toDouble(), "Tari", yatUser.yat)

val intent = Intent(activity, YatFinalizeSendTxActivity::class.java)
intent.putExtra("YatLibDataKey", data)
intent.putExtra(FinalizeSendTxViewModel.transactionDataKey, transactionData as Serializable)
intent.putExtra("YatLibDataKey", data as Serializable)
val gson = Gson().toJson(transactionData)
intent.putExtra(FinalizeSendTxViewModel.transactionDataKey, gson)
intent.flags = Intent.FLAG_ACTIVITY_NO_ANIMATION
activity.startActivity(intent, ActivityOptions.makeSceneTransitionAnimation(activity).toBundle())
}
Expand Down
38 changes: 16 additions & 22 deletions app/src/main/java/com/tari/android/wallet/yat/YatUser.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,45 +4,39 @@ import android.os.Parcel
import android.os.Parcelable
import com.tari.android.wallet.model.PublicKey
import com.tari.android.wallet.model.User
import java.io.Serializable

class YatUser : User, Serializable {
class YatUser() : User(), Parcelable {

var yat: String = ""

constructor(publicKey: PublicKey) : super() {
constructor(publicKey: PublicKey) : this() {
this.publicKey = publicKey
}

// region Parcelable

constructor(parcel: Parcel) : super() {
readFromParcel(parcel)
}

companion object CREATOR : Parcelable.Creator<User> {

override fun createFromParcel(parcel: Parcel): User {
return User(parcel)
}

override fun newArray(size: Int): Array<User> {
return Array(size) { User() }
}

constructor(parcel: Parcel) : this() {
yat = parcel.readString().orEmpty()
}

override fun writeToParcel(parcel: Parcel, flags: Int) {
parcel.writeParcelable(publicKey, flags)
}

private fun readFromParcel(inParcel: Parcel) {
publicKey = inParcel.readParcelable(PublicKey::class.java.classLoader)!!
super.writeToParcel(parcel, flags)
parcel.writeString(yat)
}

override fun describeContents(): Int {
return 0
}

companion object CREATOR : Parcelable.Creator<YatUser> {
override fun createFromParcel(parcel: Parcel): YatUser {
return YatUser(parcel)
}

override fun newArray(size: Int): Array<YatUser?> {
return arrayOfNulls(size)
}
}

// endregion
}
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ buildscript {
ext.kotlin_version = '1.5.21'

// build & version
ext.buildNumber = 174
ext.buildNumber = 175
ext.versionNumber = "0.8.1"

// JNI libs
Expand Down

0 comments on commit 65cc68b

Please sign in to comment.