diff --git a/android/src/main/java/com/stripeterminalreactnative/StripeTerminalReactNativeModule.kt b/android/src/main/java/com/stripeterminalreactnative/StripeTerminalReactNativeModule.kt index 91a92d4a..cf4c8e4a 100644 --- a/android/src/main/java/com/stripeterminalreactnative/StripeTerminalReactNativeModule.kt +++ b/android/src/main/java/com/stripeterminalreactnative/StripeTerminalReactNativeModule.kt @@ -98,28 +98,25 @@ class StripeTerminalReactNativeModule(reactContext: ReactApplicationContext) : @ReactMethod @Suppress("unused") fun initialize(params: ReadableMap, promise: Promise) = withExceptionResolver(promise) { - - UiThreadUtil.runOnUiThread { - onCreate(context.currentActivity?.application as Application) - - val result = if (!Terminal.isInitialized()) { - Terminal.initTerminal( - this.context.applicationContext, - mapToLogLevel(params.getString("logLevel")), - tokenProvider, - RNTerminalListener(context), - RNOfflineListener(context), - ) - NativeTypeFactory.writableNativeMap() - } else { - nativeMapOf { - terminal.connectedReader?.let { - putMap("reader", mapFromReader(it)) - } + UiThreadUtil.runOnUiThread { onCreate(context.applicationContext as Application) } + + val result = if (!Terminal.isInitialized()) { + Terminal.initTerminal( + this.context.applicationContext, + mapToLogLevel(params.getString("logLevel")), + tokenProvider, + RNTerminalListener(context), + RNOfflineListener(context), + ) + NativeTypeFactory.writableNativeMap() + } else { + nativeMapOf { + terminal.connectedReader?.let { + putMap("reader", mapFromReader(it)) } } - promise.resolve(result) } + promise.resolve(result) } @ReactMethod @@ -699,34 +696,7 @@ class StripeTerminalReactNativeModule(reactContext: ReactApplicationContext) : @ReactMethod @Suppress("unused") fun getOfflineStatus(promise: Promise) { - promise.resolve( - nativeMapOf { - val sdkMap = nativeMapOf { - putInt("offlinePaymentsCount", terminal.offlineStatus.sdk.offlinePaymentsCount) - - val map = nativeMapOf { - terminal.offlineStatus.sdk.offlinePaymentAmountsByCurrency.forEach { - putInt(it.key, it.value.toInt()) - } - } - putMap("offlinePaymentAmountsByCurrency", map) - } - - val readerMap = nativeMapOf { - putInt("offlinePaymentsCount", terminal.offlineStatus.reader?.offlinePaymentsCount?:0) - - val map = nativeMapOf { - terminal.offlineStatus.reader?.offlinePaymentAmountsByCurrency?.forEach { - putInt(it.key, it.value.toInt()) - } - } - putMap("offlinePaymentAmountsByCurrency", map) - } - - putMap("sdk", sdkMap) - putMap("reader", readerMap) - } - ) + promise.resolve(mapFromOfflineStatus(terminal.offlineStatus)) } private fun cancelOperation(