Skip to content

Send files directly between devices over the internet - no cloud storage, no size limits.

fix the code screen after a store purchase

Denis Lupookov4ec658e7602c
diff --git a/packages/domain/src/account/runtime/purchaseFlow.test.ts b/packages/domain/src/account/runtime/purchaseFlow.test.ts
index 4f2f3b0..4d58015 100644
--- a/packages/domain/src/account/runtime/purchaseFlow.test.ts
+++ b/packages/domain/src/account/runtime/purchaseFlow.test.ts
@@ -102,11 +102,19 @@ describe('restoreFromStore', () => {
})
describe('buyFromStore', () => {
+ it('leaves the paywall before the store sheet opens', async () => {
+ const { ctx, actions } = makeContext({ stored: 'kept-code' })
+
+ await buyFromStore(ctx, { code: 'kept-code', fresh: false }, 'monthly')
+
+ expect(actions[0]?.type).toBe('upgrading')
+ })
+
it('waits for the entitlement instead of claiming success', async () => {
const { ctx, actions, polled } = makeContext({ stored: 'kept-code', active: false })
expect(await buyFromStore(ctx, { code: 'kept-code', fresh: false }, 'monthly')).toBe(true)
- expect(actions.map((a) => a.type)).toEqual(['awaitingApproval'])
+ expect(actions.map((a) => a.type)).toEqual(['upgrading', 'awaitingApproval'])
expect(polled).toEqual(['kept-code'])
})
@@ -114,7 +122,7 @@ describe('buyFromStore', () => {
const { ctx, actions, polled } = makeContext({ stored: 'kept-code' })
expect(await buyFromStore(ctx, { code: 'kept-code', fresh: false }, 'monthly')).toBe(true)
- expect(actions.map((a) => a.type)).toEqual(['purchased'])
+ expect(actions.map((a) => a.type)).toEqual(['upgrading', 'purchased'])
expect(polled).toEqual([])
})
})
diff --git a/packages/domain/src/account/runtime/purchaseFlow.ts b/packages/domain/src/account/runtime/purchaseFlow.ts
index ab1871d..c7b8e82 100644
--- a/packages/domain/src/account/runtime/purchaseFlow.ts
+++ b/packages/domain/src/account/runtime/purchaseFlow.ts
@@ -39,7 +39,10 @@ export async function reserveCode(ctx: PurchaseContext): Promise<ReservedCode> {
}
export async function abandon(ctx: PurchaseContext, reserved: ReservedCode): Promise<void> {
- if (!reserved.fresh) return
+ if (!reserved.fresh) {
+ ctx.dispatch({ type: 'showPaywall' })
+ return
+ }
const status = await ctx.client.status(reserved.code).catch((err) => {
warn('status check before discard failed', err)
@@ -94,6 +97,8 @@ export async function buyFromStore(
if (!purchases) return false
const { code } = reserved
+
+ ctx.dispatch({ type: 'upgrading', account: { code, validUntil: null } })
await purchases.identify(code)
const outcome = await purchases.buy(plan)