@nairaramp/react 0.0.0-stage → 0.1.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.
- package/LICENSE +201 -0
- package/README.md +56 -2
- package/dist/index.cjs +575 -0
- package/dist/index.d.cts +56 -0
- package/dist/index.d.ts +56 -0
- package/dist/index.js +555 -0
- package/package.json +52 -4
package/dist/index.js
ADDED
|
@@ -0,0 +1,555 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
// src/usePayWithNaira.ts
|
|
4
|
+
import { useState, useCallback, useRef, useEffect } from "react";
|
|
5
|
+
import {
|
|
6
|
+
TERMINAL_STATUSES,
|
|
7
|
+
NairaRampError,
|
|
8
|
+
isNairaRampError
|
|
9
|
+
} from "@nairaramp/core";
|
|
10
|
+
function ensureNairaRampError(err) {
|
|
11
|
+
if (isNairaRampError(err)) {
|
|
12
|
+
return err;
|
|
13
|
+
}
|
|
14
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
15
|
+
return new NairaRampError("TRANSACTION_FAILED", message, { cause: err });
|
|
16
|
+
}
|
|
17
|
+
function usePayWithNaira({
|
|
18
|
+
ramp,
|
|
19
|
+
assetCode
|
|
20
|
+
}) {
|
|
21
|
+
const [phase, setPhase] = useState("idle");
|
|
22
|
+
const [status, setStatus] = useState(void 0);
|
|
23
|
+
const [transactionId, setTransactionId] = useState(void 0);
|
|
24
|
+
const [url, setUrl] = useState(void 0);
|
|
25
|
+
const [error, setError] = useState(void 0);
|
|
26
|
+
const phaseRef = useRef("idle");
|
|
27
|
+
const subscriptionRef = useRef(void 0);
|
|
28
|
+
const isMountedRef = useRef(true);
|
|
29
|
+
useEffect(() => {
|
|
30
|
+
phaseRef.current = phase;
|
|
31
|
+
}, [phase]);
|
|
32
|
+
const stopWatcher = useCallback(() => {
|
|
33
|
+
if (subscriptionRef.current) {
|
|
34
|
+
subscriptionRef.current.stop();
|
|
35
|
+
subscriptionRef.current = void 0;
|
|
36
|
+
}
|
|
37
|
+
}, []);
|
|
38
|
+
const reset = useCallback(() => {
|
|
39
|
+
stopWatcher();
|
|
40
|
+
phaseRef.current = "idle";
|
|
41
|
+
if (isMountedRef.current) {
|
|
42
|
+
setPhase("idle");
|
|
43
|
+
setStatus(void 0);
|
|
44
|
+
setTransactionId(void 0);
|
|
45
|
+
setUrl(void 0);
|
|
46
|
+
setError(void 0);
|
|
47
|
+
}
|
|
48
|
+
}, [stopWatcher]);
|
|
49
|
+
const start = useCallback(
|
|
50
|
+
async (amount) => {
|
|
51
|
+
if (phaseRef.current !== "idle") {
|
|
52
|
+
return void 0;
|
|
53
|
+
}
|
|
54
|
+
phaseRef.current = "starting";
|
|
55
|
+
if (isMountedRef.current) {
|
|
56
|
+
setPhase("starting");
|
|
57
|
+
setError(void 0);
|
|
58
|
+
}
|
|
59
|
+
let depositResult;
|
|
60
|
+
try {
|
|
61
|
+
depositResult = await ramp.deposit({
|
|
62
|
+
assetCode,
|
|
63
|
+
...amount !== void 0 ? { amount } : {}
|
|
64
|
+
});
|
|
65
|
+
} catch (err) {
|
|
66
|
+
const wrapped = ensureNairaRampError(err);
|
|
67
|
+
phaseRef.current = "failed";
|
|
68
|
+
if (isMountedRef.current) {
|
|
69
|
+
setError(wrapped);
|
|
70
|
+
setPhase("failed");
|
|
71
|
+
}
|
|
72
|
+
return void 0;
|
|
73
|
+
}
|
|
74
|
+
if (!isMountedRef.current) {
|
|
75
|
+
return void 0;
|
|
76
|
+
}
|
|
77
|
+
const { id, url: hostedUrl } = depositResult;
|
|
78
|
+
setTransactionId(id);
|
|
79
|
+
setUrl(hostedUrl);
|
|
80
|
+
phaseRef.current = "awaiting_user";
|
|
81
|
+
setPhase("awaiting_user");
|
|
82
|
+
stopWatcher();
|
|
83
|
+
const subscription = ramp.watch(id, {
|
|
84
|
+
onStatus: (nextStatus) => {
|
|
85
|
+
if (!isMountedRef.current) return;
|
|
86
|
+
setStatus(nextStatus);
|
|
87
|
+
if (nextStatus === "completed") {
|
|
88
|
+
phaseRef.current = "completed";
|
|
89
|
+
setPhase("completed");
|
|
90
|
+
} else if (TERMINAL_STATUSES.includes(nextStatus)) {
|
|
91
|
+
phaseRef.current = "failed";
|
|
92
|
+
setPhase("failed");
|
|
93
|
+
} else if (nextStatus === "pending_user_transfer_start" || nextStatus === "incomplete") {
|
|
94
|
+
phaseRef.current = "awaiting_user";
|
|
95
|
+
setPhase("awaiting_user");
|
|
96
|
+
} else {
|
|
97
|
+
phaseRef.current = "processing";
|
|
98
|
+
setPhase("processing");
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
onComplete: () => {
|
|
102
|
+
if (!isMountedRef.current) return;
|
|
103
|
+
setStatus("completed");
|
|
104
|
+
phaseRef.current = "completed";
|
|
105
|
+
setPhase("completed");
|
|
106
|
+
},
|
|
107
|
+
onError: (err) => {
|
|
108
|
+
if (!isMountedRef.current) return;
|
|
109
|
+
const wrapped = ensureNairaRampError(err);
|
|
110
|
+
setError(wrapped);
|
|
111
|
+
phaseRef.current = "failed";
|
|
112
|
+
setPhase("failed");
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
subscriptionRef.current = subscription;
|
|
116
|
+
return depositResult;
|
|
117
|
+
},
|
|
118
|
+
[ramp, assetCode, stopWatcher]
|
|
119
|
+
);
|
|
120
|
+
useEffect(() => {
|
|
121
|
+
isMountedRef.current = true;
|
|
122
|
+
return () => {
|
|
123
|
+
isMountedRef.current = false;
|
|
124
|
+
stopWatcher();
|
|
125
|
+
};
|
|
126
|
+
}, [stopWatcher]);
|
|
127
|
+
return {
|
|
128
|
+
start,
|
|
129
|
+
phase,
|
|
130
|
+
status,
|
|
131
|
+
transactionId,
|
|
132
|
+
url,
|
|
133
|
+
error,
|
|
134
|
+
reset
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// src/PayWithNaira.tsx
|
|
139
|
+
import {
|
|
140
|
+
useState as useState2,
|
|
141
|
+
useRef as useRef2,
|
|
142
|
+
useEffect as useEffect2,
|
|
143
|
+
useCallback as useCallback2
|
|
144
|
+
} from "react";
|
|
145
|
+
import {
|
|
146
|
+
NairaRampError as NairaRampErrorClass
|
|
147
|
+
} from "@nairaramp/core";
|
|
148
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
149
|
+
var containerStyle = {
|
|
150
|
+
width: "100%",
|
|
151
|
+
maxWidth: "420px",
|
|
152
|
+
boxSizing: "border-box",
|
|
153
|
+
fontFamily: "system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif",
|
|
154
|
+
fontSize: "16px",
|
|
155
|
+
lineHeight: 1.5,
|
|
156
|
+
color: "#111827",
|
|
157
|
+
textAlign: "center"
|
|
158
|
+
};
|
|
159
|
+
var baseButtonStyle = {
|
|
160
|
+
width: "100%",
|
|
161
|
+
boxSizing: "border-box",
|
|
162
|
+
padding: "12px 16px",
|
|
163
|
+
fontSize: "16px",
|
|
164
|
+
fontWeight: 600,
|
|
165
|
+
borderRadius: "8px",
|
|
166
|
+
border: "1px solid transparent",
|
|
167
|
+
cursor: "pointer",
|
|
168
|
+
textAlign: "center",
|
|
169
|
+
display: "inline-block",
|
|
170
|
+
transition: "outline 0.15s ease"
|
|
171
|
+
};
|
|
172
|
+
var primaryButtonStyle = {
|
|
173
|
+
...baseButtonStyle,
|
|
174
|
+
color: "#ffffff",
|
|
175
|
+
backgroundColor: "#059669"
|
|
176
|
+
};
|
|
177
|
+
var disabledButtonStyle = {
|
|
178
|
+
...baseButtonStyle,
|
|
179
|
+
color: "#ffffff",
|
|
180
|
+
backgroundColor: "#9ca3af",
|
|
181
|
+
cursor: "not-allowed",
|
|
182
|
+
opacity: 0.8
|
|
183
|
+
};
|
|
184
|
+
var retryButtonStyle = {
|
|
185
|
+
...baseButtonStyle,
|
|
186
|
+
marginTop: "12px",
|
|
187
|
+
padding: "10px 16px",
|
|
188
|
+
fontSize: "15px",
|
|
189
|
+
color: "#1f2937",
|
|
190
|
+
backgroundColor: "#f3f4f6",
|
|
191
|
+
border: "1px solid #d1d5db"
|
|
192
|
+
};
|
|
193
|
+
var statusTextStyle = {
|
|
194
|
+
margin: "8px 0",
|
|
195
|
+
fontSize: "16px",
|
|
196
|
+
fontWeight: 500,
|
|
197
|
+
color: "#1f2937"
|
|
198
|
+
};
|
|
199
|
+
var errorTextStyle = {
|
|
200
|
+
margin: "8px 0",
|
|
201
|
+
fontSize: "15px",
|
|
202
|
+
fontWeight: 500,
|
|
203
|
+
color: "#b91c1c",
|
|
204
|
+
wordBreak: "break-word"
|
|
205
|
+
};
|
|
206
|
+
var linkStyle = {
|
|
207
|
+
display: "inline-block",
|
|
208
|
+
fontSize: "15px",
|
|
209
|
+
fontWeight: 600,
|
|
210
|
+
color: "#2563eb",
|
|
211
|
+
textDecoration: "underline",
|
|
212
|
+
wordBreak: "break-all",
|
|
213
|
+
cursor: "pointer"
|
|
214
|
+
};
|
|
215
|
+
function PayWithNaira({
|
|
216
|
+
ramp,
|
|
217
|
+
assetCode,
|
|
218
|
+
amount,
|
|
219
|
+
onComplete,
|
|
220
|
+
onError,
|
|
221
|
+
label = "Pay with Naira"
|
|
222
|
+
}) {
|
|
223
|
+
const { start, phase, error, url, reset } = usePayWithNaira({
|
|
224
|
+
ramp,
|
|
225
|
+
assetCode
|
|
226
|
+
});
|
|
227
|
+
const [popupBlocked, setPopupBlocked] = useState2(false);
|
|
228
|
+
const [isPrimaryFocused, setIsPrimaryFocused] = useState2(false);
|
|
229
|
+
const [isRetryFocused, setIsRetryFocused] = useState2(false);
|
|
230
|
+
const [isLinkFocused, setIsLinkFocused] = useState2(false);
|
|
231
|
+
const popupRef = useRef2(null);
|
|
232
|
+
const onCompleteRef = useRef2(onComplete);
|
|
233
|
+
const onErrorRef = useRef2(onError);
|
|
234
|
+
const completedFiredRef = useRef2(false);
|
|
235
|
+
const errorFiredRef = useRef2(false);
|
|
236
|
+
useEffect2(() => {
|
|
237
|
+
onCompleteRef.current = onComplete;
|
|
238
|
+
}, [onComplete]);
|
|
239
|
+
useEffect2(() => {
|
|
240
|
+
onErrorRef.current = onError;
|
|
241
|
+
}, [onError]);
|
|
242
|
+
const closePopup = useCallback2(() => {
|
|
243
|
+
if (popupRef.current && !popupRef.current.closed) {
|
|
244
|
+
try {
|
|
245
|
+
popupRef.current.close();
|
|
246
|
+
} catch {
|
|
247
|
+
}
|
|
248
|
+
popupRef.current = null;
|
|
249
|
+
}
|
|
250
|
+
}, []);
|
|
251
|
+
const handleClick = useCallback2(async () => {
|
|
252
|
+
setPopupBlocked(false);
|
|
253
|
+
let popup = null;
|
|
254
|
+
try {
|
|
255
|
+
popup = window.open("", "nairaramp_anchor");
|
|
256
|
+
} catch {
|
|
257
|
+
popup = null;
|
|
258
|
+
}
|
|
259
|
+
popupRef.current = popup;
|
|
260
|
+
if (!popup) {
|
|
261
|
+
setPopupBlocked(true);
|
|
262
|
+
}
|
|
263
|
+
try {
|
|
264
|
+
const result = await start(amount);
|
|
265
|
+
if (result?.url) {
|
|
266
|
+
if (popup && !popup.closed) {
|
|
267
|
+
popup.location.href = result.url;
|
|
268
|
+
}
|
|
269
|
+
} else {
|
|
270
|
+
closePopup();
|
|
271
|
+
}
|
|
272
|
+
} catch {
|
|
273
|
+
closePopup();
|
|
274
|
+
}
|
|
275
|
+
}, [start, amount, closePopup]);
|
|
276
|
+
const handleRetry = useCallback2(() => {
|
|
277
|
+
setPopupBlocked(false);
|
|
278
|
+
closePopup();
|
|
279
|
+
completedFiredRef.current = false;
|
|
280
|
+
errorFiredRef.current = false;
|
|
281
|
+
reset();
|
|
282
|
+
}, [reset, closePopup]);
|
|
283
|
+
useEffect2(() => {
|
|
284
|
+
if (phase === "completed") {
|
|
285
|
+
if (!completedFiredRef.current) {
|
|
286
|
+
completedFiredRef.current = true;
|
|
287
|
+
onCompleteRef.current?.();
|
|
288
|
+
}
|
|
289
|
+
} else if (phase === "failed") {
|
|
290
|
+
closePopup();
|
|
291
|
+
if (!errorFiredRef.current) {
|
|
292
|
+
errorFiredRef.current = true;
|
|
293
|
+
const finalError = error ?? new NairaRampErrorClass("TRANSACTION_FAILED", "Payment failed");
|
|
294
|
+
onErrorRef.current?.(finalError);
|
|
295
|
+
}
|
|
296
|
+
} else if (phase === "idle") {
|
|
297
|
+
completedFiredRef.current = false;
|
|
298
|
+
errorFiredRef.current = false;
|
|
299
|
+
}
|
|
300
|
+
}, [phase, error, closePopup]);
|
|
301
|
+
return /* @__PURE__ */ jsxs("div", { style: containerStyle, children: [
|
|
302
|
+
phase === "idle" && /* @__PURE__ */ jsx(
|
|
303
|
+
"button",
|
|
304
|
+
{
|
|
305
|
+
type: "button",
|
|
306
|
+
onClick: handleClick,
|
|
307
|
+
onFocus: () => setIsPrimaryFocused(true),
|
|
308
|
+
onBlur: () => setIsPrimaryFocused(false),
|
|
309
|
+
style: {
|
|
310
|
+
...primaryButtonStyle,
|
|
311
|
+
outline: isPrimaryFocused ? "3px solid #047857" : "2px solid transparent",
|
|
312
|
+
outlineOffset: "2px"
|
|
313
|
+
},
|
|
314
|
+
children: label
|
|
315
|
+
}
|
|
316
|
+
),
|
|
317
|
+
/* @__PURE__ */ jsxs("div", { "aria-live": "polite", "aria-atomic": "true", children: [
|
|
318
|
+
phase === "starting" && /* @__PURE__ */ jsx(
|
|
319
|
+
"button",
|
|
320
|
+
{
|
|
321
|
+
type: "button",
|
|
322
|
+
disabled: true,
|
|
323
|
+
style: disabledButtonStyle,
|
|
324
|
+
children: "Connecting..."
|
|
325
|
+
}
|
|
326
|
+
),
|
|
327
|
+
phase === "awaiting_user" && /* @__PURE__ */ jsxs("div", { children: [
|
|
328
|
+
/* @__PURE__ */ jsx("p", { style: statusTextStyle, children: "Complete the steps in the anchor window" }),
|
|
329
|
+
popupBlocked && url && /* @__PURE__ */ jsx("p", { style: { margin: "8px 0 0 0" }, children: /* @__PURE__ */ jsx(
|
|
330
|
+
"a",
|
|
331
|
+
{
|
|
332
|
+
href: url,
|
|
333
|
+
target: "_blank",
|
|
334
|
+
rel: "noopener noreferrer",
|
|
335
|
+
onFocus: () => setIsLinkFocused(true),
|
|
336
|
+
onBlur: () => setIsLinkFocused(false),
|
|
337
|
+
style: {
|
|
338
|
+
...linkStyle,
|
|
339
|
+
outline: isLinkFocused ? "2px solid #2563eb" : "2px solid transparent",
|
|
340
|
+
outlineOffset: "2px"
|
|
341
|
+
},
|
|
342
|
+
children: "Continue to the anchor"
|
|
343
|
+
}
|
|
344
|
+
) })
|
|
345
|
+
] }),
|
|
346
|
+
phase === "processing" && /* @__PURE__ */ jsx("p", { style: statusTextStyle, children: "Processing your payment" }),
|
|
347
|
+
phase === "completed" && /* @__PURE__ */ jsx("p", { style: statusTextStyle, children: "Payment completed" }),
|
|
348
|
+
phase === "failed" && /* @__PURE__ */ jsxs("div", { children: [
|
|
349
|
+
/* @__PURE__ */ jsx("p", { style: errorTextStyle, children: error?.message ?? "Payment failed" }),
|
|
350
|
+
/* @__PURE__ */ jsx(
|
|
351
|
+
"button",
|
|
352
|
+
{
|
|
353
|
+
type: "button",
|
|
354
|
+
onClick: handleRetry,
|
|
355
|
+
onFocus: () => setIsRetryFocused(true),
|
|
356
|
+
onBlur: () => setIsRetryFocused(false),
|
|
357
|
+
style: {
|
|
358
|
+
...retryButtonStyle,
|
|
359
|
+
outline: isRetryFocused ? "2px solid #2563eb" : "2px solid transparent",
|
|
360
|
+
outlineOffset: "2px"
|
|
361
|
+
},
|
|
362
|
+
children: "Try again"
|
|
363
|
+
}
|
|
364
|
+
)
|
|
365
|
+
] })
|
|
366
|
+
] })
|
|
367
|
+
] });
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
// src/StatusTimeline.tsx
|
|
371
|
+
import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
372
|
+
var TIMELINE_STEPS = [
|
|
373
|
+
"Started",
|
|
374
|
+
"Waiting for your payment",
|
|
375
|
+
"Payment received",
|
|
376
|
+
"Anchor processing",
|
|
377
|
+
"Sending on Stellar",
|
|
378
|
+
"Completed"
|
|
379
|
+
];
|
|
380
|
+
var STATUS_MAP = {
|
|
381
|
+
incomplete: {
|
|
382
|
+
kind: "step",
|
|
383
|
+
stepIndex: 0,
|
|
384
|
+
label: "Started"
|
|
385
|
+
},
|
|
386
|
+
pending_user_transfer_start: {
|
|
387
|
+
kind: "step",
|
|
388
|
+
stepIndex: 1,
|
|
389
|
+
label: "Waiting for your payment"
|
|
390
|
+
},
|
|
391
|
+
pending_user_transfer_complete: {
|
|
392
|
+
kind: "step",
|
|
393
|
+
stepIndex: 2,
|
|
394
|
+
label: "Payment received"
|
|
395
|
+
},
|
|
396
|
+
pending_external: {
|
|
397
|
+
kind: "step",
|
|
398
|
+
stepIndex: 2,
|
|
399
|
+
label: "Payment received"
|
|
400
|
+
},
|
|
401
|
+
pending_anchor: {
|
|
402
|
+
kind: "step",
|
|
403
|
+
stepIndex: 3,
|
|
404
|
+
label: "Anchor processing"
|
|
405
|
+
},
|
|
406
|
+
pending_stellar: {
|
|
407
|
+
kind: "step",
|
|
408
|
+
stepIndex: 4,
|
|
409
|
+
label: "Sending on Stellar"
|
|
410
|
+
},
|
|
411
|
+
pending_trust: {
|
|
412
|
+
kind: "step",
|
|
413
|
+
stepIndex: 4,
|
|
414
|
+
label: "Sending on Stellar"
|
|
415
|
+
},
|
|
416
|
+
pending_user: {
|
|
417
|
+
kind: "step",
|
|
418
|
+
stepIndex: 1,
|
|
419
|
+
label: "Waiting for your payment"
|
|
420
|
+
},
|
|
421
|
+
completed: {
|
|
422
|
+
kind: "step",
|
|
423
|
+
stepIndex: 5,
|
|
424
|
+
label: "Completed"
|
|
425
|
+
},
|
|
426
|
+
refunded: {
|
|
427
|
+
kind: "failure",
|
|
428
|
+
label: "Refunded"
|
|
429
|
+
},
|
|
430
|
+
expired: {
|
|
431
|
+
kind: "failure",
|
|
432
|
+
label: "Expired"
|
|
433
|
+
},
|
|
434
|
+
no_market: {
|
|
435
|
+
kind: "failure",
|
|
436
|
+
label: "No market"
|
|
437
|
+
},
|
|
438
|
+
too_small: {
|
|
439
|
+
kind: "failure",
|
|
440
|
+
label: "Too small"
|
|
441
|
+
},
|
|
442
|
+
too_large: {
|
|
443
|
+
kind: "failure",
|
|
444
|
+
label: "Too large"
|
|
445
|
+
},
|
|
446
|
+
error: {
|
|
447
|
+
kind: "failure",
|
|
448
|
+
label: "Error"
|
|
449
|
+
}
|
|
450
|
+
};
|
|
451
|
+
var containerStyle2 = {
|
|
452
|
+
width: "100%",
|
|
453
|
+
maxWidth: "420px",
|
|
454
|
+
boxSizing: "border-box",
|
|
455
|
+
fontFamily: "system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif",
|
|
456
|
+
fontSize: "15px",
|
|
457
|
+
lineHeight: 1.5,
|
|
458
|
+
color: "#111827"
|
|
459
|
+
};
|
|
460
|
+
var listStyle = {
|
|
461
|
+
listStyle: "none",
|
|
462
|
+
padding: 0,
|
|
463
|
+
margin: 0,
|
|
464
|
+
display: "flex",
|
|
465
|
+
flexDirection: "column",
|
|
466
|
+
gap: "12px"
|
|
467
|
+
};
|
|
468
|
+
var failureContainerStyle = {
|
|
469
|
+
...containerStyle2,
|
|
470
|
+
padding: "16px",
|
|
471
|
+
borderRadius: "8px",
|
|
472
|
+
backgroundColor: "#fef2f2",
|
|
473
|
+
border: "1px solid #fee2e2",
|
|
474
|
+
textAlign: "center"
|
|
475
|
+
};
|
|
476
|
+
var failureTitleStyle = {
|
|
477
|
+
margin: 0,
|
|
478
|
+
fontSize: "16px",
|
|
479
|
+
fontWeight: 600,
|
|
480
|
+
color: "#991b1b"
|
|
481
|
+
};
|
|
482
|
+
var messageTextStyle = {
|
|
483
|
+
margin: "6px 0 0 0",
|
|
484
|
+
fontSize: "14px",
|
|
485
|
+
color: "#4b5563"
|
|
486
|
+
};
|
|
487
|
+
function StatusTimeline({
|
|
488
|
+
status,
|
|
489
|
+
message,
|
|
490
|
+
labels
|
|
491
|
+
}) {
|
|
492
|
+
const mapping = status !== void 0 ? STATUS_MAP[status] : {
|
|
493
|
+
kind: "step",
|
|
494
|
+
stepIndex: 0,
|
|
495
|
+
label: "Started"
|
|
496
|
+
};
|
|
497
|
+
if (mapping.kind === "failure") {
|
|
498
|
+
return /* @__PURE__ */ jsxs2("div", { style: failureContainerStyle, role: "alert", children: [
|
|
499
|
+
/* @__PURE__ */ jsx2("p", { style: failureTitleStyle, children: mapping.label }),
|
|
500
|
+
message && /* @__PURE__ */ jsx2("p", { style: messageTextStyle, children: message })
|
|
501
|
+
] });
|
|
502
|
+
}
|
|
503
|
+
const activeIndex = mapping.stepIndex;
|
|
504
|
+
return /* @__PURE__ */ jsxs2("div", { style: containerStyle2, children: [
|
|
505
|
+
/* @__PURE__ */ jsx2("ol", { style: listStyle, "aria-label": "Payment status timeline", children: TIMELINE_STEPS.map((step, index) => {
|
|
506
|
+
const isDone = index < activeIndex;
|
|
507
|
+
const isActive = index === activeIndex;
|
|
508
|
+
const displayLabel = labels?.[step] ?? step;
|
|
509
|
+
const itemStyle = {
|
|
510
|
+
display: "flex",
|
|
511
|
+
alignItems: "center",
|
|
512
|
+
gap: "12px",
|
|
513
|
+
color: isActive ? "#111827" : isDone ? "#059669" : "#9ca3af",
|
|
514
|
+
fontWeight: isActive ? 600 : isDone ? 500 : 400
|
|
515
|
+
};
|
|
516
|
+
const badgeStyle = {
|
|
517
|
+
width: "24px",
|
|
518
|
+
height: "24px",
|
|
519
|
+
borderRadius: "50%",
|
|
520
|
+
display: "inline-flex",
|
|
521
|
+
alignItems: "center",
|
|
522
|
+
justifyContent: "center",
|
|
523
|
+
fontSize: "12px",
|
|
524
|
+
fontWeight: 700,
|
|
525
|
+
boxSizing: "border-box",
|
|
526
|
+
backgroundColor: isActive ? "#2563eb" : isDone ? "#059669" : "#e5e7eb",
|
|
527
|
+
color: isActive || isDone ? "#ffffff" : "#6b7280"
|
|
528
|
+
};
|
|
529
|
+
return /* @__PURE__ */ jsxs2(
|
|
530
|
+
"li",
|
|
531
|
+
{
|
|
532
|
+
"aria-current": isActive ? "step" : void 0,
|
|
533
|
+
style: itemStyle,
|
|
534
|
+
children: [
|
|
535
|
+
/* @__PURE__ */ jsx2("span", { style: badgeStyle, "aria-hidden": "true", children: isDone ? "\u2713" : index + 1 }),
|
|
536
|
+
/* @__PURE__ */ jsx2("span", { children: displayLabel })
|
|
537
|
+
]
|
|
538
|
+
},
|
|
539
|
+
step
|
|
540
|
+
);
|
|
541
|
+
}) }),
|
|
542
|
+
message && /* @__PURE__ */ jsx2("p", { style: messageTextStyle, children: message })
|
|
543
|
+
] });
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
// src/index.ts
|
|
547
|
+
var VERSION = "0.1.0";
|
|
548
|
+
export {
|
|
549
|
+
PayWithNaira,
|
|
550
|
+
STATUS_MAP,
|
|
551
|
+
StatusTimeline,
|
|
552
|
+
TIMELINE_STEPS,
|
|
553
|
+
VERSION,
|
|
554
|
+
usePayWithNaira
|
|
555
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,54 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nairaramp/react",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"packageManager": "pnpm@9.15.9",
|
|
7
|
+
"engines": {
|
|
8
|
+
"node": ">=20"
|
|
9
|
+
},
|
|
10
|
+
"sideEffects": false,
|
|
11
|
+
"main": "./dist/index.cjs",
|
|
12
|
+
"module": "./dist/index.js",
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"exports": {
|
|
15
|
+
".": {
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"import": "./dist/index.js",
|
|
18
|
+
"require": "./dist/index.cjs"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"dist",
|
|
23
|
+
"README.md",
|
|
24
|
+
"LICENSE"
|
|
25
|
+
],
|
|
26
|
+
"scripts": {
|
|
27
|
+
"build": "tsup",
|
|
28
|
+
"lint": "eslint .",
|
|
29
|
+
"typecheck": "tsc --noEmit",
|
|
30
|
+
"test": "vitest run"
|
|
31
|
+
},
|
|
32
|
+
"peerDependencies": {
|
|
33
|
+
"@nairaramp/core": "^0.1.0",
|
|
34
|
+
"react": ">=18",
|
|
35
|
+
"react-dom": ">=18"
|
|
36
|
+
},
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"@nairaramp/core": "0.1.0",
|
|
39
|
+
"@testing-library/react": "16.3.3",
|
|
40
|
+
"@types/node": "26.6.6",
|
|
41
|
+
"@types/react": "18.3.18",
|
|
42
|
+
"@types/react-dom": "18.3.5",
|
|
43
|
+
"@vitest/coverage-v8": "5.1.0",
|
|
44
|
+
"eslint": "9.22.0",
|
|
45
|
+
"eslint-plugin-react-hooks": "5.1.0",
|
|
46
|
+
"jsdom": "26.0.0",
|
|
47
|
+
"react": "18.3.1",
|
|
48
|
+
"react-dom": "18.3.1",
|
|
49
|
+
"tsup": "9.0.0",
|
|
50
|
+
"typescript": "5.8.3",
|
|
51
|
+
"typescript-eslint": "8.72.1",
|
|
52
|
+
"vitest": "5.1.0"
|
|
53
|
+
}
|
|
54
|
+
}
|