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
frontend: improve routing and introduce device switch #145
Conversation
6f39642
to
c8f9176
Compare
} | ||
} | ||
time.Sleep(time.Second) | ||
} | ||
} | ||
|
||
// Start listens for inserted/removed devices forever. Run this in a goroutine. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Run this in a goroutine.
Why? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Forgot to adjust the comment (was the same comment before refactor). Thanks! #150
}); | ||
if (!accountsInitialized) { | ||
console.log('app.jsx route /'); // eslint-disable-line no-console | ||
route('/', true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it this why my accounts are no longer directly activated when I use the software-based keystore? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, that is because they are activated in device.jsx after unlock. Similar should be done in the software based one, or move this to a more generic place.
Btw. this particular lines I restored later, but adjusted to only apply when you are in /accounts/ (otherwise it would override othe redirects, e.g. to the inserted device, in a race).
path="/device/:deviceID" | ||
deviceIDs={deviceIDs} /> | ||
<Device | ||
key={devices} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need a key property here? 🤔 And this might no longer be valid/possible after preactjs/preact#1248.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I picked apart multiple commits and this belonged to a different one afaik. Anyway, it carries over here:
Needed to that the component remounts with different keys, to trigger the componentDidMount().
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, that sounds like a misuse of componentDidMount
then in https://github.com/digitalbitbox/bitbox-wallet-app/blob/97bd934996a3d5ba027b6ec782d151fe4b445ec6/frontends/web/src/routes/device/deviceswitch.tsx#L30
Maybe use componentWillReceiveProps
instead? (https://github.com/developit/preact#components).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or at least add a comment why the key properties are needed there. This is very subtle and uncommon (as far as I can judge) and it's shortcuts like this that make our code so fragile.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can do. After doing the research on resetting components, using the key seems to be a normal solution, but noted.
Didn't use componentWillReceiveProps because it's use seems discouraged:
https://reactjs.org/docs/react-component.html#unsafe_componentwillreceiveprops
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can also use https://reactjs.org/docs/react-component.html#componentdidupdate, if you prefer. And I don't know to what degree Preact will follow such deprecations.
No description provided.