omnipay-reactnative-sdk 1.0.4 → 1.0.6

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 (42) hide show
  1. package/README.md +41 -0
  2. package/lib/commonjs/components/OmnipayProvider.js +2 -2
  3. package/lib/commonjs/components/OmnipayProvider.js.map +1 -1
  4. package/lib/commonjs/components/OmnipayView.js +27 -6
  5. package/lib/commonjs/components/OmnipayView.js.map +1 -1
  6. package/lib/commonjs/components/views/Registration.js +135 -0
  7. package/lib/commonjs/components/views/Registration.js.map +1 -0
  8. package/lib/commonjs/index.js +5 -7
  9. package/lib/commonjs/index.js.map +1 -1
  10. package/lib/commonjs/lib/colors.js +35 -0
  11. package/lib/commonjs/lib/colors.js.map +1 -0
  12. package/lib/commonjs/lib/config.js +17 -0
  13. package/lib/commonjs/lib/config.js.map +1 -0
  14. package/lib/module/components/OmnipayProvider.js +2 -2
  15. package/lib/module/components/OmnipayProvider.js.map +1 -1
  16. package/lib/module/components/OmnipayView.js +27 -6
  17. package/lib/module/components/OmnipayView.js.map +1 -1
  18. package/lib/module/components/views/Registration.js +126 -0
  19. package/lib/module/components/views/Registration.js.map +1 -0
  20. package/lib/module/index.js +2 -1
  21. package/lib/module/index.js.map +1 -1
  22. package/lib/module/lib/colors.js +28 -0
  23. package/lib/module/lib/colors.js.map +1 -0
  24. package/lib/module/lib/config.js +9 -0
  25. package/lib/module/lib/config.js.map +1 -0
  26. package/lib/typescript/components/OmnipayView.d.ts +16 -3
  27. package/lib/typescript/components/OmnipayView.d.ts.map +1 -1
  28. package/lib/typescript/components/views/Registration.d.ts +15 -0
  29. package/lib/typescript/components/views/Registration.d.ts.map +1 -0
  30. package/lib/typescript/index.d.ts +2 -1
  31. package/lib/typescript/index.d.ts.map +1 -1
  32. package/lib/typescript/lib/colors.d.ts +28 -0
  33. package/lib/typescript/lib/colors.d.ts.map +1 -0
  34. package/lib/typescript/lib/config.d.ts +9 -0
  35. package/lib/typescript/lib/config.d.ts.map +1 -0
  36. package/package.json +1 -1
  37. package/src/components/OmnipayProvider.tsx +2 -2
  38. package/src/components/OmnipayView.tsx +31 -7
  39. package/src/components/views/Registration.tsx +163 -0
  40. package/src/index.tsx +3 -1
  41. package/src/lib/colors.ts +27 -0
  42. package/src/lib/config.ts +9 -0
@@ -0,0 +1,163 @@
1
+ import React, { Fragment, useRef, useState } from 'react';
2
+ import {
3
+ ActivityIndicator,
4
+ Platform,
5
+ StyleSheet,
6
+ Text,
7
+ View,
8
+ } from 'react-native';
9
+ import { WebView, WebViewMessageEvent } from 'react-native-webview';
10
+ import { serverSdkBaseUrl } from 'src/lib/config';
11
+
12
+ type RegisterSuccessType = {
13
+ customerRef: string;
14
+ walletId: string;
15
+ };
16
+
17
+ type OmnipayProps = {
18
+ color: string;
19
+ env: 'dev' | 'prod';
20
+ publicKey: string;
21
+ phoneNumber: string;
22
+ onRegistrationSuccessful?: ({
23
+ customerRef,
24
+ walletId,
25
+ }: RegisterSuccessType) => void;
26
+ onClose?: () => void;
27
+ };
28
+
29
+ // type PostMessage = {
30
+ // [key: string]: unknown;
31
+ // };
32
+
33
+ type Status = 'error' | 'loading' | 'success';
34
+
35
+ export const Registration = ({
36
+ color,
37
+ env,
38
+ publicKey,
39
+ phoneNumber,
40
+ onRegistrationSuccessful,
41
+ onClose,
42
+ }: OmnipayProps): JSX.Element => {
43
+ const webviewRef = useRef<WebView>(null);
44
+ const [webviewStatus, setWebviewStatus] = useState<Status>('loading');
45
+ const webHost = getWebHost();
46
+ const webUrl = getWebUrl();
47
+
48
+ const onWebviewMount = `
49
+ window.nativeOs = ${Platform.OS};
50
+ true;
51
+ `;
52
+
53
+ function getWebHost() {
54
+ return serverSdkBaseUrl[env];
55
+ }
56
+
57
+ function getWebUrl() {
58
+ const themeColor = color.includes('#') ? color.split('#')[1] : color;
59
+ return `${webHost}auth/register?theme=${themeColor}&publicKey=${publicKey}&phoneNumber=${phoneNumber}`;
60
+ }
61
+
62
+ // function postMessage(data: PostMessage) {
63
+ // if (!webviewRef.current) {
64
+ // return;
65
+ // }
66
+ // try {
67
+ // webviewRef.current.postMessage(JSON.stringify(data));
68
+ // } catch (error) {}
69
+ // }
70
+
71
+ async function onWebviewMessage(e: WebViewMessageEvent) {
72
+ try {
73
+ if (e.nativeEvent && e.nativeEvent.data) {
74
+ const eventData = JSON.parse(e.nativeEvent.data);
75
+ const { dataKey, dataValue } = eventData;
76
+
77
+ const { action, details } = JSON.parse(dataValue);
78
+
79
+ if (dataKey === 'customer.registered') {
80
+ if (onRegistrationSuccessful) {
81
+ onRegistrationSuccessful({
82
+ customerRef: details.customerRef,
83
+ walletId: details.walletId,
84
+ });
85
+ }
86
+ return;
87
+ }
88
+ if (action === 'close.registration') {
89
+ if (onClose) {
90
+ onClose();
91
+ }
92
+ return;
93
+ }
94
+ }
95
+ } catch (error) {}
96
+ }
97
+
98
+ if (!publicKey.includes('OMNIPUBKEY_')) {
99
+ return <Text>Invalid public key</Text>;
100
+ }
101
+
102
+ if (phoneNumber.length < 10) {
103
+ return <Text>Invalid phone number</Text>;
104
+ }
105
+
106
+ if (color.length < 3) {
107
+ return <Text>Invalid color</Text>;
108
+ }
109
+
110
+ if (!['dev', 'prod'].includes(env)) {
111
+ return <Text>Invalid environment</Text>;
112
+ }
113
+
114
+ return (
115
+ <Fragment>
116
+ <View style={styles.full}>
117
+ <WebView
118
+ source={{
119
+ uri: webUrl,
120
+ }}
121
+ style={styles.webview}
122
+ injectedJavaScriptBeforeContentLoaded={onWebviewMount}
123
+ onMessage={onWebviewMessage}
124
+ ref={webviewRef}
125
+ onLoadEnd={() => setWebviewStatus('success')}
126
+ />
127
+ {webviewStatus === 'loading' && (
128
+ <View style={styles.webviewLoader}>
129
+ <ActivityIndicator size="small" color={color} />
130
+ </View>
131
+ )}
132
+ </View>
133
+ </Fragment>
134
+ );
135
+ };
136
+
137
+ const styles = StyleSheet.create({
138
+ hide: {
139
+ display: 'none',
140
+ },
141
+ full: {
142
+ flex: 1,
143
+ width: '100%',
144
+ height: '100%',
145
+ },
146
+ webview: {
147
+ flex: 1,
148
+ width: '100%',
149
+ height: '100%',
150
+ },
151
+ webviewLoader: {
152
+ zIndex: 3,
153
+ backgroundColor: 'white',
154
+ alignItems: 'center',
155
+ justifyContent: 'center',
156
+ flex: 1,
157
+ width: '100%',
158
+ height: '100%',
159
+ position: 'absolute',
160
+ top: 0,
161
+ left: 0,
162
+ },
163
+ });
package/src/index.tsx CHANGED
@@ -1,3 +1,5 @@
1
+ import Omnipay from './components/OmnipayView';
2
+
1
3
  export { OmnipayProvider } from './components/OmnipayProvider';
2
4
  export { useOmnipay } from './hooks/useOmnipay';
3
- export { Omnipay } from './components/OmnipayView';
5
+ export default Omnipay;
@@ -0,0 +1,27 @@
1
+ export const colors = {
2
+ 10: 'rgba(166, 130, 255, 0.1)',
3
+ 20: 'rgba(166, 130, 255, 0.2)',
4
+ 30: 'rgba(166, 130, 255, 0.3)',
5
+ 40: 'rgba(166, 130, 255, 0.4)',
6
+ 50: 'rgba(166, 130, 255, 0.10)',
7
+ 100: '#F0E6FF',
8
+ 200: '#DFCDFF',
9
+ 300: '#CEB3FF',
10
+ 400: '#BFA1FF',
11
+ 500: '#A682FF',
12
+ 600: '#a27dff',
13
+ 700: '#5C41B7',
14
+ 800: '#3E2993',
15
+ 900: '#29187A',
16
+ 1500: '#FF9900',
17
+ black: '#1E3565',
18
+ secondary: '#E06900',
19
+ light: 'rgb(83, 100, 113)',
20
+ iconColor: 'rgba(35, 47, 73, 0.6)',
21
+ bgColor: '#D7EEEB',
22
+ grey: '#61728F',
23
+ danger: '#E32828',
24
+ black500: '#1A1D1F',
25
+ black600: '#3E4554',
26
+ darkGrey: '#6F767E',
27
+ };
@@ -0,0 +1,9 @@
1
+ export const serverSdkBaseUrl = {
2
+ dev: 'https://dev.omnipay-sdk.pages.dev/',
3
+ prod: 'https://omnipay-sdk.pages.dev/',
4
+ };
5
+
6
+ export const clientSdkBaseUrl = {
7
+ dev: 'https://omnipay-websdk.vercel.app/',
8
+ prod: 'https://sdk.omnipay.ng/',
9
+ };