Exchange screens access improvements (#409)

* move tag prop to the crypto currency

* add currency icons
This commit is contained in:
Serhii
2022-07-11 16:20:16 +01:00
committed by GitHub
parent 1f8cf9b229
commit 52b8bafac9
10 changed files with 237 additions and 265 deletions
@@ -1,6 +1,5 @@
import 'dart:ui';
import 'package:cake_wallet/src/screens/exchange/widgets/currency_picker_item_widget.dart';
import 'package:cake_wallet/src/screens/exchange/widgets/currency_utils.dart';
import 'package:cake_wallet/src/screens/exchange/widgets/picker_item.dart';
import 'package:cake_wallet/src/widgets/alert_close_button.dart';
import 'package:flutter/cupertino.dart';
@@ -35,45 +34,33 @@ class CurrencyPickerState extends State<CurrencyPicker> {
CurrencyPickerState(this.items)
: isSearchBarActive = false,
textFieldValue = '',
subPickerItemsList = [],
subPickerItemsList = items,
appBarTextStyle =
TextStyle(fontSize: 20, fontFamily: 'Lato', backgroundColor: Colors.transparent, color: Colors.white);
TextStyle(fontSize: 20, fontFamily: 'Lato', backgroundColor: Colors.transparent, color: Colors.white);
@override
void initState() {
pickerItemsList = CryptoCurrency.all
.map((CryptoCurrency cur) => PickerItem<CryptoCurrency>(cur,
title: CurrencyUtils.titleForCurrency(cur),
iconPath: CurrencyUtils.iconPathForCurrency(cur),
tag: CurrencyUtils.tagForCurrency(cur),
description: CurrencyUtils.descriptionForCurrency(cur)))
.toList();
cleanSubPickerItemsList();
super.initState();
}
List<PickerItem<CryptoCurrency>> pickerItemsList;
List<CryptoCurrency> items;
bool isSearchBarActive;
String textFieldValue;
List<PickerItem<CryptoCurrency>> subPickerItemsList;
List<CryptoCurrency> subPickerItemsList;
TextStyle appBarTextStyle;
void cleanSubPickerItemsList() {
subPickerItemsList = pickerItemsList.where((element) => items.contains(element.original)).toList();
}
void cleanSubPickerItemsList() => subPickerItemsList = items;
void currencySearchBySubstring(String subString, List<PickerItem<CryptoCurrency>> list) {
void currencySearchBySubstring(String subString) {
setState(() {
if (subString.isNotEmpty) {
subPickerItemsList = subPickerItemsList
subPickerItemsList = items
.where((element) =>
element.title.contains(subString.toUpperCase()) ||
element.description.contains(subString.toLowerCase()))
(element.title != null ? element.title.toLowerCase().contains(subString.toLowerCase()) : false) ||
(element.tag != null ? element.tag.toLowerCase().contains(subString.toLowerCase()) : false) ||
(element.name != null ? element.name.toLowerCase().contains(subString.toLowerCase()) : false))
.toList();
} else {
cleanSubPickerItemsList();
return;
}
cleanSubPickerItemsList();
});
}
@@ -140,7 +127,7 @@ class CurrencyPickerState extends State<CurrencyPicker> {
onChanged: (value) {
this.textFieldValue = value;
cleanSubPickerItemsList();
currencySearchBySubstring(textFieldValue, subPickerItemsList);
currencySearchBySubstring(textFieldValue);
},
),
),
@@ -152,10 +139,10 @@ class CurrencyPickerState extends State<CurrencyPicker> {
AspectRatio(
aspectRatio: 6,
child: PickerItemWidget(
title: pickerItemsList[widget.selectedAtIndex].title,
iconPath: pickerItemsList[widget.selectedAtIndex].iconPath,
title: items[widget.selectedAtIndex].title,
iconPath: items[widget.selectedAtIndex].iconPath,
isSelected: true,
tag: pickerItemsList[widget.selectedAtIndex].tag,
tag: items[widget.selectedAtIndex].tag,
),
),
Flexible(
@@ -167,10 +154,10 @@ class CurrencyPickerState extends State<CurrencyPicker> {
setState(() {
widget.selectedAtIndex = index;
});
widget.onItemSelected(subPickerItemsList[index].original);
widget.onItemSelected(subPickerItemsList[index]);
if (widget.isConvertFrom &&
!widget.isMoneroWallet &&
(subPickerItemsList[index].original == CryptoCurrency.xmr)) {
(subPickerItemsList[index] == CryptoCurrency.xmr)) {
} else {
Navigator.of(context).pop();
}
@@ -14,7 +14,7 @@ class CurrencyPickerWidget extends StatelessWidget {
final int crossAxisCount;
final int selectedAtIndex;
final Function pickListItem;
final List<PickerItem<CryptoCurrency>> pickerItemsList;
final List<CryptoCurrency> pickerItemsList;
final ScrollController _scrollController = ScrollController();
@@ -1,101 +0,0 @@
import 'package:cw_core/crypto_currency.dart';
class CurrencyUtils {
static String tagForCurrency(CryptoCurrency cur) {
switch (cur) {
case CryptoCurrency.bnb:
return 'BEP2';
case CryptoCurrency.dai:
return 'ETH';
case CryptoCurrency.usdt:
return 'OMNI';
case CryptoCurrency.usdterc20:
return 'ETH';
default:
return null;
}
}
static String iconPathForCurrency(CryptoCurrency cur) {
switch (cur) {
case CryptoCurrency.xmr:
return 'assets/images/monero_icon.png';
case CryptoCurrency.ada:
return 'assets/images/ada_icon.png';
case CryptoCurrency.bch:
return 'assets/images/bch_icon.png';
case CryptoCurrency.bnb:
return 'assets/images/bnb_icon.png';
case CryptoCurrency.btc:
return 'assets/images/btc.png';
case CryptoCurrency.dai:
return 'assets/images/dai_icon.png';
case CryptoCurrency.dash:
return 'assets/images/dash_icon.png';
case CryptoCurrency.eos:
return 'assets/images/eos_icon.png';
case CryptoCurrency.eth:
return 'assets/images/eth_icon.png';
case CryptoCurrency.ltc:
return 'assets/images/litecoin-ltc_icon.png';
case CryptoCurrency.trx:
return 'assets/images/trx_icon.png';
case CryptoCurrency.usdt:
return 'assets/images/usdt_icon.png';
case CryptoCurrency.usdterc20:
return 'assets/images/usdterc20_icon.png';
case CryptoCurrency.xlm:
return 'assets/images/xlm_icon.png';
case CryptoCurrency.xrp:
return 'assets/images/xrp_icon.png';
case CryptoCurrency.xhv:
return 'assets/images/xhv_logo.png';
default:
return null;
}
}
static String titleForCurrency(CryptoCurrency cur) {
switch (cur) {
case CryptoCurrency.bnb:
return 'BNB';
case CryptoCurrency.usdterc20:
return 'USDT';
default:
return cur.title;
}
}
static String descriptionForCurrency(CryptoCurrency cur) {
switch (cur) {
case CryptoCurrency.xmr:
return 'monero';
case CryptoCurrency.ada:
return 'cardano';
case CryptoCurrency.bch:
return 'bitcoin cash';
case CryptoCurrency.bnb:
return 'binance bep2';
case CryptoCurrency.btc:
return 'bitcoin';
case CryptoCurrency.dai:
return 'dai eth';
case CryptoCurrency.eth:
return 'ethereum';
case CryptoCurrency.ltc:
return 'litecoin';
case CryptoCurrency.trx:
return 'tron';
case CryptoCurrency.usdt:
return 'usdt omni';
case CryptoCurrency.usdterc20:
return 'tether ERC20 eth';
case CryptoCurrency.xlm:
return 'lumens';
case CryptoCurrency.xrp:
return 'ripple';
default:
return cur.title;
}
}
}
@@ -176,7 +176,7 @@ class ExchangeCardState extends State<ExchangeCard> {
padding: EdgeInsets.only(right: 5),
child: widget.imageArrow,
),
Text(_selectedCurrency.toString() + ':',
Text(_selectedCurrency.toString(),
style: TextStyle(
fontWeight: FontWeight.w600,
fontSize: 16,
@@ -184,6 +184,40 @@ class ExchangeCardState extends State<ExchangeCard> {
]),
),
),
_selectedCurrency.tag != null ? Padding(
padding: const EdgeInsets.only(right:3.0),
child: Container(
height: 32,
decoration: BoxDecoration(
color: widget.addressButtonsColor ?? Theme.of(context)
.primaryTextTheme
.display1
.color,
borderRadius:
BorderRadius.all(Radius.circular(6))),
child: Center(
child: Padding(
padding: const EdgeInsets.all(6.0),
child: Text(_selectedCurrency.tag,
style: TextStyle(
fontSize: 12,
fontWeight: FontWeight.bold,
color: Theme.of(context)
.primaryTextTheme
.display1
.decorationColor)),
),
),
),
) : Container(),
Padding(
padding: const EdgeInsets.only(right: 4.0),
child: Text(':',
style: TextStyle(
fontWeight: FontWeight.w600,
fontSize: 16,
color: Colors.white)),
),
Expanded(
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
+120 -76
View File
@@ -173,85 +173,129 @@ class SendCardState extends State<SendCard>
Observer(
builder: (_) => Padding(
padding: const EdgeInsets.only(top: 20),
child: Stack(
children: [
BaseTextFormField(
focusNode: cryptoAmountFocus,
controller: cryptoAmountController,
keyboardType:
TextInputType.numberWithOptions(
signed: false, decimal: true),
inputFormatters: [
FilteringTextInputFormatter.deny(RegExp('[\\-|\\ ]'))
],
prefixIcon: Padding(
padding: EdgeInsets.only(top: 9),
child: Text(
sendViewModel.selectedCryptoCurrency.title +
':',
child: Row(
children: [
Padding(
padding: const EdgeInsets.only(bottom: 8.0),
child: Row(
children: [
Text(
sendViewModel.selectedCryptoCurrency.title,
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w600,
color: Colors.white,
)),
sendViewModel.selectedCryptoCurrency.tag != null ? Padding(
padding: const EdgeInsets.fromLTRB(3.0,0,3.0,0),
child: Container(
height: 32,
decoration: BoxDecoration(
color: Theme.of(context)
.primaryTextTheme
.display1
.color,
borderRadius:
BorderRadius.all(Radius.circular(6))),
child: Center(
child: Padding(
padding: const EdgeInsets.all(6.0),
child: Text( sendViewModel.selectedCryptoCurrency.tag,
style: TextStyle(
fontSize: 12,
fontWeight: FontWeight.bold,
color: Theme.of(context)
.primaryTextTheme
.display1
.decorationColor)),
),
),
),
) : Container(),
Padding(
padding: const EdgeInsets.only(right: 10.0),
child: Text(':',
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w600,
color: Colors.white,
)),
fontWeight: FontWeight.w600,
fontSize: 16,
color: Colors.white)),
),
suffixIcon: SizedBox(
width: prefixIconWidth,
),
hintText: '0.0000',
borderColor: Theme.of(context)
.primaryTextTheme
.headline
.color,
textStyle: TextStyle(
fontSize: 14,
fontWeight: FontWeight.w500,
color: Colors.white),
placeholderTextStyle: TextStyle(
color: Theme.of(context)
.primaryTextTheme
.headline
.decorationColor,
fontWeight: FontWeight.w500,
fontSize: 14),
validator: output.sendAll
? sendViewModel.allAmountValidator
: sendViewModel
.amountValidator),
if (!sendViewModel.isBatchSending) Positioned(
top: 2,
right: 0,
child: Container(
width: prefixIconWidth,
height: prefixIconHeight,
child: InkWell(
onTap: () async =>
output.setSendAll(),
child: Container(
decoration: BoxDecoration(
color: Theme.of(context)
.primaryTextTheme
.display1
.color,
borderRadius:
BorderRadius.all(
Radius.circular(6))),
child: Center(
child: Text(
S.of(context).all,
textAlign:
TextAlign.center,
style: TextStyle(
fontSize: 12,
fontWeight:
FontWeight.bold,
color:
Theme.of(context)
.primaryTextTheme
.display1
.decorationColor))),
))))])
],
),
),
Expanded(
child: Stack(
children: [
BaseTextFormField(
focusNode: cryptoAmountFocus,
controller: cryptoAmountController,
keyboardType:
TextInputType.numberWithOptions(
signed: false, decimal: true),
inputFormatters: [
FilteringTextInputFormatter.deny(RegExp('[\\-|\\ ]'))
],
suffixIcon: SizedBox(
width: prefixIconWidth,
),
hintText: '0.0000',
borderColor: Colors.transparent,
textStyle: TextStyle(
fontSize: 14,
fontWeight: FontWeight.w500,
color: Colors.white),
placeholderTextStyle: TextStyle(
color: Theme.of(context)
.primaryTextTheme
.headline
.decorationColor,
fontWeight: FontWeight.w500,
fontSize: 14),
validator: output.sendAll
? sendViewModel.allAmountValidator
: sendViewModel
.amountValidator),
if (!sendViewModel.isBatchSending) Positioned(
top: 2,
right: 0,
child: Container(
width: prefixIconWidth,
height: prefixIconHeight,
child: InkWell(
onTap: () async =>
output.setSendAll(),
child: Container(
decoration: BoxDecoration(
color: Theme.of(context)
.primaryTextTheme
.display1
.color,
borderRadius:
BorderRadius.all(
Radius.circular(6))),
child: Center(
child: Text(
S.of(context).all,
textAlign:
TextAlign.center,
style: TextStyle(
fontSize: 12,
fontWeight:
FontWeight.bold,
color:
Theme.of(context)
.primaryTextTheme
.display1
.decorationColor))),
))))]),
),
],
)
)),
Divider(height: 1,color: Theme.of(context)
.primaryTextTheme
.headline
.decorationColor),
Observer(
builder: (_) => Padding(
padding: EdgeInsets.only(top: 10),