From ed8b343af4dbae36931ab1fee312579c59faa85f Mon Sep 17 00:00:00 2001 From: poka Date: Fri, 19 Mar 2021 06:33:48 +0100 Subject: [PATCH] Change wallet list store format; Start to implement figma wallet options screen --- assets/walletOptions/QR_icon.png | Bin 0 -> 1622 bytes assets/walletOptions/android-checkmark.png | Bin 0 -> 264 bytes assets/walletOptions/camera.png | Bin 0 -> 585 bytes assets/walletOptions/clock.png | Bin 0 -> 1048 bytes assets/walletOptions/copy-white.png | Bin 0 -> 482 bytes assets/walletOptions/edit.png | Bin 0 -> 284 bytes assets/walletOptions/icon_oeuil.png | Bin 0 -> 719 bytes assets/walletOptions/key.png | Bin 0 -> 492 bytes assets/walletOptions/trash.png | Bin 0 -> 2275 bytes lib/globals.dart | 3 + lib/main.dart | 2 +- lib/models/cesiumPlus.dart | 4 +- lib/models/generateWallets.dart | 16 +- lib/models/history.dart | 3 +- lib/models/myWallets.dart | 85 ++++--- lib/models/queries.dart | 2 +- lib/models/walletOptions.dart | 44 ++-- lib/screens/history.dart | 2 +- .../myWallets/confirmWalletStorage.dart | 6 +- lib/screens/myWallets/walletOptions-old.dart | 164 +++++++++++++ lib/screens/myWallets/walletOptions.dart | 220 ++++++++++-------- lib/screens/myWallets/walletsHome.dart | 181 ++++++-------- lib/screens/myWallets/walletsHome_old.dart | 157 ------------- lib/screens/onBoarding/12.dart | 6 +- pubspec.yaml | 1 + 25 files changed, 476 insertions(+), 420 deletions(-) create mode 100755 assets/walletOptions/QR_icon.png create mode 100755 assets/walletOptions/android-checkmark.png create mode 100755 assets/walletOptions/camera.png create mode 100755 assets/walletOptions/clock.png create mode 100755 assets/walletOptions/copy-white.png create mode 100755 assets/walletOptions/edit.png create mode 100755 assets/walletOptions/icon_oeuil.png create mode 100755 assets/walletOptions/key.png create mode 100755 assets/walletOptions/trash.png create mode 100644 lib/screens/myWallets/walletOptions-old.dart delete mode 100644 lib/screens/myWallets/walletsHome_old.dart diff --git a/assets/walletOptions/QR_icon.png b/assets/walletOptions/QR_icon.png new file mode 100755 index 0000000000000000000000000000000000000000..6b6a887d727560ae6bfe018fd8f4eff3cb85858d GIT binary patch literal 1622 zcmeAS@N?(olHy`uVBq!ia0y~yV2l7^4mO~OSk4m%AjMhW5n0T@z%2~Ij105pNB{*H zi-X*q7}lMWc?smOq&xaLGB9lH=l+w(%D}+-+SA1`q=ND7UB|q~ZUPP$iyl-*nhVz& zzfKX>{8rSE^P_p?2ipbT&W62iey}VZXaG)7_c&K-`|}!}=$dms^EN-{v6=VT^!aZ7 z=#X@Uk5&=;&&<-ilm2h=*7=6tGjl5Igy%NyXKQFVz~sUrrl7QeL9mgvgG0x`C4o_i ziCaK0qM?HrsfpijF5Sgi-hKUO&hePrSI-|XJga+P_Mcg*dk#`&FvvMMyT5EGs6Kam z&ihy5mqXtb?>k<+@7b+4*$xT&A6K3E$+E5R%+Ef-8_DO&&m8@JRh@}AC*$?#-+gmF z=+0QZdHrsY{a2sI%)u81d=AdU1lEb)Z;Iw;?>;LBiktM^yxBS2ZwzxjcD**7^VUph zcbh*8nPHFcNW#qPya)C-HJVZ*)c5#4{x+xI^8WKV@6FCearZy3Im@?ww{{LWd? zOirRi1PmxCSI&>^v%H@y1x%lB)6I6+K2JXP-ST<$-0R8f-p=?OD%)`6^|W)3zMWsa zzI5{G_p7Pkk7+CQtc}m+1ljzrm8!p#|EGQywIb%<98hB4dbjRb&QVK{S8hC-@wxWz z8MgkLo3FhIySe)Imi5CP~n{@JxJ^V@n^ekWk}&dp7Y_d&`$UHx3vIVCg!06H}sA^-pY literal 0 HcmV?d00001 diff --git a/assets/walletOptions/android-checkmark.png b/assets/walletOptions/android-checkmark.png new file mode 100755 index 0000000000000000000000000000000000000000..578859d6b12b932c7fc9668e0a5163c485ab242d GIT binary patch literal 264 zcmeAS@N?(olHy`uVBq!ia0vp^;y^6M!3HF?%h*|g6lZ})WHAE+w=f7ZGR&GI0Tg5` z4sv&5Sa(k5C6L3C?&#~tz_78O`%fZB$6QYr$B+ufw-X=oIv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K+L`Biy(PXfJOI4+-y^zG?eVEBQyYXA!zYSJ0LI6n+%$MChp)0Dp3npEBH``o@z6 z^0M2bZh@bIv}=L+za8n(qI9TD8o*0yld4|0AwYO<0~7~+h?2LQ7=)w$#QYO16!dU5 z7aGVnunEy|Uo?I6t?>XiKyglxF+sg)Ush{p@(F4GIf}>^H>)vgg^y626Kpl}GupCA z8o%lV^YeCON99Kn#;iv1z?|oWTJx@p5F=xIn*0s0xCjv1RGW`G7Y-Vcoh6oIalnl9 zjaus}Jkg2lY*Byhx8NQKTQE(~i59QSkXoY)DL|!kVSx8DKvbouhaYSS<}kuyz$-O3 z^ZV45j4EUo2ppX9=Q?MEZf;-fO0-L1KuEkS~0LitW^}@5r zelxZpP}H2B1%t`hBJ>b+Wj7I~9_LN}NrX;-&fy-Ct8vbS0AJ8N(2h+bUF=BZm{&U$ z015>?LI$CaomoIJ1}*gQOjA?6+G5nq35Hd?yZeOe5XOeQ3hxnqD6?3>e}I1g{7)|d S!Wq>70000cmINY=ou;=Wr=uT7)8uM^V($ zhB=y?C%9#TR7`=U4%5ut*b__83^?M3HcZB6O+T9qj?(PIDI9q+G#MPTzK?A7QdhB{ znCvp?F%ws&I>U^Lc@e)F*0afUO)tngvM@y%gMMrHoguqr8`Ax*dXnoMnw!7viTQ&0w8@NP>@x{UllfA< zB{V~hT%oDRKjI`|hAbSSSrAW#Y) Y0~AMBz@5c-@&Et;07*qoM6N<$f<&Rt761SM literal 0 HcmV?d00001 diff --git a/assets/walletOptions/edit.png b/assets/walletOptions/edit.png new file mode 100755 index 0000000000000000000000000000000000000000..a45788da6b98ff24811ebacd61d02ba9716887d4 GIT binary patch literal 284 zcmeAS@N?(olHy`uVBq!ia0vp^f7# z@qDEU#{35l^v?CkIpkl^p7QUeb!qnb33dEJ70wH5b(j8qpscC5Ur1n77mvSo7b+;fBV-p8gfADkXE73X0db2RGh* zxUDuiBuvaZ$ d{BEBewQ^r1i}oWsX`tg7JYD@<);T3K0RYKjXvqKo literal 0 HcmV?d00001 diff --git a/assets/walletOptions/icon_oeuil.png b/assets/walletOptions/icon_oeuil.png new file mode 100755 index 0000000000000000000000000000000000000000..f707647c214f59072e8349f8bbf994aa3770b676 GIT binary patch literal 719 zcmV;=0xl!r}Z_5XBfl1btA%pXaNJPew$9xCKN77hEHPCT^K5W?xBi z4s|-yxy)qdAy45Jd`#cl-Bs1+R`r-=me~SWQs%m)V6&(OOSE?yOoA?u1Ks5~OG?b` z1odDKSZ1ZI7kmV-!2kIi7cvHG0yTQ(iE@H-E26by3b4UkkzjAYV=E9mDe!z2oYHs{ zyacbo8gLa1f%l+a?~a(ueHW|-XTW;-W57G0qgc=ia6>1dwSuP#T&uZ<=F&~4l4X(& z;3jAX2f=x;O7qQ1el}3BMsP^uN1(;LNNCs1<$4Y(!D(>9T+&YP-CXixQibn6fjX_{ zLE6BeNfsI_@}$P!z_TcswQ~LWIu#lZM8Rl%;Fsp9N>8+Ro#j>R2nmFsl%`eVr_IlNGft$ zffMb!r+KyxRqBpT))Xb!92~~g`_o+WZD5yqKmOAkWjhCco2$a2dT0Lqc?IqT7tE{v zuX(>-Gr!3wF$?Nzp`gsBO&QY30kB1x^F42y%W}ws*uN|wwht@w33zMXvscWeW{cbc zAEG!#ufgr$64 ztJtD)|JrD53rfbzqDp&NKrE)5f{a^cnPs*pYzCmQin{_rTmk?9002ovPDHLkV1jJ` BM1=qV literal 0 HcmV?d00001 diff --git a/assets/walletOptions/key.png b/assets/walletOptions/key.png new file mode 100755 index 0000000000000000000000000000000000000000..45c0e85ae5630256f68c58881ae717c3bd1d7049 GIT binary patch literal 492 zcmVvgSEM8QJT zf0zjg<8C%lHVN$c;Dfn^Ihi?=2_Oi9AP9nx0b1(xPtYk^pn3X0&*(bcMg~x{M888k zvEx!h(K5n=^wi^qkOKYm3eke})Z_DLFzrr#7V)=J!329sKVVk*&i1|2C;CcX=%-b; z-Ox8g#63)9I$+C3bd~1l3>ue@`sJ=^1?DAm`H=3|@-N2VZ|A<#r|2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ZQVWyR9bM{%@7&k5EWapE#MG2qt8IDAVm&I zBs{Cs)zxj_(%`D&Npkt}EC+*wud{f1G@kK002ovPDHLkV1l main() async { MyWalletsProvider _walletsProvider = MyWalletsProvider(); await _homeProvider.getAppPath(); await _homeProvider.createDefaultAvatar(); - await _walletsProvider.getDefaultWallet(); + await _walletsProvider.initWalletFolder(); appVersion = await _homeProvider.getAppVersion(); prefs = await SharedPreferences.getInstance(); final HiveStore _store = diff --git a/lib/models/cesiumPlus.dart b/lib/models/cesiumPlus.dart index bf59c6c..7cbe5e4 100644 --- a/lib/models/cesiumPlus.dart +++ b/lib/models/cesiumPlus.dart @@ -67,7 +67,7 @@ class CesiumPlusProvider with ChangeNotifier { String _name; List queryOptions = await _buildQuery(_pubkey); - final response = await http.post(queryOptions[0], + final response = await http.post((Uri.parse(queryOptions[0])), body: queryOptions[1], headers: queryOptions[2]); // print('RESULT CESIUM QUERY: ${response.body}'); //For debug final responseJson = json.decode(response.body); @@ -87,7 +87,7 @@ class CesiumPlusProvider with ChangeNotifier { Future getAvatar(String _pubkey) async { List queryOptions = await _buildQuery(_pubkey); - final response = await http.post(queryOptions[0], + final response = await http.post((Uri.parse(queryOptions[0])), body: queryOptions[1], headers: queryOptions[2]); // print('RESULT CESIUM QUERY: ${response.body}'); //For debug final responseJson = json.decode(response.body); diff --git a/lib/models/generateWallets.dart b/lib/models/generateWallets.dart index 88b85c2..dfcd9e9 100644 --- a/lib/models/generateWallets.dart +++ b/lib/models/generateWallets.dart @@ -39,14 +39,16 @@ class GenerateWalletsProvider with ChangeNotifier { bool canImport = false; bool isPinChanged = false; - Future storeHDWallet( + Future storeHDWChest( NewWallet _wallet, String _name, BuildContext context) async { // Directory walletDirectory; final Directory hdDirectory = Directory('${walletsDirectory.path}/0'); await hdDirectory.create(); - final configFile = File('${hdDirectory.path}/config.txt'); + final configFile = File('${hdDirectory.path}/list.conf'); + File _currentChestFile = File('${walletsDirectory.path}/currentChest.conf'); + final dewifFile = File('${hdDirectory.path}/wallet.dewif'); // List _lastConfig = []; @@ -61,8 +63,14 @@ class GenerateWalletsProvider with ChangeNotifier { accountsIndex: [_derivationNbr]); String _pubkey = _pubkeysTmp[0]; - await configFile.writeAsString('0:$_name:$_derivationNbr:$_pubkey'); + await configFile.writeAsString('0:0:$_name:$_derivationNbr:$_pubkey'); await dewifFile.writeAsString(_wallet.dewif); + bool isCurrentChestExist = _currentChestFile.existsSync(); + if (isCurrentChestExist) { + await _currentChestFile.delete(); + } + await _currentChestFile.create(); + await _currentChestFile.writeAsString('0'); return _name; } @@ -147,11 +155,9 @@ class GenerateWalletsProvider with ChangeNotifier { generatedMnemonic = await DubpRust.genMnemonic(language: Language.french); this.actualWallet = await generateWallet(this.generatedMnemonic); walletIsGenerated = true; - // notifyListeners(); } catch (e) { print(e); } - // await checkIfWalletExist(); return generatedMnemonic; } diff --git a/lib/models/history.dart b/lib/models/history.dart index d8da067..facb32b 100644 --- a/lib/models/history.dart +++ b/lib/models/history.dart @@ -101,7 +101,6 @@ class HistoryProvider with ChangeNotifier { // Lion simone: 78jhpprYkMNF6i5kQPXfkAVBpd2aqcpieNsXTSW4c21f List parseHistory(txs, _pubkey) { - // print(txs); var transBC = []; int i = 0; @@ -135,7 +134,7 @@ class HistoryProvider with ChangeNotifier { transBC[i].add(date); // print( // "DEBUG date et comment: ${date.toString()} -- ${transaction['comment'].toString()}"); - int amountBrut = int.parse(output.split(':')[0]); + final int amountBrut = int.parse(output.split(':')[0]); final base = int.parse(output.split(':')[1]); final int applyBase = base - currentBase; final num amount = diff --git a/lib/models/myWallets.dart b/lib/models/myWallets.dart index b0b61ba..350a227 100644 --- a/lib/models/myWallets.dart +++ b/lib/models/myWallets.dart @@ -8,15 +8,50 @@ import 'package:provider/provider.dart'; class MyWalletsProvider with ChangeNotifier { String listWallets; + Future initWalletFolder() async { + await getDefaultWallet(); + + final bool isWalletFolderExist = await walletsDirectory.exists(); + if (!isWalletFolderExist) { + await Directory(walletsDirectory.path).create(); + } + + File _currentChestFile = File('${walletsDirectory.path}/currentChest.conf'); + + await _currentChestFile.create(); + await _currentChestFile.writeAsString('0'); + + final bool isChestsExist = + await Directory('${walletsDirectory.path}/0').exists(); + if (!isChestsExist) { + await Directory('${walletsDirectory.path}/0').create(); + await Directory('${walletsDirectory.path}/1').create(); + await File('${walletsDirectory.path}/0/list.conf').create(); + await File('${walletsDirectory.path}/0/order.conf').create(); + await File('${walletsDirectory.path}/1/list.conf').create(); + await File('${walletsDirectory.path}/1/order.conf').create(); + } + } + + int getCurrentChest() { + File _currentChestFile = File('${walletsDirectory.path}/currentChest.conf'); + + bool isCurrentChestExist = _currentChestFile.existsSync(); + if (!isCurrentChestExist) { + _currentChestFile.createSync(); + _currentChestFile.writeAsString('0'); + } + return int.parse(_currentChestFile.readAsStringSync()); + } + bool checkIfWalletExist() { if (appPath == null) { return false; } - print(walletsDirectory.listSync()); + final String _walletList = getAllWalletsNames(0); - List contents = walletsDirectory.listSync(); - if (contents.length == 0) { + if (_walletList == '') { print('No wallets detected'); return false; } else { @@ -25,12 +60,7 @@ class MyWalletsProvider with ChangeNotifier { } } - String getAllWalletsNames() { - final bool _isWalletsExists = checkIfWalletExist(); - if (!_isWalletsExists) { - return ''; - } - + String getAllWalletsNames(int _chest) { if (listWallets != null && listWallets.isNotEmpty) { listWallets = ''; } @@ -39,17 +69,13 @@ class MyWalletsProvider with ChangeNotifier { } // int i = 0; - walletsDirectory - .listSync(recursive: false, followLinks: false) - .forEach((_wallet) { - File _walletConfig = File('${_wallet.path}/config.txt'); - _walletConfig.readAsLinesSync().forEach((element) { - if (listWallets != '') { - listWallets += '\n'; - } - listWallets += element; - // listWallets += "${element.split(':')[0]}:${element.split(':')[1]}:${element.split(':')[2]}" - }); + File _walletConfig = File('${walletsDirectory.path}/$_chest/list.conf'); + _walletConfig.readAsLinesSync().forEach((element) { + if (listWallets != '') { + listWallets += '\n'; + } + listWallets += element; + // listWallets += "${element.split(':')[0]}:${element.split(':')[1]}:${element.split(':')[2]}" }); print(listWallets); @@ -68,9 +94,9 @@ class MyWalletsProvider with ChangeNotifier { try { defaultWallet = await defaultWalletFile.readAsString(); } catch (e) { - defaultWallet = '0:3'; + defaultWallet = '0:0'; } - if (defaultWallet == '') defaultWallet = '0:3'; + if (defaultWallet == '') defaultWallet = '0:0'; } Future deleteAllWallet(context) async { @@ -82,6 +108,7 @@ class MyWalletsProvider with ChangeNotifier { if (_answer) { await walletsDirectory.delete(recursive: true); await walletsDirectory.create(); + await initWalletFolder(); notifyListeners(); Navigator.pop(context); } @@ -114,7 +141,7 @@ class MyWalletsProvider with ChangeNotifier { onPressed: () { WidgetsBinding.instance.addPostFrameCallback((_) { _myWalletProvider.listWallets = - _myWalletProvider.getAllWalletsNames(); + _myWalletProvider.getAllWalletsNames(getCurrentChest()); _myWalletProvider.rebuildWidget(); }); Navigator.pop(context, true); @@ -128,18 +155,24 @@ class MyWalletsProvider with ChangeNotifier { Future generateNewDerivation(context, String _name) async { int _newDerivationNbr; - final _walletConfig = File('${walletsDirectory.path}/0/config.txt'); + int _newWalletNbr; + final _walletConfig = File('${walletsDirectory.path}/0/list.conf'); if (await _walletConfig.readAsString() == '') { _newDerivationNbr = 3; + _newWalletNbr = 0; } else { String _lastWallet = await _walletConfig.readAsLines().then((value) => value.last); - int _lastDerivation = int.parse(_lastWallet.split(':')[2]); + int _lastDerivation = int.parse(_lastWallet.split(':')[3]); _newDerivationNbr = _lastDerivation + 3; + + int _lastWalletNbr = int.parse(_lastWallet.split(':')[1]); + _newWalletNbr = _lastWalletNbr + 1; } - await _walletConfig.writeAsString('\n0:$_name:$_newDerivationNbr', + await _walletConfig.writeAsString( + '\n0:$_newWalletNbr:$_name:$_newDerivationNbr', mode: FileMode.append); print(await _walletConfig.readAsString()); diff --git a/lib/models/queries.dart b/lib/models/queries.dart index 52754ab..fda9345 100644 --- a/lib/models/queries.dart +++ b/lib/models/queries.dart @@ -1,7 +1,7 @@ const String getHistory = r''' query ($pubkey: String!, $number: Int!, $cursor: String) { txsHistoryBc( - pubkeyOrScript: $pubkey + script: $pubkey pagination: { pageSize: $number, ord: DESC, cursor: $cursor } ) { both { diff --git a/lib/models/walletOptions.dart b/lib/models/walletOptions.dart index 034f9a5..2c238a7 100644 --- a/lib/models/walletOptions.dart +++ b/lib/models/walletOptions.dart @@ -1,9 +1,12 @@ import 'dart:io'; +import 'package:crypto/crypto.dart'; import 'package:dubp/dubp.dart'; +import 'package:fast_base58/fast_base58.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'dart:async'; import 'package:gecko/globals.dart'; +import 'package:truncate/truncate.dart'; class WalletOptionsProvider with ChangeNotifier { TextEditingController pubkey = TextEditingController(); @@ -65,8 +68,7 @@ class WalletOptionsProvider with ChangeNotifier { int _walletNbr, String _pin, int _pinLenght, int derivation) async { isWalletUnlock = false; try { - File _walletFile = - File('${walletsDirectory.path}/$_walletNbr/wallet.dewif'); + File _walletFile = File('${walletsDirectory.path}/0/wallet.dewif'); String _localDewif = await _walletFile.readAsString(); String _localPubkey; @@ -107,8 +109,7 @@ class WalletOptionsProvider with ChangeNotifier { int getPinLenght(_walletNbr) { String _localDewif; if (_walletNbr is int) { - File _walletFile = - File('${walletsDirectory.path}/$_walletNbr/wallet.dewif'); + File _walletFile = File('${walletsDirectory.path}/0/wallet.dewif'); _localDewif = _walletFile.readAsStringSync(); } else { _localDewif = _walletNbr; @@ -121,21 +122,21 @@ class WalletOptionsProvider with ChangeNotifier { } Future _renameWallet(_walletName, _newName, _walletNbr, _derivation) async { - final _walletConfig = - File('${walletsDirectory.path}/$_walletNbr/config.txt'); + final _walletConfig = File('${walletsDirectory.path}/0/list.conf'); String newConfig = await _walletConfig.readAsLines().then((List lines) { int nbrLines = lines.length; - int _index = lines.indexOf('$_walletNbr:$_walletName:$_derivation'); + print(lines); print(nbrLines); + int _index = lines.indexOf('0:$_walletNbr:$_walletName:$_derivation'); if (nbrLines != 1) { lines.removeWhere((element) => - element.contains('$_walletNbr:$_walletName:$_derivation')); - lines.insert(_index, '$_walletNbr:$_newName:$_derivation'); + element.contains('0:$_walletNbr:$_walletName:$_derivation')); + lines.insert(_index, '0:$_walletNbr:$_newName:$_derivation'); return lines.join('\n'); } else { - return '$_walletNbr:$_newName:$_derivation'; + return '0:$_walletNbr:$_newName:$_derivation'; } }); @@ -189,14 +190,13 @@ class WalletOptionsProvider with ChangeNotifier { final bool _answer = await _confirmDeletingWallet(context, _name); if (_answer) { - final _walletConfig = - File('${walletsDirectory.path}/$_walletNbr/config.txt'); + final _walletConfig = File('${walletsDirectory.path}/0/list.conf'); if (_derivation != -1) { String newConfig = await _walletConfig.readAsLines().then((List lines) { - lines.removeWhere( - (element) => element.contains('$_walletNbr:$_name:$_derivation')); + lines.removeWhere((element) => + element.contains('0:$_walletNbr:$_name:$_derivation')); return lines.join('\n'); }); @@ -289,6 +289,22 @@ class WalletOptionsProvider with ChangeNotifier { ScaffoldMessenger.of(context).showSnackBar(snackBar); } + String getShortPubkey(String pubkey) { + List pubkeyByte = Base58Decode(pubkey); + Digest pubkeyS256 = sha256.convert(sha256.convert(pubkeyByte).bytes); + String pubkeyCheksum = Base58Encode(pubkeyS256.bytes); + String pubkeyChecksumShort = truncate(pubkeyCheksum, 3, + omission: "", position: TruncatePosition.end); + + String pubkeyShort = truncate(pubkey, 5, + omission: String.fromCharCode(0x2026), + position: TruncatePosition.end) + + truncate(pubkey, 4, omission: "", position: TruncatePosition.start) + + ':$pubkeyChecksumShort'; + + return pubkeyShort; + } + void reloadBuild() { notifyListeners(); } diff --git a/lib/screens/history.dart b/lib/screens/history.dart index a8b4cb1..6f26752 100644 --- a/lib/screens/history.dart +++ b/lib/screens/history.dart @@ -254,7 +254,7 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier { initialData: '...', builder: (context, snapshot) { return Text( - snapshot.data != '' + snapshot.data != null ? snapshot.data : '-', style: diff --git a/lib/screens/myWallets/confirmWalletStorage.dart b/lib/screens/myWallets/confirmWalletStorage.dart index db1566a..4aa0130 100644 --- a/lib/screens/myWallets/confirmWalletStorage.dart +++ b/lib/screens/myWallets/confirmWalletStorage.dart @@ -28,6 +28,8 @@ class ConfirmStoreWallet extends StatelessWidget with ChangeNotifier { Provider.of(context); MyWalletsProvider _myWalletProvider = Provider.of(context); + final int _currentChest = _myWalletProvider.getCurrentChest(); + this._mnemonicController.text = generatedMnemonic; return WillPopScope( @@ -126,7 +128,7 @@ class ConfirmStoreWallet extends StatelessWidget with ChangeNotifier { .isAskedWordValid && this.walletName.text != '') ? () async { - await _generateWalletProvider.storeHDWallet( + await _generateWalletProvider.storeHDWChest( generatedWallet, walletName.text, context); @@ -138,7 +140,7 @@ class ConfirmStoreWallet extends StatelessWidget with ChangeNotifier { .addPostFrameCallback((_) { _myWalletProvider.listWallets = _myWalletProvider - .getAllWalletsNames(); + .getAllWalletsNames(_currentChest); _myWalletProvider.rebuildWidget(); }); } diff --git a/lib/screens/myWallets/walletOptions-old.dart b/lib/screens/myWallets/walletOptions-old.dart new file mode 100644 index 0000000..7713274 --- /dev/null +++ b/lib/screens/myWallets/walletOptions-old.dart @@ -0,0 +1,164 @@ +import 'package:flutter/foundation.dart'; +import 'package:flutter/material.dart'; +import 'package:gecko/models/myWallets.dart'; +import 'package:gecko/models/walletOptions.dart'; +import 'dart:async'; +import 'package:provider/provider.dart'; +import 'package:flutter/services.dart'; + +// ignore: must_be_immutable +class WalletOptionsOld extends StatelessWidget with ChangeNotifier { + WalletOptionsOld( + {Key keyMyWallets, + @required this.walletNbr, + @required this.walletName, + @required this.derivation}) + : super(key: keyMyWallets); + int walletNbr; + String walletName; + int derivation; + + @override + Widget build(BuildContext context) { + SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]); + print("Build walletOptions"); + WalletOptionsProvider _walletOptions = + Provider.of(context); + MyWalletsProvider _myWalletProvider = + Provider.of(context); + + // _walletOptions.isWalletUnlock = false; + print("Is unlock ? ${_walletOptions.isWalletUnlock}"); + + final int _currentChest = _myWalletProvider.getCurrentChest(); + + return WillPopScope( + onWillPop: () { + _walletOptions.isWalletUnlock = false; + Navigator.popUntil( + context, + ModalRoute.withName('/mywallets'), + ); + return Future.value(true); + }, + child: Scaffold( + resizeToAvoidBottomInset: false, + appBar: AppBar( + leading: IconButton( + icon: Icon(Icons.arrow_back, color: Colors.black), + onPressed: () { + _walletOptions.isWalletUnlock = false; + Navigator.popUntil( + context, + ModalRoute.withName('/mywallets'), + ); + }), + title: SizedBox( + height: 22, + child: Text(walletName), + )), + body: Builder( + builder: (ctx) => SafeArea( + child: Column(children: [ + Expanded( + child: Column(children: [ + SizedBox(height: 15), + Text( + 'Clé publique:', + style: TextStyle( + fontSize: 15.0, + color: Colors.grey[600], + fontWeight: FontWeight.w400), + ), + SizedBox(height: 15), + GestureDetector( + onTap: () { + Clipboard.setData(ClipboardData( + text: _walletOptions.pubkey.text)); + _walletOptions.snackCopyKey(ctx); + }, + child: Text( + _walletOptions.pubkey.text, + style: TextStyle( + fontSize: 14.0, + color: Colors.black, + fontWeight: FontWeight.bold, + fontFamily: 'Monospace'), + )), + Expanded( + child: Align( + alignment: Alignment.bottomCenter, + child: SizedBox( + height: 50, + width: 300, + child: ElevatedButton( + style: ElevatedButton.styleFrom( + elevation: 5, + primary: Color( + 0xffFFD68E), //Color(0xffFFD68E), // background + onPrimary: Colors.black, // foreground + ), + onPressed: () => _walletOptions + .renameWalletAlerte( + context, + walletName, + walletNbr, + derivation) + .then((_result) { + if (_result == true) { + WidgetsBinding.instance + .addPostFrameCallback((_) { + _myWalletProvider + .listWallets = + _myWalletProvider + .getAllWalletsNames(_currentChest); + _myWalletProvider + .rebuildWidget(); + }); + Navigator.popUntil( + context, + ModalRoute.withName( + '/mywallets'), + ); + } + }), + child: Text('Renommer ce portefeuille', + style: TextStyle(fontSize: 20)))))), + SizedBox(height: 30), + SizedBox( + height: 50, + width: 300, + child: ElevatedButton( + style: ElevatedButton.styleFrom( + elevation: 6, + primary: Colors + .redAccent, //Color(0xffFFD68E), // background + onPrimary: Colors.black, // foreground + ), + onPressed: () async { + await _walletOptions.deleteWallet(context, + walletNbr, walletName, derivation); + WidgetsBinding.instance + .addPostFrameCallback((_) { + _myWalletProvider.listWallets = + _myWalletProvider.getAllWalletsNames(_currentChest); + _myWalletProvider.rebuildWidget(); + }); + }, + child: Text('Supprimer ce portefeuille', + style: TextStyle(fontSize: 20)))), + SizedBox(height: 50), + Text( + 'Portefeuille déverrouillé', + style: TextStyle( + color: Colors.green, + fontWeight: FontWeight.w700, + fontSize: 15), + ), + SizedBox(height: 10) + ])), + ]), + )), + )); + } +} diff --git a/lib/screens/myWallets/walletOptions.dart b/lib/screens/myWallets/walletOptions.dart index 221e9e1..8ed09d4 100644 --- a/lib/screens/myWallets/walletOptions.dart +++ b/lib/screens/myWallets/walletOptions.dart @@ -27,12 +27,12 @@ class WalletOptions extends StatelessWidget with ChangeNotifier { MyWalletsProvider _myWalletProvider = Provider.of(context); - // _walletOptions.isWalletUnlock = false; - print("Is unlock ? ${_walletOptions.isWalletUnlock}"); + final int _currentChest = _myWalletProvider.getCurrentChest(); + final String shortPubkey = + _walletOptions.getShortPubkey(_walletOptions.pubkey.text); return WillPopScope( onWillPop: () { - _walletOptions.isWalletUnlock = false; Navigator.popUntil( context, ModalRoute.withName('/mywallets'), @@ -45,7 +45,6 @@ class WalletOptions extends StatelessWidget with ChangeNotifier { leading: IconButton( icon: Icon(Icons.arrow_back, color: Colors.black), onPressed: () { - _walletOptions.isWalletUnlock = false; Navigator.popUntil( context, ModalRoute.withName('/mywallets'), @@ -57,105 +56,124 @@ class WalletOptions extends StatelessWidget with ChangeNotifier { )), body: Builder( builder: (ctx) => SafeArea( - child: Column(children: [ - Expanded( - child: Column(children: [ - SizedBox(height: 15), - Text( - 'Clé publique:', - style: TextStyle( - fontSize: 15.0, - color: Colors.grey[600], - fontWeight: FontWeight.w400), - ), - SizedBox(height: 15), - GestureDetector( - onTap: () { - Clipboard.setData(ClipboardData( - text: _walletOptions.pubkey.text)); - _walletOptions.snackCopyKey(ctx); - }, - child: Text( - _walletOptions.pubkey.text, - style: TextStyle( - fontSize: 14.0, - color: Colors.black, - fontWeight: FontWeight.bold, - fontFamily: 'Monospace'), - )), - Expanded( - child: Align( - alignment: Alignment.bottomCenter, - child: SizedBox( - height: 50, - width: 300, - child: ElevatedButton( - style: ElevatedButton.styleFrom( - elevation: 5, - primary: Color( - 0xffFFD68E), //Color(0xffFFD68E), // background - onPrimary: Colors.black, // foreground - ), - onPressed: () => _walletOptions - .renameWalletAlerte( - context, - walletName, - walletNbr, - derivation) - .then((_result) { - if (_result == true) { - WidgetsBinding.instance - .addPostFrameCallback((_) { - _myWalletProvider - .listWallets = - _myWalletProvider - .getAllWalletsNames(); - _myWalletProvider - .rebuildWidget(); - }); - Navigator.popUntil( - context, - ModalRoute.withName( - '/mywallets'), - ); - } - }), - child: Text('Renommer ce portefeuille', - style: TextStyle(fontSize: 20)))))), - SizedBox(height: 30), - SizedBox( - height: 50, - width: 300, - child: ElevatedButton( - style: ElevatedButton.styleFrom( - elevation: 6, - primary: Colors - .redAccent, //Color(0xffFFD68E), // background - onPrimary: Colors.black, // foreground + child: Expanded( + child: Column(children: [ + SizedBox(height: 25), + Row(children: [ + SizedBox(width: 25), + Image.asset( + 'assets/chopp-gecko2.png', + ), + Image.asset( + 'assets/walletOptions/camera.png', + ), + // SizedBox(width: 20), + Column(children: [ + Row(children: [ + Column(children: [ + SizedBox( + width: 250, + child: Text( + walletName, + textAlign: TextAlign.center, + style: TextStyle(fontSize: 27), + )), + SizedBox(height: 5), + Text( + '500 DU', + style: TextStyle( + fontSize: 20, color: Colors.black), ), - onPressed: () async { - await _walletOptions.deleteWallet(context, - walletNbr, walletName, derivation); - WidgetsBinding.instance - .addPostFrameCallback((_) { - _myWalletProvider.listWallets = - _myWalletProvider.getAllWalletsNames(); - _myWalletProvider.rebuildWidget(); - }); - }, - child: Text('Supprimer ce portefeuille', - style: TextStyle(fontSize: 20)))), - SizedBox(height: 50), - Text( - 'Portefeuille déverrouillé', - style: TextStyle( - color: Colors.green, - fontWeight: FontWeight.w700, - fontSize: 15), + SizedBox(height: 5), + Image.asset( + 'assets/walletOptions/icon_oeuil.png', + ), + ]), + SizedBox(width: 0), + Column(children: [ + Image.asset( + 'assets/walletOptions/edit.png', + ), + SizedBox( + height: 60, + ) + ]) + ]), + ]), + ]), + Image.asset( + 'assets/walletOptions/QR_icon.png', ), - SizedBox(height: 10) - ])), - ]), + SizedBox(height: 15), + Row(children: [ + SizedBox(width: 30), + Image.asset( + 'assets/walletOptions/key.png', + ), + SizedBox(width: 10), + Text("${shortPubkey.split(':')[0]}:", + style: TextStyle( + fontSize: 22, + fontWeight: FontWeight.w800, + fontFamily: 'Monospace', + color: Colors.black)), + Text(shortPubkey.split(':')[1], + style: TextStyle( + fontSize: 22, + fontWeight: FontWeight.w800, + fontFamily: 'Monospace')), + SizedBox(width: 15), + ElevatedButton( + style: ElevatedButton.styleFrom( + shape: RoundedRectangleBorder( + borderRadius: new BorderRadius.circular(8), + ), + elevation: 1, + primary: Color(0xffD28928), // background + onPrimary: Colors.black, // foreground + ), + onPressed: () { + print('COPY PUBKEY'); + }, + child: Text('Copier', + style: TextStyle( + fontSize: 15, color: Colors.grey[50]))), + ]), + SizedBox(height: 10), + Row(children: [ + SizedBox(width: 30), + Image.asset( + 'assets/walletOptions/clock.png', + ), + SizedBox(width: 10), + Text('Historique des transactions', + style: + TextStyle(fontSize: 20, color: Colors.black)), + ]), + SizedBox(height: 15), + Row(children: [ + SizedBox(width: 35), + Image.asset( + 'assets/walletOptions/android-checkmark.png', + ), + SizedBox(width: 10), + Text('Portefeuille par defaut', + style: + TextStyle(fontSize: 20, color: Colors.black)), + ]), + SizedBox(height: 15), + Row(children: [ + SizedBox(width: 30), + Image.asset( + 'assets/walletOptions/trash.png', + ), + SizedBox(width: 10), + Text('Supprimer ce portefeuille', + style: TextStyle( + fontSize: 20, color: Color(0xffD80000))), + ]), + ]), + ), )), )); } diff --git a/lib/screens/myWallets/walletsHome.dart b/lib/screens/myWallets/walletsHome.dart index 1ab1650..a4aca34 100644 --- a/lib/screens/myWallets/walletsHome.dart +++ b/lib/screens/myWallets/walletsHome.dart @@ -20,12 +20,16 @@ class WalletsHome extends StatelessWidget { WalletOptionsProvider _walletOptions = Provider.of(context); _walletOptions.isWalletUnlock = false; - myWalletProvider.listWallets = myWalletProvider.getAllWalletsNames(); + + final int _currentChest = myWalletProvider.getCurrentChest(); + + myWalletProvider.listWallets = + myWalletProvider.getAllWalletsNames(_currentChest); final bool isWalletsExists = myWalletProvider.checkIfWalletExist(); if (myWalletProvider.listWallets != '') { firstWalletDerivation = - int.parse(myWalletProvider.listWallets.split('\n')[0].split(':')[2]); + int.parse(myWalletProvider.listWallets.split('\n')[0].split(':')[3]); } return Scaffold( @@ -95,114 +99,79 @@ class WalletsHome extends StatelessWidget { for (String _repository in _listWallets) Padding( padding: EdgeInsets.all(16), - child: ClipRRect( - borderRadius: BorderRadius.all(Radius.circular(12)), - child: Column(children: [ - Expanded( - child: Container( - width: double.infinity, - height: double.infinity, - decoration: BoxDecoration( - gradient: RadialGradient( - radius: 1, - colors: [ - Colors.green[100], - Colors.green[500], - ], - )), - child: - // SvgPicture.asset('assets/chopp-gecko2.png', - // semanticsLabel: 'Gecko', height: 48), - Image.asset( - 'assets/chopp-gecko2.png', - ), - )), - ListTile( - // contentPadding: const EdgeInsets.only(left: 7.0), - tileColor: - "${_repository.split(':')[0]}:${_repository.split(':')[2]}" == - defaultWallet - ? Color(0xffD28928) - : Color(0xffFFD58D), - // leading: Text('IMAGE'), + child: GestureDetector( + onTap: () { + Navigator.push(context, + MaterialPageRoute(builder: (context) { + return UnlockingWallet( + walletNbr: int.parse(_repository.split(':')[1]), + walletName: _repository.split(':')[2], + derivation: int.parse(_repository.split(':')[3])); + })); + }, + child: ClipRRect( + borderRadius: BorderRadius.all(Radius.circular(12)), + child: Column(children: [ + Expanded( + child: Container( + width: double.infinity, + height: double.infinity, + decoration: BoxDecoration( + gradient: RadialGradient( + radius: 1, + colors: [ + Colors.green[100], + Colors.green[500], + ], + )), + child: + // SvgPicture.asset('assets/chopp-gecko2.png', + // semanticsLabel: 'Gecko', height: 48), + Image.asset( + 'assets/chopp-gecko2.png', + ), + )), + ListTile( + // contentPadding: const EdgeInsets.only(left: 7.0), + tileColor: + "${_repository.split(':')[0]}:${_repository.split(':')[1]}" == + defaultWallet + ? Color(0xffD28928) + : Color(0xffFFD58D), + // leading: Text('IMAGE'), - // subtitle: Text(_repository.split(':')[3], - // style: TextStyle(fontSize: 12.0, fontFamily: 'Monospace')), - title: Center( - child: Padding( - padding: EdgeInsets.symmetric(horizontal: 5), - child: Text(_repository.split(':')[1], - textAlign: TextAlign.center, - style: TextStyle( - fontSize: 16.0, - color: - "${_repository.split(':')[0]}:${_repository.split(':')[2]}" == - defaultWallet - ? Color(0xffF9F9F1) - : Colors.black)))), - // dense: true, - onTap: () { - Navigator.push(context, - MaterialPageRoute(builder: (context) { - return UnlockingWallet( - walletNbr: int.parse(_repository.split(':')[0]), - walletName: _repository.split(':')[1], - derivation: - int.parse(_repository.split(':')[2])); - })); - }, - ) - ]))) + // subtitle: Text(_repository.split(':')[3], + // style: TextStyle(fontSize: 12.0, fontFamily: 'Monospace')), + title: Center( + child: Padding( + padding: + EdgeInsets.symmetric(horizontal: 5), + child: Text(_repository.split(':')[2], + textAlign: TextAlign.center, + style: TextStyle( + fontSize: 16.0, + color: + "${_repository.split(':')[0]}:${_repository.split(':')[1]}" == + defaultWallet + ? Color(0xffF9F9F1) + : Colors.black)))), + // dense: true, + onTap: () { + Navigator.push(context, + MaterialPageRoute(builder: (context) { + return UnlockingWallet( + walletNbr: + int.parse(_repository.split(':')[1]), + walletName: _repository.split(':')[2], + derivation: + int.parse(_repository.split(':')[3])); + })); + }, + ) + ])))) ]); } - Widget myWalletsList(BuildContext context) { - MyWalletsProvider _myWalletProvider = - Provider.of(context); - - final bool isWalletsExists = _myWalletProvider.checkIfWalletExist(); - - if (!isWalletsExists) { - return Text(''); - } - - if (_myWalletProvider.listWallets == '') { - return Expanded( - child: Center( - child: Text( - 'Veuillez générer votre premier portefeuille', - style: TextStyle(fontSize: 17, fontWeight: FontWeight.w500), - ))); - } - - List _listWallets = _myWalletProvider.listWallets.split('\n'); - - return Expanded( - child: ListView(children: [ - SizedBox(height: 8), - for (String _repository in _listWallets) - ListTile( - contentPadding: const EdgeInsets.only(left: 7.0), - leading: Padding( - padding: const EdgeInsets.all(6.0), - child: Text("0 Ğ1", style: TextStyle(fontSize: 14.0))), - // subtitle: Text(_repository.split(':')[3], - // style: TextStyle(fontSize: 12.0, fontFamily: 'Monospace')), - title: - Text(_repository.split(':')[1], style: TextStyle(fontSize: 16.0)), - dense: true, - onTap: () { - Navigator.push(context, MaterialPageRoute(builder: (context) { - return UnlockingWallet( - walletNbr: int.parse(_repository.split(':')[0]), - walletName: _repository.split(':')[1], - derivation: int.parse(_repository.split(':')[2])); - })); - }, - ) - ])); - } - Widget addNewDerivation(context, int _walletNbr) { final TextEditingController _newDerivationName = TextEditingController(); MyWalletsProvider _myWalletProvider = diff --git a/lib/screens/myWallets/walletsHome_old.dart b/lib/screens/myWallets/walletsHome_old.dart deleted file mode 100644 index 7a5f99e..0000000 --- a/lib/screens/myWallets/walletsHome_old.dart +++ /dev/null @@ -1,157 +0,0 @@ -import 'package:flutter/services.dart'; -import 'package:gecko/models/myWallets.dart'; -import 'package:gecko/models/walletOptions.dart'; -import 'package:flutter/material.dart'; -import 'package:gecko/screens/myWallets/unlockingWallet.dart'; -import 'package:gecko/screens/onBoarding/0_noKeychainFound.dart'; -import 'package:provider/provider.dart'; - -// ignore: must_be_immutable -class WalletsHome extends StatelessWidget { - final _derivationKey = GlobalKey(); - int firstWalletDerivation; - - @override - Widget build(BuildContext context) { - SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]); - MyWalletsProvider myWalletProvider = - Provider.of(context); - WalletOptionsProvider _walletOptions = - Provider.of(context); - _walletOptions.isWalletUnlock = false; - myWalletProvider.listWallets = myWalletProvider.getAllWalletsNames(); - final bool isWalletsExists = myWalletProvider.checkIfWalletExist(); - - if (myWalletProvider.listWallets != '') { - firstWalletDerivation = - int.parse(myWalletProvider.listWallets.split('\n')[0].split(':')[2]); - } - - return Scaffold( - appBar: AppBar( - title: Text('Mes portefeuilles', - style: TextStyle(color: Colors.grey[850])), - backgroundColor: Color(0xffFFD58D), - ), - floatingActionButton: Visibility( - visible: (isWalletsExists && firstWalletDerivation != -1), - child: Container( - height: 80.0, - width: 80.0, - child: FittedBox( - child: FloatingActionButton( - heroTag: "buttonGenerateWallet", - onPressed: () { - showDialog( - context: context, - builder: (BuildContext context) { - return addNewDerivation(context, 1); - }); - }, - child: Container( - height: 40, - width: 40, - child: Icon(Icons.person_add_alt_1_rounded, - color: Colors.grey[850])), - backgroundColor: Color(0xffEFEFBF))))), - body: SafeArea( - child: !isWalletsExists - ? NoKeyChainScreen() - : myWalletsList(context))); - } - - Widget myWalletsList(BuildContext context) { - MyWalletsProvider _myWalletProvider = - Provider.of(context); - - final bool isWalletsExists = _myWalletProvider.checkIfWalletExist(); - - if (!isWalletsExists) { - return Text(''); - } - - if (_myWalletProvider.listWallets == '') { - return Expanded( - child: Center( - child: Text( - 'Veuillez générer votre premier portefeuille', - style: TextStyle(fontSize: 17, fontWeight: FontWeight.w500), - ))); - } - - List _listWallets = _myWalletProvider.listWallets.split('\n'); - - return Expanded( - child: ListView(children: [ - SizedBox(height: 8), - for (String _repository in _listWallets) - ListTile( - contentPadding: const EdgeInsets.only(left: 7.0), - leading: Padding( - padding: const EdgeInsets.all(6.0), - child: Text("0 Ğ1", style: TextStyle(fontSize: 14.0))), - // subtitle: Text(_repository.split(':')[3], - // style: TextStyle(fontSize: 12.0, fontFamily: 'Monospace')), - title: - Text(_repository.split(':')[1], style: TextStyle(fontSize: 16.0)), - dense: true, - onTap: () { - Navigator.push(context, MaterialPageRoute(builder: (context) { - return UnlockingWallet( - walletNbr: int.parse(_repository.split(':')[0]), - walletName: _repository.split(':')[1], - derivation: int.parse(_repository.split(':')[2])); - })); - }, - ) - ])); - } - - Widget addNewDerivation(context, int _walletNbr) { - final TextEditingController _newDerivationName = TextEditingController(); - MyWalletsProvider _myWalletProvider = - Provider.of(context); - - return AlertDialog( - content: Stack( - clipBehavior: Clip.hardEdge, - children: [ - Form( - key: _derivationKey, - child: Column( - mainAxisSize: MainAxisSize.min, - children: [ - Text('Nom du portefeuille:'), - Padding( - padding: EdgeInsets.all(8.0), - child: TextFormField( - controller: _newDerivationName, - textAlign: TextAlign.center, - autofocus: true, - ), - ), - SizedBox(height: 20), - Padding( - padding: const EdgeInsets.all(8.0), - child: ElevatedButton( - style: ElevatedButton.styleFrom( - elevation: 1, - primary: Color(0xffFFD68E), // background - onPrimary: Colors.black, // foreground - ), - onPressed: () async { - await _myWalletProvider - .generateNewDerivation( - context, _newDerivationName.text) - .then((_) => _newDerivationName.text == ''); - }, - child: Text("Créer")), - ) - ], - ), - ), - ], - ), - ); - } -} diff --git a/lib/screens/onBoarding/12.dart b/lib/screens/onBoarding/12.dart index d9e8e61..fd01ff4 100644 --- a/lib/screens/onBoarding/12.dart +++ b/lib/screens/onBoarding/12.dart @@ -61,6 +61,8 @@ class OnboardingStepFourteen extends StatelessWidget { GenerateWalletsProvider _generateWalletProvider = Provider.of(context); + final int _currentChest = _myWalletProvider.getCurrentChest(); + return Form( key: formKey, child: Padding( @@ -116,9 +118,9 @@ class OnboardingStepFourteen extends StatelessWidget { if (resultWallet) { pinColor = Colors.green[500]; print(generatedWallet.pin); - await _generateWalletProvider.storeHDWallet( + await _generateWalletProvider.storeHDWChest( generatedWallet, 'Mon portefeuille courant', context); - _myWalletProvider.getAllWalletsNames(); + _myWalletProvider.getAllWalletsNames(_currentChest); _walletOptions.reloadBuild(); _myWalletProvider.rebuildWidget(); Navigator.push( diff --git a/pubspec.yaml b/pubspec.yaml index 8cdb9aa..73c0f3f 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -67,3 +67,4 @@ flutter: - assets/icon/ - assets/onBoarding/ - assets/onBoarding/progress_bar/ + - assets/walletOptions/