react-native-fpay 0.3.4 → 0.3.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 (155) hide show
  1. package/lib/module/FountainPayProvider.js +106 -16
  2. package/lib/module/FountainPayProvider.js.map +1 -1
  3. package/lib/module/core/api/client.js +13 -1
  4. package/lib/module/core/api/client.js.map +1 -1
  5. package/lib/module/core/api/index.js +66 -24
  6. package/lib/module/core/api/index.js.map +1 -1
  7. package/lib/module/engine/BLEReceiverService.js.map +1 -1
  8. package/lib/module/engine/BLESenderService.js.map +1 -1
  9. package/lib/module/engine/FPEngine.js +164 -43
  10. package/lib/module/engine/FPEngine.js.map +1 -1
  11. package/lib/module/engine/NearbyUsersService.js +1 -1
  12. package/lib/module/engine/NearbyUsersService.js.map +1 -1
  13. package/lib/module/index.js +1 -0
  14. package/lib/module/index.js.map +1 -1
  15. package/lib/module/store/FPStore.js +155 -0
  16. package/lib/module/store/FPStore.js.map +1 -0
  17. package/lib/module/ui/components/AnimatedDots.js +3 -3
  18. package/lib/module/ui/components/AnimatedDots.js.map +1 -1
  19. package/lib/module/ui/components/ConfirmScreen.js +137 -123
  20. package/lib/module/ui/components/ConfirmScreen.js.map +1 -1
  21. package/lib/module/ui/components/FPButton.js.map +1 -1
  22. package/lib/module/ui/components/LoadingAnimation/InLoading.js +3 -3
  23. package/lib/module/ui/components/LoadingAnimation/InLoading.js.map +1 -1
  24. package/lib/module/ui/components/LoadingAnimation/index.js +3 -3
  25. package/lib/module/ui/components/LoadingAnimation/index.js.map +1 -1
  26. package/lib/module/ui/components/OtpInput/OTPInputView.js +11 -11
  27. package/lib/module/ui/components/OtpInput/OTPInputView.js.map +1 -1
  28. package/lib/module/ui/components/OtpInput/Styles.js +1 -1
  29. package/lib/module/ui/components/OtpInput/helpers/codeToArray.js +1 -1
  30. package/lib/module/ui/components/OtpInput/helpers/device.js.map +1 -1
  31. package/lib/module/ui/components/OtpInput/helpers/styles.js.map +1 -1
  32. package/lib/module/ui/components/OtpInput/index.js +3 -1
  33. package/lib/module/ui/components/OtpInput/index.js.map +1 -1
  34. package/lib/module/ui/components/PulseAnimation.js +2 -2
  35. package/lib/module/ui/components/PulseAnimation.js.map +1 -1
  36. package/lib/module/ui/modals/FPPaymentRequestModal.js +8 -7
  37. package/lib/module/ui/modals/FPPaymentRequestModal.js.map +1 -1
  38. package/lib/module/ui/modals/FPShell.js +2 -0
  39. package/lib/module/ui/modals/FPShell.js.map +1 -1
  40. package/lib/module/ui/screens/ReceiveScreen.js +8 -9
  41. package/lib/module/ui/screens/ReceiveScreen.js.map +1 -1
  42. package/lib/module/ui/screens/SendScreen.js +43 -94
  43. package/lib/module/ui/screens/SendScreen.js.map +1 -1
  44. package/lib/module/ui/screens/styles.js +15 -3
  45. package/lib/module/ui/screens/styles.js.map +1 -1
  46. package/lib/module/ui/screens/sub/receivePayment/Nfc/index.js +4 -4
  47. package/lib/module/ui/screens/sub/receivePayment/Nfc/index.js.map +1 -1
  48. package/lib/module/ui/screens/sub/receivePayment/Qr/index.js +5 -5
  49. package/lib/module/ui/screens/sub/receivePayment/Qr/index.js.map +1 -1
  50. package/lib/module/ui/screens/sub/receivePayment/Transfer/index.js +10 -11
  51. package/lib/module/ui/screens/sub/receivePayment/Transfer/index.js.map +1 -1
  52. package/lib/module/ui/screens/sub/sendPayment/BluetoothSubScreen.js +31 -8
  53. package/lib/module/ui/screens/sub/sendPayment/BluetoothSubScreen.js.map +1 -1
  54. package/lib/module/ui/screens/sub/sendPayment/NFCSubScreen.js +12 -8
  55. package/lib/module/ui/screens/sub/sendPayment/NFCSubScreen.js.map +1 -1
  56. package/lib/module/ui/screens/sub/sendPayment/NQRSubScreen.js +17 -5
  57. package/lib/module/ui/screens/sub/sendPayment/NQRSubScreen.js.map +1 -1
  58. package/lib/module/ui/screens/sub/sendPayment/ProximitySubScreen.js +67 -35
  59. package/lib/module/ui/screens/sub/sendPayment/ProximitySubScreen.js.map +1 -1
  60. package/lib/module/ui/screens/sub/sendPayment/TransferSubScreen.js +110 -34
  61. package/lib/module/ui/screens/sub/sendPayment/TransferSubScreen.js.map +1 -1
  62. package/lib/module/ui/theme/index.js.map +1 -1
  63. package/lib/typescript/src/FountainPayProvider.d.ts +1 -1
  64. package/lib/typescript/src/FountainPayProvider.d.ts.map +1 -1
  65. package/lib/typescript/src/core/api/client.d.ts.map +1 -1
  66. package/lib/typescript/src/core/api/index.d.ts +42 -26
  67. package/lib/typescript/src/core/api/index.d.ts.map +1 -1
  68. package/lib/typescript/src/core/types/index.d.ts +53 -28
  69. package/lib/typescript/src/core/types/index.d.ts.map +1 -1
  70. package/lib/typescript/src/engine/BLEReceiverService.d.ts +2 -0
  71. package/lib/typescript/src/engine/BLEReceiverService.d.ts.map +1 -1
  72. package/lib/typescript/src/engine/BLESenderService.d.ts.map +1 -1
  73. package/lib/typescript/src/engine/FPEngine.d.ts +5 -3
  74. package/lib/typescript/src/engine/FPEngine.d.ts.map +1 -1
  75. package/lib/typescript/src/engine/useIsForeground.d.ts.map +1 -1
  76. package/lib/typescript/src/index.d.ts +2 -1
  77. package/lib/typescript/src/index.d.ts.map +1 -1
  78. package/lib/typescript/src/store/FPStore.d.ts +60 -0
  79. package/lib/typescript/src/store/FPStore.d.ts.map +1 -0
  80. package/lib/typescript/src/ui/components/AnimatedDots.d.ts.map +1 -1
  81. package/lib/typescript/src/ui/components/ConfirmScreen.d.ts +5 -5
  82. package/lib/typescript/src/ui/components/ConfirmScreen.d.ts.map +1 -1
  83. package/lib/typescript/src/ui/components/FPButton.d.ts +1 -1
  84. package/lib/typescript/src/ui/components/FPButton.d.ts.map +1 -1
  85. package/lib/typescript/src/ui/components/LoadingAnimation/InLoading.d.ts.map +1 -1
  86. package/lib/typescript/src/ui/components/LoadingAnimation/index.d.ts.map +1 -1
  87. package/lib/typescript/src/ui/components/OtpInput/OTPInputView.d.ts.map +1 -1
  88. package/lib/typescript/src/ui/components/OtpInput/helpers/codeToArray.d.ts.map +1 -1
  89. package/lib/typescript/src/ui/components/OtpInput/helpers/device.d.ts.map +1 -1
  90. package/lib/typescript/src/ui/components/OtpInput/helpers/styles.d.ts.map +1 -1
  91. package/lib/typescript/src/ui/components/OtpInput/helpers/types.d.ts +1 -2
  92. package/lib/typescript/src/ui/components/OtpInput/helpers/types.d.ts.map +1 -1
  93. package/lib/typescript/src/ui/components/OtpInput/index.d.ts +3 -1
  94. package/lib/typescript/src/ui/components/OtpInput/index.d.ts.map +1 -1
  95. package/lib/typescript/src/ui/components/PulseAnimation.d.ts.map +1 -1
  96. package/lib/typescript/src/ui/modals/FPPaymentRequestModal.d.ts.map +1 -1
  97. package/lib/typescript/src/ui/modals/FPShell.d.ts.map +1 -1
  98. package/lib/typescript/src/ui/screens/ReceiveScreen.d.ts +1 -1
  99. package/lib/typescript/src/ui/screens/ReceiveScreen.d.ts.map +1 -1
  100. package/lib/typescript/src/ui/screens/SendScreen.d.ts +1 -1
  101. package/lib/typescript/src/ui/screens/SendScreen.d.ts.map +1 -1
  102. package/lib/typescript/src/ui/screens/styles.d.ts +197 -0
  103. package/lib/typescript/src/ui/screens/styles.d.ts.map +1 -1
  104. package/lib/typescript/src/ui/screens/sub/receivePayment/Nfc/index.d.ts.map +1 -1
  105. package/lib/typescript/src/ui/screens/sub/receivePayment/Qr/index.d.ts.map +1 -1
  106. package/lib/typescript/src/ui/screens/sub/receivePayment/Transfer/index.d.ts.map +1 -1
  107. package/lib/typescript/src/ui/screens/sub/sendPayment/BluetoothSubScreen.d.ts.map +1 -1
  108. package/lib/typescript/src/ui/screens/sub/sendPayment/NFCSubScreen.d.ts +1 -1
  109. package/lib/typescript/src/ui/screens/sub/sendPayment/NFCSubScreen.d.ts.map +1 -1
  110. package/lib/typescript/src/ui/screens/sub/sendPayment/NQRSubScreen.d.ts +1 -1
  111. package/lib/typescript/src/ui/screens/sub/sendPayment/NQRSubScreen.d.ts.map +1 -1
  112. package/lib/typescript/src/ui/screens/sub/sendPayment/ProximitySubScreen.d.ts +1 -1
  113. package/lib/typescript/src/ui/screens/sub/sendPayment/ProximitySubScreen.d.ts.map +1 -1
  114. package/lib/typescript/src/ui/screens/sub/sendPayment/TransferSubScreen.d.ts +1 -1
  115. package/lib/typescript/src/ui/screens/sub/sendPayment/TransferSubScreen.d.ts.map +1 -1
  116. package/lib/typescript/src/ui/theme/index.d.ts.map +1 -1
  117. package/package.json +4 -5
  118. package/src/FountainPayProvider.tsx +164 -23
  119. package/src/core/api/client.ts +26 -4
  120. package/src/core/api/index.ts +170 -49
  121. package/src/core/types/index.ts +81 -48
  122. package/src/engine/BLEReceiverService.ts +86 -28
  123. package/src/engine/BLESenderService.ts +133 -69
  124. package/src/engine/FPEngine.ts +316 -97
  125. package/src/engine/NearbyUsersService.ts +6 -6
  126. package/src/engine/useIsForeground.ts +12 -12
  127. package/src/index.ts +10 -4
  128. package/src/store/FPStore.ts +216 -0
  129. package/src/ui/components/AnimatedDots.tsx +4 -5
  130. package/src/ui/components/ConfirmScreen.tsx +182 -169
  131. package/src/ui/components/FPButton.tsx +50 -9
  132. package/src/ui/components/LoadingAnimation/InLoading.tsx +23 -27
  133. package/src/ui/components/LoadingAnimation/index.tsx +3 -7
  134. package/src/ui/components/OtpInput/OTPInputView.tsx +254 -205
  135. package/src/ui/components/OtpInput/Styles.ts +1 -1
  136. package/src/ui/components/OtpInput/helpers/codeToArray.ts +2 -2
  137. package/src/ui/components/OtpInput/helpers/device.ts +4 -3
  138. package/src/ui/components/OtpInput/helpers/styles.ts +13 -14
  139. package/src/ui/components/OtpInput/helpers/types.ts +83 -79
  140. package/src/ui/components/OtpInput/index.tsx +18 -15
  141. package/src/ui/components/PulseAnimation.tsx +3 -5
  142. package/src/ui/modals/FPPaymentRequestModal.tsx +111 -28
  143. package/src/ui/modals/FPShell.tsx +60 -34
  144. package/src/ui/screens/ReceiveScreen.tsx +245 -84
  145. package/src/ui/screens/SendScreen.tsx +419 -167
  146. package/src/ui/screens/styles.ts +17 -5
  147. package/src/ui/screens/sub/receivePayment/Nfc/index.tsx +17 -25
  148. package/src/ui/screens/sub/receivePayment/Qr/index.tsx +21 -20
  149. package/src/ui/screens/sub/receivePayment/Transfer/index.tsx +34 -28
  150. package/src/ui/screens/sub/sendPayment/BluetoothSubScreen.tsx +135 -67
  151. package/src/ui/screens/sub/sendPayment/NFCSubScreen.tsx +188 -112
  152. package/src/ui/screens/sub/sendPayment/NQRSubScreen.tsx +102 -69
  153. package/src/ui/screens/sub/sendPayment/ProximitySubScreen.tsx +225 -99
  154. package/src/ui/screens/sub/sendPayment/TransferSubScreen.tsx +209 -89
  155. package/src/ui/theme/index.ts +14 -2
@@ -0,0 +1,216 @@
1
+ // ─────────────────────────────────────────────────────────────────────────────
2
+ // FPStore — SDK-internal Zustand store with persistence
3
+ //
4
+ // Stores: access token, user info, wallet/account details, bank list cache.
5
+ // Persisted to AsyncStorage under the key '@fp_store' so it survives
6
+ // app restarts without hitting the backend again.
7
+ //
8
+ // Usage (inside SDK only — never exported to host app):
9
+ // import { useFPStore, getFPStore, setFPStore } from '../store/FPStore';
10
+ // const token = getFPStore().accessToken;
11
+ // setFPStore({ accessToken: 'abc123' });
12
+ // ─────────────────────────────────────────────────────────────────────────────
13
+
14
+ import { create } from 'zustand';
15
+ import { persist, createJSONStorage } from 'zustand/middleware';
16
+ import AsyncStorage from '@react-native-async-storage/async-storage';
17
+ import type {
18
+ FPUserInfo,
19
+ FPBankItem,
20
+ FPTransferRecipient,
21
+ FPAccount,
22
+ } from '../core/types';
23
+
24
+ // ── State shape ───────────────────────────────────────────────────────────────
25
+
26
+ export interface FPStoreState {
27
+ // Auth
28
+ accessToken: string | null;
29
+ tokenExpiresAt: number | null; // unix ms — null means no expiry info
30
+
31
+ // User set via initializeSDK()
32
+ user: FPUserInfo | null;
33
+
34
+ // Account details set via setAccountDetails()
35
+ accountDetails: FPTransferRecipient | null;
36
+ balance: number | null;
37
+ balanceFetchedAt: number | null;
38
+
39
+ // Bank list (rarely changes — cache aggressively)
40
+ banks: FPBankItem[];
41
+ banksFetchedAt: number | null;
42
+
43
+ // Whether the API key has been verified this session
44
+ isAuthenticated: boolean;
45
+ authError: string | null;
46
+
47
+ psspId: string | null; // PSSP-assigned ID from generate-virtual-account
48
+ account: FPAccount | null;
49
+
50
+ lastBroadcastPosition: { latitude: number; longitude: number } | null;
51
+ }
52
+
53
+ // ── Actions shape ─────────────────────────────────────────────────────────────
54
+
55
+ export interface FPStoreActions {
56
+ setAccessToken: (token: string, expiresInSeconds?: number) => void;
57
+ clearAccessToken: () => void;
58
+
59
+ setUser: (user: FPUserInfo) => void;
60
+ clearUser: () => void;
61
+
62
+ setAccountDetails: (account: FPTransferRecipient) => void;
63
+ setBalance: (balance: number) => void;
64
+ clearBalance: () => void;
65
+
66
+ setBanks: (banks: FPBankItem[]) => void;
67
+
68
+ setAuthenticated: (value: boolean, error?: string | null) => void;
69
+ setPsspId: (id: string) => void;
70
+ setAccount: (account: FPAccount) => void;
71
+ setLastBroadcastPosition: (pos: {
72
+ latitude: number;
73
+ longitude: number;
74
+ }) => void;
75
+ clearAccount: () => void;
76
+
77
+ // Full reset — call on logout
78
+ reset: () => void;
79
+ }
80
+
81
+ export type FPStore = FPStoreState & FPStoreActions;
82
+
83
+ // ── Initial state ─────────────────────────────────────────────────────────────
84
+
85
+ const initialState: FPStoreState = {
86
+ accessToken: null,
87
+ tokenExpiresAt: null,
88
+ user: null,
89
+ accountDetails: null,
90
+ banks: [],
91
+ balance: null,
92
+ balanceFetchedAt: null,
93
+ banksFetchedAt: null,
94
+ isAuthenticated: false,
95
+ authError: null,
96
+ psspId: null,
97
+ account: null,
98
+ lastBroadcastPosition: null,
99
+ };
100
+
101
+ // ── Store ─────────────────────────────────────────────────────────────────────
102
+
103
+ export const useFPStore = create<FPStore>()(
104
+ persist(
105
+ (set, get) => ({
106
+ ...initialState,
107
+
108
+ setAccessToken: (token, expiresInSeconds) =>
109
+ set({
110
+ accessToken: token,
111
+ tokenExpiresAt: expiresInSeconds
112
+ ? Date.now() + expiresInSeconds * 1000
113
+ : null,
114
+ }),
115
+
116
+ clearAccessToken: () =>
117
+ set({
118
+ accessToken: null,
119
+ tokenExpiresAt: null,
120
+ }),
121
+
122
+ setUser: (user) => set({ user }),
123
+
124
+ clearUser: () => set({ user: null }),
125
+
126
+ setAccountDetails: (accountDetails) => set({ accountDetails }),
127
+ setBalance: (balance) => set({ balance, balanceFetchedAt: Date.now() }),
128
+ clearBalance: () => set({ balance: null, balanceFetchedAt: null }),
129
+
130
+ setBanks: (banks) =>
131
+ set({
132
+ banks,
133
+ banksFetchedAt: Date.now(),
134
+ }),
135
+
136
+ setAuthenticated: (value, error = null) =>
137
+ set({
138
+ isAuthenticated: value,
139
+ authError: error,
140
+ }),
141
+
142
+ setPsspId: (id: string) => set({ psspId: id }),
143
+ setAccount: (account: FPAccount) => set({ account }),
144
+ clearAccount: () =>
145
+ set({
146
+ psspId: null,
147
+ account: null,
148
+ balance: null,
149
+ balanceFetchedAt: null,
150
+ }),
151
+
152
+ setLastBroadcastPosition: (pos: {
153
+ latitude: number;
154
+ longitude: number;
155
+ }) => set({ lastBroadcastPosition: pos }),
156
+
157
+ reset: () => set(initialState),
158
+ }),
159
+ {
160
+ name: '@fp_store', // AsyncStorage key
161
+ storage: createJSONStorage(() => AsyncStorage),
162
+
163
+ // Only persist data that should survive app restarts.
164
+ // Omit runtime-only flags that should reset each session.
165
+ partialize: (state) => ({
166
+ accessToken: state.accessToken,
167
+ tokenExpiresAt: state.tokenExpiresAt,
168
+ user: state.user,
169
+ accountDetails: state.accountDetails,
170
+ banks: state.banks,
171
+ banksFetchedAt: state.banksFetchedAt,
172
+ psspId: state.psspId,
173
+ account: state.account,
174
+ balance: state.balance,
175
+ balanceFetchedAt: state.balanceFetchedAt,
176
+ lastBroadcastPosition: state.lastBroadcastPosition,
177
+ // isAuthenticated and authError are NOT persisted —
178
+ // the API key must be verified fresh each session
179
+ }),
180
+ }
181
+ )
182
+ );
183
+
184
+ // ── Helpers for use outside React components (e.g. FPEngine) ─────────────────
185
+
186
+ /** Read current store state without subscribing */
187
+ export const getFPStore = () => useFPStore.getState();
188
+
189
+ /** Update store state without subscribing */
190
+ export const setFPStore = (partial: Partial<FPStoreState>) =>
191
+ useFPStore.setState(partial);
192
+
193
+ // ── Cache validity helpers ────────────────────────────────────────────────────
194
+
195
+ const WALLET_CACHE_TTL = 5 * 60 * 1000; // 5 minutes
196
+ const BANKS_CACHE_TTL = 24 * 60 * 60 * 1000; // 24 hours
197
+ const BALANCE_CACHE_TTL = 2 * 60 * 1000; // 2 minutes
198
+
199
+ export function isBanksCacheValid(): boolean {
200
+ const { banksFetchedAt } = getFPStore();
201
+ if (!banksFetchedAt) return false;
202
+ return Date.now() - banksFetchedAt < BANKS_CACHE_TTL;
203
+ }
204
+
205
+ export function isTokenValid(): boolean {
206
+ const { accessToken, tokenExpiresAt } = getFPStore();
207
+ if (!accessToken) return false;
208
+ if (!tokenExpiresAt) return true; // no expiry info — assume valid
209
+ return Date.now() < tokenExpiresAt - 60000; // 60s buffer before expiry
210
+ }
211
+
212
+ export function isBalanceCacheValid(): boolean {
213
+ const { balanceFetchedAt } = getFPStore();
214
+ if (!balanceFetchedAt) return false;
215
+ return Date.now() - balanceFetchedAt < BALANCE_CACHE_TTL;
216
+ }
@@ -1,6 +1,6 @@
1
- import { useEffect, useRef } from "react";
2
- import { Animated, Easing } from "react-native";
3
- import styled from "styled-components/native";
1
+ import { useEffect, useRef } from 'react';
2
+ import { Animated, Easing } from 'react-native';
3
+ import styled from 'styled-components/native';
4
4
 
5
5
  // Animated Dots Component
6
6
  const DotsContainer = styled.View`
@@ -23,7 +23,6 @@ export const AnimatedDots: React.FC = () => {
23
23
 
24
24
  const AnimatedDot = Animated.createAnimatedComponent(Dot);
25
25
 
26
-
27
26
  useEffect(() => {
28
27
  const animateDot = (dot: Animated.Value, delay: number) => {
29
28
  return Animated.loop(
@@ -78,4 +77,4 @@ export const AnimatedDots: React.FC = () => {
78
77
  <AnimatedDot style={dotStyle(dot3)} delay={400} />
79
78
  </DotsContainer>
80
79
  );
81
- };
80
+ };