Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add watchonly setting to accounts & handle watchonly account loading/unloading #2327

Merged
merged 6 commits into from Nov 9, 2023

Conversation

benma
Copy link
Contributor

@benma benma commented Oct 31, 2023

Enabling the watchonly setting on an account leaves the account loaded when the keystore is removed, and the account is loaded at app launch too.

Watch-only is opt-in per account for now - in the future we might switch to enabling watch-only by default.

Not done in this PR: handling the case when the user performs an action on a watchonly account that requires the keystore, like verifying an address or transaction. This will follow in another PR.

Regression from 18aea1d, which started loading the persisted
accounts for all accounts, not just ETH. For ERC20 token accounts
there is no corresponding persisted account, so the token would fail
to be shown in the frontend.

We can just use  `account.Config().Config` instead, which is loaded
from the persisted config, and which has meaningful data for tokens -
e.g. the same signing config as the parent ETH account.
@benma benma requested a review from Beerosagos October 31, 2023 23:23
// AccountSetWatch sets the account's persisted watch flag to `watch`. Set to `true` if the account
// should be loaded even if its keystore is not connected.
// If `watch` is set to `false`, the account is unloaded and the frontend notified.
func (backend *Backend) AccountSetWatch(accountCode accountsTypes.Code, watch bool) error {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

not unit tested yet, i plan on adding one at some point

// watchonly results in the account *and* the tokens remaining loaded.
if acct := backend.accounts.lookup(accountCode); acct != nil {
if acct.Config().Config.CoinCode == coinpkg.CodeETH {
for _, erc20TokenCode := range acct.Config().Config.ActiveTokens {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jadzeidan fyi the erc20-as-their-own-accounts model is really quite bad for the code 🙈 special cases everywhere. it would be very nice (from the code point of view) if we could bundle the tokens into the parent ETH account. could also reduce the confusion about that the fees for an erc20 token tx are coming from a "different" account.

@thisconnect
Copy link
Collaborator

@Beerosagos PTAL :)

@Beerosagos
Copy link
Collaborator

@Beerosagos PTAL :)

doing it rn :)

Copy link
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'd like to test a bit more, but I'll start sharing a few comments

backend/config/accounts.go Outdated Show resolved Hide resolved
backend/accounts.go Outdated Show resolved Hide resolved
backend/accounts.go Outdated Show resolved Hide resolved
@@ -203,7 +203,7 @@ class Sidebar extends Component<Props> {
{
accountsByKeystore.map(keystore => (<React.Fragment key={keystore.keystore.rootFingerprint}>
<div className={style.sidebarHeaderContainer}>
<span className={style.sidebarHeader} hidden={!keystores?.length}>
<span className={style.sidebarHeader} hidden={!keystore.accounts.length}>
{t('sidebar.accounts')} - {keystore.keystore.name}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just a nit: I find the ACCOUNT - <keystore name> notation a bit confusing, as it seems to suggest that is the name of an account. I'd prefer <keystore name> - ACCOUNT or even removing the ACCOUNT part completely (maybe replacing it with the root fingerprint? smth like <keystore name> [fingerprint].
Anyway, this can be discussed and possibly changed in a future PR as well.

cc @jadzeidan

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For clarity, this is the title of the group header above the accounts (it says ACCOUNTS, not ACCOUNT).

Anyway, I agree the "ACCOUNTS" part could be dropped.

About the fingeprint: we had discussed that fingeprints are too technical/noisy to show by default. that discussion was in relation to disambiguate keystores from the same wallet but different passphrases, but decided that users can just rename the individual accounts.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah then it is just in the Italian translation, I guess. Plural english words are often transformed into their singular version: in Italian we have 'ACCOUNT' instead of accounts.

This will determine if an account will be displayed at launch even
without the keystore being connected.
@benma
Copy link
Contributor Author

benma commented Nov 8, 2023

@Beerosagos thanks for the nice review! I addressed all comments, PTAL

@benma benma requested a review from Beerosagos November 8, 2023 06:09
Copy link
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.

tACK! Very nice 🔥

When disconnecting a keystore, previously all accounts were removed,
because we had no watch-only accounts.

When registering, all keystore accounts were (re-)loaded, because they
were the only ones to be shown.

With watch-only, we don't want to reinit accounts that are being
watched. This allows a user to connect a keystore e.g. in the middle
of an action inside an account, like displaying an address, without
being disrupted.

The force flag is needed to reinitialize also watch-only accounts if
e.g. the activeTokens field changes for an ETH account. Ideally we can
always dynamically fix the loaded accounts to match the persisted
config, but that is for the future.
@benma benma merged commit 240c34e into BitBoxSwiss:staging-watchonly Nov 9, 2023
4 of 5 checks passed
@benma benma deleted the watchonly-toggle branch November 9, 2023 02:38
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.

None yet

3 participants