Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class AtomicTransactFlutterPlugin: FlutterPlugin, MethodCallHandler, ActivityAwa
if (call.method == "presentTransact") {
val transactPath = call.argument<String>("transactPath") as String? ?: ""
val apiPath = call.argument<String>("apiPath") as String? ?: ""
val debug = call.argument<Boolean>("debug") ?: false
val configuration = call.argument<Map<String, Any>>("configuration")
val publicToken = configuration?.get("publicToken") as String
val scope = configuration?.get("scope") as String
Expand Down Expand Up @@ -66,7 +67,8 @@ class AtomicTransactFlutterPlugin: FlutterPlugin, MethodCallHandler, ActivityAwa
experiments = configExperimentsFromMap(experiments),
search = configSearchFromMap(search),
environment = Config.Environment.CUSTOM,
environmentURL = transactPath
environmentURL = transactPath,
webContentsDebuggingEnabled = debug
)

Transact.registerReceiver(activity, object: TransactBroadcastReceiver() {
Expand Down Expand Up @@ -96,12 +98,14 @@ class AtomicTransactFlutterPlugin: FlutterPlugin, MethodCallHandler, ActivityAwa
val id = call.argument<String>("id") ?: return
val transactPath = call.argument<String>("transactPath") as String? ?: ""
val apiPath = call.argument<String>("apiPath") as String? ?: ""
val debug = call.argument<Boolean>("debug") ?: false
var theme = call.argument<Map<String, Any>>("theme")
val config = ActionConfig(
id = id,
environment = Config.Environment.CUSTOM,
environmentURL = transactPath,
theme = configThemeFromMap(theme)
theme = configThemeFromMap(theme),
webContentsDebuggingEnabled = debug
)

Transact.registerReceiver(activity, object: TransactBroadcastReceiver() {
Expand Down
4 changes: 4 additions & 0 deletions example/lib/models/app_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ class AppState extends ChangeNotifier {
bool get darkMode => _darkMode;
set darkMode(bool v) { _darkMode = v; notifyListeners(); }

bool _debug = false;
bool get debug => _debug;
set debug(bool v) { _debug = v; notifyListeners(); }

// Pay Link
PayLinkTask _payLinkTask = PayLinkTask.switchPayment;
PayLinkTask get payLinkTask => _payLinkTask;
Expand Down
1 change: 1 addition & 0 deletions example/lib/screens/pay_link_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class PayLinkScreen extends StatelessWidget {
Atomic.transact(
config: config,
environment: state.environment,
debug: state.debug,
onInteraction: (interaction) {
eventLog.add(EventEntry(
type: EventType.interaction,
Expand Down
5 changes: 5 additions & 0 deletions example/lib/screens/settings_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ class SettingsScreen extends StatelessWidget {
value: state.darkMode,
onChanged: (v) => state.darkMode = v,
),
ToggleRow(
title: 'Debug Mode',
value: state.debug,
onChanged: (v) => state.debug = v,
),
const SizedBox(height: 32),
],
),
Expand Down
1 change: 1 addition & 0 deletions example/lib/screens/user_link_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class UserLinkScreen extends StatelessWidget {
Atomic.transact(
config: config,
environment: state.environment,
debug: state.debug,
onInteraction: (interaction) {
eventLog.add(EventEntry(
type: EventType.interaction,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ public class AtomicTransactFlutterPlugin: NSObject, FlutterPlugin {
let arguments = call.arguments as! [String: Any]
let transactPath = arguments["transactPath"] as! String
let apiPath = arguments["apiPath"] as! String
let debugEnabled = arguments["debug"] as? Bool ?? false
let decoder = JSONDecoder()

let presentationStyle = getPresentationStyle(from: arguments["presentationStyleIOS"] as? String)

if let configuration = arguments["configuration"] as? [String: Any] {
do {
var json = configuration
Expand All @@ -41,6 +42,12 @@ public class AtomicTransactFlutterPlugin: NSObject, FlutterPlugin {
var config = try decoder.decode(AtomicConfig.self, from: data)

Task { @MainActor in
await Atomic.setDebug(isEnabled: debugEnabled, forwardLogs: { logMessage in
DispatchQueue.main.async {
self.channel.invokeMethod("onDebugLog", arguments: ["message": logMessage])
}
})

if let controller = UIApplication.shared.windows.filter({$0.isKeyWindow}).first?.rootViewController {
Atomic.presentTransact(from: controller, config: config, environment: .custom(transactPath: transactPath, apiPath: apiPath), presentationStyle: presentationStyle, onInteraction: onInteraction, onDataRequest: onDataRequest, onAuthStatusUpdate: onAuthStatusUpdate, onTaskStatusUpdate: onTaskStatusUpdate, onCompletion: onCompletion)
result(nil)
Expand All @@ -58,6 +65,7 @@ public class AtomicTransactFlutterPlugin: NSObject, FlutterPlugin {
let id = arguments["id"] as! String
let transactPath = arguments["transactPath"] as! String
let apiPath = arguments["apiPath"] as! String
let debugEnabled = arguments["debug"] as? Bool ?? false
let decoder = JSONDecoder()
let theme: AtomicConfig.Theme = {
if let themeData = arguments["theme"] as? [String: Any],
Expand All @@ -67,10 +75,16 @@ public class AtomicTransactFlutterPlugin: NSObject, FlutterPlugin {
}
return AtomicConfig.Theme(dark: .system)
}()

let presentationStyle = getPresentationStyle(from: arguments["presentationStyleIOS"] as? String)

Task { @MainActor in
await Atomic.setDebug(isEnabled: debugEnabled, forwardLogs: { logMessage in
DispatchQueue.main.async {
self.channel.invokeMethod("onDebugLog", arguments: ["message": logMessage])
}
})

if let controller = UIApplication.shared.windows.filter({$0.isKeyWindow}).first?.rootViewController {
Atomic.presentAction(from: controller, id: id, environment: .custom(transactPath: transactPath, apiPath: apiPath), presentationStyle: presentationStyle, theme: theme, onLaunch: onLaunch, onAuthStatusUpdate: onAuthStatusUpdate, onTaskStatusUpdate: onTaskStatusUpdate, onCompletion: onCompletion)
result(nil)
Expand Down
10 changes: 10 additions & 0 deletions lib/platform_interface/atomic_method_channel.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:atomic_transact_flutter/src/events.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';

import '../src/config.dart';
Expand All @@ -21,6 +22,7 @@ class AtomicMethodChannel extends AtomicPlatformInterface {
required AtomicConfig configuration,
required TransactEnvironment environment,
AtomicPresentationStyleIOS? presentationStyleIOS,
bool debug = false,
}) async {
await _channel.invokeMethod(
'presentTransact',
Expand All @@ -29,6 +31,7 @@ class AtomicMethodChannel extends AtomicPlatformInterface {
'transactPath': environment.transactPath,
'apiPath': environment.apiPath,
'presentationStyleIOS': presentationStyleIOS?.name,
'debug': debug,
},
);
}
Expand All @@ -41,13 +44,15 @@ class AtomicMethodChannel extends AtomicPlatformInterface {
required TransactEnvironment environment,
AtomicTheme? theme,
AtomicPresentationStyleIOS? presentationStyleIOS,
bool debug = false,
}) async {
await _channel.invokeMethod('presentAction', {
'id': id,
'transactPath': environment.transactPath,
'apiPath': environment.apiPath,
'theme': theme?.toJson(),
'presentationStyleIOS': presentationStyleIOS?.name,
'debug': debug,
});
}

Expand Down Expand Up @@ -95,6 +100,11 @@ class AtomicMethodChannel extends AtomicPlatformInterface {
onLaunch?.call();
break;

case 'onDebugLog':
final message = call.arguments['message'] as String? ?? '';
debugPrint('[AtomicTransact] $message');
break;

case 'onAuthStatusUpdate':
final authData = call.arguments['auth'];
onAuthStatusUpdate?.call(
Expand Down
2 changes: 2 additions & 0 deletions lib/platform_interface/atomic_platform_interface.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ abstract class AtomicPlatformInterface extends PlatformInterface {
required AtomicConfig configuration,
required TransactEnvironment environment,
AtomicPresentationStyleIOS? presentationStyleIOS,
bool debug = false,
}) async {
throw UnimplementedError('presentTransact() has not been implemented.');
}
Expand All @@ -51,6 +52,7 @@ abstract class AtomicPlatformInterface extends PlatformInterface {
required TransactEnvironment environment,
AtomicTheme? theme,
AtomicPresentationStyleIOS? presentationStyleIOS,
bool debug = false,
}) async {
throw UnimplementedError('presentAction() has not been implemented.');
}
Expand Down
6 changes: 5 additions & 1 deletion lib/src/atomic.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class Atomic {
AtomicTaskStatusUpdateHandler? onTaskStatusUpdate,
AtomicCompletionHandler? onCompletion,
AtomicPresentationStyleIOS? presentationStyleIOS,
bool debug = false,
}) async {
if (_isLoading) {
return;
Expand All @@ -49,6 +50,7 @@ class Atomic {
configuration: config,
environment: environment,
presentationStyleIOS: presentationStyleIOS,
debug: debug,
);
}

Expand All @@ -61,6 +63,7 @@ class Atomic {
AtomicCompletionHandler? onCompletion,
AtomicTheme? theme,
AtomicPresentationStyleIOS? presentationStyleIOS,
bool debug = false,
}) async {
if (_isLoading) {
return;
Expand All @@ -81,7 +84,8 @@ class Atomic {
id: id,
environment: environment,
theme: theme,
presentationStyleIOS: presentationStyleIOS);
presentationStyleIOS: presentationStyleIOS,
debug: debug);
}

static Future<void> close() async {
Expand Down