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

backend issue => estimate fee backend only if account has not balance #211

Closed

Conversation

MSghais
Copy link
Collaborator

@MSghais MSghais commented Jul 5, 2024

I've one backend issue (CORS) to estimate the fee through the backend, in this case also the UI claim flow is broken.

Changes:
Try estimate fees and get nonce on the UI.

Do estimate claim fees with backend only if no balance ETH in the account.

Check few things for run backend process claim:

  • no balance to pay the fees
  • If not ETH balance on the account connected

@MSghais MSghais requested a review from ugur-eren July 5, 2024 13:26
Copy link

vercel bot commented Jul 5, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
joyboy-webapp ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 5, 2024 2:16pm

Copy link

vercel bot commented Jul 5, 2024

@MSghais is attempting to deploy a commit to the keep-starknet-strange Team on Vercel.

A member of the Team first needs to authorize it.

@ugur-eren
Copy link
Collaborator

It would be better to check that the connected account can pay the transaction fees instead of having balance. So IMO it should stay as it is

@MSghais
Copy link
Collaborator Author

MSghais commented Jul 5, 2024

It would be better to check that the connected account can pay the transaction fees instead of having balance. So IMO it should stay as it is

We can also add the estimate claim fees on the UI too for the check if it's gonna be done by the UI or backend.

Copy link
Collaborator

@ugur-eren ugur-eren left a comment

Choose a reason for hiding this comment

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

I've requested some changes.

Comment on lines +55 to +57
/** @TODO add more check for the two claim flow */
// Default min to 0 => Change to a constant or UI estimate base claim
// Nonce first account tx => deduced it never do a tx before.
Copy link
Collaborator

@ugur-eren ugur-eren Jul 5, 2024

Choose a reason for hiding this comment

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

Unnecessary comments can be removed

/** @TODO add more check for the two claim flow */
// Default min to 0 => Change to a constant or UI estimate base claim
// Nonce first account tx => deduced it never do a tx before.
const minAmountBalanceToClaim = BigInt(0);
Copy link
Collaborator

Choose a reason for hiding this comment

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

This can be removed since we can directly use it in the check, no need for extra variable

// Default min to 0 => Change to a constant or UI estimate base claim
// Nonce first account tx => deduced it never do a tx before.
const minAmountBalanceToClaim = BigInt(0);
let nonce: undefined | string;
Copy link
Collaborator

Choose a reason for hiding this comment

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

No need for nonce check. It is useless. Either the account has balance, or not.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The nonce let us check if user have no funds because it's a new account (0 tx) or no

@@ -62,7 +65,62 @@ export const Tips: React.FC = () => {
});
const balance = uint256.uint256ToBN({low: balanceLow, high: balanceHigh});

if (balance < fee) {
// Send the claim through the wallet
Copy link
Collaborator

Choose a reason for hiding this comment

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

Comment can be removed

Comment on lines +105 to +111
if (!estimateFee?.overall_fee) {
try {
nonce = await connectedAccount?.account?.getNonce();
} catch (error) {
console.log('Get nonce error => maybe first tx', error);
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Again, no need for nonce check.

Comment on lines +94 to +103
let estimateFee;
try {
estimateFee = await connectedAccount?.account?.estimateInvokeFee({
contractAddress: ESCROW_ADDRESSES[await provider.getChainId()],
entrypoint: Entrypoint.CLAIM,
calldata: claimCalldata,
});
} catch (error) {
console.log("Can't estimate UI fees", error);
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Error needs to be handled. Either remove the check, or show a warning etc.

Comment on lines +117 to +120
const isBackendNeeded =
(!nonce && !estimateFee) ||
(estimateFee?.overall_fee && balance < estimateFee?.overall_fee) ||
(nonce && Number(nonce) > 0 && balance <= minAmountBalanceToClaim);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Check is too complex, only check needed is either the account has balance, or not.

@MSghais MSghais closed this Jul 5, 2024
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