Newer
Older
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/services.dart';
import 'package:gecko/globals.dart';
import 'package:flutter/material.dart';
import 'package:gecko/providers/cesium_plus.dart';
import 'package:gecko/providers/substrate_sdk.dart';
import 'package:gecko/providers/my_wallets.dart';
import 'package:gecko/providers/wallets_profiles.dart';
import 'package:gecko/screens/activity.dart';
import 'package:gecko/screens/common_elements.dart';
import 'package:gecko/screens/myWallets/choose_wallet.dart';
import 'package:gecko/screens/myWallets/unlocking_wallet.dart';
import 'package:gecko/screens/transaction_in_progress.dart';
import 'package:provider/provider.dart';
class WalletViewScreen extends StatelessWidget {
{required this.pubkey, this.username, this.avatar, Key? key})
final String? pubkey;
final String? username;
final Image? avatar;
final double buttonSize = 100;
final double buttonFontSize = 18;
@override
Widget build(BuildContext context) {
SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
WalletsProfilesProvider _walletProfile =
CesiumPlusProvider _cesiumPlusProvider =
SubstrateSdk _sub = Provider.of<SubstrateSdk>(context, listen: false);
HomeProvider _homeProvider =
Provider.of<HomeProvider>(context, listen: false);
MyWalletsProvider _myWalletProvider =
Provider.of<MyWalletsProvider>(context, listen: false);
WalletData? defaultWallet = _myWalletProvider.getDefaultWallet();
actions: [
InkWell(
onTap: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) {
return QrCodeFullscreen(
title: const SizedBox(
height: 22,
child: Text('Voir un portefeuille'),
),
),
bottomNavigationBar: _homeProvider.bottomAppBar(context),
body: SafeArea(
child: Column(children: <Widget>[
_walletProfile.headerProfileView(context, pubkey!, username),
SizedBox(height: isTall ? 10 : 0),
Row(mainAxisAlignment: MainAxisAlignment.spaceAround, children: [
Column(children: <Widget>[
SizedBox(
child: ClipOval(
child: Material(
color: yellowC, //const Color(0xffFFD58D), // button color
child: InkWell(
key: const Key('viewHistory'),
splashColor: orangeC, // inkwell color
child: const Padding(
child: Image(
image: AssetImage(
'assets/walletOptions/clock.png'),
height: 90)),
onTap: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) {
return ActivityScreen(
address: pubkey,
avatar:
_cesiumPlusProvider.defaultAvatar(50));
}),
);
}),
),
),
),
const SizedBox(height: 9),
textAlign: TextAlign.center,
style: TextStyle(
fontSize: buttonFontSize, fontWeight: FontWeight.w500),
Consumer<SubstrateSdk>(builder: (context, _sub, _) {
WalletData? _defaultWallet =
_myWalletProvider.getDefaultWallet();
future: _sub.certState(_defaultWallet.address!,
pubkey!), // .canCertify(_defaultWallet.address!, pubkey!),
builder: (context, AsyncSnapshot<Map<String, int>> snapshot) {
if (snapshot.data == null) return const SizedBox();
String _duration = '';
if (snapshot.data!['certDelay'] != null ||
snapshot.data!['certRenewable'] != null) {
final Duration _durationSeconds = Duration(
seconds: snapshot.data!['certDelay'] ??
snapshot.data!['certRenewable']!);
final int _seconds = _durationSeconds.inSeconds;
final int _minutes = _durationSeconds.inMinutes;
if (_seconds <= 0) {
_duration = '0 secondes';
} else if (_seconds <= 60) {
_duration = '$_seconds secondes';
} else if (_seconds <= 3600) {
_duration = '$_minutes minutes';
} else if (_seconds <= 86400) {
final int _hours = _durationSeconds.inHours;
final int _minutesLeft = _minutes - _hours * 60;
String _showMinutes = '';
if (_minutesLeft < 60) {}
_showMinutes = ' $_minutesLeft minutes';
_duration = '$_hours heures$_showMinutes';
} else if (_seconds <= 2592000) {
final int _days = _durationSeconds.inDays;
_duration = '$_days jours';
} else {
final int _months =
(_durationSeconds.inDays / 30).round();
_duration = '$_months mois';
}
}
child: Column(children: <Widget>[
if (snapshot.data!['canCert'] != null ||
_duration == '0 secondes')
Column(children: <Widget>[
SizedBox(
height: buttonSize,
child: ClipOval(
child: Material(
color:
const Color(0xffFFD58D), // button color
child: InkWell(
key: const Key('copyKey'),
splashColor: orangeC, // inkwell color
child: const Padding(
padding: EdgeInsets.only(bottom: 0),
child: Image(
image: AssetImage(
'assets/gecko_certify.png')),
),
onTap: () async {
final bool? _result =
await confirmPopup(
context,
"areYouSureYouWantToCertify".tr(
args: [
getShortPubkey(pubkey!)
]));
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
if (_result ?? false) {
String? _pin;
if (_myWalletProvider.pinCode == '') {
_pin = await Navigator.push(
context,
MaterialPageRoute(
builder: (homeContext) {
return UnlockingWallet(
wallet: defaultWallet);
},
),
);
}
if (_pin != null ||
_myWalletProvider.pinCode != '') {
WalletsProfilesProvider
_walletViewProvider = Provider
.of<WalletsProfilesProvider>(
context,
listen: false);
final acc = _sub.getCurrentWallet();
_sub.certify(
acc.address!,
_pin ??
_myWalletProvider.pinCode,
_walletViewProvider.address!);
Navigator.push(
context,
MaterialPageRoute(
builder: (context) {
return const TransactionInProgress(
transType: 'cert');
}),
);
}
}
}),
),
),
),
const SizedBox(height: 9),
Text(
"Certifier",
textAlign: TextAlign.center,
style: TextStyle(
fontSize: buttonFontSize,
fontWeight: FontWeight.w500),
),
]),
if (snapshot.data!['certDelay'] != null)
Column(children: <Widget>[
SizedBox(
height: buttonSize,
child: Padding(
padding: const EdgeInsets.only(bottom: 0),
child: Container(
foregroundDecoration: const BoxDecoration(
color: Colors.grey,
backgroundBlendMode: BlendMode.saturation,
),
child: const Opacity(
opacity: 0.5,
child: Image(
image: AssetImage(
'assets/gecko_certify.png')),
),
),
),
),
Text(
"Vous devez attendre\n$_duration avant\nde pouvoir certifier",
textAlign: TextAlign.center,
style: TextStyle(
fontSize: buttonFontSize - 4,
fontWeight: FontWeight.w400,
color: Colors.grey[600]),
),
]),
if (snapshot.data!['certRenewable'] != null &&
_duration != '0 secondes')
Column(children: <Widget>[
SizedBox(
height: buttonSize,
child: Padding(
padding: const EdgeInsets.only(bottom: 0),
child: Container(
foregroundDecoration: const BoxDecoration(
color: Colors.grey,
backgroundBlendMode: BlendMode.saturation,
),
child: const Opacity(
opacity: 0.5,
child: Image(
image: AssetImage(
'assets/gecko_certify.png')),
),
),
),
),
Text(
"Vous pourrez renouveller\ncette certification\ndans $_duration",
textAlign: TextAlign.center,
style: TextStyle(
fontSize: buttonFontSize - 4,
fontWeight: FontWeight.w400,
color: Colors.grey[600]),
]),
);
},
);
}),
Column(children: <Widget>[
SizedBox(
child: ClipOval(
child: Material(
color: const Color(0xffFFD58D), // button color
child: InkWell(
key: const Key('copyKey'),
splashColor: orangeC, // inkwell color
child: const Padding(
padding: EdgeInsets.all(20),
child: Image(
image: AssetImage('assets/copy_key.png'),
height: 90)),
onTap: () {
Clipboard.setData(ClipboardData(text: pubkey));
}),
),
),
),
const SizedBox(height: 9),
textAlign: TextAlign.center,
style: TextStyle(
fontSize: buttonFontSize, fontWeight: FontWeight.w500),
// FutureBuilder(
// future: _walletOptions.generateQRcode(_historyProvider.pubkey),
// builder: (context, snapshot) {
// return snapshot.data != null
// ? GestureDetector(
// key: const Key('openQrcode'),
// onTap: () {
// Navigator.push(
// context,
// MaterialPageRoute(builder: (context) {
// return AvatarFullscreen(
// Image.memory(snapshot.data),
// title: 'QrCode du profil',
// color: Colors.white,
// );
// }),
// );
// },
// child: Image.memory(snapshot.data, height: 60 * ratio),
// )
// : const Text('-', style: TextStyle(fontSize: 20));
// },
// ),
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
Consumer<SubstrateSdk>(builder: (context, _sub, _) {
return Opacity(
opacity: _sub.nodeConnected ? 1 : 0.5,
child: Container(
height: buttonSize,
decoration: BoxDecoration(
color: const Color(0xff7c94b6),
borderRadius: const BorderRadius.all(Radius.circular(100)),
border: Border.all(
color: const Color(0xFF6c4204),
width: 4,
),
),
child: ClipOval(
child: Material(
color: orangeC, // button color
child: InkWell(
key: const Key('pay'),
splashColor: yellowC, // inkwell color
child: const Padding(
padding: EdgeInsets.all(14),
child: Image(
image: AssetImage('assets/vector_white.png'),
)),
onTap: _sub.nodeConnected
? () {
paymentPopup(context, _walletProfile);
const SizedBox(height: 9),
Consumer<SubstrateSdk>(builder: (context, _sub, _) {
return Text(
"Faire un\nvirement",
textAlign: TextAlign.center,
style: TextStyle(
color: _sub.nodeConnected ? Colors.black : Colors.grey[500],
fontSize: buttonFontSize,
fontWeight: FontWeight.w500),
);
}),
void paymentPopup(
BuildContext context, WalletsProfilesProvider _walletViewProvider) {
// WalletsProfilesProvider _walletViewProvider =
// Provider.of<WalletsProfilesProvider>(context, listen: false);
MyWalletsProvider _myWalletProvider =
Provider.of<MyWalletsProvider>(context, listen: false);
// SubstrateSdk _sub = Provider.of<SubstrateSdk>(context, listen: false);
const double shapeSize = 20;
WalletData? defaultWallet = _myWalletProvider.getDefaultWallet();
showModalBottomSheet<void>(
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.only(
topRight: Radius.circular(shapeSize),
topLeft: Radius.circular(shapeSize),
),
),
isScrollControlled: true,
context: context,
builder: (BuildContext context) {
return StatefulBuilder(
builder: (BuildContext context, StateSetter setState) {
if (_walletViewProvider.payAmount.text != '' &&
(double.parse(_walletViewProvider.payAmount.text) + 2) <=
_walletViewProvider.address != defaultWallet.address) {
if ((balanceCache[pubkey] == 0 || balanceCache[pubkey] == null) &&
double.parse(_walletViewProvider.payAmount.text) < 5) {
canValidate = false;
} else {
canValidate = true;
}
return Padding(
padding: EdgeInsets.only(
bottom: MediaQuery.of(context).viewInsets.bottom),
child: Container(
height: 400,
decoration: const ShapeDecoration(
color: Color(0xffffeed1),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.only(
topRight: Radius.circular(shapeSize),
topLeft: Radius.circular(shapeSize),
),
child: Padding(
padding: const EdgeInsets.only(
top: 24, bottom: 0, left: 24, right: 24),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
const Text(
'Effectuer un virement',
style: TextStyle(
fontSize: 26, fontWeight: FontWeight.w700),
),
IconButton(
iconSize: 40,
icon: const Icon(Icons.cancel_outlined),
onPressed: () {
Navigator.pop(context);
},
),
]),
const SizedBox(height: 20),
Text(
style: TextStyle(
fontSize: 19,
fontWeight: FontWeight.w500,
color: Colors.grey[600]),
),
const SizedBox(height: 10),
Consumer<SubstrateSdk>(builder: (context, _sub, _) {
return InkWell(
onTap: () async {
String? _pin;
if (_myWalletProvider.pinCode == '') {
_pin = await Navigator.push(
context,
MaterialPageRoute(
builder: (homeContext) {
return UnlockingWallet(
wallet: defaultWallet);
},
),
);
}
if (_pin != null ||
_myWalletProvider.pinCode != '') {
Navigator.push(
context,
MaterialPageRoute(builder: (context) {
return ChooseWalletScreen(
pin: _pin ?? _myWalletProvider.pinCode);
}),
);
}
},
child: Container(
width: double.infinity,
decoration: BoxDecoration(
border: Border.all(
padding: const EdgeInsets.all(10),
child: Row(children: [
Text(defaultWallet.name!),
const Spacer(),
FutureBuilder(
future:
_sub.getBalance(defaultWallet.address!),
builder: (BuildContext context,
if (_balance.connectionState !=
ConnectionState.done ||
_balance.hasError) {
if (balanceCache[
defaultWallet.address!] !=
null) {
return Text(
"${balanceCache[defaultWallet.address!]} $currencyName",
style: const TextStyle(
fontSize: 20,
));
} else {
return SizedBox(
height: 15,
width: 15,
child: CircularProgressIndicator(
color: orangeC,
strokeWidth: 2,
),
);
}
}
balanceCache[defaultWallet.address!] =
"${balanceCache[defaultWallet.address!]} $currencyName",
style: const TextStyle(
fontSize: 20,
),
);
}),
]),
);
}),
const Spacer(),
// const SizedBox(height: 10),
Text(
'Montant:',
style: TextStyle(
fontSize: 19,
fontWeight: FontWeight.w500,
color: Colors.grey[600]),
),
const SizedBox(height: 10),
TextField(
controller: _walletViewProvider.payAmount,
autofocus: true,
maxLines: 1,
textAlign: TextAlign.center,
keyboardType: TextInputType.number,
onChanged: (_) => setState(() {
// _walletViewProvider.reload();
}),
inputFormatters: <TextInputFormatter>[
// FilteringTextInputFormatter.digitsOnly,
FilteringTextInputFormatter.deny(',',
replacementString: '.'),
RegExp(r'(^\d+\.?\d{0,2})')),
],
// onChanged: (v) => _searchProvider.rebuildWidget(),
decoration: InputDecoration(
hintText: '0.00',
suffix: Text(currencyName),
filled: true,
fillColor: Colors.transparent,
// border: OutlineInputBorder(
// borderSide:
// BorderSide(color: Colors.grey[500], width: 2),
// borderRadius: BorderRadius.circular(8)),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(
color: Colors.grey[500]!, width: 2),
borderRadius: BorderRadius.circular(8),
contentPadding: const EdgeInsets.all(20),
),
style: const TextStyle(
fontSize: 40,
color: Colors.black,
fontWeight: FontWeight.w600,
),
// const SizedBox(height: 40),
const Spacer(),
SizedBox(
width: double.infinity,
height: 60,
child: ElevatedButton(
style: ElevatedButton.styleFrom(
elevation: 4,
primary: orangeC, // background
onPrimary: Colors.white, // foreground
),
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
? () async {
String? _pin;
if (_myWalletProvider.pinCode == '') {
_pin = await Navigator.push(
context,
MaterialPageRoute(
builder: (homeContext) {
return UnlockingWallet(
wallet: defaultWallet);
},
),
);
}
log.d(_pin);
if (_pin != null ||
_myWalletProvider.pinCode != '') {
// Payment workflow !
WalletsProfilesProvider
_walletViewProvider =
Provider.of<WalletsProfilesProvider>(
context,
listen: false);
SubstrateSdk _sub =
Provider.of<SubstrateSdk>(context,
listen: false);
final acc = _sub.getCurrentWallet();
log.d(
"fromAddress: ${acc.address!},destAddress: ${_walletViewProvider.address!}, amount: ${double.parse(_walletViewProvider.payAmount.text)}, password: $_pin");
_sub.pay(
fromAddress: acc.address!,
destAddress:
_walletViewProvider.address!,
amount: double.parse(
_walletViewProvider
.payAmount.text),
password: _pin ??
_myWalletProvider.pinCode);
Navigator.push(
context,
MaterialPageRoute(builder: (context) {
return const TransactionInProgress();
}),
);
}
}
: null,
child: const Text(
'Effectuer le virement',
style: TextStyle(
fontSize: 20, fontWeight: FontWeight.w600),
),
),
),
const Spacer(),
]),
),
);
});
}).then((value) => _walletViewProvider.payAmount.text = '');
}