mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-02 17:26:24 +00:00
Recheck the agreement before opening the store purchase sheet [skip ci]
This commit is contained in:
+28
-12
@@ -7,7 +7,14 @@ import { PASSWORD_MIN_LENGTH, passwordProblem, passwordRuleStates } from '../../
|
||||
import logoWhite from '../public/logo-light.svg'; // #fff wordmark, for the landscape
|
||||
import { pageUnderStatusBar } from '../src/native/appBoot';
|
||||
import { AUTH_GATE_NAMES, canSignInInApp, type AuthGate } from '../src/native/authGate';
|
||||
import { isNewCloudPlan, opensSoon, planForUnclaimedPurchase, refundedBeforeOpening } from '../src/native/cloudOrders';
|
||||
import {
|
||||
isNewCloudPlan,
|
||||
matchesPurchaseAgreement,
|
||||
opensSoon,
|
||||
planForUnclaimedPurchase,
|
||||
refundedBeforeOpening,
|
||||
type CloudPurchaseAgreement,
|
||||
} from '../src/native/cloudOrders';
|
||||
import { fakeIapClient, getIapClient, productIdFor, type IapProduct, type Purchase } from '../src/native/iap';
|
||||
import {
|
||||
APP_STORE_SUBSCRIPTIONS_URL,
|
||||
@@ -1126,11 +1133,7 @@ async function slugStatus(slug: string): Promise<SlugStatus> {
|
||||
* (terms § 2 (1a), § 327h BGB), as the control plane words and versions it. The
|
||||
* app shows the server's text, never its own, and sends back the version it showed.
|
||||
*/
|
||||
interface DeviationsConsent {
|
||||
version: string;
|
||||
text: string;
|
||||
}
|
||||
async function fetchConsent(): Promise<DeviationsConsent | null> {
|
||||
async function fetchConsent(): Promise<CloudPurchaseAgreement | null> {
|
||||
try {
|
||||
const res = await CapacitorHttp.get({
|
||||
url: `${CLOUD_URL}/api/iap/consent`,
|
||||
@@ -1285,7 +1288,7 @@ function showClaim(
|
||||
};
|
||||
|
||||
// The § 327h agreement, asked on its own before anything is bought.
|
||||
let consent: DeviationsConsent | null = null;
|
||||
let consent: CloudPurchaseAgreement | null = null;
|
||||
const consentBox = el('input', { type: 'checkbox' });
|
||||
const consentText = el('span', { className: 'consent-text' }, t('native.claim.consentLoading'));
|
||||
const consentField = el(
|
||||
@@ -1294,13 +1297,16 @@ function showClaim(
|
||||
consentBox,
|
||||
el('span', {}, el('strong', {}, t('native.claim.consentTitle')), consentText)
|
||||
);
|
||||
const loadConsent = async (): Promise<DeviationsConsent | null> => {
|
||||
const showConsent = (current: CloudPurchaseAgreement | null): void => {
|
||||
consent = current;
|
||||
consentBox.checked = false;
|
||||
consentBox.disabled = true;
|
||||
consentText.textContent = t('native.claim.consentLoading');
|
||||
consent = await fetchConsent();
|
||||
consentBox.disabled = consent === null;
|
||||
consentText.textContent = consent ? consent.text : t('native.claim.consentUnavailable');
|
||||
};
|
||||
const loadConsent = async (): Promise<CloudPurchaseAgreement | null> => {
|
||||
consentBox.disabled = true;
|
||||
consentText.textContent = t('native.claim.consentLoading');
|
||||
showConsent(await fetchConsent());
|
||||
return consent;
|
||||
};
|
||||
void loadConsent();
|
||||
@@ -1453,7 +1459,8 @@ function showClaim(
|
||||
consentBox.focus();
|
||||
return;
|
||||
}
|
||||
const consentVersion = consent ? consent.version : null;
|
||||
const acceptedConsent = consent;
|
||||
const consentVersion = acceptedConsent?.version ?? null;
|
||||
|
||||
void tap(ImpactStyle.Medium);
|
||||
// The purchase sheet and the progress want the whole screen, not the keyboard.
|
||||
@@ -1473,6 +1480,15 @@ function showClaim(
|
||||
};
|
||||
|
||||
if (!bought) {
|
||||
const currentConsent = await fetchConsent();
|
||||
if (!form.isConnected) return;
|
||||
if (!matchesPurchaseAgreement(acceptedConsent, currentConsent)) {
|
||||
restore();
|
||||
showConsent(currentConsent);
|
||||
setNotice(error, t(currentConsent ? 'native.claim.consentRequired' : 'native.claim.consentUnavailable'));
|
||||
if (currentConsent) consentBox.focus();
|
||||
return;
|
||||
}
|
||||
const trialRenewalPrice = opts.freeTrial ? priceLabel : undefined;
|
||||
const outcome = await iap.purchase(productIdFor(plan.id, interval), trialRenewalPrice);
|
||||
if (outcome.kind === 'offer-changed') {
|
||||
|
||||
Reference in New Issue
Block a user