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(bridge-ui): preserve custom processing fee selection across components #16346

Merged
merged 7 commits into from
Mar 8, 2024

Conversation

CodeDragonVN
Copy link
Contributor

@CodeDragonVN CodeDragonVN commented Mar 6, 2024

Description

This pull request solves an issue where the processing fee selection is not preserved when navigating between components in the bridge. Specifically, when a user selected 'None' as the processing fee, it would revert to the recommended instead of showing '0 ETH | Customized' after returning to the Import step, unlike when a custom fee was selected and remain at the Import Step.
This happened because hasEnoughEth would be set the it's false declaration in ProcessingFee.svelte, since the ProcessingFee component created in TokenInput.svelte wasn't binding the hasEnoughEth prop, which would then trigger unselectNoneIfNotEnoughETH($processingFeeMethod, hasEnoughEth) and set the processingFeeMethod to recommended.

Changes

  • Ensured the hasEnoughEth prop is correctly bound and passed through to the ProcessingFee component within TokenInput.svelte.

How to Reproduce the Issue

  1. Navigate to the 'Review' step of the bridge.
  2. Select 'None' for the processing fee.
  3. Return to the 'Import' step.
  4. Observe that previously, the fee selection would reset to the recommended, but with this fix, it should now correctly show zero.

Screenshots

Description Screenshot
The issue where the processing fee reverted to the recommended. Broken Fee Selection
The custom fee selection being preserved as expected. Custom Fee Selection
The fixed state showing the '0 ETH | Customized' fee preserved correctly. Fixed Zero Fee
Console warning indicating the missing hasEnoughEth prop. Console Warning

@KorbinianK
Copy link
Contributor

KorbinianK commented Mar 6, 2024

@CodeDragonVN Thanks for your effort and kudos to this very well formatted PR ❤️

  • The processing fee should reset when you go back to the first step, as it is a reset. But I can see why you may want it to stick.

  • I can't reproduce the console warning on the deployed bridge, how did you cause this warning?

@CodeDragonVN
Copy link
Contributor Author

@KorbinianK, thank you for the acknowledgment!

Regarding the processing fee behavior, I see your point about the reset at the first step. However, the current behavior is somewhat inconsistent, as a custom fee or recipient address does not reset, but only selecting the 'None' fee does.

The reset of the 'None' fee is arbitrarily caused by the initialization of TokenInput. By default, hasEnoughEth is assigned false in ProcessingFee.svelte, and when the ProcessingFee component is instantiated by TokenInput.svelte without passing this prop, it triggers the unintended reset due to the logic in unselectNoneIfNotEnoughETH($processingFeeMethod, hasEnoughEth).
The cause of the 'None' fee reset is not the intentional design of a step reset but rather an oversight in not binding hasEnoughEth, which differentiates its behavior from other custom settings like the custom fee and custom recipient by getting reset.

Here's a screenshot illustrating that the custom fee does not get reset:

custom fee

If the intention is for these settings to reset when returning to the first step, I can implement the logic and make another PR. Just let me know if you'd like me to proceed with those changes.

As for the console warning, it indeed appears under the specific circumstance if I omit the default false assignment of hasEnoughEth in ProcessingFee.svelte so my earlier assumption was incorrect.

@KorbinianK
Copy link
Contributor

@CodeDragonVN
Valid point, it's indeed missing the binding to reset correctly.
Feel free to fix the issue. It should reset fully when going back to the start.
You can keep this PR open I suppose and just add the changes, but up to you.

@dantaik dantaik requested a review from KorbinianK March 7, 2024 01:15
@CodeDragonVN
Copy link
Contributor Author

@KorbinianK, I took a moment to review the implementation in the NFT bridge's ImportStep.svelte and noticed it uses a reset pattern upon mounting:

const reset = () => {
  foundNFTs = [];
  $selectedNFTs = [];
  $selectedImportMethod = ImportMethod.NONE;
};
...
onMount(() => {
  reset();
});

Inspired by it, I've implemented a similar reset logic for the Fungible Bridge:

const reset = () => {
  $recipientAddress = null;
  $processingFeeMethod = ProcessingFeeMethod.RECOMMENDED;
};

onMount(async () => {
  reset();
});

Regarding the previous changes made in this branch, considering that they still enhance the overall code structure and functionality, I believe it would be beneficial to keep them.

Please let me know your thoughts on keeping these improvements as part of the branch. I'm open to any further suggestions or modifications you believe might be necessary.

@davidtaikocha davidtaikocha added this pull request to the merge queue Mar 8, 2024
Merged via the queue into taikoxyz:main with commit 9cf6b3a Mar 8, 2024
4 checks passed
Copy link

gitpoap-bot bot commented Mar 8, 2024

Congrats, your important contribution to this open-source project has earned you a GitPOAP!

GitPOAP: 2024 Taiko Contributor:

GitPOAP: 2024 Taiko Contributor GitPOAP Badge

Head to gitpoap.io & connect your GitHub account to mint!

Learn more about GitPOAPs here.

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.

3 participants