chore: remove calling payments server for subscriptions if using third party api hosts (#2398)

This commit is contained in:
Karol Sójko
2023-08-09 13:16:19 +02:00
committed by GitHub
parent e05d8c9e76
commit 90dcb33a44
24 changed files with 233 additions and 89 deletions

View File

@@ -52,4 +52,6 @@ export const Web_TYPES = {
LoadPurchaseFlowUrl: Symbol.for('LoadPurchaseFlowUrl'),
OpenSubscriptionDashboard: Symbol.for('OpenSubscriptionDashboard'),
PanesForLayout: Symbol.for('PanesForLayout'),
GetHost: Symbol.for('GetHost'),
IsApplicationUsingThirdPartyHost: Symbol.for('IsApplicationUsingThirdPartyHost'),
}

View File

@@ -17,7 +17,7 @@ import {
} from '@standardnotes/ui-services'
import { DependencyContainer } from '@standardnotes/utils'
import { Web_TYPES } from './Types'
import { BackupServiceInterface, isDesktopDevice } from '@standardnotes/snjs'
import { BackupServiceInterface, GetHost, IsApplicationUsingThirdPartyHost, isDesktopDevice } from '@standardnotes/snjs'
import { DesktopManager } from '../Device/DesktopManager'
import { MomentsService } from '@/Controllers/Moments/MomentsService'
import { PersistenceService } from '@/Controllers/Abstract/PersistenceService'
@@ -195,6 +195,14 @@ export class WebDependencies extends DependencyContainer {
return new PanesForLayout(this.get<IsTabletOrMobileScreen>(Web_TYPES.IsTabletOrMobileScreen))
})
this.bind(Web_TYPES.GetHost, () => {
return new GetHost(application.legacyApi)
})
this.bind(Web_TYPES.IsApplicationUsingThirdPartyHost, () => {
return new IsApplicationUsingThirdPartyHost(this.get<GetHost>(Web_TYPES.GetHost))
})
this.bind(Web_TYPES.IsTabletOrMobileScreen, () => {
return new IsTabletOrMobileScreen(application.environment)
})
@@ -320,7 +328,11 @@ export class WebDependencies extends DependencyContainer {
})
this.bind(Web_TYPES.GetPurchaseFlowUrl, () => {
return new GetPurchaseFlowUrl(application, application.legacyApi)
return new GetPurchaseFlowUrl(
application,
application.legacyApi,
this.get<IsApplicationUsingThirdPartyHost>(Web_TYPES.IsApplicationUsingThirdPartyHost),
)
})
this.bind(Web_TYPES.SyncStatusController, () => {

View File

@@ -1,17 +1,30 @@
import { isDesktopApplication } from '@/Utils'
import { ApplicationInterface, LegacyApiServiceInterface, Result, UseCaseInterface } from '@standardnotes/snjs'
import {
ApplicationInterface,
IsApplicationUsingThirdPartyHost,
LegacyApiServiceInterface,
Result,
UseCaseInterface,
} from '@standardnotes/snjs'
export class GetPurchaseFlowUrl implements UseCaseInterface<string> {
constructor(
private application: ApplicationInterface,
private legacyApi: LegacyApiServiceInterface,
private isApplicationUsingThirdPartyHostUseCase: IsApplicationUsingThirdPartyHost,
) {}
async execute(): Promise<Result<string>> {
const currentUrl = window.location.origin
const successUrl = isDesktopApplication() ? 'standardnotes://' : currentUrl
if (this.application.sessions.isSignedOut() || this.application.isThirdPartyHostUsed()) {
const isThirdPartyHostUsedOrError = this.isApplicationUsingThirdPartyHostUseCase.execute()
if (isThirdPartyHostUsedOrError.isFailed()) {
return Result.fail(isThirdPartyHostUsedOrError.getError()!)
}
const isThirdPartyHostUsed = isThirdPartyHostUsedOrError.getValue()
if (this.application.sessions.isSignedOut() || isThirdPartyHostUsed) {
return Result.ok(`${window.purchaseUrl}/offline?&success_url=${successUrl}`)
}

View File

@@ -17,7 +17,7 @@ type Props = {
}
const AccountPreferences = ({ application }: Props) => {
const isUsingThirdPartyServer = application.isThirdPartyHostUsed()
const isUsingThirdPartyServer = !application.sessions.isSignedIntoFirstPartyServer()
return (
<PreferencesPane>

View File

@@ -25,7 +25,7 @@ const FilesSection: FunctionComponent<Props> = ({ application }) => {
setFilesQuotaUsed(parseFloat(filesQuotaUsed))
}
if (!application.isThirdPartyHostUsed()) {
if (application.sessions.isSignedIntoFirstPartyServer()) {
const filesQuotaTotal = await application.settings.getSubscriptionSetting(
SettingName.create(SettingName.NAMES.FileUploadBytesLimit).getValue(),
)
@@ -54,7 +54,12 @@ const FilesSection: FunctionComponent<Props> = ({ application }) => {
<>
<div className="mb-1 mt-1">
<span className="font-semibold">{formatSizeToReadableString(filesQuotaUsed)}</span> of{' '}
<span>{application.isThirdPartyHostUsed() ? '∞' : formatSizeToReadableString(filesQuotaTotal)}</span> used
<span>
{application.sessions.isSignedIntoFirstPartyServer()
? formatSizeToReadableString(filesQuotaTotal)
: '∞'}
</span>{' '}
used
</div>
<progress
className="progress-bar w-full"

View File

@@ -13,7 +13,7 @@ type Props = {
}
const Backups: FunctionComponent<Props> = ({ application }) => {
const isUsingThirdPartyServer = application.isThirdPartyHostUsed()
const isUsingThirdPartyServer = !application.sessions.isSignedIntoFirstPartyServer()
return (
<PreferencesPane>

View File

@@ -26,7 +26,9 @@ const OfflineSubscription: FunctionComponent<Props> = ({ application, onSuccess
}, [application])
const shouldShowOfflineSubscription = () => {
return !application.hasAccount() || application.isThirdPartyHostUsed() || hasUserPreviouslyStoredCode
return (
!application.hasAccount() || !application.sessions.isSignedIntoFirstPartyServer() || hasUserPreviouslyStoredCode
)
}
const handleSubscriptionCodeSubmit = async (event: React.FormEvent) => {