Skip to content

Commit

Permalink
Merge pull request #48 from peaqnetwork/feature/1202839432398962_impl…
Browse files Browse the repository at this point in the history
…ement-transaction-auto-approval

Feature/1202839432398962 implement transaction auto approval
  • Loading branch information
irediaes authored Aug 29, 2022
2 parents 8d5a84e + e5b484f commit d4d2273
Show file tree
Hide file tree
Showing 17 changed files with 527 additions and 116 deletions.
5 changes: 5 additions & 0 deletions lib/common/models/enum.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,8 @@ enum LoadingStatus {
waiting,
authorize,
}

enum TransactonType {
spent,
refund,
}
42 changes: 42 additions & 0 deletions lib/common/models/transaction.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import 'package:charmev/common/models/enum.dart';
import 'package:json_annotation/json_annotation.dart';
import 'dart:convert';

part 'transaction.g.dart';

String? transactionTypeToString(TransactonType type) =>
_$TransactonTypeEnumMap[type];

@JsonSerializable(fieldRename: FieldRename.snake)
class CEVTransactionDbModel {
CEVTransactionDbModel({
required this.id,
required this.data,
required this.progress,
required this.transactionType,
required this.signatory,
required this.date,
});

factory CEVTransactionDbModel.fromJson(Map<String, dynamic> json) =>
_$CEVTransactionDbModelFromJson(json);

Map<String, dynamic> toJson() => _$CEVTransactionDbModelToJson(this);

String id;
String data;
double progress;
String signatory;
TransactonType transactionType;
int date;

@override
bool operator ==(Object other) =>
identical(this, other) ||
other is CEVTransactionDbModel &&
runtimeType == other.runtimeType &&
id == other.id;

@override
int get hashCode => id.hashCode;
}
35 changes: 35 additions & 0 deletions lib/common/models/transaction.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 9 additions & 3 deletions lib/common/providers/application_provider.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:charmev/common/providers/account_provider.dart';
import 'package:charmev/common/widgets/route.dart';
import 'package:charmev/screens/charging_session.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:charmev/common/utils/logger.dart';
Expand Down Expand Up @@ -81,13 +82,18 @@ class CEVApplicationProvider extends ChangeNotifier {
/// to the next screen.
Future<void> _onInitialized(BuildContext context) async {
_log.fine("on initialized");
peerProvider.initLog();
// use to initiate rust log in lib
peerProvider.initLog().then((v) {
chargeProvider.processPendingTransactionsFromDB();
});

bool hasTransaction = await chargeProvider.hasPendingTransaction();

if (authenticated) {
_log.fine("navigating to home screen");
// use to initiate rust log in lib
CEVNavigator.pushReplacementRoute(CEVFadeRoute(
builder: (context) => const HomeScreen(),
builder: (context) =>
hasTransaction ? const CharginSessionScreen() : const HomeScreen(),
duration: const Duration(milliseconds: 600),
));
} else {
Expand Down
Loading

0 comments on commit d4d2273

Please sign in to comment.