11package com.flipcash.app.core.onramp.deeplinks
22
33import android.os.Parcelable
4- import com.flipcash.app.core.AppRoute
5- import com.getcode.ed25519.Ed25519
6- import com.getcode.opencode.model.core.ID
7- import com.getcode.opencode.utils.base64
8- import com.getcode.opencode.utils.base64UrlSafe
9- import com.getcode.solana.keys.Mint
104import com.getcode.solana.keys.PublicKey
11- import com.getcode.solana.keys.base58
12- import com.getcode.utils.base58
13- import com.getcode.utils.decodeBase58
14- import com.getcode.utils.decodeBase64
15- import com.getcode.utils.serializer.ByteListAsBase64Serializer
165import kotlinx.parcelize.Parcelize
176import kotlinx.serialization.SerialName
187import kotlinx.serialization.Serializable
@@ -31,101 +20,3 @@ data class ExternallySignedTransaction(
3120 @SerialName(" transaction" )
3221 val serializedTransaction : String ,
3322): Parcelable
34-
35- @Serializable
36- @Parcelize
37- sealed class OnRampDeeplinkOrigin : Parcelable {
38- @Serializable @Parcelize
39- data object Menu : OnRampDeeplinkOrigin ()
40-
41- @Serializable @Parcelize
42- data class Give (val tokenAddress : Mint ? ) : OnRampDeeplinkOrigin()
43-
44- @Serializable @Parcelize
45- data object Wallet : OnRampDeeplinkOrigin ()
46-
47- @Serializable @Parcelize
48- data class TokenInfo (val mint : Mint ): OnRampDeeplinkOrigin()
49-
50- @Serializable @Parcelize
51- data object Reserves : OnRampDeeplinkOrigin ()
52-
53- @Serializable @Parcelize
54- data object CurrencyCreator : OnRampDeeplinkOrigin ()
55-
56-
57- fun forUri (): String {
58- return when (this ) {
59- Menu -> " menu"
60- is Give -> " give-${tokenAddress?.base58()?.base64UrlSafe} "
61- Wallet -> " wallet"
62- is TokenInfo -> " token-${mint.base58().base64UrlSafe} "
63- Reserves -> " reserves"
64- CurrencyCreator -> " currency-creator"
65- }.lowercase()
66- }
67-
68- companion object Companion {
69- fun fromRoute (route : AppRoute ? ): OnRampDeeplinkOrigin ? {
70- return when (route) {
71- is AppRoute .Sheets .Menu -> Menu
72- is AppRoute .Sheets .Give -> Give (route.mint)
73- is AppRoute .Sheets .Wallet -> Wallet
74- is AppRoute .Token .Info -> {
75- if (route.mint == Mint .usdf) Reserves else TokenInfo (route.mint)
76- }
77- is AppRoute .Token .CurrencyCreator -> CurrencyCreator
78-
79- else -> null
80- }
81- }
82-
83- fun fromString (value : String? ): OnRampDeeplinkOrigin ? {
84- return when {
85- value == " menu" -> Menu
86- value?.startsWith(" give-" ) == true -> {
87- val tokenAddress = value.removePrefix(" give-" ).decodeBase64().base58
88- val mint = runCatching {
89- Mint (tokenAddress)
90- }.getOrNull() ? : return null
91- Give (mint)
92- }
93- value == " wallet" -> Wallet
94- value == " reserves" -> Reserves
95- value == " currency-creator" -> CurrencyCreator
96- value?.startsWith(" token-" ) == true -> {
97- val mintString = value.removePrefix(" token-" ).decodeBase64().base58
98- val mint = runCatching {
99- Mint (mintString)
100- }.onFailure { it.printStackTrace() }.getOrNull() ? : return null
101-
102- TokenInfo (mint)
103- }
104-
105- else -> return null
106- }
107- }
108- }
109- }
110-
111- @Serializable
112- @Parcelize
113- data class WalletDeeplinkConnectionResult (
114- @Serializable(with = ByteListAsBase64Serializer ::class ) val encryptionPublicKey : List <Byte >,
115- @Serializable(with = ByteListAsBase64Serializer ::class ) val nonce : List <Byte >,
116- @Serializable(with = ByteListAsBase64Serializer ::class ) val encryptedData : List <Byte >
117- ): Parcelable
118-
119- @Serializable
120- @Parcelize
121- data class WalletDeeplinkSigningResult (
122- @Serializable(with = ByteListAsBase64Serializer ::class ) val nonce : List <Byte >,
123- @Serializable(with = ByteListAsBase64Serializer ::class ) val encryptedData : List <Byte >,
124- ): Parcelable
125-
126- @Serializable
127- @Parcelize
128- data class ExternalWalletDeeplinkError (
129- val errorCode : String ,
130- val errorMessage : String ,
131- ): Parcelable
0 commit comments