react-native-fpay 0.2.9 → 0.3.2

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 (120) hide show
  1. package/lib/module/FountainPayProvider.js +5 -1
  2. package/lib/module/FountainPayProvider.js.map +1 -1
  3. package/lib/module/core/api/index.js +22 -12
  4. package/lib/module/core/api/index.js.map +1 -1
  5. package/lib/module/engine/BLEReceiverService.js.map +1 -1
  6. package/lib/module/engine/FPEngine.js +24 -13
  7. package/lib/module/engine/FPEngine.js.map +1 -1
  8. package/lib/module/engine/useIsForeground.js +17 -0
  9. package/lib/module/engine/useIsForeground.js.map +1 -0
  10. package/lib/module/ui/components/AnimatedDots.js +68 -0
  11. package/lib/module/ui/components/AnimatedDots.js.map +1 -0
  12. package/lib/module/ui/components/ConfirmScreen.js +333 -0
  13. package/lib/module/ui/components/ConfirmScreen.js.map +1 -0
  14. package/lib/module/ui/modals/FPPaymentRequestModal.js +6 -8
  15. package/lib/module/ui/modals/FPPaymentRequestModal.js.map +1 -1
  16. package/lib/module/ui/modals/FPShell.js +7 -4
  17. package/lib/module/ui/modals/FPShell.js.map +1 -1
  18. package/lib/module/ui/screens/ReceiveScreen.js +379 -274
  19. package/lib/module/ui/screens/ReceiveScreen.js.map +1 -1
  20. package/lib/module/ui/screens/SendScreen.js +154 -45
  21. package/lib/module/ui/screens/SendScreen.js.map +1 -1
  22. package/lib/module/ui/screens/styles.js +89 -0
  23. package/lib/module/ui/screens/styles.js.map +1 -0
  24. package/lib/module/ui/screens/sub/receivePayment/Nfc/index.js +361 -0
  25. package/lib/module/ui/screens/sub/receivePayment/Nfc/index.js.map +1 -0
  26. package/lib/module/ui/screens/sub/receivePayment/Qr/index.js +338 -0
  27. package/lib/module/ui/screens/sub/receivePayment/Qr/index.js.map +1 -0
  28. package/lib/module/ui/screens/sub/receivePayment/Transfer/index.js +453 -0
  29. package/lib/module/ui/screens/sub/receivePayment/Transfer/index.js.map +1 -0
  30. package/lib/module/ui/screens/sub/{BluetoothSubScreen.js → sendPayment/BluetoothSubScreen.js} +25 -32
  31. package/lib/module/ui/screens/sub/sendPayment/BluetoothSubScreen.js.map +1 -0
  32. package/lib/module/ui/screens/sub/sendPayment/NFCSubScreen.js +354 -0
  33. package/lib/module/ui/screens/sub/sendPayment/NFCSubScreen.js.map +1 -0
  34. package/lib/module/ui/screens/sub/sendPayment/NQRSubScreen.js +440 -0
  35. package/lib/module/ui/screens/sub/sendPayment/NQRSubScreen.js.map +1 -0
  36. package/lib/module/ui/screens/sub/{ProximitySubScreen.js → sendPayment/ProximitySubScreen.js} +20 -111
  37. package/lib/module/ui/screens/sub/sendPayment/ProximitySubScreen.js.map +1 -0
  38. package/lib/module/ui/screens/sub/sendPayment/TransferSubScreen.js +327 -0
  39. package/lib/module/ui/screens/sub/sendPayment/TransferSubScreen.js.map +1 -0
  40. package/lib/typescript/src/FountainPayProvider.d.ts.map +1 -1
  41. package/lib/typescript/src/core/api/index.d.ts +20 -27
  42. package/lib/typescript/src/core/api/index.d.ts.map +1 -1
  43. package/lib/typescript/src/core/types/index.d.ts +56 -13
  44. package/lib/typescript/src/core/types/index.d.ts.map +1 -1
  45. package/lib/typescript/src/engine/BLEReceiverService.d.ts +2 -0
  46. package/lib/typescript/src/engine/BLEReceiverService.d.ts.map +1 -1
  47. package/lib/typescript/src/engine/FPEngine.d.ts +3 -1
  48. package/lib/typescript/src/engine/FPEngine.d.ts.map +1 -1
  49. package/lib/typescript/src/engine/useIsForeground.d.ts +2 -0
  50. package/lib/typescript/src/engine/useIsForeground.d.ts.map +1 -0
  51. package/lib/typescript/src/ui/components/AnimatedDots.d.ts +2 -0
  52. package/lib/typescript/src/ui/components/AnimatedDots.d.ts.map +1 -0
  53. package/lib/typescript/src/ui/components/ConfirmScreen.d.ts +10 -0
  54. package/lib/typescript/src/ui/components/ConfirmScreen.d.ts.map +1 -0
  55. package/lib/typescript/src/ui/components/OtpInput/Styles.d.ts +3 -3
  56. package/lib/typescript/src/ui/modals/FPPaymentRequestModal.d.ts.map +1 -1
  57. package/lib/typescript/src/ui/modals/FPShell.d.ts.map +1 -1
  58. package/lib/typescript/src/ui/screens/ReceiveScreen.d.ts +2 -9
  59. package/lib/typescript/src/ui/screens/ReceiveScreen.d.ts.map +1 -1
  60. package/lib/typescript/src/ui/screens/SendScreen.d.ts +4 -2
  61. package/lib/typescript/src/ui/screens/SendScreen.d.ts.map +1 -1
  62. package/lib/typescript/src/ui/screens/styles.d.ts +1390 -0
  63. package/lib/typescript/src/ui/screens/styles.d.ts.map +1 -0
  64. package/lib/typescript/src/ui/screens/sub/receivePayment/Nfc/index.d.ts +10 -0
  65. package/lib/typescript/src/ui/screens/sub/receivePayment/Nfc/index.d.ts.map +1 -0
  66. package/lib/typescript/src/ui/screens/sub/receivePayment/Qr/index.d.ts +10 -0
  67. package/lib/typescript/src/ui/screens/sub/receivePayment/Qr/index.d.ts.map +1 -0
  68. package/lib/typescript/src/ui/screens/sub/receivePayment/Transfer/index.d.ts +5 -0
  69. package/lib/typescript/src/ui/screens/sub/receivePayment/Transfer/index.d.ts.map +1 -0
  70. package/lib/typescript/src/ui/screens/sub/{BluetoothSubScreen.d.ts → sendPayment/BluetoothSubScreen.d.ts} +2 -11
  71. package/lib/typescript/src/ui/screens/sub/sendPayment/BluetoothSubScreen.d.ts.map +1 -0
  72. package/lib/typescript/src/ui/screens/sub/sendPayment/NFCSubScreen.d.ts +3 -0
  73. package/lib/typescript/src/ui/screens/sub/sendPayment/NFCSubScreen.d.ts.map +1 -0
  74. package/lib/typescript/src/ui/screens/sub/sendPayment/NQRSubScreen.d.ts +3 -0
  75. package/lib/typescript/src/ui/screens/sub/sendPayment/NQRSubScreen.d.ts.map +1 -0
  76. package/lib/typescript/src/ui/screens/sub/{ProximitySubScreen.d.ts → sendPayment/ProximitySubScreen.d.ts} +2 -10
  77. package/lib/typescript/src/ui/screens/sub/sendPayment/ProximitySubScreen.d.ts.map +1 -0
  78. package/lib/typescript/src/ui/screens/sub/sendPayment/TransferSubScreen.d.ts +3 -0
  79. package/lib/typescript/src/ui/screens/sub/sendPayment/TransferSubScreen.d.ts.map +1 -0
  80. package/package.json +1 -1
  81. package/src/FountainPayProvider.tsx +7 -1
  82. package/src/core/api/index.ts +34 -19
  83. package/src/core/types/index.ts +67 -13
  84. package/src/engine/BLEReceiverService.ts +2 -0
  85. package/src/engine/FPEngine.ts +29 -14
  86. package/src/engine/useIsForeground.ts +18 -0
  87. package/src/ui/components/AnimatedDots.tsx +81 -0
  88. package/src/ui/components/ConfirmScreen.tsx +421 -0
  89. package/src/ui/modals/FPPaymentRequestModal.tsx +7 -6
  90. package/src/ui/modals/FPShell.tsx +9 -9
  91. package/src/ui/screens/ReceiveScreen.tsx +266 -115
  92. package/src/ui/screens/SendScreen.tsx +141 -19
  93. package/src/ui/screens/styles.ts +101 -0
  94. package/src/ui/screens/sub/receivePayment/Nfc/index.tsx +418 -0
  95. package/src/ui/screens/sub/receivePayment/Qr/index.tsx +391 -0
  96. package/src/ui/screens/sub/receivePayment/Transfer/index.tsx +512 -0
  97. package/src/ui/screens/sub/{BluetoothSubScreen.tsx → sendPayment/BluetoothSubScreen.tsx} +27 -46
  98. package/src/ui/screens/sub/sendPayment/NFCSubScreen.tsx +302 -0
  99. package/src/ui/screens/sub/sendPayment/NQRSubScreen.tsx +490 -0
  100. package/src/ui/screens/sub/{ProximitySubScreen.tsx → sendPayment/ProximitySubScreen.tsx} +24 -44
  101. package/src/ui/screens/sub/sendPayment/TransferSubScreen.tsx +345 -0
  102. package/lib/module/ui/screens/sub/BluetoothSubScreen.js.map +0 -1
  103. package/lib/module/ui/screens/sub/NFCSubScreen.js +0 -164
  104. package/lib/module/ui/screens/sub/NFCSubScreen.js.map +0 -1
  105. package/lib/module/ui/screens/sub/NQRSubScreen.js +0 -131
  106. package/lib/module/ui/screens/sub/NQRSubScreen.js.map +0 -1
  107. package/lib/module/ui/screens/sub/ProximitySubScreen.js.map +0 -1
  108. package/lib/module/ui/screens/sub/TransferSubScreen.js +0 -353
  109. package/lib/module/ui/screens/sub/TransferSubScreen.js.map +0 -1
  110. package/lib/typescript/src/ui/screens/sub/BluetoothSubScreen.d.ts.map +0 -1
  111. package/lib/typescript/src/ui/screens/sub/NFCSubScreen.d.ts +0 -18
  112. package/lib/typescript/src/ui/screens/sub/NFCSubScreen.d.ts.map +0 -1
  113. package/lib/typescript/src/ui/screens/sub/NQRSubScreen.d.ts +0 -12
  114. package/lib/typescript/src/ui/screens/sub/NQRSubScreen.d.ts.map +0 -1
  115. package/lib/typescript/src/ui/screens/sub/ProximitySubScreen.d.ts.map +0 -1
  116. package/lib/typescript/src/ui/screens/sub/TransferSubScreen.d.ts +0 -11
  117. package/lib/typescript/src/ui/screens/sub/TransferSubScreen.d.ts.map +0 -1
  118. package/src/ui/screens/sub/NFCSubScreen.tsx +0 -86
  119. package/src/ui/screens/sub/NQRSubScreen.tsx +0 -62
  120. package/src/ui/screens/sub/TransferSubScreen.tsx +0 -147
@@ -0,0 +1,302 @@
1
+ import React, { useEffect, useRef, useState } from 'react';
2
+ import { View, Text, StyleSheet, TouchableOpacity, Animated, Alert } from 'react-native';
3
+ import NfcManager, { NfcTech, Ndef } from 'react-native-nfc-manager';
4
+ import { transferAPI } from '../../../../core/api';
5
+ import { FPButton } from '../../../components/FPButton';
6
+ import { C, R, S, F } from '../../../theme';
7
+ import type { FPCurrency, FPError, FPTransaction, Props } from '../../../../core/types';
8
+ import styled from 'styled-components/native';
9
+ import Svg, { Path } from 'react-native-svg';
10
+ import Ionicons from 'react-native-vector-icons/Ionicons';
11
+ import { PulseAnimation } from '../../../components/PulseAnimation';
12
+
13
+ // Styled Components
14
+ const Container = styled(View)`
15
+ flex: 1;
16
+ background-color: #000000;
17
+ `;
18
+
19
+ const Header = styled(View)`
20
+ flex-direction: row;
21
+ align-items: center;
22
+ justify-content: space-between;
23
+ padding: 12px 16px;
24
+ position: absolute !important;
25
+ top: 40px;
26
+ left: 0;
27
+ right: 0;
28
+ z-index: 10;
29
+ elevation: 4;
30
+ shadow-color: #000;
31
+ shadow-offset: 0px 2px;
32
+ shadow-opacity: 0.1;
33
+ shadow-radius: 4px;
34
+ z-index: 9999999999 !important;
35
+ `;
36
+
37
+ const HeaderButton = styled(TouchableOpacity)`
38
+ padding: 8px;
39
+ background-color: #fff;
40
+ width: 40px;
41
+ height: 40px;
42
+ border-radius: 50%;
43
+ justify-content: center;
44
+ align-items: center;
45
+ `;
46
+
47
+ const HeaderCenter = styled(View)`
48
+ flex-direction: row;
49
+ align-items: center;
50
+ gap: 8px;
51
+ `;
52
+
53
+ const HeaderRight = styled(View)`
54
+ flex-direction: row;
55
+ align-items: center;
56
+ gap: 8px;
57
+ `;
58
+
59
+ const QuickLinksContainer = styled.View`
60
+ align-items: center;
61
+ margin-top: 250px;
62
+ `;
63
+
64
+ const QuickLinksIcon = styled.TouchableOpacity<{ bg?: string }>`
65
+ width: 96px;
66
+ height: 96px;
67
+ border-radius: 100%;
68
+ background-color: ${props => props.bg || '#18181b'};
69
+ justify-content: center;
70
+ align-items: center;
71
+ margin-bottom: 16px;
72
+ `;
73
+
74
+ const QuickLinksText = styled.Text`
75
+ color: #9ca3af;
76
+ font-size: 18px;
77
+ `;
78
+
79
+ const LCAnimationContainer = styled.View`
80
+ align-items: center;
81
+ justify-content: center;
82
+ margin-top: 40%;
83
+ `;
84
+
85
+ const LCIconContainer = styled(Animated.View)`
86
+ width: 140px;
87
+ height: 140px;
88
+ border-radius: 90px;
89
+ background-color: #E8F5F1;
90
+ align-items: center;
91
+ justify-content: center;
92
+ margin-top: 24px;
93
+ margin-bottom: 24px;
94
+ `;
95
+
96
+ const LCIcon = styled.Text`
97
+ font-size: 80px;
98
+ `;
99
+
100
+ const StatusTextContainer = styled.View`
101
+ align-items: center;
102
+ margin-bottom: 8px;
103
+ `;
104
+
105
+ const StatusText = styled.Text`
106
+ font-size: 18px;
107
+ font-weight: 600;
108
+ color: #333333;
109
+ text-align: center;
110
+ margin-bottom: 8px;
111
+ `;
112
+
113
+ const NFCIcon =({ color = "#111", size = 22 })=>(
114
+ <Svg width={size} height={size} strokeWidth="0.9" viewBox="0 0 24 24" fill="none" color={color}>
115
+ <Path d="M12 19.51L12.01 19.4989" stroke="#fff" strokeWidth="0.9" strokeLinecap="round" strokeLinejoin="round" />
116
+ <Path d="M2 8C8 3.5 16 3.5 22 8" stroke="#fff" strokeWidth="0.9" strokeLinecap="round" strokeLinejoin="round" />
117
+ <Path d="M5 12C9 9 15 9 19 12" stroke="#fff" strokeWidth="0.9" strokeLinecap="round" strokeLinejoin="round" />
118
+ <Path d="M8.5 15.5C10.7504 14.1 13.2498 14.0996 15.5001 15.5" stroke="#fff" strokeWidth="0.9" strokeLinecap="round" strokeLinejoin="round" />
119
+ </Svg>
120
+ )
121
+
122
+
123
+ interface PropT {
124
+ mode: 'send' | 'receive';
125
+ amount?: number; currency?: FPCurrency;
126
+ myWallet?: { accountName: string;
127
+ accountNumber: string;
128
+ bankCode: string;
129
+ bankName: string
130
+ };
131
+ onDone: () => void;
132
+ onSuccess?: (tx: FPTransaction) => void; onError?: (err: FPError) => void;
133
+ }
134
+
135
+ type Phase = 'idle' | 'active' | 'success' | 'error';
136
+
137
+ export function NFCSubScreen({
138
+ amount,
139
+ currency,
140
+ onClose,
141
+ onProcessTransaction,
142
+ onError
143
+ }: Props) {
144
+ const [phase, setPhase] = useState<Phase>('idle');
145
+ const [msg, setMsg] = useState('');
146
+ const iconScale = useRef(new Animated.Value(1)).current;
147
+
148
+ // const tapToReceive = async () => {
149
+ // if (!myWallet) return;
150
+ // setPhase('active');
151
+ // try {
152
+ // await NfcManager.start();
153
+ // await NfcManager.requestTechnology(NfcTech.Ndef);
154
+ // const bytes = Ndef.encodeMessage([Ndef.textRecord(JSON.stringify(myWallet))]);
155
+ // if (bytes) await NfcManager.ndefHandler.writeNdefMessage(bytes);
156
+ // setPhase('success'); setMsg('Your payment details are now on the NFC tag.');
157
+ // } catch (e: any) { setPhase('error'); setMsg(e.message); onError?.({ code: 'NFC_ERROR', message: e.message }); }
158
+ // finally { NfcManager.cancelTechnologyRequest(); }
159
+ // };
160
+
161
+ const sendMoney = async (wallet: any) => {
162
+
163
+ console.log('NFC details:', wallet);
164
+ onProcessTransaction?.(wallet as any);
165
+ }
166
+
167
+
168
+ const tapToSend = async () => {
169
+ setPhase('active');
170
+ try {
171
+ await NfcManager.start();
172
+ await NfcManager.requestTechnology(NfcTech.Ndef);
173
+ const tag = await NfcManager.getTag();
174
+ if (!tag?.ndefMessage?.[0]?.payload) throw new Error('No wallet data on tag');
175
+ const payload = new Uint8Array(tag.ndefMessage[0].payload);
176
+ const text = Ndef.text.decodePayload(payload);
177
+ const wallet = JSON.parse(text);
178
+ setPhase('success'); setMsg('NFC scanned!');
179
+ Alert.alert(
180
+ 'NFC Scanned',
181
+ `Would you love to continue with this transaction?`,
182
+ [
183
+ {
184
+ text: 'Cancel',
185
+ style: 'cancel',
186
+ },
187
+ {
188
+ text: `Continue`,
189
+ onPress: () => sendMoney(wallet),
190
+ },
191
+ ]
192
+ );
193
+
194
+ } catch (e: any) {
195
+ setPhase('error');
196
+ setMsg(e.message);
197
+ onError?.({ code: 'NFC_ERROR', message: e.message });
198
+ }
199
+ finally { NfcManager.cancelTechnologyRequest(); }
200
+ };
201
+
202
+ useEffect(() => {
203
+ NfcManager.start()
204
+ .then(() => console.log('NFC Manager started'))
205
+ .catch((err: any) => {
206
+ console.log('NFC start error:', err);
207
+ setPhase('error');
208
+ setMsg(err.message);
209
+ onError?.({ code: 'NFC_ERROR', message: err.message });
210
+ });
211
+
212
+ return () => {
213
+ NfcManager.cancelTechnologyRequest().catch(() => {});
214
+ };
215
+ }, []);
216
+
217
+ return (
218
+
219
+
220
+ <Container>
221
+
222
+ {/* Header */}
223
+ <Header>
224
+ <HeaderButton onPress={onClose}>
225
+ <Ionicons name="close" size={24} />
226
+ </HeaderButton>
227
+
228
+ <HeaderCenter>
229
+ <Text style={{ fontWeight: 'bold', fontSize: 16, color:'#FFF' }}>NFC</Text>
230
+ <Text style={{ fontSize: 10, color: '#FFF' }}>Transfer</Text>
231
+ </HeaderCenter>
232
+
233
+ <HeaderRight>
234
+ <HeaderButton>
235
+ <Ionicons name="image-outline" size={22} />
236
+ </HeaderButton>
237
+ <HeaderButton>
238
+ <Ionicons name="settings-outline" size={22} />
239
+ </HeaderButton>
240
+ </HeaderRight>
241
+ </Header>
242
+
243
+ <QuickLinksContainer>
244
+ {phase === 'idle' ? (
245
+ <>
246
+ <QuickLinksIcon onPress={()=>{tapToSend()}}>
247
+ <NFCIcon size={40} color="#FFF" />
248
+ </QuickLinksIcon>
249
+ <QuickLinksText>Start NFC Scan</QuickLinksText>
250
+ </>
251
+ )
252
+ : phase === 'active' ? (
253
+ <LCAnimationContainer>
254
+ <PulseAnimation />
255
+ <LCIconContainer style={{ transform: [{ scale: iconScale }], marginTop: 64 }}>
256
+ <LCIcon>📡</LCIcon>
257
+ </LCIconContainer>
258
+
259
+ <StatusTextContainer>
260
+ <StatusText>
261
+ Searching for nearby users
262
+ </StatusText>
263
+ {/* <StatusSubText>Hold devices back-to-back</StatusSubText> */}
264
+ </StatusTextContainer>
265
+ </LCAnimationContainer>
266
+ )
267
+ : phase === 'success' ? (
268
+ <>
269
+ <QuickLinksIcon bg="#057e32" onPress={()=>{tapToSend()}}>
270
+ <Ionicons name="checkmark" size={40} color="#FFF" />
271
+ </QuickLinksIcon>
272
+ <QuickLinksText>NFC Scanned</QuickLinksText>
273
+ </>
274
+ )
275
+ : (
276
+ <>
277
+ <View style={[st.tapZone, st.tapError]}>
278
+ <Text style={st.tapEmoji}>{'ERR'}</Text>
279
+ <Text style={st.tapLabel}>
280
+ {msg}
281
+ </Text>
282
+ </View>
283
+ <FPButton label="Try Again" onPress={() => setPhase('idle')} style={{ marginTop: S.md }} />
284
+ </>
285
+ )}
286
+
287
+ </QuickLinksContainer>
288
+ </Container>
289
+ );
290
+ }
291
+
292
+ const st = StyleSheet.create({
293
+ wrap: { flex: 1, padding: S.lg },
294
+ back: { color: C.brand, fontSize: F.md, fontWeight: '600', marginBottom: S.md },
295
+ title: { fontSize: F.xl, fontWeight: '800', color: C.ink, marginBottom: S.lg },
296
+ tapZone: { height: 180, backgroundColor: C.ink, borderRadius: R.xl, justifyContent: 'center', alignItems: 'center' },
297
+ tapActive: { backgroundColor: C.brand },
298
+ tapSuccess: { backgroundColor: C.green },
299
+ tapError: { backgroundColor: C.red },
300
+ tapEmoji: { fontSize: 40, color: C.white, fontWeight: '800', marginBottom: S.sm },
301
+ tapLabel: { color: C.white, fontSize: F.lg, fontWeight: '700' },
302
+ });