mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-02-06 21:31:33 +00:00
bg-sync testing
This commit is contained in:
parent
c78243f802
commit
1b8218f970
7 changed files with 149 additions and 49 deletions
|
@ -13,7 +13,9 @@ class CwMweb {
|
||||||
options: const ChannelOptions(
|
options: const ChannelOptions(
|
||||||
credentials: ChannelCredentials.insecure(),
|
credentials: ChannelCredentials.insecure(),
|
||||||
keepAlive: ClientKeepAliveOptions(permitWithoutCalls: true),
|
keepAlive: ClientKeepAliveOptions(permitWithoutCalls: true),
|
||||||
)),
|
), channelShutdownHandler: () {
|
||||||
|
print("SHUTDOWN HANDLER CALLED @@@@@@@@@@@@@@@@@");
|
||||||
|
}),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,7 @@ import workmanager
|
||||||
}
|
}
|
||||||
|
|
||||||
WorkmanagerPlugin.registerTask(withIdentifier: "com.fotolockr.cakewallet.monero_sync_task")
|
WorkmanagerPlugin.registerTask(withIdentifier: "com.fotolockr.cakewallet.monero_sync_task")
|
||||||
|
WorkmanagerPlugin.registerTask(withIdentifier: "com.fotolockr.cakewallet.mweb_sync_task")
|
||||||
|
|
||||||
makeSecure()
|
makeSecure()
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
<key>BGTaskSchedulerPermittedIdentifiers</key>
|
<key>BGTaskSchedulerPermittedIdentifiers</key>
|
||||||
<array>
|
<array>
|
||||||
<string>com.fotolockr.cakewallet.monero_sync_task</string>
|
<string>com.fotolockr.cakewallet.monero_sync_task</string>
|
||||||
|
<string>com.fotolockr.cakewallet.mweb_sync_task</string>
|
||||||
</array>
|
</array>
|
||||||
<key>CFBundleDevelopmentRegion</key>
|
<key>CFBundleDevelopmentRegion</key>
|
||||||
<string>$(DEVELOPMENT_LANGUAGE)</string>
|
<string>$(DEVELOPMENT_LANGUAGE)</string>
|
||||||
|
|
|
@ -17,12 +17,42 @@ import 'package:cake_wallet/main.dart';
|
||||||
import 'package:cake_wallet/di.dart';
|
import 'package:cake_wallet/di.dart';
|
||||||
|
|
||||||
const moneroSyncTaskKey = "com.fotolockr.cakewallet.monero_sync_task";
|
const moneroSyncTaskKey = "com.fotolockr.cakewallet.monero_sync_task";
|
||||||
|
const mwebSyncTaskKey = "com.fotolockr.cakewallet.mweb_sync_task";
|
||||||
|
|
||||||
@pragma('vm:entry-point')
|
@pragma('vm:entry-point')
|
||||||
void callbackDispatcher() {
|
void callbackDispatcher() {
|
||||||
Workmanager().executeTask((task, inputData) async {
|
Workmanager().executeTask((task, inputData) async {
|
||||||
try {
|
try {
|
||||||
switch (task) {
|
switch (task) {
|
||||||
|
case mwebSyncTaskKey:
|
||||||
|
final List<WalletListItem> ltcWallets = getIt
|
||||||
|
.get<WalletListViewModel>()
|
||||||
|
.wallets
|
||||||
|
.where((element) => [WalletType.litecoin].contains(element.type))
|
||||||
|
.toList();
|
||||||
|
|
||||||
|
if (ltcWallets.isEmpty) {
|
||||||
|
return Future.error("No ltc wallets found");
|
||||||
|
}
|
||||||
|
|
||||||
|
final walletLoadingService = getIt.get<WalletLoadingService>();
|
||||||
|
|
||||||
|
var wallet =
|
||||||
|
await walletLoadingService.load(ltcWallets.first.type, ltcWallets.first.name);
|
||||||
|
await wallet.startSync();
|
||||||
|
|
||||||
|
for (int i = 0;; i++) {
|
||||||
|
await Future<void>.delayed(const Duration(seconds: 1));
|
||||||
|
if (wallet.syncStatus.progress() == 1.0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (i > 600) {
|
||||||
|
return Future.error("Synchronization Timed out");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
case moneroSyncTaskKey:
|
case moneroSyncTaskKey:
|
||||||
|
|
||||||
/// The work manager runs on a separate isolate from the main flutter isolate.
|
/// The work manager runs on a separate isolate from the main flutter isolate.
|
||||||
|
@ -98,8 +128,13 @@ class BackgroundTasks {
|
||||||
.wallets
|
.wallets
|
||||||
.any((element) => element.type == WalletType.monero);
|
.any((element) => element.type == WalletType.monero);
|
||||||
|
|
||||||
|
bool hasLitecoin = getIt
|
||||||
|
.get<WalletListViewModel>()
|
||||||
|
.wallets
|
||||||
|
.any((element) => element.type == WalletType.litecoin);
|
||||||
|
|
||||||
/// if its not android nor ios, or the user has no monero wallets; exit
|
/// if its not android nor ios, or the user has no monero wallets; exit
|
||||||
if (!DeviceInfo.instance.isMobile || !hasMonero) {
|
if (!DeviceInfo.instance.isMobile || (!hasMonero && !hasLitecoin)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -128,10 +163,18 @@ class BackgroundTasks {
|
||||||
);
|
);
|
||||||
|
|
||||||
if (Platform.isIOS) {
|
if (Platform.isIOS) {
|
||||||
|
// await Workmanager().registerOneOffTask(
|
||||||
|
// moneroSyncTaskKey,
|
||||||
|
// moneroSyncTaskKey,
|
||||||
|
// initialDelay: syncMode.frequency,
|
||||||
|
// existingWorkPolicy: ExistingWorkPolicy.replace,
|
||||||
|
// inputData: inputData,
|
||||||
|
// constraints: constraints,
|
||||||
|
// );
|
||||||
await Workmanager().registerOneOffTask(
|
await Workmanager().registerOneOffTask(
|
||||||
moneroSyncTaskKey,
|
mwebSyncTaskKey,
|
||||||
moneroSyncTaskKey,
|
mwebSyncTaskKey,
|
||||||
initialDelay: syncMode.frequency,
|
initialDelay: Duration(seconds: 10),
|
||||||
existingWorkPolicy: ExistingWorkPolicy.replace,
|
existingWorkPolicy: ExistingWorkPolicy.replace,
|
||||||
inputData: inputData,
|
inputData: inputData,
|
||||||
constraints: constraints,
|
constraints: constraints,
|
||||||
|
@ -139,9 +182,18 @@ class BackgroundTasks {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// await Workmanager().registerPeriodicTask(
|
||||||
|
// moneroSyncTaskKey,
|
||||||
|
// moneroSyncTaskKey,
|
||||||
|
// initialDelay: syncMode.frequency,
|
||||||
|
// frequency: syncMode.frequency,
|
||||||
|
// existingWorkPolicy: changeExisting ? ExistingWorkPolicy.replace : ExistingWorkPolicy.keep,
|
||||||
|
// inputData: inputData,
|
||||||
|
// constraints: constraints,
|
||||||
|
// );
|
||||||
await Workmanager().registerPeriodicTask(
|
await Workmanager().registerPeriodicTask(
|
||||||
moneroSyncTaskKey,
|
mwebSyncTaskKey,
|
||||||
moneroSyncTaskKey,
|
mwebSyncTaskKey,
|
||||||
initialDelay: syncMode.frequency,
|
initialDelay: syncMode.frequency,
|
||||||
frequency: syncMode.frequency,
|
frequency: syncMode.frequency,
|
||||||
existingWorkPolicy: changeExisting ? ExistingWorkPolicy.replace : ExistingWorkPolicy.keep,
|
existingWorkPolicy: changeExisting ? ExistingWorkPolicy.replace : ExistingWorkPolicy.keep,
|
||||||
|
|
43
lib/lightning/lightning.dart
Normal file
43
lib/lightning/lightning.dart
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
import 'package:cw_core/transaction_priority.dart';
|
||||||
|
import 'package:cw_core/wallet_info.dart';
|
||||||
|
import 'package:cw_core/unspent_coins_info.dart';
|
||||||
|
import 'package:cw_core/wallet_service.dart';
|
||||||
|
import 'package:cw_core/receive_page_option.dart';
|
||||||
|
import 'package:cw_core/crypto_amount_format.dart';
|
||||||
|
import 'package:hive/hive.dart';
|
||||||
|
import 'package:mobx/mobx.dart';
|
||||||
|
import 'package:intl/intl.dart';
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Lightning? lightning;
|
||||||
|
|
||||||
|
abstract class Lightning {
|
||||||
|
String formatterLightningAmountToString({required int amount});
|
||||||
|
double formatterLightningAmountToDouble({required int amount});
|
||||||
|
int formatterStringDoubleToLightningAmount(String amount);
|
||||||
|
WalletService createLightningWalletService(
|
||||||
|
Box<WalletInfo> walletInfoSource, Box<UnspentCoinsInfo> unspentCoinSource);
|
||||||
|
List<ReceivePageOption> getLightningReceivePageOptions();
|
||||||
|
String satsToLightningString(int sats);
|
||||||
|
ReceivePageOption getOptionInvoice();
|
||||||
|
ReceivePageOption getOptionOnchain();
|
||||||
|
String bitcoinAmountToLightningString({required int amount});
|
||||||
|
int bitcoinAmountToLightningAmount({required int amount});
|
||||||
|
double bitcoinDoubleToLightningDouble({required double amount});
|
||||||
|
double lightningDoubleToBitcoinDouble({required double amount});
|
||||||
|
Map<String, int> getIncomingPayments(Object wallet);
|
||||||
|
void clearIncomingPayments(Object wallet);
|
||||||
|
String lightningTransactionPriorityWithLabel(TransactionPriority priority, int rate, {int? customRate});
|
||||||
|
List<TransactionPriority> getTransactionPriorities();
|
||||||
|
TransactionPriority getLightningTransactionPriorityCustom();
|
||||||
|
int getFeeRate(Object wallet, TransactionPriority priority);
|
||||||
|
int getMaxCustomFeeRate(Object wallet);
|
||||||
|
Future<void> fetchFees(Object wallet);
|
||||||
|
Future<int> calculateEstimatedFeeAsync(Object wallet, TransactionPriority? priority, int? amount);
|
||||||
|
Future<int> getEstimatedFeeWithFeeRate(Object wallet, int feeRate, int? amount);
|
||||||
|
TransactionPriority getDefaultTransactionPriority();
|
||||||
|
TransactionPriority deserializeLightningTransactionPriority({required int raw});
|
||||||
|
String getBreezApiKey();
|
||||||
|
}
|
||||||
|
|
|
@ -44,7 +44,7 @@ class ConnectionSyncPage extends BasePage {
|
||||||
: S.current.rescan,
|
: S.current.rescan,
|
||||||
handler: (context) => Navigator.of(context).pushNamed(Routes.rescan),
|
handler: (context) => Navigator.of(context).pushNamed(Routes.rescan),
|
||||||
),
|
),
|
||||||
if (DeviceInfo.instance.isMobile && FeatureFlag.isBackgroundSyncEnabled) ...[
|
// if (DeviceInfo.instance.isMobile && FeatureFlag.isBackgroundSyncEnabled) ...[
|
||||||
Observer(builder: (context) {
|
Observer(builder: (context) {
|
||||||
return SettingsPickerCell<SyncMode>(
|
return SettingsPickerCell<SyncMode>(
|
||||||
title: S.current.background_sync_mode,
|
title: S.current.background_sync_mode,
|
||||||
|
@ -89,7 +89,7 @@ class ConnectionSyncPage extends BasePage {
|
||||||
);
|
);
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
],
|
// ],
|
||||||
SettingsCellWithArrow(
|
SettingsCellWithArrow(
|
||||||
title: S.current.manage_nodes,
|
title: S.current.manage_nodes,
|
||||||
handler: (context) => Navigator.of(context).pushNamed(Routes.manageNodes),
|
handler: (context) => Navigator.of(context).pushNamed(Routes.manageNodes),
|
||||||
|
@ -109,7 +109,8 @@ class ConnectionSyncPage extends BasePage {
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
if (isWalletConnectCompatibleChain(dashboardViewModel.wallet.type) &&
|
if (isWalletConnectCompatibleChain(dashboardViewModel.wallet.type) &&
|
||||||
!dashboardViewModel.wallet.isHardwareWallet) ...[ // ToDo: Remove this line once WalletConnect is implemented
|
!dashboardViewModel.wallet.isHardwareWallet) ...[
|
||||||
|
// ToDo: Remove this line once WalletConnect is implemented
|
||||||
WalletConnectTile(
|
WalletConnectTile(
|
||||||
onTap: () => Navigator.of(context).pushNamed(Routes.walletConnectConnectionsListing),
|
onTap: () => Navigator.of(context).pushNamed(Routes.walletConnectConnectionsListing),
|
||||||
),
|
),
|
||||||
|
|
|
@ -2,5 +2,5 @@ class FeatureFlag {
|
||||||
static const bool isCakePayEnabled = false;
|
static const bool isCakePayEnabled = false;
|
||||||
static const bool isExolixEnabled = true;
|
static const bool isExolixEnabled = true;
|
||||||
static const bool isInAppTorEnabled = false;
|
static const bool isInAppTorEnabled = false;
|
||||||
static const bool isBackgroundSyncEnabled = false;
|
static const bool isBackgroundSyncEnabled = true;
|
||||||
}
|
}
|
Loading…
Reference in a new issue