Skip to content

Commit

Permalink
Multi Account Support & Some Bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
aryanA101a committed Jul 4, 2023
1 parent 6682bb3 commit b33c5bb
Show file tree
Hide file tree
Showing 14 changed files with 686 additions and 248 deletions.
4 changes: 3 additions & 1 deletion lib/exceptions/app_exceptions.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
enum AppEType { somethingElse, empty }
enum AppEType { somethingElse, empty, importAccount }

class AppException {
AppException(this.eType) : _message = _setMessage(eType);
Expand All @@ -13,6 +13,8 @@ class AppException {
return "Empty";
case AppEType.somethingElse:
return "Something went wrong!";
case AppEType.importAccount:
return "Cannot import account!";
}
}
}
49 changes: 29 additions & 20 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import 'package:batua/pages/onboardingPage.dart';
import 'package:batua/pages/tokenInfoPage.dart';
import 'package:batua/pages/transactionHistoryPage.dart';
import 'package:batua/pages/transactionPage.dart';
import 'package:batua/services/account_service.dart';
import 'package:batua/ui_helper/homePageUiHelper.dart';
import 'package:batua/ui_helper/onboarding_page_ui_helper.dart';
import 'package:batua/ui_helper/transaction_history_page_ui_helper.dart';
import 'package:batua/ui_helper/transaction_page_ui_helper.dart';
import 'package:batua/utils/utils.dart';
Expand All @@ -25,7 +27,7 @@ void main() async {
);

WidgetsFlutterBinding.ensureInitialized();
bool loggedIn = await isLogged();
bool loggedIn = await AccountService.isLogged();
runApp(MyApp(loggedIn: loggedIn));
}

Expand All @@ -35,24 +37,31 @@ class MyApp extends StatelessWidget {

@override
Widget build(BuildContext context) {
return MaterialApp(
scaffoldMessengerKey: rootScaffoldMessengerKey,
title: "Batua",
initialRoute: loggedIn ? HomePage.route : OnboardingPage.route,
routes: {
"/": (context) => const OnboardingPage(),
"/home": (context) => ChangeNotifierProvider(
create: (context) => getIt<HomePageUiHelper>(),
child: const HomePage(),
),
"/tokenInfoPage": (context) => const TokenInfoPage(),
"/transactionHistory": (context) => ChangeNotifierProvider(
create: (context) => TransactionHistoryPageUiHelper(),
child: const TransactionHistoryPage()),
"/transactionPage": (context) => ChangeNotifierProvider(
create: (context) => TransactionPageUiHelper(),
child: const TransactionPage()),
},
);
return ChangeNotifierProvider(
create: (context) => OnboardingPageUiHelper(),
child: MaterialApp(
scaffoldMessengerKey: rootScaffoldMessengerKey,
title: "Batua",
home: loggedIn
? ChangeNotifierProvider(
create: (context) => getIt<HomePageUiHelper>(),
child: const HomePage(),
)
: OnboardingPage(),
routes: {
"/onboardingPage": (context) => const OnboardingPage(),
"/homePage": (context) => ChangeNotifierProvider(
create: (context) => getIt<HomePageUiHelper>(),
child: const HomePage(),
),
"/tokenInfoPage": (context) => const TokenInfoPage(),
"/transactionHistory": (context) => ChangeNotifierProvider(
create: (context) => TransactionHistoryPageUiHelper(),
child: const TransactionHistoryPage()),
"/transactionPage": (context) => ChangeNotifierProvider(
create: (context) => TransactionPageUiHelper(),
child: const TransactionPage()),
},
));
}
}
6 changes: 4 additions & 2 deletions lib/models/mined_transaction_model.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import 'dart:convert';

import 'package:web3dart/crypto.dart';

class MinedTransactionModel {
final String jsonrpc;
final String method;
Expand Down Expand Up @@ -128,15 +130,15 @@ class MinedTransaction {
MinedTransaction(
blockHash: json["blockHash"],
blockNumber: json["blockNumber"],
from: json["from"].substring(2),
from: strip0x(json["from"]),
gas: json["gas"],
gasPrice: json["gasPrice"],
maxFeePerGas: json["maxFeePerGas"],
maxPriorityFeePerGas: json["maxPriorityFeePerGas"],
hash: json["hash"],
input: json["input"],
nonce: json["nonce"],
to: json["to"].substring(2),
to: strip0x(json["to"]),
transactionIndex: json["transactionIndex"],
value: json["value"],
type: json["type"],
Expand Down
6 changes: 4 additions & 2 deletions lib/models/transaction_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import 'dart:convert';
import 'dart:math';

import 'package:web3dart/crypto.dart';

class TransactionModel {
final String status;
final String message;
Expand Down Expand Up @@ -97,8 +99,8 @@ class TransactionModelResult {
nonce: json["nonce"],
blockHash: json["blockHash"],
transactionIndex: json["transactionIndex"],
from: json["from"].substring(2),
to: json["to"].substring(2),
from:strip0x( json["from"]),
to: strip0x(json["to"]),
value: json["tokenDecimal"] == null
? BigInt.parse(json["value"]) / BigInt.from(pow(10, 18))
: BigInt.parse(json["value"]) /
Expand Down
108 changes: 77 additions & 31 deletions lib/pages/homePage.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'dart:developer';

import 'package:batua/di/locator.dart';
import 'package:batua/main.dart';
import 'package:batua/models/token.dart';
import 'package:batua/pages/tokenInfoPage.dart';
Expand All @@ -21,37 +22,31 @@ import 'package:shimmer/shimmer.dart';
import 'onboardingPage.dart';

class HomePage extends StatelessWidget {
static const route = "/home";
static const route = "/homePage";
const HomePage({super.key});

@override
Widget build(BuildContext context) {
// var provider = Provider.of<HomePageUiHelper>(context);
return WillPopScope(
onWillPop: () async {
SystemNavigator.pop();
return false;
},
child: Scaffold(
body: SafeArea(
child: Column(
children: [
Container(
height: MediaQuery.sizeOf(context).height * (1 / 3),
child: const Column(
children: [
TopBar(),
Expanded(child: WalletInfo()),
],
),
return Scaffold(
body: SafeArea(
child: Column(
children: [
Container(
height: MediaQuery.sizeOf(context).height * (1 / 3),
child: const Column(
children: [
TopBar(),
Expanded(child: WalletInfo()),
],
),
const Expanded(
child: TokensSectionWidget(),
)
],
),
)),
);
),
const Expanded(
child: TokensSectionWidget(),
)
],
),
));
}
}

Expand Down Expand Up @@ -272,13 +267,64 @@ class TopBar extends StatelessWidget {
},
icon: Icon(FontAwesomeIcons.fileInvoice,
color: Colors.blue.shade800)),
IconButton(
onPressed: () async {
AccountService.deletePrivateKey();
Navigator.popAndPushNamed(context, OnboardingPage.route);
Padding(
padding: const EdgeInsets.only(right: 8, left: 2),
child: PopupMenuButton<String>(
elevation: 2,
shape:
RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
position: PopupMenuPosition.under,
child: Icon(
Icons.settings_rounded,
color: Colors.grey.shade900,
),
onSelected: (String value) {
switch (value) {
case "CopyPrivateKey":
AccountService.retrievePrivateKey(
context.read<HomePageUiHelper>().address!)
.then((value) {
Clipboard.setData(ClipboardData(text: value ?? ""));

ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text(
'Private key copied!',
),
),
);
});

case "Accounts":
// AccountService.deletePrivateKey();
Navigator.popAndPushNamed(context, OnboardingPage.route);
}
},
icon: Icon(FontAwesomeIcons.arrowRightFromBracket,
color: Colors.grey.shade900)),
itemBuilder: (BuildContext context) {
return [
("Copy Private Key", Icons.security_rounded),
("Accounts", Icons.account_circle_rounded)
]
.map(((String, IconData) v) => PopupMenuItem<String>(
value: v.$1.replaceAll(' ', ''),
child: Row(
children: [
Container(
margin: const EdgeInsets.all(8.0),
child: Icon(v.$2),
),
Text(
v.$1,
overflow: TextOverflow.ellipsis,
style: TextStyle(fontWeight: FontWeight.w500),
),
],
),
))
.toList();
},
),
),
],
);
}
Expand Down
Loading

0 comments on commit b33c5bb

Please sign in to comment.