feat: iap (#1996)
This commit is contained in:
BIN
.yarn/cache/react-native-iap-npm-12.4.4-a063846c19-f5c71ba006.zip
vendored
Normal file
BIN
.yarn/cache/react-native-iap-npm-12.4.4-a063846c19-f5c71ba006.zip
vendored
Normal file
Binary file not shown.
@@ -3,4 +3,5 @@ export enum SubscriptionApiOperations {
|
|||||||
CancelingInvite,
|
CancelingInvite,
|
||||||
ListingInvites,
|
ListingInvites,
|
||||||
AcceptingInvite,
|
AcceptingInvite,
|
||||||
|
ConfirmAppleIAP,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,8 @@ import { SubscriptionInviteAcceptResponse } from '../../Response/Subscription/Su
|
|||||||
import { SubscriptionApiServiceInterface } from './SubscriptionApiServiceInterface'
|
import { SubscriptionApiServiceInterface } from './SubscriptionApiServiceInterface'
|
||||||
import { SubscriptionApiOperations } from './SubscriptionApiOperations'
|
import { SubscriptionApiOperations } from './SubscriptionApiOperations'
|
||||||
import { Uuid } from '@standardnotes/common'
|
import { Uuid } from '@standardnotes/common'
|
||||||
|
import { AppleIAPConfirmResponse } from './../../Response/Subscription/AppleIAPConfirmResponse'
|
||||||
|
import { AppleIAPConfirmRequestParams } from '../../Request'
|
||||||
|
|
||||||
export class SubscriptionApiService implements SubscriptionApiServiceInterface {
|
export class SubscriptionApiService implements SubscriptionApiServiceInterface {
|
||||||
private operationsInProgress: Map<SubscriptionApiOperations, boolean>
|
private operationsInProgress: Map<SubscriptionApiOperations, boolean>
|
||||||
@@ -31,11 +33,11 @@ export class SubscriptionApiService implements SubscriptionApiServiceInterface {
|
|||||||
[ApiEndpointParam.ApiVersion]: ApiVersion.v0,
|
[ApiEndpointParam.ApiVersion]: ApiVersion.v0,
|
||||||
})
|
})
|
||||||
|
|
||||||
this.operationsInProgress.set(SubscriptionApiOperations.ListingInvites, false)
|
|
||||||
|
|
||||||
return response
|
return response
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new ApiCallError(ErrorMessage.GenericFail)
|
throw new ApiCallError(ErrorMessage.GenericFail)
|
||||||
|
} finally {
|
||||||
|
this.operationsInProgress.set(SubscriptionApiOperations.ListingInvites, false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -52,11 +54,11 @@ export class SubscriptionApiService implements SubscriptionApiServiceInterface {
|
|||||||
inviteUuid,
|
inviteUuid,
|
||||||
})
|
})
|
||||||
|
|
||||||
this.operationsInProgress.set(SubscriptionApiOperations.CancelingInvite, false)
|
|
||||||
|
|
||||||
return response
|
return response
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new ApiCallError(ErrorMessage.GenericFail)
|
throw new ApiCallError(ErrorMessage.GenericFail)
|
||||||
|
} finally {
|
||||||
|
this.operationsInProgress.set(SubscriptionApiOperations.CancelingInvite, false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -73,11 +75,11 @@ export class SubscriptionApiService implements SubscriptionApiServiceInterface {
|
|||||||
identifier: inviteeEmail,
|
identifier: inviteeEmail,
|
||||||
})
|
})
|
||||||
|
|
||||||
this.operationsInProgress.set(SubscriptionApiOperations.Inviting, false)
|
|
||||||
|
|
||||||
return response
|
return response
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new ApiCallError(ErrorMessage.GenericFail)
|
throw new ApiCallError(ErrorMessage.GenericFail)
|
||||||
|
} finally {
|
||||||
|
this.operationsInProgress.set(SubscriptionApiOperations.Inviting, false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -93,11 +95,27 @@ export class SubscriptionApiService implements SubscriptionApiServiceInterface {
|
|||||||
inviteUuid,
|
inviteUuid,
|
||||||
})
|
})
|
||||||
|
|
||||||
this.operationsInProgress.set(SubscriptionApiOperations.AcceptingInvite, false)
|
|
||||||
|
|
||||||
return response
|
return response
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new ApiCallError(ErrorMessage.GenericFail)
|
throw new ApiCallError(ErrorMessage.GenericFail)
|
||||||
|
} finally {
|
||||||
|
this.operationsInProgress.set(SubscriptionApiOperations.AcceptingInvite, false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async confirmAppleIAP(params: AppleIAPConfirmRequestParams): Promise<AppleIAPConfirmResponse> {
|
||||||
|
if (this.operationsInProgress.get(SubscriptionApiOperations.ConfirmAppleIAP)) {
|
||||||
|
throw new ApiCallError(ErrorMessage.GenericInProgress)
|
||||||
|
}
|
||||||
|
|
||||||
|
this.operationsInProgress.set(SubscriptionApiOperations.ConfirmAppleIAP, true)
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await this.subscriptionServer.confirmAppleIAP(params)
|
||||||
|
|
||||||
|
return response
|
||||||
|
} finally {
|
||||||
|
this.operationsInProgress.set(SubscriptionApiOperations.ConfirmAppleIAP, false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
import { Uuid } from '@standardnotes/common'
|
import { Uuid } from '@standardnotes/common'
|
||||||
|
|
||||||
|
import { AppleIAPConfirmResponse } from './../../Response/Subscription/AppleIAPConfirmResponse'
|
||||||
|
import { AppleIAPConfirmRequestParams } from '../../Request'
|
||||||
import { SubscriptionInviteAcceptResponse } from '../../Response/Subscription/SubscriptionInviteAcceptResponse'
|
import { SubscriptionInviteAcceptResponse } from '../../Response/Subscription/SubscriptionInviteAcceptResponse'
|
||||||
import { SubscriptionInviteCancelResponse } from '../../Response/Subscription/SubscriptionInviteCancelResponse'
|
import { SubscriptionInviteCancelResponse } from '../../Response/Subscription/SubscriptionInviteCancelResponse'
|
||||||
import { SubscriptionInviteListResponse } from '../../Response/Subscription/SubscriptionInviteListResponse'
|
import { SubscriptionInviteListResponse } from '../../Response/Subscription/SubscriptionInviteListResponse'
|
||||||
@@ -10,4 +12,5 @@ export interface SubscriptionApiServiceInterface {
|
|||||||
listInvites(): Promise<SubscriptionInviteListResponse>
|
listInvites(): Promise<SubscriptionInviteListResponse>
|
||||||
cancelInvite(inviteUuid: Uuid): Promise<SubscriptionInviteCancelResponse>
|
cancelInvite(inviteUuid: Uuid): Promise<SubscriptionInviteCancelResponse>
|
||||||
acceptInvite(inviteUuid: Uuid): Promise<SubscriptionInviteAcceptResponse>
|
acceptInvite(inviteUuid: Uuid): Promise<SubscriptionInviteAcceptResponse>
|
||||||
|
confirmAppleIAP(params: AppleIAPConfirmRequestParams): Promise<AppleIAPConfirmResponse>
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,11 @@ describe('HttpService', () => {
|
|||||||
const host = 'http://bar'
|
const host = 'http://bar'
|
||||||
let updateMetaCallback: (meta: HttpResponseMeta) => void
|
let updateMetaCallback: (meta: HttpResponseMeta) => void
|
||||||
|
|
||||||
const createService = () => new HttpService(environment, appVersion, snjsVersion, host, updateMetaCallback)
|
const createService = () => {
|
||||||
|
const service = new HttpService(environment, appVersion, snjsVersion, updateMetaCallback)
|
||||||
|
service.setHost(host)
|
||||||
|
return service
|
||||||
|
}
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
updateMetaCallback = jest.fn()
|
updateMetaCallback = jest.fn()
|
||||||
|
|||||||
@@ -14,12 +14,12 @@ import { HttpErrorResponseBody } from './HttpErrorResponseBody'
|
|||||||
export class HttpService implements HttpServiceInterface {
|
export class HttpService implements HttpServiceInterface {
|
||||||
private authorizationToken?: string
|
private authorizationToken?: string
|
||||||
private __latencySimulatorMs?: number
|
private __latencySimulatorMs?: number
|
||||||
|
private host!: string
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private environment: Environment,
|
private environment: Environment,
|
||||||
private appVersion: string,
|
private appVersion: string,
|
||||||
private snjsVersion: string,
|
private snjsVersion: string,
|
||||||
private host: string,
|
|
||||||
private updateMetaCallback: (meta: HttpResponseMeta) => void,
|
private updateMetaCallback: (meta: HttpResponseMeta) => void,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
export type AppleIAPConfirmRequestParams = {
|
||||||
|
productId: string
|
||||||
|
transactionId: string
|
||||||
|
transactionDate: string
|
||||||
|
transactionReceipt: string
|
||||||
|
subscription_token: string
|
||||||
|
}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
export * from './ApiEndpointParam'
|
export * from './ApiEndpointParam'
|
||||||
|
export * from './Subscription/AppleIAPConfirmRequestParams'
|
||||||
export * from './Subscription/SubscriptionInviteAcceptRequestParams'
|
export * from './Subscription/SubscriptionInviteAcceptRequestParams'
|
||||||
export * from './Subscription/SubscriptionInviteCancelRequestParams'
|
export * from './Subscription/SubscriptionInviteCancelRequestParams'
|
||||||
export * from './Subscription/SubscriptionInviteDeclineRequestParams'
|
export * from './Subscription/SubscriptionInviteDeclineRequestParams'
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
import { Either } from '@standardnotes/common'
|
||||||
|
|
||||||
|
import { HttpErrorResponseBody } from '../../Http/HttpErrorResponseBody'
|
||||||
|
import { HttpResponse } from '../../Http/HttpResponse'
|
||||||
|
import { AppleIAPConfirmResponseBody } from './AppleIAPConfirmResponseBody'
|
||||||
|
|
||||||
|
export interface AppleIAPConfirmResponse extends HttpResponse {
|
||||||
|
data: Either<AppleIAPConfirmResponseBody, HttpErrorResponseBody>
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
export type AppleIAPConfirmResponseBody = { success: true } | { success: false; message: string }
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
|
export * from './Subscription/AppleIAPConfirmResponse'
|
||||||
|
export * from './Subscription/AppleIAPConfirmResponseBody'
|
||||||
export * from './Subscription/SubscriptionInviteAcceptResponse'
|
export * from './Subscription/SubscriptionInviteAcceptResponse'
|
||||||
export * from './Subscription/SubscriptionInviteAcceptResponseBody'
|
export * from './Subscription/SubscriptionInviteAcceptResponseBody'
|
||||||
export * from './Subscription/SubscriptionInviteCancelResponse'
|
export * from './Subscription/SubscriptionInviteCancelResponse'
|
||||||
|
|||||||
@@ -8,8 +8,13 @@ const SharingPaths = {
|
|||||||
listInvites: '/v1/subscription-invites',
|
listInvites: '/v1/subscription-invites',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const ApplePaths = {
|
||||||
|
confirmAppleIAP: '/v1/subscriptions/apple_iap_confirm',
|
||||||
|
}
|
||||||
|
|
||||||
export const Paths = {
|
export const Paths = {
|
||||||
v1: {
|
v1: {
|
||||||
...SharingPaths,
|
...SharingPaths,
|
||||||
|
...ApplePaths,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
|
import { AppleIAPConfirmResponse } from './../../Response/Subscription/AppleIAPConfirmResponse'
|
||||||
import { HttpServiceInterface } from '../../Http/HttpServiceInterface'
|
import { HttpServiceInterface } from '../../Http/HttpServiceInterface'
|
||||||
|
import { AppleIAPConfirmRequestParams } from '../../Request'
|
||||||
import { SubscriptionInviteAcceptRequestParams } from '../../Request/Subscription/SubscriptionInviteAcceptRequestParams'
|
import { SubscriptionInviteAcceptRequestParams } from '../../Request/Subscription/SubscriptionInviteAcceptRequestParams'
|
||||||
import { SubscriptionInviteCancelRequestParams } from '../../Request/Subscription/SubscriptionInviteCancelRequestParams'
|
import { SubscriptionInviteCancelRequestParams } from '../../Request/Subscription/SubscriptionInviteCancelRequestParams'
|
||||||
import { SubscriptionInviteDeclineRequestParams } from '../../Request/Subscription/SubscriptionInviteDeclineRequestParams'
|
import { SubscriptionInviteDeclineRequestParams } from '../../Request/Subscription/SubscriptionInviteDeclineRequestParams'
|
||||||
@@ -45,4 +47,10 @@ export class SubscriptionServer implements SubscriptionServerInterface {
|
|||||||
|
|
||||||
return response as SubscriptionInviteResponse
|
return response as SubscriptionInviteResponse
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async confirmAppleIAP(params: AppleIAPConfirmRequestParams): Promise<AppleIAPConfirmResponse> {
|
||||||
|
const response = await this.httpService.post(Paths.v1.confirmAppleIAP, params)
|
||||||
|
|
||||||
|
return response as AppleIAPConfirmResponse
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import { AppleIAPConfirmResponse } from './../../Response/Subscription/AppleIAPConfirmResponse'
|
||||||
|
import { AppleIAPConfirmRequestParams } from './../../Request/Subscription/AppleIAPConfirmRequestParams'
|
||||||
import { SubscriptionInviteAcceptRequestParams } from '../../Request/Subscription/SubscriptionInviteAcceptRequestParams'
|
import { SubscriptionInviteAcceptRequestParams } from '../../Request/Subscription/SubscriptionInviteAcceptRequestParams'
|
||||||
import { SubscriptionInviteCancelRequestParams } from '../../Request/Subscription/SubscriptionInviteCancelRequestParams'
|
import { SubscriptionInviteCancelRequestParams } from '../../Request/Subscription/SubscriptionInviteCancelRequestParams'
|
||||||
import { SubscriptionInviteDeclineRequestParams } from '../../Request/Subscription/SubscriptionInviteDeclineRequestParams'
|
import { SubscriptionInviteDeclineRequestParams } from '../../Request/Subscription/SubscriptionInviteDeclineRequestParams'
|
||||||
@@ -15,4 +17,5 @@ export interface SubscriptionServerInterface {
|
|||||||
declineInvite(params: SubscriptionInviteDeclineRequestParams): Promise<SubscriptionInviteDeclineResponse>
|
declineInvite(params: SubscriptionInviteDeclineRequestParams): Promise<SubscriptionInviteDeclineResponse>
|
||||||
cancelInvite(params: SubscriptionInviteCancelRequestParams): Promise<SubscriptionInviteCancelResponse>
|
cancelInvite(params: SubscriptionInviteCancelRequestParams): Promise<SubscriptionInviteCancelResponse>
|
||||||
listInvites(params: SubscriptionInviteListRequestParams): Promise<SubscriptionInviteListResponse>
|
listInvites(params: SubscriptionInviteListRequestParams): Promise<SubscriptionInviteListResponse>
|
||||||
|
confirmAppleIAP(params: AppleIAPConfirmRequestParams): Promise<AppleIAPConfirmResponse>
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -349,6 +349,8 @@ PODS:
|
|||||||
- React-Core
|
- React-Core
|
||||||
- RNFS (2.20.0):
|
- RNFS (2.20.0):
|
||||||
- React-Core
|
- React-Core
|
||||||
|
- RNIap (12.4.4):
|
||||||
|
- React-Core
|
||||||
- RNKeychain (8.0.0):
|
- RNKeychain (8.0.0):
|
||||||
- React-Core
|
- React-Core
|
||||||
- RNPrivacySnapshot (1.0.0):
|
- RNPrivacySnapshot (1.0.0):
|
||||||
@@ -422,6 +424,7 @@ DEPENDENCIES:
|
|||||||
- "RNCAsyncStorage (from `../node_modules/@react-native-community/async-storage`)"
|
- "RNCAsyncStorage (from `../node_modules/@react-native-community/async-storage`)"
|
||||||
- RNFileViewer (from `../node_modules/react-native-file-viewer`)
|
- RNFileViewer (from `../node_modules/react-native-file-viewer`)
|
||||||
- RNFS (from `../node_modules/react-native-fs`)
|
- RNFS (from `../node_modules/react-native-fs`)
|
||||||
|
- RNIap (from `../node_modules/react-native-iap`)
|
||||||
- RNKeychain (from `../node_modules/react-native-keychain`)
|
- RNKeychain (from `../node_modules/react-native-keychain`)
|
||||||
- RNPrivacySnapshot (from `../node_modules/react-native-privacy-snapshot`)
|
- RNPrivacySnapshot (from `../node_modules/react-native-privacy-snapshot`)
|
||||||
- RNShare (from `../node_modules/react-native-share`)
|
- RNShare (from `../node_modules/react-native-share`)
|
||||||
@@ -518,6 +521,8 @@ EXTERNAL SOURCES:
|
|||||||
:path: "../node_modules/react-native-file-viewer"
|
:path: "../node_modules/react-native-file-viewer"
|
||||||
RNFS:
|
RNFS:
|
||||||
:path: "../node_modules/react-native-fs"
|
:path: "../node_modules/react-native-fs"
|
||||||
|
RNIap:
|
||||||
|
:path: "../node_modules/react-native-iap"
|
||||||
RNKeychain:
|
RNKeychain:
|
||||||
:path: "../node_modules/react-native-keychain"
|
:path: "../node_modules/react-native-keychain"
|
||||||
RNPrivacySnapshot:
|
RNPrivacySnapshot:
|
||||||
@@ -578,6 +583,7 @@ SPEC CHECKSUMS:
|
|||||||
RNCAsyncStorage: b03032fdbdb725bea0bd9e5ec5a7272865ae7398
|
RNCAsyncStorage: b03032fdbdb725bea0bd9e5ec5a7272865ae7398
|
||||||
RNFileViewer: ce7ca3ac370e18554d35d6355cffd7c30437c592
|
RNFileViewer: ce7ca3ac370e18554d35d6355cffd7c30437c592
|
||||||
RNFS: 4ac0f0ea233904cb798630b3c077808c06931688
|
RNFS: 4ac0f0ea233904cb798630b3c077808c06931688
|
||||||
|
RNIap: 3bcd6982cf99503339cf9243e4ba70a45ea2cf72
|
||||||
RNKeychain: 4f63aada75ebafd26f4bc2c670199461eab85d94
|
RNKeychain: 4f63aada75ebafd26f4bc2c670199461eab85d94
|
||||||
RNPrivacySnapshot: 8eaf571478a353f2e5184f5c803164f22428b023
|
RNPrivacySnapshot: 8eaf571478a353f2e5184f5c803164f22428b023
|
||||||
RNShare: a5dc3b9c53ddc73e155b8cd9a94c70c91913c43c
|
RNShare: a5dc3b9c53ddc73e155b8cd9a94c70c91913c43c
|
||||||
|
|||||||
@@ -14,6 +14,7 @@
|
|||||||
1C2EEB3B45F4EB07AC795C77 /* (null) in Frameworks */ = {isa = PBXBuildFile; };
|
1C2EEB3B45F4EB07AC795C77 /* (null) in Frameworks */ = {isa = PBXBuildFile; };
|
||||||
33BB1B14071EBE5978EBF3A8 /* libPods-StandardNotes-StandardNotesTests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 04FCB5A3A3387CA3CFC82AA3 /* libPods-StandardNotes-StandardNotesTests.a */; };
|
33BB1B14071EBE5978EBF3A8 /* libPods-StandardNotes-StandardNotesTests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 04FCB5A3A3387CA3CFC82AA3 /* libPods-StandardNotes-StandardNotesTests.a */; };
|
||||||
BC8DEA834BF198E8511F04FF /* libPods-StandardNotesDev.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 51F2D747BE02C2A1BCFEEFD1 /* libPods-StandardNotesDev.a */; };
|
BC8DEA834BF198E8511F04FF /* libPods-StandardNotesDev.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 51F2D747BE02C2A1BCFEEFD1 /* libPods-StandardNotesDev.a */; };
|
||||||
|
CD6592A9291EEFCC00C09DC6 /* StoreKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CD6592A8291EEFCC00C09DC6 /* StoreKit.framework */; };
|
||||||
CD7D5ECA27800609005FE1BF /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = CD7D5EC927800608005FE1BF /* LaunchScreen.storyboard */; };
|
CD7D5ECA27800609005FE1BF /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = CD7D5EC927800608005FE1BF /* LaunchScreen.storyboard */; };
|
||||||
CD7D5ECF278015D2005FE1BF /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 13B07FB01A68108700A75B9A /* AppDelegate.m */; };
|
CD7D5ECF278015D2005FE1BF /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 13B07FB01A68108700A75B9A /* AppDelegate.m */; };
|
||||||
CD7D5ED0278015D2005FE1BF /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 13B07FB71A68108700A75B9A /* main.m */; };
|
CD7D5ED0278015D2005FE1BF /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 13B07FB71A68108700A75B9A /* main.m */; };
|
||||||
@@ -59,6 +60,7 @@
|
|||||||
66417CEB7622E77D89928FCA /* Pods-StandardNotes.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-StandardNotes.debug.xcconfig"; path = "Target Support Files/Pods-StandardNotes/Pods-StandardNotes.debug.xcconfig"; sourceTree = "<group>"; };
|
66417CEB7622E77D89928FCA /* Pods-StandardNotes.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-StandardNotes.debug.xcconfig"; path = "Target Support Files/Pods-StandardNotes/Pods-StandardNotes.debug.xcconfig"; sourceTree = "<group>"; };
|
||||||
948EE90E15EA48C27577820B /* Pods-StandardNotes.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-StandardNotes.release.xcconfig"; path = "Target Support Files/Pods-StandardNotes/Pods-StandardNotes.release.xcconfig"; sourceTree = "<group>"; };
|
948EE90E15EA48C27577820B /* Pods-StandardNotes.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-StandardNotes.release.xcconfig"; path = "Target Support Files/Pods-StandardNotes/Pods-StandardNotes.release.xcconfig"; sourceTree = "<group>"; };
|
||||||
A09B7794259DBFABFC4D05CE /* Pods-StandardNotesDev.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-StandardNotesDev.debug.xcconfig"; path = "Target Support Files/Pods-StandardNotesDev/Pods-StandardNotesDev.debug.xcconfig"; sourceTree = "<group>"; };
|
A09B7794259DBFABFC4D05CE /* Pods-StandardNotesDev.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-StandardNotesDev.debug.xcconfig"; path = "Target Support Files/Pods-StandardNotesDev/Pods-StandardNotesDev.debug.xcconfig"; sourceTree = "<group>"; };
|
||||||
|
CD6592A8291EEFCC00C09DC6 /* StoreKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = StoreKit.framework; path = System/Library/Frameworks/StoreKit.framework; sourceTree = SDKROOT; };
|
||||||
CD7D5EC8278005B6005FE1BF /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; name = Info.plist; path = StandardNotes/Info.plist; sourceTree = "<group>"; };
|
CD7D5EC8278005B6005FE1BF /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; name = Info.plist; path = StandardNotes/Info.plist; sourceTree = "<group>"; };
|
||||||
CD7D5EC927800608005FE1BF /* LaunchScreen.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = LaunchScreen.storyboard; sourceTree = "<group>"; };
|
CD7D5EC927800608005FE1BF /* LaunchScreen.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = LaunchScreen.storyboard; sourceTree = "<group>"; };
|
||||||
CD7D5EDF278015D2005FE1BF /* StandardNotesDev.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = StandardNotesDev.app; sourceTree = BUILT_PRODUCTS_DIR; };
|
CD7D5EDF278015D2005FE1BF /* StandardNotesDev.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = StandardNotesDev.app; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||||
@@ -86,6 +88,7 @@
|
|||||||
isa = PBXFrameworksBuildPhase;
|
isa = PBXFrameworksBuildPhase;
|
||||||
buildActionMask = 2147483647;
|
buildActionMask = 2147483647;
|
||||||
files = (
|
files = (
|
||||||
|
CD6592A9291EEFCC00C09DC6 /* StoreKit.framework in Frameworks */,
|
||||||
1C2EEB3B45F4EB07AC795C77 /* (null) in Frameworks */,
|
1C2EEB3B45F4EB07AC795C77 /* (null) in Frameworks */,
|
||||||
DD3D1CE428EC1C8BA0C49211 /* libPods-StandardNotes.a in Frameworks */,
|
DD3D1CE428EC1C8BA0C49211 /* libPods-StandardNotes.a in Frameworks */,
|
||||||
);
|
);
|
||||||
@@ -153,6 +156,7 @@
|
|||||||
2D16E6871FA4F8E400B85C8A /* Frameworks */ = {
|
2D16E6871FA4F8E400B85C8A /* Frameworks */ = {
|
||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
children = (
|
children = (
|
||||||
|
CD6592A8291EEFCC00C09DC6 /* StoreKit.framework */,
|
||||||
ED297162215061F000B7C4FE /* JavaScriptCore.framework */,
|
ED297162215061F000B7C4FE /* JavaScriptCore.framework */,
|
||||||
04FCB5A3A3387CA3CFC82AA3 /* libPods-StandardNotes-StandardNotesTests.a */,
|
04FCB5A3A3387CA3CFC82AA3 /* libPods-StandardNotes-StandardNotesTests.a */,
|
||||||
51F2D747BE02C2A1BCFEEFD1 /* libPods-StandardNotesDev.a */,
|
51F2D747BE02C2A1BCFEEFD1 /* libPods-StandardNotesDev.a */,
|
||||||
|
|||||||
@@ -57,6 +57,7 @@
|
|||||||
"react-native-fingerprint-scanner": "standardnotes/react-native-fingerprint-scanner#b55d1c0ca627a87a130f758603f12911fbac200f",
|
"react-native-fingerprint-scanner": "standardnotes/react-native-fingerprint-scanner#b55d1c0ca627a87a130f758603f12911fbac200f",
|
||||||
"react-native-flag-secure-android": "standardnotes/react-native-flag-secure-android#cb08e74583c22a5d912842459b35ebbbb4bcd852",
|
"react-native-flag-secure-android": "standardnotes/react-native-flag-secure-android#cb08e74583c22a5d912842459b35ebbbb4bcd852",
|
||||||
"react-native-fs": "^2.19.0",
|
"react-native-fs": "^2.19.0",
|
||||||
|
"react-native-iap": "^12.4.4",
|
||||||
"react-native-keychain": "standardnotes/react-native-keychain#d277d360494cbd02be4accb4a360772a8e0e97b6",
|
"react-native-keychain": "standardnotes/react-native-keychain#d277d360494cbd02be4accb4a360772a8e0e97b6",
|
||||||
"react-native-privacy-snapshot": "standardnotes/react-native-privacy-snapshot#653e904c90fc6f2b578da59138f2bfe5d7f942fe",
|
"react-native-privacy-snapshot": "standardnotes/react-native-privacy-snapshot#653e904c90fc6f2b578da59138f2bfe5d7f942fe",
|
||||||
"react-native-share": "^7.9.0",
|
"react-native-share": "^7.9.0",
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import AsyncStorage from '@react-native-community/async-storage'
|
import AsyncStorage from '@react-native-community/async-storage'
|
||||||
import SNReactNative from '@standardnotes/react-native-utils'
|
import SNReactNative from '@standardnotes/react-native-utils'
|
||||||
|
import { AppleIAPReceipt } from '@standardnotes/services/dist/Domain/Subscription/AppleIAPReceipt'
|
||||||
import {
|
import {
|
||||||
ApplicationIdentifier,
|
ApplicationIdentifier,
|
||||||
Environment,
|
Environment,
|
||||||
@@ -11,6 +12,7 @@ import {
|
|||||||
RawKeychainValue,
|
RawKeychainValue,
|
||||||
removeFromArray,
|
removeFromArray,
|
||||||
TransferPayload,
|
TransferPayload,
|
||||||
|
AppleIAPProductId,
|
||||||
UuidString,
|
UuidString,
|
||||||
} from '@standardnotes/snjs'
|
} from '@standardnotes/snjs'
|
||||||
import { ColorSchemeObserverService } from 'ColorSchemeObserverService'
|
import { ColorSchemeObserverService } from 'ColorSchemeObserverService'
|
||||||
@@ -41,6 +43,7 @@ import Share from 'react-native-share'
|
|||||||
import { AndroidBackHandlerService } from '../AndroidBackHandlerService'
|
import { AndroidBackHandlerService } from '../AndroidBackHandlerService'
|
||||||
import { AppStateObserverService } from './../AppStateObserverService'
|
import { AppStateObserverService } from './../AppStateObserverService'
|
||||||
import Keychain from './Keychain'
|
import Keychain from './Keychain'
|
||||||
|
import { PurchaseManager } from '../PurchaseManager'
|
||||||
|
|
||||||
export type BiometricsType = 'Fingerprint' | 'Face ID' | 'Biometrics' | 'Touch ID'
|
export type BiometricsType = 'Fingerprint' | 'Face ID' | 'Biometrics' | 'Touch ID'
|
||||||
|
|
||||||
@@ -99,6 +102,10 @@ export class MobileDevice implements MobileDeviceInterface {
|
|||||||
private colorSchemeService?: ColorSchemeObserverService,
|
private colorSchemeService?: ColorSchemeObserverService,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
|
purchaseSubscriptionIAP(plan: AppleIAPProductId): Promise<AppleIAPReceipt | undefined> {
|
||||||
|
return PurchaseManager.getInstance().purchase(plan)
|
||||||
|
}
|
||||||
|
|
||||||
deinit() {
|
deinit() {
|
||||||
this.stateObserverService?.deinit()
|
this.stateObserverService?.deinit()
|
||||||
;(this.stateObserverService as unknown) = undefined
|
;(this.stateObserverService as unknown) = undefined
|
||||||
@@ -108,7 +115,7 @@ export class MobileDevice implements MobileDeviceInterface {
|
|||||||
;(this.colorSchemeService as unknown) = undefined
|
;(this.colorSchemeService as unknown) = undefined
|
||||||
}
|
}
|
||||||
|
|
||||||
consoleLog(...args: any[]): void {
|
consoleLog(...args: unknown[]): void {
|
||||||
// eslint-disable-next-line no-console
|
// eslint-disable-next-line no-console
|
||||||
console.log(args)
|
console.log(args)
|
||||||
}
|
}
|
||||||
|
|||||||
18
packages/mobile/src/Lib/Logging.ts
Normal file
18
packages/mobile/src/Lib/Logging.ts
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
import { log as utilsLog } from '@standardnotes/snjs'
|
||||||
|
|
||||||
|
export enum LoggingDomain {
|
||||||
|
AppleIAP,
|
||||||
|
}
|
||||||
|
|
||||||
|
const LoggingStatus: Record<LoggingDomain, boolean> = {
|
||||||
|
[LoggingDomain.AppleIAP]: true,
|
||||||
|
}
|
||||||
|
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
|
export function log(domain: LoggingDomain, ...args: any[]): void {
|
||||||
|
if (!LoggingStatus[domain]) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
utilsLog(LoggingDomain[domain], ...args)
|
||||||
|
}
|
||||||
80
packages/mobile/src/PurchaseManager.ts
Normal file
80
packages/mobile/src/PurchaseManager.ts
Normal file
@@ -0,0 +1,80 @@
|
|||||||
|
import { LoggingDomain, log } from './Lib/Logging'
|
||||||
|
import { EmitterSubscription } from 'react-native'
|
||||||
|
import {
|
||||||
|
initConnection,
|
||||||
|
endConnection,
|
||||||
|
purchaseErrorListener,
|
||||||
|
purchaseUpdatedListener,
|
||||||
|
type ProductPurchase,
|
||||||
|
type PurchaseError,
|
||||||
|
type SubscriptionPurchase,
|
||||||
|
finishTransaction,
|
||||||
|
requestSubscription,
|
||||||
|
getSubscriptions,
|
||||||
|
} from 'react-native-iap'
|
||||||
|
import { AppleIAPReceipt, AppleIAPProductId } from '@standardnotes/snjs'
|
||||||
|
|
||||||
|
export class PurchaseManager {
|
||||||
|
private static instance: PurchaseManager
|
||||||
|
private listenerDisposer: EmitterSubscription
|
||||||
|
private errorDisposer: EmitterSubscription
|
||||||
|
|
||||||
|
private constructor() {
|
||||||
|
this.listenerDisposer = purchaseUpdatedListener((purchase: SubscriptionPurchase | ProductPurchase) => {
|
||||||
|
log(LoggingDomain.AppleIAP, 'purchaseUpdatedListener', purchase)
|
||||||
|
const receipt = purchase.transactionReceipt
|
||||||
|
if (receipt) {
|
||||||
|
void finishTransaction({ purchase, isConsumable: false })
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
this.errorDisposer = purchaseErrorListener((error: PurchaseError) => {
|
||||||
|
log(LoggingDomain.AppleIAP, 'purchaseErrorListener', error)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
public static getInstance(): PurchaseManager {
|
||||||
|
if (!PurchaseManager.instance) {
|
||||||
|
PurchaseManager.instance = new PurchaseManager()
|
||||||
|
}
|
||||||
|
|
||||||
|
return PurchaseManager.instance
|
||||||
|
}
|
||||||
|
|
||||||
|
deinit() {
|
||||||
|
this.listenerDisposer.remove()
|
||||||
|
this.errorDisposer.remove()
|
||||||
|
void endConnection()
|
||||||
|
}
|
||||||
|
|
||||||
|
async purchase(sku: AppleIAPProductId): Promise<AppleIAPReceipt | undefined> {
|
||||||
|
await initConnection()
|
||||||
|
|
||||||
|
const subscriptions = await getSubscriptions({
|
||||||
|
skus: [AppleIAPProductId.PlusPlanYearly, AppleIAPProductId.ProPlanYearly],
|
||||||
|
})
|
||||||
|
|
||||||
|
log(LoggingDomain.AppleIAP, 'Retrieved subscriptions', subscriptions)
|
||||||
|
|
||||||
|
try {
|
||||||
|
const result = await requestSubscription({ sku, andDangerouslyFinishTransactionAutomaticallyIOS: true })
|
||||||
|
|
||||||
|
log(LoggingDomain.AppleIAP, 'Purchase result', result)
|
||||||
|
|
||||||
|
if (result && result.transactionId && result.transactionDate) {
|
||||||
|
return {
|
||||||
|
transactionId: result.transactionId,
|
||||||
|
productId: result.productId as AppleIAPProductId,
|
||||||
|
transactionDate: String(result.transactionDate),
|
||||||
|
transactionReceipt: result.transactionReceipt,
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
log(LoggingDomain.AppleIAP, 'Purchase method returning undefined even though successful')
|
||||||
|
return undefined
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
log(LoggingDomain.AppleIAP, error)
|
||||||
|
return undefined
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
|
import { AppleIAPProductId } from './../Subscription/AppleIAPProductId'
|
||||||
import { DeviceInterface } from './DeviceInterface'
|
import { DeviceInterface } from './DeviceInterface'
|
||||||
import { Environment, Platform, RawKeychainValue } from '@standardnotes/models'
|
import { Environment, Platform, RawKeychainValue } from '@standardnotes/models'
|
||||||
|
import { AppleIAPReceipt } from '../Subscription/AppleIAPReceipt'
|
||||||
|
|
||||||
export interface MobileDeviceInterface extends DeviceInterface {
|
export interface MobileDeviceInterface extends DeviceInterface {
|
||||||
environment: Environment.Mobile
|
environment: Environment.Mobile
|
||||||
@@ -22,4 +24,5 @@ export interface MobileDeviceInterface extends DeviceInterface {
|
|||||||
isUrlComponentUrl(url: string): boolean
|
isUrlComponentUrl(url: string): boolean
|
||||||
getAppState(): Promise<'active' | 'background' | 'inactive' | 'unknown' | 'extension'>
|
getAppState(): Promise<'active' | 'background' | 'inactive' | 'unknown' | 'extension'>
|
||||||
getColorScheme(): Promise<'light' | 'dark' | null | undefined>
|
getColorScheme(): Promise<'light' | 'dark' | null | undefined>
|
||||||
|
purchaseSubscriptionIAP(plan: AppleIAPProductId): Promise<AppleIAPReceipt | undefined>
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -64,4 +64,5 @@ export enum ApplicationEvent {
|
|||||||
CompletedInitialSync = 30,
|
CompletedInitialSync = 30,
|
||||||
BiometricsSoftLockEngaged = 31,
|
BiometricsSoftLockEngaged = 31,
|
||||||
BiometricsSoftLockDisengaged = 32,
|
BiometricsSoftLockDisengaged = 32,
|
||||||
|
DidPurchaseSubscription = 33,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
export enum FeaturesEvent {
|
export enum FeaturesEvent {
|
||||||
UserRolesChanged = 'UserRolesChanged',
|
UserRolesChanged = 'UserRolesChanged',
|
||||||
FeaturesUpdated = 'FeaturesUpdated',
|
FeaturesUpdated = 'FeaturesUpdated',
|
||||||
|
DidPurchaseSubscription = 'DidPurchaseSubscription',
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
export enum AppleIAPProductId {
|
||||||
|
ProPlanYearly = 'pro_plan_yearly',
|
||||||
|
PlusPlanYearly = 'plus_plan_yearly',
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
import { AppleIAPProductId } from './AppleIAPProductId'
|
||||||
|
|
||||||
|
export type AppleIAPReceipt = {
|
||||||
|
productId: AppleIAPProductId
|
||||||
|
transactionDate: string
|
||||||
|
transactionId: string
|
||||||
|
transactionReceipt: string
|
||||||
|
}
|
||||||
@@ -1,9 +1,14 @@
|
|||||||
import { Uuid } from '@standardnotes/common'
|
import { Uuid } from '@standardnotes/common'
|
||||||
import { Invitation } from '@standardnotes/models'
|
import { Invitation } from '@standardnotes/models'
|
||||||
|
import { AppleIAPReceipt } from './AppleIAPReceipt'
|
||||||
|
|
||||||
export interface SubscriptionClientInterface {
|
export interface SubscriptionClientInterface {
|
||||||
listSubscriptionInvitations(): Promise<Invitation[]>
|
listSubscriptionInvitations(): Promise<Invitation[]>
|
||||||
inviteToSubscription(inviteeEmail: string): Promise<boolean>
|
inviteToSubscription(inviteeEmail: string): Promise<boolean>
|
||||||
cancelInvitation(inviteUuid: Uuid): Promise<boolean>
|
cancelInvitation(inviteUuid: Uuid): Promise<boolean>
|
||||||
acceptInvitation(inviteUuid: Uuid): Promise<{ success: true } | { success: false; message: string }>
|
acceptInvitation(inviteUuid: Uuid): Promise<{ success: true } | { success: false; message: string }>
|
||||||
|
confirmAppleIAP(
|
||||||
|
receipt: AppleIAPReceipt,
|
||||||
|
subscriptionToken: string,
|
||||||
|
): Promise<{ success: true } | { success: false; message: string }>
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import { InternalEventBusInterface } from '../Internal/InternalEventBusInterface
|
|||||||
import { AbstractService } from '../Service/AbstractService'
|
import { AbstractService } from '../Service/AbstractService'
|
||||||
import { SubscriptionClientInterface } from './SubscriptionClientInterface'
|
import { SubscriptionClientInterface } from './SubscriptionClientInterface'
|
||||||
import { Uuid } from '@standardnotes/common'
|
import { Uuid } from '@standardnotes/common'
|
||||||
|
import { AppleIAPReceipt } from './AppleIAPReceipt'
|
||||||
|
|
||||||
export class SubscriptionManager extends AbstractService implements SubscriptionClientInterface {
|
export class SubscriptionManager extends AbstractService implements SubscriptionClientInterface {
|
||||||
constructor(
|
constructor(
|
||||||
@@ -56,4 +57,24 @@ export class SubscriptionManager extends AbstractService implements Subscription
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async confirmAppleIAP(
|
||||||
|
params: AppleIAPReceipt,
|
||||||
|
subscriptionToken: string,
|
||||||
|
): Promise<{ success: true } | { success: false; message: string }> {
|
||||||
|
try {
|
||||||
|
const result = await this.subscriptionApiService.confirmAppleIAP({
|
||||||
|
...params,
|
||||||
|
subscription_token: subscriptionToken,
|
||||||
|
})
|
||||||
|
|
||||||
|
if (result.data.error) {
|
||||||
|
return { success: false, message: result.data.error.message }
|
||||||
|
}
|
||||||
|
|
||||||
|
return result.data
|
||||||
|
} catch (error) {
|
||||||
|
return { success: false, message: 'Could not confirm IAP.' }
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -76,6 +76,8 @@ export * from './Strings/InfoStrings'
|
|||||||
export * from './Strings/Messages'
|
export * from './Strings/Messages'
|
||||||
export * from './Subscription/SubscriptionClientInterface'
|
export * from './Subscription/SubscriptionClientInterface'
|
||||||
export * from './Subscription/SubscriptionManager'
|
export * from './Subscription/SubscriptionManager'
|
||||||
|
export * from './Subscription/AppleIAPProductId'
|
||||||
|
export * from './Subscription/AppleIAPReceipt'
|
||||||
export * from './Sync/SyncMode'
|
export * from './Sync/SyncMode'
|
||||||
export * from './Sync/SyncOptions'
|
export * from './Sync/SyncOptions'
|
||||||
export * from './Sync/SyncQueueStrategy'
|
export * from './Sync/SyncQueueStrategy'
|
||||||
|
|||||||
@@ -287,6 +287,10 @@ export class SNApplication implements ApplicationInterface, AppGroupManagedAppli
|
|||||||
return this.listedService
|
return this.listedService
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public get alerts(): ExternalServices.AlertService {
|
||||||
|
return this.alertService
|
||||||
|
}
|
||||||
|
|
||||||
public computePrivateUsername(username: string): Promise<string | undefined> {
|
public computePrivateUsername(username: string): Promise<string | undefined> {
|
||||||
return ComputePrivateUsername(this.options.crypto, username)
|
return ComputePrivateUsername(this.options.crypto, username)
|
||||||
}
|
}
|
||||||
@@ -367,8 +371,12 @@ export class SNApplication implements ApplicationInterface, AppGroupManagedAppli
|
|||||||
|
|
||||||
await this.handleStage(ExternalServices.ApplicationStage.StorageDecrypted_09)
|
await this.handleStage(ExternalServices.ApplicationStage.StorageDecrypted_09)
|
||||||
|
|
||||||
this.apiService.loadHost()
|
const host = this.apiService.loadHost()
|
||||||
|
|
||||||
|
this.httpService.setHost(host)
|
||||||
|
|
||||||
this.webSocketsService.loadWebSocketUrl()
|
this.webSocketsService.loadWebSocketUrl()
|
||||||
|
|
||||||
await this.sessionManager.initializeFromDisk()
|
await this.sessionManager.initializeFromDisk()
|
||||||
|
|
||||||
this.settingsService.initializeFromDisk()
|
this.settingsService.initializeFromDisk()
|
||||||
@@ -594,6 +602,7 @@ export class SNApplication implements ApplicationInterface, AppGroupManagedAppli
|
|||||||
|
|
||||||
public async setCustomHost(host: string): Promise<void> {
|
public async setCustomHost(host: string): Promise<void> {
|
||||||
await this.setHost(host)
|
await this.setHost(host)
|
||||||
|
|
||||||
this.webSocketsService.setWebSocketUrl(undefined)
|
this.webSocketsService.setWebSocketUrl(undefined)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1072,7 +1081,7 @@ export class SNApplication implements ApplicationInterface, AppGroupManagedAppli
|
|||||||
this.createProtocolService()
|
this.createProtocolService()
|
||||||
this.diskStorageService.provideEncryptionProvider(this.protocolService)
|
this.diskStorageService.provideEncryptionProvider(this.protocolService)
|
||||||
this.createChallengeService()
|
this.createChallengeService()
|
||||||
this.createHttpManager()
|
this.createLegacyHttpManager()
|
||||||
this.createApiService()
|
this.createApiService()
|
||||||
this.createHttpService()
|
this.createHttpService()
|
||||||
this.createUserServer()
|
this.createUserServer()
|
||||||
@@ -1238,6 +1247,10 @@ export class SNApplication implements ApplicationInterface, AppGroupManagedAppli
|
|||||||
void this.notifyEvent(ApplicationEvent.FeaturesUpdated)
|
void this.notifyEvent(ApplicationEvent.FeaturesUpdated)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
case ExternalServices.FeaturesEvent.DidPurchaseSubscription: {
|
||||||
|
void this.notifyEvent(ApplicationEvent.DidPurchaseSubscription)
|
||||||
|
break
|
||||||
|
}
|
||||||
default: {
|
default: {
|
||||||
Utils.assertUnreachable(event)
|
Utils.assertUnreachable(event)
|
||||||
}
|
}
|
||||||
@@ -1385,7 +1398,7 @@ export class SNApplication implements ApplicationInterface, AppGroupManagedAppli
|
|||||||
this.services.push(this.componentManagerService)
|
this.services.push(this.componentManagerService)
|
||||||
}
|
}
|
||||||
|
|
||||||
private createHttpManager() {
|
private createLegacyHttpManager() {
|
||||||
this.deprecatedHttpService = new InternalServices.SNHttpService(
|
this.deprecatedHttpService = new InternalServices.SNHttpService(
|
||||||
this.environment,
|
this.environment,
|
||||||
this.options.appVersion,
|
this.options.appVersion,
|
||||||
@@ -1399,7 +1412,6 @@ export class SNApplication implements ApplicationInterface, AppGroupManagedAppli
|
|||||||
this.environment,
|
this.environment,
|
||||||
this.options.appVersion,
|
this.options.appVersion,
|
||||||
SnjsVersion,
|
SnjsVersion,
|
||||||
this.options.defaultHost,
|
|
||||||
this.apiService.processMetaObject.bind(this.apiService),
|
this.apiService.processMetaObject.bind(this.apiService),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -110,7 +110,7 @@ export class SNApiService
|
|||||||
this.invalidSessionObserver = observer
|
this.invalidSessionObserver = observer
|
||||||
}
|
}
|
||||||
|
|
||||||
public loadHost(): void {
|
public loadHost(): string {
|
||||||
const storedValue = this.storageService.getValue<string | undefined>(StorageKey.ServerHost)
|
const storedValue = this.storageService.getValue<string | undefined>(StorageKey.ServerHost)
|
||||||
this.host =
|
this.host =
|
||||||
storedValue ||
|
storedValue ||
|
||||||
@@ -120,6 +120,8 @@ export class SNApiService
|
|||||||
_default_sync_server?: string
|
_default_sync_server?: string
|
||||||
}
|
}
|
||||||
)._default_sync_server as string)
|
)._default_sync_server as string)
|
||||||
|
|
||||||
|
return this.host
|
||||||
}
|
}
|
||||||
|
|
||||||
public async setHost(host: string): Promise<void> {
|
public async setHost(host: string): Promise<void> {
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import { PureCryptoInterface } from '@standardnotes/sncrypto-common'
|
|||||||
import { convertTimestampToMilliseconds } from '@standardnotes/utils'
|
import { convertTimestampToMilliseconds } from '@standardnotes/utils'
|
||||||
import {
|
import {
|
||||||
AlertService,
|
AlertService,
|
||||||
|
FeaturesEvent,
|
||||||
FeatureStatus,
|
FeatureStatus,
|
||||||
InternalEventBusInterface,
|
InternalEventBusInterface,
|
||||||
StorageKey,
|
StorageKey,
|
||||||
@@ -203,6 +204,47 @@ describe('featuresService', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
describe('updateRoles()', () => {
|
describe('updateRoles()', () => {
|
||||||
|
it('setRoles should notify event if roles changed', async () => {
|
||||||
|
storageService.getValue = jest.fn().mockReturnValue(roles)
|
||||||
|
const featuresService = createService()
|
||||||
|
featuresService.initializeFromDisk()
|
||||||
|
|
||||||
|
const mock = (featuresService['notifyEvent'] = jest.fn())
|
||||||
|
|
||||||
|
const newRoles = [...roles, RoleName.PlusUser]
|
||||||
|
await featuresService.setRoles(newRoles)
|
||||||
|
|
||||||
|
expect(mock.mock.calls[0][0]).toEqual(FeaturesEvent.UserRolesChanged)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should notify of subscription purchase', async () => {
|
||||||
|
storageService.getValue = jest.fn().mockReturnValue(roles)
|
||||||
|
const featuresService = createService()
|
||||||
|
featuresService.initializeFromDisk()
|
||||||
|
|
||||||
|
const spy = jest.spyOn(featuresService, 'notifyEvent' as never)
|
||||||
|
|
||||||
|
const newRoles = [...roles, RoleName.ProUser]
|
||||||
|
await featuresService.updateRolesAndFetchFeatures('123', newRoles)
|
||||||
|
|
||||||
|
expect(spy.mock.calls[2][0]).toEqual(FeaturesEvent.DidPurchaseSubscription)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should not notify of subscription purchase on initial roles load after sign in', async () => {
|
||||||
|
storageService.getValue = jest.fn().mockReturnValue(roles)
|
||||||
|
const featuresService = createService()
|
||||||
|
featuresService.initializeFromDisk()
|
||||||
|
featuresService['roles'] = []
|
||||||
|
|
||||||
|
const spy = jest.spyOn(featuresService, 'notifyEvent' as never)
|
||||||
|
|
||||||
|
const newRoles = [...roles, RoleName.ProUser]
|
||||||
|
await featuresService.updateRolesAndFetchFeatures('123', newRoles)
|
||||||
|
|
||||||
|
const triggeredEvents = spy.mock.calls.map((call) => call[0])
|
||||||
|
expect(triggeredEvents).not.toContain(FeaturesEvent.DidPurchaseSubscription)
|
||||||
|
})
|
||||||
|
|
||||||
it('saves new roles to storage and fetches features if a role has been added', async () => {
|
it('saves new roles to storage and fetches features if a role has been added', async () => {
|
||||||
const newRoles = [...roles, RoleName.PlusUser]
|
const newRoles = [...roles, RoleName.PlusUser]
|
||||||
|
|
||||||
@@ -631,7 +673,7 @@ describe('featuresService', () => {
|
|||||||
await featuresService.updateRolesAndFetchFeatures('123', [RoleName.CoreUser, RoleName.PlusUser])
|
await featuresService.updateRolesAndFetchFeatures('123', [RoleName.CoreUser, RoleName.PlusUser])
|
||||||
|
|
||||||
sessionManager.isSignedIntoFirstPartyServer = jest.fn().mockReturnValue(false)
|
sessionManager.isSignedIntoFirstPartyServer = jest.fn().mockReturnValue(false)
|
||||||
featuresService.hasOnlineSubscription = jest.fn().mockReturnValue(false)
|
featuresService.rolesIncludePaidSubscription = jest.fn().mockReturnValue(false)
|
||||||
featuresService['completedSuccessfulFeaturesRetrieval'] = true
|
featuresService['completedSuccessfulFeaturesRetrieval'] = true
|
||||||
|
|
||||||
expect(featuresService.getFeatureStatus(FeatureIdentifier.MidnightTheme)).toBe(FeatureStatus.NoUserSubscription)
|
expect(featuresService.getFeatureStatus(FeatureIdentifier.MidnightTheme)).toBe(FeatureStatus.NoUserSubscription)
|
||||||
|
|||||||
@@ -154,7 +154,7 @@ export class SNFeaturesService
|
|||||||
if (stage === ApplicationStage.FullSyncCompleted_13) {
|
if (stage === ApplicationStage.FullSyncCompleted_13) {
|
||||||
void this.addDarkTheme()
|
void this.addDarkTheme()
|
||||||
|
|
||||||
if (!this.hasOnlineSubscription()) {
|
if (!this.rolesIncludePaidSubscription()) {
|
||||||
const offlineRepo = this.getOfflineRepo()
|
const offlineRepo = this.getOfflineRepo()
|
||||||
if (offlineRepo) {
|
if (offlineRepo) {
|
||||||
void this.downloadOfflineFeatures(offlineRepo)
|
void this.downloadOfflineFeatures(offlineRepo)
|
||||||
@@ -355,8 +355,12 @@ export class SNFeaturesService
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async updateRolesAndFetchFeatures(userUuid: UuidString, roles: RoleName[]): Promise<void> {
|
public async updateRolesAndFetchFeatures(userUuid: UuidString, roles: RoleName[]): Promise<void> {
|
||||||
|
const previousRoles = this.roles
|
||||||
|
|
||||||
const userRolesChanged = this.haveRolesChanged(roles)
|
const userRolesChanged = this.haveRolesChanged(roles)
|
||||||
|
|
||||||
|
const isInitialLoadRolesChange = previousRoles.length === 0 && userRolesChanged
|
||||||
|
|
||||||
if (!userRolesChanged && !this.needsInitialFeaturesUpdate) {
|
if (!userRolesChanged && !this.needsInitialFeaturesUpdate) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -375,13 +379,23 @@ export class SNFeaturesService
|
|||||||
await this.didDownloadFeatures(features)
|
await this.didDownloadFeatures(features)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (userRolesChanged && !isInitialLoadRolesChange) {
|
||||||
|
if (this.rolesIncludePaidSubscription()) {
|
||||||
|
await this.notifyEvent(FeaturesEvent.DidPurchaseSubscription)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async setRoles(roles: RoleName[]): Promise<void> {
|
async setRoles(roles: RoleName[]): Promise<void> {
|
||||||
|
const rolesChanged = !arraysEqual(this.roles, roles)
|
||||||
|
|
||||||
this.roles = roles
|
this.roles = roles
|
||||||
if (!arraysEqual(this.roles, roles)) {
|
|
||||||
|
if (rolesChanged) {
|
||||||
void this.notifyEvent(FeaturesEvent.UserRolesChanged)
|
void this.notifyEvent(FeaturesEvent.UserRolesChanged)
|
||||||
}
|
}
|
||||||
|
|
||||||
this.storageService.setValue(StorageKey.UserRoles, this.roles)
|
this.storageService.setValue(StorageKey.UserRoles, this.roles)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -434,14 +448,13 @@ export class SNFeaturesService
|
|||||||
return this.features.find((feature) => feature.identifier === featureId)
|
return this.features.find((feature) => feature.identifier === featureId)
|
||||||
}
|
}
|
||||||
|
|
||||||
hasOnlineSubscription(): boolean {
|
rolesIncludePaidSubscription(): boolean {
|
||||||
const roles = this.roles
|
|
||||||
const unpaidRoles = [RoleName.CoreUser]
|
const unpaidRoles = [RoleName.CoreUser]
|
||||||
return roles.some((role) => !unpaidRoles.includes(role))
|
return this.roles.some((role) => !unpaidRoles.includes(role))
|
||||||
}
|
}
|
||||||
|
|
||||||
public hasPaidOnlineOrOfflineSubscription(): boolean {
|
public hasPaidOnlineOrOfflineSubscription(): boolean {
|
||||||
return this.hasOnlineSubscription() || this.hasOfflineRepo()
|
return this.rolesIncludePaidSubscription() || this.hasOfflineRepo()
|
||||||
}
|
}
|
||||||
|
|
||||||
public rolesBySorting(roles: RoleName[]): RoleName[] {
|
public rolesBySorting(roles: RoleName[]): RoleName[] {
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ export class SKAlert {
|
|||||||
buttonsString() {
|
buttonsString() {
|
||||||
const genButton = function (buttonDesc: AlertButton, index: number) {
|
const genButton = function (buttonDesc: AlertButton, index: number) {
|
||||||
return `
|
return `
|
||||||
<button id='button-${index}' class='font-bold px-2.5 py-2 text-xs text-info-contrast bg-${buttonDesc.style}'>
|
<button id='button-${index}' class='font-bold px-2.5 py-2 text-base lg:text-xs text-info-contrast bg-${buttonDesc.style}'>
|
||||||
<div class='sk-label'>${buttonDesc.text}</div>
|
<div class='sk-label'>${buttonDesc.text}</div>
|
||||||
</button>
|
</button>
|
||||||
`
|
`
|
||||||
@@ -57,8 +57,8 @@ export class SKAlert {
|
|||||||
buttonsTemplate = ''
|
buttonsTemplate = ''
|
||||||
panelStyle = 'style="padding-bottom: 8px"'
|
panelStyle = 'style="padding-bottom: 8px"'
|
||||||
}
|
}
|
||||||
const titleTemplate = this.title ? `<div class='sk-h3 sk-panel-section-title'>${this.title}</div>` : ''
|
const titleTemplate = this.title ? `<div class='mb-1 font-bold text-lg lg:text-base'>${this.title}</div>` : ''
|
||||||
const messageTemplate = this.text ? `<p class='sk-p'>${this.text}</p>` : ''
|
const messageTemplate = this.text ? `<p class='sk-p text-base lg:text-sm'>${this.text}</p>` : ''
|
||||||
|
|
||||||
const template = `
|
const template = `
|
||||||
<div class="sk-modal">
|
<div class="sk-modal">
|
||||||
|
|||||||
@@ -204,10 +204,6 @@ export class WebApplication extends SNApplication implements WebApplicationInter
|
|||||||
return this.isNativeMobileWeb() && this.platform === Platform.Ios
|
return this.isNativeMobileWeb() && this.platform === Platform.Ios
|
||||||
}
|
}
|
||||||
|
|
||||||
get hideSubscriptionMarketing() {
|
|
||||||
return this.isNativeIOS()
|
|
||||||
}
|
|
||||||
|
|
||||||
mobileDevice(): MobileDeviceInterface {
|
mobileDevice(): MobileDeviceInterface {
|
||||||
if (!this.isNativeMobileWeb()) {
|
if (!this.isNativeMobileWeb()) {
|
||||||
throw Error('Attempting to access device as mobile device on non mobile platform')
|
throw Error('Attempting to access device as mobile device on non mobile platform')
|
||||||
|
|||||||
@@ -199,7 +199,7 @@ const ApplicationView: FunctionComponent<Props> = ({ application, mainApplicatio
|
|||||||
<AndroidBackHandlerProvider application={application}>
|
<AndroidBackHandlerProvider application={application}>
|
||||||
<DarkModeHandler application={application} />
|
<DarkModeHandler application={application} />
|
||||||
<ResponsivePaneProvider paneController={application.getViewControllerManager().paneController}>
|
<ResponsivePaneProvider paneController={application.getViewControllerManager().paneController}>
|
||||||
<PremiumModalProvider application={application} viewControllerManager={viewControllerManager}>
|
<PremiumModalProvider application={application} featuresController={viewControllerManager.featuresController}>
|
||||||
<div className={platformString + ' main-ui-view sn-component h-full'}>
|
<div className={platformString + ' main-ui-view sn-component h-full'}>
|
||||||
<div id="app" className="app app-column-container" ref={appColumnContainerRef}>
|
<div id="app" className="app app-column-container" ref={appColumnContainerRef}>
|
||||||
<FileDragNDropProvider
|
<FileDragNDropProvider
|
||||||
|
|||||||
@@ -213,16 +213,14 @@ const DisplayOptionsMenu: FunctionComponent<DisplayOptionsMenuProps> = ({
|
|||||||
'Create powerful workflows and organizational layouts with per-tag display preferences.'}
|
'Create powerful workflows and organizational layouts with per-tag display preferences.'}
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
{!application.hideSubscriptionMarketing && (
|
<Button
|
||||||
<Button
|
primary
|
||||||
primary
|
small
|
||||||
small
|
className="col-start-1 col-end-3 mt-3 justify-self-start uppercase"
|
||||||
className="col-start-1 col-end-3 mt-3 justify-self-start uppercase"
|
onClick={() => application.openPurchaseFlow()}
|
||||||
onClick={() => application.openPurchaseFlow()}
|
>
|
||||||
>
|
Upgrade Features
|
||||||
Upgrade Features
|
</Button>
|
||||||
</Button>
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ import { WebApplication } from '@/Application/Application'
|
|||||||
import { FeaturesController } from '@/Controllers/FeaturesController'
|
import { FeaturesController } from '@/Controllers/FeaturesController'
|
||||||
import { SubscriptionController } from '@/Controllers/Subscription/SubscriptionController'
|
import { SubscriptionController } from '@/Controllers/Subscription/SubscriptionController'
|
||||||
import { observer } from 'mobx-react-lite'
|
import { observer } from 'mobx-react-lite'
|
||||||
import { loadPurchaseFlowUrl } from '../PurchaseFlow/PurchaseFlowFunctions'
|
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
application: WebApplication
|
application: WebApplication
|
||||||
@@ -14,22 +13,11 @@ const UpgradeNow = ({ application, featuresController, subscriptionContoller }:
|
|||||||
const shouldShowCTA = !featuresController.hasFolders
|
const shouldShowCTA = !featuresController.hasFolders
|
||||||
const hasAccount = subscriptionContoller.hasAccount
|
const hasAccount = subscriptionContoller.hasAccount
|
||||||
|
|
||||||
if (hasAccount && subscriptionContoller.hideSubscriptionMarketing) {
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
|
|
||||||
return shouldShowCTA ? (
|
return shouldShowCTA ? (
|
||||||
<div className="flex h-full items-center px-2">
|
<div className="flex h-full items-center px-2">
|
||||||
<button
|
<button
|
||||||
className="rounded bg-info py-0.5 px-1.5 text-sm font-bold uppercase text-info-contrast hover:brightness-125 lg:text-xs"
|
className="rounded bg-info py-0.5 px-1.5 text-sm font-bold uppercase text-info-contrast hover:brightness-125 lg:text-xs"
|
||||||
onClick={() => {
|
onClick={() => application.openPurchaseFlow()}
|
||||||
if (hasAccount) {
|
|
||||||
void loadPurchaseFlowUrl(application)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
application.getViewControllerManager().purchaseFlowController.openPurchaseFlow()
|
|
||||||
}}
|
|
||||||
>
|
>
|
||||||
{hasAccount ? 'Unlock features' : 'Sign up to sync'}
|
{hasAccount ? 'Unlock features' : 'Sign up to sync'}
|
||||||
</button>
|
</button>
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ import { FunctionComponent, useState } from 'react'
|
|||||||
import { LinkButton, Text } from '@/Components/Preferences/PreferencesComponents/Content'
|
import { LinkButton, Text } from '@/Components/Preferences/PreferencesComponents/Content'
|
||||||
import Button from '@/Components/Button/Button'
|
import Button from '@/Components/Button/Button'
|
||||||
import { WebApplication } from '@/Application/Application'
|
import { WebApplication } from '@/Application/Application'
|
||||||
import { loadPurchaseFlowUrl } from '@/Components/PurchaseFlow/PurchaseFlowFunctions'
|
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
application: WebApplication
|
application: WebApplication
|
||||||
@@ -16,9 +15,7 @@ const NoSubscription: FunctionComponent<Props> = ({ application }) => {
|
|||||||
const errorMessage = 'There was an error when attempting to redirect you to the subscription page.'
|
const errorMessage = 'There was an error when attempting to redirect you to the subscription page.'
|
||||||
setIsLoadingPurchaseFlow(true)
|
setIsLoadingPurchaseFlow(true)
|
||||||
try {
|
try {
|
||||||
if (!(await loadPurchaseFlowUrl(application))) {
|
application.openPurchaseFlow()
|
||||||
setPurchaseFlowError(errorMessage)
|
|
||||||
}
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
setPurchaseFlowError(errorMessage)
|
setPurchaseFlowError(errorMessage)
|
||||||
} finally {
|
} finally {
|
||||||
@@ -31,14 +28,12 @@ const NoSubscription: FunctionComponent<Props> = ({ application }) => {
|
|||||||
<Text>You don't have a Standard Notes subscription yet.</Text>
|
<Text>You don't have a Standard Notes subscription yet.</Text>
|
||||||
{isLoadingPurchaseFlow && <Text>Redirecting you to the subscription page...</Text>}
|
{isLoadingPurchaseFlow && <Text>Redirecting you to the subscription page...</Text>}
|
||||||
{purchaseFlowError && <Text className="text-danger">{purchaseFlowError}</Text>}
|
{purchaseFlowError && <Text className="text-danger">{purchaseFlowError}</Text>}
|
||||||
{!application.hideSubscriptionMarketing && (
|
<div className="flex">
|
||||||
<div className="flex">
|
<LinkButton className="mt-3 mr-3 min-w-20" label="Learn More" link={window.plansUrl as string} />
|
||||||
<LinkButton className="mt-3 mr-3 min-w-20" label="Learn More" link={window.plansUrl as string} />
|
{application.hasAccount() && (
|
||||||
{application.hasAccount() && (
|
<Button className="mt-3 min-w-20" primary label="Subscribe" onClick={onPurchaseClick} />
|
||||||
<Button className="mt-3 min-w-20" primary label="Subscribe" onClick={onPurchaseClick} />
|
)}
|
||||||
)}
|
</div>
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ import { FunctionComponent, useState } from 'react'
|
|||||||
import { LinkButton, Text } from '@/Components/Preferences/PreferencesComponents/Content'
|
import { LinkButton, Text } from '@/Components/Preferences/PreferencesComponents/Content'
|
||||||
import Button from '@/Components/Button/Button'
|
import Button from '@/Components/Button/Button'
|
||||||
import { WebApplication } from '@/Application/Application'
|
import { WebApplication } from '@/Application/Application'
|
||||||
import { loadPurchaseFlowUrl } from '@/Components/PurchaseFlow/PurchaseFlowFunctions'
|
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
application: WebApplication
|
application: WebApplication
|
||||||
@@ -16,9 +15,7 @@ const NoProSubscription: FunctionComponent<Props> = ({ application }) => {
|
|||||||
const errorMessage = 'There was an error when attempting to redirect you to the subscription page.'
|
const errorMessage = 'There was an error when attempting to redirect you to the subscription page.'
|
||||||
setIsLoadingPurchaseFlow(true)
|
setIsLoadingPurchaseFlow(true)
|
||||||
try {
|
try {
|
||||||
if (!(await loadPurchaseFlowUrl(application))) {
|
application.openPurchaseFlow()
|
||||||
setPurchaseFlowError(errorMessage)
|
|
||||||
}
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
setPurchaseFlowError(errorMessage)
|
setPurchaseFlowError(errorMessage)
|
||||||
} finally {
|
} finally {
|
||||||
@@ -35,14 +32,12 @@ const NoProSubscription: FunctionComponent<Props> = ({ application }) => {
|
|||||||
{isLoadingPurchaseFlow && <Text>Redirecting you to the subscription page...</Text>}
|
{isLoadingPurchaseFlow && <Text>Redirecting you to the subscription page...</Text>}
|
||||||
{purchaseFlowError && <Text className="text-danger">{purchaseFlowError}</Text>}
|
{purchaseFlowError && <Text className="text-danger">{purchaseFlowError}</Text>}
|
||||||
|
|
||||||
{!application.hideSubscriptionMarketing && (
|
<div className="flex">
|
||||||
<div className="flex">
|
<LinkButton className="mt-3 mr-3 min-w-20" label="Learn More" link={window.plansUrl as string} />
|
||||||
<LinkButton className="mt-3 mr-3 min-w-20" label="Learn More" link={window.plansUrl as string} />
|
{application.hasAccount() && (
|
||||||
{application.hasAccount() && (
|
<Button className="mt-3 min-w-20" primary label="Upgrade" onClick={onPurchaseClick} />
|
||||||
<Button className="mt-3 min-w-20" primary label="Upgrade" onClick={onPurchaseClick} />
|
)}
|
||||||
)}
|
</div>
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
export enum PremiumFeatureModalType {
|
||||||
|
UpgradePrompt,
|
||||||
|
UpgradeSuccess,
|
||||||
|
}
|
||||||
@@ -4,7 +4,7 @@ import Icon from '@/Components/Icon/Icon'
|
|||||||
import { WebApplication } from '@/Application/Application'
|
import { WebApplication } from '@/Application/Application'
|
||||||
import { openSubscriptionDashboard } from '@/Utils/ManageSubscription'
|
import { openSubscriptionDashboard } from '@/Utils/ManageSubscription'
|
||||||
import { PremiumFeatureIconClass, PremiumFeatureIconName } from '../Icon/PremiumFeatureIcon'
|
import { PremiumFeatureIconClass, PremiumFeatureIconName } from '../Icon/PremiumFeatureIcon'
|
||||||
import { loadPurchaseFlowUrl } from '../PurchaseFlow/PurchaseFlowFunctions'
|
import { PremiumFeatureModalType } from './PremiumFeatureModalType'
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
application: WebApplication
|
application: WebApplication
|
||||||
@@ -13,6 +13,7 @@ type Props = {
|
|||||||
hasAccount: boolean
|
hasAccount: boolean
|
||||||
onClose: () => void
|
onClose: () => void
|
||||||
showModal: boolean
|
showModal: boolean
|
||||||
|
type: PremiumFeatureModalType
|
||||||
}
|
}
|
||||||
|
|
||||||
const PremiumFeaturesModal: FunctionComponent<Props> = ({
|
const PremiumFeaturesModal: FunctionComponent<Props> = ({
|
||||||
@@ -22,6 +23,7 @@ const PremiumFeaturesModal: FunctionComponent<Props> = ({
|
|||||||
hasAccount,
|
hasAccount,
|
||||||
onClose,
|
onClose,
|
||||||
showModal,
|
showModal,
|
||||||
|
type = PremiumFeatureModalType.UpgradePrompt,
|
||||||
}) => {
|
}) => {
|
||||||
const plansButtonRef = useRef<HTMLButtonElement>(null)
|
const plansButtonRef = useRef<HTMLButtonElement>(null)
|
||||||
|
|
||||||
@@ -29,11 +31,58 @@ const PremiumFeaturesModal: FunctionComponent<Props> = ({
|
|||||||
if (hasSubscription) {
|
if (hasSubscription) {
|
||||||
void openSubscriptionDashboard(application)
|
void openSubscriptionDashboard(application)
|
||||||
} else if (hasAccount) {
|
} else if (hasAccount) {
|
||||||
void loadPurchaseFlowUrl(application)
|
void application.openPurchaseFlow()
|
||||||
} else if (window.plansUrl) {
|
} else if (window.plansUrl) {
|
||||||
window.location.assign(window.plansUrl)
|
window.location.assign(window.plansUrl)
|
||||||
}
|
}
|
||||||
}, [application, hasSubscription, hasAccount])
|
onClose()
|
||||||
|
}, [application, hasSubscription, hasAccount, onClose])
|
||||||
|
|
||||||
|
const UpgradePrompt = (
|
||||||
|
<>
|
||||||
|
<AlertDialogDescription className="mb-2 px-4.5 text-center text-sm text-passive-1">
|
||||||
|
To take advantage of <span className="font-semibold">{featureName}</span> and other advanced features, upgrade
|
||||||
|
your current plan.
|
||||||
|
</AlertDialogDescription>
|
||||||
|
|
||||||
|
<div className="p-4">
|
||||||
|
<button
|
||||||
|
onClick={handleClick}
|
||||||
|
className="no-border w-full cursor-pointer rounded bg-info py-2 font-bold text-info-contrast hover:brightness-125 focus:brightness-125"
|
||||||
|
ref={plansButtonRef}
|
||||||
|
>
|
||||||
|
Upgrade
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
|
||||||
|
const SuccessPrompt = (
|
||||||
|
<>
|
||||||
|
<AlertDialogDescription className="mb-2 px-4.5 text-center text-sm text-passive-1">
|
||||||
|
Enjoy your new powered up experience.
|
||||||
|
</AlertDialogDescription>
|
||||||
|
|
||||||
|
<div className="p-4">
|
||||||
|
<button
|
||||||
|
onClick={onClose}
|
||||||
|
className="no-border w-full cursor-pointer rounded bg-info py-2 font-bold text-info-contrast hover:brightness-125 focus:brightness-125"
|
||||||
|
ref={plansButtonRef}
|
||||||
|
>
|
||||||
|
Continue
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
|
||||||
|
const title =
|
||||||
|
type === PremiumFeatureModalType.UpgradePrompt ? 'Enable Advanced Features' : 'Your purchase was successful!'
|
||||||
|
|
||||||
|
const iconName = type === PremiumFeatureModalType.UpgradePrompt ? PremiumFeatureIconName : '🎉'
|
||||||
|
const iconClass =
|
||||||
|
type === PremiumFeatureModalType.UpgradePrompt
|
||||||
|
? `h-12 w-12 ${PremiumFeatureIconClass}`
|
||||||
|
: 'px-7 py-2 h-24 w-24 text-[50px]'
|
||||||
|
|
||||||
return showModal ? (
|
return showModal ? (
|
||||||
<AlertDialog leastDestructiveRef={plansButtonRef} className="p-0">
|
<AlertDialog leastDestructiveRef={plansButtonRef} className="p-0">
|
||||||
@@ -53,25 +102,11 @@ const PremiumFeaturesModal: FunctionComponent<Props> = ({
|
|||||||
className="mx-auto mb-5 flex h-24 w-24 items-center justify-center rounded-[50%] bg-contrast"
|
className="mx-auto mb-5 flex h-24 w-24 items-center justify-center rounded-[50%] bg-contrast"
|
||||||
aria-hidden={true}
|
aria-hidden={true}
|
||||||
>
|
>
|
||||||
<Icon className={`h-12 w-12 ${PremiumFeatureIconClass}`} type={PremiumFeatureIconName} />
|
<Icon className={iconClass} size={'custom'} type={iconName} />
|
||||||
</div>
|
</div>
|
||||||
<div className="mb-1 text-center text-lg font-bold">Enable Advanced Features</div>
|
<div className="mb-1 text-center text-lg font-bold">{title}</div>
|
||||||
</AlertDialogLabel>
|
</AlertDialogLabel>
|
||||||
<AlertDialogDescription className="mb-2 px-4.5 text-center text-sm text-passive-1">
|
{type === PremiumFeatureModalType.UpgradePrompt ? UpgradePrompt : SuccessPrompt}
|
||||||
To take advantage of <span className="font-semibold">{featureName}</span> and other advanced features,
|
|
||||||
upgrade your current plan.
|
|
||||||
</AlertDialogDescription>
|
|
||||||
{!application.hideSubscriptionMarketing && (
|
|
||||||
<div className="p-4">
|
|
||||||
<button
|
|
||||||
onClick={handleClick}
|
|
||||||
className="no-border w-full cursor-pointer rounded bg-info py-2 font-bold text-info-contrast hover:brightness-125 focus:brightness-125"
|
|
||||||
ref={plansButtonRef}
|
|
||||||
>
|
|
||||||
Upgrade
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</AlertDialog>
|
</AlertDialog>
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import { ChangeEventHandler, FunctionComponent, useEffect, useRef, useState } fr
|
|||||||
import FloatingLabelInput from '@/Components/Input/FloatingLabelInput'
|
import FloatingLabelInput from '@/Components/Input/FloatingLabelInput'
|
||||||
import { isEmailValid } from '@/Utils'
|
import { isEmailValid } from '@/Utils'
|
||||||
import { BlueDotIcon, CircleIcon, DiamondIcon, CreateAccountIllustration } from '@standardnotes/icons'
|
import { BlueDotIcon, CircleIcon, DiamondIcon, CreateAccountIllustration } from '@standardnotes/icons'
|
||||||
import { loadPurchaseFlowUrl } from '../PurchaseFlowFunctions'
|
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
viewControllerManager: ViewControllerManager
|
viewControllerManager: ViewControllerManager
|
||||||
@@ -52,10 +51,7 @@ const CreateAccount: FunctionComponent<Props> = ({ viewControllerManager, applic
|
|||||||
}
|
}
|
||||||
|
|
||||||
const subscribeWithoutAccount = () => {
|
const subscribeWithoutAccount = () => {
|
||||||
loadPurchaseFlowUrl(application).catch((err) => {
|
application.getViewControllerManager().purchaseFlowController.openPurchaseWebpage()
|
||||||
console.error(err)
|
|
||||||
application.alertService.alert(err).catch(console.error)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleCreateAccount = async () => {
|
const handleCreateAccount = async () => {
|
||||||
@@ -93,13 +89,7 @@ const CreateAccount: FunctionComponent<Props> = ({ viewControllerManager, applic
|
|||||||
await application.register(email, password)
|
await application.register(email, password)
|
||||||
|
|
||||||
viewControllerManager.purchaseFlowController.closePurchaseFlow()
|
viewControllerManager.purchaseFlowController.closePurchaseFlow()
|
||||||
|
viewControllerManager.purchaseFlowController.openPurchaseFlow()
|
||||||
if (!application.hideSubscriptionMarketing) {
|
|
||||||
loadPurchaseFlowUrl(application).catch((err) => {
|
|
||||||
console.error(err)
|
|
||||||
application.alertService.alert(err).catch(console.error)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(err)
|
console.error(err)
|
||||||
application.alertService.alert(err as string).catch(console.error)
|
application.alertService.alert(err as string).catch(console.error)
|
||||||
@@ -170,13 +160,15 @@ const CreateAccount: FunctionComponent<Props> = ({ viewControllerManager, applic
|
|||||||
>
|
>
|
||||||
Sign in instead
|
Sign in instead
|
||||||
</button>
|
</button>
|
||||||
<button
|
{!application.isNativeIOS() && (
|
||||||
onClick={subscribeWithoutAccount}
|
<button
|
||||||
disabled={isCreatingAccount}
|
onClick={subscribeWithoutAccount}
|
||||||
className="flex cursor-pointer items-start border-0 bg-default p-0 font-medium text-info hover:underline"
|
disabled={isCreatingAccount}
|
||||||
>
|
className="flex cursor-pointer items-start border-0 bg-default p-0 font-medium text-info hover:underline"
|
||||||
Subscribe without account
|
>
|
||||||
</button>
|
Subscribe without account
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
<Button
|
<Button
|
||||||
className="mb-4 py-2.5 md:mb-0"
|
className="mb-4 py-2.5 md:mb-0"
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import { ChangeEventHandler, FunctionComponent, useEffect, useRef, useState } fr
|
|||||||
import FloatingLabelInput from '@/Components/Input/FloatingLabelInput'
|
import FloatingLabelInput from '@/Components/Input/FloatingLabelInput'
|
||||||
import { isEmailValid } from '@/Utils'
|
import { isEmailValid } from '@/Utils'
|
||||||
import { BlueDotIcon, CircleIcon, DiamondIcon } from '@standardnotes/icons'
|
import { BlueDotIcon, CircleIcon, DiamondIcon } from '@standardnotes/icons'
|
||||||
import { loadPurchaseFlowUrl } from '../PurchaseFlowFunctions'
|
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
viewControllerManager: ViewControllerManager
|
viewControllerManager: ViewControllerManager
|
||||||
@@ -75,13 +74,7 @@ const SignIn: FunctionComponent<Props> = ({ viewControllerManager, application }
|
|||||||
throw new Error(response.error?.message || response.data?.error?.message)
|
throw new Error(response.error?.message || response.data?.error?.message)
|
||||||
} else {
|
} else {
|
||||||
viewControllerManager.purchaseFlowController.closePurchaseFlow()
|
viewControllerManager.purchaseFlowController.closePurchaseFlow()
|
||||||
|
viewControllerManager.purchaseFlowController.openPurchaseFlow()
|
||||||
if (!application.hideSubscriptionMarketing) {
|
|
||||||
loadPurchaseFlowUrl(application).catch((err) => {
|
|
||||||
console.error(err)
|
|
||||||
application.alertService.alert(err).catch(console.error)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(err)
|
console.error(err)
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { WebApplication } from '@/Application/Application'
|
import { WebApplication } from '@/Application/Application'
|
||||||
|
import { PremiumFeatureModalType } from '@/Components/PremiumFeaturesModal/PremiumFeatureModalType'
|
||||||
import { destroyAllObjectProperties } from '@/Utils'
|
import { destroyAllObjectProperties } from '@/Utils'
|
||||||
import {
|
import {
|
||||||
ApplicationEvent,
|
ApplicationEvent,
|
||||||
@@ -16,6 +17,7 @@ export class FeaturesController extends AbstractViewController {
|
|||||||
hasSmartViews: boolean
|
hasSmartViews: boolean
|
||||||
hasFiles: boolean
|
hasFiles: boolean
|
||||||
premiumAlertFeatureName: string | undefined
|
premiumAlertFeatureName: string | undefined
|
||||||
|
premiumAlertType: PremiumFeatureModalType | undefined = undefined
|
||||||
|
|
||||||
override deinit() {
|
override deinit() {
|
||||||
super.deinit()
|
super.deinit()
|
||||||
@@ -25,6 +27,7 @@ export class FeaturesController extends AbstractViewController {
|
|||||||
;(this.hasSmartViews as unknown) = undefined
|
;(this.hasSmartViews as unknown) = undefined
|
||||||
;(this.hasFiles as unknown) = undefined
|
;(this.hasFiles as unknown) = undefined
|
||||||
;(this.premiumAlertFeatureName as unknown) = undefined
|
;(this.premiumAlertFeatureName as unknown) = undefined
|
||||||
|
;(this.premiumAlertType as unknown) = undefined
|
||||||
|
|
||||||
destroyAllObjectProperties(this)
|
destroyAllObjectProperties(this)
|
||||||
}
|
}
|
||||||
@@ -43,10 +46,11 @@ export class FeaturesController extends AbstractViewController {
|
|||||||
hasFolders: observable,
|
hasFolders: observable,
|
||||||
hasSmartViews: observable,
|
hasSmartViews: observable,
|
||||||
hasFiles: observable,
|
hasFiles: observable,
|
||||||
|
premiumAlertType: observable,
|
||||||
premiumAlertFeatureName: observable,
|
premiumAlertFeatureName: observable,
|
||||||
showPremiumAlert: action,
|
showPremiumAlert: action,
|
||||||
closePremiumAlert: action,
|
closePremiumAlert: action,
|
||||||
|
showPurchaseSuccessAlert: action,
|
||||||
})
|
})
|
||||||
|
|
||||||
this.showPremiumAlert = this.showPremiumAlert.bind(this)
|
this.showPremiumAlert = this.showPremiumAlert.bind(this)
|
||||||
@@ -55,6 +59,9 @@ export class FeaturesController extends AbstractViewController {
|
|||||||
this.disposers.push(
|
this.disposers.push(
|
||||||
application.addEventObserver(async (event) => {
|
application.addEventObserver(async (event) => {
|
||||||
switch (event) {
|
switch (event) {
|
||||||
|
case ApplicationEvent.DidPurchaseSubscription:
|
||||||
|
this.showPurchaseSuccessAlert()
|
||||||
|
break
|
||||||
case ApplicationEvent.FeaturesUpdated:
|
case ApplicationEvent.FeaturesUpdated:
|
||||||
case ApplicationEvent.Launched:
|
case ApplicationEvent.Launched:
|
||||||
runInAction(() => {
|
runInAction(() => {
|
||||||
@@ -76,11 +83,17 @@ export class FeaturesController extends AbstractViewController {
|
|||||||
|
|
||||||
public async showPremiumAlert(featureName: string): Promise<void> {
|
public async showPremiumAlert(featureName: string): Promise<void> {
|
||||||
this.premiumAlertFeatureName = featureName
|
this.premiumAlertFeatureName = featureName
|
||||||
return when(() => this.premiumAlertFeatureName === undefined)
|
this.premiumAlertType = PremiumFeatureModalType.UpgradePrompt
|
||||||
|
|
||||||
|
return when(() => this.premiumAlertType === undefined)
|
||||||
|
}
|
||||||
|
|
||||||
|
showPurchaseSuccessAlert = () => {
|
||||||
|
this.premiumAlertType = PremiumFeatureModalType.UpgradeSuccess
|
||||||
}
|
}
|
||||||
|
|
||||||
public closePremiumAlert() {
|
public closePremiumAlert() {
|
||||||
this.premiumAlertFeatureName = undefined
|
this.premiumAlertType = undefined
|
||||||
}
|
}
|
||||||
|
|
||||||
private isEntitledToFiles(): boolean {
|
private isEntitledToFiles(): boolean {
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
|
import { LoggingDomain, log } from '@/Logging'
|
||||||
import { loadPurchaseFlowUrl } from '@/Components/PurchaseFlow/PurchaseFlowFunctions'
|
import { loadPurchaseFlowUrl } from '@/Components/PurchaseFlow/PurchaseFlowFunctions'
|
||||||
import { InternalEventBus } from '@standardnotes/snjs'
|
import { InternalEventBus, AppleIAPProductId } from '@standardnotes/snjs'
|
||||||
import { action, makeObservable, observable } from 'mobx'
|
import { action, makeObservable, observable } from 'mobx'
|
||||||
import { WebApplication } from '../../Application/Application'
|
import { WebApplication } from '../../Application/Application'
|
||||||
import { AbstractViewController } from '../Abstract/AbstractViewController'
|
import { AbstractViewController } from '../Abstract/AbstractViewController'
|
||||||
@@ -26,15 +27,67 @@ export class PurchaseFlowController extends AbstractViewController {
|
|||||||
this.currentPane = currentPane
|
this.currentPane = currentPane
|
||||||
}
|
}
|
||||||
|
|
||||||
openPurchaseFlow = (): void => {
|
openPurchaseFlow = (plan = AppleIAPProductId.ProPlanYearly): void => {
|
||||||
const user = this.application.getUser()
|
const user = this.application.getUser()
|
||||||
if (!user) {
|
if (!user) {
|
||||||
this.isOpen = true
|
this.isOpen = true
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.application.isNativeIOS()) {
|
||||||
|
void this.beginIosIapPurchaseFlow(plan)
|
||||||
} else {
|
} else {
|
||||||
loadPurchaseFlowUrl(this.application).catch(console.error)
|
loadPurchaseFlowUrl(this.application).catch(console.error)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
openPurchaseWebpage = () => {
|
||||||
|
loadPurchaseFlowUrl(this.application).catch((err) => {
|
||||||
|
console.error(err)
|
||||||
|
this.application.alertService.alert(err).catch(console.error)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
beginIosIapPurchaseFlow = async (plan: AppleIAPProductId): Promise<void> => {
|
||||||
|
const result = await this.application.mobileDevice().purchaseSubscriptionIAP(plan)
|
||||||
|
|
||||||
|
log(LoggingDomain.Purchasing, 'BeginIosIapPurchaseFlow result', result)
|
||||||
|
|
||||||
|
if (!result) {
|
||||||
|
void this.application.alertService.alert('Your purchase was canceled or failed. Please try again.')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const showGenericError = () => {
|
||||||
|
void this.application.alertService.alert(
|
||||||
|
'There was an error confirming your purchase. Please contact support at help@standardnotes.com.',
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
log(LoggingDomain.Purchasing, 'Confirming result with our server')
|
||||||
|
|
||||||
|
const token = await this.application.getNewSubscriptionToken()
|
||||||
|
|
||||||
|
if (!token) {
|
||||||
|
log(LoggingDomain.Purchasing, 'Unable to generate subscription token')
|
||||||
|
showGenericError()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const confirmResult = await this.application.subscriptions.confirmAppleIAP(result, token)
|
||||||
|
|
||||||
|
log(LoggingDomain.Purchasing, 'Server confirm result', confirmResult)
|
||||||
|
|
||||||
|
if (confirmResult) {
|
||||||
|
void this.application.alerts.alert(
|
||||||
|
'Please allow a few minutes for your subscription benefits to activate. You will see a confirmation alert in the app when your subscription is ready.',
|
||||||
|
'Your purchase was successful!',
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
showGenericError()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
closePurchaseFlow = (): void => {
|
closePurchaseFlow = (): void => {
|
||||||
this.isOpen = false
|
this.isOpen = false
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ export class SubscriptionController extends AbstractViewController {
|
|||||||
userSubscription: Subscription | undefined = undefined
|
userSubscription: Subscription | undefined = undefined
|
||||||
availableSubscriptions: AvailableSubscriptions | undefined = undefined
|
availableSubscriptions: AvailableSubscriptions | undefined = undefined
|
||||||
subscriptionInvitations: Invitation[] | undefined = undefined
|
subscriptionInvitations: Invitation[] | undefined = undefined
|
||||||
hideSubscriptionMarketing: boolean
|
|
||||||
hasAccount: boolean
|
hasAccount: boolean
|
||||||
|
|
||||||
override deinit() {
|
override deinit() {
|
||||||
@@ -39,14 +38,12 @@ export class SubscriptionController extends AbstractViewController {
|
|||||||
private subscriptionManager: SubscriptionClientInterface,
|
private subscriptionManager: SubscriptionClientInterface,
|
||||||
) {
|
) {
|
||||||
super(application, eventBus)
|
super(application, eventBus)
|
||||||
this.hideSubscriptionMarketing = application.hideSubscriptionMarketing
|
|
||||||
this.hasAccount = application.hasAccount()
|
this.hasAccount = application.hasAccount()
|
||||||
|
|
||||||
makeObservable(this, {
|
makeObservable(this, {
|
||||||
userSubscription: observable,
|
userSubscription: observable,
|
||||||
availableSubscriptions: observable,
|
availableSubscriptions: observable,
|
||||||
subscriptionInvitations: observable,
|
subscriptionInvitations: observable,
|
||||||
hideSubscriptionMarketing: observable,
|
|
||||||
hasAccount: observable,
|
hasAccount: observable,
|
||||||
|
|
||||||
userSubscriptionName: computed,
|
userSubscriptionName: computed,
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import { WebApplication } from '@/Application/Application'
|
import { WebApplication } from '@/Application/Application'
|
||||||
import { ViewControllerManager } from '@/Controllers/ViewControllerManager'
|
|
||||||
import { observer } from 'mobx-react-lite'
|
import { observer } from 'mobx-react-lite'
|
||||||
import { FunctionComponent, createContext, useCallback, useContext, ReactNode } from 'react'
|
import { FunctionComponent, createContext, useCallback, useContext, ReactNode } from 'react'
|
||||||
import PremiumFeaturesModal from '@/Components/PremiumFeaturesModal/PremiumFeaturesModal'
|
import PremiumFeaturesModal from '@/Components/PremiumFeaturesModal/PremiumFeaturesModal'
|
||||||
|
import { FeaturesController } from '@/Controllers/FeaturesController'
|
||||||
|
|
||||||
type PremiumModalContextData = {
|
type PremiumModalContextData = {
|
||||||
activate: (featureName: string) => void
|
activate: (featureName: string) => void
|
||||||
@@ -24,15 +24,13 @@ export const usePremiumModal = (): PremiumModalContextData => {
|
|||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
application: WebApplication
|
application: WebApplication
|
||||||
viewControllerManager: ViewControllerManager
|
featuresController: FeaturesController
|
||||||
children: ReactNode
|
children: ReactNode
|
||||||
}
|
}
|
||||||
|
|
||||||
const PremiumModalProvider: FunctionComponent<Props> = observer(
|
const PremiumModalProvider: FunctionComponent<Props> = observer(
|
||||||
({ application, viewControllerManager, children }: Props) => {
|
({ application, featuresController, children }: Props) => {
|
||||||
const featureName = viewControllerManager.featuresController.premiumAlertFeatureName || ''
|
const featureName = featuresController.premiumAlertFeatureName || ''
|
||||||
|
|
||||||
const showModal = !!featureName
|
|
||||||
|
|
||||||
const hasSubscription = application.hasValidSubscription()
|
const hasSubscription = application.hasValidSubscription()
|
||||||
|
|
||||||
@@ -40,25 +38,26 @@ const PremiumModalProvider: FunctionComponent<Props> = observer(
|
|||||||
|
|
||||||
const activate = useCallback(
|
const activate = useCallback(
|
||||||
(feature: string) => {
|
(feature: string) => {
|
||||||
viewControllerManager.featuresController.showPremiumAlert(feature).catch(console.error)
|
featuresController.showPremiumAlert(feature).catch(console.error)
|
||||||
},
|
},
|
||||||
[viewControllerManager],
|
[featuresController],
|
||||||
)
|
)
|
||||||
|
|
||||||
const close = useCallback(() => {
|
const close = useCallback(() => {
|
||||||
viewControllerManager.featuresController.closePremiumAlert()
|
featuresController.closePremiumAlert()
|
||||||
}, [viewControllerManager])
|
}, [featuresController])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{showModal && (
|
{featuresController.premiumAlertType != undefined && (
|
||||||
<PremiumFeaturesModal
|
<PremiumFeaturesModal
|
||||||
application={application}
|
application={application}
|
||||||
featureName={featureName}
|
featureName={featureName}
|
||||||
hasSubscription={hasSubscription}
|
hasSubscription={hasSubscription}
|
||||||
hasAccount={hasAccount}
|
hasAccount={hasAccount}
|
||||||
onClose={close}
|
onClose={close}
|
||||||
showModal={!!featureName}
|
showModal={featuresController.premiumAlertType != undefined}
|
||||||
|
type={featuresController.premiumAlertType}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
<PremiumModalProvider_ value={{ activate }}>{children}</PremiumModalProvider_>
|
<PremiumModalProvider_ value={{ activate }}>{children}</PremiumModalProvider_>
|
||||||
@@ -71,12 +70,10 @@ PremiumModalProvider.displayName = 'PremiumModalProvider'
|
|||||||
|
|
||||||
const PremiumModalProviderWithDeallocateHandling: FunctionComponent<Props> = ({
|
const PremiumModalProviderWithDeallocateHandling: FunctionComponent<Props> = ({
|
||||||
application,
|
application,
|
||||||
viewControllerManager,
|
featuresController,
|
||||||
children,
|
children,
|
||||||
}) => {
|
}) => {
|
||||||
return (
|
return <PremiumModalProvider application={application} featuresController={featuresController} children={children} />
|
||||||
<PremiumModalProvider application={application} viewControllerManager={viewControllerManager} children={children} />
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default observer(PremiumModalProviderWithDeallocateHandling)
|
export default observer(PremiumModalProviderWithDeallocateHandling)
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ export enum LoggingDomain {
|
|||||||
Viewport,
|
Viewport,
|
||||||
Selection,
|
Selection,
|
||||||
BlockEditor,
|
BlockEditor,
|
||||||
|
Purchasing,
|
||||||
}
|
}
|
||||||
|
|
||||||
const LoggingStatus: Record<LoggingDomain, boolean> = {
|
const LoggingStatus: Record<LoggingDomain, boolean> = {
|
||||||
@@ -18,7 +19,8 @@ const LoggingStatus: Record<LoggingDomain, boolean> = {
|
|||||||
[LoggingDomain.NavigationList]: false,
|
[LoggingDomain.NavigationList]: false,
|
||||||
[LoggingDomain.Viewport]: false,
|
[LoggingDomain.Viewport]: false,
|
||||||
[LoggingDomain.Selection]: false,
|
[LoggingDomain.Selection]: false,
|
||||||
[LoggingDomain.BlockEditor]: true,
|
[LoggingDomain.BlockEditor]: false,
|
||||||
|
[LoggingDomain.Purchasing]: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
|
|||||||
11
yarn.lock
11
yarn.lock
@@ -5728,6 +5728,7 @@ __metadata:
|
|||||||
react-native-fingerprint-scanner: "standardnotes/react-native-fingerprint-scanner#b55d1c0ca627a87a130f758603f12911fbac200f"
|
react-native-fingerprint-scanner: "standardnotes/react-native-fingerprint-scanner#b55d1c0ca627a87a130f758603f12911fbac200f"
|
||||||
react-native-flag-secure-android: "standardnotes/react-native-flag-secure-android#cb08e74583c22a5d912842459b35ebbbb4bcd852"
|
react-native-flag-secure-android: "standardnotes/react-native-flag-secure-android#cb08e74583c22a5d912842459b35ebbbb4bcd852"
|
||||||
react-native-fs: ^2.19.0
|
react-native-fs: ^2.19.0
|
||||||
|
react-native-iap: ^12.4.4
|
||||||
react-native-keychain: "standardnotes/react-native-keychain#d277d360494cbd02be4accb4a360772a8e0e97b6"
|
react-native-keychain: "standardnotes/react-native-keychain#d277d360494cbd02be4accb4a360772a8e0e97b6"
|
||||||
react-native-privacy-snapshot: "standardnotes/react-native-privacy-snapshot#653e904c90fc6f2b578da59138f2bfe5d7f942fe"
|
react-native-privacy-snapshot: "standardnotes/react-native-privacy-snapshot#653e904c90fc6f2b578da59138f2bfe5d7f942fe"
|
||||||
react-native-share: ^7.9.0
|
react-native-share: ^7.9.0
|
||||||
@@ -25623,6 +25624,16 @@ __metadata:
|
|||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
|
"react-native-iap@npm:^12.4.4":
|
||||||
|
version: 12.4.4
|
||||||
|
resolution: "react-native-iap@npm:12.4.4"
|
||||||
|
peerDependencies:
|
||||||
|
react: ">=16.13.1"
|
||||||
|
react-native: ">=0.65.1"
|
||||||
|
checksum: f5c71ba006d12bc12791f085d5da70259e06d81d333f67dca4499cee189266b3eed88078c29f0d01138fccd97e87893936de4946a21a322c7bbb2e601273471f
|
||||||
|
languageName: node
|
||||||
|
linkType: hard
|
||||||
|
|
||||||
"react-native-keychain@standardnotes/react-native-keychain#d277d360494cbd02be4accb4a360772a8e0e97b6":
|
"react-native-keychain@standardnotes/react-native-keychain#d277d360494cbd02be4accb4a360772a8e0e97b6":
|
||||||
version: 8.0.0
|
version: 8.0.0
|
||||||
resolution: "react-native-keychain@https://github.com/standardnotes/react-native-keychain.git#commit=d277d360494cbd02be4accb4a360772a8e0e97b6"
|
resolution: "react-native-keychain@https://github.com/standardnotes/react-native-keychain.git#commit=d277d360494cbd02be4accb4a360772a8e0e97b6"
|
||||||
|
|||||||
Reference in New Issue
Block a user