Skip to content

Commit

Permalink
revert RNModule.kt changes
Browse files Browse the repository at this point in the history
  • Loading branch information
nazli-stripe committed Dec 22, 2023
1 parent b3f294f commit 1567a3c
Showing 1 changed file with 17 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 1567a3c

Please sign in to comment.