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

fix: allow virtuoso to resize dynamically, ref #5242 #5289

Merged
merged 1 commit into from
Apr 24, 2024

Conversation

pete-watters
Copy link
Contributor

@pete-watters pete-watters commented Apr 22, 2024

Try out Leather build 6f242c3Extension build, Test report, Storybook, Chromatic

This PR ensures that account lists grow appropriately and that users with many accounts can access all of them.

#5242

@pete-watters pete-watters force-pushed the fix/5242/virtuoso-dynamic-height branch from 94d01c6 to ab6dd7b Compare April 22, 2024 10:42
@@ -34,12 +37,16 @@ export const ChooseAccount = memo(() => {
{url && <RequesterFlag requester={url.toString()} />}
<LogomarkIcon width="248px" height="58px" />
<Stack gap="space.04">
<styled.h1 textStyle="heading.05">Choose an account to connect</styled.h1>
<styled.h1 textStyle="heading.05">
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added this code as if you only have BTC connected on Ledger and then try to sign in to something it was just showing the logo and an empty screen

Now it shows:
Screenshot 2024-04-23 at 11 14 46

Copy link
Contributor

Choose a reason for hiding this comment

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

I believe we prob need some more explanation of what's going on for users?
something like 'you are connected with ledger in bitcoin mode only, please connect stacks account as well to use this feature' or smth like that

Copy link
Contributor Author

@pete-watters pete-watters Apr 24, 2024

Choose a reason for hiding this comment

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

@mica000 @markmhendrickson @fabric-8 :

Do you have any input on what copy to use on this screen?

Right now :

  • AS A USER signed in with ledger
  • AND only have BTC connected
  • WHEN you try and sign in to a site e.g. Gamma
  • THEN you see an empty screen below the leather logo like this

Screenshot 2024-04-24 at 11 23 15

I've just made a small change so that in these cases we say No connected accounts found instead of Choose an account to connect

Copy link
Collaborator

Choose a reason for hiding this comment

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

Following up here a bit late:

Ideally the user should be able to connect their wallet to any site with a Ledger account, regardless of whether they've connected with Ledger for BTC or STX.

It seems that our legacy endpoint for connecting (used by Gamma and others) is not behaving this way. However, because it's legacy (and deprecated), we don't need to update it per se.

I also assume that our newer endpoint (getAddresses) does behave this way, though I haven't tested per se. And as we implement this endpoint for mobile, we should retain this agnostic behavior, allowing users to connect regardless of Ledger connectivity by token.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for following up anyway 👍

@pete-watters pete-watters force-pushed the fix/5242/virtuoso-dynamic-height branch 2 times, most recently from a8698eb to 6e6765d Compare April 23, 2024 10:37
const heightOffset = headerHeight + footerHeight;
const height = vhToPixels(virtualHeight) - heightOffset;

const onResize = () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried to be more precise and update to the exact height we wanted on re-size but it was buggy.

Instead, here I force a re-render on re-size by changing the key. This means the wrapper height can adjust properly according to the parents vh

}

function vhToPixels(vh: string) {
const numericHeight = +vh.replace('vh', '');
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is converting vh to pixels so that it's a numeric value and we can compute the height of the wrapper, taking into account offsets needed for headers + footers

return (numericHeight * window.innerHeight) / 100;
}

export function VirtuosoWrapper({ children, hasFooter, isPopup }: VirtuosoWrapper) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I should improve this more by:

  • accepting the height as a prop
  • using tokens for footer / header height
    • I couldn't get them working using token('size
    • When importing and using token.size.X.value it was giving type errors

I can improve this further but I think this needs to get released sooner

>
{children}
</Box>
{wrapChildren ? (
Copy link
Contributor Author

Choose a reason for hiding this comment

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

All other dialogs have this Box to help them size dynamically but ones containing Virtuoso lists now bypass that.

onClose={onGoBack}
wrapChildren={false}
>
<VirtuosoWrapper>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Virtuoso height is now set to 100% and the actual height is controlled by a wrapping container

const { decodedAuthRequest } = useOnboardingState();

const { isShowingSwitchAccount, setIsShowingSwitchAccount } =
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was investigating why we were re-rendering SwitchAccount and I found this mistake.

We were rendering it both inside of the main <Container and also inside of AccountCard.

Now it stays at Container level only and OutletContext is used to show / hide it.

It needs to stay at that level so the settings menu can also trigger it

@@ -17,8 +17,8 @@ export function MessagePreviewBox({ message, hash }: MessageBoxProps) {
py="space.05"
overflowX="auto"
>
{message.split(/\r?\n/).map(line => (
<styled.span key={line} textStyle="label.01">
{message.split(/\r?\n/).map((line, index) => (
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was throwing a duplicate keys error

isShowing={isShowingSwitchAccount}
onClose={() => setIsShowingSwitchAccount(false)}
/>
{isShowingSwitchAccount && (
Copy link
Contributor Author

Choose a reason for hiding this comment

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

There was a mistake here in that <SwitchAccountDialog shouldn't be in the DOM unless showing

Copy link
Contributor

Choose a reason for hiding this comment

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

nice catch! I believe problem with requests not being cancelled on close in SwitchAccountDialog is here

@@ -0,0 +1,23 @@
import { useEffect, useState } from 'react';
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Re-adding this which I naively removed as I thought we didn't need it, however it's important as it alters the breakpoint on re-size

@pete-watters pete-watters marked this pull request as ready for review April 23, 2024 10:50
@pete-watters pete-watters force-pushed the fix/5242/virtuoso-dynamic-height branch from 6e6765d to 6f242c3 Compare April 23, 2024 13:33
@pete-watters pete-watters requested a review from fbwoolf April 23, 2024 14:27
Copy link
Contributor

@alter-eggo alter-eggo left a comment

Choose a reason for hiding this comment

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

great work 💪

src/app/common/hooks/use-media-query.ts Show resolved Hide resolved
isShowing={isShowingSwitchAccount}
onClose={() => setIsShowingSwitchAccount(false)}
/>
{isShowingSwitchAccount && (
Copy link
Contributor

Choose a reason for hiding this comment

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

nice catch! I believe problem with requests not being cancelled on close in SwitchAccountDialog is here

@@ -34,12 +37,16 @@ export const ChooseAccount = memo(() => {
{url && <RequesterFlag requester={url.toString()} />}
<LogomarkIcon width="248px" height="58px" />
<Stack gap="space.04">
<styled.h1 textStyle="heading.05">Choose an account to connect</styled.h1>
<styled.h1 textStyle="heading.05">
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe we prob need some more explanation of what's going on for users?
something like 'you are connected with ledger in bitcoin mode only, please connect stacks account as well to use this feature' or smth like that

@pete-watters pete-watters added this pull request to the merge queue Apr 24, 2024
Merged via the queue into dev with commit 5d618aa Apr 24, 2024
28 checks passed
@pete-watters pete-watters deleted the fix/5242/virtuoso-dynamic-height branch April 24, 2024 13:36
@pete-watters pete-watters linked an issue Apr 25, 2024 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants