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

feat(bridge-ui-v2): Fixed input validations and catching additional errors #14331

Merged
merged 3 commits into from
Aug 2, 2023

Conversation

KorbinianK
Copy link
Contributor

Bridging ERC20 Tokens was not allowing to send all tokens, as it calculated the fees as if we were paying with the token

Also reordered some validations to stop other validations if we already hit an "error"

@codecov
Copy link

codecov bot commented Aug 1, 2023

Codecov Report

Merging #14331 (436b699) into alpha-4 (45549b8) will increase coverage by 9.45%.
The diff coverage is n/a.

❗ Current head 436b699 differs from pull request most recent head 2a6a75c. Consider uploading reports for the commit 2a6a75c to get more accurate results

@@             Coverage Diff             @@
##           alpha-4   #14331      +/-   ##
===========================================
+ Coverage    67.75%   77.20%   +9.45%     
===========================================
  Files           88       56      -32     
  Lines         3045     1452    -1593     
  Branches       112      112              
===========================================
- Hits          2063     1121     -942     
+ Misses         859      299     -560     
+ Partials       123       32      -91     
Flag Coverage Δ
bridge-ui 94.25% <ø> (ø)
eventindexer 51.71% <ø> (ø)
relayer ?

see 32 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

// Todo: viem does not seem to detect UserRejectError
warningToast($t('bridge.errors.rejected'));
break;
case err instanceof TransactionExecutionError && err.shortMessage === 'User rejected the request.':
Copy link
Contributor

@jscriptcoder jscriptcoder Aug 1, 2023

Choose a reason for hiding this comment

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

Not quite understand why this is needed? denying tx signature is handled in the bridge method which re-throws UserRejectedRequestError getting caught here already

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As discussed, we can move this logic to the ERC20Bridge but for some reason the wrong error is thrown and we need to catch it

@@ -33,17 +37,19 @@
let inputBox: InputBox;
let computingMaxAmount = false;

onMount(() => {
clearAmount();
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we want to clear on mount? If the reason is to clear the state, before we actually wanted to leave the amount on purpose when switching pages

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 is not persisting (visibly) right now. We either clear it here or we make sure it is also displayed.

// Public API
export function clearAmount() {
inputBox.clear();
$enteredAmount = BigInt(0);
}

export async function validateAmount(token = $selectedToken, fee = $processingFee) {
$insufficientBalance = false;
$insufficientAllowance = false;
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this fixing a problem? We're gonna validate these two, we start assuming there is no issue and then validate

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, it helps with the flickering of the buttons. In the future we could introduce a loading or disabled status

if (!tokenAddress) return;

// Check for allowance
$insufficientAllowance = await erc20Bridge.requireAllowance({
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need to do this here?, we already get the error when running the estimation, don't we?, is this not redundant?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As discussed in the call, the gas estimation does not throw an error, so we need to call it.

@KorbinianK KorbinianK added this pull request to the merge queue Aug 2, 2023
Merged via the queue into alpha-4 with commit 4a78b6b Aug 2, 2023
3 checks passed
@KorbinianK KorbinianK deleted the fix/bridge-ui-v2--briding-validations branch August 2, 2023 09:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants