Skip to content

Commit

Permalink
refactor(deriv_web_view)!: remove hardcoded redirect urls
Browse files Browse the repository at this point in the history
  • Loading branch information
sahani-deriv committed Feb 5, 2024
1 parent 4b91058 commit 68d2ef6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
2 changes: 2 additions & 0 deletions packages/deriv_web_view/lib/deriv_web_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,15 @@ Future<void> openInAppWebViewWithUriHandler({
required Function(Uri) uriHandler,
required Function(String) onError,
required VoidCallback onClosed,
required List<String> redirectURLs,
}) async {
try {
_openInAppTabView(url, onClosed);
} on PlatformException catch (_) {
final AppInAppBrowser browser = AppInAppBrowser(
onUrlChanged: (Uri uri) => uriHandler(uri),
onError: (String message) => onError(message),
redirectURLs: redirectURLs,
);

await browser.openUrlRequest(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,24 @@ import 'package:flutter_inappwebview/flutter_inappwebview.dart';

/// The browser that is used to launch deriv's login web page
class AppInAppBrowser extends InAppBrowser {
/// AppInAppBrowser is called from *login_helper.dart* and launches deriv's
/// login page.
///
/// It takes the following requires parameters
/// [onUrlChanged] function that is called when the url passed has changed,
/// for a redirect link in this case.
/// [onAccountsFetched] function which is called when accounts are fetched.
AppInAppBrowser({
required this.onUrlChanged,
required this.onError,
required this.redirectURLs,
});

/// A Function callback to url change.
void Function(Uri) onUrlChanged;

/// A Function callback to error.
void Function(String) onError;

final List<String> _redirectURLs = <String>['deriv://multipliers'];
/// List of redirect urls.
List<String> redirectURLs;

@override
void onBrowserCreated() => logger.log('\n\nBrowser Created!\n\n');
Expand All @@ -30,7 +30,7 @@ class AppInAppBrowser extends InAppBrowser {
void onLoadStart(Uri? url) {
logger.log('\n\nStarted\n\n');

for (final String redirectURL in _redirectURLs) {
for (final String redirectURL in redirectURLs) {
if (url.toString().startsWith(redirectURL)) {
close();
onUrlChanged(url!);
Expand Down

0 comments on commit 68d2ef6

Please sign in to comment.