code formatting

This commit is contained in:
Serhii 2023-03-27 10:27:54 +03:00
parent 5a95fd4ab5
commit 05e7cb3a10
4 changed files with 53 additions and 71 deletions

View file

@ -25,21 +25,18 @@ class ElectrumBalance extends Balance {
final int frozen; final int frozen;
@override @override
String get formattedAvailableBalance => String get formattedAvailableBalance => bitcoinAmountToString(amount: confirmed);
bitcoinAmountToString(amount: confirmed);
@override @override
String get formattedAdditionalBalance => String get formattedAdditionalBalance => bitcoinAmountToString(amount: unconfirmed);
bitcoinAmountToString(amount: unconfirmed);
String get formattedFrozenBalance { String get formattedFrozenBalance {
final frozenFormatted = bitcoinAmountToString(amount: frozen); final frozenFormatted = bitcoinAmountToString(amount: frozen);
return frozenFormatted == '0.0' ? '' : frozenFormatted; return frozenFormatted == '0.0' ? '' : frozenFormatted;
} }
@override @override
String get formattedTotalAvailableBalance => String get formattedTotalAvailableBalance => bitcoinAmountToString(amount: confirmed - frozen);
bitcoinAmountToString(amount: confirmed - frozen);
String toJSON() => String toJSON() =>
json.encode({'confirmed': confirmed, 'unconfirmed': unconfirmed, 'frozen': frozen}); json.encode({'confirmed': confirmed, 'unconfirmed': unconfirmed, 'frozen': frozen});

View file

@ -33,15 +33,12 @@ class UnspentCoinsDetailsPage extends BasePage {
final item = unspentCoinsDetailsViewModel.items[index]; final item = unspentCoinsDetailsViewModel.items[index];
if (item is StandartListItem) { if (item is StandartListItem) {
return GestureDetector( return GestureDetector(
onTap: () { onTap: () {
Clipboard.setData(ClipboardData(text: item.value)); Clipboard.setData(ClipboardData(text: item.value));
showBar<void>(context, showBar<void>(context, S.of(context).transaction_details_copied(item.title));
S.of(context).transaction_details_copied(item.title));
}, },
child: child: ListRow(title: '${item.title}:', value: item.value),
ListRow(title: '${item.title}:', value: item.value),
); );
} }
@ -54,18 +51,17 @@ class UnspentCoinsDetailsPage extends BasePage {
} }
if (item is UnspentCoinsSwitchItem) { if (item is UnspentCoinsSwitchItem) {
return Observer(builder: (_) => UnspentCoinsSwitchRow( return Observer(
title: item.title, builder: (_) => UnspentCoinsSwitchRow(
switchValue: item.switchValue(), title: item.title,
onSwitchValueChange: item.onSwitchValueChange switchValue: item.switchValue(),
)); onSwitchValueChange: item.onSwitchValueChange));
} }
if (item is BlockExplorerListItem) { if (item is BlockExplorerListItem) {
return GestureDetector( return GestureDetector(
onTap: item.onTap, onTap: item.onTap,
child: child: ListRow(title: '${item.title}:', value: item.value),
ListRow(title: '${item.title}:', value: item.value),
); );
} }

View file

@ -16,21 +16,14 @@ class UnspentCoinsDetailsViewModel = UnspentCoinsDetailsViewModelBase
with _$UnspentCoinsDetailsViewModel; with _$UnspentCoinsDetailsViewModel;
abstract class UnspentCoinsDetailsViewModelBase with Store { abstract class UnspentCoinsDetailsViewModelBase with Store {
UnspentCoinsDetailsViewModelBase({ UnspentCoinsDetailsViewModelBase(
required this.unspentCoinsItem, {required this.unspentCoinsItem, required this.unspentCoinsListViewModel})
required this.unspentCoinsListViewModel})
: items = <TransactionDetailsListItem>[], : items = <TransactionDetailsListItem>[],
isFrozen = unspentCoinsItem.isFrozen, isFrozen = unspentCoinsItem.isFrozen,
note = unspentCoinsItem.note { note = unspentCoinsItem.note {
items = [ items = [
StandartListItem( StandartListItem(title: S.current.transaction_details_amount, value: unspentCoinsItem.amount),
title: S.current.transaction_details_amount, StandartListItem(title: S.current.widgets_address, value: unspentCoinsItem.address),
value: unspentCoinsItem.amount
),
StandartListItem(
title: S.current.widgets_address,
value: unspentCoinsItem.address
),
TextFieldListItem( TextFieldListItem(
title: S.current.note_tap_to_change, title: S.current.note_tap_to_change,
value: note, value: note,
@ -39,27 +32,25 @@ abstract class UnspentCoinsDetailsViewModelBase with Store {
unspentCoinsListViewModel.saveUnspentCoinInfo(unspentCoinsItem); unspentCoinsListViewModel.saveUnspentCoinInfo(unspentCoinsItem);
}), }),
UnspentCoinsSwitchItem( UnspentCoinsSwitchItem(
title: S.current.freeze, title: S.current.freeze,
value: '', value: '',
switchValue: () => isFrozen, switchValue: () => isFrozen,
onSwitchValueChange: (value) async { onSwitchValueChange: (value) async {
isFrozen = value; isFrozen = value;
unspentCoinsItem.isFrozen = value; unspentCoinsItem.isFrozen = value;
if (value) { if (value) {
unspentCoinsItem.isSending = !value; unspentCoinsItem.isSending = !value;
} }
await unspentCoinsListViewModel.saveUnspentCoinInfo(unspentCoinsItem); await unspentCoinsListViewModel.saveUnspentCoinInfo(unspentCoinsItem);
} }),
),
BlockExplorerListItem( BlockExplorerListItem(
title: S.current.view_in_block_explorer, title: S.current.view_in_block_explorer,
value: _explorerDescription(unspentCoinsListViewModel.wallet.type), value: _explorerDescription(unspentCoinsListViewModel.wallet.type),
onTap: () { onTap: () {
final url = Uri.parse(_explorerUrl(unspentCoinsListViewModel.wallet.type, final url = Uri.parse(
unspentCoinsItem.hash)); _explorerUrl(unspentCoinsListViewModel.wallet.type, unspentCoinsItem.hash));
return launchUrl(url); return launchUrl(url);
} })
)
]; ];
} }

View file

@ -13,10 +13,9 @@ part 'unspent_coins_list_view_model.g.dart';
class UnspentCoinsListViewModel = UnspentCoinsListViewModelBase with _$UnspentCoinsListViewModel; class UnspentCoinsListViewModel = UnspentCoinsListViewModelBase with _$UnspentCoinsListViewModel;
abstract class UnspentCoinsListViewModelBase with Store { abstract class UnspentCoinsListViewModelBase with Store {
UnspentCoinsListViewModelBase({ UnspentCoinsListViewModelBase(
required this.wallet, {required this.wallet, required Box<UnspentCoinsInfo> unspentCoinsInfo})
required Box<UnspentCoinsInfo> unspentCoinsInfo}) : _unspentCoinsInfo = unspentCoinsInfo {
: _unspentCoinsInfo = unspentCoinsInfo {
bitcoin!.updateUnspents(wallet); bitcoin!.updateUnspents(wallet);
} }
@ -24,28 +23,27 @@ abstract class UnspentCoinsListViewModelBase with Store {
final Box<UnspentCoinsInfo> _unspentCoinsInfo; final Box<UnspentCoinsInfo> _unspentCoinsInfo;
@computed @computed
ObservableList<UnspentCoinsItem> get items => ObservableList.of(bitcoin!.getUnspents(wallet).map((elem) { ObservableList<UnspentCoinsItem> get items =>
final amount = bitcoin!.formatterBitcoinAmountToString(amount: elem.value) + ObservableList.of(bitcoin!.getUnspents(wallet).map((elem) {
' ${wallet.currency.title}'; final amount = bitcoin!.formatterBitcoinAmountToString(amount: elem.value) +
' ${wallet.currency.title}';
final info = _unspentCoinsInfo.values final info = _unspentCoinsInfo.values
.firstWhere((element) => element.walletId == wallet.id && element.hash == elem.hash); .firstWhere((element) => element.walletId == wallet.id && element.hash == elem.hash);
return UnspentCoinsItem( return UnspentCoinsItem(
address: elem.address, address: elem.address,
amount: amount, amount: amount,
hash: elem.hash, hash: elem.hash,
isFrozen: info.isFrozen, isFrozen: info.isFrozen,
note: info.note, note: info.note,
isSending: info.isSending isSending: info.isSending);
); }));
}));
Future<void> saveUnspentCoinInfo(UnspentCoinsItem item) async { Future<void> saveUnspentCoinInfo(UnspentCoinsItem item) async {
try { try {
final info = _unspentCoinsInfo.values final info = _unspentCoinsInfo.values.firstWhere(
.firstWhere((element) => element.walletId.contains(wallet.id) && (element) => element.walletId.contains(wallet.id) && element.hash.contains(item.hash));
element.hash.contains(item.hash));
info.isFrozen = item.isFrozen; info.isFrozen = item.isFrozen;
info.isSending = item.isSending; info.isSending = item.isSending;