Skip to content

Commit e6e0405

Browse files
committed
fix(fiat): handle all token balances via Fiat#tokenBalance
allow USDC balances to be returned instead of conditionals throughout Signed-off-by: Brandon McAnsh <[email protected]>
1 parent 593cdb5 commit e6e0405

File tree

4 files changed

+6
-12
lines changed

4 files changed

+6
-12
lines changed

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ internal class WithdrawalViewModel @Inject constructor(
7171
private val resources: ResourceHelper,
7272
private val exchange: Exchange,
7373
private val userManager: UserManager,
74-
balanceController: BalanceController,
7574
transactionController: TransactionController,
7675
clipboardManager: ClipboardManager,
7776
activityFeedCoordinator: ActivityFeedCoordinator,

apps/flipcash/features/withdrawal/src/main/kotlin/com/flipcash/app/withdrawal/internal/confirmation/WithdrawalConfirmationScreen.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,8 @@ private fun WithdrawalConfirmationScreenContent(
140140
token = this,
141141
balance = Fiat.tokenBalance(
142142
state.amountEntryState.selectedAmount.underlyingTokenAmount.quarks,
143-
this
143+
currencyCode = state.amountEntryState.selectedAmount.underlyingTokenAmount.currencyCode,
144+
token = this
144145
)
145146
),
146147
destination = state.destinationState.textFieldState.text.toString(),

services/opencode/src/main/kotlin/com/getcode/opencode/controllers/TokenController.kt

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,7 @@ class TokenController @Inject constructor(
143143
.getOrDefault(emptyList())
144144
.firstOrNull() ?: return@mapNotNull null
145145

146-
val tokenBalance = if (token.address == Mint.usdc) {
147-
Fiat(account.balance)
148-
} else {
149-
Fiat.tokenBalance(account.balance, token)
150-
}
146+
val tokenBalance = Fiat.tokenBalance(account.balance, token = token)
151147

152148
TokenWithBalance(token, tokenBalance)
153149
}
@@ -223,8 +219,7 @@ class TokenController @Inject constructor(
223219
)?.map { (account, token) ->
224220
when {
225221
account == null -> throw IllegalStateException("No account found for token with mint ${token.symbol}")
226-
account.mint == Mint.usdc -> token to Fiat(account.balance)
227-
else -> token to Fiat.tokenBalance(account.balance, token)
222+
else -> token to Fiat.tokenBalance(account.balance, token = token)
228223
}
229224
}?.onSuccess { (token, tokenBalance) ->
230225
mintBalances.update { it + (mint to tokenBalance) }

services/opencode/src/main/kotlin/com/getcode/opencode/model/financial/Fiat.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,12 +156,11 @@ data class Fiat(
156156

157157
fun tokenBalance(
158158
quarks: Long,
159+
currencyCode: CurrencyCode = CurrencyCode.USD,
159160
token: Token
160161
): Fiat {
161162
if (token.address == Mint.usdc) {
162-
throw IllegalArgumentException(
163-
"Cannot create Fiat from USDC Token directly, use the Fiat(quarks: Long, currencyCode: CurrencyCode) constructor instead"
164-
)
163+
return Fiat(quarks, currencyCode)
165164
}
166165

167166
return Fiat(

0 commit comments

Comments
 (0)