react-native-unit-components 1.0.1 → 1.0.3

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.
Files changed (218) hide show
  1. package/README.md +75 -6
  2. package/android/src/main/AndroidManifest.xml +12 -1
  3. package/android/src/main/java/com/unitreactnativecomponents/UnitReactNativeComponentsPackage.kt +2 -1
  4. package/android/src/main/java/com/unitreactnativecomponents/sharepdf/UNSharePDF.kt +75 -0
  5. package/android/src/main/res/layout/un_black_add_to_googlepay_button.xml +2 -2
  6. package/android/src/main/res/layout/un_view_google_push_provisioning.xml +1 -13
  7. package/android/src/main/res/layout/un_white_add_to_googlepay_button.xml +1 -1
  8. package/android/src/main/res/layout/un_white_add_to_googlepay_button_no_shadow.xml +1 -1
  9. package/android/src/main/res/xml/file_paths.xml +4 -0
  10. package/ios/UnitReactNativeComponentsViewManager.m +0 -1
  11. package/ios/UnitReactNativeComponentsViewManager.swift +6 -2
  12. package/lib/commonjs/components/UNAccountComponent/UNAccountComponent.js +103 -0
  13. package/lib/commonjs/components/UNAccountComponent/UNAccountComponent.js.map +1 -0
  14. package/lib/commonjs/components/UNAccountComponent/UNAccountComponent.utils.js +47 -0
  15. package/lib/commonjs/components/UNAccountComponent/UNAccountComponent.utils.js.map +1 -0
  16. package/lib/commonjs/components/UNActivityComponent/UNActivityComponent.js +63 -8
  17. package/lib/commonjs/components/UNActivityComponent/UNActivityComponent.js.map +1 -1
  18. package/lib/commonjs/components/UNActivityComponent/UNActivityComponent.utils.js +18 -3
  19. package/lib/commonjs/components/UNActivityComponent/UNActivityComponent.utils.js.map +1 -1
  20. package/lib/commonjs/components/UNBookPaymentComponent/UNBookPaymentComponent.js +56 -13
  21. package/lib/commonjs/components/UNBookPaymentComponent/UNBookPaymentComponent.js.map +1 -1
  22. package/lib/commonjs/components/UNBookPaymentComponent/UNBookPaymentComponent.utils.js +4 -3
  23. package/lib/commonjs/components/UNBookPaymentComponent/UNBookPaymentComponent.utils.js.map +1 -1
  24. package/lib/commonjs/components/UNBottomSheetComponent/UNBottomSheetComponent.constants.js +3 -3
  25. package/lib/commonjs/components/UNBottomSheetComponent/UNBottomSheetComponent.constants.js.map +1 -1
  26. package/lib/commonjs/components/UNBottomSheetComponent/UNBottomSheetComponent.js +114 -46
  27. package/lib/commonjs/components/UNBottomSheetComponent/UNBottomSheetComponent.js.map +1 -1
  28. package/lib/commonjs/components/UNBottomSheetComponent/UNBottomSheetComponent.utils.js +4 -8
  29. package/lib/commonjs/components/UNBottomSheetComponent/UNBottomSheetComponent.utils.js.map +1 -1
  30. package/lib/commonjs/components/UNBottomSheetComponent/components/UNAddToWalletBottomSheetItem.js +95 -0
  31. package/lib/commonjs/components/UNBottomSheetComponent/components/UNAddToWalletBottomSheetItem.js.map +1 -0
  32. package/lib/commonjs/components/UNBottomSheetComponent/components/UNAddToWalletBottomSheetItem.styles.js +31 -0
  33. package/lib/commonjs/components/UNBottomSheetComponent/components/UNAddToWalletBottomSheetItem.styles.js.map +1 -0
  34. package/lib/commonjs/components/UNCardComponent/UNCardComponent.js +65 -7
  35. package/lib/commonjs/components/UNCardComponent/UNCardComponent.js.map +1 -1
  36. package/lib/commonjs/components/UNCardComponent/UNCardComponent.utils.js +56 -10
  37. package/lib/commonjs/components/UNCardComponent/UNCardComponent.utils.js.map +1 -1
  38. package/lib/commonjs/components/UNCardComponent/networking/common/UNNetworkConstants.js +20 -0
  39. package/lib/commonjs/components/UNCardComponent/networking/common/UNNetworkConstants.js.map +1 -0
  40. package/lib/commonjs/components/UNCardComponent/networking/requests/UNWalletPayloadRequest.js +44 -0
  41. package/lib/commonjs/components/UNCardComponent/networking/requests/UNWalletPayloadRequest.js.map +1 -0
  42. package/lib/commonjs/components/index.js +13 -0
  43. package/lib/commonjs/components/index.js.map +1 -1
  44. package/lib/commonjs/helpers/BottomSheet/BottomSheet.js +32 -12
  45. package/lib/commonjs/helpers/BottomSheet/BottomSheet.js.map +1 -1
  46. package/lib/commonjs/helpers/BottomSheet/BottomSheet.styles.js +1 -1
  47. package/lib/commonjs/helpers/BottomSheet/BottomSheet.styles.js.map +1 -1
  48. package/lib/commonjs/helpers/EventBus.js.map +1 -1
  49. package/lib/commonjs/messages/nativeMessages/cardMessage.js +36 -0
  50. package/lib/commonjs/messages/nativeMessages/cardMessage.js.map +1 -0
  51. package/lib/commonjs/messages/nativeMessages/index.js +0 -7
  52. package/lib/commonjs/messages/nativeMessages/index.js.map +1 -1
  53. package/lib/commonjs/messages/nativeMessages/sdkMessage.js +14 -0
  54. package/lib/commonjs/messages/nativeMessages/sdkMessage.js.map +1 -0
  55. package/lib/commonjs/messages/webMessages/unitMessages.js +1 -0
  56. package/lib/commonjs/messages/webMessages/unitMessages.js.map +1 -1
  57. package/lib/commonjs/nativeComponent/{UNNativeAddToWalletButton.js → UnitAddToWalletButton.js} +1 -1
  58. package/lib/commonjs/nativeComponent/UnitAddToWalletButton.js.map +1 -0
  59. package/lib/commonjs/scripts/html/bodyHtml.js +1 -1
  60. package/lib/commonjs/scripts/html/bodyHtml.js.map +1 -1
  61. package/lib/commonjs/scripts/html/bodyScript.js +22 -5
  62. package/lib/commonjs/scripts/html/bodyScript.js.map +1 -1
  63. package/lib/commonjs/sharedTypes/bookPayment.types.js.map +1 -1
  64. package/lib/commonjs/sharedTypes/card.types.js.map +1 -1
  65. package/lib/commonjs/sharedTypes/index.js +13 -0
  66. package/lib/commonjs/sharedTypes/index.js.map +1 -1
  67. package/lib/commonjs/sharedTypes/onLoadResponse.types.js +6 -0
  68. package/lib/commonjs/sharedTypes/onLoadResponse.types.js.map +1 -0
  69. package/lib/commonjs/sharedTypes/wallet.types.js +22 -0
  70. package/lib/commonjs/sharedTypes/wallet.types.js.map +1 -0
  71. package/lib/commonjs/unitSdkManager/UnitSdk.api.js +5 -3
  72. package/lib/commonjs/unitSdkManager/UnitSdk.api.js.map +1 -1
  73. package/lib/commonjs/unitSdkManager/UnitSdkManager.js +18 -0
  74. package/lib/commonjs/unitSdkManager/UnitSdkManager.js.map +1 -1
  75. package/lib/commonjs/webComponent/WebComponent.js +35 -10
  76. package/lib/commonjs/webComponent/WebComponent.js.map +1 -1
  77. package/lib/commonjs/webComponent/WebComponent.utils.js +41 -0
  78. package/lib/commonjs/webComponent/WebComponent.utils.js.map +1 -0
  79. package/lib/commonjs/webComponent/html.js +9 -1
  80. package/lib/commonjs/webComponent/html.js.map +1 -1
  81. package/lib/module/components/UNAccountComponent/UNAccountComponent.js +74 -0
  82. package/lib/module/components/UNAccountComponent/UNAccountComponent.js.map +1 -0
  83. package/lib/module/components/UNAccountComponent/UNAccountComponent.utils.js +26 -0
  84. package/lib/module/components/UNAccountComponent/UNAccountComponent.utils.js.map +1 -0
  85. package/lib/module/components/UNActivityComponent/UNActivityComponent.js +56 -8
  86. package/lib/module/components/UNActivityComponent/UNActivityComponent.js.map +1 -1
  87. package/lib/module/components/UNActivityComponent/UNActivityComponent.utils.js +10 -2
  88. package/lib/module/components/UNActivityComponent/UNActivityComponent.utils.js.map +1 -1
  89. package/lib/module/components/UNBookPaymentComponent/UNBookPaymentComponent.js +50 -12
  90. package/lib/module/components/UNBookPaymentComponent/UNBookPaymentComponent.js.map +1 -1
  91. package/lib/module/components/UNBookPaymentComponent/UNBookPaymentComponent.utils.js +3 -2
  92. package/lib/module/components/UNBookPaymentComponent/UNBookPaymentComponent.utils.js.map +1 -1
  93. package/lib/module/components/UNBottomSheetComponent/UNBottomSheetComponent.constants.js +1 -1
  94. package/lib/module/components/UNBottomSheetComponent/UNBottomSheetComponent.constants.js.map +1 -1
  95. package/lib/module/components/UNBottomSheetComponent/UNBottomSheetComponent.js +111 -46
  96. package/lib/module/components/UNBottomSheetComponent/UNBottomSheetComponent.js.map +1 -1
  97. package/lib/module/components/UNBottomSheetComponent/UNBottomSheetComponent.utils.js +5 -9
  98. package/lib/module/components/UNBottomSheetComponent/UNBottomSheetComponent.utils.js.map +1 -1
  99. package/lib/module/components/UNBottomSheetComponent/components/UNAddToWalletBottomSheetItem.js +68 -0
  100. package/lib/module/components/UNBottomSheetComponent/components/UNAddToWalletBottomSheetItem.js.map +1 -0
  101. package/lib/module/components/UNBottomSheetComponent/components/UNAddToWalletBottomSheetItem.styles.js +21 -0
  102. package/lib/module/components/UNBottomSheetComponent/components/UNAddToWalletBottomSheetItem.styles.js.map +1 -0
  103. package/lib/module/components/UNCardComponent/UNCardComponent.js +65 -9
  104. package/lib/module/components/UNCardComponent/UNCardComponent.js.map +1 -1
  105. package/lib/module/components/UNCardComponent/UNCardComponent.utils.js +48 -9
  106. package/lib/module/components/UNCardComponent/UNCardComponent.utils.js.map +1 -1
  107. package/lib/module/components/UNCardComponent/networking/common/UNNetworkConstants.js +10 -0
  108. package/lib/module/components/UNCardComponent/networking/common/UNNetworkConstants.js.map +1 -0
  109. package/lib/module/components/UNCardComponent/networking/requests/UNWalletPayloadRequest.js +29 -0
  110. package/lib/module/components/UNCardComponent/networking/requests/UNWalletPayloadRequest.js.map +1 -0
  111. package/lib/module/components/index.js +1 -0
  112. package/lib/module/components/index.js.map +1 -1
  113. package/lib/module/helpers/BottomSheet/BottomSheet.js +30 -13
  114. package/lib/module/helpers/BottomSheet/BottomSheet.js.map +1 -1
  115. package/lib/module/helpers/BottomSheet/BottomSheet.styles.js +2 -2
  116. package/lib/module/helpers/BottomSheet/BottomSheet.styles.js.map +1 -1
  117. package/lib/module/helpers/EventBus.js.map +1 -1
  118. package/lib/module/messages/nativeMessages/cardMessage.js +27 -0
  119. package/lib/module/messages/nativeMessages/cardMessage.js.map +1 -0
  120. package/lib/module/messages/nativeMessages/index.js +1 -5
  121. package/lib/module/messages/nativeMessages/index.js.map +1 -1
  122. package/lib/module/messages/nativeMessages/sdkMessage.js +7 -0
  123. package/lib/module/messages/nativeMessages/sdkMessage.js.map +1 -0
  124. package/lib/module/messages/webMessages/unitMessages.js +1 -0
  125. package/lib/module/messages/webMessages/unitMessages.js.map +1 -1
  126. package/lib/module/nativeComponent/{UNNativeAddToWalletButton.js → UnitAddToWalletButton.js} +1 -1
  127. package/lib/module/nativeComponent/UnitAddToWalletButton.js.map +1 -0
  128. package/lib/module/scripts/html/bodyHtml.js +1 -1
  129. package/lib/module/scripts/html/bodyHtml.js.map +1 -1
  130. package/lib/module/scripts/html/bodyScript.js +19 -3
  131. package/lib/module/scripts/html/bodyScript.js.map +1 -1
  132. package/lib/module/sharedTypes/bookPayment.types.js.map +1 -1
  133. package/lib/module/sharedTypes/card.types.js.map +1 -1
  134. package/lib/module/sharedTypes/index.js +1 -0
  135. package/lib/module/sharedTypes/index.js.map +1 -1
  136. package/lib/module/sharedTypes/onLoadResponse.types.js +2 -0
  137. package/lib/module/sharedTypes/onLoadResponse.types.js.map +1 -0
  138. package/lib/module/sharedTypes/wallet.types.js +14 -0
  139. package/lib/module/sharedTypes/wallet.types.js.map +1 -0
  140. package/lib/module/unitSdkManager/UnitSdk.api.js +4 -3
  141. package/lib/module/unitSdkManager/UnitSdk.api.js.map +1 -1
  142. package/lib/module/unitSdkManager/UnitSdkManager.js +13 -0
  143. package/lib/module/unitSdkManager/UnitSdkManager.js.map +1 -1
  144. package/lib/module/webComponent/WebComponent.js +32 -10
  145. package/lib/module/webComponent/WebComponent.js.map +1 -1
  146. package/lib/module/webComponent/WebComponent.utils.js +27 -0
  147. package/lib/module/webComponent/WebComponent.utils.js.map +1 -0
  148. package/lib/module/webComponent/html.js +9 -2
  149. package/lib/module/webComponent/html.js.map +1 -1
  150. package/lib/typescript/components/UNAccountComponent/UNAccountComponent.d.ts +12 -0
  151. package/lib/typescript/components/UNAccountComponent/UNAccountComponent.utils.d.ts +7 -0
  152. package/lib/typescript/components/UNActivityComponent/UNActivityComponent.d.ts +2 -0
  153. package/lib/typescript/components/UNActivityComponent/UNActivityComponent.utils.d.ts +4 -0
  154. package/lib/typescript/components/UNBookPaymentComponent/UNBookPaymentComponent.d.ts +2 -1
  155. package/lib/typescript/components/UNBottomSheetComponent/UNBottomSheetComponent.constants.d.ts +1 -1
  156. package/lib/typescript/components/UNBottomSheetComponent/UNBottomSheetComponent.d.ts +9 -2
  157. package/lib/typescript/components/UNBottomSheetComponent/UNBottomSheetComponent.utils.d.ts +2 -1
  158. package/lib/typescript/components/UNBottomSheetComponent/components/UNAddToWalletBottomSheetItem.d.ts +6 -0
  159. package/lib/typescript/components/UNBottomSheetComponent/components/UNAddToWalletBottomSheetItem.styles.d.ts +17 -0
  160. package/lib/typescript/components/UNCardComponent/UNCardComponent.d.ts +4 -1
  161. package/lib/typescript/components/UNCardComponent/UNCardComponent.utils.d.ts +9 -1
  162. package/lib/typescript/components/UNCardComponent/networking/common/UNNetworkConstants.d.ts +8 -0
  163. package/lib/typescript/components/UNCardComponent/networking/requests/UNWalletPayloadRequest.d.ts +1 -0
  164. package/lib/typescript/components/index.d.ts +1 -0
  165. package/lib/typescript/helpers/EventBus.d.ts +3 -3
  166. package/lib/typescript/messages/nativeMessages/cardMessage.d.ts +28 -0
  167. package/lib/typescript/messages/nativeMessages/index.d.ts +7 -2
  168. package/lib/typescript/messages/nativeMessages/sdkMessage.d.ts +8 -0
  169. package/lib/typescript/messages/webMessages/unitMessages.d.ts +16 -6
  170. package/lib/typescript/scripts/html/bodyScript.d.ts +4 -1
  171. package/lib/typescript/sharedTypes/bookPayment.types.d.ts +3 -3
  172. package/lib/typescript/sharedTypes/card.types.d.ts +6 -6
  173. package/lib/typescript/sharedTypes/index.d.ts +1 -0
  174. package/lib/typescript/sharedTypes/onLoadResponse.types.d.ts +18 -0
  175. package/lib/typescript/sharedTypes/wallet.types.d.ts +14 -0
  176. package/lib/typescript/unitSdkManager/UnitSdkManager.d.ts +3 -0
  177. package/lib/typescript/webComponent/WebComponent.d.ts +4 -1
  178. package/lib/typescript/webComponent/WebComponent.utils.d.ts +2 -0
  179. package/package.json +2 -1
  180. package/src/components/UNAccountComponent/UNAccountComponent.tsx +82 -0
  181. package/src/components/UNAccountComponent/UNAccountComponent.utils.ts +30 -0
  182. package/src/components/UNActivityComponent/UNActivityComponent.tsx +57 -8
  183. package/src/components/UNActivityComponent/UNActivityComponent.utils.ts +14 -2
  184. package/src/components/UNBookPaymentComponent/UNBookPaymentComponent.tsx +47 -13
  185. package/src/components/UNBookPaymentComponent/UNBookPaymentComponent.utils.ts +3 -2
  186. package/src/components/UNBottomSheetComponent/UNBottomSheetComponent.constants.ts +1 -1
  187. package/src/components/UNBottomSheetComponent/UNBottomSheetComponent.tsx +120 -44
  188. package/src/components/UNBottomSheetComponent/UNBottomSheetComponent.utils.ts +7 -10
  189. package/src/components/UNBottomSheetComponent/components/UNAddToWalletBottomSheetItem.styles.ts +21 -0
  190. package/src/components/UNBottomSheetComponent/components/UNAddToWalletBottomSheetItem.tsx +74 -0
  191. package/src/components/UNCardComponent/UNCardComponent.tsx +68 -13
  192. package/src/components/UNCardComponent/UNCardComponent.utils.ts +47 -9
  193. package/src/components/UNCardComponent/networking/common/UNNetworkConstants.ts +11 -0
  194. package/src/components/UNCardComponent/networking/requests/UNWalletPayloadRequest.ts +34 -0
  195. package/src/components/index.ts +1 -0
  196. package/src/helpers/BottomSheet/BottomSheet.styles.ts +2 -2
  197. package/src/helpers/BottomSheet/BottomSheet.tsx +28 -12
  198. package/src/helpers/EventBus.ts +3 -3
  199. package/src/messages/nativeMessages/cardMessage.ts +37 -0
  200. package/src/messages/nativeMessages/index.ts +14 -2
  201. package/src/messages/nativeMessages/sdkMessage.ts +11 -0
  202. package/src/messages/webMessages/unitMessages.ts +20 -7
  203. package/src/scripts/html/bodyHtml.ts +1 -1
  204. package/src/scripts/html/bodyScript.ts +21 -4
  205. package/src/sharedTypes/bookPayment.types.ts +3 -3
  206. package/src/sharedTypes/card.types.ts +6 -6
  207. package/src/sharedTypes/index.ts +1 -0
  208. package/src/sharedTypes/onLoadResponse.types.ts +27 -0
  209. package/src/sharedTypes/wallet.types.ts +17 -0
  210. package/src/unitSdkManager/UnitSdk.api.ts +3 -2
  211. package/src/unitSdkManager/UnitSdkManager.ts +12 -0
  212. package/src/webComponent/WebComponent.tsx +35 -12
  213. package/src/webComponent/WebComponent.utils.ts +26 -0
  214. package/src/webComponent/html.ts +9 -2
  215. package/lib/commonjs/nativeComponent/UNNativeAddToWalletButton.js.map +0 -1
  216. package/lib/module/nativeComponent/UNNativeAddToWalletButton.js.map +0 -1
  217. /package/lib/typescript/nativeComponent/{UNNativeAddToWalletButton.d.ts → UnitAddToWalletButton.d.ts} +0 -0
  218. /package/src/nativeComponent/{UNNativeAddToWalletButton.tsx → UnitAddToWalletButton.tsx} +0 -0
@@ -1,24 +1,22 @@
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 { RequestRefreshEvent, UnitMessage } from '../../messages/webMessages/unitMessages';
5
- import { UnitSDK } from '../../unitSdkManager/UnitSdkManager';
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';
6
9
 
7
10
  export const getCardParams = (props: UNCardComponentProps) => {
8
11
  return `
9
12
  card-id="${props.cardId}"
10
13
  customer-token="${props.customerToken}"
11
- theme="${props.theme ?? UnitSDK.getTheme()}"
14
+ enable-mobile-wallet="${!!props.pushProvisioningModule}"
12
15
  `;
13
16
  };
14
17
 
15
18
  export const getCardScript = () => {
16
- return `
17
- const dispatchRefreshEvent = (details) => {
18
- const event = new CustomEvent("${UnitMessage.UNIT_REQUEST_REFRESH}",{ detail: JSON.parse(details) })
19
- window.dispatchEvent(event)
20
- }
21
- `;
19
+ return DISPATCH_REQUEST_REFRESH;
22
20
  };
23
21
 
24
22
  export const injectRefreshEventIfNeeded = (currentWeb: WebView | null, requestRefreshEvent: RequestRefreshEvent | null, cardId: string) => {
@@ -26,3 +24,43 @@ export const injectRefreshEventIfNeeded = (currentWeb: WebView | null, requestRe
26
24
  currentWeb?.injectJavaScript(`dispatchRefreshEvent('${JSON.stringify(requestRefreshEvent)}')`);
27
25
  }
28
26
  };
27
+
28
+ export const launchGetWallets = async (customerToken: string, cardId: string, pushProvisioningModule: typeof NativeModules) => {
29
+ try {
30
+ const encryptedPayload = await getMobileWalletPayload(customerToken, cardId);
31
+ if (!encryptedPayload) return null;
32
+
33
+ const walletsResponse = await pushProvisioningModule.launchGetWallets(JSON.stringify({ encPayload: encryptedPayload }));
34
+ const parsedWalletsResponse = JSON.parse(walletsResponse);
35
+ const wallets = parsedWalletsResponse.wallets;
36
+
37
+ if (!wallets) return null;
38
+ if (wallets[0].code === UNWalletCode.Apple) {
39
+ return ({ name: UNWalletName.Apple, code: UNWalletCode.Apple, status: wallets[0].status });
40
+ } else {
41
+ const googleWallet = wallets.filter((wallet: { name: UNWalletName }) => {
42
+ return wallet.name === UNWalletName.Google;
43
+ });
44
+ if (!googleWallet) return;
45
+ return ({ name: UNWalletName.Google, code: UNWalletCode.Google, status: googleWallet[0].status });
46
+ }
47
+ } catch (error) {
48
+ return Promise.reject(error);
49
+ }
50
+
51
+ };
52
+
53
+ export const launchStartCardProvisioning = async (pushProvisioningModule: typeof NativeModules, wallet: UNWallet | null) => {
54
+ try {
55
+ const response = await pushProvisioningModule.launchStartCardProvisioning(
56
+ JSON.stringify({
57
+ walletCode: wallet?.code,
58
+ walletName: wallet?.name
59
+ }));
60
+ return response;
61
+ }
62
+
63
+ catch (error) {
64
+ return Promise.reject(error);
65
+ }
66
+ };
@@ -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,34 @@
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
+ const env = UnitSDK.getEnv();
6
+
7
+ export const getMobileWalletPayload = async (customerToken: string, cardId: string) => {
8
+ const headers = {
9
+ 'Content-Type': APIHeaders.CONTENT_TYPE,
10
+ 'Authorization': `Bearer ${customerToken}`,
11
+ };
12
+
13
+ const data = {
14
+ data: {
15
+ attributes: {
16
+ signedNonce: UnitSDK.getSignedNonce(),
17
+ },
18
+ },
19
+ };
20
+
21
+ const baseURL = `${UNIT_SECURE_URL[env as keyof typeof UNEnvironment]}/cards/${cardId}/mobile-wallet-payload`;
22
+ try {
23
+ const response = await axios.post(
24
+ baseURL,
25
+ data,
26
+ {
27
+ headers: headers,
28
+ });
29
+ const encryptedPayload = response.data.data.attributes.payload;
30
+ return encryptedPayload;
31
+ } catch (error) {
32
+ return Promise.reject(error);
33
+ }
34
+ };
@@ -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 { BOTTOM_SHEET_MAX_PRECANTAGE_SIZE } from '../../components/UNBottomSheetComponent/UNBottomSheetComponent.constants';
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 - BOTTOM_SHEET_MAX_PRECANTAGE_SIZE),
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 { BOTTOM_SHEET_MAX_PRECANTAGE_SIZE } from '../../components/UNBottomSheetComponent/UNBottomSheetComponent.constants';
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(() => { setIsPanelOpened(true); });
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
- setIsPanelOpened(false);
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 - BOTTOM_SHEET_MAX_PRECANTAGE_SIZE)}
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 * BOTTOM_SHEET_MAX_PRECANTAGE_SIZE,
250
+ sliderMaxHeight: Dimensions.get('window').height * BOTTOM_SHEET_MAX_PERCENTAGE_SIZE,
235
251
  animationDuration: 200,
236
252
  onOpen: () => null,
237
253
  onClose: () => null,
@@ -1,8 +1,8 @@
1
1
  /* eslint-disable @typescript-eslint/no-explicit-any */
2
- import type { NativeMessage } from '../messages/nativeMessages';
2
+ import type { NativeMessageType } from '../messages/nativeMessages';
3
3
  import type { WebViewMessageType } from '../messages/webMessages';
4
4
 
5
- export type BusEventKey = NativeMessage | WebViewMessageType
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: any) {
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,3 +1,15 @@
1
- export enum NativeMessage {
2
- IS_SCRIPT_FETCHED = 'isScriptFetched'
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
3
15
  }
@@ -0,0 +1,11 @@
1
+ export enum SDKMessage {
2
+ IS_SCRIPT_FETCHED = 'isScriptFetched',
3
+ IS_SDK_INITIALIZED = 'isSdkInitialized',
4
+ }
5
+
6
+ export interface SdkScriptFetched {
7
+ unitScript: string
8
+ }
9
+
10
+ export type SDKEvent =
11
+ | SdkScriptFetched
@@ -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
- export interface RequestRenderingData {
10
- nativePlace: string;
11
- nativeComponent: string;
11
+ export interface RequestRenderingEvent {
12
+ data: RequestRenderingEventData
12
13
  }
13
14
 
14
- export interface RequestRenderingEvent {
15
- data: string;
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
@@ -15,7 +15,7 @@ export enum PresentationMode {
15
15
  }
16
16
 
17
17
  export const getHtmlBody = (unitComponent: string, unitComponentProps?: string, presentationMode?: PresentationMode) => {
18
- const currentComponent = `<${unitComponent} ${unitComponentProps || ''}> </${unitComponent}>`;
18
+ const currentComponent = `<${unitComponent} ${unitComponentProps || ''} }> </${unitComponent}>`;
19
19
 
20
20
  switch (presentationMode) {
21
21
  case PresentationMode.CoverInjectedHeight:
@@ -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: JSON.stringify(e.detail) }})
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 DISPTACH_RENDERING_EVENT = `
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 "./types"
1
+ import type { Tags, Relationship } from './types';
2
2
 
3
- type BookPaymentStatus = "Sent" | "Rejected"
3
+ type BookPaymentStatus = 'Sent' | 'Rejected'
4
4
 
5
5
  export type UNBookPaymentData = {
6
- type: "bookPayment",
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 "./types"
1
+ import type { Address, FullName, Limits, Relationship, Tags } from './types';
2
2
 
3
3
  export type UNCardData = IndividualDebitCard | BusinessDebitCard
4
4
 
5
- type CardStatus = "Active" | "Inactive" | "Stolen" | "Lost" | "Frozen" | "ClosedByCustomer" | "SuspectedFraud"
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: "individualDebitCard" | "individualVirtualDebitCard",
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: "businessDebitCard" | "businessVirtualDebitCard",
32
+ type: 'businessDebitCard' | 'businessVirtualDebitCard',
33
33
  attributes: {
34
34
  fullName: FullName,
35
35
  dateOfBirth: string,
@@ -1,2 +1,3 @@
1
1
  export * from './bookPayment.types';
2
2
  export * from './card.types';
3
+ export * from './onLoadResponse.types';
@@ -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
@@ -0,0 +1,17 @@
1
+ import type { CardAddToWalletStatus } from 'src/messages/nativeMessages/cardMessage';
2
+
3
+ export enum UNWalletCode {
4
+ Apple = 'ApplePayPushProvision',
5
+ Google = 'GooglePayPushProvision',
6
+ }
7
+
8
+ export enum UNWalletName {
9
+ Apple = 'APPLE',
10
+ Google = 'GOOGLE',
11
+ }
12
+
13
+ export interface UNWallet {
14
+ name: string;
15
+ code: string;
16
+ status: CardAddToWalletStatus
17
+ }
@@ -1,5 +1,5 @@
1
1
  import EventBus from '../helpers/EventBus';
2
- import { NativeMessage } from '../messages/nativeMessages';
2
+ import { SDKMessage, SdkScriptFetched } from '../messages/nativeMessages/sdkMessage';
3
3
  import { UnitSDK, UNIT_SCRIPT_URL } from './UnitSdkManager';
4
4
 
5
5
  let isLoadingScript = false;
@@ -18,7 +18,8 @@ export const fetchUnitScript = async () => {
18
18
  const unitScriptRes = await fetch(UNIT_SCRIPT_URL[env]);
19
19
  const unitScript = await unitScriptRes.text();
20
20
  if (unitScript) {
21
- EventBus.Instance.event(NativeMessage.IS_SCRIPT_FETCHED, { unitScript });
21
+ const scriptFetchData: SdkScriptFetched = { unitScript };
22
+ EventBus.Instance.event(SDKMessage.IS_SCRIPT_FETCHED, scriptFetchData);
22
23
  globalUnitScript = unitScript;
23
24
  }
24
25
  return null;
@@ -1,3 +1,5 @@
1
+ import EventBus from '../helpers/EventBus';
2
+ import { SDKMessage } from '../messages/nativeMessages/sdkMessage';
1
3
  import { fetchUnitScript } from './UnitSdk.api';
2
4
 
3
5
  export enum UNEnvironment {
@@ -12,17 +14,23 @@ export const UNIT_SCRIPT_URL = {
12
14
  export class UnitSDK {
13
15
  protected static env?: UNEnvironment;
14
16
  protected static theme?: string;
17
+ protected static signedNonce?: string;
15
18
 
16
19
  public static init = async (env: UNEnvironment, theme?: string) => {
17
20
  try {
18
21
  this.env = env;
19
22
  this.theme = theme;
20
23
  await fetchUnitScript();
24
+ EventBus.Instance.event(SDKMessage.IS_SDK_INITIALIZED, {});
21
25
  } catch (e) {
22
26
  console.log(e);
23
27
  }
24
28
  };
25
29
 
30
+ public static setSignedNonce = (signedNonce: string) => {
31
+ this.signedNonce = signedNonce;
32
+ };
33
+
26
34
  public static getEnv = () => {
27
35
  return this.env;
28
36
  };
@@ -30,4 +38,8 @@ export class UnitSDK {
30
38
  public static getTheme = () => {
31
39
  return this.theme;
32
40
  };
41
+
42
+ public static getSignedNonce = () => {
43
+ return this.signedNonce;
44
+ };
33
45
  }