fix(base): resolve the sats key in price conversions #165

Merged
padreug merged 1 commit from fix/price-conversion-sats-key into dev 2026-09-22 21:06:28 +00:00
Owner

Every fiat-to-sat conversion returned null.

convert() looked up the response by the to key it had passed in, but LNbits does not echo that key back. It always names the satoshi amount sats, plural, whatever the caller asked for. So data["sat"] missed and the function fell through to its null path.

POST {from_: "EUR", to: "sat", amount: 5.50}
  -> {"EUR": 5.5, "sats": 7298, "BTC": 7.298e-05}

Impact

This silently broke the one shipped caller that converts in that direction. PurchaseTicketDialog computes lightningSats via convert(amount, currency, 'sat'), so that value was always null. PriceConversionPreview has a to === 'sat' formatting branch that could never be reached either.

I found this while building fiat invoice support for the wallet, which needs the same conversion for its live preview.

Fix

Key selection moves into pickConverted, which maps sat/sats onto the plural key the server actually uses and keeps the previous fallbacks for other shapes. The reverse direction, sat to fiat, already worked and is unchanged.

Verification

Against the live LNbits on this machine:

conversion old new
EUR to sat (5.50) null 7299 fixed
USD to sat (10) null 11588 fixed
JPY to sat (1000) null 7360 fixed
sat to EUR (7295) 5.4969 5.4969 unchanged

Note that sat to BTC is rejected by the endpoint itself with "Currency 'BTC' not allowed", since BTC is not in the fiat currency list. The API client throws on that, so it never reaches this helper.

vue-tsc --noEmit is clean.

Every fiat-to-sat conversion returned null. `convert()` looked up the response by the `to` key it had passed in, but LNbits does not echo that key back. It always names the satoshi amount `sats`, plural, whatever the caller asked for. So `data["sat"]` missed and the function fell through to its null path. ``` POST {from_: "EUR", to: "sat", amount: 5.50} -> {"EUR": 5.5, "sats": 7298, "BTC": 7.298e-05} ``` ## Impact This silently broke the one shipped caller that converts in that direction. `PurchaseTicketDialog` computes `lightningSats` via `convert(amount, currency, 'sat')`, so that value was always null. `PriceConversionPreview` has a `to === 'sat'` formatting branch that could never be reached either. I found this while building fiat invoice support for the wallet, which needs the same conversion for its live preview. ## Fix Key selection moves into `pickConverted`, which maps `sat`/`sats` onto the plural key the server actually uses and keeps the previous fallbacks for other shapes. The reverse direction, sat to fiat, already worked and is unchanged. ## Verification Against the live LNbits on this machine: | conversion | old | new | | |---|---|---|---| | EUR to sat (5.50) | null | 7299 | fixed | | USD to sat (10) | null | 11588 | fixed | | JPY to sat (1000) | null | 7360 | fixed | | sat to EUR (7295) | 5.4969 | 5.4969 | unchanged | Note that `sat` to `BTC` is rejected by the endpoint itself with "Currency 'BTC' not allowed", since BTC is not in the fiat currency list. The API client throws on that, so it never reaches this helper. `vue-tsc --noEmit` is clean.
Every fiat-to-sat conversion returned null. `convert()` looked up the
response by the `to` key it had passed in, but LNbits does not echo that
key: it always names the satoshi amount "sats" (plural), whatever the
caller asked for. So `data["sat"]` missed and the function fell through
to its null path.

    POST {from_: "EUR", to: "sat", amount: 5.50}
      -> {"EUR": 5.5, "sats": 7298, "BTC": 7.298e-05}

This silently broke the one shipped caller that converts in that
direction: `PurchaseTicketDialog` computes `lightningSats` via
`convert(amount, currency, 'sat')`, so it was always null.
`PriceConversionPreview` has a `to === 'sat'` formatting branch that
could never be reached either.

Key selection moves into `pickConverted`, which maps sat/sats onto the
plural key the server actually uses and keeps the previous fallbacks.
The reverse direction (sat to fiat) already worked and is unchanged.

Verified against the live LNbits:

  EUR -> sat (5.50):  old=null   new=7299     FIXED
  USD -> sat (10):    old=null   new=11588    FIXED
  JPY -> sat (1000):  old=null   new=7360     FIXED
  sat -> EUR (7295):  old=5.4969 new=5.4969   unchanged
padreug deleted branch fix/price-conversion-sats-key 2026-09-22 21:06:28 +00:00
Sign in to join this conversation.
No description provided.