2023-06-21 00:46:58 +00:00
|
|
|
import 'package:cake_wallet/entities/sort_balance_types.dart';
|
2023-06-22 21:17:54 +00:00
|
|
|
import 'package:cake_wallet/ethereum/ethereum.dart';
|
2023-06-21 00:46:58 +00:00
|
|
|
import 'package:cake_wallet/store/settings_store.dart';
|
|
|
|
import 'package:cake_wallet/view_model/dashboard/balance_view_model.dart';
|
2023-06-22 21:17:54 +00:00
|
|
|
import 'package:cw_core/crypto_currency.dart';
|
|
|
|
import 'package:cw_core/erc20_token.dart';
|
2023-06-21 00:46:58 +00:00
|
|
|
import 'package:mobx/mobx.dart';
|
|
|
|
|
|
|
|
part 'home_settings_view_model.g.dart';
|
|
|
|
|
|
|
|
class HomeSettingsViewModel = HomeSettingsViewModelBase with _$HomeSettingsViewModel;
|
|
|
|
|
|
|
|
abstract class HomeSettingsViewModelBase with Store {
|
2023-06-22 21:17:54 +00:00
|
|
|
HomeSettingsViewModelBase(this._settingsStore, this._balanceViewModel);
|
2023-06-21 00:46:58 +00:00
|
|
|
|
|
|
|
final SettingsStore _settingsStore;
|
|
|
|
final BalanceViewModel _balanceViewModel;
|
|
|
|
|
|
|
|
@computed
|
|
|
|
SortBalanceBy get sortBalanceBy => _settingsStore.sortBalanceBy;
|
|
|
|
|
|
|
|
@action
|
|
|
|
void setSortBalanceBy(SortBalanceBy value) => _settingsStore.sortBalanceBy = value;
|
|
|
|
|
2023-06-22 21:17:54 +00:00
|
|
|
@computed
|
|
|
|
bool get pinNativeToken => _settingsStore.pinNativeTokenAtTop;
|
|
|
|
|
|
|
|
@action
|
|
|
|
void setPinNativeToken(bool value) => _settingsStore.pinNativeTokenAtTop = value;
|
2023-06-21 00:46:58 +00:00
|
|
|
|
2023-06-22 21:17:54 +00:00
|
|
|
@computed
|
2023-06-21 00:46:58 +00:00
|
|
|
List<String> get tokens =>
|
|
|
|
_balanceViewModel.balances.keys.map((e) => e.fullName ?? e.title).toList();
|
2023-06-22 21:17:54 +00:00
|
|
|
|
|
|
|
Future<CryptoCurrency?> addErc20Token(String contractAddress) async =>
|
|
|
|
await ethereum!.addErc20Token(_balanceViewModel.wallet, contractAddress);
|
|
|
|
|
|
|
|
Future<Erc20Token?> getErc20Token(String contractAddress) async =>
|
|
|
|
await ethereum!.getErc20Token(_balanceViewModel.wallet, contractAddress);
|
|
|
|
|
|
|
|
String get nativeToken => _balanceViewModel.wallet.currency.title;
|
2023-06-21 00:46:58 +00:00
|
|
|
}
|