@rownd/react-native 0.2.4 → 2.1.0

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 (253) hide show
  1. package/LICENSE +1 -2
  2. package/README.md +15 -52
  3. package/android/build.gradle +127 -37
  4. package/android/gradle.properties +5 -0
  5. package/android/src/main/AndroidManifest.xml +1 -1
  6. package/android/src/main/java/com/reactnativerowndplugin/RowndPluginModule.kt +98 -0
  7. package/android/src/main/java/com/reactnativerowndplugin/RowndPluginPackage.kt +16 -0
  8. package/ios/{ReactNative.xcodeproj → Rownd.xcodeproj}/project.pbxproj +13 -12
  9. package/ios/Rownd.xcodeproj/project.xcworkspace/contents.xcworkspacedata +4 -0
  10. package/ios/RowndPlugin-Bridging-Header.h +3 -0
  11. package/ios/RowndPlugin.m +26 -0
  12. package/ios/RowndPlugin.swift +83 -0
  13. package/ios/RowndPluginEventEmitter.m +12 -0
  14. package/ios/RowndPluginEventEmitter.swift +19 -0
  15. package/lib/commonjs/components/GlobalContext.js +30 -298
  16. package/lib/commonjs/components/GlobalContext.js.map +1 -1
  17. package/lib/commonjs/components/{BottomSheetTextInput/types.js → GlobalContext.types.js} +1 -1
  18. package/lib/commonjs/components/GlobalContext.types.js.map +1 -0
  19. package/lib/commonjs/constants/action.js +13 -0
  20. package/lib/commonjs/constants/action.js.map +1 -0
  21. package/lib/commonjs/hooks/rownd.js +15 -146
  22. package/lib/commonjs/hooks/rownd.js.map +1 -1
  23. package/lib/commonjs/index.js +2 -12
  24. package/lib/commonjs/index.js.map +1 -1
  25. package/lib/commonjs/reducer/rowndReducer.js +89 -0
  26. package/lib/commonjs/reducer/rowndReducer.js.map +1 -0
  27. package/lib/commonjs/utils/config.js +0 -26
  28. package/lib/commonjs/utils/config.js.map +1 -1
  29. package/lib/commonjs/utils/nativeModule.js +72 -0
  30. package/lib/commonjs/utils/nativeModule.js.map +1 -0
  31. package/lib/module/components/GlobalContext.js +29 -293
  32. package/lib/module/components/GlobalContext.js.map +1 -1
  33. package/lib/module/components/GlobalContext.types.js +2 -0
  34. package/lib/module/components/GlobalContext.types.js.map +1 -0
  35. package/lib/module/constants/action.js +6 -0
  36. package/lib/module/constants/action.js.map +1 -0
  37. package/lib/module/hooks/rownd.js +12 -137
  38. package/lib/module/hooks/rownd.js.map +1 -1
  39. package/lib/module/index.js +2 -4
  40. package/lib/module/index.js.map +1 -1
  41. package/lib/module/reducer/rowndReducer.js +78 -0
  42. package/lib/module/reducer/rowndReducer.js.map +1 -0
  43. package/lib/module/utils/config.js +1 -16
  44. package/lib/module/utils/config.js.map +1 -1
  45. package/lib/module/utils/nativeModule.js +48 -0
  46. package/lib/module/utils/nativeModule.js.map +1 -0
  47. package/lib/typescript/components/GlobalContext.d.ts +13 -0
  48. package/lib/typescript/{src/components/GlobalContext.d.ts → components/GlobalContext.types.d.ts} +9 -35
  49. package/lib/typescript/constants/action.d.ts +7 -0
  50. package/lib/typescript/{src/hooks → hooks}/rownd.d.ts +10 -13
  51. package/lib/typescript/index.d.ts +3 -0
  52. package/lib/typescript/reducer/rowndReducer.d.ts +4 -0
  53. package/lib/typescript/utils/config.d.ts +10 -0
  54. package/lib/typescript/utils/nativeModule.d.ts +10 -0
  55. package/package.json +36 -56
  56. package/rownd-react-native.podspec +36 -0
  57. package/src/components/GlobalContext.tsx +44 -457
  58. package/src/components/GlobalContext.types.ts +105 -0
  59. package/src/constants/action.ts +8 -0
  60. package/src/hooks/rownd.ts +29 -147
  61. package/src/index.tsx +2 -4
  62. package/src/reducer/rowndReducer.ts +78 -0
  63. package/src/utils/config.ts +0 -27
  64. package/src/utils/nativeModule.ts +69 -0
  65. package/android/src/main/java/com/reactnative/ReactNativePackage.java +0 -22
  66. package/android/src/main/java/com/reactnative/ReactNativeViewManager.java +0 -31
  67. package/ios/ReactNativeViewManager.m +0 -34
  68. package/lib/commonjs/assets/images/checkmark--filled.svg +0 -12
  69. package/lib/commonjs/assets/images/email-verify-waiting.svg +0 -36
  70. package/lib/commonjs/assets/images/error-icon-material.svg +0 -1
  71. package/lib/commonjs/assets/images/phone-verify-waiting.svg +0 -26
  72. package/lib/commonjs/components/AuthenticatedComponent.js +0 -35
  73. package/lib/commonjs/components/AuthenticatedComponent.js.map +0 -1
  74. package/lib/commonjs/components/AutoSigninDialog.js +0 -132
  75. package/lib/commonjs/components/AutoSigninDialog.js.map +0 -1
  76. package/lib/commonjs/components/BottomSheetTextInput/BottomSheetTextInput.js +0 -65
  77. package/lib/commonjs/components/BottomSheetTextInput/BottomSheetTextInput.js.map +0 -1
  78. package/lib/commonjs/components/BottomSheetTextInput/index.js +0 -24
  79. package/lib/commonjs/components/BottomSheetTextInput/index.js.map +0 -1
  80. package/lib/commonjs/components/BottomSheetTextInput/types.js.map +0 -1
  81. package/lib/commonjs/components/DarkText.js +0 -35
  82. package/lib/commonjs/components/DarkText.js.map +0 -1
  83. package/lib/commonjs/components/DefaultContext.js +0 -266
  84. package/lib/commonjs/components/DefaultContext.js.map +0 -1
  85. package/lib/commonjs/components/RowndComponents.js +0 -25
  86. package/lib/commonjs/components/RowndComponents.js.map +0 -1
  87. package/lib/commonjs/components/RowndProvider.js +0 -55
  88. package/lib/commonjs/components/RowndProvider.js.map +0 -1
  89. package/lib/commonjs/components/SignIn.js +0 -638
  90. package/lib/commonjs/components/SignIn.js.map +0 -1
  91. package/lib/commonjs/components/images/CheckmarkFilled.js +0 -40
  92. package/lib/commonjs/components/images/CheckmarkFilled.js.map +0 -1
  93. package/lib/commonjs/components/images/EmailVerifyWaiting.js +0 -100
  94. package/lib/commonjs/components/images/EmailVerifyWaiting.js.map +0 -1
  95. package/lib/commonjs/components/images/ErrorIcon.js +0 -31
  96. package/lib/commonjs/components/images/ErrorIcon.js.map +0 -1
  97. package/lib/commonjs/components/images/PhoneVerifyWaiting.js +0 -91
  98. package/lib/commonjs/components/images/PhoneVerifyWaiting.js.map +0 -1
  99. package/lib/commonjs/data/actions.js +0 -26
  100. package/lib/commonjs/data/actions.js.map +0 -1
  101. package/lib/commonjs/hooks/api.js +0 -155
  102. package/lib/commonjs/hooks/api.js.map +0 -1
  103. package/lib/commonjs/hooks/debounce.js +0 -38
  104. package/lib/commonjs/hooks/debounce.js.map +0 -1
  105. package/lib/commonjs/hooks/fingerprint.js +0 -176
  106. package/lib/commonjs/hooks/fingerprint.js.map +0 -1
  107. package/lib/commonjs/hooks/index.js +0 -48
  108. package/lib/commonjs/hooks/index.js.map +0 -1
  109. package/lib/commonjs/hooks/interval.js +0 -31
  110. package/lib/commonjs/hooks/interval.js.map +0 -1
  111. package/lib/commonjs/hooks/nav.js +0 -39
  112. package/lib/commonjs/hooks/nav.js.map +0 -1
  113. package/lib/commonjs/index.tsx.bak +0 -26
  114. package/lib/commonjs/types.js +0 -2
  115. package/lib/commonjs/types.js.map +0 -1
  116. package/lib/commonjs/utils/events.js +0 -57
  117. package/lib/commonjs/utils/events.js.map +0 -1
  118. package/lib/commonjs/utils/form.js +0 -46
  119. package/lib/commonjs/utils/form.js.map +0 -1
  120. package/lib/commonjs/utils/queue.js +0 -117
  121. package/lib/commonjs/utils/queue.js.map +0 -1
  122. package/lib/commonjs/utils/storage.js +0 -15
  123. package/lib/commonjs/utils/storage.js.map +0 -1
  124. package/lib/commonjs/utils/tokens.js +0 -35
  125. package/lib/commonjs/utils/tokens.js.map +0 -1
  126. package/lib/commonjs/utils/user-data.js +0 -21
  127. package/lib/commonjs/utils/user-data.js.map +0 -1
  128. package/lib/module/assets/images/checkmark--filled.svg +0 -12
  129. package/lib/module/assets/images/email-verify-waiting.svg +0 -36
  130. package/lib/module/assets/images/error-icon-material.svg +0 -1
  131. package/lib/module/assets/images/phone-verify-waiting.svg +0 -26
  132. package/lib/module/components/AuthenticatedComponent.js +0 -24
  133. package/lib/module/components/AuthenticatedComponent.js.map +0 -1
  134. package/lib/module/components/AutoSigninDialog.js +0 -110
  135. package/lib/module/components/AutoSigninDialog.js.map +0 -1
  136. package/lib/module/components/BottomSheetTextInput/BottomSheetTextInput.js +0 -52
  137. package/lib/module/components/BottomSheetTextInput/BottomSheetTextInput.js.map +0 -1
  138. package/lib/module/components/BottomSheetTextInput/index.js +0 -5
  139. package/lib/module/components/BottomSheetTextInput/index.js.map +0 -1
  140. package/lib/module/components/BottomSheetTextInput/types.js +0 -2
  141. package/lib/module/components/BottomSheetTextInput/types.js.map +0 -1
  142. package/lib/module/components/DarkText.js +0 -24
  143. package/lib/module/components/DarkText.js.map +0 -1
  144. package/lib/module/components/DefaultContext.js +0 -244
  145. package/lib/module/components/DefaultContext.js.map +0 -1
  146. package/lib/module/components/RowndComponents.js +0 -12
  147. package/lib/module/components/RowndComponents.js.map +0 -1
  148. package/lib/module/components/RowndProvider.js +0 -39
  149. package/lib/module/components/RowndProvider.js.map +0 -1
  150. package/lib/module/components/SignIn.js +0 -610
  151. package/lib/module/components/SignIn.js.map +0 -1
  152. package/lib/module/components/images/CheckmarkFilled.js +0 -27
  153. package/lib/module/components/images/CheckmarkFilled.js.map +0 -1
  154. package/lib/module/components/images/EmailVerifyWaiting.js +0 -87
  155. package/lib/module/components/images/EmailVerifyWaiting.js.map +0 -1
  156. package/lib/module/components/images/ErrorIcon.js +0 -18
  157. package/lib/module/components/images/ErrorIcon.js.map +0 -1
  158. package/lib/module/components/images/PhoneVerifyWaiting.js +0 -78
  159. package/lib/module/components/images/PhoneVerifyWaiting.js.map +0 -1
  160. package/lib/module/data/actions.js +0 -19
  161. package/lib/module/data/actions.js.map +0 -1
  162. package/lib/module/hooks/api.js +0 -135
  163. package/lib/module/hooks/api.js.map +0 -1
  164. package/lib/module/hooks/debounce.js +0 -29
  165. package/lib/module/hooks/debounce.js.map +0 -1
  166. package/lib/module/hooks/fingerprint.js +0 -157
  167. package/lib/module/hooks/fingerprint.js.map +0 -1
  168. package/lib/module/hooks/index.js +0 -7
  169. package/lib/module/hooks/index.js.map +0 -1
  170. package/lib/module/hooks/interval.js +0 -23
  171. package/lib/module/hooks/interval.js.map +0 -1
  172. package/lib/module/hooks/nav.js +0 -30
  173. package/lib/module/hooks/nav.js.map +0 -1
  174. package/lib/module/index.tsx.bak +0 -26
  175. package/lib/module/types.js +0 -2
  176. package/lib/module/types.js.map +0 -1
  177. package/lib/module/utils/events.js +0 -45
  178. package/lib/module/utils/events.js.map +0 -1
  179. package/lib/module/utils/form.js +0 -34
  180. package/lib/module/utils/form.js.map +0 -1
  181. package/lib/module/utils/queue.js +0 -109
  182. package/lib/module/utils/queue.js.map +0 -1
  183. package/lib/module/utils/storage.js +0 -6
  184. package/lib/module/utils/storage.js.map +0 -1
  185. package/lib/module/utils/tokens.js +0 -24
  186. package/lib/module/utils/tokens.js.map +0 -1
  187. package/lib/module/utils/user-data.js +0 -14
  188. package/lib/module/utils/user-data.js.map +0 -1
  189. package/lib/package.json +0 -173
  190. package/lib/typescript/src/components/AuthenticatedComponent.d.ts +0 -7
  191. package/lib/typescript/src/components/AutoSigninDialog.d.ts +0 -2
  192. package/lib/typescript/src/components/BottomSheetTextInput/BottomSheetTextInput.d.ts +0 -4
  193. package/lib/typescript/src/components/BottomSheetTextInput/index.d.ts +0 -2
  194. package/lib/typescript/src/components/BottomSheetTextInput/types.d.ts +0 -3
  195. package/lib/typescript/src/components/DarkText.d.ts +0 -3
  196. package/lib/typescript/src/components/DefaultContext.d.ts +0 -12
  197. package/lib/typescript/src/components/RowndComponents.d.ts +0 -2
  198. package/lib/typescript/src/components/RowndProvider.d.ts +0 -8
  199. package/lib/typescript/src/components/SignIn.d.ts +0 -2
  200. package/lib/typescript/src/components/images/CheckmarkFilled.d.ts +0 -4
  201. package/lib/typescript/src/components/images/EmailVerifyWaiting.d.ts +0 -4
  202. package/lib/typescript/src/components/images/ErrorIcon.d.ts +0 -4
  203. package/lib/typescript/src/components/images/PhoneVerifyWaiting.d.ts +0 -4
  204. package/lib/typescript/src/data/actions.d.ts +0 -20
  205. package/lib/typescript/src/hooks/api.d.ts +0 -12
  206. package/lib/typescript/src/hooks/debounce.d.ts +0 -5
  207. package/lib/typescript/src/hooks/fingerprint.d.ts +0 -12
  208. package/lib/typescript/src/hooks/index.d.ts +0 -6
  209. package/lib/typescript/src/hooks/interval.d.ts +0 -2
  210. package/lib/typescript/src/hooks/nav.d.ts +0 -6
  211. package/lib/typescript/src/index.d.ts +0 -4
  212. package/lib/typescript/src/types.d.ts +0 -26
  213. package/lib/typescript/src/utils/config.d.ts +0 -18
  214. package/lib/typescript/src/utils/events.d.ts +0 -22
  215. package/lib/typescript/src/utils/form.d.ts +0 -18
  216. package/lib/typescript/src/utils/queue.d.ts +0 -21
  217. package/lib/typescript/src/utils/storage.d.ts +0 -3
  218. package/lib/typescript/src/utils/tokens.d.ts +0 -4
  219. package/lib/typescript/src/utils/user-data.d.ts +0 -3
  220. package/react-native.podspec +0 -19
  221. package/src/assets/images/checkmark--filled.svg +0 -12
  222. package/src/assets/images/email-verify-waiting.svg +0 -36
  223. package/src/assets/images/error-icon-material.svg +0 -1
  224. package/src/assets/images/phone-verify-waiting.svg +0 -26
  225. package/src/components/AuthenticatedComponent.tsx +0 -30
  226. package/src/components/AutoSigninDialog.tsx +0 -131
  227. package/src/components/BottomSheetTextInput/BottomSheetTextInput.tsx +0 -57
  228. package/src/components/BottomSheetTextInput/index.ts +0 -5
  229. package/src/components/BottomSheetTextInput/types.ts +0 -3
  230. package/src/components/DarkText.tsx +0 -16
  231. package/src/components/DefaultContext.tsx +0 -278
  232. package/src/components/RowndComponents.tsx +0 -18
  233. package/src/components/RowndProvider.tsx +0 -56
  234. package/src/components/SignIn.tsx +0 -793
  235. package/src/components/images/CheckmarkFilled.tsx +0 -30
  236. package/src/components/images/EmailVerifyWaiting.tsx +0 -95
  237. package/src/components/images/ErrorIcon.tsx +0 -11
  238. package/src/components/images/PhoneVerifyWaiting.tsx +0 -74
  239. package/src/data/actions.ts +0 -21
  240. package/src/hooks/api.ts +0 -162
  241. package/src/hooks/debounce.ts +0 -36
  242. package/src/hooks/fingerprint.ts +0 -217
  243. package/src/hooks/index.ts +0 -7
  244. package/src/hooks/interval.ts +0 -25
  245. package/src/hooks/nav.tsx +0 -29
  246. package/src/index.tsx.bak +0 -26
  247. package/src/types.ts +0 -27
  248. package/src/utils/events.ts +0 -54
  249. package/src/utils/form.tsx +0 -64
  250. package/src/utils/queue.ts +0 -75
  251. package/src/utils/storage.ts +0 -7
  252. package/src/utils/tokens.ts +0 -26
  253. package/src/utils/user-data.ts +0 -15
@@ -1,131 +0,0 @@
1
- import React, { useMemo, useCallback, useEffect, useRef } from 'react';
2
- import { View, Text, StyleSheet, ActivityIndicator } from 'react-native';
3
- import {
4
- BottomSheetBackdrop,
5
- BottomSheetBackdropProps,
6
- BottomSheetModal,
7
- } from '@gorhom/bottom-sheet';
8
- import bottomSheetMeta from '@gorhom/bottom-sheet/package.json';
9
- import { useTimeout } from 'usehooks-ts';
10
-
11
- import { useNav } from '../hooks';
12
- import { useGlobalContext } from './GlobalContext';
13
-
14
- import ErrorIcon from './images/ErrorIcon';
15
-
16
- export function AutoSigninDialog() {
17
- const navTo = useNav();
18
- const { state } = useGlobalContext();
19
-
20
- // Let the user know they're auto signing-in, then close when done
21
- useTimeout(() => {
22
- if (state?.nav?.options?.type === 'error') {
23
- return;
24
- }
25
-
26
- handleClose();
27
- }, 3000);
28
-
29
- const bottomSheetModalRef = useRef<BottomSheetModal>(null);
30
- useEffect(() => {
31
- if (bottomSheetModalRef.current) {
32
- bottomSheetModalRef.current.present();
33
- }
34
- }, []);
35
-
36
- const handleClose = useCallback(() => {
37
- setTimeout(() => {
38
- navTo({ hide: true });
39
- }, 150);
40
- }, [navTo]);
41
-
42
- const snapPoints = useMemo(() => ['30%', '60%'], []);
43
-
44
- const renderBackdrop = useCallback(
45
- (props: BottomSheetBackdropProps) => (
46
- <BottomSheetBackdrop {...props} pressBehavior="none" />
47
- ),
48
- []
49
- );
50
-
51
- let extraBottomSheetProps: any = {};
52
- if (bottomSheetMeta.version.startsWith('4')) {
53
- extraBottomSheetProps.keyboardBehavior = 'fillParent';
54
- extraBottomSheetProps.android_keyboardInputMode = 'adjustResize';
55
- extraBottomSheetProps.enablePanDownToClose =
56
- state?.nav?.options?.type === 'error';
57
- }
58
-
59
- return (
60
- <BottomSheetModal
61
- snapPoints={snapPoints}
62
- index={0}
63
- backdropComponent={renderBackdrop}
64
- onDismiss={handleClose}
65
- style={styles.bottomSheet}
66
- ref={bottomSheetModalRef}
67
- {...extraBottomSheetProps}
68
- >
69
- <View style={styles.innerContainer}>
70
- {state?.nav?.options?.type === 'error' && (
71
- <>
72
- <ErrorIcon />
73
- <Text style={styles.errorMessage}>
74
- {state.nav.options.message ||
75
- 'An error occurred. Please try again.'}
76
- </Text>
77
- </>
78
- )}
79
-
80
- {state?.nav?.options?.type === 'sign-in' && (
81
- <>
82
- <ActivityIndicator size="large" color="#5b0ae0" />
83
- <Text style={styles.signInMessage}>
84
- Automatically signing you in. Just a sec...
85
- </Text>
86
- </>
87
- )}
88
- </View>
89
- </BottomSheetModal>
90
- );
91
- }
92
-
93
- const styles = StyleSheet.create({
94
- modal: {
95
- // flex: 1,
96
- },
97
- bottomSheet: {
98
- shadowColor: '#000',
99
- shadowOffset: {
100
- width: 0,
101
- height: 12,
102
- },
103
- shadowOpacity: 0.58,
104
- shadowRadius: 16.0,
105
-
106
- elevation: 24,
107
- },
108
- innerContainer: {
109
- borderRadius: 20,
110
- borderColor: 'transparent',
111
- borderWidth: 0,
112
- padding: 25,
113
- textAlign: 'center',
114
- },
115
- signInMessage: {
116
- textAlign: 'center',
117
- fontSize: 24,
118
- padding: 20,
119
- },
120
- errorMessage: {
121
- textAlign: 'center',
122
- fontSize: 24,
123
- padding: 20,
124
- },
125
- errorIcon: {
126
- textAlign: 'center',
127
- color: '#DA1E28',
128
- height: 24,
129
- width: 24,
130
- },
131
- });
@@ -1,57 +0,0 @@
1
- import React, { memo, useCallback, forwardRef } from 'react';
2
- import { TextInput } from 'react-native-gesture-handler';
3
- import { BottomSheetTextInputProps } from './types';
4
-
5
- // @ts-ignore
6
- const {
7
- useBottomSheetInternal,
8
- } = require('@gorhom/bottom-sheet/src/hooks/useBottomSheetInternal');
9
-
10
- const BottomSheetTextInputComponent = forwardRef<
11
- TextInput,
12
- BottomSheetTextInputProps
13
- >(({ onFocus, onBlur, ...rest }, ref) => {
14
- //#region hooks
15
- // @ts-ignore
16
- let { shouldHandleKeyboardEvents } = useBottomSheetInternal();
17
- //#endregion
18
-
19
- if (!shouldHandleKeyboardEvents) {
20
- shouldHandleKeyboardEvents = {};
21
- }
22
-
23
- //#region callbacks
24
- const handleOnFocus = useCallback(
25
- (args) => {
26
- shouldHandleKeyboardEvents.value = true;
27
- if (onFocus) {
28
- onFocus(args);
29
- }
30
- },
31
- [onFocus, shouldHandleKeyboardEvents]
32
- );
33
- const handleOnBlur = useCallback(
34
- (args) => {
35
- shouldHandleKeyboardEvents.value = false;
36
- if (onBlur) {
37
- onBlur(args);
38
- }
39
- },
40
- [onBlur, shouldHandleKeyboardEvents]
41
- );
42
- //#endregion
43
-
44
- return (
45
- <TextInput
46
- ref={ref}
47
- onFocus={handleOnFocus}
48
- onBlur={handleOnBlur}
49
- {...rest}
50
- />
51
- );
52
- });
53
-
54
- const BottomSheetTextInput = memo(BottomSheetTextInputComponent);
55
- BottomSheetTextInput.displayName = 'BottomSheetTextInput';
56
-
57
- export default BottomSheetTextInput;
@@ -1,5 +0,0 @@
1
- // @ts-ignore
2
- export { default } from './BottomSheetTextInput';
3
-
4
- // @ts-ignore
5
- export { BottomSheetTextInputProps } from './types';
@@ -1,3 +0,0 @@
1
- import { TextInputProps } from 'react-native';
2
-
3
- export interface BottomSheetTextInputProps extends TextInputProps {}
@@ -1,16 +0,0 @@
1
- import React from 'react';
2
- import { Text, TextProps, TextStyle } from 'react-native';
3
-
4
- export default function DarkText({ style, children, ...rest }: TextProps) {
5
- if (style) {
6
- (style as TextStyle).color = '#000000';
7
- } else {
8
- style = { color: '#000000' };
9
- }
10
-
11
- return (
12
- <Text style={style} {...rest}>
13
- {children}
14
- </Text>
15
- );
16
- }
@@ -1,278 +0,0 @@
1
- import { useEffect, useCallback, useRef } from 'react';
2
- import isEqual from 'lodash-es/isEqual';
3
- import { useDebounce, useApi, useDeviceFingerprint } from '../hooks';
4
- import { DEFAULT_USER_AGENT } from '../hooks/api';
5
- import { IConfig } from '../utils/config';
6
- import { useGlobalContext } from './GlobalContext';
7
- import { ActionType } from '../data/actions';
8
- import ky from 'ky';
9
- import Clipboard from '@react-native-clipboard/clipboard';
10
- import base64 from 'react-native-base64';
11
- import { Linking } from 'react-native';
12
- import { events, EventType } from '../utils/events';
13
-
14
- export type UserInfoResp = {
15
- data: {
16
- [key: string]: any;
17
- };
18
- redacted: string[];
19
- };
20
-
21
- interface UserAclsResponse {
22
- acls: Record<string, { shared: boolean }>;
23
- }
24
-
25
- type DefaultContextProps = {
26
- config: IConfig;
27
- };
28
-
29
- export function DefaultContext({ config }: DefaultContextProps) {
30
- const { state, dispatch } = useGlobalContext();
31
- const { client: api } = useApi();
32
- useDeviceFingerprint();
33
-
34
- // Fetch app schema and config
35
- useEffect(() => {
36
- (async () => {
37
- try {
38
- const resp: any = await api
39
- .get('hub/app-config', {
40
- headers: {
41
- 'x-rownd-app-key': config.appKey,
42
- },
43
- })
44
- .json();
45
-
46
- if (resp?.app?.icon) {
47
- const iconMeta = await ky.get(resp.app.icon);
48
- resp.app.icon_content_type = iconMeta.headers.get('content-type');
49
- }
50
-
51
- dispatch({
52
- type: ActionType.SET_APP_CONFIG,
53
- payload: resp.app,
54
- });
55
- } catch (err) {
56
- console.error('Failed to fetch app config:', err);
57
- }
58
- })();
59
- }, [api, config.appKey, dispatch]);
60
-
61
- /**
62
- * If not signed in, check the clipboard for an init hash or auth link we can use to auto-auth the user
63
- */
64
- useEffect(() => {
65
- if (state.auth.access_token || !state.app.id) {
66
- return;
67
- }
68
-
69
- (async () => {
70
- try {
71
- let authData = null;
72
-
73
- let authLink =
74
- (await Linking.getInitialURL()) || (await Clipboard.getString());
75
- if (authLink.includes('rownd.link')) {
76
- dispatch({
77
- type: ActionType.CHANGE_ROUTE,
78
- payload: {
79
- route: '/account/auto-signin',
80
- opts: {
81
- type: 'sign-in',
82
- },
83
- },
84
- });
85
-
86
- authData = await ky
87
- .get(authLink, {
88
- headers: {
89
- 'User-Agent': DEFAULT_USER_AGENT,
90
- },
91
- })
92
- .json();
93
- } else if (authLink.startsWith('rph_init=')) {
94
- const authStr = authLink.split('rph_init=')[1];
95
- authData = JSON.parse(base64.decode(authStr));
96
- } else {
97
- return;
98
- }
99
-
100
- // Clear the clipboard value so we don't leak any creds
101
- Clipboard.setString('');
102
-
103
- dispatch({
104
- type: ActionType.LOGIN_SUCCESS,
105
- payload: authData,
106
- });
107
- } catch (err) {
108
- console.error(
109
- 'We found an auth link or string, but failed to authenticate with it because:',
110
- err
111
- );
112
- }
113
- })();
114
- }, [state.auth.access_token, state.app.id, dispatch]);
115
-
116
- const retrieveUserInfo = useCallback(() => {
117
- if (!state.auth.access_token || !state.app.id) {
118
- return;
119
- }
120
-
121
- (async () => {
122
- const userInfo: UserInfoResp = await api
123
- .get(`me/applications/${state.app.id}/data`, {
124
- headers: {
125
- Authorization: `Bearer ${state.auth.access_token}`,
126
- },
127
- })
128
- .json();
129
- dispatch({
130
- type: ActionType.LOAD_USER,
131
- payload: userInfo,
132
- });
133
-
134
- dispatch({
135
- type: ActionType.UPDATE_LOCAL_ACLS,
136
- payload: userInfo.redacted.reduce(
137
- (acc: Record<string, any>, field: string) => {
138
- acc[field] = { shared: false };
139
- return acc;
140
- },
141
- {}
142
- ),
143
- });
144
- })();
145
- }, [api, dispatch, state.app.id, state.auth.access_token]);
146
-
147
- const retrieveAcls = useCallback(() => {
148
- if (!state.app.id || !state.auth.access_token) {
149
- return;
150
- }
151
-
152
- (async () => {
153
- try {
154
- const appUserAcls: UserAclsResponse = await api
155
- .get(`me/applications/${state.app.id}/acls`, {
156
- headers: {
157
- Authorization: `Bearer ${state.auth.access_token}`,
158
- },
159
- })
160
- .json();
161
- dispatch({
162
- type: ActionType.UPDATE_LOCAL_ACLS,
163
- payload: appUserAcls.acls,
164
- });
165
- } catch (err) {
166
- if (err instanceof Error) {
167
- // const unsharedAcls = reduceSchemaToUnsharedAcls();
168
- dispatch({
169
- type: ActionType.UPDATE_LOCAL_ACLS,
170
- payload: {},
171
- });
172
- }
173
- }
174
- })();
175
- }, [api, dispatch, state.app.id, state.auth.access_token]);
176
-
177
- useEffect(retrieveUserInfo, [retrieveUserInfo]);
178
- useEffect(retrieveAcls, [retrieveAcls]);
179
-
180
- useEffect(() => {
181
- if (!state.user.needs_refresh) {
182
- return;
183
- }
184
- retrieveUserInfo();
185
- dispatch({
186
- type: ActionType.SET_REFRESH_USER_DATA,
187
- payload: { needs_refresh: false },
188
- });
189
- }, [dispatch, retrieveUserInfo, state.user.needs_refresh]);
190
-
191
- const saveAclsDebounced = useDebounce(saveAcls, 2000); // 2s
192
-
193
- async function saveAcls() {
194
- if (state.app.id && state.local_acls) {
195
- await api
196
- .put(`me/applications/${state.app.id}/acls`, {
197
- headers: {
198
- Authorization: `Bearer ${state.auth.access_token}`,
199
- },
200
- json: {
201
- acls: state.local_acls,
202
- },
203
- })
204
- .json();
205
- }
206
- }
207
-
208
- const localAclsRef = useRef(state.local_acls);
209
- useEffect(() => {
210
- // Don't save acls if they were just loaded for the first time or they haven't changed
211
- if (
212
- !localAclsRef.current ||
213
- isEqual(localAclsRef.current, state.local_acls)
214
- ) {
215
- return;
216
- }
217
- saveAclsDebounced();
218
- }, [saveAclsDebounced, state.local_acls]);
219
-
220
- const saveUserDataDebounced = useDebounce(saveUserData, 2000); // 2s
221
-
222
- // Save user data in the application state to the API server
223
- async function saveUserData() {
224
- if (state.app.id && state.user.data && state.auth.access_token) {
225
- dispatch({
226
- type: ActionType.SET_IS_SAVING_USER_DATA,
227
- payload: {
228
- saving: true,
229
- },
230
- });
231
-
232
- const eventDetails: Record<string, any> = {};
233
- try {
234
- eventDetails.data = await api
235
- .put(`me/applications/${state.app.id}/data`, {
236
- headers: {
237
- Authorization: `Bearer ${state.auth.access_token}`,
238
- },
239
- json: {
240
- data: state.user.data,
241
- },
242
- })
243
- .json();
244
- } catch (err) {
245
- eventDetails.error = err;
246
- // Get the latest user info from Rownd. Something was probably bad
247
- // with the data we just tried to save.
248
- // This is a bit hacky. We should be able to reset the state without
249
- // calling rownd again by rolling back to a previously good state...
250
- retrieveUserInfo();
251
- // TODO: Set some error state
252
- } finally {
253
- events.dispatch(EventType.USER_DATA_SAVED, eventDetails);
254
- dispatch({
255
- type: ActionType.SET_IS_SAVING_USER_DATA,
256
- payload: {
257
- saving: false,
258
- },
259
- });
260
- }
261
- }
262
- }
263
-
264
- const userDataRef = useRef(state.user.data);
265
- useEffect(() => {
266
- // Don't update the user data in the API server if the email is unknown or the data hasn't changed
267
- if (
268
- (!state.user.data?.email && !state.user.data.phone_number) ||
269
- isEqual(userDataRef.current, state.user.data)
270
- ) {
271
- return;
272
- }
273
- saveUserDataDebounced();
274
- userDataRef.current = state.user.data;
275
- }, [dispatch, saveUserDataDebounced, state.user.data]);
276
-
277
- return null;
278
- }
@@ -1,18 +0,0 @@
1
- import React from 'react';
2
- import { SignIn } from './SignIn';
3
- import { AutoSigninDialog } from './AutoSigninDialog';
4
- import { useGlobalContext } from './GlobalContext';
5
-
6
- export function RowndComponents() {
7
- const { state } = useGlobalContext();
8
- // useDeviceContext(tw);
9
-
10
- return (
11
- <>
12
- {state.nav.current_route === '/account/login' && <SignIn />}
13
- {state.nav.current_route === '/account/auto-signin' && (
14
- <AutoSigninDialog />
15
- )}
16
- </>
17
- );
18
- }
@@ -1,56 +0,0 @@
1
- import React from 'react';
2
- import { View, StyleSheet } from 'react-native';
3
- import { GlobalContextProvider } from './GlobalContext';
4
- import { DefaultContext } from './DefaultContext';
5
- import { createConfig } from '../utils/config';
6
- import { RowndComponents } from './RowndComponents';
7
- import { BottomSheetModalProvider } from '@gorhom/bottom-sheet';
8
-
9
- // const RowndContext = createContext<TRowndContext | undefined>(undefined);
10
-
11
- interface IRowndProviderProps {
12
- appKey: string;
13
- apiUrl?: string;
14
- children: React.ReactNode;
15
- }
16
-
17
- export function RowndProvider({
18
- appKey,
19
- apiUrl,
20
- children,
21
- }: IRowndProviderProps) {
22
- // const [isSigningIn, setIsSigningIn] = useState<boolean>(false);
23
-
24
- // const requestSignIn = useRef(function () {
25
- // setIsSigningIn(true);
26
- // });
27
-
28
- // const [rowndState, setRowndState] = useState<any>({
29
- // requestSignIn: requestSignIn.current,
30
- // });
31
-
32
- const config = createConfig({
33
- appKey,
34
- apiUrl,
35
- });
36
-
37
- return (
38
- <GlobalContextProvider config={config}>
39
- <DefaultContext config={config} />
40
- <BottomSheetModalProvider>
41
- <View style={styles.container}>
42
- <>
43
- {children}
44
- <RowndComponents />
45
- </>
46
- </View>
47
- </BottomSheetModalProvider>
48
- </GlobalContextProvider>
49
- );
50
- }
51
-
52
- const styles = StyleSheet.create({
53
- container: {
54
- flex: 1,
55
- },
56
- });