Fix deleting token

Fix renaming tokens
This commit is contained in:
OmarHatem 2023-07-04 04:41:37 +03:00
parent 72a99ab7dd
commit fcabc7aec1
2 changed files with 30 additions and 22 deletions

View file

@ -305,24 +305,24 @@ abstract class EthereumWalletBase
.iconPath;
} catch (_) {}
await erc20TokensBox.put(
token.contractAddress,
Erc20Token(
name: token.name,
symbol: token.symbol,
contractAddress: token.contractAddress,
decimal: token.decimal,
enabled: token.enabled,
iconPath: iconPath,
));
final _token = Erc20Token(
name: token.name,
symbol: token.symbol,
contractAddress: token.contractAddress,
decimal: token.decimal,
enabled: token.enabled,
iconPath: iconPath,
);
if (token.enabled) {
balance[token] = await _client.fetchERC20Balances(
await erc20TokensBox.put(_token.contractAddress, _token);
if (_token.enabled) {
balance[_token] = await _client.fetchERC20Balances(
_privateKey.address,
token.contractAddress,
_token.contractAddress,
);
} else {
balance.remove(token);
balance.remove(_token);
}
}

View file

@ -30,7 +30,10 @@ abstract class HomeSettingsViewModelBase with Store {
SortBalanceBy get sortBalanceBy => _settingsStore.sortBalanceBy;
@action
void setSortBalanceBy(SortBalanceBy value) => _settingsStore.sortBalanceBy = value;
void setSortBalanceBy(SortBalanceBy value) {
_settingsStore.sortBalanceBy = value;
_updateTokensList();
}
@computed
bool get pinNativeToken => _settingsStore.pinNativeTokenAtTop;
@ -40,11 +43,13 @@ abstract class HomeSettingsViewModelBase with Store {
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,17 +75,20 @@ abstract class HomeSettingsViewModelBase with Store {
@action
void _updateTokensList() {
tokens.clear();
int _sortFunc(e1, e2) {
int index1 = _balanceViewModel.formattedBalances.indexWhere((element) => element.asset == e1);
int index2 = _balanceViewModel.formattedBalances.indexWhere((element) => element.asset == e2);
_balanceViewModel.formattedBalances.forEach((e) {
if (e.asset is Erc20Token && _matchesSearchText(e.asset as Erc20Token)) {
tokens.add(e.asset as Erc20Token);
}
});
return index1.compareTo(index2);
}
tokens.clear();
tokens.addAll(ethereum!
.getERC20Currencies(_balanceViewModel.wallet)
.where((element) => _matchesSearchText(element)));
.where((element) => _matchesSearchText(element))
.toList()
..sort(_sortFunc));
}
@action