mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-01-23 11:15:33 +00:00
Fix Accounts Popup UI
This commit is contained in:
parent
474abe15a7
commit
5905ac35d8
6 changed files with 37 additions and 34 deletions
|
@ -13,7 +13,7 @@ class Erc20Token extends CryptoCurrency with HiveObjectMixin {
|
|||
final String contractAddress;
|
||||
@HiveField(3)
|
||||
final int decimal;
|
||||
@HiveField(4, defaultValue: false)
|
||||
@HiveField(4, defaultValue: true)
|
||||
bool _enabled;
|
||||
@HiveField(5)
|
||||
final String? iconPath;
|
||||
|
@ -30,7 +30,7 @@ class Erc20Token extends CryptoCurrency with HiveObjectMixin {
|
|||
required this.symbol,
|
||||
required this.contractAddress,
|
||||
required this.decimal,
|
||||
bool enabled = false,
|
||||
bool enabled = true,
|
||||
this.iconPath,
|
||||
}) : _enabled = enabled,
|
||||
super(
|
||||
|
|
|
@ -310,7 +310,7 @@ abstract class EthereumWalletBase
|
|||
symbol: token.symbol,
|
||||
contractAddress: token.contractAddress,
|
||||
decimal: token.decimal,
|
||||
enabled: true,
|
||||
enabled: token.enabled,
|
||||
iconPath: iconPath,
|
||||
));
|
||||
|
||||
|
|
|
@ -31,6 +31,7 @@ class EditTokenPage extends BasePage {
|
|||
return EditTokenPageBody(
|
||||
homeSettingsViewModel: homeSettingsViewModel,
|
||||
erc20token: erc20token,
|
||||
initialContractAddress: initialContractAddress,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -70,6 +70,7 @@ class HomeSettingsPage extends BasePage {
|
|||
borderSide: const BorderSide(color: Colors.transparent),
|
||||
),
|
||||
),
|
||||
onChanged: (String text) => _homeSettingsViewModel.changeSearchText(text),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
@ -104,7 +105,7 @@ class HomeSettingsPage extends BasePage {
|
|||
margin: EdgeInsets.only(top: 16, left: 16, right: 16),
|
||||
child: Observer(
|
||||
builder: (_) {
|
||||
final token = _homeSettingsViewModel.tokens[index];
|
||||
final token = _homeSettingsViewModel.tokens.elementAt(index);
|
||||
|
||||
return SettingsSwitcherCell(
|
||||
title: "${token.name} "
|
||||
|
|
|
@ -308,8 +308,12 @@ abstract class BalanceViewModelBase with Store {
|
|||
|
||||
switch (sortBalanceBy) {
|
||||
case SortBalanceBy.FiatBalance:
|
||||
return double.parse(b.fiatAvailableBalance)
|
||||
.compareTo(double.parse(a.fiatAvailableBalance));
|
||||
return double.parse(_getFiatBalance(
|
||||
price: fiatConvertationStore.prices[b.asset]!,
|
||||
cryptoAmount: b.availableBalance))
|
||||
.compareTo(double.parse(_getFiatBalance(
|
||||
price: fiatConvertationStore.prices[a.asset]!,
|
||||
cryptoAmount: a.availableBalance)));
|
||||
case SortBalanceBy.GrossBalance:
|
||||
return double.parse(b.availableBalance)
|
||||
.compareTo(double.parse(a.availableBalance));
|
||||
|
|
|
@ -13,24 +13,19 @@ part 'home_settings_view_model.g.dart';
|
|||
class HomeSettingsViewModel = HomeSettingsViewModelBase with _$HomeSettingsViewModel;
|
||||
|
||||
abstract class HomeSettingsViewModelBase with Store {
|
||||
HomeSettingsViewModelBase(this._settingsStore, this._balanceViewModel)
|
||||
: tokens = ObservableList<Erc20Token>() {
|
||||
_updateTokensList();
|
||||
}
|
||||
HomeSettingsViewModelBase(this._settingsStore, this._balanceViewModel);
|
||||
|
||||
final SettingsStore _settingsStore;
|
||||
final BalanceViewModel _balanceViewModel;
|
||||
|
||||
final ObservableList<Erc20Token> tokens;
|
||||
@observable
|
||||
String searchText = '';
|
||||
|
||||
@computed
|
||||
SortBalanceBy get sortBalanceBy => _settingsStore.sortBalanceBy;
|
||||
|
||||
@action
|
||||
void setSortBalanceBy(SortBalanceBy value) {
|
||||
_settingsStore.sortBalanceBy = value;
|
||||
_sortTokens();
|
||||
}
|
||||
void setSortBalanceBy(SortBalanceBy value) => _settingsStore.sortBalanceBy = value;
|
||||
|
||||
@computed
|
||||
bool get pinNativeToken => _settingsStore.pinNativeTokenAtTop;
|
||||
|
@ -38,20 +33,13 @@ abstract class HomeSettingsViewModelBase with Store {
|
|||
@action
|
||||
void setPinNativeToken(bool value) => _settingsStore.pinNativeTokenAtTop = value;
|
||||
|
||||
@action
|
||||
void _updateTokensList() {
|
||||
_sortTokens();
|
||||
}
|
||||
|
||||
Future<void> addErc20Token(Erc20Token token) async {
|
||||
await ethereum!.addErc20Token(_balanceViewModel.wallet, token);
|
||||
_updateTokensList();
|
||||
_updateFiatPrices(token);
|
||||
}
|
||||
|
||||
Future<void> deleteErc20Token(Erc20Token token) async {
|
||||
await ethereum!.deleteErc20Token(_balanceViewModel.wallet, token);
|
||||
_updateTokensList();
|
||||
}
|
||||
|
||||
Future<Erc20Token?> getErc20Token(String contractAddress) async =>
|
||||
|
@ -70,25 +58,34 @@ abstract class HomeSettingsViewModelBase with Store {
|
|||
}
|
||||
|
||||
void changeTokenAvailability(int index, bool value) async {
|
||||
tokens[index].enabled = value;
|
||||
tokens.elementAt(index).enabled = value;
|
||||
_balanceViewModel.wallet.updateBalance();
|
||||
_updateTokensList();
|
||||
}
|
||||
|
||||
void _sortTokens() {
|
||||
tokens.clear();
|
||||
@computed
|
||||
Set<Erc20Token> get tokens {
|
||||
final Set<Erc20Token> tokens = {};
|
||||
|
||||
// Add Sorted Enabled tokens
|
||||
for (int i = 0; i < _balanceViewModel.balances.keys.length; i++) {
|
||||
final CryptoCurrency currency = _balanceViewModel.balances.keys.elementAt(i);
|
||||
if (currency is Erc20Token) {
|
||||
tokens.add(currency);
|
||||
_balanceViewModel.formattedBalances.forEach((e) {
|
||||
if (e.asset is Erc20Token && _matchesSearchText(e.asset as Erc20Token)) {
|
||||
tokens.add(e.asset as Erc20Token);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Add disabled tokens
|
||||
tokens.addAll(ethereum!
|
||||
.getERC20Currencies(_balanceViewModel.wallet)
|
||||
.where((element) => !element.enabled));
|
||||
.where((element) => _matchesSearchText(element)));
|
||||
|
||||
return tokens;
|
||||
}
|
||||
|
||||
@action
|
||||
void changeSearchText(String text) => searchText = text;
|
||||
|
||||
bool _matchesSearchText(Erc20Token asset) {
|
||||
return searchText.isEmpty ||
|
||||
asset.fullName!.toLowerCase().contains(searchText.toLowerCase()) ||
|
||||
asset.title.toLowerCase().contains(searchText.toLowerCase()) ||
|
||||
asset.contractAddress == searchText;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue