Skip to content

Commit 49a45e5

Browse files
committed
chore: fetch subscription if billing is enabled
1 parent 72fb3b4 commit 49a45e5

File tree

1 file changed

+28
-19
lines changed

1 file changed

+28
-19
lines changed

frontend/appflowy_flutter/lib/workspace/application/user/user_workspace_bloc.dart

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import 'package:appflowy/startup/startup.dart';
66
import 'package:appflowy/user/application/reminder/reminder_bloc.dart';
77
import 'package:appflowy/user/application/user_listener.dart';
88
import 'package:appflowy/user/application/user_service.dart';
9+
import 'package:appflowy/workspace/presentation/settings/widgets/setting_appflowy_cloud.dart';
910
import 'package:appflowy_backend/log.dart';
1011
import 'package:appflowy_backend/protobuf/flowy-error/code.pbenum.dart';
1112
import 'package:appflowy_backend/protobuf/flowy-error/errors.pb.dart';
@@ -119,28 +120,36 @@ class UserWorkspaceBloc extends Bloc<UserWorkspaceEvent, UserWorkspaceState> {
119120
Emitter<UserWorkspaceState> emit,
120121
String workspaceId,
121122
) async {
122-
unawaited(UserBackendService.getWorkspaceSubscriptionInfo(workspaceId).fold(
123-
(workspaceSubscriptionInfo) {
124-
if (!isClosed) {
125-
return;
126-
}
123+
final enabled = await isBillingEnabled();
124+
// If billing is not enabled, we don't need to fetch the workspace subscription info
125+
if (!enabled) {
126+
return;
127+
}
127128

128-
if (state.currentWorkspace?.workspaceId != workspaceId) {
129-
return;
130-
}
129+
unawaited(
130+
UserBackendService.getWorkspaceSubscriptionInfo(workspaceId).fold(
131+
(workspaceSubscriptionInfo) {
132+
if (isClosed) {
133+
return;
134+
}
131135

132-
Log.debug(
133-
'fetch workspace subscription info: $workspaceId, $workspaceSubscriptionInfo',
134-
);
136+
if (state.currentWorkspace?.workspaceId != workspaceId) {
137+
return;
138+
}
135139

136-
emit(
137-
state.copyWith(
138-
workspaceSubscriptionInfo: workspaceSubscriptionInfo,
139-
),
140-
);
141-
},
142-
(e) => Log.error('fetch workspace subscription info error: $e'),
143-
));
140+
Log.debug(
141+
'fetch workspace subscription info: $workspaceId, $workspaceSubscriptionInfo',
142+
);
143+
144+
emit(
145+
state.copyWith(
146+
workspaceSubscriptionInfo: workspaceSubscriptionInfo,
147+
),
148+
);
149+
},
150+
(e) => Log.error('fetch workspace subscription info error: $e'),
151+
),
152+
);
144153
}
145154

146155
Future<void> _initializeWorkspaces(Emitter<UserWorkspaceState> emit) async {

0 commit comments

Comments
 (0)