Skip to content

Commit 4a1cadf

Browse files
committed
feat: implement persistence for token and valuations
Signed-off-by: Brandon McAnsh <git@bmcreations.dev>
1 parent a001845 commit 4a1cadf

48 files changed

Lines changed: 1838 additions & 750 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

apps/flipcash/core/src/main/kotlin/com/flipcash/app/core/internal/bill/BillController.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class BillController @Inject constructor(
3838
token: Token,
3939
owner: AccountCluster,
4040
present: (List<Byte>) -> Unit,
41-
onGrabbed: () -> Unit,
41+
onGrabbed: suspend (LocalFiat) -> Unit,
4242
onTimeout: () -> Unit,
4343
onError: (Throwable) -> Unit,
4444
) = transactionManager.awaitGrabFromRecipient(token, amount, owner, present, onGrabbed, onTimeout, onError)
@@ -48,7 +48,7 @@ class BillController @Inject constructor(
4848
fun attemptGrab(
4949
owner: AccountCluster,
5050
payload: OpenCodePayload,
51-
onGrabbed: (Token, LocalFiat) -> Unit,
51+
onGrabbed: suspend (Token, LocalFiat) -> Unit,
5252
onError: (Throwable) -> Unit,
5353
) = transactionManager.attemptGrabFromSender(owner, payload, onGrabbed, onError)
5454

@@ -57,15 +57,15 @@ class BillController @Inject constructor(
5757
amount: LocalFiat,
5858
token: Token,
5959
owner: AccountCluster,
60-
onFunded: (LocalFiat) -> Unit,
60+
onFunded: suspend (LocalFiat) -> Unit,
6161
onError: (Throwable) -> Unit,
6262
) = transactionManager.fundGiftCard(giftCard, amount, owner, token, onFunded, onError)
6363

6464
fun receiveGiftCard(
6565
entropy: String,
6666
owner: AccountCluster,
6767
claimIfOwned: Boolean,
68-
onReceived: (Token, LocalFiat) -> Unit,
68+
onReceived: suspend (Token, LocalFiat) -> Unit,
6969
onError: (Throwable) -> Unit,
7070
) = transactionManager.receiveGiftCard(owner, entropy, claimIfOwned, onReceived, onError)
7171
}

apps/flipcash/features/cash/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ dependencies {
5656
implementation(project(":apps:flipcash:core"))
5757
implementation(project(":apps:flipcash:shared:onramp:common"))
5858
implementation(project(":apps:flipcash:shared:session"))
59+
implementation(project(":apps:flipcash:shared:tokens"))
5960
implementation(project(":libs:datetime"))
6061
implementation(project(":libs:logging"))
6162
implementation(project(":libs:messaging"))

apps/flipcash/features/cash/src/main/kotlin/com/flipcash/app/cash/internal/CashScreenViewModel.kt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import com.flipcash.app.core.ui.CurrencyHolder
77
import com.flipcash.app.onramp.ConfirmationEvent
88
import com.flipcash.app.onramp.OnRampAmount
99
import com.flipcash.app.onramp.OnRampAmountController
10+
import com.flipcash.app.tokens.TokenCoordinator
1011
import com.flipcash.features.cash.R
1112
import com.flipcash.services.analytics.AnalyticsEvent
1213
import com.flipcash.services.analytics.FlipcashAnalyticsService
@@ -52,7 +53,7 @@ import kotlin.math.min
5253
internal class CashScreenViewModel @Inject constructor(
5354
private val resources: ResourceHelper,
5455
private val exchange: Exchange,
55-
tokenController: TokenController,
56+
tokenCoordinator: TokenCoordinator,
5657
transactionController: TransactionController,
5758
onrampController: OnRampAmountController,
5859
analytics: FlipcashAnalyticsService,
@@ -187,7 +188,7 @@ internal class CashScreenViewModel @Inject constructor(
187188
init {
188189
numberInputHelper.reset()
189190

190-
tokenController.observeSelectedTokenMint()
191+
tokenCoordinator.observeSelectedTokenMint()
191192
.distinctUntilChanged()
192193
.onEach { dispatchEvent(Event.OnTokenSelected(it)) }
193194
.launchIn(viewModelScope)
@@ -196,8 +197,8 @@ internal class CashScreenViewModel @Inject constructor(
196197
.mapNotNull { it.selectedTokenAddress }
197198
.flatMapLatest { tokenAddress ->
198199
combine(
199-
tokenController.tokens,
200-
tokenController.balanceForToken(tokenAddress),
200+
tokenCoordinator.tokens,
201+
tokenCoordinator.balanceForToken(tokenAddress),
201202
exchange.observeEntryRate(),
202203
) { tokens, balance, rate ->
203204
val token = tokens.find { it.address == tokenAddress } ?: return@combine null

apps/flipcash/features/transactions/src/main/kotlin/com/flipcash/app/transactions/internal/TransactionHistoryViewModel.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import com.flipcash.app.core.feed.MessageMetadata
99
import com.flipcash.app.core.money.formatted
1010
import com.flipcash.app.featureflags.FeatureFlag
1111
import com.flipcash.app.featureflags.FeatureFlagController
12+
import com.flipcash.app.tokens.TokenCoordinator
1213
import com.flipcash.features.transactions.R
1314
import com.flipcash.services.user.UserManager
1415
import com.getcode.manager.BottomBarAction
@@ -32,7 +33,7 @@ import javax.inject.Inject
3233

3334
@HiltViewModel
3435
class TransactionHistoryViewModel @Inject constructor(
35-
tokenController: TokenController,
36+
tokenCoordinator: TokenCoordinator,
3637
feedCoordinator: ActivityFeedCoordinator,
3738
transactionController: TransactionController,
3839
featureFlags: FeatureFlagController,
@@ -124,7 +125,7 @@ class TransactionHistoryViewModel @Inject constructor(
124125
onSuccess = {
125126
viewModelScope.launch {
126127
feedCoordinator.checkPendingMessagesForUpdates()
127-
tokenController.update()
128+
tokenCoordinator.update()
128129
}
129130
}
130131
).launchIn(viewModelScope)

apps/flipcash/features/withdrawal/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ dependencies {
5252

5353
implementation(project(":apps:flipcash:core"))
5454
implementation(project(":apps:flipcash:shared:activityfeed"))
55+
implementation(project(":apps:flipcash:shared:tokens"))
5556
implementation(project(":libs:logging"))
5657
implementation(project(":libs:messaging"))
5758

apps/flipcash/features/withdrawal/src/main/kotlin/com/flipcash/app/withdrawal/WithdrawalViewModel.kt

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ import androidx.lifecycle.viewModelScope
88
import com.flipcash.app.activityfeed.ActivityFeedCoordinator
99
import com.flipcash.app.core.extensions.onResult
1010
import com.flipcash.app.core.ui.CurrencyHolder
11+
import com.flipcash.app.tokens.TokenCoordinator
1112
import com.flipcash.features.withdrawal.R
1213
import com.flipcash.services.analytics.AnalyticsEvent
1314
import com.flipcash.services.analytics.FlipcashAnalyticsService
1415
import com.flipcash.services.user.UserManager
1516
import com.getcode.manager.BottomBarAction
1617
import com.getcode.manager.BottomBarManager
17-
import com.getcode.opencode.controllers.TokenController
1818
import com.getcode.opencode.controllers.TransactionController
1919
import com.getcode.opencode.exchange.Exchange
2020
import com.getcode.opencode.model.financial.Currency
@@ -34,7 +34,6 @@ import com.getcode.vendor.Base58
3434
import com.getcode.view.BaseViewModel2
3535
import com.getcode.view.LoadingSuccessState
3636
import dagger.hilt.android.lifecycle.HiltViewModel
37-
import kotlinx.coroutines.Dispatchers
3837
import kotlinx.coroutines.coroutineScope
3938
import kotlinx.coroutines.delay
4039
import kotlinx.coroutines.flow.combine
@@ -73,7 +72,7 @@ internal class WithdrawalViewModel @Inject constructor(
7372
clipboardManager: ClipboardManager,
7473
activityFeedCoordinator: ActivityFeedCoordinator,
7574
analytics: FlipcashAnalyticsService,
76-
tokenController: TokenController,
75+
tokenCoordinator: TokenCoordinator,
7776
) : BaseViewModel2<WithdrawalViewModel.State, WithdrawalViewModel.Event>(
7877
initialState = State(),
7978
updateStateForEvent = updateStateForEvent
@@ -181,8 +180,8 @@ internal class WithdrawalViewModel @Inject constructor(
181180
.mapNotNull { it.selectedTokenAddress }
182181
.flatMapLatest { tokenAddress ->
183182
combine(
184-
tokenController.tokens,
185-
tokenController.balanceForToken(tokenAddress),
183+
tokenCoordinator.tokens,
184+
tokenCoordinator.balanceForToken(tokenAddress),
186185
) { tokens, balance ->
187186
val token = tokens.find { it.address == tokenAddress } ?: return@combine null
188187
TokenWithBalance(

apps/flipcash/shared/activityfeed/src/main/kotlin/com/flipcash/app/activityfeed/ActivityFeedCoordinator.kt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import com.flipcash.services.models.ActivityFeedType
1616
import com.flipcash.services.models.NotificationState
1717
import com.flipcash.services.models.QueryOptions
1818
import com.flipcash.services.user.UserManager
19-
import com.getcode.opencode.controllers.TokenController
19+
import com.getcode.opencode.providers.TokenMetadataProvider
2020
import com.getcode.solana.keys.Mint
2121
import com.getcode.utils.TraceType
2222
import com.getcode.utils.trace
@@ -28,15 +28,14 @@ import kotlinx.coroutines.flow.map
2828
import kotlinx.coroutines.flow.mapNotNull
2929
import javax.inject.Inject
3030
import javax.inject.Singleton
31-
import kotlin.math.min
3231

3332
@Singleton
3433
class ActivityFeedCoordinator @Inject constructor(
3534
private val activityFeedController: ActivityFeedController,
3635
private val dataSource: MessageDataSource,
3736
private val mapper: MessageEntityToFeedMessageMapper,
3837
private val userManager: UserManager,
39-
private val tokenController: TokenController,
38+
private val tokenProvider: TokenMetadataProvider,
4039
) {
4140
private val pagingConfig = PagingConfig(pageSize = 20)
4241

@@ -63,7 +62,7 @@ class ActivityFeedCoordinator @Inject constructor(
6362
page.filter { message ->
6463
message.amount?.mint == mint
6564
}.map { msg ->
66-
val result = msg.amount?.mint?.let { tokenController.getTokenMetadata(it) }?.getOrNull()
65+
val result = msg.amount?.mint?.let { tokenProvider.getTokenMetadata(it) }?.getOrNull()
6766
ActivityFeedMessageWithToken(msg, result?.token)
6867
}
6968
}

apps/flipcash/shared/authentication/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,6 @@ dependencies {
5353
implementation(project(":apps:flipcash:shared:appsettings"))
5454
implementation(project(":apps:flipcash:shared:persistence:provider"))
5555
implementation(project(":apps:flipcash:shared:featureflags"))
56+
implementation(project(":apps:flipcash:shared:tokens"))
5657
implementation(project(":services:flipcash"))
5758
}

apps/flipcash/shared/authentication/src/main/kotlin/com/flipcash/app/auth/AuthManager.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import com.flipcash.app.auth.internal.credentials.PassphraseCredentialManager
88
import com.flipcash.app.auth.internal.extensions.token
99
import com.flipcash.app.featureflags.FeatureFlagController
1010
import com.flipcash.app.persistence.PersistenceProvider
11+
import com.flipcash.app.tokens.TokenCoordinator
1112
import com.flipcash.services.controllers.AccountController
1213
import com.flipcash.services.controllers.PushController
1314
import com.flipcash.services.user.AuthState
@@ -34,7 +35,7 @@ class AuthManager @Inject constructor(
3435
private val notificationManager: NotificationManagerCompat,
3536
private val accountController: AccountController,
3637
private val pushController: PushController,
37-
private val tokenController: TokenController,
38+
private val tokenCoordinator: TokenCoordinator,
3839
private val persistence: PersistenceProvider,
3940
private val featureFlagController: FeatureFlagController,
4041
private val appSettings: AppSettingsCoordinator,
@@ -195,7 +196,7 @@ class AuthManager @Inject constructor(
195196
pushController.deleteTokens()
196197
notificationManager.cancelAll()
197198
userManager.clear()
198-
tokenController.reset()
199+
tokenCoordinator.reset()
199200
persistence.close()
200201
featureFlagController.reset()
201202
appSettings.reset()

apps/flipcash/shared/notifications/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ dependencies {
4444

4545
implementation(project(":apps:flipcash:core"))
4646
implementation(project(":apps:flipcash:shared:authentication"))
47+
implementation(project(":apps:flipcash:shared:tokens"))
4748
implementation(project(":services:flipcash"))
4849

4950
implementation(project(":libs:logging"))

0 commit comments

Comments
 (0)