Skip to content

Commit

Permalink
Fix Order serialization for iOS (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
pavel-kuznetsov-hypertrack authored Aug 28, 2024
1 parent 6231235 commit b3baec4
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
5 changes: 4 additions & 1 deletion ios/Plugin/common/Serialization.swift
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,10 @@ func serializeIsInsideGeofence(_ isInsideGeofence: Result<Bool, HyperTrack.Locat
case let .success(success):
return [
keyType: typeSuccess,
keyValue: success,
keyValue: [
keyType: "isInsideGeofence",
keyValue: success,
],
]
case let .failure(failure):
return [
Expand Down
9 changes: 7 additions & 2 deletions src/HyperTrack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import type { OrderStatus } from './data_types/OrderStatus';
import type { Order } from './data_types/Order';
import type { OrdersInternal } from './data_types/internal/OrdersInternal';
import type { OrderInternal } from './data_types/internal/OrderInternal';
import { IsInsideGeofence } from './data_types/internal/IsInsideGeofence';

export const EVENT_ERRORS = 'errors';
export const EVENT_IS_AVAILABLE = 'isAvailable';
Expand Down Expand Up @@ -499,13 +500,17 @@ export default class HyperTrack {

/** @ignore */
private static deserializeIsInsideGeofence(
isInsideGeofence: Result<boolean, LocationErrorInternal>,
isInsideGeofence: Result<IsInsideGeofence, LocationErrorInternal>,
): Result<boolean, LocationError> {
switch (isInsideGeofence.type) {
case 'success':
let successValue = isInsideGeofence.value;
if (successValue.type !== 'isInsideGeofence') {
throw new Error(`Invalid isInsideGeofence: ${JSON.stringify(successValue)}`);
}
return {
type: 'success',
value: isInsideGeofence.value,
value: successValue.value,
};
case 'failure':
return {
Expand Down
4 changes: 4 additions & 0 deletions src/data_types/internal/IsInsideGeofence.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export type IsInsideGeofence = {
type: 'isInsideGeofence';
value: boolean;
};
3 changes: 2 additions & 1 deletion src/data_types/internal/OrderInternal.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { Result } from '../Result';
import type { LocationErrorInternal } from './LocationErrorInternal';
import type { IsInsideGeofence } from './IsInsideGeofence';

export type OrderInternal = {
orderHandle: string;
isInsideGeofence: Result<boolean, LocationErrorInternal>;
isInsideGeofence: Result<IsInsideGeofence, LocationErrorInternal>;
index: number;
};

0 comments on commit b3baec4

Please sign in to comment.