Skip to content

Commit

Permalink
Rename creditInfo to subscriptionData
Browse files Browse the repository at this point in the history
  • Loading branch information
FadhlanR committed Nov 19, 2024
1 parent d311160 commit 7628afe
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -209,31 +209,31 @@ export default class ProfileInfoPopover extends Component<ProfileInfoPopoverSign
@service declare matrixService: MatrixService;

private fetchCreditInfo = task(async () => {
await this.realmServer.fetchCreditInfo();
await this.realmServer.fetchSubscriptionData();
});

@action private logout() {
this.matrixService.logout();
}

private get isLoading() {
return this.realmServer.fetchingCreditInfo;
return this.realmServer.fetchingSubscriptionData;
}

private get plan() {
return this.realmServer.creditInfo?.plan;
return this.realmServer.subscriptionData?.plan;
}

private get creditsIncludedInPlanAllowance() {
return this.realmServer.creditInfo?.creditsIncludedInPlanAllowance;
return this.realmServer.subscriptionData?.creditsIncludedInPlanAllowance;
}

private get creditsAvailableInPlanAllowance() {
return this.realmServer.creditInfo?.creditsAvailableInPlanAllowance;
return this.realmServer.subscriptionData?.creditsAvailableInPlanAllowance;
}

private get extraCreditsAvailableInBalance() {
return this.realmServer.creditInfo?.extraCreditsAvailableInBalance;
return this.realmServer.subscriptionData?.extraCreditsAvailableInBalance;
}

private get monthlyCreditText() {
Expand Down
26 changes: 13 additions & 13 deletions packages/host/app/services/realm-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ interface AvailableRealm {
type: 'base' | 'catalog' | 'user';
}

interface CreditInfo {
interface SubscriptionData {
plan: string | null;
creditsAvailableInPlanAllowance: number | null;
creditsIncludedInPlanAllowance: number | null;
Expand All @@ -56,7 +56,7 @@ interface CreditInfo {
export default class RealmServerService extends Service {
@service private declare network: NetworkService;
@service private declare reset: ResetService;
@tracked private _creditInfo: CreditInfo | null = null;
@tracked private _subscriptionData: SubscriptionData | null = null;
private auth: AuthStatus = { type: 'anonymous' };
private client: ExtendedClient | undefined;
private availableRealms = new TrackedArray<AvailableRealm>([
Expand Down Expand Up @@ -176,11 +176,11 @@ export default class RealmServerService extends Service {
});
}

async fetchCreditInfo() {
if (this.creditInfo) {
async fetchSubscriptionData() {
if (this.subscriptionData) {
return;
}
await this.fetchCreditInfoTask.perform();
await this.fetchSubscriptionDataTask.perform();
}

async handleRealmServerEvent(maybeRealmServerEvent: Partial<IEvent>) {
Expand All @@ -195,15 +195,15 @@ export default class RealmServerService extends Service {
return;
}

await this.fetchCreditInfoTask.perform();
await this.fetchSubscriptionDataTask.perform();
}

get creditInfo() {
return this._creditInfo;
get subscriptionData() {
return this._subscriptionData;
}

get fetchingCreditInfo() {
return this.fetchCreditInfoTask.isRunning;
get fetchingSubscriptionData() {
return this.fetchSubscriptionDataTask.isRunning;
}

async fetchCatalogRealms() {
Expand Down Expand Up @@ -239,9 +239,9 @@ export default class RealmServerService extends Service {
return new URL(url);
}

private fetchCreditInfoTask = dropTask(async () => {
private fetchSubscriptionDataTask = dropTask(async () => {
if (!this.client) {
throw new Error(`Cannot fetch credit info without matrix client`);
throw new Error(`Cannot fetch subscription data without matrix client`);
}
await this.login();
if (this.auth.type !== 'logged-in') {
Expand Down Expand Up @@ -270,7 +270,7 @@ export default class RealmServerService extends Service {
json.data?.attributes?.creditsIncludedInPlanAllowance ?? null;
let extraCreditsAvailableInBalance =
json.data?.attributes?.extraCreditsAvailableInBalance ?? null;
this._creditInfo = {
this._subscriptionData = {
plan,
creditsAvailableInPlanAllowance,
creditsIncludedInPlanAllowance,
Expand Down

0 comments on commit 7628afe

Please sign in to comment.