Skip to content

Commit

Permalink
first iteration
Browse files Browse the repository at this point in the history
  • Loading branch information
quetool committed Jun 11, 2024
1 parent dd44624 commit 082a041
Show file tree
Hide file tree
Showing 17 changed files with 254 additions and 239 deletions.
15 changes: 6 additions & 9 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,19 @@ Steps to reproduce the behavior:
3. Scroll down to '....'
4. See error

**Expected behavior**
A clear and concise description of what you expected to happen.
**Meaningful logs**
Any error or information log that would help identify the issue

**Reproducible code**
Minimum reproducible code of the issue

**Screenshots**
If applicable, add screenshots to help explain your problem.

**Desktop (please complete the following information):**
- OS: [e.g. iOS]
- Browser [e.g. chrome, safari]
- Version [e.g. 22]

**Smartphone (please complete the following information):**
- Device: [e.g. iPhone6]
- OS: [e.g. iOS8.1]
- Browser [e.g. stock browser, safari]
- Version [e.g. 22]
- Web3Modal Version [e.g. 22]

**Additional context**
Add any other context about the problem here.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 3.2.3-alpha01

- One-Click Auth implementation

## 3.2.2

- Network change improvements
Expand Down
25 changes: 18 additions & 7 deletions example/lib/home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,25 +44,36 @@ class _MyHomePageState extends State<MyHomePage> {
// See https://docs.walletconnect.com/web3modal/flutter/custom-chains
W3MChainPresets.chains.addAll(W3MChainPresets.extraChains);
W3MChainPresets.chains.addAll(W3MChainPresets.testChains);
// W3MChainPresets.chains.removeWhere((key, _) => key != '137');

final sortedChains = W3MChainPresets.chains.keys.toList()
..sort((e1, e2) => e1.compareTo(e2));

final ocaRequestParams = OCARequestParams(
chains: sortedChains.map((e) => 'eip155:$e').toList(),
domain: 'web3modal.com',
nonce: AuthUtils.generateNonce(),
uri: 'https://web3modal.com/login',
statement: 'Welcome to Web3Modal for Flutter.',
methods: MethodsConstants.allMethods,
);

_w3mService = W3MService(
projectId: DartDefines.projectId,
logLevel: LogLevel.error,
metadata: const PairingMetadata(
metadata: PairingMetadata(
name: StringConstants.w3mPageTitleV3,
description: StringConstants.w3mPageTitleV3,
url: 'https://web3modal.com/',
url: 'https://${ocaRequestParams.domain}/',
icons: [
'https://docs.walletconnect.com/assets/images/web3modalLogo-2cee77e07851ba0a710b56d03d4d09dd.png'
],
redirect: Redirect(
redirect: const Redirect(
native: 'web3modalflutter://',
universal: 'https://web3modal.com',
),
),
enableAnalytics: true, // OPTIONAL - null by default
enableEmail: true, // OPTIONAL - false by default
ocaRequestParams: ocaRequestParams,
// enableAnalytics: true, // OPTIONAL - null by default
// enableEmail: true, // OPTIONAL - false by default
// requiredNamespaces: {},
// optionalNamespaces: {},
// excludedWalletIds: {
Expand Down
6 changes: 3 additions & 3 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1105,10 +1105,10 @@ packages:
dependency: transitive
description:
name: walletconnect_flutter_v2
sha256: cc6fa6a537910a66258ee64bb510edbfc0dee01485ea1138651431087c94671b
sha256: "6bfd9e700f5fc712edf487e49842ba682a5e7ba0570f7299c9162e7dd7b5d549"
url: "https://pub.dev"
source: hosted
version: "2.2.3"
version: "2.3.0-alpha01"
watcher:
dependency: transitive
description:
Expand Down Expand Up @@ -1139,7 +1139,7 @@ packages:
path: ".."
relative: true
source: path
version: "3.2.2"
version: "3.2.3-alpha01"
web_socket_channel:
dependency: transitive
description:
Expand Down
14 changes: 8 additions & 6 deletions lib/pages/qr_code_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,14 @@ class _QRCodePageState extends State<QRCodePage> {
setState(() {});
}

void _onError(EventArgs? args) {
_showUserRejection();
void _onError(ModalError? args) {
final event = args ?? ModalError('An error occurred');
toastUtils.instance.show(
ToastMessage(
type: ToastType.error,
text: event.message,
),
);
}

@override
Expand Down Expand Up @@ -144,8 +150,4 @@ class _QRCodePageState extends State<QRCodePage> {
ToastMessage(type: ToastType.success, text: 'Link copied'),
);
}

void _showUserRejection() => toastUtils.instance.show(
ToastMessage(type: ToastType.error, text: 'User rejected'),
);
}
10 changes: 5 additions & 5 deletions lib/services/analytics_service/analytics_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ class AnalyticsService implements IAnalyticsService {
_endpoint = kDebugMode
? _debugApiEndpoint
: await coreUtils.instance.getAnalyticsUrl();
loggerService.instance.p('[$runtimeType] enabled: $_isEnabled');
loggerService.instance.d('[$runtimeType] enabled: $_isEnabled');
} catch (e, s) {
loggerService.instance.p(
loggerService.instance.d(
'[$runtimeType] init error',
error: e,
stackTrace: s,
Expand All @@ -68,7 +68,7 @@ class AnalyticsService implements IAnalyticsService {
final enabled = json['isAnalyticsEnabled'] as bool?;
return enabled ?? false;
} catch (e, s) {
loggerService.instance.p(
loggerService.instance.d(
'[$runtimeType] fetch remote configuration error',
error: e,
stackTrace: s,
Expand Down Expand Up @@ -101,9 +101,9 @@ class AnalyticsService implements IAnalyticsService {
if (code == 200 || code == 202) {
_eventsController.sink.add(analyticsEvent.toMap());
}
loggerService.instance.p('[$runtimeType] send event $code: $body');
loggerService.instance.d('[$runtimeType] send event $code: $body');
} catch (e, s) {
loggerService.instance.p(
loggerService.instance.d(
'[$runtimeType] send event error',
error: e,
stackTrace: s,
Expand Down
4 changes: 2 additions & 2 deletions lib/services/explorer_service/explorer_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ class ExplorerService implements IExplorerService {
sampleWallets.add(sampleWallet);
}
}
loggerService.instance.p(
loggerService.instance.d(
'[$runtimeType] sample wallets: ${sampleWallets.length}',
);
return sampleWallets;
Expand Down Expand Up @@ -399,7 +399,7 @@ class ExplorerService implements IExplorerService {
final excludedIds = (excludedWalletIds ?? <String>{});
final exclude = excludedIds.isNotEmpty ? excludedIds.join(',') : null;

loggerService.instance.p('[$runtimeType] search $query');
loggerService.instance.d('[$runtimeType] search $query');
_currentSearchValue = query;
final newListins = await _fetchListings(
params: RequestParams(
Expand Down
33 changes: 0 additions & 33 deletions lib/services/logger_service/i_logger_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,6 @@ abstract class ILoggerService {
StackTrace? stackTrace,
});

/// Log a message at level [Level.warning].
void w(
dynamic message, {
DateTime? time,
Object? error,
StackTrace? stackTrace,
});

/// Log a message at level [Level.error].
void e(
dynamic message, {
Expand All @@ -41,31 +33,6 @@ abstract class ILoggerService {
StackTrace? stackTrace,
});

/// Log a message at level [Level.fatal].
void f(
dynamic message, {
DateTime? time,
Object? error,
StackTrace? stackTrace,
});

/// Log a message with [level].
void log(
Level level,
dynamic message, {
DateTime? time,
Object? error,
StackTrace? stackTrace,
});

/// Log a message at level private.
void p(
dynamic message, {
DateTime? time,
Object? error,
StackTrace? stackTrace,
});

/// Closes the logger and releases all resources.
Future<void> close();
}
58 changes: 5 additions & 53 deletions lib/services/logger_service/logger_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,10 @@ import 'package:web3modal_flutter/web3modal_flutter.dart';

class LoggerService implements ILoggerService {
late Logger _logger;
late String _projectId;
LoggerService({
required LogLevel level,
required String projectId,
bool debugMode = true,
bool debugMode = kDebugMode,
}) {
_projectId = projectId;
_logger = Logger(
level: level.toLevel(),
printer: PrettyPrinter(methodCount: null),
Expand All @@ -22,22 +19,7 @@ class LoggerService implements ILoggerService {
}
}

void _logListener(LogEvent event) {
debugPrint('${event.message}');
}

@override
void p(
message, {
DateTime? time,
Object? error,
StackTrace? stackTrace,
}) {
// TODO [LoggerService] fix this
if (_projectId == 'cad4956f31a5e40a00b62865b030c6f8') {
_logger.i(message, time: time, error: error, stackTrace: stackTrace);
}
}
void _logListener(LogEvent event) => debugPrint('${event.message}');

@override
void d(
Expand All @@ -59,16 +41,6 @@ class LoggerService implements ILoggerService {
_logger.e(message, time: time, error: error, stackTrace: stackTrace);
}

@override
void f(
message, {
DateTime? time,
Object? error,
StackTrace? stackTrace,
}) {
_logger.f(message, time: time, error: error, stackTrace: stackTrace);
}

@override
void i(
message, {
Expand All @@ -79,18 +51,6 @@ class LoggerService implements ILoggerService {
_logger.i(message, time: time, error: error, stackTrace: stackTrace);
}

@override
void log(
Level level,
message, {
DateTime? time,
Object? error,
StackTrace? stackTrace,
}) {
_logger.log(level, message,
time: time, error: error, stackTrace: stackTrace);
}

@override
void t(
message, {
Expand All @@ -101,19 +61,11 @@ class LoggerService implements ILoggerService {
_logger.t(message, time: time, error: error, stackTrace: stackTrace);
}

@override
void w(
message, {
DateTime? time,
Object? error,
StackTrace? stackTrace,
}) {
_logger.w(message, time: time, error: error, stackTrace: stackTrace);
}

@override
Future<void> close() async {
Logger.removeLogListener(_logListener);
try {
Logger.removeLogListener(_logListener);
} catch (_) {}
return await _logger.close();
}
}
29 changes: 15 additions & 14 deletions lib/services/magic_service/magic_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -143,14 +143,15 @@ class MagicService implements IMagicService {
onWebResourceError: _onWebResourceError,
onPageFinished: (String url) async {
_onLoadCount++;
// If bundleId/packageName is whitelisted in cloud then for some reason it enters here twice
// Like as if secure-mobile.walletconnect.com is loaded twice
// If bundleId/packageName is NOT whitelisted in cloud then it enter just once.
// This is happening only on Android devices, on iOS only once execution is done no matter what.
if (_onLoadCount < 2 && Platform.isAndroid) return;
await _runJavascript(_web3app.core.projectId);
Future.delayed(Duration(milliseconds: 200)).then((_) async {
try {
_initialized.complete(true);
} catch (e) {
loggerService.instance.e('[$runtimeType] CRASH! $e');
}
await _runJavascript();
Future.delayed(Duration(milliseconds: 600)).then((value) {
if (_initialized.isCompleted) return;
_initialized.complete(true);
});
},
),
Expand Down Expand Up @@ -327,7 +328,7 @@ class MagicService implements IMagicService {

void _onFrameMessage(JavaScriptMessage jsMessage) async {
if (Platform.isAndroid) {
loggerService.instance.p('[$runtimeType] jsMessage ${jsMessage.message}');
loggerService.instance.d('[$runtimeType] jsMessage ${jsMessage.message}');
}
try {
final frameMessage = jsMessage.toFrameMessage();
Expand Down Expand Up @@ -482,7 +483,7 @@ class MagicService implements IMagicService {
_error(SignOutErrorEvent());
}
} catch (e, s) {
loggerService.instance.p('[$runtimeType] $jsMessage', stackTrace: s);
loggerService.instance.d('[$runtimeType] $jsMessage', stackTrace: s);
}
}

Expand Down Expand Up @@ -531,24 +532,24 @@ class MagicService implements IMagicService {
onMagicError.broadcast(errorEvent);
}

Future<void> _runJavascript(String projectId) async {
Future<void> _runJavascript() async {
return await _webViewController.runJavaScript('''
const iframeFL = document.getElementById('frame-mobile-sdk')
window.addEventListener('message', ({ data, origin }) => {
console.log('w3mMessage received <=== ' + JSON.stringify({data,origin}))
console.log('[MagicService] received <=== ' + JSON.stringify({data,origin}))
window.w3mWebview.postMessage(JSON.stringify({data,origin}))
})
const sendW3Message = async (message) => {
console.log('w3mMessage posted =====> ' + JSON.stringify(message))
console.log('[MagicService] posted =====> ' + JSON.stringify(message))
iframeFL.contentWindow.postMessage(message, '*')
}
''');
}

void _onDebugConsoleReceived(JavaScriptConsoleMessage message) {
loggerService.instance.p('[$runtimeType] JS Console ${message.message}');
loggerService.instance.d('[$runtimeType] JS Console ${message.message}');
}

void _onWebResourceError(WebResourceError error) {
Expand Down
Loading

0 comments on commit 082a041

Please sign in to comment.