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/4028/leather wallet modal routing #4325

Merged
merged 17 commits into from
Oct 16, 2023

Conversation

pete-watters
Copy link
Contributor

@pete-watters pete-watters commented Oct 5, 2023

Try out this version of Leather — download extension builds.

This PR fixes: #4086 & #4028.

Some work was performed on this before rebranding as Leather in this PR and this PR

The changes introduced here:

  • refactor our routes
  • introduce ModalBackgroundWrapper which allows us to overlay modals above other routes
    • This lets us show the correct background behind nested routes
  • adds useBackgroundLocationRedirect so that when pages are visited directly or opened in new tabs we can properly set the content behind them

This video shows how it's working:

Kapture.2023-10-13.at.13.12.40.mp4

I found two bugs that I haven't fixed yet and are present on dev:

  • as a user when I
    • choose to view secret key
    • and use the settings menu
    • then the menu modal does not display until I enter my password
  • as a user when I
    • try to directly access /receive/collectible/ordinal (new tab or copy paste)
    • then the page crashes as it doesn't have the tap root address TypeError: Cannot read properties of null (reading 'btcAddressTaproot')

@pete-watters pete-watters self-assigned this Oct 5, 2023
@pete-watters pete-watters added effort:large Expected to take over 1 week of integration work bug-p3 Non-critical functionality broken for many users, or there are clear workarounds Visual bug 🧼 labels Oct 9, 2023
@pete-watters pete-watters force-pushed the fix/4028/leather-wallet-modal-routing branch 5 times, most recently from b3042d0 to 8bff6a8 Compare October 12, 2023 09:59
@pete-watters
Copy link
Contributor Author

@kyranjamie - I need to work on setting the BG location on the /receive/stx modal but opening this for initial review in case you spot any flaws / don't like what I'm doing

return createHashRouter(
createRoutesFromElements(
<Route element={<Container />}>
<Route
path={RouteUrls.Home}
path={`/${RouteUrls.Receive}/${RouteUrls.ReceiveStx}`}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

To go direct to /receive/stx for example in Ledger mode, we need this declaration also.

Doing this outside of <Home /> means we bypass the check for <Routes location={backgroundLocation || location}>

We can't do that check in this file without moving from createHashRouter -> <HashRouter> or introducing another wrapper which I can investigate

Copy link
Collaborator

Choose a reason for hiding this comment

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

Confused by this. What's ledger mode got to do with it?

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 had a test failing in the ledger.spec.ts as direct access to this route was not available.

// ledger.spec.ts
 test('that receive modal opens', async ({ homePage }) => {
    const address = await homePage.getReceiveStxAddress();
    test.expect(address).toEqual('SPSDM5RXY2E3V7JTFYKPFNRPDHG1B85788FKG2KN');
  });

That calls homePage.getReceiveStxAddress() in home.page.ts which has this code:

async getReceiveStxAddress() {
    await this.goToReceiveModal();
    // In Ledger mode, this element isn't visible, so clicking is conditional
    const qrCodeBtn = this.page.getByTestId(HomePageSelectors.ReceiveStxQrCodeBtn);
    if (await qrCodeBtn.isVisible()) await qrCodeBtn.click();
    const displayerAddress = await this.page
      .getByTestId(SharedComponentsSelectors.AddressDisplayer)
      .innerText();
    return displayerAddress.replaceAll('\n', '');
  }

Basically, here its trying to go direct to /receive/stx but it crashes. The same issue occured on the onboarding.spec.ts that restoring a wallet generates the correct stacks address

I think it's more to do with the route than with ledger mode specifically. It's just that in most of the other tests we first open the receive modal then click the QR code

import { ReceiveModal } from '@app/pages/receive/receive-modal';
import { ReceiveOrdinalModal } from '@app/pages/receive/receive-ordinal';
import { ReceiveStxModal } from '@app/pages/receive/receive-stx';

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 split app-routes up as it was difficult to work with.

I could refactor further to change this to object config:

export const receiveRoutesArray = [
  {
    path: RouteUrls.Receive,
    element: <ReceiveModal />,
    routes: [
      {
        path: RouteUrls.ReceiveStx,
        element: <ReceiveStxModal />,
      },

@pete-watters pete-watters force-pushed the fix/4028/leather-wallet-modal-routing branch from efb3843 to 341a6a6 Compare October 13, 2023 12:09
@pete-watters pete-watters marked this pull request as ready for review October 13, 2023 12:21
Copy link
Contributor

@fbwoolf fbwoolf left a comment

Choose a reason for hiding this comment

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

Nice work here, @pete-watters! 👍

@pete-watters pete-watters added this pull request to the merge queue Oct 16, 2023
Merged via the queue into dev with commit a06aa39 Oct 16, 2023
26 checks passed
@pete-watters pete-watters deleted the fix/4028/leather-wallet-modal-routing branch October 16, 2023 07:41
@pete-watters pete-watters linked an issue Oct 16, 2023 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
bug-p3 Non-critical functionality broken for many users, or there are clear workarounds effort:large Expected to take over 1 week of integration work
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Wallet always opens to Balances tab Fix state change behavior upon selecting "Send" for inscription
3 participants