mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-02-05 12:46:34 +00:00
Testing the sync before transaction flow WIP
This commit is contained in:
parent
2ec8ef0805
commit
3d3bdf3de5
4 changed files with 55 additions and 29 deletions
|
@ -1,3 +1,5 @@
|
||||||
|
import 'dart:async';
|
||||||
|
|
||||||
abstract class SyncStatus {
|
abstract class SyncStatus {
|
||||||
const SyncStatus();
|
const SyncStatus();
|
||||||
double progress();
|
double progress();
|
||||||
|
@ -52,3 +54,5 @@ class LostConnectionSyncStatus extends SyncStatus {
|
||||||
@override
|
@override
|
||||||
double progress() => 1.0;
|
double progress() => 1.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Completer<void> syncCompleter = Completer();
|
||||||
|
|
|
@ -380,9 +380,11 @@ abstract class MoneroWalletBase extends WalletBase<MoneroBalance,
|
||||||
void _askForUpdateBalance() {
|
void _askForUpdateBalance() {
|
||||||
final unlockedBalance = _getUnlockedBalance();
|
final unlockedBalance = _getUnlockedBalance();
|
||||||
final fullBalance = _getFullBalance();
|
final fullBalance = _getFullBalance();
|
||||||
|
print('Unlocked Balance: $unlockedBalance');
|
||||||
|
print('Full Balance: $fullBalance');
|
||||||
if (balance[currency]!.fullBalance != fullBalance ||
|
if (balance[currency]!.fullBalance != fullBalance ||
|
||||||
balance[currency]!.unlockedBalance != unlockedBalance) {
|
balance[currency]!.unlockedBalance != unlockedBalance) {
|
||||||
|
print('Currency Balance: ${balance[currency]}');
|
||||||
balance[currency] = MoneroBalance(
|
balance[currency] = MoneroBalance(
|
||||||
fullBalance: fullBalance, unlockedBalance: unlockedBalance);
|
fullBalance: fullBalance, unlockedBalance: unlockedBalance);
|
||||||
}
|
}
|
||||||
|
@ -398,6 +400,12 @@ abstract class MoneroWalletBase extends WalletBase<MoneroBalance,
|
||||||
accountIndex: walletAddresses.account!.id);
|
accountIndex: walletAddresses.account!.id);
|
||||||
|
|
||||||
void _onNewBlock(int height, int blocksLeft, double ptc) async {
|
void _onNewBlock(int height, int blocksLeft, double ptc) async {
|
||||||
|
print('----------------');
|
||||||
|
print('Blocks left: $blocksLeft');
|
||||||
|
print('height $height');
|
||||||
|
print('ptc: $ptc');
|
||||||
|
print('----------------');
|
||||||
|
_askForUpdateBalance();
|
||||||
try {
|
try {
|
||||||
if (walletInfo.isRecovery) {
|
if (walletInfo.isRecovery) {
|
||||||
await _askForUpdateTransactionHistory();
|
await _askForUpdateTransactionHistory();
|
||||||
|
@ -410,7 +418,8 @@ abstract class MoneroWalletBase extends WalletBase<MoneroBalance,
|
||||||
_askForUpdateBalance();
|
_askForUpdateBalance();
|
||||||
walletAddresses.accountList.update();
|
walletAddresses.accountList.update();
|
||||||
syncStatus = SyncedSyncStatus();
|
syncStatus = SyncedSyncStatus();
|
||||||
|
//! Introduce completer
|
||||||
|
syncCompleter.complete();
|
||||||
if (!_hasSyncAfterStartup) {
|
if (!_hasSyncAfterStartup) {
|
||||||
_hasSyncAfterStartup = true;
|
_hasSyncAfterStartup = true;
|
||||||
await save();
|
await save();
|
||||||
|
|
|
@ -52,7 +52,8 @@ Future<void> main() async {
|
||||||
/// A callback that is invoked when an unhandled error occurs in the root
|
/// A callback that is invoked when an unhandled error occurs in the root
|
||||||
/// isolate.
|
/// isolate.
|
||||||
PlatformDispatcher.instance.onError = (error, stack) {
|
PlatformDispatcher.instance.onError = (error, stack) {
|
||||||
ExceptionHandler.onError(FlutterErrorDetails(exception: error, stack: stack));
|
ExceptionHandler.onError(
|
||||||
|
FlutterErrorDetails(exception: error, stack: stack));
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
@ -106,25 +107,32 @@ Future<void> main() async {
|
||||||
}
|
}
|
||||||
|
|
||||||
final secureStorage = FlutterSecureStorage();
|
final secureStorage = FlutterSecureStorage();
|
||||||
final transactionDescriptionsBoxKey =
|
final transactionDescriptionsBoxKey = await getEncryptionKey(
|
||||||
await getEncryptionKey(secureStorage: secureStorage, forKey: TransactionDescription.boxKey);
|
secureStorage: secureStorage, forKey: TransactionDescription.boxKey);
|
||||||
final tradesBoxKey = await getEncryptionKey(secureStorage: secureStorage, forKey: Trade.boxKey);
|
final tradesBoxKey = await getEncryptionKey(
|
||||||
final ordersBoxKey = await getEncryptionKey(secureStorage: secureStorage, forKey: Order.boxKey);
|
secureStorage: secureStorage, forKey: Trade.boxKey);
|
||||||
|
final ordersBoxKey = await getEncryptionKey(
|
||||||
|
secureStorage: secureStorage, forKey: Order.boxKey);
|
||||||
final contacts = await Hive.openBox<Contact>(Contact.boxName);
|
final contacts = await Hive.openBox<Contact>(Contact.boxName);
|
||||||
final nodes = await Hive.openBox<Node>(Node.boxName);
|
final nodes = await Hive.openBox<Node>(Node.boxName);
|
||||||
final transactionDescriptions = await Hive.openBox<TransactionDescription>(
|
final transactionDescriptions = await Hive.openBox<TransactionDescription>(
|
||||||
TransactionDescription.boxName,
|
TransactionDescription.boxName,
|
||||||
encryptionKey: transactionDescriptionsBoxKey);
|
encryptionKey: transactionDescriptionsBoxKey);
|
||||||
final trades = await Hive.openBox<Trade>(Trade.boxName, encryptionKey: tradesBoxKey);
|
final trades =
|
||||||
final orders = await Hive.openBox<Order>(Order.boxName, encryptionKey: ordersBoxKey);
|
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 walletInfoSource = await Hive.openBox<WalletInfo>(WalletInfo.boxName);
|
||||||
final templates = await Hive.openBox<Template>(Template.boxName);
|
final templates = await Hive.openBox<Template>(Template.boxName);
|
||||||
final exchangeTemplates = await Hive.openBox<ExchangeTemplate>(ExchangeTemplate.boxName);
|
final exchangeTemplates =
|
||||||
final anonpayInvoiceInfo = await Hive.openBox<AnonpayInvoiceInfo>(AnonpayInvoiceInfo.boxName);
|
await Hive.openBox<ExchangeTemplate>(ExchangeTemplate.boxName);
|
||||||
|
final anonpayInvoiceInfo =
|
||||||
|
await Hive.openBox<AnonpayInvoiceInfo>(AnonpayInvoiceInfo.boxName);
|
||||||
Box<UnspentCoinsInfo>? unspentCoinsInfoSource;
|
Box<UnspentCoinsInfo>? unspentCoinsInfoSource;
|
||||||
|
|
||||||
if (!isMoneroOnly) {
|
if (!isMoneroOnly) {
|
||||||
unspentCoinsInfoSource = await Hive.openBox<UnspentCoinsInfo>(UnspentCoinsInfo.boxName);
|
unspentCoinsInfoSource =
|
||||||
|
await Hive.openBox<UnspentCoinsInfo>(UnspentCoinsInfo.boxName);
|
||||||
}
|
}
|
||||||
|
|
||||||
await initialSetup(
|
await initialSetup(
|
||||||
|
@ -144,7 +152,8 @@ Future<void> main() async {
|
||||||
initialMigrationVersion: 19);
|
initialMigrationVersion: 19);
|
||||||
runApp(App());
|
runApp(App());
|
||||||
}, (error, stackTrace) async {
|
}, (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 {
|
class AppState extends State<App> with SingleTickerProviderStateMixin {
|
||||||
AppState() : yatStore = getIt.get<YatStore>() {
|
AppState() : yatStore = getIt.get<YatStore>() {
|
||||||
SystemChrome.setPreferredOrientations(
|
SystemChrome.setPreferredOrientations(
|
||||||
ResponsiveLayoutUtil.instance.isIpad ?
|
// ResponsiveLayoutUtil.instance.isIpad ?
|
||||||
[DeviceOrientation.landscapeLeft, DeviceOrientation.landscapeRight] :
|
// [DeviceOrientation.landscapeLeft, DeviceOrientation.landscapeRight] :
|
||||||
[DeviceOrientation.portraitUp, DeviceOrientation.portraitDown]);
|
[DeviceOrientation.portraitUp, DeviceOrientation.portraitDown]);
|
||||||
}
|
}
|
||||||
|
|
||||||
YatStore yatStore;
|
YatStore yatStore;
|
||||||
|
@ -261,14 +270,17 @@ class AppState extends State<App> with SingleTickerProviderStateMixin {
|
||||||
final settingsStore = appStore.settingsStore;
|
final settingsStore = appStore.settingsStore;
|
||||||
final statusBarColor = Colors.transparent;
|
final statusBarColor = Colors.transparent;
|
||||||
final authenticationStore = getIt.get<AuthenticationStore>();
|
final authenticationStore = getIt.get<AuthenticationStore>();
|
||||||
final initialRoute = authenticationStore.state == AuthenticationState.uninitialized
|
final initialRoute =
|
||||||
? Routes.disclaimer
|
authenticationStore.state == AuthenticationState.uninitialized
|
||||||
: Routes.login;
|
? Routes.disclaimer
|
||||||
|
: Routes.login;
|
||||||
final currentTheme = settingsStore.currentTheme;
|
final currentTheme = settingsStore.currentTheme;
|
||||||
final statusBarBrightness =
|
final statusBarBrightness = currentTheme.type == ThemeType.dark
|
||||||
currentTheme.type == ThemeType.dark ? Brightness.light : Brightness.dark;
|
? Brightness.light
|
||||||
final statusBarIconBrightness =
|
: Brightness.dark;
|
||||||
currentTheme.type == ThemeType.dark ? Brightness.light : Brightness.dark;
|
final statusBarIconBrightness = currentTheme.type == ThemeType.dark
|
||||||
|
? Brightness.light
|
||||||
|
: Brightness.dark;
|
||||||
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
|
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
|
||||||
statusBarColor: statusBarColor,
|
statusBarColor: statusBarColor,
|
||||||
statusBarBrightness: statusBarBrightness,
|
statusBarBrightness: statusBarBrightness,
|
||||||
|
|
|
@ -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:cake_wallet/view_model/send/output.dart';
|
||||||
import 'package:cw_core/balance.dart';
|
import 'package:cw_core/balance.dart';
|
||||||
import 'package:cw_core/pending_transaction.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_history.dart';
|
||||||
import 'package:cw_core/transaction_info.dart';
|
import 'package:cw_core/transaction_info.dart';
|
||||||
import 'package:hive/hive.dart';
|
import 'package:hive/hive.dart';
|
||||||
|
@ -50,8 +51,6 @@ abstract class WalletCreationVMBase with Store {
|
||||||
final AppStore _appStore;
|
final AppStore _appStore;
|
||||||
final FiatConversionStore _fiatConversationStore;
|
final FiatConversionStore _fiatConversationStore;
|
||||||
|
|
||||||
Completer<void> syncCompleter = Completer<void>();
|
|
||||||
|
|
||||||
bool nameExists(String name) => walletCreationService.exists(name);
|
bool nameExists(String name) => walletCreationService.exists(name);
|
||||||
|
|
||||||
bool typeExists(WalletType type) => walletCreationService.typeExists(type);
|
bool typeExists(WalletType type) => walletCreationService.typeExists(type);
|
||||||
|
@ -69,7 +68,7 @@ abstract class WalletCreationVMBase with Store {
|
||||||
|
|
||||||
// if (restoreWallet != null &&
|
// if (restoreWallet != null &&
|
||||||
// restoreWallet.restoreMode == WalletRestoreMode.txids) {
|
// restoreWallet.restoreMode == WalletRestoreMode.txids) {
|
||||||
//* Create the newWallet that will received the funds
|
//* Create the newWallet that will receive the funds
|
||||||
final newWallet = await createNewWalletWithoutSwitching(
|
final newWallet = await createNewWalletWithoutSwitching(
|
||||||
options: options,
|
options: options,
|
||||||
regenerateName: true,
|
regenerateName: true,
|
||||||
|
@ -81,6 +80,9 @@ abstract class WalletCreationVMBase with Store {
|
||||||
_appStore.changeCurrentWallet(restoredWallet);
|
_appStore.changeCurrentWallet(restoredWallet);
|
||||||
|
|
||||||
await restoredWallet.startSync();
|
await restoredWallet.startSync();
|
||||||
|
print('Before syncing starts');
|
||||||
|
await syncCompleter.future;
|
||||||
|
print('After syncing ends');
|
||||||
|
|
||||||
//* Sweep all funds from restoredWallet to newWallet
|
//* Sweep all funds from restoredWallet to newWallet
|
||||||
await sweepAllFundsToNewWallet(
|
await sweepAllFundsToNewWallet(
|
||||||
|
@ -161,7 +163,7 @@ abstract class WalletCreationVMBase with Store {
|
||||||
try {
|
try {
|
||||||
await createTransaction(wallet, credentials);
|
await createTransaction(wallet, credentials);
|
||||||
// final currentNode = _appStore.settingsStore.getCurrentNode(type);
|
// 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
|
//* Switch back to new wallet
|
||||||
_appStore.changeCurrentWallet(wallet);
|
_appStore.changeCurrentWallet(wallet);
|
||||||
|
@ -176,7 +178,6 @@ abstract class WalletCreationVMBase with Store {
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
state = FailureState(e.toString());
|
state = FailureState(e.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Object _credentials(
|
Object _credentials(
|
||||||
|
|
Loading…
Reference in a new issue