mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2025-01-23 19:05:51 +00:00
single coin list for swap currency selection
This commit is contained in:
parent
3ab706424c
commit
bc90723c86
1 changed files with 124 additions and 192 deletions
|
@ -111,26 +111,28 @@ class _ExchangeCurrencySelectionViewState
|
||||||
return currencies;
|
return currencies;
|
||||||
}
|
}
|
||||||
|
|
||||||
await showDialog<void>(
|
if (mounted) {
|
||||||
context: context,
|
await showDialog<void>(
|
||||||
builder: (context) => StackDialog(
|
context: context,
|
||||||
title: "ChangeNOW Error",
|
builder: (context) => StackDialog(
|
||||||
message: "Failed to load currency data: ${cn.exception}",
|
title: "ChangeNOW Error",
|
||||||
leftButton: SecondaryButton(
|
message: "Failed to load currency data: ${cn.exception}",
|
||||||
label: "Ok",
|
leftButton: SecondaryButton(
|
||||||
onPressed: Navigator.of(context, rootNavigator: isDesktop).pop,
|
label: "Ok",
|
||||||
|
onPressed: Navigator.of(context, rootNavigator: isDesktop).pop,
|
||||||
|
),
|
||||||
|
rightButton: PrimaryButton(
|
||||||
|
label: "Retry",
|
||||||
|
onPressed: () async {
|
||||||
|
Navigator.of(context, rootNavigator: isDesktop).pop();
|
||||||
|
_currencies = await _showUpdatingCurrencies(
|
||||||
|
whileFuture: _loadCurrencies());
|
||||||
|
setState(() {});
|
||||||
|
},
|
||||||
|
),
|
||||||
),
|
),
|
||||||
rightButton: PrimaryButton(
|
);
|
||||||
label: "Retry",
|
}
|
||||||
onPressed: () async {
|
|
||||||
Navigator.of(context, rootNavigator: isDesktop).pop();
|
|
||||||
_currencies =
|
|
||||||
await _showUpdatingCurrencies(whileFuture: _loadCurrencies());
|
|
||||||
setState(() {});
|
|
||||||
},
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
currencies.addAll(cn.value!);
|
currencies.addAll(cn.value!);
|
||||||
}
|
}
|
||||||
|
@ -180,13 +182,13 @@ class _ExchangeCurrencySelectionViewState
|
||||||
.where((e) =>
|
.where((e) =>
|
||||||
e.name.toLowerCase().contains(text.toLowerCase()) ||
|
e.name.toLowerCase().contains(text.toLowerCase()) ||
|
||||||
e.ticker.toLowerCase().contains(text.toLowerCase()))
|
e.ticker.toLowerCase().contains(text.toLowerCase()))
|
||||||
.toList(growable: false);
|
.toList();
|
||||||
} else {
|
} else {
|
||||||
if (text.isEmpty) {
|
if (text.isEmpty) {
|
||||||
return _currencies
|
return _currencies
|
||||||
.where((e) =>
|
.where((e) =>
|
||||||
e.ticker.toLowerCase() != widget.pairedTicker!.toLowerCase())
|
e.ticker.toLowerCase() != widget.pairedTicker!.toLowerCase())
|
||||||
.toList(growable: false);
|
.toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
return _currencies
|
return _currencies
|
||||||
|
@ -194,7 +196,7 @@ class _ExchangeCurrencySelectionViewState
|
||||||
e.ticker.toLowerCase() != widget.pairedTicker!.toLowerCase() &&
|
e.ticker.toLowerCase() != widget.pairedTicker!.toLowerCase() &&
|
||||||
(e.name.toLowerCase().contains(text.toLowerCase()) ||
|
(e.name.toLowerCase().contains(text.toLowerCase()) ||
|
||||||
e.ticker.toLowerCase().contains(text.toLowerCase())))
|
e.ticker.toLowerCase().contains(text.toLowerCase())))
|
||||||
.toList(growable: false);
|
.toList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -328,181 +330,111 @@ class _ExchangeCurrencySelectionViewState
|
||||||
height: 12,
|
height: 12,
|
||||||
),
|
),
|
||||||
Flexible(
|
Flexible(
|
||||||
child: Builder(builder: (context) {
|
child: Builder(
|
||||||
final coins = Coin.values.where((e) =>
|
builder: (context) {
|
||||||
e.ticker.toLowerCase() != widget.pairedTicker?.toLowerCase());
|
final coins = Coin.values.where((e) =>
|
||||||
|
e.ticker.toLowerCase() !=
|
||||||
|
widget.pairedTicker?.toLowerCase());
|
||||||
|
|
||||||
final items = filter(_searchString)
|
final items = filter(_searchString);
|
||||||
.where((e) => coins
|
|
||||||
.where((coin) =>
|
|
||||||
coin.ticker.toLowerCase() == e.ticker.toLowerCase())
|
|
||||||
.isNotEmpty)
|
|
||||||
.toList(growable: false);
|
|
||||||
items.sort((a, b) => a.name.compareTo(b.name));
|
|
||||||
|
|
||||||
return RoundedWhiteContainer(
|
final walletCoins = items
|
||||||
padding: const EdgeInsets.all(0),
|
.where((currency) => coins
|
||||||
child: ListView.builder(
|
.where((coin) =>
|
||||||
shrinkWrap: true,
|
coin.ticker.toLowerCase() ==
|
||||||
primary: isDesktop ? false : null,
|
currency.ticker.toLowerCase())
|
||||||
itemCount: items.length,
|
.isNotEmpty)
|
||||||
itemBuilder: (builderContext, index) {
|
.toList();
|
||||||
final bool hasImageUrl =
|
|
||||||
items[index].image.startsWith("http");
|
// sort alphabetically by name
|
||||||
return Padding(
|
items.sort((a, b) => a.name.compareTo(b.name));
|
||||||
padding: const EdgeInsets.symmetric(vertical: 4),
|
|
||||||
child: GestureDetector(
|
// reverse sort walletCoins to prepare for next step
|
||||||
onTap: () {
|
walletCoins.sort((a, b) => b.name.compareTo(a.name));
|
||||||
Navigator.of(context).pop(items[index]);
|
|
||||||
},
|
// insert wallet coins at beginning
|
||||||
child: RoundedWhiteContainer(
|
for (final c in walletCoins) {
|
||||||
child: Row(
|
items.remove(c);
|
||||||
children: [
|
items.insert(0, c);
|
||||||
SizedBox(
|
}
|
||||||
width: 24,
|
|
||||||
height: 24,
|
return RoundedWhiteContainer(
|
||||||
child: isStackCoin(items[index].ticker)
|
padding: const EdgeInsets.all(0),
|
||||||
? getIconForTicker(
|
child: ListView.builder(
|
||||||
items[index].ticker,
|
shrinkWrap: true,
|
||||||
size: 24,
|
primary: isDesktop ? false : null,
|
||||||
)
|
itemCount: items.length,
|
||||||
: hasImageUrl
|
itemBuilder: (builderContext, index) {
|
||||||
? SvgPicture.network(
|
final bool hasImageUrl =
|
||||||
items[index].image,
|
items[index].image.startsWith("http");
|
||||||
width: 24,
|
return Padding(
|
||||||
height: 24,
|
padding: const EdgeInsets.symmetric(vertical: 4),
|
||||||
placeholderBuilder: (_) =>
|
child: GestureDetector(
|
||||||
const LoadingIndicator(),
|
onTap: () {
|
||||||
)
|
Navigator.of(context).pop(items[index]);
|
||||||
: const SizedBox(
|
},
|
||||||
width: 24,
|
child: RoundedWhiteContainer(
|
||||||
height: 24,
|
child: Row(
|
||||||
),
|
children: [
|
||||||
),
|
SizedBox(
|
||||||
const SizedBox(
|
width: 24,
|
||||||
width: 10,
|
height: 24,
|
||||||
),
|
child: isStackCoin(items[index].ticker)
|
||||||
Expanded(
|
? getIconForTicker(
|
||||||
child: Column(
|
items[index].ticker,
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
size: 24,
|
||||||
children: [
|
)
|
||||||
Text(
|
: hasImageUrl
|
||||||
items[index].name,
|
? SvgPicture.network(
|
||||||
style: STextStyles.largeMedium14(context),
|
items[index].image,
|
||||||
),
|
width: 24,
|
||||||
const SizedBox(
|
height: 24,
|
||||||
height: 2,
|
placeholderBuilder: (_) =>
|
||||||
),
|
const LoadingIndicator(),
|
||||||
Text(
|
)
|
||||||
items[index].ticker.toUpperCase(),
|
: const SizedBox(
|
||||||
style: STextStyles.smallMed12(context)
|
width: 24,
|
||||||
.copyWith(
|
height: 24,
|
||||||
color: Theme.of(context)
|
),
|
||||||
.extension<StackColors>()!
|
|
||||||
.textSubtitle1,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
),
|
||||||
),
|
const SizedBox(
|
||||||
],
|
width: 10,
|
||||||
|
),
|
||||||
|
Expanded(
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment:
|
||||||
|
CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
Text(
|
||||||
|
items[index].name,
|
||||||
|
style:
|
||||||
|
STextStyles.largeMedium14(context),
|
||||||
|
),
|
||||||
|
const SizedBox(
|
||||||
|
height: 2,
|
||||||
|
),
|
||||||
|
Text(
|
||||||
|
items[index].ticker.toUpperCase(),
|
||||||
|
style: STextStyles.smallMed12(context)
|
||||||
|
.copyWith(
|
||||||
|
color: Theme.of(context)
|
||||||
|
.extension<StackColors>()!
|
||||||
|
.textSubtitle1,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
);
|
||||||
);
|
},
|
||||||
},
|
),
|
||||||
),
|
);
|
||||||
);
|
},
|
||||||
}),
|
),
|
||||||
),
|
|
||||||
const SizedBox(
|
|
||||||
height: 20,
|
|
||||||
),
|
|
||||||
Text(
|
|
||||||
"All coins",
|
|
||||||
style: STextStyles.smallMed12(context),
|
|
||||||
),
|
|
||||||
const SizedBox(
|
|
||||||
height: 12,
|
|
||||||
),
|
|
||||||
Flexible(
|
|
||||||
child: Builder(builder: (context) {
|
|
||||||
final filtered = filter(_searchString);
|
|
||||||
filtered.sort((a, b) => a.name.compareTo(b.name));
|
|
||||||
return RoundedWhiteContainer(
|
|
||||||
padding: const EdgeInsets.all(0),
|
|
||||||
child: ListView.builder(
|
|
||||||
shrinkWrap: true,
|
|
||||||
primary: isDesktop ? false : null,
|
|
||||||
itemCount: filtered.length,
|
|
||||||
itemBuilder: (builderContext, index) {
|
|
||||||
final bool hasImageUrl =
|
|
||||||
filtered[index].image.startsWith("http");
|
|
||||||
return Padding(
|
|
||||||
padding: const EdgeInsets.symmetric(vertical: 4),
|
|
||||||
child: GestureDetector(
|
|
||||||
onTap: () {
|
|
||||||
Navigator.of(context).pop(filtered[index]);
|
|
||||||
},
|
|
||||||
child: RoundedWhiteContainer(
|
|
||||||
child: Row(
|
|
||||||
children: [
|
|
||||||
SizedBox(
|
|
||||||
width: 24,
|
|
||||||
height: 24,
|
|
||||||
child: isStackCoin(filtered[index].ticker)
|
|
||||||
? getIconForTicker(
|
|
||||||
filtered[index].ticker,
|
|
||||||
size: 24,
|
|
||||||
)
|
|
||||||
: hasImageUrl
|
|
||||||
? SvgPicture.network(
|
|
||||||
filtered[index].image,
|
|
||||||
width: 24,
|
|
||||||
height: 24,
|
|
||||||
placeholderBuilder: (_) =>
|
|
||||||
const LoadingIndicator(),
|
|
||||||
)
|
|
||||||
: const SizedBox(
|
|
||||||
width: 24,
|
|
||||||
height: 24,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(
|
|
||||||
width: 10,
|
|
||||||
),
|
|
||||||
Expanded(
|
|
||||||
child: Column(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: [
|
|
||||||
Text(
|
|
||||||
filtered[index].name,
|
|
||||||
style: STextStyles.largeMedium14(context),
|
|
||||||
),
|
|
||||||
const SizedBox(
|
|
||||||
height: 2,
|
|
||||||
),
|
|
||||||
Text(
|
|
||||||
filtered[index].ticker.toUpperCase(),
|
|
||||||
style: STextStyles.smallMed12(context)
|
|
||||||
.copyWith(
|
|
||||||
color: Theme.of(context)
|
|
||||||
.extension<StackColors>()!
|
|
||||||
.textSubtitle1,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}),
|
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
|
Loading…
Reference in a new issue