mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-03-11 17:06:34 +00:00
Add Sorting and Pin Native Token features
This commit is contained in:
parent
38bb1327e3
commit
46c64c782e
3 changed files with 50 additions and 4 deletions
|
@ -2,8 +2,6 @@
|
||||||
uri: ethereum.publicnode.com
|
uri: ethereum.publicnode.com
|
||||||
-
|
-
|
||||||
uri: eth.llamarpc.com
|
uri: eth.llamarpc.com
|
||||||
-
|
|
||||||
uri: rpc.ankr.com/eth
|
|
||||||
-
|
-
|
||||||
uri: rpc.flashbots.net
|
uri: rpc.flashbots.net
|
||||||
-
|
-
|
||||||
|
|
|
@ -161,7 +161,7 @@ class Node extends HiveObject with Keyable {
|
||||||
} catch (_) {
|
} catch (_) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<bool> requestElectrumServer() async {
|
Future<bool> requestElectrumServer() async {
|
||||||
try {
|
try {
|
||||||
|
@ -172,4 +172,17 @@ class Node extends HiveObject with Keyable {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<bool> requestEthereumServer() async {
|
||||||
|
try {
|
||||||
|
final response = await http.get(
|
||||||
|
uri,
|
||||||
|
headers: {'Content-Type': 'application/json'},
|
||||||
|
);
|
||||||
|
|
||||||
|
return response.statusCode >= 200 && response.statusCode < 300;
|
||||||
|
} catch (_) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import 'package:cake_wallet/entities/fiat_api_mode.dart';
|
import 'package:cake_wallet/entities/fiat_api_mode.dart';
|
||||||
|
import 'package:cake_wallet/entities/sort_balance_types.dart';
|
||||||
import 'package:cw_core/transaction_history.dart';
|
import 'package:cw_core/transaction_history.dart';
|
||||||
import 'package:cw_core/wallet_base.dart';
|
import 'package:cw_core/wallet_base.dart';
|
||||||
import 'package:cw_core/balance.dart';
|
import 'package:cw_core/balance.dart';
|
||||||
|
@ -81,6 +82,12 @@ abstract class BalanceViewModelBase with Store {
|
||||||
@computed
|
@computed
|
||||||
bool get isHomeScreenSettingsEnabled => wallet.type == WalletType.ethereum;
|
bool get isHomeScreenSettingsEnabled => wallet.type == WalletType.ethereum;
|
||||||
|
|
||||||
|
@computed
|
||||||
|
SortBalanceBy get sortBalanceBy => settingsStore.sortBalanceBy;
|
||||||
|
|
||||||
|
@computed
|
||||||
|
bool get pinNativeToken => settingsStore.pinNativeTokenAtTop;
|
||||||
|
|
||||||
@computed
|
@computed
|
||||||
String get asset {
|
String get asset {
|
||||||
final typeFormatted = walletTypeToString(appStore.wallet!.type);
|
final typeFormatted = walletTypeToString(appStore.wallet!.type);
|
||||||
|
@ -213,7 +220,7 @@ abstract class BalanceViewModelBase with Store {
|
||||||
|
|
||||||
@computed
|
@computed
|
||||||
Map<CryptoCurrency, BalanceRecord> get balances {
|
Map<CryptoCurrency, BalanceRecord> get balances {
|
||||||
return wallet.balance.map((key, value) {
|
return _sortedBalance.map((key, value) {
|
||||||
if (displayMode == BalanceDisplayMode.hiddenBalance) {
|
if (displayMode == BalanceDisplayMode.hiddenBalance) {
|
||||||
return MapEntry(key, BalanceRecord(
|
return MapEntry(key, BalanceRecord(
|
||||||
availableBalance: '---',
|
availableBalance: '---',
|
||||||
|
@ -362,5 +369,33 @@ abstract class BalanceViewModelBase with Store {
|
||||||
}
|
}
|
||||||
|
|
||||||
String getFormattedFrozenBalance(Balance walletBalance) => walletBalance.formattedFrozenBalance;
|
String getFormattedFrozenBalance(Balance walletBalance) => walletBalance.formattedFrozenBalance;
|
||||||
|
|
||||||
|
@computed
|
||||||
|
Map<CryptoCurrency, Balance> get _sortedBalance {
|
||||||
|
final Map<CryptoCurrency, Balance> sortedMap = {};
|
||||||
|
if (pinNativeToken) {
|
||||||
|
sortedMap[wallet.currency] = wallet.balance[wallet.currency]!;
|
||||||
|
}
|
||||||
|
switch (sortBalanceBy) {
|
||||||
|
case SortBalanceBy.FiatBalance:
|
||||||
|
sortedMap.addAll(Map.fromEntries(wallet.balance.entries.toList()
|
||||||
|
..sort((e1, e2) => double.parse(
|
||||||
|
_getFiatBalance(price: price, cryptoAmount: e2.value.formattedAvailableBalance))
|
||||||
|
.compareTo(double.parse(_getFiatBalance(
|
||||||
|
price: price, cryptoAmount: e1.value.formattedAvailableBalance))))));
|
||||||
|
break;
|
||||||
|
case SortBalanceBy.GrossBalance:
|
||||||
|
sortedMap.addAll(Map.fromEntries(wallet.balance.entries.toList()
|
||||||
|
..sort((e1, e2) => double.parse(e2.value.formattedAvailableBalance)
|
||||||
|
.compareTo(double.parse(e1.value.formattedAvailableBalance)))));
|
||||||
|
break;
|
||||||
|
case SortBalanceBy.Alphabetical:
|
||||||
|
sortedMap.addAll(Map.fromEntries(wallet.balance.entries.toList()
|
||||||
|
..sort((e1, e2) => e1.key.title.compareTo(e2.key.title))));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return sortedMap;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue