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

Wen Account Selector: Fill in the rest of the account selector data, adjust the wallet tab to only display current account #502

Merged
merged 15 commits into from
Dec 4, 2021

Conversation

Shadowfiend
Copy link
Contributor

@Shadowfiend Shadowfiend commented Dec 2, 2021

This PR fils in the remaining data in the account selector, as
well as adjusting the wallet and single asset tabs to only display
balances and activity related to the currently-selected account. In
the process, almost all of the combined activity-related code in the
accounts slice is removed, since it was meant to populate this view,
which was never meant to display data across accounts.

The other large refactor here was the introduction of the
accountsSelectors file, following @henryboldi's example with the
activitiesSelectors file. Both of these are exposed at the top level
via a re-exporting background/redux-slices/selectors package that
exposes all internal selectors for the UI to use, which has allowed
some cleanup in typing dependencies to take place (in particular,
allowing the selectors to reference the full state without having to
resort to redeclaring it to avoid circular dependencies).

A few additional tweaks include trying to resolve avatars where
possible, changing the fixed Trezor header to display read-only mode
(for now), and not displaying a name when an account has no associated
ENS name. Also, the single asset page no longer displays placeholder
“this asset is on Arbitrum” language, which was confusing users and is
rooted in unimplemented functionality. These elements are hidden for
now.

Updated account selector

Base automatically changed from wen-token-data to fix-fairy December 2, 2021 15:43
Base automatically changed from fix-fairy to main December 2, 2021 16:14
accountSelectors now holds selectAccountAndTimestampedActivities, but
just as important selectors are imported directly from the top-level
`redux-slices/selectors` package instead of going to the particular
subpackage for simplicity.

In the process, use a RootState defined at the top level of redux-slices
that can be used in the selectors package, since there is no longer a
circular dependencies concern.
In addition to the already-functioning address and ENS name in the
list, this commit adds the populating of correct per-address totals,
updates the account grouping to indicate that the addresses are
read-only, and replaces the bolded name with the shortened address in
cases where there is no ENS name to work with. It also populates the
correct avatar, when available.

A new selectAccountTotals selector is introduced that does per-account
totaling to make this possible. There is likely an opportunity for
refactoring of some of the code that is similar with
selectAccountAndTimestampedActivities.
This selector allows for the selection of just the currently selected
account's balances, both with a total in the main currency value and per
asset owned by that particular account.
These two components were operating on the combined asset data from all
accounts, but were always meant to only display the current account's
information. Activities/transactions are currently still shown across
accounts.
To do this, WalletActivityList now takes an array of activities to
display from its caller rather than selecting it directly. The Wallet
and SingleAsset components use
selectCurrentAccountActivitiesWithTimestamps to pull current activity,
and SingleAsset further filters to the asset it is displaying.
This isn't supported yet, and displaying it is confusing to real users.
Coming S∞n™.
Use the number of accounts in the account slice to determine if the
wallet has any accounts, and update the accounts balance selector to
exit early if there is no current account.
This ensures that adding a checksum address doesn't result in two redux
entries, only one of which will actually receive data.
These were rendered at-size, and are now rendered scaled to their
containing box.
@Shadowfiend
Copy link
Contributor Author

There's an issue remaining with the back button on the single asset page, but it's present on main due to the onboarding flow changes that made it position: fixed. I should have flagged that, position: fixed in a shared component is always a recipe for disaster down the line haha.

I tried to fix it up but ran into some walls… @henryboldi could use some help with it, maybe as a separate PR?

@Shadowfiend Shadowfiend marked this pull request as ready for review December 3, 2021 04:34
@henryboldi
Copy link
Contributor

I should have flagged that, position: fixed in a shared component is always a recipe for disaster down the line haha. I tried to fix it up but ran into some walls… @henryboldi could use some help with it, maybe as a separate PR?

Totally my bad! Yes, I'll open up a separate PR with a fix @Shadowfiend

Copy link
Contributor

@henryboldi henryboldi left a comment

Choose a reason for hiding this comment

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

This is chef's kiss! A few questions and comments though,

  1. After adding a new account, the wallet should probably switch to it

  2. The avatar border should be rounded

Avatar

  1. How about hiding this "add address" button? It could be confusing


add address

  1. How do we feel about hiding the notifications tab in this PR?

}
)

export type AccountTotal = {
Copy link
Contributor

Choose a reason for hiding this comment

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

The AccountTotal naming is a tad confusing to me. To someone unfamiliar with the codebase, it might give the impression that it's some sort of total amount

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's the account info + it's total balance, which is in line with how we've done eg AccountNetwork.

Would love a better name though--I don't love that pattern, but I couldn't come up with anything great after giving it some thought.

Either way a jsdoc couldn't hurt.

@Shadowfiend
Copy link
Contributor Author

  1. Yes 2. Yes but not doing it for this release in the interest of time 3. Yes 4. Yes.

It shall rise again.
Existing avatars are rounded at the image level, but ENS avatars may not
be, so the border rounding is now applied at the browser/element level.
The add flow is currently via Add Wallet, while Add address is meant for
adding within an account. Thinking through how these pieces will
interact will read-only wallets will happen later, so for now hide the
(always-disabled-anyway) Add address button.
This also obviates the need to try to auto-select the first account for
wallet initialization.
The key error interferes with a linter error, but we can skip the linter
error to save our developer console.
@Shadowfiend
Copy link
Contributor Author

Ended up doing all of them + fixing a React console error. Notably, wanting to select the newly-added account led to also removing some hacky code that was in use for initial wallet startup 🎉

Copy link
Contributor

@mhluongo mhluongo left a comment

Choose a reason for hiding this comment

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

Non-controversial, LGTM!

@@ -5,11 +5,13 @@ import { AnyAction } from "@reduxjs/toolkit"

import Main from "./main"
import { encodeJSON, decodeJSON } from "./lib/utils"
import logger from "./lib/logger"

import { RootState } from "./redux-slices"
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice to be done with the ReturnType


export default mainReducer

export type RootState = ReturnType<typeof mainReducer>
Copy link
Contributor

Choose a reason for hiding this comment

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

Drat

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's overall better, otherwise we'd have to update every time we added a slice 🤷 DRY and all.

@mhluongo mhluongo merged commit 28eb79e into main Dec 4, 2021
@mhluongo mhluongo deleted the wen-account-selector branch December 4, 2021 04:39
@henryboldi
Copy link
Contributor

Should this close #363?

@Shadowfiend
Copy link
Contributor Author

I'm interested in your take on that. I didn't set out to refactor the accounts slice as a goal, so there may still be some work to do if it's considered from that perspective.

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