Skip to content

Commit eb520d3

Browse files
committed
fix(ocp): correct intent and LocalFiat generation for non USD currencies
Signed-off-by: Brandon McAnsh <git@bmcreations.dev>
1 parent 2d84b98 commit eb520d3

5 files changed

Lines changed: 18 additions & 19 deletions

File tree

apps/flipcash/features/give/src/main/kotlin/com/flipcash/app/give/internal/GiveScreenViewModel.kt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,14 @@ internal class GiveScreenViewModel @Inject constructor(
228228
exchange.fetchRatesIfNeeded()
229229
}
230230

231-
val amountFiat = data.amountData.amount.let { LocalFiat(it, rate) }
231+
val localizedAmount = Fiat(data.amountData.amount, rate.currency)
232+
233+
val amountFiat = LocalFiat(
234+
usdc = localizedAmount.convertingTo(exchange.rateToUsd(rate.currency)!!),
235+
converted = localizedAmount,
236+
rate = rate,
237+
)
238+
232239
val bill = Bill.Cash(amount = amountFiat)
233240
dispatchEvent(Event.UpdateLoadingState(loading = false, success = true))
234241
dispatchEvent(Event.PresentBill(bill))

apps/flipcash/features/send/src/main/kotlin/com/flipcash/app/send/internal/SendScreenViewModel.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,12 @@ internal class SendScreenViewModel @Inject constructor(
228228
exchange.fetchRatesIfNeeded()
229229
}
230230

231-
val amountFiat = data.amountData.amount.let { LocalFiat(it, rate) }
231+
val localizedAmount = Fiat(data.amountData.amount, rate.currency)
232+
val amountFiat = LocalFiat(
233+
usdc = localizedAmount.convertingTo(exchange.rateToUsd(rate.currency)!!),
234+
converted = localizedAmount,
235+
rate = rate,
236+
)
232237
val bill = Bill.Cash(amount = amountFiat, kind = Bill.Kind.remote)
233238
dispatchEvent(Event.UpdateLoadingState(loading = false, success = true))
234239
dispatchEvent(Event.PresentBill(bill))

services/opencode/src/main/kotlin/com/getcode/opencode/internal/network/api/intents/IntentRemoteSend.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,14 @@ internal class IntentRemoteSend(
4545

4646
// 2. Transfer all funds from primary account to the created gift card
4747
val transferToGiftCardAccount = ActionPublicTransfer.newInstance(
48-
amount = amount.converted,
48+
amount = amount.usdc,
4949
sourceCluster = sourceCluster,
5050
destination = openGiftCardAccount.owner.vaultPublicKey
5151
)
5252

5353
// 3. Allow auto-returning back to the primary if not collected
5454
val withdrawToDestination = ActionPublicWithdraw.newInstance(
55-
amount = amount.converted,
55+
amount = amount.usdc,
5656
sourceCluster = giftCard.cluster,
5757
destination = sourceCluster.vaultPublicKey,
5858
canAutoReturn = true

services/opencode/src/main/kotlin/com/getcode/opencode/internal/network/extensions/LocalToProtobuf.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,8 @@ internal fun Message.asProtobufMessage(): MessagingService.Message {
210210

211211
internal fun LocalFiat.asExchangeData(): TransactionService.ExchangeData {
212212
return TransactionService.ExchangeData.newBuilder()
213-
.setQuarks(converted.quarks.toLong())
214-
.setCurrency(rate.currency.name.lowercase())
213+
.setQuarks(usdc.quarks.toLong())
214+
.setCurrency(converted.currencyCode.name.lowercase())
215215
.setExchangeRate(rate.fx)
216216
.setNativeAmount(converted.doubleValue)
217217
.build()

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

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,6 @@ data class LocalFiat(
99
val converted: Fiat,
1010
val rate: Rate
1111
) {
12-
// Constructor from string amount
13-
constructor(value: String, rate: Rate) : this(
14-
usdc = Fiat(value, CurrencyCode.USD),
15-
converted = Fiat(value, rate.currency),
16-
rate = rate
17-
)
18-
1912
@Throws(Exception::class)
2013
constructor(exchangeData: ExchangeData.WithRate): this(
2114
usdc = Fiat(exchangeData.quarks.toULong(), CurrencyCode.USD),
@@ -29,12 +22,6 @@ data class LocalFiat(
2922
),
3023
)
3124

32-
// Replace rate
33-
fun replacing(rate: Rate): LocalFiat = copy(
34-
converted = Fiat(usdc.doubleValue, rate.currency),
35-
rate = rate
36-
)
37-
3825
companion object {
3926
val Zero = LocalFiat(
4027
usdc = Fiat(0),

0 commit comments

Comments
 (0)