react-native-fpay 0.4.29 → 0.4.31

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 (79) hide show
  1. package/lib/module/FountainPayProvider.js +5 -0
  2. package/lib/module/FountainPayProvider.js.map +1 -1
  3. package/lib/module/core/api/index.js +59 -0
  4. package/lib/module/core/api/index.js.map +1 -1
  5. package/lib/module/core/types/index.js +32 -0
  6. package/lib/module/core/types/index.js.map +1 -1
  7. package/lib/module/engine/FPEngine.js +9 -0
  8. package/lib/module/engine/FPEngine.js.map +1 -1
  9. package/lib/module/hooks/useLocation.js +66 -0
  10. package/lib/module/hooks/useLocation.js.map +1 -0
  11. package/lib/module/ui/components/ConfirmScreen.js +43 -51
  12. package/lib/module/ui/components/ConfirmScreen.js.map +1 -1
  13. package/lib/module/ui/components/RecurringToggle.js +94 -0
  14. package/lib/module/ui/components/RecurringToggle.js.map +1 -0
  15. package/lib/module/ui/modals/FPShell.js +19 -0
  16. package/lib/module/ui/modals/FPShell.js.map +1 -1
  17. package/lib/module/ui/screens/BillsScreen.js +186 -0
  18. package/lib/module/ui/screens/BillsScreen.js.map +1 -0
  19. package/lib/module/ui/screens/ResultScreen.js +113 -28
  20. package/lib/module/ui/screens/ResultScreen.js.map +1 -1
  21. package/lib/module/ui/screens/SendScreen.js +85 -16
  22. package/lib/module/ui/screens/SendScreen.js.map +1 -1
  23. package/lib/module/ui/screens/sub/billPayment/AirtimeScreen.js +257 -0
  24. package/lib/module/ui/screens/sub/billPayment/AirtimeScreen.js.map +1 -0
  25. package/lib/module/ui/screens/sub/billPayment/CableScreen.js +264 -0
  26. package/lib/module/ui/screens/sub/billPayment/CableScreen.js.map +1 -0
  27. package/lib/module/ui/screens/sub/billPayment/DataScreen.js +273 -0
  28. package/lib/module/ui/screens/sub/billPayment/DataScreen.js.map +1 -0
  29. package/lib/module/ui/screens/sub/billPayment/ElectricityScreen.js +337 -0
  30. package/lib/module/ui/screens/sub/billPayment/ElectricityScreen.js.map +1 -0
  31. package/lib/module/ui/screens/sub/sendPayment/TransferSubScreen.js +1 -1
  32. package/lib/module/ui/screens/sub/sendPayment/TransferSubScreen.js.map +1 -1
  33. package/lib/typescript/src/FountainPayProvider.d.ts.map +1 -1
  34. package/lib/typescript/src/core/api/index.d.ts +52 -63
  35. package/lib/typescript/src/core/api/index.d.ts.map +1 -1
  36. package/lib/typescript/src/core/types/index.d.ts +159 -6
  37. package/lib/typescript/src/core/types/index.d.ts.map +1 -1
  38. package/lib/typescript/src/engine/FPEngine.d.ts +4 -2
  39. package/lib/typescript/src/engine/FPEngine.d.ts.map +1 -1
  40. package/lib/typescript/src/hooks/useLocation.d.ts +12 -0
  41. package/lib/typescript/src/hooks/useLocation.d.ts.map +1 -0
  42. package/lib/typescript/src/index.d.ts +1 -1
  43. package/lib/typescript/src/index.d.ts.map +1 -1
  44. package/lib/typescript/src/ui/components/ConfirmScreen.d.ts +25 -4
  45. package/lib/typescript/src/ui/components/ConfirmScreen.d.ts.map +1 -1
  46. package/lib/typescript/src/ui/components/RecurringToggle.d.ts +7 -0
  47. package/lib/typescript/src/ui/components/RecurringToggle.d.ts.map +1 -0
  48. package/lib/typescript/src/ui/modals/FPShell.d.ts.map +1 -1
  49. package/lib/typescript/src/ui/screens/BillsScreen.d.ts +10 -0
  50. package/lib/typescript/src/ui/screens/BillsScreen.d.ts.map +1 -0
  51. package/lib/typescript/src/ui/screens/ResultScreen.d.ts +20 -3
  52. package/lib/typescript/src/ui/screens/ResultScreen.d.ts.map +1 -1
  53. package/lib/typescript/src/ui/screens/SendScreen.d.ts.map +1 -1
  54. package/lib/typescript/src/ui/screens/sub/billPayment/AirtimeScreen.d.ts +15 -0
  55. package/lib/typescript/src/ui/screens/sub/billPayment/AirtimeScreen.d.ts.map +1 -0
  56. package/lib/typescript/src/ui/screens/sub/billPayment/CableScreen.d.ts +14 -0
  57. package/lib/typescript/src/ui/screens/sub/billPayment/CableScreen.d.ts.map +1 -0
  58. package/lib/typescript/src/ui/screens/sub/billPayment/DataScreen.d.ts +14 -0
  59. package/lib/typescript/src/ui/screens/sub/billPayment/DataScreen.d.ts.map +1 -0
  60. package/lib/typescript/src/ui/screens/sub/billPayment/ElectricityScreen.d.ts +16 -0
  61. package/lib/typescript/src/ui/screens/sub/billPayment/ElectricityScreen.d.ts.map +1 -0
  62. package/package.json +2 -2
  63. package/src/FountainPayProvider.tsx +7 -0
  64. package/src/core/api/index.ts +149 -27
  65. package/src/core/types/index.ts +194 -11
  66. package/src/engine/FPEngine.ts +12 -1
  67. package/src/hooks/useLocation.ts +81 -0
  68. package/src/index.ts +9 -1
  69. package/src/ui/components/ConfirmScreen.tsx +47 -54
  70. package/src/ui/components/RecurringToggle.tsx +106 -0
  71. package/src/ui/modals/FPShell.tsx +26 -3
  72. package/src/ui/screens/BillsScreen.tsx +197 -0
  73. package/src/ui/screens/ResultScreen.tsx +129 -28
  74. package/src/ui/screens/SendScreen.tsx +124 -68
  75. package/src/ui/screens/sub/billPayment/AirtimeScreen.tsx +252 -0
  76. package/src/ui/screens/sub/billPayment/CableScreen.tsx +274 -0
  77. package/src/ui/screens/sub/billPayment/DataScreen.tsx +263 -0
  78. package/src/ui/screens/sub/billPayment/ElectricityScreen.tsx +344 -0
  79. package/src/ui/screens/sub/sendPayment/TransferSubScreen.tsx +1 -1
@@ -0,0 +1,263 @@
1
+ import { useEffect, useState } from 'react';
2
+ import { View, Text, TouchableOpacity, ScrollView, KeyboardAvoidingView, Platform, ActivityIndicator } from 'react-native';
3
+ import styled from 'styled-components/native';
4
+ import { C, F, R, S } from '../../../theme';
5
+ import { billsAPI } from '../../../../core/api';
6
+ import type { FPNetworkCode, FPNetworkOperator, FPDataPlan, FPDataPurchaseRequest } from '../../../../core/types';
7
+
8
+ const PREFIX_MAP: Record<string, FPNetworkCode> = {
9
+ '0803': 'MTN', '0806': 'MTN', '0703': 'MTN', '0706': 'MTN', '0813': 'MTN', '0816': 'MTN', '0810': 'MTN', '0814': 'MTN', '0903': 'MTN', '0906': 'MTN', '0913': 'MTN', '0916': 'MTN',
10
+ '0802': 'AIRTEL', '0808': 'AIRTEL', '0708': 'AIRTEL', '0812': 'AIRTEL', '0701': 'AIRTEL', '0902': 'AIRTEL', '0907': 'AIRTEL', '0901': 'AIRTEL', '0911': 'AIRTEL',
11
+ '0805': 'GLO', '0807': 'GLO', '0815': 'GLO', '0811': 'GLO', '0905': 'GLO', '0915': 'GLO',
12
+ '0809': '9MOBILE', '0817': '9MOBILE', '0818': '9MOBILE', '0908': '9MOBILE', '0909': '9MOBILE',
13
+ };
14
+
15
+ function detectNetwork(phone: string): FPNetworkCode | null {
16
+ return PREFIX_MAP[phone.slice(0, 4)] ?? null;
17
+ }
18
+
19
+ const Container = styled(View)`
20
+ flex: 1;
21
+ background-color: ${C.white};
22
+ `;
23
+
24
+ const Body = styled(ScrollView)`
25
+ flex: 1;
26
+ padding: ${S.lg}px;
27
+ `;
28
+
29
+ const FieldLabel = styled(Text)`
30
+ font-size: ${F.sm}px;
31
+ font-weight: 600;
32
+ color: ${C.muted};
33
+ margin-bottom: ${S.xs}px;
34
+ `;
35
+
36
+ const InputBox = styled.View`
37
+ background-color: ${C.surface};
38
+ border-radius: ${R.lg}px;
39
+ padding: 0 ${S.md}px;
40
+ height: 52px;
41
+ flex-direction: row;
42
+ align-items: center;
43
+ margin-bottom: ${S.md}px;
44
+ `;
45
+
46
+ const StyledInput = styled.TextInput`
47
+ flex: 1;
48
+ font-size: ${F.md}px;
49
+ color: ${C.ink};
50
+ `;
51
+
52
+ const NetworkRow = styled(View)`
53
+ flex-direction: row;
54
+ gap: ${S.sm}px;
55
+ margin-bottom: ${S.lg}px;
56
+ `;
57
+
58
+ const NetworkChip = styled(TouchableOpacity)<{ selected: boolean; brandColor?: string }>`
59
+ flex: 1;
60
+ height: 44px;
61
+ border-radius: ${R.full}px;
62
+ align-items: center;
63
+ justify-content: center;
64
+ background-color: ${(props: any) => (props.selected ? (props.brandColor ?? C.brand) : C.surface)};
65
+ `;
66
+
67
+ const NetworkChipText = styled(Text)<{ selected: boolean }>`
68
+ font-size: ${F.sm}px;
69
+ font-weight: 700;
70
+ color: ${(props: any) => (props.selected ? C.white : C.muted)};
71
+ `;
72
+
73
+ const PlanCard = styled(TouchableOpacity)<{ selected: boolean; disabled?: boolean }>`
74
+ border-radius: ${R.lg}px;
75
+ padding: ${S.md}px;
76
+ margin-bottom: ${S.sm}px;
77
+ background-color: ${(props: any) => (props.selected ? C.brandLight : C.surface)};
78
+ border-width: 1.5px;
79
+ border-color: ${(props: any) => (props.selected ? C.brand : 'transparent')};
80
+ opacity: ${(props: any) => (props.disabled ? 0.45 : 1)};
81
+ flex-direction: row;
82
+ justify-content: space-between;
83
+ align-items: center;
84
+ `;
85
+
86
+ const PlanLabel = styled(Text)`
87
+ font-size: ${F.md}px;
88
+ font-weight: 700;
89
+ color: ${C.ink};
90
+ `;
91
+
92
+ const PlanValidity = styled(Text)`
93
+ font-size: ${F.xs}px;
94
+ color: ${C.muted};
95
+ margin-top: 2px;
96
+ `;
97
+
98
+ const PlanPrice = styled(Text)`
99
+ font-size: ${F.md}px;
100
+ font-weight: 800;
101
+ color: ${C.brand};
102
+ `;
103
+
104
+ const EmptyText = styled(Text)`
105
+ text-align: center;
106
+ color: ${C.muted};
107
+ margin-top: ${S.lg}px;
108
+ `;
109
+
110
+ const ContinueButton = styled(TouchableOpacity)<{ disabled?: boolean }>`
111
+ background-color: ${(props: any) => (props.disabled ? C.ghost : C.brand)};
112
+ border-radius: ${R.full}px;
113
+ padding: ${S.md}px 0;
114
+ align-items: center;
115
+ margin-top: ${S.md}px;
116
+ `;
117
+
118
+ const ContinueButtonText = styled(Text)`
119
+ color: ${C.white};
120
+ font-weight: 800;
121
+ font-size: ${F.md}px;
122
+ `;
123
+
124
+ interface Props {
125
+ onProcessTransaction: (
126
+ payload: FPDataPurchaseRequest,
127
+ summaryRows: { label: string; value: string }[]
128
+ ) => void;
129
+ onError?: (err: { code: string; message: string }) => void;
130
+ }
131
+
132
+ export default function DataScreen({ onProcessTransaction, onError }: Props) {
133
+ const [networks, setNetworks] = useState<FPNetworkOperator[]>([]);
134
+ const [phone, setPhone] = useState('');
135
+ const [network, setNetwork] = useState<FPNetworkCode | null>(null);
136
+ const [networkTouched, setNetworkTouched] = useState(false);
137
+ const [plans, setPlans] = useState<FPDataPlan[]>([]);
138
+ const [plansLoading, setPlansLoading] = useState(false);
139
+ const [selectedPlan, setSelectedPlan] = useState<FPDataPlan | null>(null);
140
+
141
+ useEffect(() => {
142
+ billsAPI
143
+ .getNetworks()
144
+ .then((res: any) => {
145
+ if (res.status) setNetworks(res.payload.filter((n: FPNetworkOperator) => n.isActive));
146
+ })
147
+ .catch(() => {
148
+ onError?.({ code: 'NETWORK_LOAD_FAILED', message: 'Could not load network list' });
149
+ });
150
+ }, []);
151
+
152
+ useEffect(() => {
153
+ if (!networkTouched) {
154
+ const detected = detectNetwork(phone);
155
+ if (detected) setNetwork(detected);
156
+ }
157
+ }, [phone, networkTouched]);
158
+
159
+ useEffect(() => {
160
+ if (!network) {
161
+ setPlans([]);
162
+ setSelectedPlan(null);
163
+ return;
164
+ }
165
+ setPlansLoading(true);
166
+ setSelectedPlan(null);
167
+ billsAPI
168
+ .getDataPlans(network)
169
+ .then((res: any) => {
170
+ if (res.status) setPlans(res.payload);
171
+ })
172
+ .catch(() => {
173
+ onError?.({ code: 'PLANS_LOAD_FAILED', message: 'Could not load data plans' });
174
+ })
175
+ .finally(() => setPlansLoading(false));
176
+ }, [network]);
177
+
178
+ const isValid = /^0\d{10}$/.test(phone) && !!network && !!selectedPlan;
179
+
180
+ const handleContinue = () => {
181
+ if (!isValid || !network || !selectedPlan) return;
182
+ onProcessTransaction(
183
+ {
184
+ category: 'DATA',
185
+ phoneNumber: phone,
186
+ network,
187
+ planId: selectedPlan.id,
188
+ amountInKobo: selectedPlan.priceInKobo,
189
+ idempotencyKey: `data_${Date.now()}_${Math.random().toString(36).slice(2, 8)}`,
190
+ },
191
+ [
192
+ { label: 'Phone Number', value: phone },
193
+ { label: 'Network', value: network },
194
+ { label: 'Plan', value: `${selectedPlan.label} / ${selectedPlan.validity}` },
195
+ ]
196
+ );
197
+ };
198
+
199
+ return (
200
+ <Container>
201
+ <KeyboardAvoidingView style={{ flex: 1 }} behavior={Platform.OS === 'ios' ? 'padding' : undefined}>
202
+ <Body keyboardShouldPersistTaps="handled" showsVerticalScrollIndicator={false}>
203
+ <FieldLabel>Phone Number</FieldLabel>
204
+ <InputBox>
205
+ <StyledInput
206
+ placeholder="080XXXXXXXX"
207
+ placeholderTextColor={C.ghost}
208
+ keyboardType="number-pad"
209
+ maxLength={11}
210
+ value={phone}
211
+ onChangeText={setPhone}
212
+ />
213
+ </InputBox>
214
+
215
+ <FieldLabel>Network</FieldLabel>
216
+ <NetworkRow>
217
+ {(['MTN', 'AIRTEL', 'GLO', '9MOBILE'] as FPNetworkCode[]).map((code) => {
218
+ const op = networks.find((n: any) => n.code === code);
219
+ return (
220
+ <NetworkChip
221
+ key={code}
222
+ selected={network === code}
223
+ brandColor={op?.brandColor}
224
+ onPress={() => {
225
+ setNetworkTouched(true);
226
+ setNetwork(code);
227
+ }}
228
+ >
229
+ <NetworkChipText selected={network === code}>{code}</NetworkChipText>
230
+ </NetworkChip>
231
+ );
232
+ })}
233
+ </NetworkRow>
234
+
235
+ <FieldLabel>Select a Plan</FieldLabel>
236
+ {plansLoading && <ActivityIndicator color={C.brand} style={{ marginTop: S.md }} />}
237
+ {!plansLoading && network && plans.length === 0 && (
238
+ <EmptyText>No plans available for {network} right now.</EmptyText>
239
+ )}
240
+ {!plansLoading &&
241
+ plans.map((plan: any) => (
242
+ <PlanCard
243
+ key={plan.id}
244
+ selected={selectedPlan?.id === plan.id}
245
+ disabled={!plan.isAvailable}
246
+ onPress={() => plan.isAvailable && setSelectedPlan(plan)}
247
+ >
248
+ <View>
249
+ <PlanLabel>{plan.label}</PlanLabel>
250
+ <PlanValidity>{plan.validity}</PlanValidity>
251
+ </View>
252
+ <PlanPrice>₦{(plan.priceInKobo / 100).toLocaleString()}</PlanPrice>
253
+ </PlanCard>
254
+ ))}
255
+
256
+ <ContinueButton disabled={!isValid} onPress={handleContinue} activeOpacity={0.85}>
257
+ <ContinueButtonText>Continue</ContinueButtonText>
258
+ </ContinueButton>
259
+ </Body>
260
+ </KeyboardAvoidingView>
261
+ </Container>
262
+ );
263
+ }
@@ -0,0 +1,344 @@
1
+ import { useEffect, useState } from 'react';
2
+ import { View, Text, TouchableOpacity, ScrollView, KeyboardAvoidingView, Platform, Switch, ActivityIndicator } from 'react-native';
3
+ import styled from 'styled-components/native';
4
+ import { C, F, R, S } from '../../../theme';
5
+ import { billsAPI } from '../../../../core/api';
6
+ import type { FPBillProvider, FPMeterType, FPElectricityPurchaseRequest, FPUserInfo } from '../../../../core/types';
7
+
8
+ const Container = styled(View)`
9
+ flex: 1;
10
+ background-color: ${C.white};
11
+ `;
12
+
13
+ const Body = styled(ScrollView)`
14
+ flex: 1;
15
+ padding: ${S.lg}px;
16
+ `;
17
+
18
+ const FieldLabel = styled(Text)`
19
+ font-size: ${F.sm}px;
20
+ font-weight: 600;
21
+ color: ${C.muted};
22
+ margin-bottom: ${S.xs}px;
23
+ `;
24
+
25
+ const InputBox = styled.View`
26
+ background-color: ${C.surface};
27
+ border-radius: ${R.lg}px;
28
+ padding: 0 ${S.md}px;
29
+ height: 52px;
30
+ flex-direction: row;
31
+ align-items: center;
32
+ margin-bottom: ${S.md}px;
33
+ `;
34
+
35
+ const StyledInput = styled.TextInput`
36
+ flex: 1;
37
+ font-size: ${F.md}px;
38
+ color: ${C.ink};
39
+ `;
40
+
41
+ const CurrencyPrefix = styled(Text)`
42
+ font-size: ${F.md}px;
43
+ color: ${C.muted};
44
+ margin-right: ${S.xs}px;
45
+ `;
46
+
47
+ const SelectBox = styled(TouchableOpacity)`
48
+ background-color: ${C.surface};
49
+ border-radius: ${R.lg}px;
50
+ padding: 0 ${S.md}px;
51
+ height: 52px;
52
+ flex-direction: row;
53
+ align-items: center;
54
+ justify-content: space-between;
55
+ margin-bottom: ${S.md}px;
56
+ `;
57
+
58
+ const SelectBoxText = styled(Text)<{ placeholder?: boolean }>`
59
+ font-size: ${F.md}px;
60
+ color: ${(props: any) => (props.placeholder ? C.ghost : C.ink)};
61
+ `;
62
+
63
+ const DiscoSheet = styled(View)`
64
+ background-color: ${C.white};
65
+ border-radius: ${R.xl}px;
66
+ padding: ${S.md}px;
67
+ margin-bottom: ${S.md}px;
68
+ max-height: 240px;
69
+ `;
70
+
71
+ const DiscoRow = styled(TouchableOpacity)<{ selected: boolean }>`
72
+ padding: ${S.sm}px ${S.md}px;
73
+ border-radius: ${R.md}px;
74
+ background-color: ${(props: any) => (props.selected ? C.brandLight : 'transparent')};
75
+ margin-bottom: 4px;
76
+ `;
77
+
78
+ const DiscoRowText = styled(Text)`
79
+ font-size: ${F.md}px;
80
+ color: ${C.ink};
81
+ font-weight: 600;
82
+ `;
83
+
84
+ const TypeRow = styled(View)`
85
+ flex-direction: row;
86
+ gap: ${S.sm}px;
87
+ margin-bottom: ${S.md}px;
88
+ `;
89
+
90
+ const TypeChip = styled(TouchableOpacity)<{ selected: boolean }>`
91
+ flex: 1;
92
+ height: 44px;
93
+ border-radius: ${R.md}px;
94
+ align-items: center;
95
+ justify-content: center;
96
+ background-color: ${(props: any) => (props.selected ? C.brand : C.surface)};
97
+ `;
98
+
99
+ const TypeChipText = styled(Text)<{ selected: boolean }>`
100
+ font-size: ${F.sm}px;
101
+ font-weight: 700;
102
+ color: ${(props: any) => (props.selected ? C.white : C.muted)};
103
+ `;
104
+
105
+ const CustomerNameBox = styled(View)`
106
+ background-color: ${C.greenLight};
107
+ border-radius: ${R.md}px;
108
+ padding: ${S.sm}px ${S.md}px;
109
+ margin-bottom: ${S.md}px;
110
+ `;
111
+
112
+ const CustomerNameText = styled(Text)`
113
+ color: ${C.green};
114
+ font-weight: 700;
115
+ font-size: ${F.sm}px;
116
+ `;
117
+
118
+ const SwitchRow = styled(View)`
119
+ flex-direction: row;
120
+ justify-content: space-between;
121
+ align-items: center;
122
+ margin-bottom: ${S.md}px;
123
+ `;
124
+
125
+ const SwitchLabel = styled(Text)`
126
+ font-size: ${F.md}px;
127
+ color: ${C.ink};
128
+ font-weight: 600;
129
+ `;
130
+
131
+ const ContinueButton = styled(TouchableOpacity)<{ disabled?: boolean }>`
132
+ background-color: ${(props: any) => (props.disabled ? C.ghost : C.brand)};
133
+ border-radius: ${R.full}px;
134
+ padding: ${S.md}px 0;
135
+ align-items: center;
136
+ margin-top: ${S.sm}px;
137
+ `;
138
+
139
+ const ContinueButtonText = styled(Text)`
140
+ color: ${C.white};
141
+ font-weight: 800;
142
+ font-size: ${F.md}px;
143
+ `;
144
+
145
+ interface Props {
146
+ amount: number;
147
+ user: FPUserInfo | null;
148
+ onProcessTransaction: (
149
+ payload: FPElectricityPurchaseRequest,
150
+ summaryRows: { label: string; value: string }[]
151
+ ) => void;
152
+ onError?: (err: { code: string; message: string }) => void;
153
+ }
154
+
155
+ export default function ElectricityScreen({ amount, user, onProcessTransaction, onError }: Props) {
156
+ const [discos, setDiscos] = useState<FPBillProvider[]>([]);
157
+ const [discoPickerOpen, setDiscoPickerOpen] = useState(false);
158
+ const [disco, setDisco] = useState<FPBillProvider | null>(null);
159
+ const [meterType, setMeterType] = useState<FPMeterType>('PREPAID');
160
+ const [meterNumber, setMeterNumber] = useState('');
161
+ const [validating, setValidating] = useState(false);
162
+ const [customerName, setCustomerName] = useState<string | null>(null);
163
+ const [minVendInKobo, setMinVendInKobo] = useState<number | null>(null);
164
+ const [purchaseAmount, setPurchaseAmount] = useState<string>(amount > 0 ? String(amount) : '');
165
+ const [forSelf, setForSelf] = useState(true);
166
+ const [phone, setPhone] = useState('');
167
+ const [email, setEmail] = useState('');
168
+
169
+ useEffect(() => {
170
+ billsAPI
171
+ .getDiscos()
172
+ .then((res: any) => {
173
+ if (res.status) setDiscos(res.payload.filter((d: FPBillProvider) => d.isActive));
174
+ })
175
+ .catch(() => onError?.({ code: 'DISCO_LOAD_FAILED', message: 'Could not load electricity providers' }));
176
+ }, []);
177
+
178
+ // Re-validate whenever the meter number reaches a plausible length, or
179
+ // the disco/type changes — mirrors checkMeterNumber()'s trigger in the
180
+ // existing BuyPower-backed Electricity screen.
181
+ useEffect(() => {
182
+ setCustomerName(null);
183
+ setMinVendInKobo(null);
184
+ if (!disco || meterNumber.length < 10) return;
185
+
186
+ setValidating(true);
187
+ billsAPI
188
+ .validateMeter(meterNumber, disco.code, meterType)
189
+ .then((res: any) => {
190
+ if (res.status) {
191
+ setCustomerName(res.payload.customerName);
192
+ setMinVendInKobo(res.payload.minVendAmountInKobo ?? null);
193
+ } else {
194
+ onError?.({ code: 'METER_INVALID', message: res.message });
195
+ }
196
+ })
197
+ .catch(() => onError?.({ code: 'METER_VALIDATION_FAILED', message: 'Could not validate meter number' }))
198
+ .finally(() => setValidating(false));
199
+ }, [disco, meterType, meterNumber]);
200
+
201
+ const amountInKobo = Math.round((Number(purchaseAmount) || 0) * 100);
202
+ const meetsMinVend = minVendInKobo == null || amountInKobo >= minVendInKobo;
203
+ const contactValid = forSelf || (/^0\d{10}$/.test(phone) && /\S+@\S+\.\S+/.test(email));
204
+
205
+ const isValid =
206
+ !!disco && meterNumber.length >= 10 && !!customerName && amountInKobo > 0 && meetsMinVend && contactValid;
207
+
208
+ const handleContinue = () => {
209
+ if (!isValid || !disco) return;
210
+ onProcessTransaction(
211
+ {
212
+ category: 'ELECTRICITY',
213
+ meterNumber,
214
+ disco: disco.code,
215
+ meterType,
216
+ amountInKobo,
217
+ forSelf,
218
+ phoneNumber: forSelf ? (user?.phone ?? '') : phone,
219
+ email: forSelf ? (user?.email ?? '') : email,
220
+ idempotencyKey: `electricity_${Date.now()}_${Math.random().toString(36).slice(2, 8)}`,
221
+ },
222
+ [
223
+ { label: 'Disco', value: disco.displayName },
224
+ { label: 'Meter Type', value: meterType },
225
+ { label: 'Meter Number', value: meterNumber },
226
+ { label: 'Customer', value: customerName ?? '' },
227
+ ]
228
+ );
229
+ };
230
+
231
+ return (
232
+ <Container>
233
+ <KeyboardAvoidingView style={{ flex: 1 }} behavior={Platform.OS === 'ios' ? 'padding' : undefined}>
234
+ <Body keyboardShouldPersistTaps="handled" showsVerticalScrollIndicator={false}>
235
+ <FieldLabel>Distribution Company</FieldLabel>
236
+ <SelectBox onPress={() => setDiscoPickerOpen((v: any) => !v)}>
237
+ <SelectBoxText placeholder={!disco}>{disco?.displayName ?? 'Select a disco'}</SelectBoxText>
238
+ <Text>{discoPickerOpen ? '▲' : '▼'}</Text>
239
+ </SelectBox>
240
+
241
+ {discoPickerOpen && (
242
+ <DiscoSheet>
243
+ <ScrollView showsVerticalScrollIndicator={false}>
244
+ {discos.map((d: any) => (
245
+ <DiscoRow
246
+ key={d.code}
247
+ selected={disco?.code === d.code}
248
+ onPress={() => {
249
+ setDisco(d);
250
+ setDiscoPickerOpen(false);
251
+ }}
252
+ >
253
+ <DiscoRowText>{d.displayName}</DiscoRowText>
254
+ </DiscoRow>
255
+ ))}
256
+ </ScrollView>
257
+ </DiscoSheet>
258
+ )}
259
+
260
+ <FieldLabel>Meter Type</FieldLabel>
261
+ <TypeRow>
262
+ <TypeChip selected={meterType === 'PREPAID'} onPress={() => setMeterType('PREPAID')}>
263
+ <TypeChipText selected={meterType === 'PREPAID'}>Prepaid</TypeChipText>
264
+ </TypeChip>
265
+ <TypeChip selected={meterType === 'POSTPAID'} onPress={() => setMeterType('POSTPAID')}>
266
+ <TypeChipText selected={meterType === 'POSTPAID'}>Postpaid</TypeChipText>
267
+ </TypeChip>
268
+ </TypeRow>
269
+
270
+ <FieldLabel>Meter Number</FieldLabel>
271
+ <InputBox>
272
+ <StyledInput
273
+ placeholder="Enter meter number"
274
+ placeholderTextColor={C.ghost}
275
+ keyboardType="number-pad"
276
+ value={meterNumber}
277
+ onChangeText={setMeterNumber}
278
+ />
279
+ </InputBox>
280
+ {validating && <ActivityIndicator color={C.brand} style={{ marginBottom: S.md }} />}
281
+ {customerName && (
282
+ <CustomerNameBox>
283
+ <CustomerNameText>{customerName}</CustomerNameText>
284
+ </CustomerNameBox>
285
+ )}
286
+
287
+ <FieldLabel>Amount</FieldLabel>
288
+ <InputBox>
289
+ <CurrencyPrefix>₦</CurrencyPrefix>
290
+ <StyledInput
291
+ placeholder="Enter amount"
292
+ placeholderTextColor={C.ghost}
293
+ keyboardType="number-pad"
294
+ value={purchaseAmount}
295
+ onChangeText={setPurchaseAmount}
296
+ />
297
+ </InputBox>
298
+ {minVendInKobo != null && !meetsMinVend && (
299
+ <Text style={{ color: C.red, fontSize: F.xs, marginBottom: S.md }}>
300
+ Minimum amount is ₦{(minVendInKobo / 100).toLocaleString()}
301
+ </Text>
302
+ )}
303
+
304
+ <SwitchRow>
305
+ <SwitchLabel>This is for me</SwitchLabel>
306
+ <Switch
307
+ value={forSelf}
308
+ onValueChange={setForSelf}
309
+ trackColor={{ false: C.border, true: C.brandLight }}
310
+ thumbColor={forSelf ? C.brand : C.ghost}
311
+ />
312
+ </SwitchRow>
313
+
314
+ {!forSelf && (
315
+ <>
316
+ <InputBox>
317
+ <StyledInput
318
+ placeholder="Phone number"
319
+ placeholderTextColor={C.ghost}
320
+ keyboardType="number-pad"
321
+ value={phone}
322
+ onChangeText={setPhone}
323
+ />
324
+ </InputBox>
325
+ <InputBox>
326
+ <StyledInput
327
+ placeholder="Email address"
328
+ placeholderTextColor={C.ghost}
329
+ keyboardType="email-address"
330
+ value={email}
331
+ onChangeText={setEmail}
332
+ />
333
+ </InputBox>
334
+ </>
335
+ )}
336
+
337
+ <ContinueButton disabled={!isValid} onPress={handleContinue} activeOpacity={0.85}>
338
+ <ContinueButtonText>Continue</ContinueButtonText>
339
+ </ContinueButton>
340
+ </Body>
341
+ </KeyboardAvoidingView>
342
+ </Container>
343
+ );
344
+ }
@@ -223,7 +223,7 @@ export function TransferSubScreen({
223
223
 
224
224
  const base = {
225
225
  recipient: accountDetail,
226
- amount: Number(amount), // keep as number — host app converts if needed
226
+ amount: String(amount), // keep as number — host app converts if needed
227
227
  currency,
228
228
  narration: `Send ${currency}${amount} to ${accountDetail.accountName}`,
229
229
  reference: `SEND_${Date.now()}`,