Skip to content

backend: clean swakpit frontend/backend interaction#3961

Open
bznein wants to merge 1 commit intoBitBoxSwiss:staging-swapfrom
bznein:swap-backend-api-cleanup
Open

backend: clean swakpit frontend/backend interaction#3961
bznein wants to merge 1 commit intoBitBoxSwiss:staging-swapfrom
bznein:swap-backend-api-cleanup

Conversation

@bznein
Copy link
Copy Markdown
Collaborator

@bznein bznein commented Mar 30, 2026

Instead of returnign the whole response to the frontend, we only return what is needed to the frontend as QuoteRouteSummary.

We also change the account code type in the backend api, to make it more aligned to what other handlers do.

Before asking for reviews, here is a check list of the most common things you might need to consider:

  • updating the Changelog
  • writing unit tests
  • checking if your changes affect other coins or tokens in unintended ways
  • testing on multiple environments (Qt, Android, ...)
  • having an AI review your changes

Copy link
Copy Markdown
Collaborator

@thisconnect thisconnect left a comment

Choose a reason for hiding this comment

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

frontend LGTM with one small change

Comment thread frontends/web/src/routes/market/swap/swap.tsx Outdated
Instead of returnign the whole response to the frontend, we only return
what is needed to the frontend as QuoteRouteSummary.

We also change the account code type in the backend api, to make it more
aligned to what other handlers do.
@bznein bznein force-pushed the swap-backend-api-cleanup branch from c629742 to 8afa7ae Compare March 30, 2026 13:09
@thisconnect
Copy link
Copy Markdown
Collaborator

@Beerosagos PTAL

return result{
Success: true,
Quote: quoteResponse,
Routes: swapkit.QuoteRouteSummariesFromResponse(quoteResponse),
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

nit: afaik we don't fetch quotes in any other place, so we could make swapkit.NewQuoteFromCoinCode return the object needed by the handler directly, and avoid the second helper

func assetFromCoinCode(coinCode string) (string, bool) {
asset, ok := swapkitAssetByCoinCode[strings.ToLower(strings.TrimSpace(coinCode))]
func assetFromCoinCode(coinCode coinpkg.Code) (string, bool) {
asset, ok := swapkitAssetByCoinCode[strings.ToLower(strings.TrimSpace(string(coinCode)))]
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

can we remove ToLower and TrimSpace?

if request.BuyAccountCode == "" {
return errorResult(swapkit.ErrInvalidRequest, "Missing buyAccountCode.")
}
if request.SellAccountCode == request.BuyAccountCode {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Maybe it would be better to move this check inside the swap logic? Comparing coins instead of accounts would be even better, I guess.

@thisconnect thisconnect mentioned this pull request Apr 8, 2026
5 tasks
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.

3 participants