CAKE-54 | added usdt erc20 to cryptocurrencies list; added usdt erc20 to currency picker; added usdt erc20 logo to contact list page; added address validator for usdt erc20; reworked currency picker
OleksandrSobol committed
Sep 25, 2020 at 16:30 UTC
dfb3112fd27e5484f9a22e57df35b7256e8d59bc
5 files changed
+121
-49
assets/images/usdterc.png
Binary files /dev/null and b/assets/images/usdterc.png differ
lib/core/address_validator.dart
+4
@@ -38,6 +38,8 @@ class AddressValidator extends TextValidator {
38
return '[0-9a-zA-Z]';
39
case CryptoCurrency.usdt:
40
return '[0-9a-zA-Z]';
41
+ case CryptoCurrency.usdterc20:
42
+ return '[0-9a-zA-Z]';
43
case CryptoCurrency.xlm:
44
return '[0-9a-zA-Z]';
45
case CryptoCurrency.xrp:
@@ -75,6 +77,8 @@ class AddressValidator extends TextValidator {
77
return [34];
78
case CryptoCurrency.usdt:
79
return [42];
80
+ case CryptoCurrency.usdterc20:
81
+ return [42];
82
case CryptoCurrency.xlm:
83
return [56];
84
case CryptoCurrency.xrp:
lib/entities/crypto_currency.dart
+9
-3
@@ -22,6 +22,7 @@ class CryptoCurrency extends EnumerableItem<int> with Serializable<int> {
22
CryptoCurrency.nano,
23
CryptoCurrency.trx,
24
CryptoCurrency.usdt,
25
+ CryptoCurrency.usdterc20,
26
CryptoCurrency.xlm,
27
CryptoCurrency.xrp
28
];
@@ -38,8 +39,9 @@ class CryptoCurrency extends EnumerableItem<int> with Serializable<int> {
39
static const nano = CryptoCurrency(title: 'NANO', raw: 10);
40
static const trx = CryptoCurrency(title: 'TRX', raw: 11);
41
static const usdt = CryptoCurrency(title: 'USDT', raw: 12);
41
- static const xlm = CryptoCurrency(title: 'XLM', raw: 13);
42
- static const xrp = CryptoCurrency(title: 'XRP', raw: 14);
42
+ static const usdterc20 = CryptoCurrency(title: 'USDTERC20', raw: 13);
43
+ static const xlm = CryptoCurrency(title: 'XLM', raw: 14);
44
+ static const xrp = CryptoCurrency(title: 'XRP', raw: 15);
45
46
static CryptoCurrency deserialize({int raw}) {
47
switch (raw) {
@@ -70,8 +72,10 @@ class CryptoCurrency extends EnumerableItem<int> with Serializable<int> {
72
case 12:
73
return CryptoCurrency.usdt;
74
case 13:
73
- return CryptoCurrency.xlm;
75
+ return CryptoCurrency.usdterc20;
76
case 14:
77
+ return CryptoCurrency.xlm;
78
+ case 15:
79
return CryptoCurrency.xrp;
80
default:
81
return null;
@@ -106,6 +110,8 @@ class CryptoCurrency extends EnumerableItem<int> with Serializable<int> {
110
return CryptoCurrency.trx;
111
case 'usdt':
112
return CryptoCurrency.usdt;
113
+ case 'usdterc20':
114
+ return CryptoCurrency.usdterc20;
115
case 'xlm':
116
return CryptoCurrency.xlm;
117
case 'xrp':
lib/src/screens/contact/contact_list_page.dart
+3
@@ -236,6 +236,9 @@ class ContactListPage extends BasePage {
236
case CryptoCurrency.usdt:
237
image = Image.asset('assets/images/usdt.png', height: 24, width: 24);
238
break;
239
+ case CryptoCurrency.usdterc20:
240
+ image = Image.asset('assets/images/usdterc.png', height: 24, width: 24);
241
+ break;
242
case CryptoCurrency.xlm:
243
image = Image.asset('assets/images/xlm.png', height: 24, width: 24);
244
break;
lib/src/screens/exchange/widgets/currency_picker.dart
+105
-46
@@ -5,8 +5,9 @@ import 'package:flutter/material.dart';
5
import 'package:cake_wallet/entities/crypto_currency.dart';
6
import 'package:cake_wallet/src/widgets/alert_background.dart';
7
import 'package:cake_wallet/src/widgets/alert_close_button.dart';
8
+import 'package:cake_wallet/src/widgets/cake_scrollbar.dart';
9
9
-class CurrencyPicker extends StatelessWidget {
10
+class CurrencyPicker extends StatefulWidget {
11
CurrencyPicker({
12
@required this.selectedAtIndex,
13
@required this.items,
@@ -18,12 +19,47 @@ class CurrencyPicker extends StatelessWidget {
19
final List<CryptoCurrency> items;
20
final String title;
21
final Function(CryptoCurrency) onItemSelected;
22
+
23
+ @override
24
+ CurrencyPickerState createState() => CurrencyPickerState(
25
+ selectedAtIndex,
26
+ items,
27
+ title,
28
+ onItemSelected
29
+ );
30
+}
31
+
32
+class CurrencyPickerState extends State<CurrencyPicker> {
33
+ CurrencyPickerState(
34
+ this.selectedAtIndex,
35
+ this.items,
36
+ this.title,
37
+ this.onItemSelected): itemsCount = items.length;
38
+
39
+ final int selectedAtIndex;
40
+ final List<CryptoCurrency> items;
41
+ final String title;
42
+ final Function(CryptoCurrency) onItemSelected;
43
+
44
final closeButton = Image.asset('assets/images/close.png',
45
color: Palette.darkBlueCraiola,
46
);
47
+ final int crossAxisCount = 3;
48
+ final int itemsCount;
49
+ final double backgroundHeight = 280;
50
+ final double thumbHeight = 72;
51
+ ScrollController controller = ScrollController();
52
+ double fromTop = 0;
53
54
@override
55
Widget build(BuildContext context) {
56
+ controller.addListener(() {
57
+ fromTop = controller.hasClients
58
+ ? (controller.offset / controller.position.maxScrollExtent * (backgroundHeight - thumbHeight))
59
+ : 0;
60
+ setState(() {});
61
+ });
62
+
63
return AlertBackground(
64
child: Stack(
65
alignment: Alignment.center,
@@ -52,54 +88,72 @@ class CurrencyPicker extends StatelessWidget {
88
child: ClipRRect(
89
borderRadius: BorderRadius.all(Radius.circular(14)),
90
child: Container(
55
- height: 400,
56
- width: 300,
57
- color: Theme.of(context).accentTextTheme.title.backgroundColor,
58
- child: GridView.count(
59
- shrinkWrap: true,
60
- crossAxisCount: 3,
61
- childAspectRatio: 1.25,
62
- physics: const NeverScrollableScrollPhysics(),
63
- crossAxisSpacing: 1,
64
- mainAxisSpacing: 1,
65
- children: List.generate(items.length, (index) {
91
+ height: 320,
92
+ width: 300,
93
+ color: Theme.of(context).accentTextTheme.title.backgroundColor,
94
+ child: Stack(
95
+ alignment: Alignment.center,
96
+ children: <Widget>[
97
+ GridView.count(
98
+ controller: controller,
99
+ crossAxisCount: crossAxisCount,
100
+ childAspectRatio: 1.25,
101
+ crossAxisSpacing: 1,
102
+ mainAxisSpacing: 1,
103
+ children: List.generate(
104
+ itemsCount
105
+ + getExtraEmptyTilesCount(crossAxisCount, itemsCount),
106
+ (index) {
107
67
- final item = items[index];
68
- final isItemSelected = index == selectedAtIndex;
108
+ if (index >= itemsCount) {
109
+ return Container(
110
+ color: Theme.of(context).accentTextTheme.title.color,
111
+ );
112
+ }
113
70
- final color = isItemSelected
71
- ? Theme.of(context).textTheme.body2.color
72
- : Theme.of(context).accentTextTheme.title.color;
73
- final textColor = isItemSelected
74
- ? Palette.blueCraiola
75
- : Theme.of(context).primaryTextTheme.title.color;
114
+ final item = items[index];
115
+ final isItemSelected = index == selectedAtIndex;
116
77
- return GestureDetector(
78
- onTap: () {
79
- if (onItemSelected == null) {
80
- return;
81
- }
82
- Navigator.of(context).pop();
83
- onItemSelected(item);
84
- },
85
- child: Container(
86
- color: color,
87
- child: Center(
88
- child: Text(
89
- item.toString(),
90
- style: TextStyle(
91
- fontSize: 18,
92
- fontFamily: 'Poppins',
93
- fontWeight: FontWeight.w600,
94
- decoration: TextDecoration.none,
95
- color: textColor
96
- ),
97
- ),
98
- ),
99
- ),
100
- );
101
- })
102
- ),
117
+ final color = isItemSelected
118
+ ? Theme.of(context).textTheme.body2.color
119
+ : Theme.of(context).accentTextTheme.title.color;
120
+ final textColor = isItemSelected
121
+ ? Palette.blueCraiola
122
+ : Theme.of(context).primaryTextTheme.title.color;
123
+
124
+ return GestureDetector(
125
+ onTap: () {
126
+ if (onItemSelected == null) {
127
+ return;
128
+ }
129
+ Navigator.of(context).pop();
130
+ onItemSelected(item);
131
+ },
132
+ child: Container(
133
+ color: color,
134
+ child: Center(
135
+ child: Text(
136
+ item.toString(),
137
+ style: TextStyle(
138
+ fontSize: 15,
139
+ fontFamily: 'Poppins',
140
+ fontWeight: FontWeight.w600,
141
+ decoration: TextDecoration.none,
142
+ color: textColor
143
+ ),
144
+ ),
145
+ ),
146
+ ),
147
+ );
148
+ })
149
+ ),
150
+ CakeScrollbar(
151
+ backgroundHeight: backgroundHeight,
152
+ thumbHeight: thumbHeight,
153
+ fromTop: fromTop
154
+ )
155
+ ],
156
+ )
157
),
158
),
159
),
@@ -111,4 +165,9 @@ class CurrencyPicker extends StatelessWidget {
165
)
166
);
167
}
168
+
169
+ int getExtraEmptyTilesCount(int crossAxisCount, int itemsCount) {
170
+ final int tilesInNewRowCount = itemsCount % crossAxisCount;
171
+ return tilesInNewRowCount == 0 ? 0 : crossAxisCount - tilesInNewRowCount;
172
+ }
173
}
\ No newline at end of file