Skip to content

Commit

Permalink
fix(ios): Executed fetch token and more actions on main thread
Browse files Browse the repository at this point in the history
  • Loading branch information
BreX900 committed Sep 14, 2023
1 parent 4f41725 commit b41d829
Show file tree
Hide file tree
Showing 11 changed files with 60 additions and 47 deletions.
12 changes: 7 additions & 5 deletions one_for_all_generator/lib/src/generators/swift_api_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -391,11 +391,13 @@ channel = FlutterMethodChannel(
channel.invokeMethod("${handler.channelName(e)}", arguments: [$parameters])''',
MethodApiType.async => '''
return try await withCheckedThrowingContinuation { continuation in
channel.invokeMethod("${handler.channelName(e)}", arguments: [$parameters]) { result in
if let result = result as? FlutterError {
continuation.resume(throwing: PlatformError(result.code, result.message, result.details))
} else {
continuation.resume(returning: ${returnType is VoidType ? '()' : codecs.encodeDeserialization(returnType, 'result')})
DispatchQueue.main.async {
self.channel.invokeMethod("${handler.channelName(e)}", arguments: [$parameters]) { result in
if let result = result as? FlutterError {
continuation.resume(throwing: PlatformError(result.code, result.message, result.details))
} else {
continuation.resume(returning: ${returnType is VoidType ? '()' : codecs.encodeDeserialization(returnType, 'result')})
}
}
}
}''',
Expand Down
3 changes: 3 additions & 0 deletions stripe_terminal/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@

## 2.1.2
- fix(ios): Executed fetch token and more actions on main thread

## 2.1.0
- docs: Documented readers (methods, classes) and payment intents (methods)
- feat: added `Readers.batteryStatus` field
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -856,23 +856,23 @@ enum class PaymentStatusApi {

data class ReaderApi(
val locationStatus: LocationStatusApi?,
val batteryLevel: Double,
val deviceType: DeviceTypeApi?,
val simulated: Boolean,
val availableUpdate: Boolean,
val locationId: String?,
val serialNumber: String,
val availableUpdate: Boolean,
val batteryLevel: Double,
val label: String?,
) {
fun serialize(): List<Any?> {
return listOf(
locationStatus?.ordinal,
batteryLevel,
deviceType?.ordinal,
simulated,
availableUpdate,
locationId,
serialNumber,
availableUpdate,
batteryLevel,
label,
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@
97C146E61CF9000F007C117D /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 1300;
LastUpgradeCheck = 1430;
ORGANIZATIONNAME = "";
TargetAttributes = {
331C8080294A63A400263BE5 = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1300"
LastUpgradeVersion = "1430"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
28 changes: 14 additions & 14 deletions stripe_terminal/example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ packages:
dependency: transitive
description:
name: collection
sha256: "4a07be6cb69c84d677a6c3096fcf960cc3285a8330b4603e0d463d15d9bd934c"
sha256: f092b211a4319e98e5ff58223576de6c2803db36221657b46c82574721240687
url: "https://pub.dev"
source: hosted
version: "1.17.1"
version: "1.17.2"
crypto:
dependency: transitive
description:
Expand Down Expand Up @@ -86,14 +86,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "4.0.2"
js:
dependency: transitive
description:
name: js
sha256: f2c445dce49627136094980615a031419f7f3eb393237e4ecd97ac15dea343f3
url: "https://pub.dev"
source: hosted
version: "0.6.7"
json_annotation:
dependency: transitive
description:
Expand Down Expand Up @@ -122,10 +114,10 @@ packages:
dependency: transitive
description:
name: material_color_utilities
sha256: d92141dc6fe1dad30722f9aa826c7fbc896d021d792f80678280601aff8cf724
sha256: "9528f2f296073ff54cb9fee677df673ace1218163c3bc7628093e7eed5203d41"
url: "https://pub.dev"
source: hosted
version: "0.2.0"
version: "0.5.0"
mek_data_class:
dependency: transitive
description:
Expand All @@ -148,7 +140,7 @@ packages:
path: ".."
relative: true
source: path
version: "1.0.0"
version: "2.1.2"
meta:
dependency: transitive
description:
Expand Down Expand Up @@ -314,6 +306,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.1.4"
web:
dependency: transitive
description:
name: web
sha256: dc8ccd225a2005c1be616fe02951e2e342092edf968cf0844220383757ef8f10
url: "https://pub.dev"
source: hosted
version: "0.1.4-beta"
sdks:
dart: ">=3.0.0 <4.0.0"
dart: ">=3.1.0-185.0.dev <4.0.0"
flutter: ">=3.10.0"
20 changes: 11 additions & 9 deletions stripe_terminal/ios/Classes/Api/StripeTerminalApi.swift
Original file line number Diff line number Diff line change
Expand Up @@ -480,11 +480,13 @@ class StripeTerminalHandlersApi {

func requestConnectionToken() async throws -> String {
return try await withCheckedThrowingContinuation { continuation in
channel.invokeMethod("_onRequestConnectionToken", arguments: []) { result in
if let result = result as? FlutterError {
continuation.resume(throwing: PlatformError(result.code, result.message, result.details))
} else {
continuation.resume(returning: result as! String)
DispatchQueue.main.async {
self.channel.invokeMethod("_onRequestConnectionToken", arguments: []) { result in
if let result = result as? FlutterError {
continuation.resume(throwing: PlatformError(result.code, result.message, result.details))
} else {
continuation.resume(returning: result as! String)
}
}
}
}
Expand Down Expand Up @@ -924,23 +926,23 @@ enum PaymentStatusApi: Int {

struct ReaderApi {
let locationStatus: LocationStatusApi?
let batteryLevel: Double
let deviceType: DeviceTypeApi?
let simulated: Bool
let availableUpdate: Bool
let locationId: String?
let serialNumber: String
let availableUpdate: Bool
let batteryLevel: Double
let label: String?

func serialize() -> [Any?] {
return [
locationStatus?.rawValue,
batteryLevel,
deviceType?.rawValue,
simulated,
availableUpdate,
locationId,
serialNumber,
availableUpdate,
batteryLevel,
label,
]
}
Expand Down
4 changes: 2 additions & 2 deletions stripe_terminal/ios/Classes/Api/ToApiExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ extension Reader {
func toApi() -> ReaderApi {
return ReaderApi(
locationStatus: locationStatus.toApi(),
batteryLevel: batteryLevel?.doubleValue ?? -1.0,
deviceType: deviceType.toApi(),
simulated: simulated,
availableUpdate: availableUpdate != nil,
locationId: locationId,
serialNumber: serialNumber,
availableUpdate: availableUpdate != nil,
batteryLevel: batteryLevel?.doubleValue ?? -1.0,
label: label
)
}
Expand Down
14 changes: 10 additions & 4 deletions stripe_terminal/ios/Classes/Plugin/TerminalDelegatePlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,24 @@ class TerminalDelegatePlugin: NSObject, ConnectionTokenProvider, TerminalDelegat
}

public func fetchConnectionToken() async throws -> String {
return try await handlers.requestConnectionToken()
return try await self.handlers.requestConnectionToken()
}

public func terminal(_: Terminal, didReportUnexpectedReaderDisconnect reader: Reader) {
handlers.unexpectedReaderDisconnect(reader: reader.toApi())
DispatchQueue.main.async {
self.handlers.unexpectedReaderDisconnect(reader: reader.toApi())
}
}

public func terminal(_: Terminal, didChangePaymentStatus status: PaymentStatus) {
handlers.paymentStatusChange(paymentStatus: status.toApi())
DispatchQueue.main.async {
self.handlers.paymentStatusChange(paymentStatus: status.toApi())
}
}

public func terminal(_: Terminal, didChangeConnectionStatus status: ConnectionStatus) {
handlers.connectionStatusChange(connectionStatus: status.toApi())
DispatchQueue.main.async {
self.handlers.connectionStatusChange(connectionStatus: status.toApi())
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion stripe_terminal/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: mek_stripe_terminal
description: A StripeTerminal plugin to discover readers, connect to them and process payments.
version: 2.1.0
version: 2.1.2
repository: https://github.com/BreX900/mek-packages/tree/main/stripe_terminal
topics:
- stripe-terminal
Expand Down

0 comments on commit b41d829

Please sign in to comment.