Skip to content

Conversation

@dpad85
Copy link
Member

@dpad85 dpad85 commented Oct 6, 2025

Bolt12 offers may specify an amount, and that amount may be in a fiat currency. The wallet should be able to understand that, and convert the amount to btc, using the feerate fetched by the CurrencyManager.

Conversion can be done using the method FiatCurrency.valueOfOrNull(offer.currency), since offer.currency is the standard currency code.

A new method fetchRateForCurrency has been added in CurrencyManager. It immediately fetches the feerate of a given fiat currency and refreshes the cache ; or will return the cached value is the cache is fresh.

Since the conversion is not accurate, the user should be able to change the amount to send, even use an amount below what Phoenix computed. The recipient may then reject the payment if it's too far from what he actually expects for the given fiat amount.

This PR depends on : ACINQ/lightning-kmp#804

Example offers:

1 euro
-----
lno1qgsyxjtl6luzd9t3pr62xr7eemp6awnejusgf6gw45q75vcfqqqqqqqxqdz425sgqyqs5rp3ypjh2un0yphkven9wggwuqun8zz24uwkkyyrjlj7lewgd08jmr9g6tmspmdfnkujzn7zwy43xsp8te5em74wwg0c4ccz0mcpgj0xqgefpvtj7q7mh3jlft208vluddqzqdc8gwx494a57zmp24zuv3c8ydu36jl2hvu5skxk2ugyxmu8ldzdcqpng62kpmcznwkgfmk9443mde6nr8d5x4g9jvl0zxm7ez45xzx6gqwtpag4q749qua5wtn69w8xgy622cc9hcp9mnkq4hveyrnjj96v7crgnmjrzwyjdjw5nustdvwfe7kf6pws33sqxt4plja8th557v6txa0yknvls6ax29mylt8lcmlm3xam8wwnnyc5euf9v9fquqc260fu3lnn0fyf9rxjlq

1234 euros
-----
lno1qgsyxjtl6luzd9t3pr62xr7eemp6awnejusgf6gw45q75vcfqqqqqqqxqdz425sgqgzdyzssxyerxdpqv46hymmnyphkven9wggwuqun8zz24uwkkyyrjlj7lewgd08jmr9g6tmspmdfnkujzn7zwy43xspsetzx8mclv6xxccuut5ep7fvkvxnp9zg5pqwsv2nhd33fjhapysqzqgja0nxwjphl5yu6qrzxky82f64gjdlt5jvnyzr9zu2254q2g78mkqpnkw5dzavwdy68rwfejmz04ed5e56zfxxf82yzqqtukyjmj6dcx9jluh62z6zpz029lxetddqayk4mmz4xyypkxph8s3mnn7x3jece5kvejrhy7qxlnelg7qt6c8tua6tcekmsh5sqxfg2deugn4ycashz95yvfz2nl3094qql2pt9lt0ude9nsvgmsugfenw2xsu43ymrktnfr69s8f97czwtay

Screenshots:

The UI is almost unchanged, except for a label below the amount input mentioning that the invoice is labelled in fiat:

image

Tapping on the "Invoice requests 1 EUR" message, the app displays a modal with some details:

image image

dpad85 added 2 commits October 6, 2025 18:23
Bolt12 offers may specify an amount, and that amount may be in a fiat
currency. The wallet should be able to understand that, and convert the
amount to btc, using the feerate fetched by the CurrencyManager.

A new method has been added in CurrencyManager to fetch the feearate of
a given fiat currency immediately (or use the cached value is cache is
fresh).

Since the conversion is not accurate, the user can change the amount to
send, even use an amount below what Phoenix computed. The recipient may
then reject the payment if it's too far from what it actually expects
for the given fiat amount.
val rates = ratesFlow.value
val fiatRate = rates.firstOrNull { it.fiatCurrency == currency } ?: return null
val now = currentTimestampMillis()
val knownMatch = rates.firstOrNull { it.fiatCurrency == fiatCurrency && (now - it.timestampMillis) < 10.minutes.inWholeMilliseconds }
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@robbiehanson The price is considered fresh enough if it was updated less than 10 minutes ago. Let me know if you want to adjust that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants