mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-29 08:00:06 +00:00
fix(native): a store account with a running TREK Cloud subscription buys no second one
One subscription per Apple ID or Google account. Choosing another plan in the app changed the running subscription on the App Store, and the redeem then failed with 'We could not set up your TREK'. The app now asks the store first and shows a screen of its own: the account already has TREK Cloud, a new one can be taken out once it has ended, with Open my TREK and the store's page to manage it. The native purchase refuses as well; a paid one that was never set up is still redeemed. On the address screens the link 'What is a TREK server?' is gone, and the small print under a purchase is set in the system text face at regular weight.
This commit is contained in:
@@ -15,8 +15,9 @@ import {
|
||||
CLOUD_TERMS_URL,
|
||||
CLOUD_URL,
|
||||
PRIVACY_URL,
|
||||
SERVER_DOCS_URL,
|
||||
STORE_TERMS_URL,
|
||||
APP_STORE_SUBSCRIPTIONS_URL,
|
||||
PLAY_SUBSCRIPTIONS_URL,
|
||||
} from '../src/native/links';
|
||||
import {
|
||||
certificateTargetFor,
|
||||
@@ -268,7 +269,7 @@ function showWelcome(opts: { back?: boolean } = {}): void {
|
||||
el('h1', { className: 'title brand-title' }, t('native.welcome.headline')),
|
||||
el('p', { className: 'sub' }, t('native.welcome.sub')),
|
||||
],
|
||||
[cloud, connect, demo, footLinks(externalLink(t('native.connect.whatIsServer'), SERVER_DOCS_URL))]
|
||||
[cloud, connect, demo, footLinks()]
|
||||
)
|
||||
),
|
||||
opts
|
||||
@@ -382,7 +383,7 @@ function showConnect(prefill = '', opts: { back?: boolean; recheck?: boolean } =
|
||||
el('h1', { className: 'title-sm' }, t('native.connect.title')),
|
||||
el('p', { className: 'sub' }, t(opts.recheck ? 'native.connect.recheckHint' : 'native.connect.hint')),
|
||||
],
|
||||
[form, addCert, footLinks(externalLink(t('native.connect.whatIsServer'), SERVER_DOCS_URL))]
|
||||
[form, addCert, footLinks()]
|
||||
)
|
||||
),
|
||||
opts
|
||||
@@ -660,10 +661,16 @@ function planCard(plan: CloudPlan, interval: 'month' | 'year', offer: Offer): HT
|
||||
const featOff = (text: string) => el('span', { className: 'off' }, icon('M5 12h14', 16), text);
|
||||
let sub: HTMLElement | null = null;
|
||||
if (buyable) {
|
||||
sub = el('button', { type: 'button', className: 'btn' }, t('native.plans.subscribe'));
|
||||
sub.addEventListener('click', () => {
|
||||
const button = el('button', { type: 'button', className: 'btn' }, t('native.plans.subscribe'));
|
||||
sub = button;
|
||||
button.addEventListener('click', async () => {
|
||||
void tap(ImpactStyle.Medium);
|
||||
showClaim(plan, interval, `${label} ${per}`);
|
||||
// A store account with a running subscription buys nothing more: say so before the form.
|
||||
button.disabled = true;
|
||||
const held = await iap.held();
|
||||
button.disabled = false;
|
||||
if (held) showSubscribed();
|
||||
else showClaim(plan, interval, `${label} ${per}`);
|
||||
});
|
||||
}
|
||||
return el(
|
||||
@@ -1157,6 +1164,10 @@ function showClaim(
|
||||
error.textContent = t('native.claim.failed');
|
||||
return;
|
||||
}
|
||||
if (outcome.kind === 'subscribed') {
|
||||
showSubscribed();
|
||||
return;
|
||||
}
|
||||
bought = outcome.purchase;
|
||||
}
|
||||
|
||||
@@ -1206,6 +1217,51 @@ function showClaim(
|
||||
requestAnimationFrame(() => slugInput.focus());
|
||||
}
|
||||
|
||||
/**
|
||||
* The store account already holds a TREK Cloud subscription: one per Apple ID or
|
||||
* Google account. Another plan would change it on the App Store and run beside
|
||||
* it on Google Play, so the app buys nothing and says why. Offered instead: the
|
||||
* TREK the subscription belongs to, and the store's own page to manage or end
|
||||
* it. Once it has ended, a new one can be taken out, at a new address too.
|
||||
*/
|
||||
function showSubscribed(): void {
|
||||
void notify(NotificationType.Warning);
|
||||
const status = el('p', { className: 'hint', role: 'status' });
|
||||
const open = el('button', { type: 'button', className: 'btn' }, t('native.subscribed.open'));
|
||||
open.addEventListener('click', async () => {
|
||||
void tap(ImpactStyle.Medium);
|
||||
open.disabled = true;
|
||||
status.className = 'hint';
|
||||
status.textContent = t('native.plans.restoring');
|
||||
const purchase = await iap.restore();
|
||||
const redeemed = purchase ? await redeemPurchase('', '', purchase) : null;
|
||||
if (purchase && redeemed?.ok && redeemed.instanceUrl) {
|
||||
await iap.finish(purchase);
|
||||
showProvisioning(redeemed.instanceUrl);
|
||||
return;
|
||||
}
|
||||
void notify(NotificationType.Error);
|
||||
open.disabled = false;
|
||||
status.className = 'hint bad';
|
||||
status.textContent = t('native.plans.restoreFailed');
|
||||
});
|
||||
const manage = externalLink(t('native.subscribed.manage'), onPlay ? PLAY_SUBSCRIPTIONS_URL : APP_STORE_SUBSCRIPTIONS_URL);
|
||||
show(
|
||||
el(
|
||||
'div',
|
||||
{},
|
||||
...columns(
|
||||
[
|
||||
topbar(() => showPlans({ back: true })),
|
||||
el('h1', { className: 'title-sm' }, t('native.subscribed.title')),
|
||||
el('p', { className: 'sub' }, t(onPlay ? 'native.subscribed.textAndroid' : 'native.subscribed.text')),
|
||||
],
|
||||
[open, status, el('div', { className: 'foot-links' }, manage)]
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/** The build runs on the server; the app waits on the new address and loads it the moment it answers. */
|
||||
function showProvisioning(instanceUrl: string, welcome?: string): void {
|
||||
const host = (() => {
|
||||
|
||||
@@ -1058,12 +1058,20 @@ a.linkbtn {
|
||||
border-color: var(--edge-strong);
|
||||
border-top-color: var(--ink);
|
||||
}
|
||||
/* Small print (the terms a purchase is under, how it renews): in the system's
|
||||
own text face at its regular weight. Poppins ships from 500 up only, which
|
||||
made a paragraph of legal text read as heavy as a heading. */
|
||||
.note {
|
||||
text-align: center;
|
||||
color: var(--faint);
|
||||
font-size: 0.84rem;
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', Roboto, system-ui, sans-serif;
|
||||
font-weight: 400;
|
||||
font-size: 0.76rem;
|
||||
margin: 2px 0 0;
|
||||
line-height: 1.45;
|
||||
line-height: 1.5;
|
||||
}
|
||||
.note a {
|
||||
color: var(--muted);
|
||||
}
|
||||
/* Under the plans: restore, the renewal terms, the legal links. */
|
||||
.plans-foot {
|
||||
|
||||
Reference in New Issue
Block a user