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: set connected false in endConnection #2807

Merged
merged 2 commits into from
Aug 4, 2024
Merged

Conversation

nej1044
Copy link
Contributor

@nej1044 nej1044 commented Jul 24, 2024

Hello.
I faced one problem using this.
Though a first purchase after the in-app connection is successful, the store purchase will be completed, but the currentPurchase status is not updating inside the library. I would have to repeat the purchase process by killing the app.
In my opinion, the purchaseListener is connected by the change of the connected value inside useEffect, which changes from false to true only when the app is first connected and not after that, so I decided that I can't subscribe to the status of the current order.
So I added a code inside the endConnection method to make connected false.
This allows you to update every subscription correctly by changing connected to true when you access the order page and false when you access endConnection.
Both iOS and Android work as expected.

I think this issue is related to the issue below.
#2700

I hope that this PR will be reflected so that it can help everyone.

@hyochan hyochan added 🛠 bugfix All kinds of bug fixes ℹ needs more info Needs more detailed information to move forward labels Jul 24, 2024
Copy link
Owner

@hyochan hyochan left a comment

Choose a reason for hiding this comment

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

This is a great investigation. However, ideally, I think the solution could go somewhere in https://github.com/dooboolab-community/react-native-iap/blob/887623698ce7b58615685745a0a7a39d518db160/src/hooks/useIAP.ts#L121-L126

Could you try setting setConnected(false) in the return statement in useEffect? Also, I think ending the connection there could be added as well. We only need the billing connection in the component where we actually need it.

src/iap.ts Outdated Show resolved Hide resolved
@nej1044
Copy link
Contributor Author

nej1044 commented Jul 24, 2024

I thought so too.
However, if setConnected(false) is added in the useEffect return, it seems necessary to test it whether its working normally. I'll fix and test it as soon as possible and add a commit once again if both IOS and Android are working fine

@nej1044
Copy link
Contributor Author

nej1044 commented Jul 29, 2024

Hello, As we discussed before, I have moved setConnected inside useIAP.
However, if you set setConnected to false during just the unmount period, it is not connected again during mount while testing in the test process, which results the connected state becomes false inside context and does not update the fetch status, so I made setConnected true even during mount.

/* withIAPContext.tsx */
    useEffect(() => {
     // here is false after setConnected(false)
      if (!connected) {
        return;
      }
     ...
    }, [connected]);

I've tested both iOS and Android, and they both work as expected.

If there are no problems, this update may help with many issues.

@nej1044 nej1044 requested a review from hyochan July 29, 2024 12:15
Copy link
Owner

@hyochan hyochan left a comment

Choose a reason for hiding this comment

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

This looks very promising! Thanks a lot 👍

@hyochan hyochan merged commit 2e76f43 into hyochan:main Aug 4, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🛠 bugfix All kinds of bug fixes ℹ needs more info Needs more detailed information to move forward
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants