Skip to content

Commit d5945b4

Browse files
committed
clean up remaining node service refactor code issues
1 parent e8a13f9 commit d5945b4

37 files changed

Lines changed: 248 additions & 271 deletions

lib/pages/add_wallet_views/new_wallet_recovery_phrase_warning_view/new_wallet_recovery_phrase_warning_view.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,10 +165,10 @@ class _NewWalletRecoveryPhraseWarningViewState
165165
.getPrimaryNodeFor(currency: coin);
166166

167167
if (node == null) {
168-
node = coin.defaultNode;
168+
node = coin.defaultNode(isPrimary: true);
169169
await ref
170170
.read(nodeServiceChangeNotifierProvider)
171-
.setPrimaryNodeFor(coin: coin, node: node);
171+
.save(node, null, false);
172172
}
173173

174174
final txTracker = TransactionNotificationTracker(walletId: info.walletId);

lib/pages/add_wallet_views/restore_wallet_view/restore_view_only_wallet_view.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,10 +198,10 @@ class _RestoreViewOnlyWalletViewState
198198
.getPrimaryNodeFor(currency: widget.coin);
199199

200200
if (node == null) {
201-
node = widget.coin.defaultNode;
201+
node = widget.coin.defaultNode(isPrimary: true);
202202
await ref
203203
.read(nodeServiceChangeNotifierProvider)
204-
.setPrimaryNodeFor(coin: widget.coin, node: node);
204+
.save(node, null, false);
205205
}
206206

207207
try {

lib/pages/add_wallet_views/restore_wallet_view/restore_wallet_view.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,10 +298,10 @@ class _RestoreWalletViewState extends ConsumerState<RestoreWalletView> {
298298
.getPrimaryNodeFor(currency: widget.coin);
299299

300300
if (node == null) {
301-
node = widget.coin.defaultNode;
301+
node = widget.coin.defaultNode(isPrimary: true);
302302
await ref
303303
.read(nodeServiceChangeNotifierProvider)
304-
.setPrimaryNodeFor(coin: widget.coin, node: node);
304+
.save(node, null, false);
305305
}
306306

307307
final txTracker = TransactionNotificationTracker(

lib/pages/settings_views/global_settings_view/stack_backup_views/helpers/restore_create_backup.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -794,8 +794,8 @@ abstract class SWB {
794794
var node = nodeService.getPrimaryNodeFor(currency: coin);
795795

796796
if (node == null) {
797-
node = coin.defaultNode;
798-
await nodeService.setPrimaryNodeFor(coin: coin, node: node);
797+
node = coin.defaultNode(isPrimary: true);
798+
await nodeService.save(node, null, false);
799799
}
800800

801801
// final txTracker = TransactionNotificationTracker(walletId: walletId);

lib/services/ethereum/ethereum_api.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class EthereumResponse<T> {
4343

4444
abstract class EthereumAPI {
4545
static String get stackBaseServer =>
46-
Ethereum(CryptoCurrencyNetwork.main).defaultNode.host;
46+
Ethereum(CryptoCurrencyNetwork.main).defaultNode(isPrimary: true).host;
4747

4848
static HTTP client = HTTP();
4949

lib/services/node_service.dart

Lines changed: 5 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,9 @@ class NodeService extends ChangeNotifier {
7474
}
7575
}
7676

77-
for (final defaultNode in AppConfig.coins.map((e) => e.defaultNode)) {
77+
for (final defaultNode in AppConfig.coins.map(
78+
(e) => e.defaultNode(isPrimary: true),
79+
)) {
7880
final savedNode = DB.instance.get<NodeModel>(
7981
boxName: DB.boxNameNodeModels,
8082
key: defaultNode.id,
@@ -102,26 +104,8 @@ class NodeService extends ChangeNotifier {
102104
torEnabled: savedNode.torEnabled,
103105
clearnetEnabled: savedNode.clearnetEnabled,
104106
loginName: savedNode.loginName,
105-
),
106-
);
107-
}
108-
109-
// check if a default node is the primary node for the crypto currency
110-
// and update it if needed
111-
final coin = AppConfig.getCryptoCurrencyByPrettyName(
112-
defaultNode.coinName,
113-
);
114-
final primaryNode = getPrimaryNodeFor(currency: coin);
115-
if (primaryNode != null && primaryNode.id == defaultNode.id) {
116-
await setPrimaryNodeFor(
117-
coin: coin,
118-
node: defaultNode.copyWith(
119-
enabled: primaryNode.enabled,
120-
isFailover: primaryNode.isFailover,
121-
trusted: primaryNode.trusted,
122-
torEnabled: primaryNode.torEnabled,
123-
clearnetEnabled: primaryNode.clearnetEnabled,
124-
loginName: primaryNode.loginName,
107+
isPrimary: savedNode.isPrimary,
108+
forceNoTor: savedNode.forceNoTor,
125109
),
126110
);
127111
}
@@ -226,17 +210,6 @@ class NodeService extends ChangeNotifier {
226210
String? password,
227211
bool shouldNotifyListeners,
228212
) async {
229-
// Handle primary node updates (logic from edit())
230-
final coin = AppConfig.getCryptoCurrencyByPrettyName(node.coinName);
231-
final primaryNode = getPrimaryNodeFor(currency: coin);
232-
if (primaryNode?.id == node.id) {
233-
await setPrimaryNodeFor(
234-
coin: coin,
235-
node: node,
236-
shouldNotifyListeners: true,
237-
);
238-
}
239-
240213
// Save to database (logic from add()).
241214
await DB.instance.put<NodeModel>(
242215
boxName: DB.boxNameNodeModels,

lib/utilities/show_node_tor_settings_mismatch.dart

Lines changed: 47 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ Future<bool> checkShowNodeTorSettingsMismatch({
2020
bool rootNavigator = false,
2121
}) async {
2222
final node =
23-
nodeService.getPrimaryNodeFor(currency: currency) ?? currency.defaultNode;
23+
nodeService.getPrimaryNodeFor(currency: currency) ??
24+
currency.defaultNode(isPrimary: true);
2425
if (prefs.useTor) {
2526
if (node.torEnabled) {
2627
return true;
@@ -34,63 +35,57 @@ Future<bool> checkShowNodeTorSettingsMismatch({
3435
final result = await showDialog<bool>(
3536
context: context,
3637
barrierDismissible: false,
37-
builder: (context) => ConditionalParent(
38-
condition: Util.isDesktop,
39-
builder: (child) => DesktopDialog(
40-
maxHeight: double.infinity,
41-
child: Padding(
42-
padding: const EdgeInsets.all(32),
43-
child: child,
44-
),
45-
),
46-
child: ConditionalParent(
47-
condition: !Util.isDesktop,
48-
builder: (child) => StackDialogBase(
49-
child: child,
50-
),
51-
child: Column(
52-
mainAxisSize: MainAxisSize.min,
53-
children: [
54-
Text(
55-
"Attention! Node connection issue detected. "
56-
"The current node will not sync due to its connectivity settings. "
57-
"Please adjust the node settings or enable/disable TOR.",
58-
style: STextStyles.w600_16(context),
59-
),
60-
SizedBox(
61-
height: Util.isDesktop ? 32 : 24,
62-
),
63-
Row(
38+
builder:
39+
(context) => ConditionalParent(
40+
condition: Util.isDesktop,
41+
builder:
42+
(child) => DesktopDialog(
43+
maxHeight: double.infinity,
44+
child: Padding(padding: const EdgeInsets.all(32), child: child),
45+
),
46+
child: ConditionalParent(
47+
condition: !Util.isDesktop,
48+
builder: (child) => StackDialogBase(child: child),
49+
child: Column(
50+
mainAxisSize: MainAxisSize.min,
6451
children: [
65-
allowCancel
66-
? Expanded(
67-
child: SecondaryButton(
68-
buttonHeight: Util.isDesktop ? ButtonHeight.l : null,
69-
label: "Cancel",
70-
onPressed: () {
71-
Navigator.of(context).pop(false);
72-
},
73-
),
74-
)
75-
: const Spacer(),
76-
SizedBox(
77-
width: Util.isDesktop ? 24 : 16,
52+
Text(
53+
"Attention! Node connection issue detected. "
54+
"The current node will not sync due to its connectivity settings. "
55+
"Please adjust the node settings or enable/disable TOR.",
56+
style: STextStyles.w600_16(context),
7857
),
79-
Expanded(
80-
child: PrimaryButton(
81-
buttonHeight: Util.isDesktop ? ButtonHeight.l : null,
82-
label: "Continue",
83-
onPressed: () {
84-
Navigator.of(context).pop(true);
85-
},
86-
),
58+
SizedBox(height: Util.isDesktop ? 32 : 24),
59+
Row(
60+
children: [
61+
allowCancel
62+
? Expanded(
63+
child: SecondaryButton(
64+
buttonHeight:
65+
Util.isDesktop ? ButtonHeight.l : null,
66+
label: "Cancel",
67+
onPressed: () {
68+
Navigator.of(context).pop(false);
69+
},
70+
),
71+
)
72+
: const Spacer(),
73+
SizedBox(width: Util.isDesktop ? 24 : 16),
74+
Expanded(
75+
child: PrimaryButton(
76+
buttonHeight: Util.isDesktop ? ButtonHeight.l : null,
77+
label: "Continue",
78+
onPressed: () {
79+
Navigator.of(context).pop(true);
80+
},
81+
),
82+
),
83+
],
8784
),
8885
],
8986
),
90-
],
87+
),
9188
),
92-
),
93-
),
9489
);
9590

9691
return result ?? true;

lib/wallets/crypto_currency/coins/banano.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,7 @@ class Banano extends NanoCurrency {
4545
int get fractionDigits => 29;
4646

4747
@override
48-
BigInt get satsPerCoin => BigInt.parse(
49-
"100000000000000000000000000000",
50-
); // 1*10^29
48+
BigInt get satsPerCoin => BigInt.parse("100000000000000000000000000000"); // 1*10^29
5149

5250
@override
5351
int get minConfirms => 1;
@@ -63,7 +61,7 @@ class Banano extends NanoCurrency {
6361
int get nanoAccountType => NanoAccountType.BANANO;
6462

6563
@override
66-
NodeModel get defaultNode {
64+
NodeModel defaultNode({required bool isPrimary}) {
6765
switch (network) {
6866
case CryptoCurrencyNetwork.main:
6967
return NodeModel(
@@ -79,6 +77,7 @@ class Banano extends NanoCurrency {
7977
isDown: false,
8078
torEnabled: true,
8179
clearnetEnabled: true,
80+
isPrimary: isPrimary,
8281
);
8382

8483
default:
@@ -99,7 +98,8 @@ class Banano extends NanoCurrency {
9998
}
10099

101100
@override
102-
DerivePathType get defaultDerivePathType => throw UnsupportedError(
101+
DerivePathType get defaultDerivePathType =>
102+
throw UnsupportedError(
103103
"$runtimeType does not use bitcoin style derivation paths",
104104
);
105105
}

lib/wallets/crypto_currency/coins/bitcoin.dart

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,11 @@ class Bitcoin extends Bip39HDCurrency
6262

6363
@override
6464
List<DerivePathType> get supportedDerivationPathTypes => [
65-
DerivePathType.bip44,
66-
DerivePathType.bip49,
67-
DerivePathType.bip84,
68-
DerivePathType.bip86, // P2TR.
69-
];
65+
DerivePathType.bip44,
66+
DerivePathType.bip49,
67+
DerivePathType.bip84,
68+
DerivePathType.bip86, // P2TR.
69+
];
7070

7171
@override
7272
String get genesisHash {
@@ -83,10 +83,8 @@ class Bitcoin extends Bip39HDCurrency
8383
}
8484

8585
@override
86-
Amount get dustLimit => Amount(
87-
rawValue: BigInt.from(294),
88-
fractionDigits: fractionDigits,
89-
);
86+
Amount get dustLimit =>
87+
Amount(rawValue: BigInt.from(294), fractionDigits: fractionDigits);
9088

9189
@override
9290
coinlib.Network get networkParams {
@@ -180,10 +178,11 @@ class Bitcoin extends Bip39HDCurrency
180178

181179
// TODO: [prio=high] verify this works similarly to bitcoindart's p2sh or something(!!)
182180
case DerivePathType.bip49:
183-
final p2wpkhScript = coinlib.P2WPKHAddress.fromPublicKey(
184-
publicKey,
185-
hrp: networkParams.bech32Hrp,
186-
).program.script;
181+
final p2wpkhScript =
182+
coinlib.P2WPKHAddress.fromPublicKey(
183+
publicKey,
184+
hrp: networkParams.bech32Hrp,
185+
).program.script;
187186

188187
final addr = coinlib.P2SHAddress.fromRedeemScript(
189188
p2wpkhScript,
@@ -226,7 +225,7 @@ class Bitcoin extends Bip39HDCurrency
226225
}
227226

228227
@override
229-
NodeModel get defaultNode {
228+
NodeModel defaultNode({required bool isPrimary}) {
230229
switch (network) {
231230
case CryptoCurrencyNetwork.main:
232231
return NodeModel(
@@ -241,6 +240,7 @@ class Bitcoin extends Bip39HDCurrency
241240
isDown: false,
242241
torEnabled: true,
243242
clearnetEnabled: true,
243+
isPrimary: isPrimary,
244244
);
245245

246246
case CryptoCurrencyNetwork.test:
@@ -256,6 +256,7 @@ class Bitcoin extends Bip39HDCurrency
256256
isDown: false,
257257
torEnabled: true,
258258
clearnetEnabled: true,
259+
isPrimary: isPrimary,
259260
);
260261

261262
case CryptoCurrencyNetwork.test4:
@@ -271,6 +272,7 @@ class Bitcoin extends Bip39HDCurrency
271272
isDown: false,
272273
torEnabled: true,
273274
clearnetEnabled: true,
275+
isPrimary: isPrimary,
274276
);
275277

276278
default:

0 commit comments

Comments
 (0)