Skip to content

Commit

Permalink
Merge branch 'refactoring' of https://github.com/vaariance/variance-dart
Browse files Browse the repository at this point in the history
 into refactoring
  • Loading branch information
code-z2 committed Apr 2, 2024
2 parents 5d9a1a4 + c08d89f commit 61fbab0
Show file tree
Hide file tree
Showing 13 changed files with 277 additions and 244 deletions.
13 changes: 13 additions & 0 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ PODS:
- Flutter (1.0.0)
- flutter_native_splash (0.0.1):
- Flutter
- fluttertoast (0.0.2):
- Flutter
- Toast
- passkeys_ios (0.0.1):
- Flutter
- path_provider_foundation (0.0.1):
Expand All @@ -10,6 +13,7 @@ PODS:
- shared_preferences_foundation (0.0.1):
- Flutter
- FlutterMacOS
- Toast (4.1.0)
- ua_client_hints (1.2.2):
- Flutter
- web3_signers (0.0.1):
Expand All @@ -18,17 +22,24 @@ PODS:
DEPENDENCIES:
- Flutter (from `Flutter`)
- flutter_native_splash (from `.symlinks/plugins/flutter_native_splash/ios`)
- fluttertoast (from `.symlinks/plugins/fluttertoast/ios`)
- passkeys_ios (from `.symlinks/plugins/passkeys_ios/ios`)
- path_provider_foundation (from `.symlinks/plugins/path_provider_foundation/darwin`)
- shared_preferences_foundation (from `.symlinks/plugins/shared_preferences_foundation/darwin`)
- ua_client_hints (from `.symlinks/plugins/ua_client_hints/ios`)
- web3_signers (from `.symlinks/plugins/web3_signers/ios`)

SPEC REPOS:
trunk:
- Toast

EXTERNAL SOURCES:
Flutter:
:path: Flutter
flutter_native_splash:
:path: ".symlinks/plugins/flutter_native_splash/ios"
fluttertoast:
:path: ".symlinks/plugins/fluttertoast/ios"
passkeys_ios:
:path: ".symlinks/plugins/passkeys_ios/ios"
path_provider_foundation:
Expand All @@ -43,9 +54,11 @@ EXTERNAL SOURCES:
SPEC CHECKSUMS:
Flutter: e0871f40cf51350855a761d2e70bf5af5b9b5de7
flutter_native_splash: 52501b97d1c0a5f898d687f1646226c1f93c56ef
fluttertoast: 31b00dabfa7fb7bacd9e7dbee580d7a2ff4bf265
passkeys_ios: fdae8c06e2178a9fcb9261a6cb21fb9a06a81d53
path_provider_foundation: 3784922295ac71e43754bd15e0653ccfd36a147c
shared_preferences_foundation: b4c3b4cddf1c21f02770737f147a3f5da9d39695
Toast: ec33c32b8688982cecc6348adeae667c1b9938da
ua_client_hints: 7f4e0f5d390685e8f7efd6eb363594f760108926
web3_signers: 5f49d582ab0d1fe673b3220aa6ecf25bb3cbed6b

Expand Down
2 changes: 1 addition & 1 deletion example/ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@
isa = PBXProject;
attributes = {
BuildIndependentTargetsInParallel = YES;
LastUpgradeCheck = 1430;
LastUpgradeCheck = 1510;
ORGANIZATIONNAME = "";
TargetAttributes = {
331C8080294A63A400263BE5 = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1430"
LastUpgradeVersion = "1510"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
2 changes: 1 addition & 1 deletion example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import 'package:google_fonts/google_fonts.dart';
import 'package:provider/provider.dart';
import 'package:variancedemo/providers/wallet_provider.dart';
import 'package:variancedemo/screens/create_account.dart';
import 'package:variancedemo/screens/home_screen.dart';
import 'package:variancedemo/screens/home/home_screen.dart';

final globalScaffoldMessengerKey = GlobalKey<ScaffoldMessengerState>();

Expand Down
13 changes: 10 additions & 3 deletions example/lib/providers/wallet_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@ class WalletProvider extends ChangeNotifier {
SmartWallet? _wallet;
SmartWallet? get wallet => _wallet;

String _errorMessage = "";
String get errorMessage => _errorMessage;

WalletProvider()
: _chain = Chains.getChain(Network.baseTestent)
: _chain = Chains.getChain(Network.baseTestnet)
..accountFactory = EthereumAddress.fromHex(
"0x402A266e92993EbF04a5B3fd6F0e2b21bFC83070")
..bundlerUrl =
Expand Down Expand Up @@ -50,6 +53,8 @@ class WalletProvider extends ChangeNotifier {

log("wallet created ${_wallet?.address.hex} ");
} catch (e) {
_errorMessage = e.toString();
notifyListeners();
log("something happened: $e");
}
}
Expand All @@ -75,13 +80,15 @@ class WalletProvider extends ChangeNotifier {
}
}

Future<void> mintNFt() async {}

Future<void> sendTransaction(String recipient, String amount) async {
if (_wallet != null) {
final etherAmount = w3d.EtherAmount.fromBigInt(w3d.EtherUnit.wei,
BigInt.from(double.parse(amount) * math.pow(10, 18)));
final response =
await _wallet!.send(EthereumAddress.fromHex(recipient), etherAmount);
final receipt = await response.wait();
await _wallet?.send(EthereumAddress.fromHex(recipient), etherAmount);
final receipt = await response?.wait();

log("Transaction receipt Hash: ${receipt?.userOpHash}");
} else {
Expand Down
27 changes: 20 additions & 7 deletions example/lib/screens/create_account.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:provider/provider.dart';
import 'package:variancedemo/main.dart';
import 'package:variancedemo/providers/wallet_provider.dart';
import 'package:variancedemo/utils/widgets.dart';

class CreateAccountScreen extends StatefulWidget {
const CreateAccountScreen({super.key});
Expand All @@ -14,6 +15,15 @@ class CreateAccountScreen extends StatefulWidget {
class _CreateAccountScreenState extends State<CreateAccountScreen> {
final TextEditingController controller = TextEditingController();
final _formKey = GlobalKey<FormState>();
FToast? fToast;

@override
void initState() {
super.initState();
fToast = FToast();
fToast?.init(context);
}

@override
Widget build(BuildContext context) {
return SafeArea(
Expand Down Expand Up @@ -79,14 +89,17 @@ class _CreateAccountScreenState extends State<CreateAccountScreen> {
SizedBox(
height: 45.h,
child: TextButton(
key: globalScaffoldMessengerKey,
onPressed: () async {
try {
await value.registerWithPassKey(controller.text,
requiresUserVerification: true);
// ignore: use_build_context_synchronously
await value.registerWithPassKey(controller.text,
requiresUserVerification: true);
// ignore: use_build_context_synchronously
if (value.errorMessage.isNotEmpty) {
fToast?.showToast(
gravity: ToastGravity.BOTTOM,
child: Text(value.errorMessage));
} else {
Navigator.pushNamed(context, '/home');
} catch (e) {
showSnackbar(e.toString());
}
},
style: TextButton.styleFrom(
Expand Down
123 changes: 123 additions & 0 deletions example/lib/screens/home/home_screen.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
import 'dart:developer';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:provider/provider.dart';
import 'package:variancedemo/providers/wallet_provider.dart';
import 'package:variancedemo/screens/home/home_widgets.dart';
import 'package:variancedemo/utils/widgets.dart';
import 'package:variancedemo/variance_colors.dart';

class WalletHome extends StatefulWidget {
const WalletHome({super.key});

@override
State<WalletHome> createState() => _WalletHomeState();
}

class _WalletHomeState extends State<WalletHome> {
final _formKey = GlobalKey<FormState>();
TextEditingController amountController = TextEditingController();
TextEditingController addressController = TextEditingController();

@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: VarianceColors.primary,
body: SafeArea(
child: Padding(
padding: EdgeInsets.symmetric(vertical: 19.h, horizontal: 16.w),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const WalletBalance(),
50.verticalSpace,
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
TextButton.icon(
onPressed: () {
showModalBottomSheetContent(context);
},
style: TextButton.styleFrom(
backgroundColor: const Color(0xffE1FF01)),
icon: const Icon(Icons.qr_code_2_sharp),
label: const Text(' Receive')),
50.horizontalSpace,
TextButton.icon(
onPressed: () {},
style: TextButton.styleFrom(
backgroundColor: const Color(0xffE1FF01)),
icon: const Icon(
Icons.all_inclusive_outlined,
),
label: const Text('Mint NFT')),
],
),
60.verticalSpace,
AddressBar(
hintText: 'Eth Address',
textEditingController: addressController,
),
18.verticalSpace,
TextFormField(
style: TextStyle(
fontSize: 51.sp,
fontWeight: FontWeight.w600,
color: VarianceColors.secondary),
key: _formKey,
validator: (value) {
if (value == null || value.isEmpty) {
return 'Please enter a value';
} else if (int.parse(value) > 100) {
return 'Value should be less than or equal to 100';
}
return null;
},
onChanged: (value) {
if (value.isEmpty) {
return;
}
},
textAlign: TextAlign.center,
controller: amountController,
keyboardType: TextInputType.number,
decoration: const InputDecoration(
focusColor: Colors.white,
fillColor: Colors.white,
border: InputBorder.none,
hintText: '0.0',
hintStyle: TextStyle(
fontSize: 51, color: VarianceColors.secondary),
),
cursorColor: VarianceColors.secondary,
inputFormatters: [
FilteringTextInputFormatter.allow(
RegExp(r'^\.?\d*(?<!\.)\.?\d*'),
)
]),
SizedBox(
height: 58.h,
width: double.infinity,
child: TextButton(
style: TextButton.styleFrom(
padding: EdgeInsets.zero,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10)),
backgroundColor: VarianceColors.white),
onPressed: () {
log(amountController.text);
log(addressController.text);
context.read<WalletProvider>().sendTransaction(
addressController.text, amountController.text);
},
child: const Text('Send')),
),
],
),
),
),
);
}
}
Loading

0 comments on commit 61fbab0

Please sign in to comment.