@@ -129,11 +129,14 @@ class WalletConnectModalService extends ChangeNotifier
129129 return ;
130130 }
131131
132- _registerListeners ();
132+ registerListeners ();
133133
134134 _initError = null ;
135135 try {
136136 await _web3App! .init ();
137+ } catch (_) {}
138+
139+ try {
137140 await WalletConnectModalServices .init ();
138141 } catch (_) {}
139142
@@ -154,7 +157,7 @@ class WalletConnectModalService extends ChangeNotifier
154157 // ignore: prefer_void_to_null
155158 Future <Null > onDispose () async {
156159 if (_isInitialized) {
157- _unregisterListeners ();
160+ unregisterListeners ();
158161 }
159162 }
160163
@@ -163,7 +166,7 @@ class WalletConnectModalService extends ChangeNotifier
163166 required BuildContext context,
164167 Widget ? startWidget,
165168 }) async {
166- _checkInitialized ();
169+ checkInitialized ();
167170
168171 if (_isOpen) {
169172 return ;
@@ -249,14 +252,14 @@ class WalletConnectModalService extends ChangeNotifier
249252
250253 @override
251254 Future <void > reconnectRelay () async {
252- _checkInitialized ();
255+ checkInitialized ();
253256
254257 await web3App! .core.relayClient.connect ();
255258 }
256259
257260 @override
258261 Future <void > disconnect () async {
259- _checkInitialized ();
262+ checkInitialized ();
260263
261264 if (_session == null ) {
262265 return ;
@@ -283,13 +286,13 @@ class WalletConnectModalService extends ChangeNotifier
283286
284287 @override
285288 Future <void > launchCurrentWallet () async {
286- _checkInitialized ();
289+ checkInitialized ();
287290
288291 if (_session == null ) {
289292 return ;
290293 }
291294
292- final Redirect ? redirect = _constructRedirect ();
295+ final Redirect ? redirect = constructRedirect ();
293296
294297 LoggerUtil .logger.i (
295298 'Launching wallet: $redirect , ${_session ?.peer .metadata }' ,
@@ -326,7 +329,7 @@ class WalletConnectModalService extends ChangeNotifier
326329 Future <void > connectWallet ({
327330 required WalletData walletData,
328331 }) async {
329- _checkInitialized ();
332+ checkInitialized ();
330333
331334 if (_connectingWallet) {
332335 return ;
@@ -356,7 +359,7 @@ class WalletConnectModalService extends ChangeNotifier
356359 void setRequiredNamespaces ({
357360 required Map <String , RequiredNamespace > requiredNamespaces,
358361 }) {
359- _checkInitialized ();
362+ checkInitialized ();
360363
361364 LoggerUtil .logger.i ('Setting required namespaces: $requiredNamespaces ' );
362365
@@ -369,7 +372,7 @@ class WalletConnectModalService extends ChangeNotifier
369372 void setOptionalNamespaces ({
370373 required Map <String , RequiredNamespace > optionalNamespaces,
371374 }) {
372- _checkInitialized ();
375+ checkInitialized ();
373376
374377 LoggerUtil .logger.i ('Setting optional namespaces: $optionalNamespaces ' );
375378
@@ -380,7 +383,7 @@ class WalletConnectModalService extends ChangeNotifier
380383
381384 @override
382385 String getReferer () {
383- _checkInitialized ();
386+ checkInitialized ();
384387
385388 return _web3App! .metadata.name.replaceAll (' ' , '' );
386389 }
@@ -408,13 +411,14 @@ class WalletConnectModalService extends ChangeNotifier
408411
409412 notifyListeners ();
410413
411- _awaitConnectResponse ();
414+ awaitConnectResponse ();
412415 }
413416 }
414417
415418 ////// Private methods //////
416419
417- Redirect ? _constructRedirect () {
420+ @protected
421+ Redirect ? constructRedirect () {
418422 if (session == null ) {
419423 return null ;
420424 }
@@ -436,38 +440,41 @@ class WalletConnectModalService extends ChangeNotifier
436440 );
437441 }
438442
439- void _registerListeners () {
443+ @protected
444+ void registerListeners () {
440445 web3App! .onSessionConnect.subscribe (
441- _onSessionConnect ,
446+ onSessionConnect ,
442447 );
443448 web3App! .onSessionDelete.subscribe (
444- _onSessionDelete ,
449+ onSessionDelete ,
445450 );
446451 web3App! .core.relayClient.onRelayClientConnect.subscribe (
447- _onRelayClientConnect ,
452+ onRelayClientConnect ,
448453 );
449454 web3App! .core.relayClient.onRelayClientError.subscribe (
450- _onRelayClientError ,
455+ onRelayClientError ,
451456 );
452457 }
453458
454- void _unregisterListeners () {
459+ @protected
460+ void unregisterListeners () {
455461 web3App! .onSessionConnect.unsubscribe (
456- _onSessionConnect ,
462+ onSessionConnect ,
457463 );
458464 web3App! .onSessionDelete.unsubscribe (
459- _onSessionDelete ,
465+ onSessionDelete ,
460466 );
461467 web3App! .core.relayClient.onRelayClientConnect.unsubscribe (
462- _onRelayClientConnect ,
468+ onRelayClientConnect ,
463469 );
464470 web3App! .core.relayClient.onRelayClientError.unsubscribe (
465- _onRelayClientError ,
471+ onRelayClientError ,
466472 );
467473 }
468474
469- void _onSessionConnect (SessionConnect ? args) {
470- LoggerUtil .logger.i ('Session connected: ${args ?.session }' );
475+ @protected
476+ void onSessionConnect (SessionConnect ? args) {
477+ LoggerUtil .logger.i ('_onSessionConnect: ${args ?.session }' );
471478 _isConnected = true ;
472479 _session = args! .session;
473480 _address = NamespaceUtils .getAccount (
@@ -481,23 +488,27 @@ class WalletConnectModalService extends ChangeNotifier
481488 }
482489 }
483490
484- void _onSessionDelete (SessionDelete ? args) {
485- LoggerUtil .logger.i ('Session deleted: $args ' );
491+ @protected
492+ void onSessionDelete (SessionDelete ? args) {
493+ LoggerUtil .logger.i ('_onSessionDelete: $args ' );
486494 _isConnected = false ;
487495 _address = '' ;
488496 _session = null ;
489497
490498 notifyListeners ();
491499 }
492500
493- void _onRelayClientConnect (EventArgs ? args) {
501+ @protected
502+ void onRelayClientConnect (EventArgs ? args) {
503+ LoggerUtil .logger.i ('_onRelayClientConnect: $args ' );
494504 _initError = null ;
495505
496506 notifyListeners ();
497507 }
498508
499- void _onRelayClientError (ErrorEvent ? args) {
500- LoggerUtil .logger.e ('Relay client error: ${args ?.error }' );
509+ @protected
510+ void onRelayClientError (ErrorEvent ? args) {
511+ LoggerUtil .logger.e ('_onRelayClientError: ${args ?.error }' );
501512 _initError = args? .error;
502513
503514 notifyListeners ();
@@ -510,7 +521,8 @@ class WalletConnectModalService extends ChangeNotifier
510521 /// If there is no connect response, it will do nothing.
511522 /// The completion of this method is triggered when the dApp
512523 /// connects to a wallet.
513- Future <void > _awaitConnectResponse () async {
524+ @protected
525+ Future <void > awaitConnectResponse () async {
514526 if (connectResponse == null ) {
515527 return ;
516528 }
@@ -532,10 +544,11 @@ class WalletConnectModalService extends ChangeNotifier
532544 }
533545 }
534546
535- void _checkInitialized () {
547+ @protected
548+ void checkInitialized () {
536549 if (! isInitialized) {
537550 throw StateError (
538- 'Web3ModalService must be initialized before calling this method.' ,
551+ 'Service must be initialized before calling this method.' ,
539552 );
540553 }
541554 }
0 commit comments