@rownd/react-native 0.2.5 → 2.2.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 (252) hide show
  1. package/LICENSE +1 -2
  2. package/README.md +34 -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/RowndPlugin-Bridging-Header.h +3 -0
  10. package/ios/RowndPlugin.m +26 -0
  11. package/ios/RowndPlugin.swift +83 -0
  12. package/ios/RowndPluginEventEmitter.m +12 -0
  13. package/ios/RowndPluginEventEmitter.swift +19 -0
  14. package/lib/commonjs/components/GlobalContext.js +32 -298
  15. package/lib/commonjs/components/GlobalContext.js.map +1 -1
  16. package/lib/commonjs/components/{BottomSheetTextInput/types.js → GlobalContext.types.js} +1 -1
  17. package/lib/commonjs/components/GlobalContext.types.js.map +1 -0
  18. package/lib/commonjs/constants/action.js +13 -0
  19. package/lib/commonjs/constants/action.js.map +1 -0
  20. package/lib/commonjs/hooks/rownd.js +15 -146
  21. package/lib/commonjs/hooks/rownd.js.map +1 -1
  22. package/lib/commonjs/index.js +2 -12
  23. package/lib/commonjs/index.js.map +1 -1
  24. package/lib/commonjs/reducer/rowndReducer.js +89 -0
  25. package/lib/commonjs/reducer/rowndReducer.js.map +1 -0
  26. package/lib/commonjs/utils/config.js +0 -26
  27. package/lib/commonjs/utils/config.js.map +1 -1
  28. package/lib/commonjs/utils/nativeModule.js +72 -0
  29. package/lib/commonjs/utils/nativeModule.js.map +1 -0
  30. package/lib/module/components/GlobalContext.js +30 -293
  31. package/lib/module/components/GlobalContext.js.map +1 -1
  32. package/lib/module/components/GlobalContext.types.js +2 -0
  33. package/lib/module/components/GlobalContext.types.js.map +1 -0
  34. package/lib/module/constants/action.js +6 -0
  35. package/lib/module/constants/action.js.map +1 -0
  36. package/lib/module/hooks/rownd.js +12 -137
  37. package/lib/module/hooks/rownd.js.map +1 -1
  38. package/lib/module/index.js +2 -4
  39. package/lib/module/index.js.map +1 -1
  40. package/lib/module/reducer/rowndReducer.js +78 -0
  41. package/lib/module/reducer/rowndReducer.js.map +1 -0
  42. package/lib/module/utils/config.js +1 -16
  43. package/lib/module/utils/config.js.map +1 -1
  44. package/lib/module/utils/nativeModule.js +48 -0
  45. package/lib/module/utils/nativeModule.js.map +1 -0
  46. package/lib/typescript/components/GlobalContext.d.ts +13 -0
  47. package/lib/typescript/{src/components/GlobalContext.d.ts → components/GlobalContext.types.d.ts} +9 -35
  48. package/lib/typescript/constants/action.d.ts +7 -0
  49. package/lib/typescript/{src/hooks → hooks}/rownd.d.ts +10 -13
  50. package/lib/typescript/index.d.ts +3 -0
  51. package/lib/typescript/reducer/rowndReducer.d.ts +4 -0
  52. package/lib/typescript/utils/config.d.ts +10 -0
  53. package/lib/typescript/utils/nativeModule.d.ts +10 -0
  54. package/package.json +36 -56
  55. package/rownd-react-native.podspec +36 -0
  56. package/src/components/GlobalContext.tsx +47 -457
  57. package/src/components/GlobalContext.types.ts +105 -0
  58. package/src/constants/action.ts +8 -0
  59. package/src/hooks/rownd.ts +29 -147
  60. package/src/index.tsx +2 -4
  61. package/src/reducer/rowndReducer.ts +78 -0
  62. package/src/utils/config.ts +0 -27
  63. package/src/utils/nativeModule.ts +69 -0
  64. package/android/src/main/java/com/reactnative/ReactNativePackage.java +0 -22
  65. package/android/src/main/java/com/reactnative/ReactNativeViewManager.java +0 -31
  66. package/ios/ReactNativeViewManager.m +0 -34
  67. package/lib/commonjs/assets/images/checkmark--filled.svg +0 -12
  68. package/lib/commonjs/assets/images/email-verify-waiting.svg +0 -36
  69. package/lib/commonjs/assets/images/error-icon-material.svg +0 -1
  70. package/lib/commonjs/assets/images/phone-verify-waiting.svg +0 -26
  71. package/lib/commonjs/components/AuthenticatedComponent.js +0 -35
  72. package/lib/commonjs/components/AuthenticatedComponent.js.map +0 -1
  73. package/lib/commonjs/components/AutoSigninDialog.js +0 -132
  74. package/lib/commonjs/components/AutoSigninDialog.js.map +0 -1
  75. package/lib/commonjs/components/BottomSheetTextInput/BottomSheetTextInput.js +0 -65
  76. package/lib/commonjs/components/BottomSheetTextInput/BottomSheetTextInput.js.map +0 -1
  77. package/lib/commonjs/components/BottomSheetTextInput/index.js +0 -24
  78. package/lib/commonjs/components/BottomSheetTextInput/index.js.map +0 -1
  79. package/lib/commonjs/components/BottomSheetTextInput/types.js.map +0 -1
  80. package/lib/commonjs/components/DarkText.js +0 -35
  81. package/lib/commonjs/components/DarkText.js.map +0 -1
  82. package/lib/commonjs/components/DefaultContext.js +0 -266
  83. package/lib/commonjs/components/DefaultContext.js.map +0 -1
  84. package/lib/commonjs/components/RowndComponents.js +0 -25
  85. package/lib/commonjs/components/RowndComponents.js.map +0 -1
  86. package/lib/commonjs/components/RowndProvider.js +0 -55
  87. package/lib/commonjs/components/RowndProvider.js.map +0 -1
  88. package/lib/commonjs/components/SignIn.js +0 -644
  89. package/lib/commonjs/components/SignIn.js.map +0 -1
  90. package/lib/commonjs/components/images/CheckmarkFilled.js +0 -40
  91. package/lib/commonjs/components/images/CheckmarkFilled.js.map +0 -1
  92. package/lib/commonjs/components/images/EmailVerifyWaiting.js +0 -100
  93. package/lib/commonjs/components/images/EmailVerifyWaiting.js.map +0 -1
  94. package/lib/commonjs/components/images/ErrorIcon.js +0 -31
  95. package/lib/commonjs/components/images/ErrorIcon.js.map +0 -1
  96. package/lib/commonjs/components/images/PhoneVerifyWaiting.js +0 -91
  97. package/lib/commonjs/components/images/PhoneVerifyWaiting.js.map +0 -1
  98. package/lib/commonjs/data/actions.js +0 -26
  99. package/lib/commonjs/data/actions.js.map +0 -1
  100. package/lib/commonjs/hooks/api.js +0 -155
  101. package/lib/commonjs/hooks/api.js.map +0 -1
  102. package/lib/commonjs/hooks/debounce.js +0 -38
  103. package/lib/commonjs/hooks/debounce.js.map +0 -1
  104. package/lib/commonjs/hooks/fingerprint.js +0 -176
  105. package/lib/commonjs/hooks/fingerprint.js.map +0 -1
  106. package/lib/commonjs/hooks/index.js +0 -48
  107. package/lib/commonjs/hooks/index.js.map +0 -1
  108. package/lib/commonjs/hooks/interval.js +0 -31
  109. package/lib/commonjs/hooks/interval.js.map +0 -1
  110. package/lib/commonjs/hooks/nav.js +0 -39
  111. package/lib/commonjs/hooks/nav.js.map +0 -1
  112. package/lib/commonjs/index.tsx.bak +0 -26
  113. package/lib/commonjs/types.js +0 -2
  114. package/lib/commonjs/types.js.map +0 -1
  115. package/lib/commonjs/utils/events.js +0 -57
  116. package/lib/commonjs/utils/events.js.map +0 -1
  117. package/lib/commonjs/utils/form.js +0 -46
  118. package/lib/commonjs/utils/form.js.map +0 -1
  119. package/lib/commonjs/utils/queue.js +0 -117
  120. package/lib/commonjs/utils/queue.js.map +0 -1
  121. package/lib/commonjs/utils/storage.js +0 -15
  122. package/lib/commonjs/utils/storage.js.map +0 -1
  123. package/lib/commonjs/utils/tokens.js +0 -35
  124. package/lib/commonjs/utils/tokens.js.map +0 -1
  125. package/lib/commonjs/utils/user-data.js +0 -21
  126. package/lib/commonjs/utils/user-data.js.map +0 -1
  127. package/lib/module/assets/images/checkmark--filled.svg +0 -12
  128. package/lib/module/assets/images/email-verify-waiting.svg +0 -36
  129. package/lib/module/assets/images/error-icon-material.svg +0 -1
  130. package/lib/module/assets/images/phone-verify-waiting.svg +0 -26
  131. package/lib/module/components/AuthenticatedComponent.js +0 -24
  132. package/lib/module/components/AuthenticatedComponent.js.map +0 -1
  133. package/lib/module/components/AutoSigninDialog.js +0 -110
  134. package/lib/module/components/AutoSigninDialog.js.map +0 -1
  135. package/lib/module/components/BottomSheetTextInput/BottomSheetTextInput.js +0 -52
  136. package/lib/module/components/BottomSheetTextInput/BottomSheetTextInput.js.map +0 -1
  137. package/lib/module/components/BottomSheetTextInput/index.js +0 -5
  138. package/lib/module/components/BottomSheetTextInput/index.js.map +0 -1
  139. package/lib/module/components/BottomSheetTextInput/types.js +0 -2
  140. package/lib/module/components/BottomSheetTextInput/types.js.map +0 -1
  141. package/lib/module/components/DarkText.js +0 -24
  142. package/lib/module/components/DarkText.js.map +0 -1
  143. package/lib/module/components/DefaultContext.js +0 -244
  144. package/lib/module/components/DefaultContext.js.map +0 -1
  145. package/lib/module/components/RowndComponents.js +0 -12
  146. package/lib/module/components/RowndComponents.js.map +0 -1
  147. package/lib/module/components/RowndProvider.js +0 -39
  148. package/lib/module/components/RowndProvider.js.map +0 -1
  149. package/lib/module/components/SignIn.js +0 -616
  150. package/lib/module/components/SignIn.js.map +0 -1
  151. package/lib/module/components/images/CheckmarkFilled.js +0 -27
  152. package/lib/module/components/images/CheckmarkFilled.js.map +0 -1
  153. package/lib/module/components/images/EmailVerifyWaiting.js +0 -87
  154. package/lib/module/components/images/EmailVerifyWaiting.js.map +0 -1
  155. package/lib/module/components/images/ErrorIcon.js +0 -18
  156. package/lib/module/components/images/ErrorIcon.js.map +0 -1
  157. package/lib/module/components/images/PhoneVerifyWaiting.js +0 -78
  158. package/lib/module/components/images/PhoneVerifyWaiting.js.map +0 -1
  159. package/lib/module/data/actions.js +0 -19
  160. package/lib/module/data/actions.js.map +0 -1
  161. package/lib/module/hooks/api.js +0 -135
  162. package/lib/module/hooks/api.js.map +0 -1
  163. package/lib/module/hooks/debounce.js +0 -29
  164. package/lib/module/hooks/debounce.js.map +0 -1
  165. package/lib/module/hooks/fingerprint.js +0 -157
  166. package/lib/module/hooks/fingerprint.js.map +0 -1
  167. package/lib/module/hooks/index.js +0 -7
  168. package/lib/module/hooks/index.js.map +0 -1
  169. package/lib/module/hooks/interval.js +0 -23
  170. package/lib/module/hooks/interval.js.map +0 -1
  171. package/lib/module/hooks/nav.js +0 -30
  172. package/lib/module/hooks/nav.js.map +0 -1
  173. package/lib/module/index.tsx.bak +0 -26
  174. package/lib/module/types.js +0 -2
  175. package/lib/module/types.js.map +0 -1
  176. package/lib/module/utils/events.js +0 -45
  177. package/lib/module/utils/events.js.map +0 -1
  178. package/lib/module/utils/form.js +0 -34
  179. package/lib/module/utils/form.js.map +0 -1
  180. package/lib/module/utils/queue.js +0 -109
  181. package/lib/module/utils/queue.js.map +0 -1
  182. package/lib/module/utils/storage.js +0 -6
  183. package/lib/module/utils/storage.js.map +0 -1
  184. package/lib/module/utils/tokens.js +0 -24
  185. package/lib/module/utils/tokens.js.map +0 -1
  186. package/lib/module/utils/user-data.js +0 -14
  187. package/lib/module/utils/user-data.js.map +0 -1
  188. package/lib/package.json +0 -173
  189. package/lib/typescript/src/components/AuthenticatedComponent.d.ts +0 -7
  190. package/lib/typescript/src/components/AutoSigninDialog.d.ts +0 -2
  191. package/lib/typescript/src/components/BottomSheetTextInput/BottomSheetTextInput.d.ts +0 -4
  192. package/lib/typescript/src/components/BottomSheetTextInput/index.d.ts +0 -2
  193. package/lib/typescript/src/components/BottomSheetTextInput/types.d.ts +0 -3
  194. package/lib/typescript/src/components/DarkText.d.ts +0 -3
  195. package/lib/typescript/src/components/DefaultContext.d.ts +0 -12
  196. package/lib/typescript/src/components/RowndComponents.d.ts +0 -2
  197. package/lib/typescript/src/components/RowndProvider.d.ts +0 -8
  198. package/lib/typescript/src/components/SignIn.d.ts +0 -2
  199. package/lib/typescript/src/components/images/CheckmarkFilled.d.ts +0 -4
  200. package/lib/typescript/src/components/images/EmailVerifyWaiting.d.ts +0 -4
  201. package/lib/typescript/src/components/images/ErrorIcon.d.ts +0 -4
  202. package/lib/typescript/src/components/images/PhoneVerifyWaiting.d.ts +0 -4
  203. package/lib/typescript/src/data/actions.d.ts +0 -20
  204. package/lib/typescript/src/hooks/api.d.ts +0 -12
  205. package/lib/typescript/src/hooks/debounce.d.ts +0 -5
  206. package/lib/typescript/src/hooks/fingerprint.d.ts +0 -12
  207. package/lib/typescript/src/hooks/index.d.ts +0 -6
  208. package/lib/typescript/src/hooks/interval.d.ts +0 -2
  209. package/lib/typescript/src/hooks/nav.d.ts +0 -6
  210. package/lib/typescript/src/index.d.ts +0 -4
  211. package/lib/typescript/src/types.d.ts +0 -26
  212. package/lib/typescript/src/utils/config.d.ts +0 -18
  213. package/lib/typescript/src/utils/events.d.ts +0 -22
  214. package/lib/typescript/src/utils/form.d.ts +0 -18
  215. package/lib/typescript/src/utils/queue.d.ts +0 -21
  216. package/lib/typescript/src/utils/storage.d.ts +0 -3
  217. package/lib/typescript/src/utils/tokens.d.ts +0 -4
  218. package/lib/typescript/src/utils/user-data.d.ts +0 -3
  219. package/react-native.podspec +0 -19
  220. package/src/assets/images/checkmark--filled.svg +0 -12
  221. package/src/assets/images/email-verify-waiting.svg +0 -36
  222. package/src/assets/images/error-icon-material.svg +0 -1
  223. package/src/assets/images/phone-verify-waiting.svg +0 -26
  224. package/src/components/AuthenticatedComponent.tsx +0 -30
  225. package/src/components/AutoSigninDialog.tsx +0 -131
  226. package/src/components/BottomSheetTextInput/BottomSheetTextInput.tsx +0 -57
  227. package/src/components/BottomSheetTextInput/index.ts +0 -5
  228. package/src/components/BottomSheetTextInput/types.ts +0 -3
  229. package/src/components/DarkText.tsx +0 -16
  230. package/src/components/DefaultContext.tsx +0 -278
  231. package/src/components/RowndComponents.tsx +0 -18
  232. package/src/components/RowndProvider.tsx +0 -56
  233. package/src/components/SignIn.tsx +0 -797
  234. package/src/components/images/CheckmarkFilled.tsx +0 -30
  235. package/src/components/images/EmailVerifyWaiting.tsx +0 -95
  236. package/src/components/images/ErrorIcon.tsx +0 -11
  237. package/src/components/images/PhoneVerifyWaiting.tsx +0 -74
  238. package/src/data/actions.ts +0 -21
  239. package/src/hooks/api.ts +0 -162
  240. package/src/hooks/debounce.ts +0 -36
  241. package/src/hooks/fingerprint.ts +0 -217
  242. package/src/hooks/index.ts +0 -7
  243. package/src/hooks/interval.ts +0 -25
  244. package/src/hooks/nav.tsx +0 -29
  245. package/src/index.tsx.bak +0 -26
  246. package/src/types.ts +0 -27
  247. package/src/utils/events.ts +0 -54
  248. package/src/utils/form.tsx +0 -64
  249. package/src/utils/queue.ts +0 -75
  250. package/src/utils/storage.ts +0 -7
  251. package/src/utils/tokens.ts +0 -26
  252. 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
- });