@nairaramp/react 0.1.0 → 0.2.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 CHANGED
@@ -21,17 +21,54 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
21
21
  // src/index.ts
22
22
  var index_exports = {};
23
23
  __export(index_exports, {
24
+ CashOutToNaira: () => CashOutToNaira,
25
+ ERROR_MESSAGES: () => ERROR_MESSAGES,
26
+ HAUSA_LABELS: () => HAUSA_LABELS,
27
+ IGBO_LABELS: () => IGBO_LABELS,
28
+ NairaRampProvider: () => NairaRampProvider,
29
+ PIDGIN_LABELS: () => PIDGIN_LABELS,
24
30
  PayWithNaira: () => PayWithNaira,
25
31
  STATUS_MAP: () => STATUS_MAP,
26
32
  StatusTimeline: () => StatusTimeline,
27
33
  TIMELINE_STEPS: () => TIMELINE_STEPS,
28
34
  VERSION: () => VERSION,
29
- usePayWithNaira: () => usePayWithNaira
35
+ YORUBA_LABELS: () => YORUBA_LABELS,
36
+ getErrorMessage: () => getErrorMessage,
37
+ getStellarExplorerUrl: () => getStellarExplorerUrl,
38
+ useAnchors: () => useAnchors,
39
+ useCashOutToNaira: () => useCashOutToNaira,
40
+ useNairaRamp: () => useNairaRamp,
41
+ usePayWithNaira: () => usePayWithNaira,
42
+ useRampQuote: () => useRampQuote
30
43
  });
31
44
  module.exports = __toCommonJS(index_exports);
32
45
 
33
- // src/usePayWithNaira.ts
46
+ // src/NairaRampContext.tsx
34
47
  var import_react = require("react");
48
+ var import_jsx_runtime = require("react/jsx-runtime");
49
+ var NairaRampContext = (0, import_react.createContext)(void 0);
50
+ function NairaRampProvider({
51
+ ramp,
52
+ children
53
+ }) {
54
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(NairaRampContext.Provider, { value: ramp, children });
55
+ }
56
+ function useNairaRamp(overrideRamp) {
57
+ const contextRamp = (0, import_react.useContext)(NairaRampContext);
58
+ const resolved = overrideRamp ?? contextRamp;
59
+ if (!resolved) {
60
+ throw new Error(
61
+ "No Ramp instance found. Pass a `ramp` prop/option or wrap your component tree in <NairaRampProvider>."
62
+ );
63
+ }
64
+ return resolved;
65
+ }
66
+
67
+ // src/usePayWithNaira.ts
68
+ var import_react2 = require("react");
69
+ var import_core2 = require("@nairaramp/core");
70
+
71
+ // src/utils.ts
35
72
  var import_core = require("@nairaramp/core");
36
73
  function ensureNairaRampError(err) {
37
74
  if ((0, import_core.isNairaRampError)(err)) {
@@ -40,46 +77,73 @@ function ensureNairaRampError(err) {
40
77
  const message = err instanceof Error ? err.message : String(err);
41
78
  return new import_core.NairaRampError("TRANSACTION_FAILED", message, { cause: err });
42
79
  }
80
+ function isSafeHttpUrl(rawUrl) {
81
+ try {
82
+ const parsed = new URL(rawUrl);
83
+ return parsed.protocol === "https:" || parsed.protocol === "http:";
84
+ } catch {
85
+ return false;
86
+ }
87
+ }
88
+ function getStellarExplorerUrl(txHash, network = "testnet") {
89
+ if (!txHash || !/^[0-9a-fA-F]{64}$/.test(txHash)) {
90
+ return void 0;
91
+ }
92
+ const segment = network === "mainnet" ? "public" : "testnet";
93
+ return `https://stellar.expert/explorer/${segment}/tx/${txHash}`;
94
+ }
95
+
96
+ // src/usePayWithNaira.ts
43
97
  function usePayWithNaira({
44
- ramp,
98
+ ramp: rampOption,
45
99
  assetCode
46
100
  }) {
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)(() => {
101
+ const ramp = useNairaRamp(rampOption);
102
+ const [phase, setPhase] = (0, import_react2.useState)("idle");
103
+ const [status, setStatus] = (0, import_react2.useState)(void 0);
104
+ const [transactionId, setTransactionId] = (0, import_react2.useState)(void 0);
105
+ const [transaction, setTransaction] = (0, import_react2.useState)(void 0);
106
+ const [stellarTransactionId, setStellarTransactionId] = (0, import_react2.useState)(void 0);
107
+ const [url, setUrl] = (0, import_react2.useState)(void 0);
108
+ const [error, setError] = (0, import_react2.useState)(void 0);
109
+ const phaseRef = (0, import_react2.useRef)("idle");
110
+ const subscriptionRef = (0, import_react2.useRef)(void 0);
111
+ const isMountedRef = (0, import_react2.useRef)(true);
112
+ const attemptIdRef = (0, import_react2.useRef)(0);
113
+ (0, import_react2.useEffect)(() => {
56
114
  phaseRef.current = phase;
57
115
  }, [phase]);
58
- const stopWatcher = (0, import_react.useCallback)(() => {
116
+ const stopWatcher = (0, import_react2.useCallback)(() => {
59
117
  if (subscriptionRef.current) {
60
118
  subscriptionRef.current.stop();
61
119
  subscriptionRef.current = void 0;
62
120
  }
63
121
  }, []);
64
- const reset = (0, import_react.useCallback)(() => {
122
+ const reset = (0, import_react2.useCallback)(() => {
123
+ attemptIdRef.current += 1;
65
124
  stopWatcher();
66
125
  phaseRef.current = "idle";
67
126
  if (isMountedRef.current) {
68
127
  setPhase("idle");
69
128
  setStatus(void 0);
70
129
  setTransactionId(void 0);
130
+ setTransaction(void 0);
131
+ setStellarTransactionId(void 0);
71
132
  setUrl(void 0);
72
133
  setError(void 0);
73
134
  }
74
135
  }, [stopWatcher]);
75
- const start = (0, import_react.useCallback)(
136
+ const start = (0, import_react2.useCallback)(
76
137
  async (amount) => {
77
138
  if (phaseRef.current !== "idle") {
78
139
  return void 0;
79
140
  }
141
+ const attemptId = ++attemptIdRef.current;
80
142
  phaseRef.current = "starting";
81
143
  if (isMountedRef.current) {
82
144
  setPhase("starting");
145
+ setTransaction(void 0);
146
+ setStellarTransactionId(void 0);
83
147
  setError(void 0);
84
148
  }
85
149
  let depositResult;
@@ -89,15 +153,16 @@ function usePayWithNaira({
89
153
  ...amount !== void 0 ? { amount } : {}
90
154
  });
91
155
  } catch (err) {
156
+ if (!isMountedRef.current || attemptId !== attemptIdRef.current) {
157
+ return void 0;
158
+ }
92
159
  const wrapped = ensureNairaRampError(err);
93
160
  phaseRef.current = "failed";
94
- if (isMountedRef.current) {
95
- setError(wrapped);
96
- setPhase("failed");
97
- }
161
+ setError(wrapped);
162
+ setPhase("failed");
98
163
  return void 0;
99
164
  }
100
- if (!isMountedRef.current) {
165
+ if (!isMountedRef.current || attemptId !== attemptIdRef.current) {
101
166
  return void 0;
102
167
  }
103
168
  const { id, url: hostedUrl } = depositResult;
@@ -107,13 +172,23 @@ function usePayWithNaira({
107
172
  setPhase("awaiting_user");
108
173
  stopWatcher();
109
174
  const subscription = ramp.watch(id, {
110
- onStatus: (nextStatus) => {
111
- if (!isMountedRef.current) return;
175
+ onStatus: (nextStatus, tx) => {
176
+ if (!isMountedRef.current || attemptId !== attemptIdRef.current) return;
112
177
  setStatus(nextStatus);
178
+ if (tx) {
179
+ setTransaction(tx);
180
+ if (tx.stellar_transaction_id) {
181
+ setStellarTransactionId(tx.stellar_transaction_id);
182
+ }
183
+ }
113
184
  if (nextStatus === "completed") {
185
+ stopWatcher();
114
186
  phaseRef.current = "completed";
115
187
  setPhase("completed");
116
- } else if (import_core.TERMINAL_STATUSES.includes(nextStatus)) {
188
+ } else if (import_core2.TERMINAL_STATUSES.includes(nextStatus)) {
189
+ stopWatcher();
190
+ const detail = tx?.message ? `Transaction ${nextStatus}: ${tx.message}` : `Transaction ${nextStatus}`;
191
+ setError(new import_core2.NairaRampError("TRANSACTION_FAILED", detail));
117
192
  phaseRef.current = "failed";
118
193
  setPhase("failed");
119
194
  } else if (nextStatus === "pending_user_transfer_start" || nextStatus === "incomplete") {
@@ -124,14 +199,22 @@ function usePayWithNaira({
124
199
  setPhase("processing");
125
200
  }
126
201
  },
127
- onComplete: () => {
128
- if (!isMountedRef.current) return;
202
+ onComplete: (tx) => {
203
+ if (!isMountedRef.current || attemptId !== attemptIdRef.current) return;
204
+ stopWatcher();
205
+ if (tx) {
206
+ setTransaction(tx);
207
+ if (tx.stellar_transaction_id) {
208
+ setStellarTransactionId(tx.stellar_transaction_id);
209
+ }
210
+ }
129
211
  setStatus("completed");
130
212
  phaseRef.current = "completed";
131
213
  setPhase("completed");
132
214
  },
133
215
  onError: (err) => {
134
- if (!isMountedRef.current) return;
216
+ if (!isMountedRef.current || attemptId !== attemptIdRef.current) return;
217
+ stopWatcher();
135
218
  const wrapped = ensureNairaRampError(err);
136
219
  setError(wrapped);
137
220
  phaseRef.current = "failed";
@@ -143,10 +226,11 @@ function usePayWithNaira({
143
226
  },
144
227
  [ramp, assetCode, stopWatcher]
145
228
  );
146
- (0, import_react.useEffect)(() => {
229
+ (0, import_react2.useEffect)(() => {
147
230
  isMountedRef.current = true;
148
231
  return () => {
149
232
  isMountedRef.current = false;
233
+ attemptIdRef.current += 1;
150
234
  stopWatcher();
151
235
  };
152
236
  }, [stopWatcher]);
@@ -155,6 +239,8 @@ function usePayWithNaira({
155
239
  phase,
156
240
  status,
157
241
  transactionId,
242
+ transaction,
243
+ stellarTransactionId,
158
244
  url,
159
245
  error,
160
246
  reset
@@ -162,10 +248,95 @@ function usePayWithNaira({
162
248
  }
163
249
 
164
250
  // 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 = {
251
+ var import_react5 = require("react");
252
+ var import_core3 = require("@nairaramp/core");
253
+
254
+ // src/theme.ts
255
+ var import_react3 = require("react");
256
+ var LIGHT_THEME = {
257
+ text: "#111827",
258
+ secondaryText: "#1f2937",
259
+ mutedText: "#4b5563",
260
+ pendingText: "#6b7280",
261
+ doneText: "#059669",
262
+ primaryBtnBg: "#059669",
263
+ primaryBtnText: "#ffffff",
264
+ disabledBtnBg: "#6b7280",
265
+ disabledBtnText: "#ffffff",
266
+ retryBtnBg: "#f3f4f6",
267
+ retryBtnText: "#1f2937",
268
+ retryBtnBorder: "#d1d5db",
269
+ errorText: "#b91c1c",
270
+ linkText: "#2563eb",
271
+ failureBg: "#fef2f2",
272
+ failureBorder: "#fee2e2",
273
+ failureTitle: "#991b1b",
274
+ activeBadgeBg: "#2563eb",
275
+ doneBadgeBg: "#059669",
276
+ activeOrDoneBadgeText: "#ffffff",
277
+ pendingBadgeBg: "#e5e7eb",
278
+ pendingBadgeText: "#374151",
279
+ focusPrimary: "#047857",
280
+ focusAccent: "#2563eb"
281
+ };
282
+ var DARK_THEME = {
283
+ text: "#f9fafb",
284
+ secondaryText: "#e5e7eb",
285
+ mutedText: "#d1d5db",
286
+ pendingText: "#9ca3af",
287
+ doneText: "#34d399",
288
+ primaryBtnBg: "#059669",
289
+ primaryBtnText: "#ffffff",
290
+ disabledBtnBg: "#4b5563",
291
+ disabledBtnText: "#ffffff",
292
+ retryBtnBg: "#1f2937",
293
+ retryBtnText: "#f9fafb",
294
+ retryBtnBorder: "#374151",
295
+ errorText: "#fca5a5",
296
+ linkText: "#60a5fa",
297
+ failureBg: "#450a0a",
298
+ failureBorder: "#7f1d1d",
299
+ failureTitle: "#fecaca",
300
+ activeBadgeBg: "#3b82f6",
301
+ doneBadgeBg: "#059669",
302
+ activeOrDoneBadgeText: "#ffffff",
303
+ pendingBadgeBg: "#374151",
304
+ pendingBadgeText: "#e5e7eb",
305
+ focusPrimary: "#34d399",
306
+ focusAccent: "#60a5fa"
307
+ };
308
+ function getSystemDarkPreference() {
309
+ if (typeof window === "undefined" || typeof window.matchMedia !== "function") {
310
+ return false;
311
+ }
312
+ return window.matchMedia("(prefers-color-scheme: dark)").matches;
313
+ }
314
+ function useResolvedTheme(theme = "system") {
315
+ const [systemDark, setSystemDark] = (0, import_react3.useState)(
316
+ () => theme === "system" ? getSystemDarkPreference() : false
317
+ );
318
+ (0, import_react3.useEffect)(() => {
319
+ if (theme !== "system" || typeof window === "undefined" || typeof window.matchMedia !== "function") {
320
+ return;
321
+ }
322
+ const mediaQuery = window.matchMedia("(prefers-color-scheme: dark)");
323
+ setSystemDark(mediaQuery.matches);
324
+ const handleChange = (event) => {
325
+ setSystemDark(event.matches);
326
+ };
327
+ mediaQuery.addEventListener("change", handleChange);
328
+ return () => {
329
+ mediaQuery.removeEventListener("change", handleChange);
330
+ };
331
+ }, [theme]);
332
+ if (theme === "dark") return DARK_THEME;
333
+ if (theme === "light") return LIGHT_THEME;
334
+ return systemDark ? DARK_THEME : LIGHT_THEME;
335
+ }
336
+
337
+ // src/useAnchorPopup.ts
338
+ var import_react4 = require("react");
339
+ var rampContainerStyle = {
169
340
  width: "100%",
170
341
  maxWidth: "420px",
171
342
  boxSizing: "border-box",
@@ -188,19 +359,19 @@ var baseButtonStyle = {
188
359
  display: "inline-block",
189
360
  transition: "outline 0.15s ease"
190
361
  };
191
- var primaryButtonStyle = {
362
+ var rampPrimaryButtonStyle = {
192
363
  ...baseButtonStyle,
193
364
  color: "#ffffff",
194
365
  backgroundColor: "#059669"
195
366
  };
196
- var disabledButtonStyle = {
367
+ var rampDisabledButtonStyle = {
197
368
  ...baseButtonStyle,
198
369
  color: "#ffffff",
199
370
  backgroundColor: "#9ca3af",
200
371
  cursor: "not-allowed",
201
372
  opacity: 0.8
202
373
  };
203
- var retryButtonStyle = {
374
+ var rampRetryButtonStyle = {
204
375
  ...baseButtonStyle,
205
376
  marginTop: "12px",
206
377
  padding: "10px 16px",
@@ -209,20 +380,20 @@ var retryButtonStyle = {
209
380
  backgroundColor: "#f3f4f6",
210
381
  border: "1px solid #d1d5db"
211
382
  };
212
- var statusTextStyle = {
383
+ var rampStatusTextStyle = {
213
384
  margin: "8px 0",
214
385
  fontSize: "16px",
215
386
  fontWeight: 500,
216
387
  color: "#1f2937"
217
388
  };
218
- var errorTextStyle = {
389
+ var rampErrorTextStyle = {
219
390
  margin: "8px 0",
220
391
  fontSize: "15px",
221
392
  fontWeight: 500,
222
393
  color: "#b91c1c",
223
394
  wordBreak: "break-word"
224
395
  };
225
- var linkStyle = {
396
+ var rampLinkStyle = {
226
397
  display: "inline-block",
227
398
  fontSize: "15px",
228
399
  fontWeight: 600,
@@ -231,34 +402,10 @@ var linkStyle = {
231
402
  wordBreak: "break-all",
232
403
  cursor: "pointer"
233
404
  };
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)(() => {
405
+ function useAnchorPopup() {
406
+ const [popupBlocked, setPopupBlocked] = (0, import_react4.useState)(false);
407
+ const popupRef = (0, import_react4.useRef)(null);
408
+ const closePopup = (0, import_react4.useCallback)(() => {
262
409
  if (popupRef.current && !popupRef.current.closed) {
263
410
  try {
264
411
  popupRef.current.close();
@@ -267,39 +414,102 @@ function PayWithNaira({
267
414
  popupRef.current = null;
268
415
  }
269
416
  }, []);
270
- const handleClick = (0, import_react2.useCallback)(async () => {
417
+ const openPopup = (0, import_react4.useCallback)(() => {
271
418
  setPopupBlocked(false);
272
419
  let popup = null;
273
- try {
274
- popup = window.open("", "nairaramp_anchor");
275
- } catch {
276
- popup = null;
420
+ if (typeof window !== "undefined" && typeof window.open === "function") {
421
+ try {
422
+ popup = window.open("", "nairaramp_anchor");
423
+ } catch {
424
+ popup = null;
425
+ }
277
426
  }
278
427
  popupRef.current = popup;
279
428
  if (!popup) {
280
429
  setPopupBlocked(true);
281
430
  }
282
- try {
283
- const result = await start(amount);
284
- if (result?.url) {
431
+ return popup;
432
+ }, []);
433
+ const navigatePopup = (0, import_react4.useCallback)(
434
+ (popup, targetUrl) => {
435
+ if (targetUrl && isSafeHttpUrl(targetUrl)) {
285
436
  if (popup && !popup.closed) {
286
- popup.location.href = result.url;
437
+ popup.location.href = targetUrl;
287
438
  }
288
439
  } else {
289
440
  closePopup();
290
441
  }
291
- } catch {
292
- closePopup();
293
- }
294
- }, [start, amount, closePopup]);
295
- const handleRetry = (0, import_react2.useCallback)(() => {
442
+ },
443
+ [closePopup]
444
+ );
445
+ const clearPopupBlocked = (0, import_react4.useCallback)(() => {
296
446
  setPopupBlocked(false);
447
+ }, []);
448
+ (0, import_react4.useEffect)(() => {
449
+ return () => {
450
+ closePopup();
451
+ };
452
+ }, [closePopup]);
453
+ return {
454
+ popupBlocked,
455
+ openPopup,
456
+ navigatePopup,
457
+ closePopup,
458
+ clearPopupBlocked
459
+ };
460
+ }
461
+
462
+ // src/PayWithNaira.tsx
463
+ var import_jsx_runtime2 = require("react/jsx-runtime");
464
+ function PayWithNaira({
465
+ ramp,
466
+ assetCode,
467
+ amount,
468
+ onComplete,
469
+ onError,
470
+ label = "Pay with Naira",
471
+ theme = "system",
472
+ className,
473
+ style
474
+ }) {
475
+ const tokens = useResolvedTheme(theme);
476
+ const { start, phase, error, url, reset } = usePayWithNaira({
477
+ ramp,
478
+ assetCode
479
+ });
480
+ const {
481
+ popupBlocked,
482
+ openPopup,
483
+ navigatePopup,
484
+ closePopup,
485
+ clearPopupBlocked
486
+ } = useAnchorPopup();
487
+ const [isPrimaryFocused, setIsPrimaryFocused] = (0, import_react5.useState)(false);
488
+ const [isRetryFocused, setIsRetryFocused] = (0, import_react5.useState)(false);
489
+ const [isLinkFocused, setIsLinkFocused] = (0, import_react5.useState)(false);
490
+ const onCompleteRef = (0, import_react5.useRef)(onComplete);
491
+ const onErrorRef = (0, import_react5.useRef)(onError);
492
+ const completedFiredRef = (0, import_react5.useRef)(false);
493
+ const errorFiredRef = (0, import_react5.useRef)(false);
494
+ (0, import_react5.useEffect)(() => {
495
+ onCompleteRef.current = onComplete;
496
+ }, [onComplete]);
497
+ (0, import_react5.useEffect)(() => {
498
+ onErrorRef.current = onError;
499
+ }, [onError]);
500
+ const handleClick = (0, import_react5.useCallback)(async () => {
501
+ const popup = openPopup();
502
+ const result = await start(amount);
503
+ navigatePopup(popup, result?.url);
504
+ }, [openPopup, start, amount, navigatePopup]);
505
+ const handleRetry = (0, import_react5.useCallback)(() => {
506
+ clearPopupBlocked();
297
507
  closePopup();
298
508
  completedFiredRef.current = false;
299
509
  errorFiredRef.current = false;
300
510
  reset();
301
- }, [reset, closePopup]);
302
- (0, import_react2.useEffect)(() => {
511
+ }, [clearPopupBlocked, closePopup, reset]);
512
+ (0, import_react5.useEffect)(() => {
303
513
  if (phase === "completed") {
304
514
  if (!completedFiredRef.current) {
305
515
  completedFiredRef.current = true;
@@ -309,7 +519,7 @@ function PayWithNaira({
309
519
  closePopup();
310
520
  if (!errorFiredRef.current) {
311
521
  errorFiredRef.current = true;
312
- const finalError = error ?? new import_core2.NairaRampError("TRANSACTION_FAILED", "Payment failed");
522
+ const finalError = error ?? new import_core3.NairaRampError("TRANSACTION_FAILED", "Payment failed");
313
523
  onErrorRef.current?.(finalError);
314
524
  }
315
525
  } else if (phase === "idle") {
@@ -317,8 +527,8 @@ function PayWithNaira({
317
527
  errorFiredRef.current = false;
318
528
  }
319
529
  }, [phase, error, closePopup]);
320
- return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: containerStyle, children: [
321
- phase === "idle" && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
530
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className, style: { ...rampContainerStyle, color: tokens.text, ...style }, children: [
531
+ phase === "idle" && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
322
532
  "button",
323
533
  {
324
534
  type: "button",
@@ -326,26 +536,32 @@ function PayWithNaira({
326
536
  onFocus: () => setIsPrimaryFocused(true),
327
537
  onBlur: () => setIsPrimaryFocused(false),
328
538
  style: {
329
- ...primaryButtonStyle,
330
- outline: isPrimaryFocused ? "3px solid #047857" : "2px solid transparent",
539
+ ...rampPrimaryButtonStyle,
540
+ color: tokens.primaryBtnText,
541
+ backgroundColor: tokens.primaryBtnBg,
542
+ outline: isPrimaryFocused ? `3px solid ${tokens.focusPrimary}` : "2px solid transparent",
331
543
  outlineOffset: "2px"
332
544
  },
333
545
  children: label
334
546
  }
335
547
  ),
336
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { "aria-live": "polite", "aria-atomic": "true", children: [
337
- phase === "starting" && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
548
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { "aria-live": "polite", "aria-atomic": "true", children: [
549
+ phase === "starting" && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
338
550
  "button",
339
551
  {
340
552
  type: "button",
341
553
  disabled: true,
342
- style: disabledButtonStyle,
554
+ style: {
555
+ ...rampDisabledButtonStyle,
556
+ color: tokens.disabledBtnText,
557
+ backgroundColor: tokens.disabledBtnBg
558
+ },
343
559
  children: "Connecting..."
344
560
  }
345
561
  ),
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)(
562
+ phase === "awaiting_user" && /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { children: [
563
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { style: { ...rampStatusTextStyle, color: tokens.secondaryText }, children: "Complete the steps in the anchor window" }),
564
+ popupBlocked && url && isSafeHttpUrl(url) && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { style: { margin: "8px 0 0 0" }, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
349
565
  "a",
350
566
  {
351
567
  href: url,
@@ -354,19 +570,20 @@ function PayWithNaira({
354
570
  onFocus: () => setIsLinkFocused(true),
355
571
  onBlur: () => setIsLinkFocused(false),
356
572
  style: {
357
- ...linkStyle,
358
- outline: isLinkFocused ? "2px solid #2563eb" : "2px solid transparent",
573
+ ...rampLinkStyle,
574
+ color: tokens.linkText,
575
+ outline: isLinkFocused ? `2px solid ${tokens.focusAccent}` : "2px solid transparent",
359
576
  outlineOffset: "2px"
360
577
  },
361
578
  children: "Continue to the anchor"
362
579
  }
363
580
  ) })
364
581
  ] }),
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)(
582
+ phase === "processing" && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { style: { ...rampStatusTextStyle, color: tokens.secondaryText }, children: "Processing your payment" }),
583
+ phase === "completed" && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { style: { ...rampStatusTextStyle, color: tokens.secondaryText }, children: "Payment completed" }),
584
+ phase === "failed" && /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { children: [
585
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { style: { ...rampErrorTextStyle, color: tokens.errorText }, children: error?.message ?? "Payment failed" }),
586
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
370
587
  "button",
371
588
  {
372
589
  type: "button",
@@ -374,8 +591,345 @@ function PayWithNaira({
374
591
  onFocus: () => setIsRetryFocused(true),
375
592
  onBlur: () => setIsRetryFocused(false),
376
593
  style: {
377
- ...retryButtonStyle,
378
- outline: isRetryFocused ? "2px solid #2563eb" : "2px solid transparent",
594
+ ...rampRetryButtonStyle,
595
+ color: tokens.retryBtnText,
596
+ backgroundColor: tokens.retryBtnBg,
597
+ border: `1px solid ${tokens.retryBtnBorder}`,
598
+ outline: isRetryFocused ? `2px solid ${tokens.focusAccent}` : "2px solid transparent",
599
+ outlineOffset: "2px"
600
+ },
601
+ children: "Try again"
602
+ }
603
+ )
604
+ ] })
605
+ ] })
606
+ ] });
607
+ }
608
+
609
+ // src/useCashOutToNaira.ts
610
+ var import_react6 = require("react");
611
+ var import_core4 = require("@nairaramp/core");
612
+ function useCashOutToNaira({
613
+ ramp: rampOption,
614
+ assetCode
615
+ }) {
616
+ const ramp = useNairaRamp(rampOption);
617
+ const [phase, setPhase] = (0, import_react6.useState)("idle");
618
+ const [status, setStatus] = (0, import_react6.useState)(void 0);
619
+ const [transactionId, setTransactionId] = (0, import_react6.useState)(void 0);
620
+ const [transaction, setTransaction] = (0, import_react6.useState)(void 0);
621
+ const [url, setUrl] = (0, import_react6.useState)(void 0);
622
+ const [txHash, setTxHash] = (0, import_react6.useState)(void 0);
623
+ const [error, setError] = (0, import_react6.useState)(void 0);
624
+ const phaseRef = (0, import_react6.useRef)("idle");
625
+ const subscriptionRef = (0, import_react6.useRef)(void 0);
626
+ const isMountedRef = (0, import_react6.useRef)(true);
627
+ const completionStartedRef = (0, import_react6.useRef)(false);
628
+ const attemptIdRef = (0, import_react6.useRef)(0);
629
+ (0, import_react6.useEffect)(() => {
630
+ phaseRef.current = phase;
631
+ }, [phase]);
632
+ const stopWatcher = (0, import_react6.useCallback)(() => {
633
+ if (subscriptionRef.current) {
634
+ subscriptionRef.current.stop();
635
+ subscriptionRef.current = void 0;
636
+ }
637
+ }, []);
638
+ const reset = (0, import_react6.useCallback)(() => {
639
+ attemptIdRef.current += 1;
640
+ stopWatcher();
641
+ phaseRef.current = "idle";
642
+ completionStartedRef.current = false;
643
+ if (isMountedRef.current) {
644
+ setPhase("idle");
645
+ setStatus(void 0);
646
+ setTransactionId(void 0);
647
+ setTransaction(void 0);
648
+ setUrl(void 0);
649
+ setTxHash(void 0);
650
+ setError(void 0);
651
+ }
652
+ }, [stopWatcher]);
653
+ const start = (0, import_react6.useCallback)(
654
+ async (amount) => {
655
+ if (phaseRef.current !== "idle") {
656
+ return void 0;
657
+ }
658
+ const attemptId = ++attemptIdRef.current;
659
+ completionStartedRef.current = false;
660
+ phaseRef.current = "starting";
661
+ if (isMountedRef.current) {
662
+ setPhase("starting");
663
+ setTransaction(void 0);
664
+ setError(void 0);
665
+ setTxHash(void 0);
666
+ }
667
+ let withdrawResult;
668
+ try {
669
+ withdrawResult = await ramp.withdraw({
670
+ assetCode,
671
+ ...amount !== void 0 ? { amount } : {}
672
+ });
673
+ } catch (err) {
674
+ if (!isMountedRef.current || attemptId !== attemptIdRef.current) {
675
+ return void 0;
676
+ }
677
+ const wrapped = ensureNairaRampError(err);
678
+ phaseRef.current = "failed";
679
+ setError(wrapped);
680
+ setPhase("failed");
681
+ return void 0;
682
+ }
683
+ if (!isMountedRef.current || attemptId !== attemptIdRef.current) {
684
+ return void 0;
685
+ }
686
+ const { id, url: hostedUrl } = withdrawResult;
687
+ setTransactionId(id);
688
+ setUrl(hostedUrl);
689
+ phaseRef.current = "awaiting_user";
690
+ setPhase("awaiting_user");
691
+ stopWatcher();
692
+ const subscription = ramp.watch(id, {
693
+ onStatus: (nextStatus, tx) => {
694
+ if (!isMountedRef.current || attemptId !== attemptIdRef.current) return;
695
+ setStatus(nextStatus);
696
+ if (tx) {
697
+ setTransaction(tx);
698
+ if (tx.stellar_transaction_id) {
699
+ setTxHash((prev) => prev ?? tx.stellar_transaction_id);
700
+ }
701
+ }
702
+ if (nextStatus === "completed") {
703
+ stopWatcher();
704
+ phaseRef.current = "completed";
705
+ setPhase("completed");
706
+ return;
707
+ }
708
+ if (import_core4.TERMINAL_STATUSES.includes(nextStatus)) {
709
+ stopWatcher();
710
+ const detail = tx?.message ? `Transaction ${nextStatus}: ${tx.message}` : `Transaction ${nextStatus}`;
711
+ setError(new import_core4.NairaRampError("TRANSACTION_FAILED", detail));
712
+ phaseRef.current = "failed";
713
+ setPhase("failed");
714
+ return;
715
+ }
716
+ if (nextStatus === "pending_user_transfer_start") {
717
+ if (!completionStartedRef.current) {
718
+ completionStartedRef.current = true;
719
+ phaseRef.current = "completing";
720
+ setPhase("completing");
721
+ ramp.completeWithdrawal(id).then(({ hash }) => {
722
+ if (!isMountedRef.current || attemptId !== attemptIdRef.current) return;
723
+ setTxHash(hash);
724
+ if (phaseRef.current === "completing") {
725
+ phaseRef.current = "processing";
726
+ setPhase("processing");
727
+ }
728
+ }).catch((err) => {
729
+ if (!isMountedRef.current || attemptId !== attemptIdRef.current) return;
730
+ stopWatcher();
731
+ setError(ensureNairaRampError(err));
732
+ phaseRef.current = "failed";
733
+ setPhase("failed");
734
+ });
735
+ }
736
+ return;
737
+ }
738
+ if (nextStatus === "incomplete" || nextStatus === "pending_user") {
739
+ phaseRef.current = "awaiting_user";
740
+ setPhase("awaiting_user");
741
+ } else {
742
+ phaseRef.current = "processing";
743
+ setPhase("processing");
744
+ }
745
+ },
746
+ onComplete: (tx) => {
747
+ if (!isMountedRef.current || attemptId !== attemptIdRef.current) return;
748
+ stopWatcher();
749
+ if (tx) {
750
+ setTransaction(tx);
751
+ if (tx.stellar_transaction_id) {
752
+ setTxHash((prev) => prev ?? tx.stellar_transaction_id);
753
+ }
754
+ }
755
+ setStatus("completed");
756
+ phaseRef.current = "completed";
757
+ setPhase("completed");
758
+ },
759
+ onError: (err) => {
760
+ if (!isMountedRef.current || attemptId !== attemptIdRef.current) return;
761
+ stopWatcher();
762
+ setError(ensureNairaRampError(err));
763
+ phaseRef.current = "failed";
764
+ setPhase("failed");
765
+ }
766
+ });
767
+ subscriptionRef.current = subscription;
768
+ return withdrawResult;
769
+ },
770
+ [ramp, assetCode, stopWatcher]
771
+ );
772
+ (0, import_react6.useEffect)(() => {
773
+ isMountedRef.current = true;
774
+ return () => {
775
+ isMountedRef.current = false;
776
+ attemptIdRef.current += 1;
777
+ stopWatcher();
778
+ };
779
+ }, [stopWatcher]);
780
+ return {
781
+ start,
782
+ phase,
783
+ status,
784
+ transactionId,
785
+ transaction,
786
+ url,
787
+ txHash,
788
+ error,
789
+ reset
790
+ };
791
+ }
792
+
793
+ // src/CashOutToNaira.tsx
794
+ var import_react7 = require("react");
795
+ var import_core5 = require("@nairaramp/core");
796
+ var import_jsx_runtime3 = require("react/jsx-runtime");
797
+ function CashOutToNaira({
798
+ ramp,
799
+ assetCode,
800
+ amount,
801
+ onComplete,
802
+ onError,
803
+ label = "Cash out to Naira",
804
+ theme = "system",
805
+ className,
806
+ style
807
+ }) {
808
+ const tokens = useResolvedTheme(theme);
809
+ const { start, phase, error, url, txHash, reset } = useCashOutToNaira({
810
+ ramp,
811
+ assetCode
812
+ });
813
+ const {
814
+ popupBlocked,
815
+ openPopup,
816
+ navigatePopup,
817
+ closePopup,
818
+ clearPopupBlocked
819
+ } = useAnchorPopup();
820
+ const [isPrimaryFocused, setIsPrimaryFocused] = (0, import_react7.useState)(false);
821
+ const [isRetryFocused, setIsRetryFocused] = (0, import_react7.useState)(false);
822
+ const [isLinkFocused, setIsLinkFocused] = (0, import_react7.useState)(false);
823
+ const onCompleteRef = (0, import_react7.useRef)(onComplete);
824
+ const onErrorRef = (0, import_react7.useRef)(onError);
825
+ const completedFiredRef = (0, import_react7.useRef)(false);
826
+ const errorFiredRef = (0, import_react7.useRef)(false);
827
+ (0, import_react7.useEffect)(() => {
828
+ onCompleteRef.current = onComplete;
829
+ }, [onComplete]);
830
+ (0, import_react7.useEffect)(() => {
831
+ onErrorRef.current = onError;
832
+ }, [onError]);
833
+ const handleClick = (0, import_react7.useCallback)(async () => {
834
+ const popup = openPopup();
835
+ const result = await start(amount);
836
+ navigatePopup(popup, result?.url);
837
+ }, [openPopup, start, amount, navigatePopup]);
838
+ const handleRetry = (0, import_react7.useCallback)(() => {
839
+ clearPopupBlocked();
840
+ closePopup();
841
+ completedFiredRef.current = false;
842
+ errorFiredRef.current = false;
843
+ reset();
844
+ }, [clearPopupBlocked, closePopup, reset]);
845
+ (0, import_react7.useEffect)(() => {
846
+ if (phase === "completed") {
847
+ if (!completedFiredRef.current) {
848
+ completedFiredRef.current = true;
849
+ onCompleteRef.current?.(txHash);
850
+ }
851
+ } else if (phase === "failed") {
852
+ closePopup();
853
+ if (!errorFiredRef.current) {
854
+ errorFiredRef.current = true;
855
+ const finalError = error ?? new import_core5.NairaRampError("TRANSACTION_FAILED", "Cash out failed");
856
+ onErrorRef.current?.(finalError);
857
+ }
858
+ } else if (phase === "idle") {
859
+ completedFiredRef.current = false;
860
+ errorFiredRef.current = false;
861
+ }
862
+ }, [phase, error, txHash, closePopup]);
863
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className, style: { ...rampContainerStyle, color: tokens.text, ...style }, children: [
864
+ phase === "idle" && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
865
+ "button",
866
+ {
867
+ type: "button",
868
+ onClick: handleClick,
869
+ onFocus: () => setIsPrimaryFocused(true),
870
+ onBlur: () => setIsPrimaryFocused(false),
871
+ style: {
872
+ ...rampPrimaryButtonStyle,
873
+ color: tokens.primaryBtnText,
874
+ backgroundColor: tokens.primaryBtnBg,
875
+ outline: isPrimaryFocused ? `3px solid ${tokens.focusPrimary}` : "2px solid transparent",
876
+ outlineOffset: "2px"
877
+ },
878
+ children: label
879
+ }
880
+ ),
881
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { "aria-live": "polite", "aria-atomic": "true", children: [
882
+ phase === "starting" && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
883
+ "button",
884
+ {
885
+ type: "button",
886
+ disabled: true,
887
+ style: {
888
+ ...rampDisabledButtonStyle,
889
+ color: tokens.disabledBtnText,
890
+ backgroundColor: tokens.disabledBtnBg
891
+ },
892
+ children: "Connecting..."
893
+ }
894
+ ),
895
+ phase === "awaiting_user" && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { children: [
896
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { style: { ...rampStatusTextStyle, color: tokens.secondaryText }, children: "Complete the steps in the anchor window" }),
897
+ popupBlocked && url && isSafeHttpUrl(url) && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { style: { margin: "8px 0 0 0" }, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
898
+ "a",
899
+ {
900
+ href: url,
901
+ target: "_blank",
902
+ rel: "noopener noreferrer",
903
+ onFocus: () => setIsLinkFocused(true),
904
+ onBlur: () => setIsLinkFocused(false),
905
+ style: {
906
+ ...rampLinkStyle,
907
+ color: tokens.linkText,
908
+ outline: isLinkFocused ? `2px solid ${tokens.focusAccent}` : "2px solid transparent",
909
+ outlineOffset: "2px"
910
+ },
911
+ children: "Continue to the anchor"
912
+ }
913
+ ) })
914
+ ] }),
915
+ phase === "completing" && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { style: { ...rampStatusTextStyle, color: tokens.secondaryText }, children: "Submitting Stellar transfer..." }),
916
+ phase === "processing" && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { style: { ...rampStatusTextStyle, color: tokens.secondaryText }, children: "Processing your cash out" }),
917
+ phase === "completed" && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { style: { ...rampStatusTextStyle, color: tokens.secondaryText }, children: "Cash out completed" }),
918
+ phase === "failed" && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { children: [
919
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { style: { ...rampErrorTextStyle, color: tokens.errorText }, children: error?.message ?? "Cash out failed" }),
920
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
921
+ "button",
922
+ {
923
+ type: "button",
924
+ onClick: handleRetry,
925
+ onFocus: () => setIsRetryFocused(true),
926
+ onBlur: () => setIsRetryFocused(false),
927
+ style: {
928
+ ...rampRetryButtonStyle,
929
+ color: tokens.retryBtnText,
930
+ backgroundColor: tokens.retryBtnBg,
931
+ border: `1px solid ${tokens.retryBtnBorder}`,
932
+ outline: isRetryFocused ? `2px solid ${tokens.focusAccent}` : "2px solid transparent",
379
933
  outlineOffset: "2px"
380
934
  },
381
935
  children: "Try again"
@@ -387,7 +941,7 @@ function PayWithNaira({
387
941
  }
388
942
 
389
943
  // src/StatusTimeline.tsx
390
- var import_jsx_runtime2 = require("react/jsx-runtime");
944
+ var import_jsx_runtime4 = require("react/jsx-runtime");
391
945
  var TIMELINE_STEPS = [
392
946
  "Started",
393
947
  "Waiting for your payment",
@@ -396,6 +950,38 @@ var TIMELINE_STEPS = [
396
950
  "Sending on Stellar",
397
951
  "Completed"
398
952
  ];
953
+ var YORUBA_LABELS = {
954
+ Started: "B\u1EB9r\u1EB9",
955
+ "Waiting for your payment": "Nduro de owo r\u1EB9",
956
+ "Payment received": "A ti gba owo",
957
+ "Anchor processing": "Anchor n \u1E63i\u1E63\u1EB9 lori r\u1EB9",
958
+ "Sending on Stellar": "Nfi ran\u1E63\u1EB9 lori Stellar",
959
+ Completed: "Pari"
960
+ };
961
+ var HAUSA_LABELS = {
962
+ Started: "An fara",
963
+ "Waiting for your payment": "Ana jiran biyan ku",
964
+ "Payment received": "An kar\u0253i biya",
965
+ "Anchor processing": "Anchor yana sarrafawa",
966
+ "Sending on Stellar": "Ana aikawa ta Stellar",
967
+ Completed: "An kammala"
968
+ };
969
+ var IGBO_LABELS = {
970
+ Started: "Amalitela",
971
+ "Waiting for your payment": "Na-eche ugwo gi",
972
+ "Payment received": "Anatala ugwo",
973
+ "Anchor processing": "Anchor na-ar\u1EE5 \u1ECDr\u1EE5",
974
+ "Sending on Stellar": "Na-eziga na Stellar",
975
+ Completed: "Emechala"
976
+ };
977
+ var PIDGIN_LABELS = {
978
+ Started: "Don start",
979
+ "Waiting for your payment": "Dey wait for your money",
980
+ "Payment received": "We don collect the money",
981
+ "Anchor processing": "Anchor dey process am",
982
+ "Sending on Stellar": "Dey send am on Stellar",
983
+ Completed: "Don finish"
984
+ };
399
985
  var STATUS_MAP = {
400
986
  incomplete: {
401
987
  kind: "step",
@@ -467,7 +1053,7 @@ var STATUS_MAP = {
467
1053
  label: "Error"
468
1054
  }
469
1055
  };
470
- var containerStyle2 = {
1056
+ var containerStyle = {
471
1057
  width: "100%",
472
1058
  maxWidth: "420px",
473
1059
  boxSizing: "border-box",
@@ -485,7 +1071,7 @@ var listStyle = {
485
1071
  gap: "12px"
486
1072
  };
487
1073
  var failureContainerStyle = {
488
- ...containerStyle2,
1074
+ ...containerStyle,
489
1075
  padding: "16px",
490
1076
  borderRadius: "8px",
491
1077
  backgroundColor: "#fef2f2",
@@ -503,25 +1089,57 @@ var messageTextStyle = {
503
1089
  fontSize: "14px",
504
1090
  color: "#4b5563"
505
1091
  };
1092
+ function resolveStatusMapping(status) {
1093
+ if (status === void 0) {
1094
+ return {
1095
+ kind: "step",
1096
+ stepIndex: 0,
1097
+ label: "Started"
1098
+ };
1099
+ }
1100
+ if (Object.prototype.hasOwnProperty.call(STATUS_MAP, status)) {
1101
+ return STATUS_MAP[status];
1102
+ }
1103
+ return {
1104
+ kind: "failure",
1105
+ label: "Unknown status"
1106
+ };
1107
+ }
506
1108
  function StatusTimeline({
507
1109
  status,
508
1110
  message,
509
- labels
1111
+ labels,
1112
+ failureLabels,
1113
+ theme = "system",
1114
+ className,
1115
+ style
510
1116
  }) {
511
- const mapping = status !== void 0 ? STATUS_MAP[status] : {
512
- kind: "step",
513
- stepIndex: 0,
514
- label: "Started"
515
- };
1117
+ const tokens = useResolvedTheme(theme);
1118
+ const mapping = resolveStatusMapping(status);
516
1119
  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
- ] });
1120
+ const failureText = failureLabels?.[mapping.label] ?? mapping.label;
1121
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
1122
+ "div",
1123
+ {
1124
+ className,
1125
+ style: {
1126
+ ...failureContainerStyle,
1127
+ color: tokens.text,
1128
+ backgroundColor: tokens.failureBg,
1129
+ border: `1px solid ${tokens.failureBorder}`,
1130
+ ...style
1131
+ },
1132
+ role: "alert",
1133
+ children: [
1134
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("p", { style: { ...failureTitleStyle, color: tokens.failureTitle }, children: failureText }),
1135
+ message && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("p", { style: { ...messageTextStyle, color: tokens.mutedText }, children: message })
1136
+ ]
1137
+ }
1138
+ );
521
1139
  }
522
1140
  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) => {
1141
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className, style: { ...containerStyle, color: tokens.text, ...style }, children: [
1142
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("ol", { style: listStyle, "aria-label": "Payment status timeline", children: TIMELINE_STEPS.map((step, index) => {
525
1143
  const isDone = index < activeIndex;
526
1144
  const isActive = index === activeIndex;
527
1145
  const displayLabel = labels?.[step] ?? step;
@@ -529,7 +1147,7 @@ function StatusTimeline({
529
1147
  display: "flex",
530
1148
  alignItems: "center",
531
1149
  gap: "12px",
532
- color: isActive ? "#111827" : isDone ? "#059669" : "#9ca3af",
1150
+ color: isActive ? tokens.text : isDone ? tokens.doneText : tokens.pendingText,
533
1151
  fontWeight: isActive ? 600 : isDone ? 500 : 400
534
1152
  };
535
1153
  const badgeStyle = {
@@ -542,34 +1160,211 @@ function StatusTimeline({
542
1160
  fontSize: "12px",
543
1161
  fontWeight: 700,
544
1162
  boxSizing: "border-box",
545
- backgroundColor: isActive ? "#2563eb" : isDone ? "#059669" : "#e5e7eb",
546
- color: isActive || isDone ? "#ffffff" : "#6b7280"
1163
+ backgroundColor: isActive ? tokens.activeBadgeBg : isDone ? tokens.doneBadgeBg : tokens.pendingBadgeBg,
1164
+ color: isActive || isDone ? tokens.activeOrDoneBadgeText : tokens.pendingBadgeText
547
1165
  };
548
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
1166
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
549
1167
  "li",
550
1168
  {
551
1169
  "aria-current": isActive ? "step" : void 0,
552
1170
  style: itemStyle,
553
1171
  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 })
1172
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { style: badgeStyle, "aria-hidden": "true", children: isDone ? "\u2713" : index + 1 }),
1173
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { children: displayLabel })
556
1174
  ]
557
1175
  },
558
1176
  step
559
1177
  );
560
1178
  }) }),
561
- message && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { style: messageTextStyle, children: message })
1179
+ message && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("p", { style: { ...messageTextStyle, color: tokens.mutedText }, children: message })
562
1180
  ] });
563
1181
  }
564
1182
 
1183
+ // src/useRampQuote.ts
1184
+ var import_react8 = require("react");
1185
+ var import_core6 = require("@nairaramp/core");
1186
+ function toQuoteError(err) {
1187
+ if ((0, import_core6.isNairaRampError)(err)) {
1188
+ return err;
1189
+ }
1190
+ const message = err instanceof Error ? err.message : String(err);
1191
+ return new import_core6.NairaRampError("QUOTE_UNAVAILABLE", message, { cause: err });
1192
+ }
1193
+ function useRampQuote({
1194
+ ramp: rampOption,
1195
+ sellAsset,
1196
+ buyAsset,
1197
+ sellAmount,
1198
+ buyAmount,
1199
+ context,
1200
+ debounceMs = 300,
1201
+ pollIntervalMs,
1202
+ enabled = true
1203
+ }) {
1204
+ const ramp = useNairaRamp(rampOption);
1205
+ const [quote, setQuote] = (0, import_react8.useState)(void 0);
1206
+ const [loading, setLoading] = (0, import_react8.useState)(false);
1207
+ const [error, setError] = (0, import_react8.useState)(void 0);
1208
+ const isMountedRef = (0, import_react8.useRef)(true);
1209
+ const requestIdRef = (0, import_react8.useRef)(0);
1210
+ const hasAmount = sellAmount !== void 0 && sellAmount.trim() !== "" || buyAmount !== void 0 && buyAmount.trim() !== "";
1211
+ const fetchQuote = (0, import_react8.useCallback)(async () => {
1212
+ if (!enabled || !hasAmount) {
1213
+ return;
1214
+ }
1215
+ const reqId = ++requestIdRef.current;
1216
+ if (isMountedRef.current) {
1217
+ setLoading(true);
1218
+ setError(void 0);
1219
+ }
1220
+ const options = {
1221
+ sellAsset,
1222
+ buyAsset,
1223
+ ...sellAmount !== void 0 && sellAmount.trim() !== "" ? { sellAmount } : {},
1224
+ ...buyAmount !== void 0 && buyAmount.trim() !== "" ? { buyAmount } : {},
1225
+ ...context !== void 0 ? { context } : {}
1226
+ };
1227
+ try {
1228
+ const nextQuote = await ramp.getPrice(options);
1229
+ if (!isMountedRef.current || reqId !== requestIdRef.current) {
1230
+ return;
1231
+ }
1232
+ setQuote(nextQuote);
1233
+ setError(void 0);
1234
+ } catch (err) {
1235
+ if (!isMountedRef.current || reqId !== requestIdRef.current) {
1236
+ return;
1237
+ }
1238
+ setError(toQuoteError(err));
1239
+ } finally {
1240
+ if (isMountedRef.current && reqId === requestIdRef.current) {
1241
+ setLoading(false);
1242
+ }
1243
+ }
1244
+ }, [ramp, sellAsset, buyAsset, sellAmount, buyAmount, context, enabled, hasAmount]);
1245
+ (0, import_react8.useEffect)(() => {
1246
+ isMountedRef.current = true;
1247
+ return () => {
1248
+ isMountedRef.current = false;
1249
+ };
1250
+ }, []);
1251
+ (0, import_react8.useEffect)(() => {
1252
+ if (!enabled || !hasAmount) {
1253
+ requestIdRef.current++;
1254
+ setQuote(void 0);
1255
+ setError(void 0);
1256
+ setLoading(false);
1257
+ return;
1258
+ }
1259
+ const delay = Math.max(0, debounceMs);
1260
+ const debounceTimer = setTimeout(() => {
1261
+ void fetchQuote();
1262
+ }, delay);
1263
+ return () => {
1264
+ clearTimeout(debounceTimer);
1265
+ };
1266
+ }, [enabled, hasAmount, debounceMs, fetchQuote]);
1267
+ (0, import_react8.useEffect)(() => {
1268
+ if (!enabled || !hasAmount || !pollIntervalMs || pollIntervalMs <= 0) {
1269
+ return;
1270
+ }
1271
+ const interval = setInterval(() => {
1272
+ void fetchQuote();
1273
+ }, pollIntervalMs);
1274
+ return () => {
1275
+ clearInterval(interval);
1276
+ };
1277
+ }, [enabled, hasAmount, pollIntervalMs, fetchQuote]);
1278
+ return {
1279
+ quote,
1280
+ loading,
1281
+ error,
1282
+ refresh: fetchQuote
1283
+ };
1284
+ }
1285
+
1286
+ // src/useAnchors.ts
1287
+ var import_react9 = require("react");
1288
+ var import_core7 = require("@nairaramp/core");
1289
+ function useAnchors(options = {}) {
1290
+ const { network, country, assetCode, sep } = options;
1291
+ const anchors = (0, import_react9.useMemo)(() => {
1292
+ const coreFilter = network !== void 0 || country !== void 0 ? {
1293
+ ...network !== void 0 ? { network } : {},
1294
+ ...country !== void 0 ? { country } : {}
1295
+ } : void 0;
1296
+ const baseAnchors = (0, import_core7.listAnchors)(coreFilter);
1297
+ return baseAnchors.filter((anchor) => {
1298
+ if (assetCode !== void 0 && !anchor.assets.some(
1299
+ (asset) => asset.code.toUpperCase() === assetCode.toUpperCase()
1300
+ )) {
1301
+ return false;
1302
+ }
1303
+ if (sep !== void 0 && !anchor.seps.includes(sep)) {
1304
+ return false;
1305
+ }
1306
+ return true;
1307
+ });
1308
+ }, [network, country, assetCode, sep]);
1309
+ const getAnchorById = (0, import_react9.useCallback)(
1310
+ (id) => anchors.find((anchor) => anchor.id === id),
1311
+ [anchors]
1312
+ );
1313
+ return { anchors, getAnchorById };
1314
+ }
1315
+
1316
+ // src/errorMessages.ts
1317
+ var ERROR_MESSAGES = {
1318
+ AUTH_FAILED: "Authentication with the anchor failed. Please try signing in again.",
1319
+ ANCHOR_UNREACHABLE: "Could not reach the anchor server. Check your connection and try again.",
1320
+ ANCHOR_NOT_FOUND: "The selected Stellar anchor is not recognized.",
1321
+ KYC_REQUIRED: "Identity verification (KYC) is required by the anchor before continuing.",
1322
+ QUOTE_EXPIRED: "Your exchange rate quote expired. Request a fresh quote to continue.",
1323
+ QUOTE_UNAVAILABLE: "Exchange rate quote is currently unavailable for this pair or amount.",
1324
+ UNSUPPORTED_ASSET: "This Stellar asset is not supported by the selected anchor.",
1325
+ SIGNER_REJECTED: "Wallet signature was cancelled or rejected.",
1326
+ TRANSACTION_FAILED: "The transaction could not be completed. Please try again.",
1327
+ MAINNET_NOT_ALLOWED: "Mainnet transactions are disabled in the current configuration.",
1328
+ ANCHOR_NOT_VERIFIED: "This anchor's mainnet verification is outdated and cannot be used."
1329
+ };
1330
+ function getErrorMessage(error, overrides) {
1331
+ if (!error) {
1332
+ return void 0;
1333
+ }
1334
+ const code = error.code;
1335
+ if (overrides && Object.prototype.hasOwnProperty.call(overrides, code)) {
1336
+ const custom = overrides[code];
1337
+ if (custom !== void 0) {
1338
+ return custom;
1339
+ }
1340
+ }
1341
+ if (Object.prototype.hasOwnProperty.call(ERROR_MESSAGES, code)) {
1342
+ return ERROR_MESSAGES[code];
1343
+ }
1344
+ return error.message;
1345
+ }
1346
+
565
1347
  // src/index.ts
566
- var VERSION = "0.1.0";
1348
+ var VERSION = "0.2.0";
567
1349
  // Annotate the CommonJS export names for ESM import in node:
568
1350
  0 && (module.exports = {
1351
+ CashOutToNaira,
1352
+ ERROR_MESSAGES,
1353
+ HAUSA_LABELS,
1354
+ IGBO_LABELS,
1355
+ NairaRampProvider,
1356
+ PIDGIN_LABELS,
569
1357
  PayWithNaira,
570
1358
  STATUS_MAP,
571
1359
  StatusTimeline,
572
1360
  TIMELINE_STEPS,
573
1361
  VERSION,
574
- usePayWithNaira
1362
+ YORUBA_LABELS,
1363
+ getErrorMessage,
1364
+ getStellarExplorerUrl,
1365
+ useAnchors,
1366
+ useCashOutToNaira,
1367
+ useNairaRamp,
1368
+ usePayWithNaira,
1369
+ useRampQuote
575
1370
  });