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: Handle planId parameter in startIap url, pass language code to Cloudery and improve IAP #1131

Merged
merged 3 commits into from
Jan 16, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions src/app/view/IAP/hooks/useClouderyOffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Dispatch, SetStateAction, useEffect, useState } from 'react'
import { Platform } from 'react-native'
import { initConnection, useIAP } from 'react-native-iap'
import { getLocales } from 'react-native-localize'
import Toast from 'react-native-toast-message'
import type { WebViewNavigation } from 'react-native-webview/lib/WebViewTypes'

import { useClient, useInstanceInfo } from 'cozy-client'
Expand All @@ -14,6 +15,8 @@ import {
buySubscription,
formatOffers
} from '/app/domain/iap/services/clouderyOffer'
import { getErrorMessage } from '/libs/functions/getErrorMessage'
import { t } from '/locales/i18n'

const log = Minilog('💳 Cloudery Offer')

Expand Down Expand Up @@ -94,9 +97,20 @@ export const useClouderyOffer = (): ClouderyOfferState => {
}

const doAsync = async (): Promise<void> => {
await initConnection()
await getSubscriptions({ skus: SKUS })
setPartialPopupUrl(current => current ?? href)
try {
await initConnection()
await getSubscriptions({ skus: SKUS })
setPartialPopupUrl(current => current ?? href)
} catch (error: unknown) {
const errorMessage = getErrorMessage(error)
Copy link
Contributor

@zatteo zatteo Jan 16, 2024

Choose a reason for hiding this comment

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

:o I finally understood the purpose of getErrorMessage. I will use it in backup feature...

log.error(
`Error while analysing WebView navigation. Intercept it anyway to prevent unexpected behavior: ${errorMessage}`
)
Toast.show({
text1: t('screens.clouderyOffer.error.title'),
type: 'error'
})
}
}

void doAsync()
Expand Down
Loading