mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2024-12-23 12:09:43 +00:00
0d7fad3610
* V4.8.1 v1.5.1 (#1038) * Revert "Cw 397 chatwoot live support (#1011)" This reverts commitaf9b5ff10c
. * Add Version 4.8.1 configs * Update macos build version [skip ci] * Re add chatwoot (#1044) * Revert "Revert "Cw 397 chatwoot live support (#1011)"" This reverts commitecdc7baa2e
. * Re-add chatwoot Change chatwoot base url * Cw 396 additional themes (#962) * fix: SectionStandardList using BuildContext as param * refactor: deprecated backgroundColor -> colorScheme.background * refactor: themeBase and current themes * refactor: accentTextTheme.titleLarge.color -> dialogTheme.backgroundColor * refactor: gradient background * refactor: text themes using the same color as primaryColor * refactor: accentTextTheme.bodySmall.color -> cardColor * refactor: text themes using same dialogBackgroundColor * refactor: scrollbarTheme * refactor: create SyncIndicatorTheme * refactor: SectionDivider * refactor: base_page improvements and simplify * refactor: collapsible_standart_list improvements * refactor: accentTextTheme.bodyLarge.backgroundColor -> KeyboardTheme.keyboardBarColor * refactor: create PinCodeTheme for accentTextTheme.bodyMedium * refactor: create SupportPageTheme for accentTextTheme.displayLarge.backgroundColor and fix cases that use it * refactor: accentTextTheme.displayLarge.color -> disabledColor * refactor: create ExchangePageTheme * refactor: create DashboardPageTheme and use textColor * refactor: create NewWalletTheme for accentTextTheme.displayMedium * refactor: create BalancePageTheme for accentTextTheme.displaySmall.backgroundColor * refactor: create AddressTheme for accentTextTheme.displaySmall.color * refactor: create IndicatorDotTheme * refactor: create CakeMenuTheme * refactor: create FilterTheme * refactor: create WalletListTheme * refactor: accentTextTheme.bodySmall.decorationColor -> InfoTheme.textColor * refactor: accentTextTheme.titleLarge.backgroundColor -> PickerTheme.dividerColor * refactor: primaryTextTheme.bodyLarge.backgroundColor -> AlertTheme.leftButtonTextColor * refactor: primaryTextTheme.displayLarge.backgroundColor -> OrderTheme.iconColor * refactor: create SendPageTheme * fix: missing migrated styles * refactor: primaryTextTheme.labelSmall.decorationColor -> PlaceholderTheme.color * refactor: create TransactionTradeTheme * refactor: create CakeTextTheme * refactor: create AccountListTheme * refactor: create ReceivePageTheme * refactor: create QRCodeTheme * refactor: move remaining items to CakeTextTheme and some missing fixes * feat(display_settings): add new theme selector * feat: additional themes * fix: conflict error * fix(lag): move colorScheme initialization to constructor * feat: add backdropColor to alert and picker backdrop filters * fix: merge fixes * fix: send template page missing new colors * fix: anonpay pages title and icon colors * fix: merge fixes * fix: unspent coins page * fix: also fix exchange template * fix: missing checkbox * fix: fixes for high contrast theme * Merge branch 'main' into CW-396-additional-themes * fix: merge fixes * fix: .gitignore and rm added files * Fix review comments --------- Co-authored-by: OmarHatem <omarh.ismail1@gmail.com> * Flutter update (#1048) * Update Flutter Update packages * Fix localization issues Fix UI issues Update old packages Update workflow Update how to build guide * Additional UI fixes for merged conflicts * Fix Ethereum network for anonpay invoice (#1051) * build: migrate from wakelock to wakelock_plus - plus is compatible with package_info_plus ^4.0.0 - plus has implemented Linux support * fix: theme & support view model merge fixes --------- Co-authored-by: Omar Hatem <omarh.ismail1@gmail.com>
151 lines
4.6 KiB
Dart
151 lines
4.6 KiB
Dart
import 'package:flutter/services.dart';
|
|
import 'package:mobx/mobx.dart';
|
|
import 'package:cw_monero/api/coins_info.dart';
|
|
import 'package:cw_monero/api/subaddress_list.dart' as subaddress_list;
|
|
import 'package:cw_core/subaddress.dart';
|
|
|
|
part 'monero_subaddress_list.g.dart';
|
|
|
|
class MoneroSubaddressList = MoneroSubaddressListBase with _$MoneroSubaddressList;
|
|
|
|
abstract class MoneroSubaddressListBase with Store {
|
|
MoneroSubaddressListBase()
|
|
: _isRefreshing = false,
|
|
_isUpdating = false,
|
|
subaddresses = ObservableList<Subaddress>();
|
|
|
|
final List<String> _usedAddresses = [];
|
|
|
|
@observable
|
|
ObservableList<Subaddress> subaddresses;
|
|
|
|
bool _isRefreshing;
|
|
bool _isUpdating;
|
|
|
|
void update({required int accountIndex}) {
|
|
// refreshCoins(accountIndex);
|
|
|
|
if (_isUpdating) {
|
|
return;
|
|
}
|
|
|
|
try {
|
|
_isUpdating = true;
|
|
refresh(accountIndex: accountIndex);
|
|
subaddresses.clear();
|
|
subaddresses.addAll(getAll());
|
|
_isUpdating = false;
|
|
} catch (e) {
|
|
_isUpdating = false;
|
|
rethrow;
|
|
}
|
|
}
|
|
|
|
List<Subaddress> getAll() {
|
|
var subaddresses = subaddress_list.getAllSubaddresses();
|
|
|
|
if (subaddresses.length > 2) {
|
|
final primary = subaddresses.first;
|
|
final rest = subaddresses.sublist(1).reversed;
|
|
subaddresses = [primary] + rest.toList();
|
|
}
|
|
|
|
return subaddresses.map((subaddressRow) {
|
|
final hasDefaultAddressName =
|
|
subaddressRow.getLabel().toLowerCase() == 'Primary account'.toLowerCase() ||
|
|
subaddressRow.getLabel().toLowerCase() == 'Untitled account'.toLowerCase();
|
|
final isPrimaryAddress = subaddressRow.getId() == 0 && hasDefaultAddressName;
|
|
return Subaddress(
|
|
id: subaddressRow.getId(),
|
|
address: subaddressRow.getAddress(),
|
|
label: isPrimaryAddress
|
|
? 'Primary address'
|
|
: hasDefaultAddressName
|
|
? ''
|
|
: subaddressRow.getLabel());
|
|
}).toList();
|
|
}
|
|
|
|
Future<void> addSubaddress({required int accountIndex, required String label}) async {
|
|
await subaddress_list.addSubaddress(accountIndex: accountIndex, label: label);
|
|
update(accountIndex: accountIndex);
|
|
}
|
|
|
|
Future<void> setLabelSubaddress(
|
|
{required int accountIndex, required int addressIndex, required String label}) async {
|
|
await subaddress_list.setLabelForSubaddress(
|
|
accountIndex: accountIndex, addressIndex: addressIndex, label: label);
|
|
update(accountIndex: accountIndex);
|
|
}
|
|
|
|
void refresh({required int accountIndex}) {
|
|
if (_isRefreshing) {
|
|
return;
|
|
}
|
|
|
|
try {
|
|
_isRefreshing = true;
|
|
subaddress_list.refreshSubaddresses(accountIndex: accountIndex);
|
|
_isRefreshing = false;
|
|
} on PlatformException catch (e) {
|
|
_isRefreshing = false;
|
|
print(e);
|
|
rethrow;
|
|
}
|
|
}
|
|
|
|
Future<void> updateWithAutoGenerate({
|
|
required int accountIndex,
|
|
required String defaultLabel,
|
|
required List<String> usedAddresses,
|
|
}) async {
|
|
_usedAddresses.addAll(usedAddresses);
|
|
if (_isUpdating) {
|
|
return;
|
|
}
|
|
|
|
try {
|
|
_isUpdating = true;
|
|
refresh(accountIndex: accountIndex);
|
|
subaddresses.clear();
|
|
final newSubAddresses =
|
|
await _getAllUnusedAddresses(accountIndex: accountIndex, label: defaultLabel);
|
|
subaddresses.addAll(newSubAddresses);
|
|
} catch (e) {
|
|
rethrow;
|
|
} finally {
|
|
_isUpdating = false;
|
|
}
|
|
}
|
|
|
|
Future<List<Subaddress>> _getAllUnusedAddresses(
|
|
{required int accountIndex, required String label}) async {
|
|
final allAddresses = subaddress_list.getAllSubaddresses();
|
|
|
|
if (allAddresses.isEmpty || _usedAddresses.contains(allAddresses.last.getAddress())) {
|
|
final isAddressUnused = await _newSubaddress(accountIndex: accountIndex, label: label);
|
|
if (!isAddressUnused) {
|
|
return await _getAllUnusedAddresses(accountIndex: accountIndex, label: label);
|
|
}
|
|
}
|
|
|
|
return allAddresses
|
|
.map((subaddressRow) => Subaddress(
|
|
id: subaddressRow.getId(),
|
|
address: subaddressRow.getAddress(),
|
|
label: subaddressRow.getId() == 0 &&
|
|
subaddressRow.getLabel().toLowerCase() == 'Primary account'.toLowerCase()
|
|
? 'Primary address'
|
|
: subaddressRow.getLabel()))
|
|
.toList();
|
|
}
|
|
|
|
Future<bool> _newSubaddress({required int accountIndex, required String label}) async {
|
|
await subaddress_list.addSubaddress(accountIndex: accountIndex, label: label);
|
|
|
|
return subaddress_list
|
|
.getAllSubaddresses()
|
|
.where((subaddressRow) => !_usedAddresses.contains(subaddressRow.getAddress()))
|
|
.isNotEmpty;
|
|
}
|
|
}
|