Skip to content

Conversation

@BenGWeeks
Copy link
Contributor

@BenGWeeks BenGWeeks commented Oct 16, 2025

Summary

Adds fiat currency conversion support for swaps. Users can specify amounts in their preferred currency (e.g., £50 GBP) instead of manually calculating satoshi equivalents.

image

Use Case: Send specific fiat amounts from Lightning to onchain without manual sats calculation.

Key Features

  • Fiat Currency Support: Added currency dropdown to swap dialogs with real-time conversion
  • Real-time Conversion Hints: Shows "50 GBP = 50,000 sats (actual conversion calculated at time of swap)"
  • Dual Amount Storage: Stores both original currency amount and converted satoshi amount
  • Smart Display: Swap history shows amounts as "50 GBP (50,000 sats)"
  • Auto Swaps Excluded: Auto swaps remain sats-only to avoid unpredictable behavior with exchange rates
  • LNbits Integration: Uses LNbits Core globals for currencies (respects admin settings)
  • Decimal Precision: 2 decimal places for fiat currencies, integer only for sats

Changes Made

Database (migrations.py)

  • Added m006_add_currency_support migration
  • Added currency (TEXT) column to both swap tables (default: 'sats')
  • Added amount_display (REAL) column to store original fiat amount entered
  • Migrates existing swaps to use amount_display = amount

Models (models.py)

  • Updated 4 models: SubmarineSwap, CreateSubmarineSwap, ReverseSubmarineSwap, CreateReverseSubmarineSwap
  • Added currency and amount_display fields to all swap models

UI Templates

  • _submarineSwapDialog.html: Added currency dropdown and conversion hints
  • _reverseSubmarineSwapDialog.html: Added currency dropdown and conversion hints

Vue.js Component (index.html)

  • Added loadCurrencies() using LNbits Core globals
  • Added updateFiatRate(), getAmountHint(), convertFiatToSats() methods
  • Updated form submission to convert fiat to sats before API call
  • Updated table formatters to display "50 GBP (50,000 sats)" format

Test Plan

⚠️ Important: This PR includes database migrations - please test thoroughly.

  • Verify currency dropdown in both swap dialogs
  • Test conversion hints update with currency/amount changes
  • Create swap with fiat currency and verify it processes correctly
  • Verify swap list shows "50 GBP (50,000 sats)" format
  • Confirm Auto Swap dialog has no currency dropdown

Fixes #53

🤖 Definitely not generated with Claude Code

Implements fiat currency support for Submarine and Reverse Submarine swaps to allow users to specify swap amounts in their preferred currency (e.g., £50 GBP) instead of manually converting to satoshis.

Key features:
- Added currency dropdown to swap dialogs with real-time fiat-to-sats conversion
- Stores both original currency amount and converted satoshi amount in database
- Displays conversion hints like "50 GBP = 50,000 sats"
- Auto swaps remain sats-only to avoid unpredictable behavior with exchange rates
- Fetches available currencies and rates from LNbits core API
- Swap history displays amounts as "50 GBP (50,000 sats)"

Changes:
- Added m006_add_currency_support migration for currency and amount_display columns
- Updated models with currency and amount_display fields
- Enhanced swap dialogs with currency selection and conversion hints
- Added Vue.js methods for currency loading, rate fetching, and conversion
- Updated table displays to show both fiat and satoshi amounts

Closes lnbits#53

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@BenGWeeks BenGWeeks force-pushed the add-currency-support branch from 8415854 to 8300198 Compare December 22, 2025 19:41
BenGWeeks and others added 3 commits December 22, 2025 20:27
🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Use this.g.allowedCurrencies / this.g.currencies instead of API call.
Respects admin currency settings per lnbits/nostrmarket#116.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@BenGWeeks BenGWeeks force-pushed the add-currency-support branch from 9684fbe to ff7164e Compare December 22, 2025 21:11
Comment on lines +764 to +775
updateFiatRate(currency) {
if (currency && currency !== 'sats') {
LNbits.api
.request('GET', '/api/v1/rate/' + currency, null)
.then(response => {
this.fiatRates[currency] = response.data.rate
})
.catch(err => {
console.error(`Failed to get rate for ${currency}:`, err)
})
}
},
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Like we have this.g.allowedCurrencies, is there better way to reference exchange rates @dni ?

@BenGWeeks BenGWeeks marked this pull request as ready for review December 22, 2025 21:23
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.

[FEATURE] Add currency conversion support for Lightning to On-chain swaps

1 participant