Skip to content

Commit 8ecc8fa

Browse files
committed
chore: create transaction for buying tokens directly with USDC
disabled for now until Phantom issue is resolved Signed-off-by: Brandon McAnsh <git@bmcreations.dev>
1 parent 838c110 commit 8ecc8fa

31 files changed

Lines changed: 573 additions & 196 deletions

File tree

apps/flipcash/app/src/main/kotlin/com/flipcash/app/MainActivity.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ import com.flipcash.app.payments.PaymentController
2727
import com.flipcash.app.phone.LocalPhoneUtils
2828
import com.flipcash.app.phone.PhoneUtils
2929
import com.flipcash.app.router.LocalRouter
30-
import com.flipcash.app.session.SessionController
3130
import com.flipcash.app.router.Router
3231
import com.flipcash.app.session.LocalSessionController
32+
import com.flipcash.app.session.SessionController
3333
import com.flipcash.app.shareable.LocalShareController
3434
import com.flipcash.app.shareable.ShareSheetController
3535
import com.flipcash.app.updates.AppUpdateController
@@ -38,6 +38,8 @@ import com.flipcash.services.analytics.FlipcashAnalyticsService
3838
import com.flipcash.services.user.UserManager
3939
import com.getcode.libs.analytics.LocalAnalytics
4040
import com.getcode.opencode.compose.LocalExchange
41+
import com.getcode.opencode.compose.LocalTransactionController
42+
import com.getcode.opencode.controllers.TransactionController
4143
import com.getcode.opencode.exchange.Exchange
4244
import com.getcode.solana.rpc.RpcConfig
4345
import com.getcode.util.permissions.LocalPermissionChecker
@@ -128,6 +130,9 @@ class MainActivity : FragmentActivity() {
128130
@Inject
129131
lateinit var appUpdater: AppUpdateController
130132

133+
@Inject
134+
lateinit var transactionController: TransactionController
135+
131136

132137
override fun onCreate(savedInstanceState: Bundle?) {
133138
super.onCreate(savedInstanceState)
@@ -153,6 +158,7 @@ class MainActivity : FragmentActivity() {
153158
LocalFeatureFlags provides featureFlagController,
154159
LocalPaymentController provides paymentController,
155160
LocalOnRampAmountController provides onRampAmountController,
161+
LocalTransactionController provides transactionController,
156162
LocalPhoneUtils provides phoneUtils,
157163
LocalBillPlaygroundController provides billPlaygroundController,
158164
LocalAppUpdater provides appUpdater,

apps/flipcash/core/src/main/res/values/strings.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@
318318

319319
<string name="action_sendAsLink">Send as a Link</string>
320320

321-
<string name="subtitle_addUsdcToWallet">Add Solana USDC to your Flipcash wallet</string>
321+
<string name="subtitle_addUsdcToWallet">Add Solana USDF to your Flipcash wallet</string>
322322

323323
<string name="title_selectCurrency">Select Currency</string>
324324
<string name="title_selectRegion">Select Region</string>
@@ -378,7 +378,7 @@
378378
<string name="action_buy">Buy</string>
379379
<string name="action_sell">Sell</string>
380380
<string name="title_amountToWithdraw">Amount to Withdraw</string>
381-
<string name="label_solanaUsdc">Solana USDC with</string>
381+
<string name="label_solanaUsdf">Solana USDC with</string>
382382
<string name="title_sellToken">Sell %1$s</string>
383383
<string name="label_sellWarning">Review the above before confirming.\nOnce made, your transaction is irreversible.</string>
384384

apps/flipcash/features/tokens/src/main/kotlin/com/flipcash/app/tokens/TokenBuySellEntryScreen.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,10 @@ class TokenBuySellEntryScreen(
9595
LaunchedEffect(viewModel) {
9696
viewModel.eventFlow
9797
.filterIsInstance<BuySellSwapTokenViewModel.Event.CreateAndSendTransactionToWallet>()
98-
.map { it.amount }
99-
.onEach { externalWalletOnRamp.amount = it }
100-
.launchIn(this)
98+
.onEach { (token, amount) ->
99+
externalWalletOnRamp.tokenToPurchase = token
100+
externalWalletOnRamp.amount = amount
101+
}.launchIn(this)
101102
}
102103

103104
LaunchedEffect(viewModel) {

apps/flipcash/shared/onramp/deeplinks/src/main/kotlin/com/flipcash/app/onramp/DeeplinkOnRampErrors.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.flipcash.app.onramp
22

33
sealed class DeeplinkOnRampError(
4-
open val code: Int = -99,
4+
open val code: Long = -99,
55
override val message: String?,
66
override val cause: Throwable? = null,
77
) : Throwable(message) {
@@ -16,7 +16,7 @@ sealed class DeeplinkOnRampError(
1616
DeeplinkOnRampError(message = message)
1717

1818
class FailedToSendTransaction(
19-
override val code: Int = -99,
19+
override val code: Long = -99,
2020
override val message: String?,
2121
override val cause: Throwable? = null
2222
) : DeeplinkOnRampError(code = code, message = message, cause = cause)
@@ -37,7 +37,7 @@ sealed class DeeplinkOnRampError(
3737
): DeeplinkOnRampError(code = error.code, message = message)
3838
}
3939

40-
enum class DeeplinkError(val code: Int) {
40+
enum class DeeplinkError(val code: Long) {
4141
Unknown(-999),
4242
Disconnected(4900),
4343
Unauthorized(4100),
@@ -49,8 +49,8 @@ enum class DeeplinkError(val code: Int) {
4949
InternalError(-32603);
5050

5151
companion object Companion {
52-
fun fromCode(code: Int?) = entries.firstOrNull { it.code == code } ?: Unknown
53-
fun fromCode(code: String?) = fromCode(code?.toIntOrNull())
52+
fun fromCode(code: Long?) = entries.firstOrNull { it.code == code } ?: Unknown
53+
fun fromCode(code: String?) = fromCode(code?.toLongOrNull())
5454
}
5555
}
5656

apps/flipcash/shared/onramp/deeplinks/src/main/kotlin/com/flipcash/app/onramp/ExternalWalletLocal.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,20 @@ import androidx.compose.runtime.rememberCoroutineScope
77
import cafe.adriel.voyager.navigator.currentOrThrow
88
import com.flipcash.app.core.LocalUserManager
99
import com.flipcash.app.onramp.internal.ExternalWalletDeeplinkState
10+
import com.getcode.opencode.compose.LocalTransactionController
1011
import com.getcode.solana.rpc.RpcConfig
1112

1213
@Composable
1314
fun rememberExternalWalletState(
1415
rpcConfig: RpcConfig
1516
): ExternalWalletDeeplinkState {
1617
val userManager = LocalUserManager.currentOrThrow
18+
val transctionController = LocalTransactionController.currentOrThrow
1719
val scope = rememberCoroutineScope()
1820
return remember(userManager, scope, rpcConfig) {
1921
ExternalWalletDeeplinkState(
2022
userManager,
23+
transctionController,
2124
scope,
2225
rpcConfig.rpcUrl,
2326
rpcConfig.networkDriver

apps/flipcash/shared/onramp/deeplinks/src/main/kotlin/com/flipcash/app/onramp/ExternalWalletOnRampHandler.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,10 @@ fun ExternalWalletOnRampHandler(
183183
ExternalWalletState.CONNECTED -> {
184184
// if amount was provided, send the transaction
185185
if (state.amount != null) {
186-
state.createAndSendTransaction()
186+
when (state.origin) {
187+
is AppRoute.Token.Info -> state.createAndValidateSwapTransaction()
188+
else -> state.createAndValidateDepositTransaction()
189+
}
187190
} else {
188191
trace(
189192
tag = TAG,
@@ -219,7 +222,7 @@ fun ExternalWalletOnRampHandler(
219222
message = "wallet transact uri: $uri",
220223
type = TraceType.Process
221224
)
222-
analytics.amountSelectedForWalletTransfer(state.provider!!, state.amount!!)
225+
analytics.amountSelectedForWalletTransfer(state.provider!!, state.amount!!.underlyingTokenAmount)
223226
uriHandler.openUri(uri.toString())
224227
}
225228

apps/flipcash/shared/onramp/deeplinks/src/main/kotlin/com/flipcash/app/onramp/internal/Deeplinks.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ internal fun buildTransactionDeeplink(state: ExternalWalletDeeplinkState): Uri?
5959
val transaction = state.unsignedTransaction ?: return null
6060
val nonce = LibsodiumRandom.buf(crypto_secretbox_NONCEBYTES).map { it.toByte() }
6161
val payload = mapOf(
62-
"transaction" to transaction.serialize().base58,
62+
"transaction" to transaction.base58,
6363
"session" to state.walletConnection?.session
6464
)
6565

0 commit comments

Comments
 (0)