react-native-unit-components 1.0.2 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +75 -6
- package/android/src/main/AndroidManifest.xml +12 -1
- package/android/src/main/java/com/unitreactnativecomponents/UnitReactNativeComponentsPackage.kt +2 -1
- package/android/src/main/java/com/unitreactnativecomponents/sharepdf/UNSharePDF.kt +75 -0
- package/android/src/main/res/layout/un_black_add_to_googlepay_button.xml +2 -2
- package/android/src/main/res/layout/un_view_google_push_provisioning.xml +1 -13
- package/android/src/main/res/layout/un_white_add_to_googlepay_button.xml +1 -1
- package/android/src/main/res/layout/un_white_add_to_googlepay_button_no_shadow.xml +1 -1
- package/android/src/main/res/xml/file_paths.xml +4 -0
- package/ios/UnitReactNativeComponentsViewManager.m +0 -1
- package/ios/UnitReactNativeComponentsViewManager.swift +6 -2
- package/lib/commonjs/components/UNAccountComponent/UNAccountComponent.js +103 -0
- package/lib/commonjs/components/UNAccountComponent/UNAccountComponent.js.map +1 -0
- package/lib/commonjs/components/UNAccountComponent/UNAccountComponent.utils.js +47 -0
- package/lib/commonjs/components/UNAccountComponent/UNAccountComponent.utils.js.map +1 -0
- package/lib/commonjs/components/UNActivityComponent/UNActivityComponent.js +28 -4
- package/lib/commonjs/components/UNActivityComponent/UNActivityComponent.js.map +1 -1
- package/lib/commonjs/components/UNActivityComponent/UNActivityComponent.utils.js +19 -1
- package/lib/commonjs/components/UNActivityComponent/UNActivityComponent.utils.js.map +1 -1
- package/lib/commonjs/components/UNBookPaymentComponent/UNBookPaymentComponent.js +22 -10
- package/lib/commonjs/components/UNBookPaymentComponent/UNBookPaymentComponent.js.map +1 -1
- package/lib/commonjs/components/UNBookPaymentComponent/UNBookPaymentComponent.utils.js +4 -0
- package/lib/commonjs/components/UNBookPaymentComponent/UNBookPaymentComponent.utils.js.map +1 -1
- package/lib/commonjs/components/UNBottomSheetComponent/UNBottomSheetComponent.constants.js +3 -3
- package/lib/commonjs/components/UNBottomSheetComponent/UNBottomSheetComponent.constants.js.map +1 -1
- package/lib/commonjs/components/UNBottomSheetComponent/UNBottomSheetComponent.js +114 -46
- package/lib/commonjs/components/UNBottomSheetComponent/UNBottomSheetComponent.js.map +1 -1
- package/lib/commonjs/components/UNBottomSheetComponent/UNBottomSheetComponent.utils.js +4 -8
- package/lib/commonjs/components/UNBottomSheetComponent/UNBottomSheetComponent.utils.js.map +1 -1
- package/lib/commonjs/components/UNBottomSheetComponent/components/UNAddToWalletBottomSheetItem.js +95 -0
- package/lib/commonjs/components/UNBottomSheetComponent/components/UNAddToWalletBottomSheetItem.js.map +1 -0
- package/lib/commonjs/components/UNBottomSheetComponent/components/UNAddToWalletBottomSheetItem.styles.js +31 -0
- package/lib/commonjs/components/UNBottomSheetComponent/components/UNAddToWalletBottomSheetItem.styles.js.map +1 -0
- package/lib/commonjs/components/UNCardComponent/UNCardComponent.js +64 -7
- package/lib/commonjs/components/UNCardComponent/UNCardComponent.js.map +1 -1
- package/lib/commonjs/components/UNCardComponent/UNCardComponent.utils.js +62 -8
- package/lib/commonjs/components/UNCardComponent/UNCardComponent.utils.js.map +1 -1
- package/lib/commonjs/components/UNCardComponent/networking/common/UNNetworkConstants.js +20 -0
- package/lib/commonjs/components/UNCardComponent/networking/common/UNNetworkConstants.js.map +1 -0
- package/lib/commonjs/components/UNCardComponent/networking/requests/UNWalletPayloadRequest.js +42 -0
- package/lib/commonjs/components/UNCardComponent/networking/requests/UNWalletPayloadRequest.js.map +1 -0
- package/lib/commonjs/components/index.js +13 -0
- package/lib/commonjs/components/index.js.map +1 -1
- package/lib/commonjs/helpers/BottomSheet/BottomSheet.js +32 -12
- package/lib/commonjs/helpers/BottomSheet/BottomSheet.js.map +1 -1
- package/lib/commonjs/helpers/BottomSheet/BottomSheet.styles.js +1 -1
- package/lib/commonjs/helpers/BottomSheet/BottomSheet.styles.js.map +1 -1
- package/lib/commonjs/helpers/EventBus.js.map +1 -1
- package/lib/commonjs/messages/nativeMessages/cardMessage.js +36 -0
- package/lib/commonjs/messages/nativeMessages/cardMessage.js.map +1 -0
- package/lib/commonjs/messages/nativeMessages/index.js +0 -8
- package/lib/commonjs/messages/nativeMessages/index.js.map +1 -1
- package/lib/commonjs/messages/nativeMessages/sdkMessage.js +14 -0
- package/lib/commonjs/messages/nativeMessages/sdkMessage.js.map +1 -0
- package/lib/commonjs/messages/webMessages/unitMessages.js +1 -0
- package/lib/commonjs/messages/webMessages/unitMessages.js.map +1 -1
- package/lib/commonjs/nativeComponent/{UNNativeAddToWalletButton.js → UnitAddToWalletButton.js} +1 -1
- package/lib/commonjs/nativeComponent/UnitAddToWalletButton.js.map +1 -0
- package/lib/commonjs/scripts/html/bodyScript.js +22 -5
- package/lib/commonjs/scripts/html/bodyScript.js.map +1 -1
- package/lib/commonjs/sharedTypes/bookPayment.types.js.map +1 -1
- package/lib/commonjs/sharedTypes/card.types.js.map +1 -1
- package/lib/commonjs/sharedTypes/index.js +13 -0
- package/lib/commonjs/sharedTypes/index.js.map +1 -1
- package/lib/commonjs/sharedTypes/onLoadResponse.types.js +6 -0
- package/lib/commonjs/sharedTypes/onLoadResponse.types.js.map +1 -0
- package/lib/commonjs/sharedTypes/wallet.types.js +22 -0
- package/lib/commonjs/sharedTypes/wallet.types.js.map +1 -0
- package/lib/commonjs/unitSdkManager/UnitSdk.api.js +5 -3
- package/lib/commonjs/unitSdkManager/UnitSdk.api.js.map +1 -1
- package/lib/commonjs/unitSdkManager/UnitSdkManager.js +12 -2
- package/lib/commonjs/unitSdkManager/UnitSdkManager.js.map +1 -1
- package/lib/commonjs/webComponent/WebComponent.js +20 -8
- package/lib/commonjs/webComponent/WebComponent.js.map +1 -1
- package/lib/commonjs/webComponent/WebComponent.utils.js +41 -0
- package/lib/commonjs/webComponent/WebComponent.utils.js.map +1 -0
- package/lib/commonjs/webComponent/html.js +9 -1
- package/lib/commonjs/webComponent/html.js.map +1 -1
- package/lib/module/components/UNAccountComponent/UNAccountComponent.js +74 -0
- package/lib/module/components/UNAccountComponent/UNAccountComponent.js.map +1 -0
- package/lib/module/components/UNAccountComponent/UNAccountComponent.utils.js +26 -0
- package/lib/module/components/UNAccountComponent/UNAccountComponent.utils.js.map +1 -0
- package/lib/module/components/UNActivityComponent/UNActivityComponent.js +28 -6
- package/lib/module/components/UNActivityComponent/UNActivityComponent.js.map +1 -1
- package/lib/module/components/UNActivityComponent/UNActivityComponent.utils.js +10 -0
- package/lib/module/components/UNActivityComponent/UNActivityComponent.utils.js.map +1 -1
- package/lib/module/components/UNBookPaymentComponent/UNBookPaymentComponent.js +21 -10
- package/lib/module/components/UNBookPaymentComponent/UNBookPaymentComponent.js.map +1 -1
- package/lib/module/components/UNBookPaymentComponent/UNBookPaymentComponent.utils.js +3 -0
- package/lib/module/components/UNBookPaymentComponent/UNBookPaymentComponent.utils.js.map +1 -1
- package/lib/module/components/UNBottomSheetComponent/UNBottomSheetComponent.constants.js +1 -1
- package/lib/module/components/UNBottomSheetComponent/UNBottomSheetComponent.constants.js.map +1 -1
- package/lib/module/components/UNBottomSheetComponent/UNBottomSheetComponent.js +111 -46
- package/lib/module/components/UNBottomSheetComponent/UNBottomSheetComponent.js.map +1 -1
- package/lib/module/components/UNBottomSheetComponent/UNBottomSheetComponent.utils.js +5 -9
- package/lib/module/components/UNBottomSheetComponent/UNBottomSheetComponent.utils.js.map +1 -1
- package/lib/module/components/UNBottomSheetComponent/components/UNAddToWalletBottomSheetItem.js +68 -0
- package/lib/module/components/UNBottomSheetComponent/components/UNAddToWalletBottomSheetItem.js.map +1 -0
- package/lib/module/components/UNBottomSheetComponent/components/UNAddToWalletBottomSheetItem.styles.js +21 -0
- package/lib/module/components/UNBottomSheetComponent/components/UNAddToWalletBottomSheetItem.styles.js.map +1 -0
- package/lib/module/components/UNCardComponent/UNCardComponent.js +64 -9
- package/lib/module/components/UNCardComponent/UNCardComponent.js.map +1 -1
- package/lib/module/components/UNCardComponent/UNCardComponent.utils.js +51 -7
- package/lib/module/components/UNCardComponent/UNCardComponent.utils.js.map +1 -1
- package/lib/module/components/UNCardComponent/networking/common/UNNetworkConstants.js +10 -0
- package/lib/module/components/UNCardComponent/networking/common/UNNetworkConstants.js.map +1 -0
- package/lib/module/components/UNCardComponent/networking/requests/UNWalletPayloadRequest.js +28 -0
- package/lib/module/components/UNCardComponent/networking/requests/UNWalletPayloadRequest.js.map +1 -0
- package/lib/module/components/index.js +1 -0
- package/lib/module/components/index.js.map +1 -1
- package/lib/module/helpers/BottomSheet/BottomSheet.js +30 -13
- package/lib/module/helpers/BottomSheet/BottomSheet.js.map +1 -1
- package/lib/module/helpers/BottomSheet/BottomSheet.styles.js +2 -2
- package/lib/module/helpers/BottomSheet/BottomSheet.styles.js.map +1 -1
- package/lib/module/helpers/EventBus.js.map +1 -1
- package/lib/module/messages/nativeMessages/cardMessage.js +27 -0
- package/lib/module/messages/nativeMessages/cardMessage.js.map +1 -0
- package/lib/module/messages/nativeMessages/index.js +1 -6
- package/lib/module/messages/nativeMessages/index.js.map +1 -1
- package/lib/module/messages/nativeMessages/sdkMessage.js +7 -0
- package/lib/module/messages/nativeMessages/sdkMessage.js.map +1 -0
- package/lib/module/messages/webMessages/unitMessages.js +1 -0
- package/lib/module/messages/webMessages/unitMessages.js.map +1 -1
- package/lib/module/nativeComponent/{UNNativeAddToWalletButton.js → UnitAddToWalletButton.js} +1 -1
- package/lib/module/nativeComponent/UnitAddToWalletButton.js.map +1 -0
- package/lib/module/scripts/html/bodyScript.js +19 -3
- package/lib/module/scripts/html/bodyScript.js.map +1 -1
- package/lib/module/sharedTypes/bookPayment.types.js.map +1 -1
- package/lib/module/sharedTypes/card.types.js.map +1 -1
- package/lib/module/sharedTypes/index.js +1 -0
- package/lib/module/sharedTypes/index.js.map +1 -1
- package/lib/module/sharedTypes/onLoadResponse.types.js +2 -0
- package/lib/module/sharedTypes/onLoadResponse.types.js.map +1 -0
- package/lib/module/sharedTypes/wallet.types.js +14 -0
- package/lib/module/sharedTypes/wallet.types.js.map +1 -0
- package/lib/module/unitSdkManager/UnitSdk.api.js +4 -3
- package/lib/module/unitSdkManager/UnitSdk.api.js.map +1 -1
- package/lib/module/unitSdkManager/UnitSdkManager.js +12 -2
- package/lib/module/unitSdkManager/UnitSdkManager.js.map +1 -1
- package/lib/module/webComponent/WebComponent.js +18 -7
- package/lib/module/webComponent/WebComponent.js.map +1 -1
- package/lib/module/webComponent/WebComponent.utils.js +27 -0
- package/lib/module/webComponent/WebComponent.utils.js.map +1 -0
- package/lib/module/webComponent/html.js +9 -2
- package/lib/module/webComponent/html.js.map +1 -1
- package/lib/typescript/components/UNAccountComponent/UNAccountComponent.d.ts +12 -0
- package/lib/typescript/components/UNAccountComponent/UNAccountComponent.utils.d.ts +7 -0
- package/lib/typescript/components/UNActivityComponent/UNActivityComponent.d.ts +2 -0
- package/lib/typescript/components/UNActivityComponent/UNActivityComponent.utils.d.ts +4 -0
- package/lib/typescript/components/UNBookPaymentComponent/UNBookPaymentComponent.d.ts +2 -1
- package/lib/typescript/components/UNBottomSheetComponent/UNBottomSheetComponent.constants.d.ts +1 -1
- package/lib/typescript/components/UNBottomSheetComponent/UNBottomSheetComponent.d.ts +9 -2
- package/lib/typescript/components/UNBottomSheetComponent/UNBottomSheetComponent.utils.d.ts +2 -1
- package/lib/typescript/components/UNBottomSheetComponent/components/UNAddToWalletBottomSheetItem.d.ts +6 -0
- package/lib/typescript/components/UNBottomSheetComponent/components/UNAddToWalletBottomSheetItem.styles.d.ts +17 -0
- package/lib/typescript/components/UNCardComponent/UNCardComponent.d.ts +4 -1
- package/lib/typescript/components/UNCardComponent/UNCardComponent.utils.d.ts +9 -1
- package/lib/typescript/components/UNCardComponent/networking/common/UNNetworkConstants.d.ts +8 -0
- package/lib/typescript/components/UNCardComponent/networking/requests/UNWalletPayloadRequest.d.ts +2 -0
- package/lib/typescript/components/index.d.ts +1 -0
- package/lib/typescript/helpers/EventBus.d.ts +3 -3
- package/lib/typescript/messages/nativeMessages/cardMessage.d.ts +28 -0
- package/lib/typescript/messages/nativeMessages/index.d.ts +7 -3
- package/lib/typescript/messages/nativeMessages/sdkMessage.d.ts +8 -0
- package/lib/typescript/messages/webMessages/unitMessages.d.ts +16 -6
- package/lib/typescript/scripts/html/bodyScript.d.ts +4 -1
- package/lib/typescript/sharedTypes/bookPayment.types.d.ts +3 -3
- package/lib/typescript/sharedTypes/card.types.d.ts +6 -6
- package/lib/typescript/sharedTypes/index.d.ts +1 -0
- package/lib/typescript/sharedTypes/onLoadResponse.types.d.ts +18 -0
- package/lib/typescript/sharedTypes/wallet.types.d.ts +14 -0
- package/lib/typescript/unitSdkManager/UnitSdkManager.d.ts +3 -0
- package/lib/typescript/webComponent/WebComponent.d.ts +2 -1
- package/lib/typescript/webComponent/WebComponent.utils.d.ts +2 -0
- package/package.json +2 -1
- package/src/components/UNAccountComponent/UNAccountComponent.tsx +82 -0
- package/src/components/UNAccountComponent/UNAccountComponent.utils.ts +30 -0
- package/src/components/UNActivityComponent/UNActivityComponent.tsx +28 -5
- package/src/components/UNActivityComponent/UNActivityComponent.utils.ts +14 -0
- package/src/components/UNBookPaymentComponent/UNBookPaymentComponent.tsx +18 -10
- package/src/components/UNBookPaymentComponent/UNBookPaymentComponent.utils.ts +3 -0
- package/src/components/UNBottomSheetComponent/UNBottomSheetComponent.constants.ts +1 -1
- package/src/components/UNBottomSheetComponent/UNBottomSheetComponent.tsx +120 -44
- package/src/components/UNBottomSheetComponent/UNBottomSheetComponent.utils.ts +7 -10
- package/src/components/UNBottomSheetComponent/components/UNAddToWalletBottomSheetItem.styles.ts +21 -0
- package/src/components/UNBottomSheetComponent/components/UNAddToWalletBottomSheetItem.tsx +74 -0
- package/src/components/UNCardComponent/UNCardComponent.tsx +67 -13
- package/src/components/UNCardComponent/UNCardComponent.utils.ts +51 -7
- package/src/components/UNCardComponent/networking/common/UNNetworkConstants.ts +11 -0
- package/src/components/UNCardComponent/networking/requests/UNWalletPayloadRequest.ts +32 -0
- package/src/components/index.ts +1 -0
- package/src/helpers/BottomSheet/BottomSheet.styles.ts +2 -2
- package/src/helpers/BottomSheet/BottomSheet.tsx +28 -12
- package/src/helpers/EventBus.ts +3 -3
- package/src/messages/nativeMessages/cardMessage.ts +37 -0
- package/src/messages/nativeMessages/index.ts +14 -3
- package/src/messages/nativeMessages/sdkMessage.ts +11 -0
- package/src/messages/webMessages/unitMessages.ts +20 -7
- package/src/scripts/html/bodyScript.ts +21 -4
- package/src/sharedTypes/bookPayment.types.ts +3 -3
- package/src/sharedTypes/card.types.ts +6 -6
- package/src/sharedTypes/index.ts +1 -0
- package/src/sharedTypes/onLoadResponse.types.ts +27 -0
- package/src/sharedTypes/wallet.types.ts +17 -0
- package/src/unitSdkManager/UnitSdk.api.ts +3 -2
- package/src/unitSdkManager/UnitSdkManager.ts +11 -2
- package/src/webComponent/WebComponent.tsx +21 -10
- package/src/webComponent/WebComponent.utils.ts +26 -0
- package/src/webComponent/html.ts +9 -2
- package/lib/commonjs/nativeComponent/UNNativeAddToWalletButton.js.map +0 -1
- package/lib/module/nativeComponent/UNNativeAddToWalletButton.js.map +0 -1
- /package/lib/typescript/nativeComponent/{UNNativeAddToWalletButton.d.ts → UnitAddToWalletButton.d.ts} +0 -0
- /package/src/nativeComponent/{UNNativeAddToWalletButton.tsx → UnitAddToWalletButton.tsx} +0 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import React, {
|
|
2
|
-
import { Dimensions, View } from 'react-native';
|
|
1
|
+
import React, { useRef, useState } from 'react';
|
|
2
|
+
import { Dimensions, NativeModule, View } from 'react-native';
|
|
3
3
|
import type WebView from 'react-native-webview';
|
|
4
4
|
import { HeightEvent, PageMessage } from '../../messages/webMessages/pageMessage';
|
|
5
5
|
import { RequestRefreshEvent, RequestRenderingEvent, UnitMessage } from '../../messages/webMessages/unitMessages';
|
|
@@ -7,22 +7,28 @@ import EventBus from '../../helpers/EventBus';
|
|
|
7
7
|
import { WebComponent, WebComponentType } from '../../webComponent/WebComponent';
|
|
8
8
|
import { useListenerToBus } from '../../hooks/listenerToBus';
|
|
9
9
|
import type { WebViewMessage } from '../../messages/webMessages';
|
|
10
|
-
import { getCardParams, getCardScript, injectRefreshEventIfNeeded } from './UNCardComponent.utils';
|
|
10
|
+
import { getCardParams, getCardScript, injectRefreshEventIfNeeded, launchStartCardProvisioning } from './UNCardComponent.utils';
|
|
11
11
|
import { PresentationMode } from '../../scripts/html/bodyHtml';
|
|
12
|
-
import type { UNCardData } from '../../sharedTypes';
|
|
12
|
+
import type { ResponseUnitOnLoadEvent, UNCardData } from '../../sharedTypes';
|
|
13
13
|
import { CardMessage } from '../../messages/webMessages/cardMessage';
|
|
14
|
-
|
|
14
|
+
import { launchGetWallets } from './UNCardComponent.utils';
|
|
15
|
+
import type { NativeModules } from 'react-native';
|
|
16
|
+
import type { UNWallet } from 'src/sharedTypes/wallet.types';
|
|
17
|
+
import { CardAddToWalletErrors, CardAddToWalletStatusEvent, CardGetAddToWalletStatusEvent, CardNativeMessage, CardStartPushProvisioningEvent } from '../../messages/nativeMessages/cardMessage';
|
|
18
|
+
import type { BottomSheetSlotData } from '../UNBottomSheetComponent/UNBottomSheetComponent';
|
|
15
19
|
export interface UNCardComponentProps {
|
|
16
20
|
cardId: string;
|
|
17
21
|
customerToken: string;
|
|
18
22
|
theme?: string;
|
|
19
23
|
onStatusChanged?: (card: UNCardData) => void;
|
|
24
|
+
pushProvisioningModule?: typeof NativeModules;
|
|
25
|
+
onLoad?: (response: ResponseUnitOnLoadEvent) => void
|
|
20
26
|
}
|
|
21
27
|
|
|
22
28
|
export const UNCardComponent = (props: UNCardComponentProps) => {
|
|
23
29
|
const [height, setHeight] = useState(0);
|
|
24
|
-
const [requestRefreshEvent, setRequestRefreshEvent] = useState<RequestRefreshEvent | null>(null);
|
|
25
30
|
const windowWidth = Dimensions.get('window').width;
|
|
31
|
+
const walletRef = useRef<UNWallet | null>(null);
|
|
26
32
|
|
|
27
33
|
const webRef = useRef<WebView>(null);
|
|
28
34
|
|
|
@@ -33,26 +39,74 @@ export const UNCardComponent = (props: UNCardComponentProps) => {
|
|
|
33
39
|
};
|
|
34
40
|
|
|
35
41
|
const requestRefresh = (data: RequestRefreshEvent) => {
|
|
36
|
-
|
|
42
|
+
injectRefreshEventIfNeeded(webRef.current, data, props.cardId);
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const startPushProvisioning = async (data: CardStartPushProvisioningEvent) => {
|
|
46
|
+
if (data.cardId !== props.cardId) return;
|
|
47
|
+
onAddToWalletClicked();
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const getAddToWalletStatus = (data: CardGetAddToWalletStatusEvent) => {
|
|
51
|
+
if (data.cardId !== props.cardId) return;
|
|
52
|
+
getWallets();
|
|
37
53
|
};
|
|
38
54
|
|
|
39
55
|
useListenerToBus([
|
|
40
56
|
{ busEventKey: CardMessage.CARD_STATUS_CHANGED, action: cardStatusChanged },
|
|
41
57
|
{ busEventKey: UnitMessage.UNIT_REQUEST_REFRESH, action: requestRefresh },
|
|
58
|
+
{ busEventKey: CardNativeMessage.CARD_START_PUSH_PROVISIONING, action: startPushProvisioning },
|
|
59
|
+
{ busEventKey: CardNativeMessage.CARD_GET_ADD_TO_WALLET_STATUS, action: getAddToWalletStatus }
|
|
42
60
|
]);
|
|
43
61
|
|
|
44
|
-
useEffect(() => {
|
|
45
|
-
injectRefreshEventIfNeeded(webRef.current, requestRefreshEvent, props.cardId);
|
|
46
|
-
}, [requestRefreshEvent]);
|
|
47
|
-
|
|
48
62
|
const handleMessage = (message: WebViewMessage) => {
|
|
63
|
+
if (!message || !message.details) return;
|
|
64
|
+
|
|
49
65
|
switch (message.type) {
|
|
50
|
-
case UnitMessage.UNIT_REQUEST_RENDERING:
|
|
51
|
-
|
|
66
|
+
case UnitMessage.UNIT_REQUEST_RENDERING: {
|
|
67
|
+
const event: BottomSheetSlotData = {
|
|
68
|
+
componentName: WebComponentType.card,
|
|
69
|
+
componentResourceId: props.cardId,
|
|
70
|
+
requestRenderingEvent: message.details as RequestRenderingEvent
|
|
71
|
+
};
|
|
72
|
+
EventBus.Instance.event(UnitMessage.UNIT_REQUEST_RENDERING, event);
|
|
52
73
|
break;
|
|
74
|
+
}
|
|
53
75
|
case PageMessage.PAGE_HEIGHT:
|
|
54
76
|
setHeight((message.details as HeightEvent).height);
|
|
55
77
|
break;
|
|
78
|
+
case UnitMessage.UNIT_ON_LOAD:
|
|
79
|
+
props.onLoad && props.onLoad(message.details as ResponseUnitOnLoadEvent);
|
|
80
|
+
break;
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
const getWallets = async () => {
|
|
85
|
+
|
|
86
|
+
try {
|
|
87
|
+
|
|
88
|
+
const walletResponse = await launchGetWallets(props.customerToken, props.cardId, props.pushProvisioningModule as NativeModule);
|
|
89
|
+
|
|
90
|
+
if (!walletResponse) return;
|
|
91
|
+
|
|
92
|
+
walletRef.current = walletResponse;
|
|
93
|
+
|
|
94
|
+
const walletStatus: CardAddToWalletStatusEvent = { status: walletResponse.status };
|
|
95
|
+
EventBus.Instance.event(CardNativeMessage.CARD_UPDATE_ADD_TO_WALLET_STATUS, walletStatus);
|
|
96
|
+
} catch (error) {
|
|
97
|
+
console.error(error);
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
const onAddToWalletClicked = async () => {
|
|
102
|
+
try {
|
|
103
|
+
await launchStartCardProvisioning(props.pushProvisioningModule as NativeModule, walletRef.current);
|
|
104
|
+
} catch (error) {
|
|
105
|
+
if (error instanceof Error) {
|
|
106
|
+
const parsedError = JSON.parse(error.message);
|
|
107
|
+
if (parsedError.code === CardAddToWalletErrors.closedNativeWalletScreen) return;
|
|
108
|
+
}
|
|
109
|
+
console.log(error);
|
|
56
110
|
}
|
|
57
111
|
};
|
|
58
112
|
|
|
@@ -1,22 +1,23 @@
|
|
|
1
|
+
import { DISPATCH_REQUEST_REFRESH } from './../../scripts/html/bodyScript';
|
|
1
2
|
import type WebView from 'react-native-webview';
|
|
2
3
|
import type { UNCardComponentProps } from './UNCardComponent';
|
|
3
4
|
import { WebComponentType } from '../../webComponent/WebComponent';
|
|
4
|
-
import {
|
|
5
|
+
import type { NativeModules } from 'react-native';
|
|
6
|
+
import { getMobileWalletPayload } from './networking/requests/UNWalletPayloadRequest';
|
|
7
|
+
import { UNWallet, UNWalletCode, UNWalletName } from '../../../src/sharedTypes/wallet.types';
|
|
8
|
+
import type { RequestRefreshEvent } from '../../messages/webMessages/unitMessages';
|
|
9
|
+
import { UnitSDK } from '../../unitSdkManager/UnitSdkManager';
|
|
5
10
|
|
|
6
11
|
export const getCardParams = (props: UNCardComponentProps) => {
|
|
7
12
|
return `
|
|
8
13
|
card-id="${props.cardId}"
|
|
9
14
|
customer-token="${props.customerToken}"
|
|
15
|
+
enable-mobile-wallet="${!!props.pushProvisioningModule}"
|
|
10
16
|
`;
|
|
11
17
|
};
|
|
12
18
|
|
|
13
19
|
export const getCardScript = () => {
|
|
14
|
-
return
|
|
15
|
-
const dispatchRefreshEvent = (details) => {
|
|
16
|
-
const event = new CustomEvent("${UnitMessage.UNIT_REQUEST_REFRESH}",{ detail: JSON.parse(details) })
|
|
17
|
-
window.dispatchEvent(event)
|
|
18
|
-
}
|
|
19
|
-
`;
|
|
20
|
+
return DISPATCH_REQUEST_REFRESH;
|
|
20
21
|
};
|
|
21
22
|
|
|
22
23
|
export const injectRefreshEventIfNeeded = (currentWeb: WebView | null, requestRefreshEvent: RequestRefreshEvent | null, cardId: string) => {
|
|
@@ -24,3 +25,46 @@ export const injectRefreshEventIfNeeded = (currentWeb: WebView | null, requestRe
|
|
|
24
25
|
currentWeb?.injectJavaScript(`dispatchRefreshEvent('${JSON.stringify(requestRefreshEvent)}')`);
|
|
25
26
|
}
|
|
26
27
|
};
|
|
28
|
+
|
|
29
|
+
export const launchGetWallets = async (customerToken: string, cardId: string, pushProvisioningModule: typeof NativeModules) => {
|
|
30
|
+
try {
|
|
31
|
+
const env = UnitSDK.getEnv();
|
|
32
|
+
if (!env) return null;
|
|
33
|
+
|
|
34
|
+
const encryptedPayload = await getMobileWalletPayload(customerToken, cardId, env);
|
|
35
|
+
if (!encryptedPayload) return null;
|
|
36
|
+
|
|
37
|
+
const walletsResponse = await pushProvisioningModule.launchGetWallets(JSON.stringify({ encPayload: encryptedPayload }));
|
|
38
|
+
const parsedWalletsResponse = JSON.parse(walletsResponse);
|
|
39
|
+
const wallets = parsedWalletsResponse.wallets;
|
|
40
|
+
|
|
41
|
+
if (!wallets) return null;
|
|
42
|
+
if (wallets[0].code === UNWalletCode.Apple) {
|
|
43
|
+
return ({ name: UNWalletName.Apple, code: UNWalletCode.Apple, status: wallets[0].status });
|
|
44
|
+
} else {
|
|
45
|
+
const googleWallet = wallets.filter((wallet: { name: UNWalletName }) => {
|
|
46
|
+
return wallet.name === UNWalletName.Google;
|
|
47
|
+
});
|
|
48
|
+
if (!googleWallet) return;
|
|
49
|
+
return ({ name: UNWalletName.Google, code: UNWalletCode.Google, status: googleWallet[0].status });
|
|
50
|
+
}
|
|
51
|
+
} catch (error) {
|
|
52
|
+
return Promise.reject(error);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
export const launchStartCardProvisioning = async (pushProvisioningModule: typeof NativeModules, wallet: UNWallet | null) => {
|
|
58
|
+
try {
|
|
59
|
+
const response = await pushProvisioningModule.launchStartCardProvisioning(
|
|
60
|
+
JSON.stringify({
|
|
61
|
+
walletCode: wallet?.code,
|
|
62
|
+
walletName: wallet?.name
|
|
63
|
+
}));
|
|
64
|
+
return response;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
catch (error) {
|
|
68
|
+
return Promise.reject(error);
|
|
69
|
+
}
|
|
70
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { UNEnvironment } from '../../../../unitSdkManager/UnitSdkManager';
|
|
2
|
+
|
|
3
|
+
export const APIHeaders = {
|
|
4
|
+
AUTHORIZATION: 'Authorization',
|
|
5
|
+
CONTENT_TYPE: 'application/vnd.api+json',
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export const UNIT_SECURE_URL = {
|
|
9
|
+
[UNEnvironment.sandbox]: 'https://secure.api.s.unit.sh',
|
|
10
|
+
[UNEnvironment.production]: 'https://secure.api.unit.co'
|
|
11
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
import { APIHeaders, UNIT_SECURE_URL } from '../common/UNNetworkConstants';
|
|
3
|
+
import { UNEnvironment, UnitSDK } from 'react-native-unit-components';
|
|
4
|
+
|
|
5
|
+
export const getMobileWalletPayload = async (customerToken: string, cardId: string, env: UNEnvironment) => {
|
|
6
|
+
const headers = {
|
|
7
|
+
'Content-Type': APIHeaders.CONTENT_TYPE,
|
|
8
|
+
'Authorization': `Bearer ${customerToken}`,
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
const data = {
|
|
12
|
+
data: {
|
|
13
|
+
attributes: {
|
|
14
|
+
signedNonce: UnitSDK.getSignedNonce(),
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const baseURL = `${UNIT_SECURE_URL[env as keyof typeof UNEnvironment]}/cards/${cardId}/mobile-wallet-payload`;
|
|
20
|
+
try {
|
|
21
|
+
const response = await axios.post(
|
|
22
|
+
baseURL,
|
|
23
|
+
data,
|
|
24
|
+
{
|
|
25
|
+
headers: headers,
|
|
26
|
+
});
|
|
27
|
+
const encryptedPayload = response.data.data.attributes.payload;
|
|
28
|
+
return encryptedPayload;
|
|
29
|
+
} catch (error) {
|
|
30
|
+
return Promise.reject(error);
|
|
31
|
+
}
|
|
32
|
+
};
|
package/src/components/index.ts
CHANGED
|
@@ -2,3 +2,4 @@ export * from './UNCardComponent/UNCardComponent';
|
|
|
2
2
|
export * from './UNBottomSheetComponent/UNBottomSheetComponent';
|
|
3
3
|
export * from './UNBookPaymentComponent/UNBookPaymentComponent';
|
|
4
4
|
export * from './UNActivityComponent/UNActivityComponent';
|
|
5
|
+
export * from './UNAccountComponent/UNAccountComponent';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Dimensions, StyleSheet } from 'react-native';
|
|
2
|
-
import {
|
|
2
|
+
import { BOTTOM_SHEET_MAX_PERCENTAGE_SIZE } from '../../components/UNBottomSheetComponent/UNBottomSheetComponent.constants';
|
|
3
3
|
import { VARIABLES } from '../../styles/variables';
|
|
4
4
|
|
|
5
5
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -20,7 +20,7 @@ export const getStylesObject = (fadeAnim: any) => {
|
|
|
20
20
|
container: {
|
|
21
21
|
position: 'relative',
|
|
22
22
|
flex: 1,
|
|
23
|
-
marginTop: Dimensions.get('window').height * (1 -
|
|
23
|
+
marginTop: Dimensions.get('window').height * (1 - BOTTOM_SHEET_MAX_PERCENTAGE_SIZE),
|
|
24
24
|
shadowColor: VARIABLES.COLORS.BLACK,
|
|
25
25
|
shadowOffset: {
|
|
26
26
|
width: 0,
|
|
@@ -13,8 +13,9 @@ import {
|
|
|
13
13
|
} from 'react-native';
|
|
14
14
|
import PropTypes from 'prop-types';
|
|
15
15
|
import { CloseIcon } from '../../assets/images';
|
|
16
|
-
import {
|
|
16
|
+
import { BOTTOM_SHEET_MAX_PERCENTAGE_SIZE } from '../../components/UNBottomSheetComponent/UNBottomSheetComponent.constants';
|
|
17
17
|
import { getStylesObject } from './BottomSheet.styles';
|
|
18
|
+
import { useAppStateListener } from '../../hooks/useAppStateListener';
|
|
18
19
|
|
|
19
20
|
export interface BottomSheetProps {
|
|
20
21
|
isOpen: boolean
|
|
@@ -40,6 +41,8 @@ const BottomSheet = (props: BottomSheetProps) => {
|
|
|
40
41
|
|
|
41
42
|
const [dy, setDy] = useState(0);
|
|
42
43
|
|
|
44
|
+
const isAppActive = useAppStateListener();
|
|
45
|
+
|
|
43
46
|
const _parentPanResponder = PanResponder.create({
|
|
44
47
|
onMoveShouldSetPanResponderCapture: (_, gestureState) => {
|
|
45
48
|
return props.shouldEnableBottomSheetScroll && Math.abs(gestureState.dy) > 10;
|
|
@@ -66,6 +69,13 @@ const BottomSheet = (props: BottomSheetProps) => {
|
|
|
66
69
|
}
|
|
67
70
|
});
|
|
68
71
|
|
|
72
|
+
useEffect(() => {
|
|
73
|
+
if (!isAppActive && isPanelOpened) {
|
|
74
|
+
setContentHeight(0);
|
|
75
|
+
_dismiss(false);
|
|
76
|
+
}
|
|
77
|
+
}, [isAppActive]);
|
|
78
|
+
|
|
69
79
|
useEffect(() => {
|
|
70
80
|
if (props.isOpen && !isPanelOpened) {
|
|
71
81
|
fadeIn();
|
|
@@ -86,21 +96,27 @@ const BottomSheet = (props: BottomSheetProps) => {
|
|
|
86
96
|
}, []);
|
|
87
97
|
|
|
88
98
|
const fadeIn = () => {
|
|
99
|
+
setIsPanelOpened(true);
|
|
89
100
|
Animated.timing(fadeAnim, {
|
|
90
101
|
toValue: 0.3,
|
|
91
102
|
duration: 500,
|
|
92
103
|
useNativeDriver: false
|
|
93
|
-
}).start(
|
|
104
|
+
}).start();
|
|
94
105
|
};
|
|
95
106
|
|
|
96
|
-
const fadeOut = () => {
|
|
107
|
+
const fadeOut = (withTimeout = true) => {
|
|
108
|
+
/*
|
|
109
|
+
withTimeout - most of the time we declare 'Close' after the animation is end.
|
|
110
|
+
In a case that the app is not active we do it without timeout. (Otherwise a race condition may occur.)
|
|
111
|
+
*/
|
|
112
|
+
setIsPanelOpened(false);
|
|
113
|
+
!withTimeout && props.onClose();
|
|
97
114
|
Animated.timing(fadeAnim, {
|
|
98
115
|
toValue: 0,
|
|
99
116
|
duration: 500,
|
|
100
117
|
useNativeDriver: false
|
|
101
118
|
}).start(() => {
|
|
102
|
-
|
|
103
|
-
props.onClose();
|
|
119
|
+
withTimeout && props.onClose();
|
|
104
120
|
});
|
|
105
121
|
};
|
|
106
122
|
|
|
@@ -115,7 +131,7 @@ const BottomSheet = (props: BottomSheetProps) => {
|
|
|
115
131
|
|
|
116
132
|
const expand = () => {
|
|
117
133
|
const { animationDuration } = props;
|
|
118
|
-
|
|
134
|
+
props.onOpen();
|
|
119
135
|
if (contentHeight && currentHeight > (sliderMaxHeight - contentHeight)) {
|
|
120
136
|
setToContentHeight(contentHeight);
|
|
121
137
|
return;
|
|
@@ -150,7 +166,7 @@ const BottomSheet = (props: BottomSheetProps) => {
|
|
|
150
166
|
setToContentHeight(newContentHeight);
|
|
151
167
|
};
|
|
152
168
|
|
|
153
|
-
const _dismiss = () => {
|
|
169
|
+
const _dismiss = (withTimeout = true) => {
|
|
154
170
|
const { animationDuration } = props;
|
|
155
171
|
Animated.timing(panelHeightValue, {
|
|
156
172
|
duration: animationDuration,
|
|
@@ -160,7 +176,7 @@ const BottomSheet = (props: BottomSheetProps) => {
|
|
|
160
176
|
}).start(() => {
|
|
161
177
|
null;
|
|
162
178
|
});
|
|
163
|
-
fadeOut();
|
|
179
|
+
fadeOut(withTimeout);
|
|
164
180
|
};
|
|
165
181
|
|
|
166
182
|
const {
|
|
@@ -172,7 +188,7 @@ const BottomSheet = (props: BottomSheetProps) => {
|
|
|
172
188
|
<>
|
|
173
189
|
<TouchableOpacity
|
|
174
190
|
style={styles.outsideContainer} activeOpacity={1}
|
|
175
|
-
onPress={_dismiss}
|
|
191
|
+
onPress={() => _dismiss()}
|
|
176
192
|
>
|
|
177
193
|
<Animated.View
|
|
178
194
|
style={styles.animation}
|
|
@@ -195,7 +211,7 @@ const BottomSheet = (props: BottomSheetProps) => {
|
|
|
195
211
|
<TouchableOpacity
|
|
196
212
|
activeOpacity={1}
|
|
197
213
|
style={styles.closeButton}
|
|
198
|
-
onPress={_dismiss}
|
|
214
|
+
onPress={() => _dismiss()}
|
|
199
215
|
>
|
|
200
216
|
<Image source={CloseIcon} />
|
|
201
217
|
</TouchableOpacity>
|
|
@@ -206,7 +222,7 @@ const BottomSheet = (props: BottomSheetProps) => {
|
|
|
206
222
|
<KeyboardAvoidingView
|
|
207
223
|
behavior="padding"
|
|
208
224
|
style={{ height: props.height }}
|
|
209
|
-
keyboardVerticalOffset={props.height * (1 -
|
|
225
|
+
keyboardVerticalOffset={props.height * (1 - BOTTOM_SHEET_MAX_PERCENTAGE_SIZE)}
|
|
210
226
|
>
|
|
211
227
|
{children}
|
|
212
228
|
</KeyboardAvoidingView>
|
|
@@ -231,7 +247,7 @@ BottomSheet.propTypes = {
|
|
|
231
247
|
BottomSheet.defaultProps = {
|
|
232
248
|
children: <View />,
|
|
233
249
|
isOpen: true,
|
|
234
|
-
sliderMaxHeight: Dimensions.get('window').height *
|
|
250
|
+
sliderMaxHeight: Dimensions.get('window').height * BOTTOM_SHEET_MAX_PERCENTAGE_SIZE,
|
|
235
251
|
animationDuration: 200,
|
|
236
252
|
onOpen: () => null,
|
|
237
253
|
onClose: () => null,
|
package/src/helpers/EventBus.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
-
import type {
|
|
2
|
+
import type { NativeMessageType } from '../messages/nativeMessages';
|
|
3
3
|
import type { WebViewMessageType } from '../messages/webMessages';
|
|
4
4
|
|
|
5
|
-
export type BusEventKey =
|
|
5
|
+
export type BusEventKey = NativeMessageType | WebViewMessageType
|
|
6
6
|
|
|
7
7
|
export default class EventBus {
|
|
8
8
|
private static _instance: EventBus;
|
|
@@ -17,7 +17,7 @@ export default class EventBus {
|
|
|
17
17
|
return this._instance || (this._instance = new this());
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
public event(event: BusEventKey, data
|
|
20
|
+
public event(event: BusEventKey, data?: any) {
|
|
21
21
|
const listeners = this.eventListeners[event.valueOf()];
|
|
22
22
|
if (Array.isArray(listeners)) {
|
|
23
23
|
listeners.map(listener => {
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export enum CardNativeMessage {
|
|
2
|
+
CARD_GET_ADD_TO_WALLET_STATUS = 'cardGetAddToWalletStatus',
|
|
3
|
+
CARD_UPDATE_ADD_TO_WALLET_STATUS = 'cardUpdateAddToWalletStatus',
|
|
4
|
+
CARD_START_PUSH_PROVISIONING = 'cardStartPushProvisioning'
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export enum CardAddToWalletStatus {
|
|
8
|
+
pending,
|
|
9
|
+
readyToProvisioning = 'ReadyToProvision',
|
|
10
|
+
addedToWallet = 'AlreadyProvisioned',
|
|
11
|
+
iosProvisionedInCurrentDevice = 'ProvisionedInCurrentDevice',
|
|
12
|
+
iosProvisionedInPairedDevice = 'ProvisionedInPairedDevice',
|
|
13
|
+
androidNotInstalled = 'NotInstalled',
|
|
14
|
+
androidWalletSetupNotCompleted = 'WalletSetupNotCompleted',
|
|
15
|
+
androidWalletAppUpdateAvailable = 'WalletAppUpdateAvailable'
|
|
16
|
+
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export enum CardAddToWalletErrors {
|
|
20
|
+
closedNativeWalletScreen = 'VP_ERROR_302'
|
|
21
|
+
}
|
|
22
|
+
export interface CardAddToWalletStatusEvent {
|
|
23
|
+
status: CardAddToWalletStatus
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface CardGetAddToWalletStatusEvent {
|
|
27
|
+
cardId: string
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface CardStartPushProvisioningEvent {
|
|
31
|
+
cardId: string
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export type CardNativeEvent =
|
|
35
|
+
| CardAddToWalletStatusEvent
|
|
36
|
+
| CardGetAddToWalletStatusEvent
|
|
37
|
+
| CardStartPushProvisioningEvent
|
|
@@ -1,4 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import type { CardNativeEvent, CardNativeMessage } from './cardMessage';
|
|
2
|
+
import type { SDKEvent, SDKMessage } from './sdkMessage';
|
|
3
|
+
|
|
4
|
+
export type NativeMessageType =
|
|
5
|
+
| SDKMessage
|
|
6
|
+
| CardNativeMessage
|
|
7
|
+
|
|
8
|
+
export type NativeEvent =
|
|
9
|
+
| CardNativeEvent
|
|
10
|
+
| SDKEvent
|
|
11
|
+
|
|
12
|
+
export interface NativeMessage {
|
|
13
|
+
type: NativeMessageType,
|
|
14
|
+
details?: NativeEvent
|
|
4
15
|
}
|
|
@@ -1,18 +1,21 @@
|
|
|
1
|
+
import type { ResponseUnitOnLoadEvent } from '../../sharedTypes';
|
|
2
|
+
|
|
1
3
|
export enum UnitMessage {
|
|
2
4
|
UNIT_REQUEST_RENDERING = 'unitRequestRendering',
|
|
3
5
|
UNIT_REQUEST_REFRESH = 'unitRequestRefresh',
|
|
4
6
|
UNIT_REQUEST_CLOSE_FLOW = 'unitRequestCloseFlow',
|
|
5
7
|
UNIT_REQUEST_OPEN_LINK = 'unitRequestOpenLink',
|
|
6
|
-
UNIT_ON_LOAD = 'unitOnLoad'
|
|
8
|
+
UNIT_ON_LOAD = 'unitOnLoad',
|
|
9
|
+
UNIT_REQUEST_DOWNLOAD = 'unitRequestDownload'
|
|
7
10
|
}
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
nativePlace: string;
|
|
11
|
-
nativeComponent: string;
|
|
11
|
+
export interface RequestRenderingEvent {
|
|
12
|
+
data: RequestRenderingEventData
|
|
12
13
|
}
|
|
13
14
|
|
|
14
|
-
export interface
|
|
15
|
-
|
|
15
|
+
export interface RequestRenderingEventData {
|
|
16
|
+
actionType?: string,
|
|
17
|
+
nativePlace: string,
|
|
18
|
+
nativeComponent: string,
|
|
16
19
|
}
|
|
17
20
|
|
|
18
21
|
export interface RequestRefreshEvent {
|
|
@@ -26,7 +29,17 @@ export interface RequestOpenLinkEvent {
|
|
|
26
29
|
target: string
|
|
27
30
|
}
|
|
28
31
|
|
|
32
|
+
export interface RequestDownloadEvent {
|
|
33
|
+
url: string
|
|
34
|
+
accessToken: string
|
|
35
|
+
fileType: string
|
|
36
|
+
responseType: string
|
|
37
|
+
fileName: string
|
|
38
|
+
}
|
|
39
|
+
|
|
29
40
|
export type UnitEvent =
|
|
30
41
|
| RequestRenderingEvent
|
|
31
42
|
| RequestRefreshEvent
|
|
32
43
|
| RequestOpenLinkEvent
|
|
44
|
+
| ResponseUnitOnLoadEvent
|
|
45
|
+
| RequestDownloadEvent
|
|
@@ -21,20 +21,25 @@ export const POST_PAGE_HEIGHT = `
|
|
|
21
21
|
`;
|
|
22
22
|
|
|
23
23
|
export const LISTENERS = {
|
|
24
|
-
isPageLoaded
|
|
24
|
+
isPageLoaded: `
|
|
25
25
|
window.addEventListener('DOMContentLoaded', e => {
|
|
26
26
|
postMessageToSDK({ type: "${PageMessage.PAGE_LOADED}" })
|
|
27
27
|
});
|
|
28
28
|
`,
|
|
29
29
|
requestRendering: `
|
|
30
30
|
window.addEventListener("${UnitMessage.UNIT_REQUEST_RENDERING}", (e) => {
|
|
31
|
-
postMessageToSDK({ type: "${UnitMessage.UNIT_REQUEST_RENDERING}", details: { data:
|
|
31
|
+
postMessageToSDK({ type: "${UnitMessage.UNIT_REQUEST_RENDERING}", details: { data: e.detail }})
|
|
32
|
+
});
|
|
33
|
+
`,
|
|
34
|
+
requestRefresh: `
|
|
35
|
+
window.addEventListener("${UnitMessage.UNIT_REQUEST_REFRESH}", (e) => {
|
|
36
|
+
postMessageToSDK({ type: "${UnitMessage.UNIT_REQUEST_REFRESH}", details: e.detail })
|
|
32
37
|
});
|
|
33
38
|
`,
|
|
34
39
|
onLoad: `
|
|
35
40
|
window.addEventListener("${UnitMessage.UNIT_ON_LOAD}", (e) => {
|
|
36
41
|
postHeight()
|
|
37
|
-
postMessageToSDK({ type: "${UnitMessage.UNIT_ON_LOAD}" })
|
|
42
|
+
postMessageToSDK({ type: "${UnitMessage.UNIT_ON_LOAD}", details: e.detail })
|
|
38
43
|
});
|
|
39
44
|
`,
|
|
40
45
|
requestCloseFlow: `
|
|
@@ -47,6 +52,11 @@ export const LISTENERS = {
|
|
|
47
52
|
postMessageToSDK({ type: "${UnitMessage.UNIT_REQUEST_OPEN_LINK}", details: e.detail })
|
|
48
53
|
});
|
|
49
54
|
`,
|
|
55
|
+
unitRequestDownload: `
|
|
56
|
+
window.addEventListener("${UnitMessage.UNIT_REQUEST_DOWNLOAD}", (e) => {
|
|
57
|
+
postMessageToSDK({ type: "${UnitMessage.UNIT_REQUEST_DOWNLOAD}", details: e.detail })
|
|
58
|
+
});
|
|
59
|
+
`,
|
|
50
60
|
cardStatusChange: `
|
|
51
61
|
window.addEventListener("${CardMessage.CARD_STATUS_CHANGED}", (e) => {
|
|
52
62
|
const response = e.detail
|
|
@@ -59,9 +69,16 @@ export const LISTENERS = {
|
|
|
59
69
|
`
|
|
60
70
|
};
|
|
61
71
|
|
|
62
|
-
export const
|
|
72
|
+
export const DISPATCH_RENDERING_EVENT = `
|
|
63
73
|
const dispatchRenderingEvent = (details) => {
|
|
64
74
|
const event = new CustomEvent("${UnitMessage.UNIT_REQUEST_RENDERING}",{ detail: JSON.parse(details) })
|
|
65
75
|
window.dispatchEvent(event)
|
|
66
76
|
}
|
|
67
77
|
`;
|
|
78
|
+
|
|
79
|
+
export const DISPATCH_REQUEST_REFRESH = `
|
|
80
|
+
const dispatchRefreshEvent = (details) => {
|
|
81
|
+
const event = new CustomEvent("${UnitMessage.UNIT_REQUEST_REFRESH}",{ detail: JSON.parse(details) })
|
|
82
|
+
window.dispatchEvent(event)
|
|
83
|
+
}
|
|
84
|
+
`;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type { Tags, Relationship } from
|
|
1
|
+
import type { Tags, Relationship } from './types';
|
|
2
2
|
|
|
3
|
-
type BookPaymentStatus =
|
|
3
|
+
type BookPaymentStatus = 'Sent' | 'Rejected'
|
|
4
4
|
|
|
5
5
|
export type UNBookPaymentData = {
|
|
6
|
-
type:
|
|
6
|
+
type: 'bookPayment',
|
|
7
7
|
id: string,
|
|
8
8
|
attributes: {
|
|
9
9
|
createdAt: string | Date,
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import type { Address, FullName, Limits, Relationship, Tags } from
|
|
1
|
+
import type { Address, FullName, Limits, Relationship, Tags } from './types';
|
|
2
2
|
|
|
3
3
|
export type UNCardData = IndividualDebitCard | BusinessDebitCard
|
|
4
4
|
|
|
5
|
-
type CardStatus =
|
|
5
|
+
type CardStatus = 'Active' | 'Inactive' | 'Stolen' | 'Lost' | 'Frozen' | 'ClosedByCustomer' | 'SuspectedFraud'
|
|
6
6
|
|
|
7
|
-
type IndividualDebitCard = {
|
|
7
|
+
export type IndividualDebitCard = {
|
|
8
8
|
id: string,
|
|
9
|
-
type:
|
|
9
|
+
type: 'individualDebitCard' | 'individualVirtualDebitCard',
|
|
10
10
|
attributes: {
|
|
11
11
|
createdAt: string,
|
|
12
12
|
last4Digits: string,
|
|
@@ -27,9 +27,9 @@ type IndividualDebitCard = {
|
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
type BusinessDebitCard = {
|
|
30
|
+
export type BusinessDebitCard = {
|
|
31
31
|
id: string,
|
|
32
|
-
type:
|
|
32
|
+
type: 'businessDebitCard' | 'businessVirtualDebitCard',
|
|
33
33
|
attributes: {
|
|
34
34
|
fullName: FullName,
|
|
35
35
|
dateOfBirth: string,
|
package/src/sharedTypes/index.ts
CHANGED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/ban-types */
|
|
2
|
+
import type { UNCardData } from '../sharedTypes';
|
|
3
|
+
|
|
4
|
+
export type SuccessResponseUnitOnLoad = {
|
|
5
|
+
/*
|
|
6
|
+
Object since the current response data types from 'Activities' and 'BookPayment' do not have documentation.
|
|
7
|
+
When things are determined, we may update it
|
|
8
|
+
*/
|
|
9
|
+
data: UNCardData | Object,
|
|
10
|
+
included: [Object],
|
|
11
|
+
errors: null
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export type ErrorResponseUnitOnLoad = {
|
|
15
|
+
errors: [
|
|
16
|
+
{
|
|
17
|
+
status: string,
|
|
18
|
+
title: string,
|
|
19
|
+
detail?: string,
|
|
20
|
+
details?: string,
|
|
21
|
+
meta?: Record<string, string>
|
|
22
|
+
}
|
|
23
|
+
]
|
|
24
|
+
}
|
|
25
|
+
export type ResponseUnitOnLoadEvent =
|
|
26
|
+
| SuccessResponseUnitOnLoad
|
|
27
|
+
| ErrorResponseUnitOnLoad
|