diff --git a/src/components/PushBanner/QuotaBanner.jsx b/src/components/PushBanner/QuotaBanner.jsx
index ffda48c0..063311bb 100644
--- a/src/components/PushBanner/QuotaBanner.jsx
+++ b/src/components/PushBanner/QuotaBanner.jsx
@@ -1,4 +1,4 @@
-import React from 'react'
+import React, { useEffect, useState } from 'react'
import CloudSyncIcon from 'cozy-ui/transpiled/react/Icons/CloudSync'
import Banner from 'cozy-ui/transpiled/react/Banner'
@@ -12,6 +12,7 @@ import {
} from 'cozy-client/dist/models/instance'
import flag from 'cozy-flags'
import { useInstanceInfo } from 'cozy-client'
+import { useWebviewIntent } from 'cozy-intent'
import styles from '../pushClient/pushClient.styl'
import { usePushBannerContext } from './PushBannerProvider'
@@ -23,6 +24,21 @@ const QuotaBanner = () => {
const { t } = useI18n()
const { dismissPushBanner } = usePushBannerContext()
const instanceInfo = useInstanceInfo()
+ const webviewIntent = useWebviewIntent()
+ const [hasIAP, setIAP] = useState(false)
+
+ useEffect(() => {
+ const fetchIapAvailability = async () => {
+ const isAvailable =
+ (await webviewIntent?.call('isAvailable', 'iap')) ?? false
+ const isEnabled = !!flag('flagship.iap.enabled')
+ setIAP(isAvailable && isEnabled)
+ }
+
+ if (isFlagshipApp()) {
+ fetchIapAvailability()
+ }
+ }, [webviewIntent])
const onAction = () => {
const link = buildPremiumLink(instanceInfo)
@@ -34,8 +50,7 @@ const QuotaBanner = () => {
}
const canOpenPremiumLink =
- arePremiumLinksEnabled(instanceInfo) &&
- (!isFlagshipApp() || (isFlagshipApp() && !!flag('flagship.iap.enabled')))
+ arePremiumLinksEnabled(instanceInfo) && (!isFlagshipApp() || hasIAP)
return (
diff --git a/src/components/PushBanner/QuotaBanner.spec.jsx b/src/components/PushBanner/QuotaBanner.spec.jsx
index 50144762..eba3b909 100644
--- a/src/components/PushBanner/QuotaBanner.spec.jsx
+++ b/src/components/PushBanner/QuotaBanner.spec.jsx
@@ -5,6 +5,7 @@ import { isFlagshipApp } from 'cozy-device-helper'
import I18n from 'cozy-ui/transpiled/react/providers/I18n'
import flag from 'cozy-flags'
import { useInstanceInfo } from 'cozy-client'
+import { useWebviewIntent } from 'cozy-intent'
import QuotaBanner from './QuotaBanner'
import { usePushBannerContext } from './PushBannerProvider'
@@ -24,6 +25,10 @@ jest.mock('cozy-client', () => ({
isLoaded: true
}))
}))
+jest.mock('cozy-intent', () => ({
+ ...jest.requireActual('cozy-intent'),
+ useWebviewIntent: jest.fn()
+}))
describe('QuotaBanner', () => {
const dismissSpy = jest.fn()
@@ -37,7 +42,8 @@ describe('QuotaBanner', () => {
enablePremiumLinks = false,
hasUuid = false,
isFlagshipApp: isFlagshipAppReturnValue = false,
- isIapEnabled = null
+ isIapEnabled = null,
+ isIapAvailable = null
} = {}) => {
usePushBannerContext.mockReturnValue({
dismissPushBanner: dismissSpy
@@ -61,6 +67,10 @@ describe('QuotaBanner', () => {
isFlagshipApp.mockReturnValue(isFlagshipAppReturnValue)
flag.mockReturnValue(isIapEnabled)
+ const mockCall = jest.fn().mockResolvedValue(isIapAvailable)
+ useWebviewIntent.mockReturnValue({
+ call: mockCall
+ })
render(
en}>
@@ -112,27 +122,44 @@ describe('QuotaBanner', () => {
expect(premiumButton).toBeNull()
})
- it('should hide premium link when is on flagship application and flag flagship.iap.enabled is false', () => {
+ it('should hide premium link when the flagship app has not IAP available with the flag flagship.iap.enabled is false', () => {
setup({
hasUuid: true,
enablePremiumLinks: true,
isFlagshipApp: true,
- isIapEnabled: false
+ isIapEnabled: false,
+ isIapAvailable: false
})
const premiumButton = screen.queryByText('Check our plans')
expect(premiumButton).toBeNull()
})
- it('should display premium link when is on flagship application and flag flagship.iap.enabled is true', () => {
+ it('should hide premium link when the flagship app has not IAP available with the flag flagship.iap.enabled is true', () => {
setup({
hasUuid: true,
enablePremiumLinks: true,
isFlagshipApp: true,
- isIapEnabled: true
+ isIapEnabled: true,
+ isIapAvailable: false
})
- fireEvent.click(screen.getByText('Check our plans'))
+ const premiumButton = screen.queryByText('Check our plans')
+ expect(premiumButton).toBeNull()
+ })
+
+ it('should display premium link when the flagship app has IAP available with the flag flagship.iap.enabled is true', async () => {
+ setup({
+ hasUuid: true,
+ enablePremiumLinks: true,
+ isFlagshipApp: true,
+ isIapEnabled: true,
+ isIapAvailable: true
+ })
+
+ const actionButton = await screen.findByText('Check our plans')
+
+ fireEvent.click(actionButton)
expect(openSpy).toBeCalledWith(
'http://mycozy.cloud/cozy/instances/123/premium',
'_self'