Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/flipcash/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ dependencies {
implementation(libs.phantom.connect) {
exclude(group = "com.ionspin.kotlin", module = "multiplatform-crypto-libsodium-bindings-android-debug")
}
implementation(project(":apps:flipcash:shared:payments"))
implementation(project(":apps:flipcash:shared:funding"))
implementation(project(":apps:flipcash:shared:permissions"))
implementation(project(":apps:flipcash:shared:phone"))
implementation(project(":apps:flipcash:shared:shareable"))
Expand Down
2 changes: 1 addition & 1 deletion apps/flipcash/features/balance/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ dependencies {

implementation(project(":apps:flipcash:shared:analytics"))
implementation(project(":apps:flipcash:shared:featureflags"))
implementation(project(":apps:flipcash:shared:payments"))
implementation(project(":apps:flipcash:shared:funding"))
implementation(project(":apps:flipcash:shared:tokens"))
implementation(project(":apps:flipcash:shared:userflags"))
implementation(project(":libs:datetime"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import com.flipcash.app.analytics.FlipcashAnalyticsService
import com.flipcash.app.core.AppRoute
import com.flipcash.app.featureflags.FeatureFlag
import com.flipcash.app.featureflags.FeatureFlagController
import com.flipcash.app.payments.PurchaseMethodController
import com.flipcash.app.funding.PurchaseMethodController
import com.flipcash.app.userflags.UserFlagsCoordinator
import com.flipcash.services.internal.model.thirdparty.OnRampProvider
import com.flipcash.services.user.AuthState
Expand Down
2 changes: 1 addition & 1 deletion apps/flipcash/features/currency-creator/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ dependencies {
implementation(project(":apps:flipcash:shared:featureflags"))
implementation(project(":apps:flipcash:shared:currency-creator"))
implementation(project(":apps:flipcash:shared:onramp:deeplinks"))
implementation(project(":apps:flipcash:shared:payments"))
implementation(project(":apps:flipcash:shared:funding"))
implementation(project(":apps:flipcash:shared:session"))
implementation(project(":apps:flipcash:shared:tokens"))
implementation(project(":apps:flipcash:shared:userflags"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import com.flipcash.app.core.extensions.onResult
import com.flipcash.app.core.tokens.CurrencyCreatorDraft
import com.flipcash.app.core.tokens.CurrencyCreatorStep
import com.flipcash.app.currencycreator.CurrencyCreatorCoordinator
import com.flipcash.app.payments.PurchaseMethodController
import com.flipcash.app.funding.PurchaseMethodController
import com.flipcash.app.tokens.BalancePoller
import com.flipcash.app.tokens.TokenCoordinator
import com.flipcash.app.userflags.UserFlagsCoordinator
Expand Down
2 changes: 1 addition & 1 deletion apps/flipcash/features/direct-send/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ dependencies {
implementation(project(":libs:messaging"))
implementation(project(":libs:permissions:bindings"))
implementation(project(":apps:flipcash:shared:featureflags"))
implementation(project(":apps:flipcash:shared:payments"))
implementation(project(":apps:flipcash:shared:funding"))
implementation(project(":apps:flipcash:shared:permissions"))
implementation(project(":apps:flipcash:shared:chat"))
implementation(project(":apps:flipcash:shared:chat-ui"))
Expand Down
2 changes: 1 addition & 1 deletion apps/flipcash/features/menu/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ dependencies {
implementation(project(":apps:flipcash:shared:authentication"))
implementation(project(":apps:flipcash:shared:featureflags"))
implementation(project(":apps:flipcash:shared:menu"))
implementation(project(":apps:flipcash:shared:payments"))
implementation(project(":apps:flipcash:shared:funding"))
implementation(project(":apps:flipcash:shared:userflags"))

implementation(project(":libs:datetime"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import com.flipcash.app.featureflags.FeatureFlag
import com.flipcash.app.core.toast.SystemToastController
import com.flipcash.app.featureflags.FeatureFlagController
import com.flipcash.app.menu.MenuItem
import com.flipcash.app.payments.PurchaseMethodController
import com.flipcash.app.funding.PurchaseMethodController
import com.flipcash.app.updates.ReleaseStage
import com.flipcash.app.updates.ReleaseStageProvider
import com.flipcash.app.userflags.UserFlagsCoordinator
Expand Down
2 changes: 1 addition & 1 deletion apps/flipcash/features/messenger/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ dependencies {
implementation(project(":apps:flipcash:shared:amount-entry"))
implementation(project(":apps:flipcash:shared:contacts"))
implementation(project(":apps:flipcash:shared:featureflags"))
implementation(project(":apps:flipcash:shared:payments"))
implementation(project(":apps:flipcash:shared:funding"))
implementation(project(":apps:flipcash:shared:tokens"))
implementation(project(":libs:vibrator:bindings"))
implementation(project(":libs:messaging"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import com.flipcash.app.featureflags.FeatureFlagController
import com.flipcash.shared.chat.models.ChatListItem
import com.flipcash.shared.chat.models.ReceiptStatus
import com.flipcash.shared.chat.models.SeparatorConfig
import com.flipcash.app.payments.PurchaseMethodController
import com.flipcash.app.funding.PurchaseMethodController
import com.flipcash.app.tokens.TokenCoordinator
import com.flipcash.features.messenger.R
import com.flipcash.services.models.buildDmPaymentMetadata
Expand Down
16 changes: 16 additions & 0 deletions apps/flipcash/shared/funding/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
plugins {
alias(libs.plugins.flipcash.android.feature)
}

android {
namespace = "${Gradle.flipcashNamespace}.shared.funding"
}

dependencies {
implementation(project(":apps:flipcash:shared:analytics"))
implementation(project(":apps:flipcash:shared:featureflags"))
implementation(project(":apps:flipcash:shared:tokens:core"))
implementation(project(":apps:flipcash:shared:userflags"))
implementation(project(":libs:messaging"))
implementation(project(":services:flipcash"))
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.flipcash.app.payments
package com.flipcash.app.funding

import com.getcode.opencode.model.financial.Fiat
import com.getcode.opencode.model.financial.LocalFiat
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.flipcash.app.payments
package com.flipcash.app.funding

import com.flipcash.app.core.AppRoute
import kotlinx.coroutines.flow.Flow
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.flipcash.app.payments
package com.flipcash.app.funding

import com.flipcash.services.internal.model.thirdparty.OnRampProvider
import com.getcode.opencode.model.financial.LocalFiat
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.flipcash.app.payments.internal
package com.flipcash.app.funding.internal

import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.Box
Expand All @@ -19,11 +19,11 @@ import androidx.compose.ui.unit.TextUnit
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.flipcash.app.core.money.formatted
import com.flipcash.app.payments.PaymentAction
import com.flipcash.app.payments.PurchaseMethod
import com.flipcash.app.payments.PurchaseMethodMetadata
import com.flipcash.app.payments.PurchaseMethodState
import com.flipcash.shared.payments.R
import com.flipcash.app.funding.PaymentAction
import com.flipcash.app.funding.PurchaseMethod
import com.flipcash.app.funding.PurchaseMethodMetadata
import com.flipcash.app.funding.PurchaseMethodState
import com.flipcash.shared.funding.R
import com.getcode.manager.BottomBarAction
import com.getcode.manager.BottomBarManager
import com.getcode.opencode.model.financial.Fiat
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.flipcash.app.payments.internal
package com.flipcash.app.funding.internal

import com.flipcash.app.analytics.Analytics
import com.flipcash.app.analytics.FlipcashAnalyticsService
Expand All @@ -7,19 +7,19 @@ import com.flipcash.app.core.tokens.FundingSource
import com.flipcash.app.core.tokens.SwapPurpose
import com.flipcash.app.featureflags.FeatureFlag
import com.flipcash.app.featureflags.FeatureFlagController
import com.flipcash.app.payments.PaymentAction
import com.flipcash.app.payments.PurchaseMethod
import com.flipcash.app.payments.PurchaseMethodController
import com.flipcash.app.payments.PurchaseMethodMetadata
import com.flipcash.app.payments.PurchaseMethodSelection
import com.flipcash.app.payments.PurchaseMethodState
import com.flipcash.app.payments.PurchasePurpose
import com.flipcash.app.funding.PaymentAction
import com.flipcash.app.funding.PurchaseMethod
import com.flipcash.app.funding.PurchaseMethodController
import com.flipcash.app.funding.PurchaseMethodMetadata
import com.flipcash.app.funding.PurchaseMethodSelection
import com.flipcash.app.funding.PurchaseMethodState
import com.flipcash.app.funding.PurchasePurpose
import com.flipcash.app.tokens.core.ReservesBalanceProvider
import com.flipcash.app.userflags.UserFlagsCoordinator
import com.flipcash.services.internal.model.thirdparty.OnRampProvider
import com.flipcash.services.internal.model.thirdparty.OnRampType
import com.flipcash.services.user.UserManager
import com.flipcash.shared.payments.R
import com.flipcash.shared.funding.R
import com.getcode.manager.BottomBarManager
import com.getcode.opencode.exchange.Exchange
import com.getcode.opencode.model.financial.LocalFiat
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.flipcash.app.payments
package com.flipcash.app.funding

import kotlin.test.Test
import kotlin.test.assertEquals
Expand Down
14 changes: 9 additions & 5 deletions apps/flipcash/shared/payments/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@ android {
}

dependencies {
implementation(project(":apps:flipcash:shared:analytics"))
implementation(project(":apps:flipcash:shared:featureflags"))
implementation(project(":apps:flipcash:shared:tokens:core"))
implementation(project(":apps:flipcash:shared:userflags"))
implementation(project(":libs:messaging"))
testImplementation(kotlin("test"))
testImplementation(libs.bundles.unit.testing)
testImplementation(libs.robolectric)

implementation(project(":apps:flipcash:core"))
implementation(project(":apps:flipcash:shared:chat"))
implementation(project(":apps:flipcash:shared:contacts"))
implementation(project(":apps:flipcash:shared:tokens"))
implementation(project(":services:flipcash"))
implementation(project(":services:opencode"))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package com.flipcash.shared.payments

import com.flipcash.app.contacts.ContactCoordinator
import com.flipcash.app.core.contacts.DeviceContact
import com.flipcash.app.tokens.TokenCoordinator
import com.flipcash.services.models.buildDmPaymentMetadata
import com.flipcash.services.models.chat.ChatId
import com.flipcash.shared.chat.ChatCoordinator
import com.getcode.opencode.controllers.TransactionController
import com.getcode.opencode.exchange.VerifiedFiat
import com.getcode.opencode.model.accounts.AccountCluster
import com.getcode.opencode.model.financial.Token
import javax.inject.Inject
import javax.inject.Singleton

/**
* Sends cash within a contact (phone-number) DM: resolves the contact's on-chain owner, attaches
* contact-DM app metadata (source + destination phone number), transfers, debits the local
* balance, and syncs the chat feed.
*
* The phone-based counterpart to [TipPaymentDelegate] (keyed by a user id, attaching tip-DM
* metadata). Performs no UI or navigation — the caller owns send state and error presentation.
*/
@Singleton
class ContactPaymentDelegate @Inject constructor(
private val contactCoordinator: ContactCoordinator,
private val transactionController: TransactionController,
private val tokenCoordinator: TokenCoordinator,
private val chatCoordinator: ChatCoordinator,
) {
suspend fun send(
contact: DeviceContact,
chatId: ChatId?,
verifiedFiat: VerifiedFiat,
token: Token,
source: AccountCluster,
): Result<Unit> {
val appMetadataBytes = buildDmPaymentMetadata(
chatId = chatId,
sourcePhone = contactCoordinator.selfPhone,
destinationPhone = contact.e164,
)

return contactCoordinator.resolve(contact.e164)
.mapCatching { destination ->
transactionController.directTransfer(
amount = verifiedFiat,
token = token,
source = source,
destinationOwner = destination,
appMetadata = appMetadataBytes,
).getOrThrow()
tokenCoordinator.subtract(token, verifiedFiat.localFiat)
if (chatId != null) {
chatCoordinator.loadMessages(chatId)
} else {
// New conversation — server just created the DM chat.
// Sync the feed so it appears in the contact list.
chatCoordinator.refreshFeed()
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package com.flipcash.shared.payments

import com.flipcash.app.tokens.TokenCoordinator
import com.flipcash.services.controllers.ResolverController
import com.flipcash.services.models.buildTipDmPaymentMetadata
import com.flipcash.services.models.chat.ChatId
import com.flipcash.shared.chat.ChatCoordinator
import com.getcode.opencode.controllers.TransactionController
import com.getcode.opencode.exchange.VerifiedFiat
import com.getcode.opencode.model.accounts.AccountCluster
import com.getcode.opencode.model.core.ID
import com.getcode.opencode.model.financial.Token
import javax.inject.Inject
import javax.inject.Singleton

/**
* Sends cash within a tip DM: derives the canonical tip chat for [ID], resolves the recipient's
* on-chain owner, attaches tip-DM app metadata, transfers, debits the local balance, and syncs the
* chat feed. Returns the canonical tip [ChatId] (for message reload / navigation), or null if it
* couldn't be derived.
*
* The user-id counterpart to [ContactPaymentDelegate] (keyed by a phone number, attaching
* contact-DM metadata). Shared by the out-of-chat tip flow
* ([com.flipcash.shared.tipping.TippingCoordinator]) and the in-chat send (a tip DM opened in the
* messenger). Performs no UI or navigation — the caller owns send state, error presentation, and
* any post-send navigation.
*/
@Singleton
class TipPaymentDelegate @Inject constructor(
private val resolverController: ResolverController,
private val transactionController: TransactionController,
private val tokenCoordinator: TokenCoordinator,
private val chatCoordinator: ChatCoordinator,
) {
suspend fun send(
userId: ID,
verifiedFiat: VerifiedFiat,
token: Token,
source: AccountCluster,
): Result<ChatId?> {
val canonicalChatId = chatCoordinator.generateChatId(userId = userId).getOrNull()
val appMetadataBytes = buildTipDmPaymentMetadata(chatId = canonicalChatId)

return resolverController.resolve(userId = userId)
.mapCatching { destination ->
transactionController.directTransfer(
amount = verifiedFiat,
token = token,
source = source,
destinationOwner = destination,
appMetadata = appMetadataBytes,
).getOrThrow()
tokenCoordinator.subtract(token, verifiedFiat.localFiat)
if (canonicalChatId != null) {
chatCoordinator.loadMessages(canonicalChatId)
} else {
// New conversation — server just created the DM chat.
// Sync the feed so it appears in the contact list.
chatCoordinator.refreshFeed()
}
canonicalChatId
}
}
}
2 changes: 1 addition & 1 deletion apps/flipcash/shared/session/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ dependencies {
implementation(project(":apps:flipcash:shared:appsettings"))
implementation(project(":apps:flipcash:shared:google-play-billing"))
implementation(project(":apps:flipcash:shared:featureflags"))
implementation(project(":apps:flipcash:shared:payments"))
implementation(project(":apps:flipcash:shared:funding"))
implementation(project(":apps:flipcash:shared:shareable"))
implementation(project(":apps:flipcash:shared:tipping"))
implementation(project(":apps:flipcash:shared:tokens"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import com.flipcash.app.analytics.FlipcashAnalyticsService
import com.flipcash.app.core.AppRoute
import com.flipcash.app.featureflags.FeatureFlag
import com.flipcash.app.featureflags.FeatureFlagController
import com.flipcash.app.payments.PurchaseMethodController
import com.flipcash.app.funding.PurchaseMethodController
import com.flipcash.app.session.DepositOperations
import com.flipcash.app.session.internal.SessionStateHolder
import com.flipcash.app.tokens.UsdcDepositSweep
Expand Down
1 change: 1 addition & 0 deletions apps/flipcash/shared/tipping/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ dependencies {
implementation(project(":apps:flipcash:shared:analytics"))
implementation(project(":apps:flipcash:shared:chat"))
implementation(project(":apps:flipcash:shared:payments"))
implementation(project(":apps:flipcash:shared:funding"))
implementation(project(":apps:flipcash:shared:region-selection:core"))
implementation(project(":apps:flipcash:shared:tokens"))
implementation(project(":apps:flipcash:shared:userflags"))
Expand Down
Loading
Loading