fix(base): resolve the sats key in price conversions #165
No reviewers
Labels
No labels
app:activities
app:chat
app:chatelet
app:events
app:forum
app:libra
app:market
app:restaurant
app:tasks
app:wallet
app:webapp
bug
enhancement
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
aiolabs/webapp!165
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "fix/price-conversion-sats-key"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Every fiat-to-sat conversion returned null.
convert()looked up the response by thetokey it had passed in, but LNbits does not echo that key back. It always names the satoshi amountsats, plural, whatever the caller asked for. Sodata["sat"]missed and the function fell through to its null path.Impact
This silently broke the one shipped caller that converts in that direction.
PurchaseTicketDialogcomputeslightningSatsviaconvert(amount, currency, 'sat'), so that value was always null.PriceConversionPreviewhas ato === '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 mapssat/satsonto 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:
Note that
sattoBTCis 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 --noEmitis clean.satskey in price conversions 45710447e1Every 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