diff --git a/cw_decred/lib/wallet.dart b/cw_decred/lib/wallet.dart index 06ba2ef6d..731aa2213 100644 --- a/cw_decred/lib/wallet.dart +++ b/cw_decred/lib/wallet.dart @@ -52,13 +52,12 @@ abstract class DecredWalletBase extends WalletBase connectToNode({required Node node}) async { if (connecting) { - throw "decred already connecting"; + return; } connecting = true; String addr = ""; @@ -235,7 +230,7 @@ abstract class DecredWalletBase extends WalletBase startSync() async { if (connecting) { - throw "decred already connecting"; + return; } connecting = true; await this._startSync(); @@ -252,8 +247,8 @@ abstract class DecredWalletBase extends WalletBase performBackgroundTasks()); + syncTimer = Timer.periodic(Duration(seconds: syncInterval), + (Timer t) => performBackgroundTasks()); } catch (e) { print(e.toString()); syncStatus = FailedSyncStatus(); @@ -272,16 +267,9 @@ abstract class DecredWalletBase extends WalletBase init() async {} @override - Future updateAddressesInBox() async {} - - @override - Future saveAddressesInBox() async {} + Future updateAddressesInBox() async { + await saveAddressesInBox(); + } } diff --git a/lib/decred/cw_decred.dart b/lib/decred/cw_decred.dart index 43d3a4e23..ef4ff0f15 100644 --- a/lib/decred/cw_decred.dart +++ b/lib/decred/cw_decred.dart @@ -113,7 +113,10 @@ class CWDecred extends Decred { } @override - void updateUnspents(Object wallet) async {} + void updateUnspents(Object wallet) async { + final decredWallet = wallet as DecredWallet; + decredWallet.unspents(); + } @override int heightByDate(DateTime date) { @@ -121,8 +124,8 @@ class CWDecred extends Decred { DateTime.fromMillisecondsSinceEpoch(1454954400 * 1000); final minutesDiff = date.difference(genesisBlocktime).inMinutes; // Decred has five minute blocks on mainnet. - // NOTE: This is off by about a day. - // TODO: Remove this and just rescan from the wallet birthday. + // NOTE: This is off by about a day but is currently unused by decred as we + // rescan from the wallet birthday. return (minutesDiff / 5).toInt(); } diff --git a/lib/di.dart b/lib/di.dart index 1d6815203..055c6ad5c 100644 --- a/lib/di.dart +++ b/lib/di.dart @@ -1114,7 +1114,7 @@ Future setup({ getIt.registerFactory(() => RescanViewModel(getIt.get().wallet!)); - getIt.registerFactory(() => RescanPage(getIt.get(), getIt.get().wallet!.type)); + getIt.registerFactory(() => RescanPage(getIt.get())); getIt.registerFactory(() => FaqPage(getIt.get())); diff --git a/lib/entities/default_settings_migration.dart b/lib/entities/default_settings_migration.dart index 8d8cb6079..3084847b8 100644 --- a/lib/entities/default_settings_migration.dart +++ b/lib/entities/default_settings_migration.dart @@ -96,7 +96,6 @@ Future defaultSettingsMigration( PreferencesKey.currentBalanceDisplayModeKey, BalanceDisplayMode.availableBalance.raw); await sharedPreferences.setBool('save_recipient_address', true); await resetToDefault(nodes); - await setDefaultDecredNodeKey(sharedPreferences, nodes); await changeMoneroCurrentNodeToDefault( sharedPreferences: sharedPreferences, nodes: nodes); await changeBitcoinCurrentElectrumServerToDefault( @@ -349,6 +348,9 @@ Future defaultSettingsMigration( type: WalletType.litecoin, useSSL: true, ); + case 47: + await addDecredNode(nodes: nodes); + await setDefaultDecredNodeKey(sharedPreferences, nodes); break; default: break; @@ -819,6 +821,11 @@ Future rewriteSecureStoragePin({required SecureStorage secureStorage}) asy ); } +Future addDecredNode({required Box nodes}) async { + final node = Node(uri: decredDefaultUri, type: WalletType.decred); + await nodes.add(node); +} + // If "node_list.resetToDefault" is called the old node.key will still be set in // preferences. Set it to whatever it is now. // @@ -1285,7 +1292,6 @@ Future checkCurrentNodes( } if (currentDecredNodeServer == null) { - final decredMainnetPort = ":9108"; final node = Node(uri: decredDefaultUri, type: WalletType.decred); await nodeSource.add(node); await sharedPreferences.setInt( diff --git a/lib/src/screens/rescan/rescan_page.dart b/lib/src/screens/rescan/rescan_page.dart index 289fd4a11..33f5498f3 100644 --- a/lib/src/screens/rescan/rescan_page.dart +++ b/lib/src/screens/rescan/rescan_page.dart @@ -12,7 +12,7 @@ import 'package:cake_wallet/generated/i18n.dart'; import 'package:cw_core/wallet_type.dart'; class RescanPage extends BasePage { - RescanPage(this._rescanViewModel, this.type) + RescanPage(this._rescanViewModel) : _blockchainHeightWidgetKey = GlobalKey(); @override @@ -21,19 +21,17 @@ class RescanPage extends BasePage { : S.current.rescan; final GlobalKey _blockchainHeightWidgetKey; final RescanViewModel _rescanViewModel; - final WalletType type; @override Widget body(BuildContext context) { var child; - if (type != WalletType.decred) { + if (_rescanViewModel.wallet.type != WalletType.decred) { child = Padding( padding: EdgeInsets.only(left: 24, right: 24, bottom: 24), child: Column(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Observer( builder: (_) => BlockchainHeightWidget( - type: this.type, key: _blockchainHeightWidgetKey, onHeightOrDateEntered: (value) => _rescanViewModel.isButtonEnabled = value, diff --git a/lib/src/widgets/blockchain_height_widget.dart b/lib/src/widgets/blockchain_height_widget.dart index 47cacdda2..605ae4484 100644 --- a/lib/src/widgets/blockchain_height_widget.dart +++ b/lib/src/widgets/blockchain_height_widget.dart @@ -16,7 +16,6 @@ import 'package:cw_core/wallet_type.dart'; class BlockchainHeightWidget extends StatefulWidget { BlockchainHeightWidget({ GlobalKey? key, - this.type, this.onHeightChange, this.focusNode, this.onHeightOrDateEntered, @@ -30,7 +29,6 @@ class BlockchainHeightWidget extends StatefulWidget { this.blockHeightTextFieldKey, }) : super(key: key); - final WalletType? type; final Function(int)? onHeightChange; final Function(bool)? onHeightOrDateEntered; final FocusNode? focusNode; @@ -188,7 +186,7 @@ class BlockchainHeightState extends State { bitcoinMempoolAPIEnabled: await widget.bitcoinMempoolAPIEnabled, ); } else { - if (widget.type == WalletType.decred) { + if (widget.walletType == WalletType.decred) { height = decred!.heightByDate(date); } else if (widget.walletType == WalletType.monero) { height = monero!.getHeightByDate(date: date); diff --git a/lib/view_model/node_list/node_list_view_model.dart b/lib/view_model/node_list/node_list_view_model.dart index 34e8bdf0d..c6b897f9a 100644 --- a/lib/view_model/node_list/node_list_view_model.dart +++ b/lib/view_model/node_list/node_list_view_model.dart @@ -49,9 +49,6 @@ abstract class NodeListViewModelBase with Store { Future reset() async { await resetToDefault(_nodeSource); - final decredNode = getDecredDefaultNode(nodes: _nodeSource)!; - final sharedPrefs = getIt.get(); - await setDefaultDecredNodeKey(sharedPrefs, _nodeSource); Node node; @@ -94,7 +91,7 @@ abstract class NodeListViewModelBase with Store { node = getWowneroDefaultNode(nodes: _nodeSource); break; case WalletType.decred: - node = decredNode; + node = getDecredDefaultNode(nodes: _nodeSource)!; break; default: throw Exception('Unexpected wallet type: ${_appStore.wallet!.type}');