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

Set default values on ProUser data class #1116

Merged
merged 13 commits into from
Jul 4, 2024
Merged

Conversation

atavism
Copy link
Contributor

@atavism atavism commented Jul 3, 2024

The changes from #1114 minus the db-android upgrade.

Resolves https://github.com/getlantern/engineering/issues/1476

@atavism
Copy link
Contributor Author

atavism commented Jul 3, 2024

@jigar-f I think we could put out a new release right away with this fix and then another release tomorrow with your change.. if that's okay with you?

@jigar-f
Copy link
Contributor

jigar-f commented Jul 3, 2024

@atavism Could you please just give me an hour, this issue is with purchase, let me look into it now.

@atavism
Copy link
Contributor Author

atavism commented Jul 3, 2024

@atavism Could you please just give me an hour, this issue is with purchase, let me look into it now.

Oh, sure. Thanks for taking a look!

@jigar-f
Copy link
Contributor

jigar-f commented Jul 3, 2024

@atavism I think you know better on this, So the issue is this events never gets a callback, It only gets callbacks when user install the app for the first time After that is never callback,

Due to that issue currency list never gets updated. So while purchasing it always sends USD, and this is an issue.

@jigar-f
Copy link
Contributor

jigar-f commented Jul 3, 2024

Do you mind taking a look at it, Since you work on these event flows, I tried to see what's going on, not able to find issue.

@atavism
Copy link
Contributor Author

atavism commented Jul 3, 2024

@atavism I think you know better on this, So the issue is this events never gets a callback, It only gets callbacks when user install the app for the first time After that is never callback,
Due to that issue currency list never gets updated. So while purchasing it always sends USD, and this is an issue.

Thanks for the information. I am just about done testing the changes here so I can look into this next

@atavism
Copy link
Contributor Author

atavism commented Jul 3, 2024

It turns out there was another issue: the GSON library that we are using "turns missing fields into null values": https://medium.com/@clay07g/gson-will-assign-missing-values-as-null-3f02f19f2145

"Obviously, this doesn’t use Kotlin’s default values. As far as I know, there isn’t a way to access them via reflection. Unfortunately, either way, the solution is very clunky."

I updated this PR to use kotlinx.serialization, and I confirmed the default values are being properly set now on ProUser:

07-03 12:06:04.045 14641 14882 D org.getlantern.lantern.model.LanternSessionManager:
Storing user data ProUser(userId=372784204, token=kI3.., referral=8YXPUN, email=, userStatus=,
code=8YXPUN, locale=en_US, subscription=, expiration=0, devices=[], userLevel=)

@atavism
Copy link
Contributor Author

atavism commented Jul 3, 2024

@jigar-f Ok, the changes to use kotlinx.serialization instead of GSON are working well for me. You can see in the logs that there are no nulls now for the different data types and the default values are preserved

07-03 14:02:57.383 26562 26812 D org.getlantern.lantern.model.LanternSessionManager: Storing user data ProUser(userId=372788064, token=BBsWlZSW3, referral=8YXDWM, email=, userStatus=, code=8YXDWM, locale=en_US, subscription=, expiration=0, devices=[], userLevel=)
07-03 14:02:57.461 26562 26806 D MainActivity: Successfully fetched payment methods with payment methods: [PaymentMethods(method=CreditCard, providers=[ProviderInfo(name=Stripe, data={pubKey=xx}, logoUrl=[https://imagedelivery.net/sB6Q2DOuXQsFvrpwTks_kA/e02a8c29-20a6-478f-ed01-e93d0dba0800/public, https://imagedelivery.net/sB6Q2DOuXQsFvrpwTks_kA/94870838-0129-417c-d65a-276422eac900/public, https://imagedelivery.net/sB6Q2DOuXQsFvrpwTks_kA/f56ce1a8-96d6-4528-fdc6-da4605f1c500/public])])] and plans {1y-usd-10=ProPlan(id=1y-usd-10, description=One Year Plan, price={usd=4800}, priceWithoutTax={}, bestValue=false, duration={days=0, months=0, years=1}, discount=0.0, renewalBonusExpected={days=0, months=0}, expectedMonthlyPrice={usd=400}, renewalText=, totalCost=$48, currencyCode=usd, oneMonthCost=$4.00), 2y-usd-10=ProPlan(id=2y-usd-10, description=Two Year Plan, price={usd=8700}, priceWithoutTax={}, bestValue=true, duration={days=0, months=0, years=2}, discount=0.0925, renewalBonusExpected={days=0, months=0}, expectedMonthlyPrice={usd=363}, renewalText=, totalCost=$87, currencyCode=usd, oneMonthCost=$3.63)}

Do you wanna take it for a spin and see how it works for you?

@atavism atavism requested a review from jigar-f July 3, 2024 21:11
@atavism
Copy link
Contributor Author

atavism commented Jul 3, 2024

@atavism I think you know better on this, So the issue is this events never gets a callback, It only gets callbacks when user install the app for the first time After that is never callback,

Supported currencies should be updated after Lantern starts now

@jigar-f
Copy link
Contributor

jigar-f commented Jul 4, 2024

@atavism Taking a look now

android/settings.gradle Outdated Show resolved Hide resolved
cb.onSuccess(response!!, user)
} catch (e: SerializationException) {
// If for some reason we get error return user with basic string
Logger.error(TAG, "Unable to parse user from JSON", e)
Copy link
Contributor

Choose a reason for hiding this comment

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

So I found that is you pass devices as null then you still crash, So I added this, so even if we get an exception we catch it and then return some basic details, So at least the app does not crash.

Copy link
Contributor Author

@atavism atavism Jul 4, 2024

Choose a reason for hiding this comment

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

To test this, I set devices to null in the user data JSON response, and another exception is thrown in the catch block (it looks like the email is missing):

07-04 07:21:42.640  1501  1790 E AndroidRuntime: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String com.google.gson.JsonElement.getAsString()' on a null object reference
07-04 07:21:42.640  1501  1790 E AndroidRuntime: 	at org.getlantern.lantern.model.LanternHttpClient$userData$1.onSuccess(LanternHttpClient.kt:104)
07-04 07:21:42.640  1501  1790 E AndroidRuntime: 	at org.getlantern.lantern.model.LanternHttpClient$proRequest$1.onResponse(LanternHttpClient.kt:321)
07-04 07:21:42.640  1501  1790 E AndroidRuntime: 	at okhttp3.internal.connection.RealCall$AsyncCall.run(RealCall.kt:519)
07-04 07:21:42.640  1501  1790 E AndroidRuntime: 	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
07-04 07:21:42.640  1501  1790 E AndroidRuntime: 	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:644)
07-04 07:21:42.640  1501  1790 E AndroidRuntime: 	at java.lang.Thread.run(Thread.java:1012)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jigar-f What do you think of this change to add and make use of a tryParseJson utility method that catches and logs any exception? #1117

@jigar-f
Copy link
Contributor

jigar-f commented Jul 4, 2024

@atavism Added a more few changes on top of your changes, Do take look at them and let me know, I am happy to merge this and upload the build. Let me know.

@atavism
Copy link
Contributor Author

atavism commented Jul 4, 2024

@atavism Added a more few changes on top of your changes, Do take look at them and let me know, I am happy to merge this and upload the build. Let me know.

Thanks for making these changes! I just had a quick follow-up PR but LGTM otherwise #1117

@jigar-f
Copy link
Contributor

jigar-f commented Jul 4, 2024

@atavism Also if all changes look good, You can go ahead and merge, if needed you can upload the build as well,

@atavism
Copy link
Contributor Author

atavism commented Jul 4, 2024

Thanks, @jigar-f! Yep, the changes here LGTM. I will put out a 7.8.9 release today

* Add tryParseJson utility method

* formatting
@atavism atavism merged commit 042186e into main Jul 4, 2024
1 check passed
@atavism atavism deleted the atavism/prouser-default-values branch July 4, 2024 16:51
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