Skip to content

frontend: enable inactive swap destination accounts#3926

Merged
bznein merged 1 commit intoBitBoxSwiss:staging-swapfrom
bznein:frontend/swap-inactive-destination-accounts
Apr 2, 2026
Merged

frontend: enable inactive swap destination accounts#3926
bznein merged 1 commit intoBitBoxSwiss:staging-swapfrom
bznein:frontend/swap-inactive-destination-accounts

Conversation

@bznein
Copy link
Copy Markdown
Collaborator

@bznein bznein commented Mar 10, 2026

This PR enables inactive account on the "buy asset" dropdown menu. If an inactive account is selected, the account is set to active after pressing "swap" -this will change in the future as we integrate proper swapping, and it will be put at the latest possible step-.

Selecting an ERC20 token also enables the parent ETH account, if not active

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

@bznein bznein requested a review from thisconnect March 10, 2026 15:28
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.

In the future when looking at specific lines of the code base it helps a lot when there is always a commit message with reason "Why this changed" so the purpose is clear.

Please always add a "why" in all commit messages.

Can be as short as: "With this the user can swap coins and receive on inactive accounts that were not used before."

Comment thread frontends/web/src/api/account.ts Outdated
Comment thread frontends/web/src/routes/market/swap/swap.tsx Outdated
Comment thread frontends/web/src/routes/account/utils.ts Outdated
@bznein bznein force-pushed the frontend/swap-inactive-destination-accounts branch 4 times, most recently from fd5debf to e5c26e9 Compare March 11, 2026 14:32
@bznein bznein requested a review from thisconnect March 11, 2026 14:34
@bznein
Copy link
Copy Markdown
Collaborator Author

bznein commented Mar 11, 2026

@thisconnect PTAL thanks :)

Comment thread frontends/web/src/routes/market/swap/swap.tsx Outdated
Comment thread frontends/web/src/routes/account/utils.ts Outdated
@bznein bznein force-pushed the frontend/swap-inactive-destination-accounts branch 4 times, most recently from b366b13 to c8d1d47 Compare March 12, 2026 12:31
@bznein bznein force-pushed the frontend/swap-inactive-destination-accounts branch from c8d1d47 to acf8226 Compare March 18, 2026 16:10
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 tested LGTM

Comment thread frontends/web/src/components/groupedaccountselector/groupedaccountselector.tsx Outdated
@bznein bznein force-pushed the frontend/swap-inactive-destination-accounts branch from acf8226 to 3ed2180 Compare March 24, 2026 10:42
@bznein bznein requested a review from thisconnect March 25, 2026 08:57
@bznein bznein force-pushed the frontend/swap-inactive-destination-accounts branch from 3ed2180 to 0b33548 Compare March 25, 2026 11:24
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 partly tested LGTM,

Comment thread frontends/web/src/routes/market/swap/swap.tsx
Copy link
Copy Markdown
Collaborator

@Beerosagos Beerosagos left a comment

Choose a reason for hiding this comment

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

I had a look, mostly in the BE part. Fitting the swap destination accounts into the generic account struct, is a bit of a stretch imo.. Would it be possible to use a dedicated object type?

Comment thread frontends/web/src/api/erc20.ts
Comment thread frontends/web/src/api/account.ts
Comment thread backend/handlers/handlers.go Outdated
ParentAccountCode *accountsTypes.Code `json:"parentAccountCode,omitempty"`
ActiveTokens []activeToken `json:"activeTokens,omitempty"`
BlockExplorerTxPrefix string `json:"blockExplorerTxPrefix"`
Balance *balanceJSON `json:"balance,omitempty"`
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.

Not sure that adding the Balance to the account struct is a good idea. It is a widely used struct in the frontend and I don't feel very comfortable in adding a balance field that is defined only in a specific case and that will not be refreshed if a transaction is received. Any reason why not to fetch it with a dedicated call when needed?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Removed, it is not fetched dynamically

Comment thread backend/handlers/handlers.go Outdated
Code accountsTypes.Code `json:"code"`
Name string `json:"name"`
IsToken bool `json:"isToken"`
ParentAccountCode *accountsTypes.Code `json:"parentAccountCode,omitempty"`
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.

I'm not strongly against the parentAccountCode, even tho one could use the activeTokens slice to look out for the parent account (given that you need the whole account list). But if we want to add it, I think it should be consistent, i.e. always defined.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

It couldn't be always defined because it only makes sense for erc20 (eth, btc, ltc don't have a concept of "parent") however with this new type, which is swap-specific, it is at least restricted to this new type, but it can't still be for every type

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.

Yeah, I meant always defined when it makes sense 😂 i.e. populating it also in the general /accounts endpoint, where it was ignored, iirc.

Comment thread backend/handlers/handlers.go Outdated
Comment thread backend/swap_destination_accounts.go
Comment thread backend/swap_destination_accounts.go Outdated
Comment thread backend/erc20.go Outdated
Comment thread backend/swap_destination_accounts.go Outdated
@bznein bznein force-pushed the frontend/swap-inactive-destination-accounts branch 2 times, most recently from 3ea21b1 to 13e4b21 Compare March 26, 2026 14:47
@bznein
Copy link
Copy Markdown
Collaborator Author

bznein commented Mar 26, 2026

I had a look, mostly in the BE part. Fitting the swap destination accounts into the generic account struct, is a bit of a stretch imo.. Would it be possible to use a dedicated object type?

Yeah, I created a dedicated type swapDestinationAccountJSON (and refactored the common parts into a base type). Other comments coming inline as replies asap :)

@bznein bznein requested a review from Beerosagos March 26, 2026 14:57
clearTimeout(timeoutId);
};
}, [fromAccount?.coinCode, sellAccountCode, sellAmount, toAccount?.coinCode, buyAccountCode]);
}, [buyAccount?.coinCode, buyAccountCode, fromAccount?.coinCode, sellAccountCode, sellAmount]);
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: it would be nice to rename fromAccount to sellAccount for consistency

Comment thread frontends/web/src/api/account.ts Outdated
};

export type TAccount = {
export type TAccountLike = {
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.

Rename to TAccountBase to match the backend? Also, maybe we can include isToken here?

Comment thread frontends/web/src/api/account.ts Outdated
accountNumber?: number;
};

type TSwapDestinationAccountBase = TAccountLike;
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't we use TAccountLike directly?

Comment thread backend/handlers/handlers.go Outdated
func (handlers *Handlers) getSwapDestinationAccounts(*http.Request) interface{} {
swapAccounts := []*swapDestinationAccountJSON{}
for _, account := range handlers.backend.SwapDestinationAccounts() {
swapAccounts = append(swapAccounts, newSwapDestinationAccountJSON(
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 just passing account to the function?

const handleConfirm = async () => {
if (buyAccount && !buyAccount.active) {
// TODO: move activation as late as possible in the real swap flow, or ask for explicit confirmation first.
if (buyAccount.isToken) {
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.

I think we should move this whole logic in the backend, as a part of the signing endpoint

@bznein bznein force-pushed the frontend/swap-inactive-destination-accounts branch from 88dac67 to ab4e16c Compare April 2, 2026 09:19
This allows user to select accounts to swap to even if those accounts
are not active yet, effectively reducing friction for the user to get
coins for an account.

Co-authored-by: beerosagos <luca@bitbox.swiss>
@bznein bznein force-pushed the frontend/swap-inactive-destination-accounts branch from ab4e16c to cd6ccbb Compare April 2, 2026 09:48
@bznein bznein requested a review from Beerosagos April 2, 2026 09:50
Copy link
Copy Markdown
Collaborator

@Beerosagos Beerosagos left a comment

Choose a reason for hiding this comment

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

LGTM

@bznein bznein merged commit 1a4b9a4 into BitBoxSwiss:staging-swap Apr 2, 2026
16 checks passed
@bznein bznein deleted the frontend/swap-inactive-destination-accounts branch April 2, 2026 10:18
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