Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/dynamic SKU #866

Merged
merged 7 commits into from
Aug 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 11 additions & 28 deletions wallet/lib/components/no_internet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ class NoInternetDialog {
_isShowing = value;
}

Future showNoInternet() {
Future showNoInternet() async {
if (navigatorKey.currentState == null || navigatorKey.currentState!.overlay == null) {
return;
}

return showDialog(
context: navigatorKey.currentState!.overlay!.context,
barrierDismissible: true,
Expand Down Expand Up @@ -60,10 +64,7 @@ class NoInternetDialog {
SizedBox(height: 30.h),
Text(
NETWORK_ERROR,
style: TextStyle(
color: Colors.white,
fontSize: 18.sp,
fontWeight: FontWeight.w800),
style: TextStyle(color: Colors.white, fontSize: 18.sp, fontWeight: FontWeight.w800),
),
SizedBox(height: 20.h),
Padding(
Expand All @@ -74,20 +75,14 @@ class NoInternetDialog {
children: [
TextSpan(
text: "no_internet_connection".tr(),
style: Theme.of(navigatorKey.currentState!.context)
.textTheme
.bodyText2!
.copyWith(
style: Theme.of(navigatorKey.currentState!.context).textTheme.bodyText2!.copyWith(
color: Colors.white,
fontSize: 12.sp,
),
),
TextSpan(
text: email,
style: Theme.of(navigatorKey.currentState!.context)
.textTheme
.bodyText2!
.copyWith(
style: Theme.of(navigatorKey.currentState!.context).textTheme.bodyText2!.copyWith(
color: Colors.white,
fontSize: 12.sp,
),
Expand All @@ -109,13 +104,7 @@ class NoInternetDialog {
child: Center(
child: Text(
kCancelText,
style: Theme.of(navigatorKey.currentState!.context)
.textTheme
.bodyText1!
.copyWith(
fontSize: 16.sp,
color: kWhite,
fontWeight: FontWeight.w300),
style: Theme.of(navigatorKey.currentState!.context).textTheme.bodyText1!.copyWith(fontSize: 16.sp, color: kWhite, fontWeight: FontWeight.w300),
),
),
),
Expand All @@ -133,10 +122,7 @@ class NoInternetDialog {
);
}

Widget buildBackupButton(
{required String title,
required Color bgColor,
required VoidCallback onPressed}) {
Widget buildBackupButton({required String title, required Color bgColor, required VoidCallback onPressed}) {
return InkWell(
onTap: () {
onPressed.call();
Expand All @@ -152,10 +138,7 @@ class NoInternetDialog {
child: Center(
child: Text(
title,
style: TextStyle(
color: bgColor == kButtonColor ? kBlue : kWhite,
fontSize: 16.sp,
fontWeight: FontWeight.w600),
style: TextStyle(color: bgColor == kButtonColor ? kBlue : kWhite, fontSize: 16.sp, fontWeight: FontWeight.w600),
textAlign: TextAlign.center,
)),
),
Expand Down
82 changes: 23 additions & 59 deletions wallet/lib/pages/home/wallet_screen/add_pylon_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,12 @@ import 'package:get_it/get_it.dart';
import 'package:pylons_wallet/components/buttons/custom_paint_button.dart';
import 'package:pylons_wallet/components/loading.dart';
import 'package:pylons_wallet/services/repository/repository.dart';
import 'package:pylons_wallet/utils/base_env.dart';
import 'package:pylons_wallet/utils/constants.dart';
import 'package:pylons_wallet/utils/svg_util.dart';

TextStyle kPylonLabelText = TextStyle(
fontSize: 18.sp,
fontFamily: kUniversalFontFamily,
color: kTextBlackColor,
fontWeight: FontWeight.w800);
TextStyle kTitleText = TextStyle(
fontSize: 15.sp,
fontFamily: kUniversalFontFamily,
color: kBlack,
fontWeight: FontWeight.w700);
TextStyle kSubTitleText = TextStyle(
fontSize: 13.sp,
fontFamily: kUniversalFontFamily,
color: kPriceTagColor,
fontWeight: FontWeight.w700);
TextStyle kPylonLabelText = TextStyle(fontSize: 18.sp, fontFamily: kUniversalFontFamily, color: kTextBlackColor, fontWeight: FontWeight.w800);
TextStyle kTitleText = TextStyle(fontSize: 15.sp, fontFamily: kUniversalFontFamily, color: kBlack, fontWeight: FontWeight.w700);
TextStyle kSubTitleText = TextStyle(fontSize: 13.sp, fontFamily: kUniversalFontFamily, color: kPriceTagColor, fontWeight: FontWeight.w700);

class AddPylonScreen extends StatefulWidget {
const AddPylonScreen({Key? key}) : super(key: key);
Expand All @@ -36,6 +24,7 @@ class AddPylonScreen extends StatefulWidget {

class _AddPylonScreenState extends State<AddPylonScreen> {
Repository get repository => GetIt.I.get();
BaseEnv get baseEnv => GetIt.I.get();

@override
Widget build(BuildContext context) {
Expand Down Expand Up @@ -72,39 +61,21 @@ class _AddPylonScreenState extends State<AddPylonScreen> {
SizedBox(
height: 80.h,
),
buildBuyRow(
svgAsset: SVGUtil.PYLON_ONE_CURRENCY,
pylonText: kBuyPylonOne,
bonusText: "",
subtitle: kOneUSD,
onPressed: () async {
buyProduct(itemId: kPylons1);
},
),
SizedBox(
height: 30.h,
),
buildBuyRow(
svgAsset: SVGUtil.PYLON_THREE_CURRENCY,
pylonText: kBuyPylonThree,
bonusText: "bonus_five".tr(),
subtitle: kThreeUSD,
onPressed: () async {
buyProduct(itemId: kPylons3);
},
),
SizedBox(
height: 40.h,
),
buildBuyRow(
svgAsset: SVGUtil.PYLON_FIVE_CURRENCY,
pylonText: kBuyPylonFive,
bonusText: "bonus_ten".tr(),
subtitle: kFiveUSD,
onPressed: () {
buyProduct(itemId: kPylons5);
},
),
Expanded(
child: ListView.separated(
itemBuilder: (context, index) => buildBuyRow(
svgAsset: baseEnv.skus[index].getSvgAsset(),
pylonText: baseEnv.skus[index].pylons,
bonusText: baseEnv.skus[index].bonus,
subtitle: baseEnv.skus[index].subtitle,
onPressed: () async {
buyProduct(itemId: baseEnv.skus[index].id);
},
),
separatorBuilder: (_, __) => SizedBox(
height: 30.h,
),
itemCount: baseEnv.skus.length)),
],
),
],
Expand All @@ -113,12 +84,7 @@ class _AddPylonScreenState extends State<AddPylonScreen> {
);
}

Widget buildBuyRow(
{required String svgAsset,
required String pylonText,
required String bonusText,
required String subtitle,
required VoidCallback onPressed}) {
Widget buildBuyRow({required String svgAsset, required String pylonText, required String bonusText, required String subtitle, required VoidCallback onPressed}) {
return Row(children: [
SizedBox(
height: 40.h,
Expand Down Expand Up @@ -181,16 +147,14 @@ class _AddPylonScreenState extends State<AddPylonScreen> {
inAppPurchaseResponse.swap().toOption().toNullable()!.message.show();
return;
}
final productsListResponse =
await repository.getProductsForSale(itemId: itemId);
final productsListResponse = await repository.getProductsForSale(itemId: itemId);
loading.dismiss();

if (productsListResponse.isLeft()) {
productsListResponse.swap().toOption().toNullable()!.message.show();
return;
}
final buyProductResponse = await repository
.buyProduct(productsListResponse.toOption().toNullable()!);
final buyProductResponse = await repository.buyProduct(productsListResponse.toOption().toNullable()!);
if (buyProductResponse.isLeft()) {
buyProductResponse.swap().toOption().toNullable()!.message.show();
return;
Expand Down
2 changes: 1 addition & 1 deletion wallet/lib/pages/routing_page/routing_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import 'package:pylons_wallet/pages/settings/utils/user_info_provider.dart';
import 'package:pylons_wallet/pylons_app.dart';
import 'package:pylons_wallet/services/data_stores/local_data_store.dart';
import 'package:pylons_wallet/services/repository/repository.dart';
import 'package:pylons_wallet/services/third_party_services/remote_config_service.dart';
import 'package:pylons_wallet/services/third_party_services/remote_config_service/remote_config_service.dart';
import 'package:pylons_wallet/stores/wallet_store.dart';
import 'package:pylons_wallet/utils/dependency_injection/dependency_injection.dart';
import 'package:pylons_wallet/utils/route_util.dart';
Expand Down
2 changes: 1 addition & 1 deletion wallet/lib/pages/routing_page/update_app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import 'package:flutter_svg/flutter_svg.dart';
import 'package:get_it/get_it.dart';
import 'package:pylons_wallet/pylons_app.dart';
import 'package:pylons_wallet/services/data_stores/local_data_store.dart';
import 'package:pylons_wallet/services/third_party_services/remote_config_service.dart';
import 'package:pylons_wallet/services/third_party_services/remote_config_service/remote_config_service.dart';
import 'package:pylons_wallet/stores/wallet_store.dart';
import 'package:pylons_wallet/utils/constants.dart';
import 'package:pylons_wallet/utils/dependency_injection/dependency_injection.dart';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// "id": "pylons_10",
// "bonus": "",
// "subtitle": "$1.00",
// "pylons" : "10 PYLN"
//

import 'package:pylons_wallet/utils/svg_util.dart';

class SKUModel {
String id;
String bonus;
String subtitle;
String pylons;

SKUModel({required this.id, required this.bonus, required this.subtitle, required this.pylons});
factory SKUModel.fromJson(Map json) {
return SKUModel(
pylons: json['pylons'].toString(),
subtitle: json['subtitle'].toString(),
id: json['id'].toString(),
bonus: json['bonus'].toString(),
);
}

String getSvgAsset() {
if(id == "pylons_10"){
return SVGUtil.PYLON_ONE_CURRENCY;
} else if (id == "pylons_35"){
return SVGUtil.PYLON_THREE_CURRENCY;
} else {
return SVGUtil.PYLON_FIVE_CURRENCY;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:firebase_app_check/firebase_app_check.dart';
import 'package:firebase_remote_config/firebase_remote_config.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart';
import 'package:pylons_wallet/services/data_stores/local_data_store.dart';
Expand Down Expand Up @@ -44,6 +45,7 @@ class RemoteConfigServiceImpl implements RemoteConfigService {
static String chainId = "CHAIN_ID";
static String ibcTrace = "IBC_TRACE_URL";
static String mongoUrl = "MONGO_URL";
static String skus = "skus";

RemoteConfigServiceImpl(
{required this.firebaseRemoteConfig,
Expand All @@ -69,6 +71,7 @@ class RemoteConfigServiceImpl implements RemoteConfigService {
firebaseRemoteConfig.getString(stripeCallbackRefreshUrl),
chainId: firebaseRemoteConfig.getString(chainId),
ibcTraceUrl: firebaseRemoteConfig.getString(ibcTrace),
skus: firebaseRemoteConfig.getString(skus),
);

// if (localDataSource.getNetworkEnvironmentPreference() == kDevNet) {
Expand Down Expand Up @@ -137,6 +140,10 @@ class RemoteConfigServiceImpl implements RemoteConfigService {
iosVERSION: IOS_VERSION,
androidVersion: ANDROID_VERSION,
chainId: dotenv.env['CHAIN_ID'],
skus: defaultPylonsSKUs,
mongoUrl: dotenv.env[mongoUrl] ?? "",


});

firebaseRemoteConfig.setConfigSettings(RemoteConfigSettings(
Expand All @@ -149,6 +156,8 @@ class RemoteConfigServiceImpl implements RemoteConfigService {
} on FormatException catch (_) {
/// Happens when there is no internet on first launch.
crashlyticsHelper.recordFatalError(error: _.message);
} on FirebaseException catch(_){
crashlyticsHelper.recordFatalError(error: _.message ?? "");
}
}

Expand Down
15 changes: 15 additions & 0 deletions wallet/lib/utils/base_env.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import 'dart:convert';

import 'package:alan/alan.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart';
import 'package:grpc/grpc.dart';
import 'package:pylons_wallet/services/third_party_services/remote_config_service/models/sku_model.dart';
import 'package:pylons_wallet/utils/constants.dart';

class BaseEnv {
Expand All @@ -17,6 +20,7 @@ class BaseEnv {
late String _ibcTraceUrl;
late String _faucetUrl;
late String _baseMongoUrl;
late List<SKUModel> _skus;

void setEnv(
{required String lcdUrl,
Expand All @@ -28,6 +32,7 @@ class BaseEnv {
required String faucetUrl,
required String ibcTraceUrl,
required String mongoUrl,
required String skus,
String? stripeUrl,
String? stripePubKey,
bool? stripeTestEnv,
Expand Down Expand Up @@ -57,6 +62,11 @@ class BaseEnv {
_chainId = chainId;
_ibcTraceUrl = ibcTraceUrl;
_faucetUrl = faucetUrl;


final List jsonSkuList = jsonDecode(skus) as List;
_skus = jsonSkuList.map(( e) => SKUModel.fromJson(e as Map )).toList();

}

NetworkInfo get networkInfo => _networkInfo;
Expand All @@ -83,8 +93,13 @@ class BaseEnv {

String get faucetUrl => _faucetUrl;


List<SKUModel> get skus => _skus;

@override
String toString() {
return 'BaseEnv{_networkInfo: $_networkInfo, _baseApiUrl: $_baseApiUrl, _baseEthUrl: $_baseEthUrl, _stripeUrl: $_stripeUrl, _stripePubKey: $_stripePubKey, _stripeTestEnv: $_stripeTestEnv, _stripeCallbackUrl: $_stripeCallbackUrl, _stripeCallbackRefreshUrl: $_stripeCallbackRefreshUrl, _chainId: $_chainId, _ibcTraceUrl: $_ibcTraceUrl, _faucetUrl: $_faucetUrl}';
}


}
Loading