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: fix bug with sending ordinals from ledger, #ref 5253 #5268

Merged
merged 1 commit into from
Apr 19, 2024

Conversation

pete-watters
Copy link
Contributor

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

Try out Leather build b878f29Extension build, Test report, Storybook, Chromatic

This PR fixes a bug with the Send Ordinal flow when logged in with Ledger. It was introduced in 6262267

The issue is that the ledger dialogs were not appearing underneath the send-ordinal flow, only on ledger, due to them not having a dialog background location set.

We had a similar problem with the Choose fee dialog here before: https://github.com/leather-wallet/extension/pull/4632/files.

The underlying issue comes from the change made to make sure we overlay modals on the correct background.

Linking this PR for the record also: #4316

@pete-watters pete-watters force-pushed the fix/5253/ledger-broken-send-ordinal branch from e6f1935 to aee828b Compare April 18, 2024 17:00
state: {
tx: bytesToHex(psbt),
inputsToSign,
backgroundLocation: { pathname: RouteUrls.Home },
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 tested pre 6262267 and we didn't need to do this before and I'm honestly not certain why we do now.

I have done local testing and confirmed I can send an ordinal from my ledger to my software wallet. Once it has arrived I will open this for review.

Other flows like send/btc/ don't need this backgroundLocation as they are page based rather than dialog based so I need to test them now.

Likely I will need to add some other code to ensure they have the correct background but that is a lesser issue than not being able to send ordinals at all on Ledger

Copy link
Collaborator

Choose a reason for hiding this comment

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

Other flows like send/btc/ don't need this backgroundLocation as they are page based rather than dialog based so I need to test them now.

MM, just read this. How can we set bg location dynamically?

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've tested sending BTC and PSBT signing on Gamma from ledger and it's working.

I have a hook from before that re-directs if there is no background location so we could use that or else try and have a set location it takes from global state.

@pete-watters pete-watters force-pushed the fix/5253/ledger-broken-send-ordinal branch from aee828b to b878f29 Compare April 18, 2024 18:39
return navigate(RouteUrls.LedgerPublicKeyMismatch, {
replace: true,
state: {
backgroundLocation: { pathname: RouteUrls.Home },
Copy link
Collaborator

Choose a reason for hiding this comment

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

This overlay modal isn't always on homepage fyi. It might show in on send tokens page, signPsbt RPC call etc

Comment on lines +144 to +147
// for send ordinal '..' brings you back to the `choose-fee` step but you lose context of the ordinal
const backLocation = location.pathname.match(RouteUrls.SendOrdinalInscription)
? RouteUrls.Home
: '..';
Copy link
Collaborator

Choose a reason for hiding this comment

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

When we have to add logic like this, we might as well just write a switch statement to each possible case.

The idea is that .. is always the route from which the flow started. Any way we can solve this without having to do this?

Is it too late to just revert the /* routing set up 😅

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 never too late to revert anything. And this is a real pain I agree.

Unfortunately .. seems to give un-predictable results and in this scenario with ledger it just sends them back to send/ordinal-inscription/choose-fee but doesn't keep the fee modal open.

Copy link
Collaborator

Choose a reason for hiding this comment

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

As far as I understand the problem, with /* anything that comes after is treated as a single route via wildcard match, thus breaking the ledger implementation that relies on route changes

Copy link
Collaborator

Choose a reason for hiding this comment

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

@pete-watters wonder if you can try something:

We're missing a path on the outer route. I wonder if that means it thinks /* routes are the same, but if we put a path in, does that behaviour change?

export function ledgerSignTxRoutes({ component, customRoutes }: LedgerSignTxRoutesProps) {
  return (
    <Route path="/" element={component}>
      {customRoutes}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea. I'll test that now and try see if I can both fix this and change the pattern to be a bit cleaner.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@kyranjamie if I add this route wrapper the whole APP won't even load, crashing with:
Screenshot 2024-04-19 at 11 56 25

I think it would be prudent to merge this fix for a P1 bug first, then continue efforts refactoring the routes to implement a more permanent solution for this and all of our routes.

The routing setup now is also proving tricky when implementing the Approval UX so I think it's worth re-reviewing it as a hole.

I checked back and I originally added the /* to the route to suppress this warning:
Screenshot 2024-04-19 at 12 00 16

I will take a look at the suggestions that provides to use / or * but I think that was causing some other issues.

It could be better to remove the /* get rid of this and accept that we will get this warning but have a simpler setup

@pete-watters pete-watters marked this pull request as ready for review April 18, 2024 19:20
@pete-watters
Copy link
Contributor Author

pete-watters commented Apr 18, 2024

@kyranjamie I've tested this and it fixes the bug of not being able to send ordinals from ledger so opening it for review.

I started work on adding a test for send inscriptions but was having difficulty with the hover to show the send button. I'll keep working on this.

In general this approach of routes and background locations is awful and is causing us a lot of problems.

We'll need to come up with a better solution for that but for now this should at least unblock users from sending on ledger.

I'd been working on this set of fixes to other ledger issues, in between fighting fires, so will look at this again when improving that

@pete-watters pete-watters requested a review from fbwoolf April 18, 2024 19:25
Copy link
Collaborator

@kyranjamie kyranjamie left a comment

Choose a reason for hiding this comment

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

Agreed, let's merge. Let's also follow up with a test for sending inscriptions on testnet (at least getting the point pre-signing with ledger)

@pete-watters pete-watters linked an issue Apr 19, 2024 that may be closed by this pull request
@pete-watters
Copy link
Contributor Author

with a test for sending inscriptions on testnet

Will do. I took #4467 into my backlog so will get working on this.

@pete-watters pete-watters added this pull request to the merge queue Apr 19, 2024
Merged via the queue into dev with commit 06aef60 Apr 19, 2024
28 checks passed
@pete-watters pete-watters deleted the fix/5253/ledger-broken-send-ordinal branch April 19, 2024 11:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants