Skip to content

Commit

Permalink
Merge pull request #136 from TheRedSpy15/develop
Browse files Browse the repository at this point in the history
Develop 1.4.0
  • Loading branch information
TheRedSpy15 committed May 10, 2024
2 parents f4e2ae7 + 5bb4546 commit e39848c
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 41 deletions.
9 changes: 4 additions & 5 deletions lib/constants.dart
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import 'package:blazedcloud/models/pocketbase/authstore.dart';
import 'package:pocketbase/pocketbase.dart';

// prod
const String backendUrl = "https://pb.blazedcloud.com";
// lan
//const String backendUrl = "http://192.168.68.89:8089";
// devs
//const String backendUrl = "https://hazmav.tplinkdns.com:8089";
const filePageIndex = 0;
const settingsPageIndex = 3;
const stripe100gbPriceId = 'price_1PF12LEnqBPpR1rOGlwYE0Xi';
const stripe1tbPriceId = 'price_1OVjb8EnqBPpR1rOYF2TdM3f';
const stripePortalUrl = 'https://billing.stripe.com/p/login/fZeaI4a7Teoycuc5kk';
const syncPageIndex = 2;
const transferPageIndex = 1;

var pb = PocketBase(backendUrl, authStore: CustomAuthStore());
2 changes: 1 addition & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import 'generated/l10n.dart';

void main() async {
WidgetsFlutterBinding.ensureInitialized();
await SystemChrome.setPreferredOrientations([
SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
]);

Expand Down
63 changes: 34 additions & 29 deletions lib/pages/transfers/usage_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:blazedcloud/constants.dart';
import 'package:blazedcloud/generated/l10n.dart';
import 'package:blazedcloud/log.dart';
import 'package:blazedcloud/providers/files_providers.dart';
import 'package:blazedcloud/services/files_api.dart';
import 'package:flutter/material.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
Expand Down Expand Up @@ -82,43 +83,47 @@ class UsageCard extends ConsumerWidget {
if (!data['isTerabyteActive'])
OutlinedButton(
onPressed: () {
final browser = RefChromeSafariBrowser(ref: ref);
browser
.open(
url: WebUri(
"https://portal.blazedcloud.com/auth/subscribe"))
.then((value) {
logger.d('Invalidating combinedDataProvider');
ref.invalidate(
combinedDataProvider(pb.authStore.model.id));
});
},
child: Text(S.of(context).upgradeStorage))
else if (data['stripeActive'])
OutlinedButton(
onPressed: () {
const link =
"https://portal.blazedcloud.com/dashboard/account";
canLaunchUrl(Uri.parse(link)).then((canLaunch) {
if (canLaunch) {
ScaffoldMessenger.of(ref.context).showSnackBar(
SnackBar(
content: Text(
S.of(ref.context).openingInBrowser),
),
);
launchUrl(Uri.parse(link));
} else {
logger.e('Could not launch url: $link');
// snackbar to show loading
ScaffoldMessenger.of(ref.context).showSnackBar(
SnackBar(
content:
Text(S.of(ref.context).openingInBrowser),
),
);

getStripeCheckout(pb.authStore.model.id,
stripe1tbPriceId, pb.authStore.token)
.then((url) {
logger.d('Opening stripe checkout $url');
final browser = RefChromeSafariBrowser(ref: ref);
browser.open(url: WebUri(url)).then((value) {
logger.d('Invalidating combinedDataProvider');
ref.invalidate(combinedDataProvider(
pb.authStore.model.id));
}).catchError((e) {
ScaffoldMessenger.of(ref.context).showSnackBar(
SnackBar(
content:
Text(S.of(context).failedToOpenPortal),
),
);
}
});
}).catchError((e) {
logger.e(e);
});
},
child: Text(S.of(context).upgradeStorage))
else if (data['stripeActive'])
OutlinedButton(
onPressed: () {
ScaffoldMessenger.of(ref.context).showSnackBar(
SnackBar(
content:
Text(S.of(ref.context).openingInBrowser),
),
);
launchUrl(Uri.parse(stripePortalUrl));
},
child: Text(S.of(context).manageAccount))
else if (!data['stripeActive'] && data['isTerabyteActive'])
Text(S.of(context).subscribedThroughPlaystoreOrAppstore),
Expand Down
20 changes: 20 additions & 0 deletions lib/services/files_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,26 @@ Future<List<String>> getSearchList(String uid, String token) async {
}
}

Future<String> getStripeCheckout(
String uid, String priceId, String token) async {
var headers = {'Authorization': 'Bearer $token'};
var request =
http.Request('POST', Uri.parse('$backendUrl/stripe/checkout/$uid'));
request.bodyFields = {'priceId': priceId};
request.headers.addAll(headers);

http.StreamedResponse response = await httpClient.send(request);

if (response.statusCode == 200) {
final responseBody = await response.stream.bytesToString();
logger.d("Got stripe checkout $responseBody");
return jsonDecode(responseBody)['url'];
} else {
logger.e(response.reasonPhrase);
throw Exception('Failed to get stripe checkout');
}
}

/// uid is automatically added to key by back end, if not present
Future<String> getUploadUrl(
String uid, String fileKey, String token, int length,
Expand Down
8 changes: 4 additions & 4 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -258,10 +258,10 @@ packages:
dependency: "direct dev"
description:
name: flutter_lints
sha256: e2a421b7e59244faef694ba7b30562e489c2b489866e505074eb005cd7060db7
sha256: "3f41d009ba7172d5ff9be5f6e6e6abb4300e263aab8866d2a0842ed2a70f8f0c"
url: "https://pub.dev"
source: hosted
version: "3.0.1"
version: "4.0.0"
flutter_local_notifications:
dependency: "direct main"
description:
Expand Down Expand Up @@ -457,10 +457,10 @@ packages:
dependency: transitive
description:
name: lints
sha256: cbf8d4b858bb0134ef3ef87841abdf8d63bfc255c266b7bf6b39daa1085c4290
sha256: "976c774dd944a42e83e2467f4cc670daef7eed6295b10b36ae8c85bcbf828235"
url: "https://pub.dev"
source: hosted
version: "3.0.0"
version: "4.0.0"
local_auth:
dependency: "direct main"
description:
Expand Down
4 changes: 2 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
# In Windows, build-name is used as the major, minor, and patch parts
# of the product and file versions while build-number is used as the build suffix.
# format: x.x.x+x0x0x
version: 1.3.9+10309
version: 1.4.0+10400

environment:
sdk: '>=3.1.2 <4.0.0'
Expand Down Expand Up @@ -73,7 +73,7 @@ dev_dependencies:
# activated in the `analysis_options.yaml` file located at the root of your
# package. See that file for information about deactivating specific lint
# rules and activating additional ones.
flutter_lints: ^3.0.0
flutter_lints: ^4.0.0
flutter_launcher_icons: "^0.13.1"

flutter_launcher_icons:
Expand Down

0 comments on commit e39848c

Please sign in to comment.