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

In the useOpenAction react hook, when the user doesn't have enough funds to collect, an unhandled promise is being thrown instead of being handled by the SDK #808

Open
1 of 2 tasks
pradel opened this issue Jan 27, 2024 · 7 comments
Labels
API Issue bug Something isn't working

Comments

@pradel
Copy link

pradel commented Jan 27, 2024

Describe the bug

In the useOpenAction hook, the SDK does not handle properly when the user doesn't have the funds to collect.
I published a post that can be collected using 0.01 WMATIC, when a user without enough funds in his wallet, an unhandled promise is thrown instead of being handled with the result.isFailure.

Uncaught (in promise) ValidationError: You do not have enough balance to collect this publication.

To Reproduce

I am having an issue with the following code

const { execute: collect, loading: loadingCollect } = useOpenAction({
    action: {
      kind: OpenActionKind.COLLECT,
    },
  });

 const onCollect = async () => {
// The collect call is currently throwing, the error should be in result.error instead
const result = await collect({
      publication,
    });
    if (result.isFailure()) {
      toast({
        title: "Failed to collect",
        description: result.error.message,
        variant: "destructive",
      });
      return;
    }
}

Expected behaviuor

The error should be catched and returned by the isFailure function

If using the React bindings, what is the essence of your React app?

  • React Web App
  • React Native

Version of the packages you are using

"@lens-protocol/client": "2.0.0-alpha.27",
    "@lens-protocol/metadata": "1.1.5",
    "@lens-protocol/react-web": "2.0.0-alpha.27",
    "@lens-protocol/wagmi": "3.0.0-alpha.24",
@pradel
Copy link
Author

pradel commented Jan 28, 2024

Probably related to the same root issue but with the same code I get the following unhandled promise rejection when trying to collect multiple times from the same profile.

ValidationError: Profile XXX has already acted on XXX in publication XXX

@cesarenaldi
Copy link
Member

@pradel thank you for raising this. Indeed the first error should be returned as Failure<InsufficientFundsError> like you said.

The second one is a different thing though. This is an API restriction that allows to use gasless collect only once for a given publication (for the same Profile).

We should model this better and not throw.

@pradel
Copy link
Author

pradel commented Jan 30, 2024

@cesarenaldi as one connected with just a wallet (no Lens profile) can collect many items I think the behavior with a Lens profile should be the same and there should be no limitations for it.

@cesarenaldi
Copy link
Member

@pradel this is absolutely true. The idea behind the error:

ValidationError: Profile XXX has already acted on XXX in publication XXX

is that the first collect for a Profile is sponsored by the Lens API (i.e. covers tx gas costs), any subsequent must be covered with own funds (like the case of just a wallet that collects, they always have to pay for gas themselves). It's to avoid abuse more than anything else.

We have intention to support this mechanics in the SDK with a specific error type so that consumers can detect this scenario and switch to self-funded collect (i.e. sponsored flag set to false). Or even have the SDK takes this decision internally.

We just didn't get to this yet, as until now, it was deemed low priority.

So to understand how urgent this is, is this a primary concern for the UX you are working on? Do you see Profiles collecting often the same exact publication?

@pradel
Copy link
Author

pradel commented Jan 30, 2024

I don't have production results to know if many people are doing this, but it came up while doing tests on testnet. Not sure people will do it.
Once we push the app to prod I can add some tracking to see how many people are affected by this error. It would be great to have the SDK return the error instead of throwing it so we can show a toast with the error for now.

@cesarenaldi
Copy link
Member

That would be a good interim step we can action pretty quick.

The retry with self-funded is where we need to change the underlying GQL mutation and need a little thinking on how to perform this check later at "broadcast time".

Regarding the very first error:

Uncaught (in promise) ValidationError: You do not have enough balance to collect this publication.

Do you have a publication ID (and where: Testnet or Mainnet)?

@cesarenaldi cesarenaldi added React Any Affects React integration RN and web bug Something isn't working labels Jan 31, 2024
@pradel
Copy link
Author

pradel commented Feb 1, 2024

@cesarenaldi it was on testnet but it seems that the error is not happening with our production build. Pretty weird, will try again next weekend to see what's going on.

@cesarenaldi cesarenaldi removed the React Any Affects React integration RN and web label Jun 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Issue bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants