Testing the sync before transaction flow WIP

This commit is contained in:
Blazebrain 2023-06-17 05:57:44 +01:00
parent 2ec8ef0805
commit 3d3bdf3de5
4 changed files with 55 additions and 29 deletions

View file

@ -1,3 +1,5 @@
import 'dart:async';
abstract class SyncStatus {
const SyncStatus();
double progress();
@ -51,4 +53,6 @@ class ConnectedSyncStatus extends SyncStatus {
class LostConnectionSyncStatus extends SyncStatus {
@override
double progress() => 1.0;
}
}
Completer<void> syncCompleter = Completer();

View file

@ -380,9 +380,11 @@ abstract class MoneroWalletBase extends WalletBase<MoneroBalance,
void _askForUpdateBalance() {
final unlockedBalance = _getUnlockedBalance();
final fullBalance = _getFullBalance();
print('Unlocked Balance: $unlockedBalance');
print('Full Balance: $fullBalance');
if (balance[currency]!.fullBalance != fullBalance ||
balance[currency]!.unlockedBalance != unlockedBalance) {
print('Currency Balance: ${balance[currency]}');
balance[currency] = MoneroBalance(
fullBalance: fullBalance, unlockedBalance: unlockedBalance);
}
@ -398,6 +400,12 @@ abstract class MoneroWalletBase extends WalletBase<MoneroBalance,
accountIndex: walletAddresses.account!.id);
void _onNewBlock(int height, int blocksLeft, double ptc) async {
print('----------------');
print('Blocks left: $blocksLeft');
print('height $height');
print('ptc: $ptc');
print('----------------');
_askForUpdateBalance();
try {
if (walletInfo.isRecovery) {
await _askForUpdateTransactionHistory();
@ -410,7 +418,8 @@ abstract class MoneroWalletBase extends WalletBase<MoneroBalance,
_askForUpdateBalance();
walletAddresses.accountList.update();
syncStatus = SyncedSyncStatus();
//! Introduce completer
syncCompleter.complete();
if (!_hasSyncAfterStartup) {
_hasSyncAfterStartup = true;
await save();

View file

@ -52,7 +52,8 @@ Future<void> main() async {
/// A callback that is invoked when an unhandled error occurs in the root
/// isolate.
PlatformDispatcher.instance.onError = (error, stack) {
ExceptionHandler.onError(FlutterErrorDetails(exception: error, stack: stack));
ExceptionHandler.onError(
FlutterErrorDetails(exception: error, stack: stack));
return true;
};
@ -106,25 +107,32 @@ Future<void> main() async {
}
final secureStorage = FlutterSecureStorage();
final transactionDescriptionsBoxKey =
await getEncryptionKey(secureStorage: secureStorage, forKey: TransactionDescription.boxKey);
final tradesBoxKey = await getEncryptionKey(secureStorage: secureStorage, forKey: Trade.boxKey);
final ordersBoxKey = await getEncryptionKey(secureStorage: secureStorage, forKey: Order.boxKey);
final transactionDescriptionsBoxKey = await getEncryptionKey(
secureStorage: secureStorage, forKey: TransactionDescription.boxKey);
final tradesBoxKey = await getEncryptionKey(
secureStorage: secureStorage, forKey: Trade.boxKey);
final ordersBoxKey = await getEncryptionKey(
secureStorage: secureStorage, forKey: Order.boxKey);
final contacts = await Hive.openBox<Contact>(Contact.boxName);
final nodes = await Hive.openBox<Node>(Node.boxName);
final transactionDescriptions = await Hive.openBox<TransactionDescription>(
TransactionDescription.boxName,
encryptionKey: transactionDescriptionsBoxKey);
final trades = await Hive.openBox<Trade>(Trade.boxName, encryptionKey: tradesBoxKey);
final orders = await Hive.openBox<Order>(Order.boxName, encryptionKey: ordersBoxKey);
final trades =
await Hive.openBox<Trade>(Trade.boxName, encryptionKey: tradesBoxKey);
final orders =
await Hive.openBox<Order>(Order.boxName, encryptionKey: ordersBoxKey);
final walletInfoSource = await Hive.openBox<WalletInfo>(WalletInfo.boxName);
final templates = await Hive.openBox<Template>(Template.boxName);
final exchangeTemplates = await Hive.openBox<ExchangeTemplate>(ExchangeTemplate.boxName);
final anonpayInvoiceInfo = await Hive.openBox<AnonpayInvoiceInfo>(AnonpayInvoiceInfo.boxName);
final exchangeTemplates =
await Hive.openBox<ExchangeTemplate>(ExchangeTemplate.boxName);
final anonpayInvoiceInfo =
await Hive.openBox<AnonpayInvoiceInfo>(AnonpayInvoiceInfo.boxName);
Box<UnspentCoinsInfo>? unspentCoinsInfoSource;
if (!isMoneroOnly) {
unspentCoinsInfoSource = await Hive.openBox<UnspentCoinsInfo>(UnspentCoinsInfo.boxName);
unspentCoinsInfoSource =
await Hive.openBox<UnspentCoinsInfo>(UnspentCoinsInfo.boxName);
}
await initialSetup(
@ -144,7 +152,8 @@ Future<void> main() async {
initialMigrationVersion: 19);
runApp(App());
}, (error, stackTrace) async {
ExceptionHandler.onError(FlutterErrorDetails(exception: error, stack: stackTrace));
ExceptionHandler.onError(
FlutterErrorDetails(exception: error, stack: stackTrace));
});
}
@ -195,9 +204,9 @@ class App extends StatefulWidget {
class AppState extends State<App> with SingleTickerProviderStateMixin {
AppState() : yatStore = getIt.get<YatStore>() {
SystemChrome.setPreferredOrientations(
ResponsiveLayoutUtil.instance.isIpad ?
[DeviceOrientation.landscapeLeft, DeviceOrientation.landscapeRight] :
[DeviceOrientation.portraitUp, DeviceOrientation.portraitDown]);
// ResponsiveLayoutUtil.instance.isIpad ?
// [DeviceOrientation.landscapeLeft, DeviceOrientation.landscapeRight] :
[DeviceOrientation.portraitUp, DeviceOrientation.portraitDown]);
}
YatStore yatStore;
@ -261,14 +270,17 @@ class AppState extends State<App> with SingleTickerProviderStateMixin {
final settingsStore = appStore.settingsStore;
final statusBarColor = Colors.transparent;
final authenticationStore = getIt.get<AuthenticationStore>();
final initialRoute = authenticationStore.state == AuthenticationState.uninitialized
? Routes.disclaimer
: Routes.login;
final initialRoute =
authenticationStore.state == AuthenticationState.uninitialized
? Routes.disclaimer
: Routes.login;
final currentTheme = settingsStore.currentTheme;
final statusBarBrightness =
currentTheme.type == ThemeType.dark ? Brightness.light : Brightness.dark;
final statusBarIconBrightness =
currentTheme.type == ThemeType.dark ? Brightness.light : Brightness.dark;
final statusBarBrightness = currentTheme.type == ThemeType.dark
? Brightness.light
: Brightness.dark;
final statusBarIconBrightness = currentTheme.type == ThemeType.dark
? Brightness.light
: Brightness.dark;
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
statusBarColor: statusBarColor,
statusBarBrightness: statusBarBrightness,

View file

@ -7,6 +7,7 @@ import 'package:cake_wallet/view_model/restore/restore_wallet.dart';
import 'package:cake_wallet/view_model/send/output.dart';
import 'package:cw_core/balance.dart';
import 'package:cw_core/pending_transaction.dart';
import 'package:cw_core/sync_status.dart';
import 'package:cw_core/transaction_history.dart';
import 'package:cw_core/transaction_info.dart';
import 'package:hive/hive.dart';
@ -50,8 +51,6 @@ abstract class WalletCreationVMBase with Store {
final AppStore _appStore;
final FiatConversionStore _fiatConversationStore;
Completer<void> syncCompleter = Completer<void>();
bool nameExists(String name) => walletCreationService.exists(name);
bool typeExists(WalletType type) => walletCreationService.typeExists(type);
@ -69,7 +68,7 @@ abstract class WalletCreationVMBase with Store {
// if (restoreWallet != null &&
// restoreWallet.restoreMode == WalletRestoreMode.txids) {
//* Create the newWallet that will received the funds
//* Create the newWallet that will receive the funds
final newWallet = await createNewWalletWithoutSwitching(
options: options,
regenerateName: true,
@ -81,6 +80,9 @@ abstract class WalletCreationVMBase with Store {
_appStore.changeCurrentWallet(restoredWallet);
await restoredWallet.startSync();
print('Before syncing starts');
await syncCompleter.future;
print('After syncing ends');
//* Sweep all funds from restoredWallet to newWallet
await sweepAllFundsToNewWallet(
@ -161,7 +163,7 @@ abstract class WalletCreationVMBase with Store {
try {
await createTransaction(wallet, credentials);
// final currentNode = _appStore.settingsStore.getCurrentNode(type);
// final result = await walletCreationService.sweepAllFunds(currentNode, newWalletAddress, paymentId);
// final result = await walletCreationService.sweepAllFunds(currentNode, newWalletAddress, paymentId);
//* Switch back to new wallet
_appStore.changeCurrentWallet(wallet);
@ -176,7 +178,6 @@ abstract class WalletCreationVMBase with Store {
} catch (e) {
state = FailureState(e.toString());
}
}
Object _credentials(