frontend: enable inactive swap destination accounts#3926
Conversation
thisconnect
left a comment
There was a problem hiding this comment.
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."
fd5debf to
e5c26e9
Compare
|
@thisconnect PTAL thanks :) |
b366b13 to
c8d1d47
Compare
c8d1d47 to
acf8226
Compare
thisconnect
left a comment
There was a problem hiding this comment.
frontend tested LGTM
acf8226 to
3ed2180
Compare
3ed2180 to
0b33548
Compare
thisconnect
left a comment
There was a problem hiding this comment.
frontend partly tested LGTM,
Beerosagos
left a comment
There was a problem hiding this comment.
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?
| ParentAccountCode *accountsTypes.Code `json:"parentAccountCode,omitempty"` | ||
| ActiveTokens []activeToken `json:"activeTokens,omitempty"` | ||
| BlockExplorerTxPrefix string `json:"blockExplorerTxPrefix"` | ||
| Balance *balanceJSON `json:"balance,omitempty"` |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Removed, it is not fetched dynamically
| Code accountsTypes.Code `json:"code"` | ||
| Name string `json:"name"` | ||
| IsToken bool `json:"isToken"` | ||
| ParentAccountCode *accountsTypes.Code `json:"parentAccountCode,omitempty"` |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Yeah, I meant always defined when it makes sense 😂 i.e. populating it also in the general /accounts endpoint, where it was ignored, iirc.
3ea21b1 to
13e4b21
Compare
Yeah, I created a dedicated type |
| clearTimeout(timeoutId); | ||
| }; | ||
| }, [fromAccount?.coinCode, sellAccountCode, sellAmount, toAccount?.coinCode, buyAccountCode]); | ||
| }, [buyAccount?.coinCode, buyAccountCode, fromAccount?.coinCode, sellAccountCode, sellAmount]); |
There was a problem hiding this comment.
nit: it would be nice to rename fromAccount to sellAccount for consistency
| }; | ||
|
|
||
| export type TAccount = { | ||
| export type TAccountLike = { |
There was a problem hiding this comment.
Rename to TAccountBase to match the backend? Also, maybe we can include isToken here?
| accountNumber?: number; | ||
| }; | ||
|
|
||
| type TSwapDestinationAccountBase = TAccountLike; |
There was a problem hiding this comment.
Can't we use TAccountLike directly?
| func (handlers *Handlers) getSwapDestinationAccounts(*http.Request) interface{} { | ||
| swapAccounts := []*swapDestinationAccountJSON{} | ||
| for _, account := range handlers.backend.SwapDestinationAccounts() { | ||
| swapAccounts = append(swapAccounts, newSwapDestinationAccountJSON( |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
I think we should move this whole logic in the backend, as a part of the signing endpoint
88dac67 to
ab4e16c
Compare
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>
ab4e16c to
cd6ccbb
Compare
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: