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 connect button loaders, improve Ledger modal #166

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

alx-khramov
Copy link
Contributor

Resolves SI-1229

Changes

  • Add the "loading" state for WC and Binance wallet connection buttons;
  • Fix the "retry" button for some cases in the Ledger HID connection modal;
  • Show a loading spinner in the Ledger modal during ledger packages loading;
  • Fix the issue with passing onClickWalletsLess, onClickWalletsMore props;

Demo

The main part of WalletConnect and Binance code is loaded only after user clicks WalletConnect button. During the code loading and executing, a user can see the loading indicator. Other connection buttons become disabled, so the user is not able to break the connection process by randomly clicking other wallets while waiting WC/Binance to load.

WalletConnect

wc.mp4

Binance

binance.mp4

Ledger

Ledger HID connection has another logic, so I had to add a loading spinner right into the Ledger modal. Ledger connection requires even more code to load and, as in other cases, it starts to load only when a user clicks Ledger button. While the code is loading, the user can see the spinner.

ledger-fast.mp4

Before the change, users could have problems if the internet speed is relatively slow: the ledger code is not loaded yet, but we already show the invitation to connect a device and nothing happens while the code is loading in background. Also, the "retry" button wasn't working properly in that case.
Still, there is an issue if the ledger packages loading takes too long (~ >5 sec). A user will see a connection error immediately after packages were loaded. That happens because of browser restrictions: we are trying to connect to a device via browser API while last user's interaction (click) happened more than 5 seconds ago (because the user waited all this time and didn't click anywhere). See this case on a video below. At least, the user can still connect by clicking the "retry" button. This case should be fixed separately.

ledger-slow.mp4

@alx-khramov alx-khramov self-assigned this Sep 6, 2024
@alx-khramov alx-khramov requested a review from a team as a code owner September 6, 2024 11:46
Copy link

changeset-bot bot commented Sep 6, 2024

⚠️ No Changeset found

Latest commit: 4eb0397

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

const contextValue = useMemo(
() => ({
rpc,
walletDataList,
chains,
loadingWalletId,
setLoadingWalletId,
Copy link
Contributor

Choose a reason for hiding this comment

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

instead of setter you can pass wrapper function to wrap connectAsync and do on/off state setting

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 don't see how it is more convenient. Some wallets don't need loaders and will use the standart connectAsync fn to connect, some will use this non-standart wrapper function

Copy link
Contributor

Choose a reason for hiding this comment

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

Because you are repeating same try {set(true) } finally {set(false)}, and bound to make mistake somewhere

Copy link
Contributor

Choose a reason for hiding this comment

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

you can pass both setter and a wrapper but I don't see any non confirming wallets so far

await connectAsync(
{ connector },
{
onSettled: () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you check if we need those callbacks? Perhaps you can use try,catch,finally.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why? These are documented callbacks, they work, why should I change them?

Copy link
Contributor

Choose a reason for hiding this comment

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

Because it makes code more complicated. If we can use try/catch/finally it will much easier to understand, e.g. right now we need to refer to docs for onSettled.

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.

2 participants