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