Skip to content

Commit

Permalink
refactor: Improve flow in my DIno and Wallet to get all info using th…
Browse files Browse the repository at this point in the history
…e best way
  • Loading branch information
dnielopez committed Oct 12, 2023
1 parent fd6eeb8 commit 601cc0f
Show file tree
Hide file tree
Showing 9 changed files with 146 additions and 34 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
.history
.svn/
migrate_working_dir/
*.jks

# IntelliJ related
*.iml
Expand Down
22 changes: 20 additions & 2 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,18 @@ if (flutterVersionName == null) {
flutterVersionName = '1.0'
}

def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('key.properties')
if (keystorePropertiesFile.exists()) {
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
namespace "com.example.dinogrow"
namespace "crypto.game.dinogrow"
compileSdkVersion flutter.compileSdkVersion
ndkVersion flutter.ndkVersion

Expand All @@ -45,7 +51,7 @@ android {

defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.dinogrow"
applicationId "crypto.game.dinogrow"
// You can update the following values to match your application needs.
// For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration.
minSdkVersion 23
Expand All @@ -54,8 +60,20 @@ android {
versionName flutterVersionName
}

signingConfigs {
release {
keyAlias keystoreProperties['keyAlias']
keyPassword keystoreProperties['keyPassword']
storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null
storePassword keystoreProperties['storePassword']
}
}

buildTypes {
release {
signingConfig signingConfigs.release
}
debug {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig signingConfigs.debug
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.dinogrow
package crypto.game.dinogrow

import io.flutter.embedding.android.FlutterActivity

Expand Down
13 changes: 10 additions & 3 deletions lib/pages/home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ class _HomeScreenState extends State<HomeScreen> {
fontWeight: FontWeight.bold, color: Colors.black),
),
const SizedBox(width: 3),
Text(_balance ?? 'Loading...',
Text(
_balance != null
? double.parse(_balance ?? '0').toStringAsFixed(2)
: 'Loading...',
style: const TextStyle(color: Colors.black)),
const SizedBox(width: 3),
const Text('SOL',
Expand Down Expand Up @@ -115,8 +118,12 @@ class _HomeScreenState extends State<HomeScreen> {
children: [
const MiniGamesScreen(),
RankingScreen(),
MydinogrowScreen(address: _publicKey ?? ''),
WalletScreen(address: _publicKey ?? '', balance: _balance),
MydinogrowScreen(
address: _publicKey ?? '', getBalance: () => _getBalance()),
WalletScreen(
address: _publicKey ?? '',
balance: _balance,
getBalance: () => _getBalance()),
],
),
),
Expand Down
14 changes: 11 additions & 3 deletions lib/pages/input_phrase.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ class InputPhraseScreen extends StatefulWidget {

class _InputPhraseScreenState extends State<InputPhraseScreen> {
final _formKey = GlobalKey<FormState>();
final _words = List<String>.filled(12, '');
bool validationFailed = false;
var controllers =
List<TextEditingController>.generate(12, (i) => TextEditingController());
Expand Down Expand Up @@ -126,9 +125,18 @@ class _InputPhraseScreenState extends State<InputPhraseScreen> {

void _onSubmit(context) async {
if (_formKey.currentState!.validate()) {
_formKey.currentState!.save();
String wordsString = _words.join(' ');
// _formKey.currentState!.save();
// String wordsString = _words.join(' ');
String wordsString = '';

for (var controller in controllers) {
wordsString = '$wordsString${controller.text} ';
}

wordsString = wordsString.substring(0, wordsString.length - 1);

final t = bip39.validateMnemonic(wordsString);

if (t) {
// GoRouter.of(context).push("/passwordSetup/$wordsString");
showModalBottomSheet(
Expand Down
16 changes: 10 additions & 6 deletions lib/pages/login.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ class LoginScreen extends StatefulWidget {
class _LoginScreenState extends State<LoginScreen> {
final _formKey = GlobalKey<FormState>();
final passwordController = TextEditingController();
bool validationFailed = false;
String? password;
bool _loading = true;
String? key;
Expand Down Expand Up @@ -83,8 +82,6 @@ class _LoginScreenState extends State<LoginScreen> {
),
),
const SizedBox(height: 8),
Text(validationFailed ? 'Invalid Password' : '',
style: const TextStyle(color: Colors.red)),
const SizedBox(height: 8),
IntroButtonWidget(
text: 'Login',
Expand Down Expand Up @@ -156,9 +153,16 @@ class _LoginScreenState extends State<LoginScreen> {
}
GoRouter.of(context).pushReplacement("/home");
} else {
setState(() {
validationFailed = true;
});
const snackBar = SnackBar(
content: Text(
'Error: Invalid Password',
style: TextStyle(color: Colors.white),
),
backgroundColor: Colors.red,
);

ScaffoldMessenger.of(context).showSnackBar(snackBar);

setState(() {
_loading = false;
});
Expand Down
3 changes: 2 additions & 1 deletion lib/pages/mini-games/mini_games.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ class _MiniGamesPageState extends State<MiniGamesScreen> {
children: [
GameCardWidget(
text: 'UP',
route: "/mini_games/up",
route: "/mini_games/comming_soon",
// route: "/mini_games/up",
),
GameCardWidget(
text: 'COMING SOON',
Expand Down
76 changes: 64 additions & 12 deletions lib/pages/my-dinogrow/my_dinogrow.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ import '../../anchor_types/nft_parameters.dart' as anchor_types;

class MydinogrowScreen extends StatefulWidget {
final String address;
final Function getBalance;

const MydinogrowScreen({super.key, required this.address});
const MydinogrowScreen(
{super.key, required this.address, required this.getBalance});

@override
State<MydinogrowScreen> createState() => _MydinogrowScreenState();
Expand Down Expand Up @@ -120,12 +122,26 @@ class _MydinogrowScreenState extends State<MydinogrowScreen> {
urlImage:
userNfts.isNotEmpty ? userNfts[nftSelected]['imageUrl'] : '',
),
const SizedBox(height: 12),
Container(
color: Colors.black,
child: const Padding(
padding: EdgeInsets.all(3),
child: Text(
"Hi ^.^ Please select one Dino to use as character when you play minigames",
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.white,
fontSize: 14,
),
),
),
),
const SizedBox(height: 30),
IntroButtonWidget(
text: 'Claim other Dino',
onPressed: createNft,
onPressed: beforeOtherNft,
),
// TextBoxWidget(text: "Hi ^.^ I'm $nameNft"),
];

bool showDinos = false;
Expand Down Expand Up @@ -206,7 +222,7 @@ class _MydinogrowScreenState extends State<MydinogrowScreen> {

Future<void> fetchNfts() async {
try {
// print('widget.address: ${widget.address}');
print('widget.address: ${widget.address}');
setState(() {
_loading = true;
userNfts = [];
Expand All @@ -223,12 +239,7 @@ class _MydinogrowScreenState extends State<MydinogrowScreen> {
},
body: jsonEncode({
"method": "qn_fetchNFTs",
"params": {
"wallet": widget.address,
// "AUMbL5J7wQuNxV7tpj1mq4SzPxqReDA6VzfkCzpJjcUi",
"page": 1,
"perPage": 10
}
"params": {"wallet": widget.address, "page": 1, "perPage": 10}
}));

final dataResponse = jsonDecode(response.body);
Expand All @@ -242,15 +253,49 @@ class _MydinogrowScreenState extends State<MydinogrowScreen> {
}
} finally {
if (mounted) {
setState(() {
_loading = false;
Future.delayed(const Duration(seconds: 1), () async {
setState(() {
_loading = false;
});
Future.delayed(const Duration(seconds: 2), () async {
widget.getBalance();
});
});
}
}
}

beforeOtherNft() {
showDialog<String>(
context: context,
builder: (BuildContext context) => AlertDialog(
title: const Text('Claim other Dino'),
content: const Text(
'Before to continue, are you sure to claim other Dino? Remember the transaction has a variable cost so please confirm if you have at least 0.05 SOL in your wallet balance.'),
actions: <Widget>[
TextButton(
onPressed: () => Navigator.pop(context, 'Cancel'),
child: const Text('Cancel'),
),
TextButton(
onPressed: () {
createNft();
Navigator.pop(context, 'OK');
},
child: const Text('Confimr'),
),
],
),
);
}

createNft() async {
try {
if (_loading) {
// avoid double call
return null;
}

if (mounted) {
setState(() {
_loading = true;
Expand Down Expand Up @@ -389,6 +434,13 @@ class _MydinogrowScreenState extends State<MydinogrowScreen> {
);
print('Tx successful with hash: $signature');
fetchNfts();
} catch (e) {
final snackBar = SnackBar(
content: Text('Error: $e', style: const TextStyle(color: Colors.white)),
backgroundColor: Colors.red,
);

ScaffoldMessenger.of(context).showSnackBar(snackBar);
} finally {
if (mounted) {
setState(() {
Expand Down
33 changes: 27 additions & 6 deletions lib/pages/wallet/wallet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,30 @@ import 'package:qr_flutter/qr_flutter.dart';

import '../../ui/widgets/widgets.dart';

class WalletScreen extends StatelessWidget {
class WalletScreen extends StatefulWidget {
final String address;
final String? balance;
final Function getBalance;

const WalletScreen({super.key, required this.address, this.balance});
const WalletScreen(
{super.key,
required this.address,
this.balance,
required this.getBalance});

@override
State<WalletScreen> createState() => _WalletScreenState();
}

class _WalletScreenState extends State<WalletScreen> {
@override
void initState() {
super.initState();

Future.delayed(const Duration(seconds: 1), () async {
widget.getBalance();
});
}

@override
Widget build(BuildContext context) {
Expand All @@ -29,7 +48,7 @@ class WalletScreen extends StatelessWidget {
child: Padding(
padding: const EdgeInsets.all(6),
child: QrImageView(
data: address,
data: widget.address,
version: QrVersions.auto,
size: 200.0,
),
Expand All @@ -41,7 +60,7 @@ class WalletScreen extends StatelessWidget {
child: Padding(
padding: const EdgeInsets.all(3),
child: Text(
"Your address: $address",
"Your address: ${widget.address}",
textAlign: TextAlign.center,
style: const TextStyle(
color: Colors.white,
Expand All @@ -54,7 +73,7 @@ class WalletScreen extends StatelessWidget {
IntroButtonWidget(
text: 'Copy',
onPressed: () {
Clipboard.setData(ClipboardData(text: address));
Clipboard.setData(ClipboardData(text: widget.address));
const snackBar = SnackBar(
content: Text('Copied!'),
);
Expand All @@ -65,7 +84,9 @@ class WalletScreen extends StatelessWidget {
const SizedBox(height: 30),
Row(children: [
Expanded(
child: TextBoxWidget(text: 'Balace: $balance SOL')),
child: TextBoxWidget(
text:
'Balace: ${double.parse(widget.balance ?? '0').toStringAsFixed(2)} SOL')),
const SizedBox(width: 12),
IntroButtonWidget(
text: 'Send',
Expand Down

0 comments on commit 601cc0f

Please sign in to comment.