Skip to content

Commit

Permalink
Fix mapping pro subscription
Browse files Browse the repository at this point in the history
  • Loading branch information
KuznetsovNikita committed Apr 15, 2024
1 parent 729d0ef commit ea18a74
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
2 changes: 1 addition & 1 deletion packages/core/src/entries/pro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export interface ProSubscriptionInvalid {
export function isTrialSubscription(
subscription: ProSubscription
): subscription is ProSubscriptionTrial {
return subscription.isTrial;
return subscription.isTrial && subscription.valid;
}

export function isValidSubscription(
Expand Down
31 changes: 15 additions & 16 deletions packages/core/src/service/proService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,31 +88,30 @@ export const loadProState = async (
const subscriptionDTO = await ProServiceService.proServiceVerify();

let subscription: ProSubscription;
if (subscriptionDTO.is_trial) {
subscription = {
valid: true,
isTrial: true,
usedTrial: true,
trialUserId: user.tg_id!,
trialEndDate: new Date(subscriptionDTO.next_charge! * 1000)
};
} else {
if (subscriptionDTO.valid) {
if (subscriptionDTO.valid) {
if (subscriptionDTO.is_trial) {
subscription = {
valid: true,
isTrial: false,
usedTrial: subscriptionDTO.used_trial,
nextChargeDate: new Date(subscriptionDTO.next_charge! * 1000)
isTrial: true,
usedTrial: true,
trialUserId: user.tg_id!,
trialEndDate: new Date(subscriptionDTO.next_charge! * 1000)
};
} else {
subscription = {
valid: false,
valid: true,
isTrial: false,
usedTrial: subscriptionDTO.used_trial
usedTrial: subscriptionDTO.used_trial,
nextChargeDate: new Date(subscriptionDTO.next_charge! * 1000)
};
}
} else {
subscription = {
valid: false,
isTrial: false,
usedTrial: subscriptionDTO.used_trial
};
}

return {
subscription,
hasWalletAuthCookie: !!user.pub_key,
Expand Down

0 comments on commit ea18a74

Please sign in to comment.