@@ -42,6 +42,7 @@ import com.getcode.solana.organizer.GiftCardAccount
4242import com.getcode.solana.organizer.Organizer
4343import com.getcode.solana.organizer.Relationship
4444import com.getcode.utils.ErrorUtils
45+ import com.getcode.utils.TraceType
4546import com.getcode.utils.bytes
4647import com.getcode.utils.trace
4748import com.google.protobuf.Timestamp
@@ -303,8 +304,8 @@ class TransactionRepository @Inject constructor(
303304 val subject = SingleSubject .create<IntentType >()
304305
305306 var serverMessageStream: StreamObserver <TransactionService .SubmitIntentRequest >? = null
306- val serverResponse = object : StreamObserver <TransactionService . SubmitIntentResponse > {
307- override fun onNext (value : TransactionService . SubmitIntentResponse ? ) {
307+ val serverResponse = object : StreamObserver <SubmitIntentResponse > {
308+ override fun onNext (value : SubmitIntentResponse ? ) {
308309 Timber .i(" Received: " + value?.responseCase?.name.orEmpty())
309310
310311 when (value?.responseCase) {
@@ -373,8 +374,9 @@ class TransactionRepository @Inject constructor(
373374 else -> Unit
374375 }
375376
376- Timber .e(
377- " Error: ${errors.joinToString(" \n " )} "
377+ trace(
378+ " Error: ${errors.joinToString(" \n " )} " ,
379+ type = TraceType .Error
378380 )
379381 }
380382
@@ -696,90 +698,90 @@ class TransactionRepository @Inject constructor(
696698 }
697699 }
698700 }
701+ }
699702
700- class ErrorSubmitIntentException (
701- val errorSubmitIntent : ErrorSubmitIntent ,
702- cause : Throwable ? = null ,
703- val messageString : String = " "
704- ) : Exception(cause) {
705- override val message: String
706- get() = " ${errorSubmitIntent.javaClass.simpleName} $messageString "
707- }
703+ class ErrorSubmitIntentException (
704+ val errorSubmitIntent : ErrorSubmitIntent ,
705+ cause : Throwable ? = null ,
706+ val messageString : String = " "
707+ ) : Exception(cause) {
708+ override val message: String
709+ get() = " ${errorSubmitIntent.javaClass.simpleName} $messageString "
710+ }
708711
709- enum class DeniedReason {
710- Unspecified ,
711- TooManyFreeAccountsForPhoneNumber ,
712- TooManyFreeAccountsForDevice ,
713- UnsupportedCountry ,
714- UnsupportedDevice ;
712+ enum class DeniedReason {
713+ Unspecified ,
714+ TooManyFreeAccountsForPhoneNumber ,
715+ TooManyFreeAccountsForDevice ,
716+ UnsupportedCountry ,
717+ UnsupportedDevice ;
715718
716- companion object {
717- fun fromValue (value : Int ): DeniedReason {
718- return entries.firstOrNull { it.ordinal == value } ? : Unspecified
719- }
719+ companion object {
720+ fun fromValue (value : Int ): DeniedReason {
721+ return entries.firstOrNull { it.ordinal == value } ? : Unspecified
720722 }
721723 }
724+ }
722725
723- sealed class ErrorSubmitIntent (val value : Int ) {
724- data class Denied (val reasons : List <DeniedReason > = emptyList()): ErrorSubmitIntent(0 )
725- data class InvalidIntent (val reasons : List <String >): ErrorSubmitIntent(1 )
726- data object SignatureError : ErrorSubmitIntent (2 )
727- data class StaleState (val reasons : List <String >): ErrorSubmitIntent(3 )
728- data object Unknown : ErrorSubmitIntent (-1 )
729- data object DeviceTokenUnavailable : ErrorSubmitIntent (-2 )
730-
731- override fun toString (): String {
732- return when (this ) {
733- is Denied -> " denied(${reasons.joinToString()} )"
734- DeviceTokenUnavailable -> " deviceTokenUnavailable"
735- is InvalidIntent -> " invalidIntent(${reasons.joinToString()} )"
736- SignatureError -> " signatureError"
737- is StaleState -> " staleState(${reasons.joinToString()} )"
738- Unknown -> " unknown"
739- }
726+ sealed class ErrorSubmitIntent (val value : Int ) {
727+ data class Denied (val reasons : List <DeniedReason > = emptyList()): ErrorSubmitIntent(0 )
728+ data class InvalidIntent (val reasons : List <String >): ErrorSubmitIntent(1 )
729+ data object SignatureError : ErrorSubmitIntent (2 )
730+ data class StaleState (val reasons : List <String >): ErrorSubmitIntent(3 )
731+ data object Unknown : ErrorSubmitIntent (-1 )
732+ data object DeviceTokenUnavailable : ErrorSubmitIntent (-2 )
733+
734+ override fun toString (): String {
735+ return when (this ) {
736+ is Denied -> " denied(${reasons.joinToString()} )"
737+ DeviceTokenUnavailable -> " deviceTokenUnavailable"
738+ is InvalidIntent -> " invalidIntent(${reasons.joinToString()} )"
739+ SignatureError -> " signatureError"
740+ is StaleState -> " staleState(${reasons.joinToString()} )"
741+ Unknown -> " unknown"
740742 }
743+ }
741744
742- companion object {
743- operator fun invoke (proto : SubmitIntentResponse .Error ): ErrorSubmitIntent {
744- val reasonStrings = proto.errorDetailsList.mapNotNull {
745- when (it.typeCase) {
746- TransactionService .ErrorDetails .TypeCase .REASON_STRING ->
747- it.reasonString.reason.takeIf { reason -> reason.isNotEmpty() }
748- else -> null
749- }
745+ companion object {
746+ operator fun invoke (proto : SubmitIntentResponse .Error ): ErrorSubmitIntent {
747+ val reasonStrings = proto.errorDetailsList.mapNotNull {
748+ when (it.typeCase) {
749+ TransactionService .ErrorDetails .TypeCase .REASON_STRING ->
750+ it.reasonString.reason.takeIf { reason -> reason.isNotEmpty() }
751+ else -> null
750752 }
751- return when (proto.code) {
752- SubmitIntentResponse .Error .Code .DENIED -> {
753- val reasons = proto.errorDetailsList.mapNotNull {
754- if (! it.hasIntentDenied()) return @mapNotNull null
755- DeniedReason .fromValue(it.intentDenied.reasonValue)
756- }
757-
758- Denied (reasons)
753+ }
754+ return when (proto.code) {
755+ SubmitIntentResponse .Error .Code .DENIED -> {
756+ val reasons = proto.errorDetailsList.mapNotNull {
757+ if (! it.hasIntentDenied()) return @mapNotNull null
758+ DeniedReason .fromValue(it.intentDenied.reasonValue)
759759 }
760- SubmitIntentResponse .Error .Code .INVALID_INTENT -> InvalidIntent (reasonStrings)
761- SubmitIntentResponse .Error .Code .SIGNATURE_ERROR -> SignatureError
762- SubmitIntentResponse .Error .Code .STALE_STATE -> StaleState (reasonStrings)
763- SubmitIntentResponse .Error .Code .UNRECOGNIZED -> Unknown
764- else -> return Unknown
760+
761+ Denied (reasons)
765762 }
763+ SubmitIntentResponse .Error .Code .INVALID_INTENT -> InvalidIntent (reasonStrings)
764+ SubmitIntentResponse .Error .Code .SIGNATURE_ERROR -> SignatureError
765+ SubmitIntentResponse .Error .Code .STALE_STATE -> StaleState (reasonStrings)
766+ SubmitIntentResponse .Error .Code .UNRECOGNIZED -> Unknown
767+ else -> return Unknown
766768 }
767769 }
768770 }
771+ }
769772
770- sealed class WithdrawException : Exception () {
771- class InvalidFractionalKinAmountException : WithdrawException ()
772- class InsufficientFundsException : WithdrawException ()
773- }
773+ sealed class WithdrawException : Exception () {
774+ class InvalidFractionalKinAmountException : WithdrawException ()
775+ class InsufficientFundsException : WithdrawException ()
776+ }
774777
775- sealed class FetchUpgradeableIntentsException : Exception () {
776- class DeserializationException : FetchUpgradeableIntentsException ()
777- class UnknownException : FetchUpgradeableIntentsException ()
778- }
778+ sealed class FetchUpgradeableIntentsException : Exception () {
779+ class DeserializationException : FetchUpgradeableIntentsException ()
780+ class UnknownException : FetchUpgradeableIntentsException ()
781+ }
779782
780- sealed class AirdropException : Exception () {
781- class AlreadyClaimedException : AirdropException ()
782- class UnavailableException : AirdropException ()
783- class UnknownException : AirdropException ()
784- }
783+ sealed class AirdropException : Exception () {
784+ class AlreadyClaimedException : AirdropException ()
785+ class UnavailableException : AirdropException ()
786+ class UnknownException : AirdropException ()
785787}
0 commit comments