Skip to content

fix: add confirmation dialog to claimUnstakedTrx method#236

Open
ulissesferreira wants to merge 1 commit intomainfrom
fix/no-confirmation-for-withdrawing-unstaked-trx
Open

fix: add confirmation dialog to claimUnstakedTrx method#236
ulissesferreira wants to merge 1 commit intomainfrom
fix/no-confirmation-for-withdrawing-unstaked-trx

Conversation

@ulissesferreira
Copy link
Contributor

@ulissesferreira ulissesferreira commented Mar 12, 2026

Explanation

Added a confirmation dialog before signing and broadcasting the claim of unstaked TRX, using the ConfirmSignTransaction UI component. The dialog estimates fees and displays relevant asset information to the user. If the user rejects, a UserRejectedRequestError is thrown

Screen.Recording.2026-03-12.at.13.47.10.mov

References

n/a

Checklist

  • I've updated the test suite for new or updated code as appropriate
  • I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate
  • I've communicated my changes to consumers by updating changelogs for packages I've changed
  • I've introduced breaking changes in this PR and have prepared draft pull requests for clients and consumer packages to resolve them

@ulissesferreira ulissesferreira force-pushed the fix/no-confirmation-for-withdrawing-unstaked-trx branch from dafbd19 to d790592 Compare March 12, 2026 10:40
@ulissesferreira ulissesferreira marked this pull request as ready for review March 12, 2026 10:42
@ulissesferreira ulissesferreira requested a review from a team as a code owner March 12, 2026 10:42
@ulissesferreira
Copy link
Contributor Author

@metamaskbot publish-preview

@github-actions
Copy link
Contributor

Preview builds have been published. See these instructions for more information about preview builds.

Expand for full list of packages and versions.
{
  "@metamask-previews/tron-wallet-snap": "1.23.1-preview-d790592"
}

@ulissesferreira ulissesferreira force-pushed the fix/no-confirmation-for-withdrawing-unstaked-trx branch from d790592 to b62f5bf Compare March 12, 2026 11:35
@ulissesferreira
Copy link
Contributor Author

@metamaskbot publish-preview

@github-actions
Copy link
Contributor

Preview builds have been published. See these instructions for more information about preview builds.

Expand for full list of packages and versions.
{
  "@metamask-previews/tron-wallet-snap": "1.23.1-preview-b62f5bf"
}

Copy link
Member

@mikesposito mikesposito left a comment

Choose a reason for hiding this comment

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

Looks good overall! I just have a couple of questions / small suggestions

});

if (!confirmed) {
throw new UserRejectedRequestError() as unknown as Error;
Copy link
Member

Choose a reason for hiding this comment

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

UserRejectedRequestError is not an error class. I don't know if it was supposed to be used with new Error(new UserRejectedRequestError()), but the class variables and methods seem to be very similar to what Error has, so maybe there will be no issue.

In that case, we could try without as unknown:

Suggested change
throw new UserRejectedRequestError() as unknown as Error;
throw new UserRejectedRequestError() as Error;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Weirdly, the last time I tried this we had some errors, I think linting ones. In the meantime all is good... Well, done ✅

throw new Error(`Unhandled keyring request method: ${method}`);
}

return false;
Copy link
Member

Choose a reason for hiding this comment

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

Is this removal intentional?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah. It was dead code due to the existance of a default case. I guess some historical artifact left behind

Screenshot 2026-03-12 at 15 00 59

try {
preferences = await this.#snapClient.getPreferences();
} catch {
// keep defaults
Copy link
Member

Choose a reason for hiding this comment

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

Curious: is this expectable in a scenario where the snap is working properly?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That is a very good question... It falls under those cases where yeah, it should never happen and if it does then the whole snap environment is acting weird. We don't really have an approach / way to handle this. When Snaps were first shipped we were worried about breaking main functionality and this kind of error never got thrown. Do you think we should turn these cases into a panic so we look into them?

Copy link
Member

Choose a reason for hiding this comment

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

We should not let the entire snap crash, though in cases of undefined behavior like this one it might be good to return an error to the snap request.

Not sure if it is useful for this case, but I see that the #handleClaimUnstakedTrx returns this object:

return {
  valid: true,
  errors: [],
};

Perhaps this would be a good case to return valid: false and an error in the errors array? We should make sure that it would bubble up to the client UI in the way we would expect, though. What do you think?

@ulissesferreira ulissesferreira force-pushed the fix/no-confirmation-for-withdrawing-unstaked-trx branch from b62f5bf to dfec0ee Compare March 12, 2026 15:03
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