Skip to content

Commit

Permalink
New Account Details + MTR in Overview
Browse files Browse the repository at this point in the history
Ability to set custom app image url by tapping the image
updated pub packages
const widgets to improve performance
  • Loading branch information
oliverbytes committed Sep 6, 2020
1 parent fc283b1 commit f89f1f0
Show file tree
Hide file tree
Showing 31 changed files with 851 additions and 181 deletions.
Binary file removed assets/images/bluer.png
Binary file not shown.
Binary file removed assets/images/noseen.png
Binary file not shown.
Binary file removed assets/images/placeholder.png
Binary file not shown.
Binary file removed assets/images/savestory.png
Binary file not shown.
18 changes: 18 additions & 0 deletions lib/core/apis/general.api.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:app/core/apis/base.api.dart';
import 'package:app/core/models/account.model.dart';
import 'package:app/core/models/api_error.model.dart';
import 'package:app/core/models/overview.model.dart';
import 'package:app/core/models/transactions.model.dart';
Expand Down Expand Up @@ -65,6 +66,23 @@ class GeneralAPI extends BaseAPI {
);
}

Future<Either<ApiError, Account>> account() async {
if (!await internetConnected())
return Left(ApiError(code: 0, message: kInternetError));

final result = await baseRequest(
function: "me",
headers: baseHeaders,
url: meUrl,
debug: true,
);

return result.fold(
(error) => Left(error),
(data) => Right(Account.fromJson(data)),
);
}

Future<Either<ApiError, List<Transaction>>> transactions({
int startTimestamp,
int endTimestamp,
Expand Down
61 changes: 61 additions & 0 deletions lib/core/controllers/account.controller.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import 'package:app/core/apis/general.api.dart';
import 'package:app/core/controllers/base.controller.dart';
import 'package:app/core/models/account.model.dart';
import 'package:app/core/models/app.model.dart';
import 'package:app/core/utils/logger.dart';
import 'package:flutter_easyrefresh/easy_refresh.dart';
import 'package:get/get.dart';
import 'package:intl/intl.dart';

final logger = initLogger("AccountController");

class AccountController extends BaseController {
static AccountController get to => Get.find();

// VARIABLES
final _api = Get.find<GeneralAPI>();
final refreshController = EasyRefreshController();

// PROPERTIES
final account = Account().obs;

// GETTERS
List<App> get apps => account.value?.apps ?? [];

String get accountId => account.value?.distinctId ?? '';
String get accountName => account.value?.name ?? '';
String get accountEmail => account.value?.email ?? '';
String get accountPlan => account.value?.currentPlan ?? '';

int get currentMtr => account.value?.billingInfo?.currentMtr ?? 0;
int get mtrLimit => account.value?.billingInfo?.mtrLimit ?? 1;

String get currentMtrFormatted =>
NumberFormat.simpleCurrency().format(currentMtr);

String get mtrLimitFormatted =>
NumberFormat.simpleCurrency().format(mtrLimit);

String get firstTransactionDate => account.value?.firstTransactionAt != null
? DateFormat.yMMMMd().add_jm().format(account.value.firstTransactionAt)
: 'none';

// INIT

// FUNCTIONS
Future<void> fetch() async {
this.busyState();
account.value = Account();
final result = await _api.account();

result.fold(
(error) =>
errorState(text: 'API Error: ${error.code}!\n${error.message}'),
(data) {
account.value = data;
},
);

this.idleState();
}
}
9 changes: 9 additions & 0 deletions lib/core/managers/hive.manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ class HiveManager {
await _persistence.put('client_token', token);
}

static Future<void> setAppImageUrl(String appId, String imageUrl) async {
await _persistence.put('${appId}_image_url', imageUrl);
}

static String getAppImageUrl(String appId) {
return _persistence.get('${appId}_image_url',
defaultValue: 'https://i.imgur.com/qWD7i5x.png');
}

static Future<void> init() async {
if (!kIsWeb) {
final dir = await getApplicationDocumentsDirectory();
Expand Down
185 changes: 185 additions & 0 deletions lib/core/models/account.model.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
import 'app.model.dart';

class Account {
Account({
this.apps,
this.billingInfo,
this.currentPlan,
this.distinctId,
this.email,
this.exceededBasicLimit,
this.firstTransactionAt,
this.hasConfiguredEntitlements,
this.hasConfiguredNewOfferings,
this.hasMadeAnyLivePurchase,
this.hasMadeAnyPurchase,
this.intercomHash,
this.isConnectedToStripe,
this.name,
this.subscriptions,
});

final List<App> apps;
final BillingInfo billingInfo;
final String currentPlan;
final String distinctId;
final String email;
final bool exceededBasicLimit;
final DateTime firstTransactionAt;
final bool hasConfiguredEntitlements;
final bool hasConfiguredNewOfferings;
final bool hasMadeAnyLivePurchase;
final bool hasMadeAnyPurchase;
final String intercomHash;
final bool isConnectedToStripe;
final String name;
final Subscriptions subscriptions;

factory Account.fromJson(Map<String, dynamic> json) => Account(
apps: json["apps"] == null
? null
: List<App>.from(json["apps"].map((x) => App.fromJson(x))),
billingInfo: json["billing_info"] == null
? null
: BillingInfo.fromJson(json["billing_info"]),
currentPlan: json["current_plan"] == null ? null : json["current_plan"],
distinctId: json["distinct_id"] == null ? null : json["distinct_id"],
email: json["email"] == null ? null : json["email"],
exceededBasicLimit: json["exceeded_basic_limit"] == null
? null
: json["exceeded_basic_limit"],
firstTransactionAt: json["first_transaction_at"] == null
? null
: DateTime.parse(json["first_transaction_at"]),
hasConfiguredEntitlements: json["has_configured_entitlements"] == null
? null
: json["has_configured_entitlements"],
hasConfiguredNewOfferings: json["has_configured_new_offerings"] == null
? null
: json["has_configured_new_offerings"],
hasMadeAnyLivePurchase: json["has_made_any_live_purchase"] == null
? null
: json["has_made_any_live_purchase"],
hasMadeAnyPurchase: json["has_made_any_purchase"] == null
? null
: json["has_made_any_purchase"],
intercomHash:
json["intercom_hash"] == null ? null : json["intercom_hash"],
isConnectedToStripe: json["is_connected_to_stripe"] == null
? null
: json["is_connected_to_stripe"],
name: json["name"] == null ? null : json["name"],
subscriptions: json["subscriptions"] == null
? null
: Subscriptions.fromJson(json["subscriptions"]),
);

Map<String, dynamic> toJson() => {
"apps": apps == null
? null
: List<dynamic>.from(apps.map((x) => x.toJson())),
"billing_info": billingInfo == null ? null : billingInfo.toJson(),
"current_plan": currentPlan == null ? null : currentPlan,
"distinct_id": distinctId == null ? null : distinctId,
"email": email == null ? null : email,
"exceeded_basic_limit":
exceededBasicLimit == null ? null : exceededBasicLimit,
"first_transaction_at": firstTransactionAt == null
? null
: firstTransactionAt.toIso8601String(),
"has_configured_entitlements": hasConfiguredEntitlements == null
? null
: hasConfiguredEntitlements,
"has_configured_new_offerings": hasConfiguredNewOfferings == null
? null
: hasConfiguredNewOfferings,
"has_made_any_live_purchase":
hasMadeAnyLivePurchase == null ? null : hasMadeAnyLivePurchase,
"has_made_any_purchase":
hasMadeAnyPurchase == null ? null : hasMadeAnyPurchase,
"intercom_hash": intercomHash == null ? null : intercomHash,
"is_connected_to_stripe":
isConnectedToStripe == null ? null : isConnectedToStripe,
"name": name == null ? null : name,
"subscriptions": subscriptions == null ? null : subscriptions.toJson(),
};
}

class BillingInfo {
BillingInfo({
this.currentMtr,
this.mtrLimit,
this.paymentCard,
this.periodEnd,
this.periodStart,
});

final int currentMtr;
final int mtrLimit;
final PaymentCard paymentCard;
final DateTime periodEnd;
final DateTime periodStart;

factory BillingInfo.fromJson(Map<String, dynamic> json) => BillingInfo(
currentMtr: json["current_mtr"] == null ? null : json["current_mtr"],
mtrLimit: json["mtr_limit"] == null ? null : json["mtr_limit"],
paymentCard: json["payment_card"] == null
? null
: PaymentCard.fromJson(json["payment_card"]),
periodEnd: json["period_end"] == null
? null
: DateTime.parse(json["period_end"]),
periodStart: json["period_start"] == null
? null
: DateTime.parse(json["period_start"]),
);

Map<String, dynamic> toJson() => {
"current_mtr": currentMtr == null ? null : currentMtr,
"mtr_limit": mtrLimit == null ? null : mtrLimit,
"payment_card": paymentCard == null ? null : paymentCard.toJson(),
"period_end": periodEnd == null ? null : periodEnd.toIso8601String(),
"period_start":
periodStart == null ? null : periodStart.toIso8601String(),
};
}

class PaymentCard {
PaymentCard({
this.brand,
this.country,
this.expirationMonth,
this.expirationYear,
this.lastDigits,
});

final dynamic brand;
final dynamic country;
final dynamic expirationMonth;
final dynamic expirationYear;
final dynamic lastDigits;

factory PaymentCard.fromJson(Map<String, dynamic> json) => PaymentCard(
brand: json["brand"],
country: json["country"],
expirationMonth: json["expiration_month"],
expirationYear: json["expiration_year"],
lastDigits: json["last_digits"],
);

Map<String, dynamic> toJson() => {
"brand": brand,
"country": country,
"expiration_month": expirationMonth,
"expiration_year": expirationYear,
"last_digits": lastDigits,
};
}

class Subscriptions {
Subscriptions();

factory Subscriptions.fromJson(Map<String, dynamic> json) => Subscriptions();

Map<String, dynamic> toJson() => {};
}
Loading

0 comments on commit f89f1f0

Please sign in to comment.