@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.d.cts CHANGED
@@ -1,9 +1,25 @@
1
- import { Ramp, TransactionStatus, NairaRampError } from '@nairaramp/core';
2
- import { ReactElement } from 'react';
1
+ import { ReactNode, ReactElement, CSSProperties } from 'react';
2
+ import { Ramp, TransactionStatus, AnchorTransaction, NairaRampError, Quote, AnchorEntry, ListAnchorsFilter, NairaRampErrorCode } from '@nairaramp/core';
3
+
4
+ type ThemeMode = "light" | "dark" | "system";
5
+
6
+ interface NairaRampProviderProps {
7
+ ramp: Ramp;
8
+ children: ReactNode;
9
+ }
10
+ /**
11
+ * Provides a `@nairaramp/core` `Ramp` instance to descendant hooks and components
12
+ * so callers do not need to thread `ramp` through every component prop.
13
+ */
14
+ declare function NairaRampProvider({ ramp, children, }: NairaRampProviderProps): ReactElement;
15
+ /**
16
+ * Resolves a `Ramp` instance from an explicit override or the nearest `NairaRampProvider`.
17
+ */
18
+ declare function useNairaRamp(overrideRamp?: Ramp): Ramp;
3
19
 
4
20
  type PayWithNairaPhase = "idle" | "starting" | "awaiting_user" | "processing" | "completed" | "failed";
5
21
  interface UsePayWithNairaOptions {
6
- ramp: Ramp;
22
+ ramp?: Ramp;
7
23
  assetCode: string;
8
24
  }
9
25
  interface UsePayWithNairaResult {
@@ -14,43 +30,144 @@ interface UsePayWithNairaResult {
14
30
  phase: PayWithNairaPhase;
15
31
  status: TransactionStatus | string | undefined;
16
32
  transactionId: string | undefined;
33
+ transaction: AnchorTransaction | undefined;
34
+ stellarTransactionId: string | undefined;
17
35
  url: string | undefined;
18
36
  error: NairaRampError | undefined;
19
37
  reset: () => void;
20
38
  }
21
- declare function usePayWithNaira({ ramp, assetCode, }: UsePayWithNairaOptions): UsePayWithNairaResult;
39
+ declare function usePayWithNaira({ ramp: rampOption, assetCode, }: UsePayWithNairaOptions): UsePayWithNairaResult;
22
40
 
23
41
  interface PayWithNairaProps {
24
- ramp: Ramp;
42
+ ramp?: Ramp;
25
43
  assetCode: string;
26
44
  amount?: string;
27
45
  onComplete?: () => void;
28
46
  onError?: (error: NairaRampError) => void;
29
47
  label?: string;
48
+ theme?: ThemeMode;
49
+ className?: string;
50
+ style?: CSSProperties;
30
51
  }
31
- declare function PayWithNaira({ ramp, assetCode, amount, onComplete, onError, label, }: PayWithNairaProps): ReactElement;
52
+ declare function PayWithNaira({ ramp, assetCode, amount, onComplete, onError, label, theme, className, style, }: PayWithNairaProps): ReactElement;
53
+
54
+ type CashOutToNairaPhase = "idle" | "starting" | "awaiting_user" | "completing" | "processing" | "completed" | "failed";
55
+ interface UseCashOutToNairaOptions {
56
+ ramp?: Ramp;
57
+ assetCode: string;
58
+ }
59
+ interface UseCashOutToNairaResult {
60
+ start: (amount?: string) => Promise<{
61
+ id: string;
62
+ url: string;
63
+ } | undefined>;
64
+ phase: CashOutToNairaPhase;
65
+ status: TransactionStatus | string | undefined;
66
+ transactionId: string | undefined;
67
+ transaction: AnchorTransaction | undefined;
68
+ url: string | undefined;
69
+ txHash: string | undefined;
70
+ error: NairaRampError | undefined;
71
+ reset: () => void;
72
+ }
73
+ declare function useCashOutToNaira({ ramp: rampOption, assetCode, }: UseCashOutToNairaOptions): UseCashOutToNairaResult;
74
+
75
+ interface CashOutToNairaProps {
76
+ ramp?: Ramp;
77
+ assetCode: string;
78
+ amount?: string;
79
+ onComplete?: (txHash?: string) => void;
80
+ onError?: (error: NairaRampError) => void;
81
+ label?: string;
82
+ theme?: ThemeMode;
83
+ className?: string;
84
+ style?: CSSProperties;
85
+ }
86
+ declare function CashOutToNaira({ ramp, assetCode, amount, onComplete, onError, label, theme, className, style, }: CashOutToNairaProps): ReactElement;
32
87
 
33
88
  type TimelineStep = "Started" | "Waiting for your payment" | "Payment received" | "Anchor processing" | "Sending on Stellar" | "Completed";
34
89
  declare const TIMELINE_STEPS: readonly TimelineStep[];
90
+ declare const YORUBA_LABELS: Record<TimelineStep, string>;
91
+ declare const HAUSA_LABELS: Record<TimelineStep, string>;
92
+ declare const IGBO_LABELS: Record<TimelineStep, string>;
93
+ declare const PIDGIN_LABELS: Record<TimelineStep, string>;
35
94
  interface StepStatusMapping {
36
95
  kind: "step";
37
96
  stepIndex: number;
38
97
  label: TimelineStep;
39
98
  }
99
+ type FailureStatusLabel = "Refunded" | "Expired" | "No market" | "Too small" | "Too large" | "Error" | "Unknown status";
40
100
  interface FailureStatusMapping {
41
101
  kind: "failure";
42
- label: string;
102
+ label: FailureStatusLabel;
43
103
  }
44
104
  type StatusMapping = StepStatusMapping | FailureStatusMapping;
45
105
  declare const STATUS_MAP: Record<TransactionStatus, StatusMapping>;
46
106
  interface StatusTimelineProps {
47
- status: TransactionStatus | undefined;
107
+ status: TransactionStatus | string | undefined;
48
108
  message?: string;
49
109
  labels?: Partial<Record<TimelineStep, string>>;
110
+ failureLabels?: Partial<Record<FailureStatusLabel, string>>;
111
+ theme?: ThemeMode;
112
+ className?: string;
113
+ style?: CSSProperties;
50
114
  }
51
- declare function StatusTimeline({ status, message, labels, }: StatusTimelineProps): ReactElement;
115
+ declare function StatusTimeline({ status, message, labels, failureLabels, theme, className, style, }: StatusTimelineProps): ReactElement;
116
+
117
+ interface UseRampQuoteOptions {
118
+ ramp?: Ramp;
119
+ sellAsset: string;
120
+ buyAsset: string;
121
+ sellAmount?: string;
122
+ buyAmount?: string;
123
+ context?: "sep6" | "sep24" | "sep31";
124
+ debounceMs?: number;
125
+ pollIntervalMs?: number;
126
+ enabled?: boolean;
127
+ }
128
+ interface UseRampQuoteResult {
129
+ quote: Quote | undefined;
130
+ loading: boolean;
131
+ error: NairaRampError | undefined;
132
+ refresh: () => Promise<void>;
133
+ }
134
+ declare function useRampQuote({ ramp: rampOption, sellAsset, buyAsset, sellAmount, buyAmount, context, debounceMs, pollIntervalMs, enabled, }: UseRampQuoteOptions): UseRampQuoteResult;
135
+
136
+ type SupportedSep = AnchorEntry["seps"][number];
137
+ interface UseAnchorsOptions extends ListAnchorsFilter {
138
+ /** Filter to anchors that support this Stellar asset code (e.g. "USDC", "SRT"). */
139
+ assetCode?: string;
140
+ /** Filter to anchors that advertise this Stellar Ecosystem Proposal (e.g. "sep24", "sep38"). */
141
+ sep?: SupportedSep;
142
+ }
143
+ interface UseAnchorsResult {
144
+ anchors: AnchorEntry[];
145
+ getAnchorById: (id: string) => AnchorEntry | undefined;
146
+ }
147
+ /**
148
+ * Discovers registered Stellar anchors from `@nairaramp/core`, optionally filtered
149
+ * by network, ISO country code, supported asset code, and supported SEP protocol.
150
+ */
151
+ declare function useAnchors(options?: UseAnchorsOptions): UseAnchorsResult;
152
+
153
+ /**
154
+ * Default user-facing error guidance mapped exhaustively across all
155
+ * `@nairaramp/core` `NairaRampErrorCode` values.
156
+ */
157
+ declare const ERROR_MESSAGES: Record<NairaRampErrorCode, string>;
158
+ /**
159
+ * Resolves a human-readable message for a `NairaRampError` using optional
160
+ * per-code overrides, falling back to `ERROR_MESSAGES` and then `error.message`.
161
+ */
162
+ declare function getErrorMessage(error: NairaRampError | undefined, overrides?: Partial<Record<NairaRampErrorCode, string>>): string | undefined;
163
+
164
+ /**
165
+ * Builds a Stellar Expert transaction explorer URL for a 64-char hex Stellar
166
+ * transaction hash. Returns `undefined` if `txHash` is not a valid hex hash.
167
+ */
168
+ declare function getStellarExplorerUrl(txHash: string | undefined, network?: "testnet" | "mainnet"): string | undefined;
52
169
 
53
- declare const VERSION = "0.1.0";
170
+ declare const VERSION = "0.2.0";
54
171
 
55
- export { PayWithNaira, STATUS_MAP, StatusTimeline, TIMELINE_STEPS, VERSION, usePayWithNaira };
56
- export type { FailureStatusMapping, PayWithNairaPhase, PayWithNairaProps, StatusMapping, StatusTimelineProps, StepStatusMapping, TimelineStep, UsePayWithNairaOptions, UsePayWithNairaResult };
172
+ export { CashOutToNaira, ERROR_MESSAGES, HAUSA_LABELS, IGBO_LABELS, NairaRampProvider, PIDGIN_LABELS, PayWithNaira, STATUS_MAP, StatusTimeline, TIMELINE_STEPS, VERSION, YORUBA_LABELS, getErrorMessage, getStellarExplorerUrl, useAnchors, useCashOutToNaira, useNairaRamp, usePayWithNaira, useRampQuote };
173
+ export type { CashOutToNairaPhase, CashOutToNairaProps, FailureStatusLabel, FailureStatusMapping, NairaRampProviderProps, PayWithNairaPhase, PayWithNairaProps, StatusMapping, StatusTimelineProps, StepStatusMapping, SupportedSep, ThemeMode, TimelineStep, UseAnchorsOptions, UseAnchorsResult, UseCashOutToNairaOptions, UseCashOutToNairaResult, UsePayWithNairaOptions, UsePayWithNairaResult, UseRampQuoteOptions, UseRampQuoteResult };
package/dist/index.d.ts CHANGED
@@ -1,9 +1,25 @@
1
- import { Ramp, TransactionStatus, NairaRampError } from '@nairaramp/core';
2
- import { ReactElement } from 'react';
1
+ import { ReactNode, ReactElement, CSSProperties } from 'react';
2
+ import { Ramp, TransactionStatus, AnchorTransaction, NairaRampError, Quote, AnchorEntry, ListAnchorsFilter, NairaRampErrorCode } from '@nairaramp/core';
3
+
4
+ type ThemeMode = "light" | "dark" | "system";
5
+
6
+ interface NairaRampProviderProps {
7
+ ramp: Ramp;
8
+ children: ReactNode;
9
+ }
10
+ /**
11
+ * Provides a `@nairaramp/core` `Ramp` instance to descendant hooks and components
12
+ * so callers do not need to thread `ramp` through every component prop.
13
+ */
14
+ declare function NairaRampProvider({ ramp, children, }: NairaRampProviderProps): ReactElement;
15
+ /**
16
+ * Resolves a `Ramp` instance from an explicit override or the nearest `NairaRampProvider`.
17
+ */
18
+ declare function useNairaRamp(overrideRamp?: Ramp): Ramp;
3
19
 
4
20
  type PayWithNairaPhase = "idle" | "starting" | "awaiting_user" | "processing" | "completed" | "failed";
5
21
  interface UsePayWithNairaOptions {
6
- ramp: Ramp;
22
+ ramp?: Ramp;
7
23
  assetCode: string;
8
24
  }
9
25
  interface UsePayWithNairaResult {
@@ -14,43 +30,144 @@ interface UsePayWithNairaResult {
14
30
  phase: PayWithNairaPhase;
15
31
  status: TransactionStatus | string | undefined;
16
32
  transactionId: string | undefined;
33
+ transaction: AnchorTransaction | undefined;
34
+ stellarTransactionId: string | undefined;
17
35
  url: string | undefined;
18
36
  error: NairaRampError | undefined;
19
37
  reset: () => void;
20
38
  }
21
- declare function usePayWithNaira({ ramp, assetCode, }: UsePayWithNairaOptions): UsePayWithNairaResult;
39
+ declare function usePayWithNaira({ ramp: rampOption, assetCode, }: UsePayWithNairaOptions): UsePayWithNairaResult;
22
40
 
23
41
  interface PayWithNairaProps {
24
- ramp: Ramp;
42
+ ramp?: Ramp;
25
43
  assetCode: string;
26
44
  amount?: string;
27
45
  onComplete?: () => void;
28
46
  onError?: (error: NairaRampError) => void;
29
47
  label?: string;
48
+ theme?: ThemeMode;
49
+ className?: string;
50
+ style?: CSSProperties;
30
51
  }
31
- declare function PayWithNaira({ ramp, assetCode, amount, onComplete, onError, label, }: PayWithNairaProps): ReactElement;
52
+ declare function PayWithNaira({ ramp, assetCode, amount, onComplete, onError, label, theme, className, style, }: PayWithNairaProps): ReactElement;
53
+
54
+ type CashOutToNairaPhase = "idle" | "starting" | "awaiting_user" | "completing" | "processing" | "completed" | "failed";
55
+ interface UseCashOutToNairaOptions {
56
+ ramp?: Ramp;
57
+ assetCode: string;
58
+ }
59
+ interface UseCashOutToNairaResult {
60
+ start: (amount?: string) => Promise<{
61
+ id: string;
62
+ url: string;
63
+ } | undefined>;
64
+ phase: CashOutToNairaPhase;
65
+ status: TransactionStatus | string | undefined;
66
+ transactionId: string | undefined;
67
+ transaction: AnchorTransaction | undefined;
68
+ url: string | undefined;
69
+ txHash: string | undefined;
70
+ error: NairaRampError | undefined;
71
+ reset: () => void;
72
+ }
73
+ declare function useCashOutToNaira({ ramp: rampOption, assetCode, }: UseCashOutToNairaOptions): UseCashOutToNairaResult;
74
+
75
+ interface CashOutToNairaProps {
76
+ ramp?: Ramp;
77
+ assetCode: string;
78
+ amount?: string;
79
+ onComplete?: (txHash?: string) => void;
80
+ onError?: (error: NairaRampError) => void;
81
+ label?: string;
82
+ theme?: ThemeMode;
83
+ className?: string;
84
+ style?: CSSProperties;
85
+ }
86
+ declare function CashOutToNaira({ ramp, assetCode, amount, onComplete, onError, label, theme, className, style, }: CashOutToNairaProps): ReactElement;
32
87
 
33
88
  type TimelineStep = "Started" | "Waiting for your payment" | "Payment received" | "Anchor processing" | "Sending on Stellar" | "Completed";
34
89
  declare const TIMELINE_STEPS: readonly TimelineStep[];
90
+ declare const YORUBA_LABELS: Record<TimelineStep, string>;
91
+ declare const HAUSA_LABELS: Record<TimelineStep, string>;
92
+ declare const IGBO_LABELS: Record<TimelineStep, string>;
93
+ declare const PIDGIN_LABELS: Record<TimelineStep, string>;
35
94
  interface StepStatusMapping {
36
95
  kind: "step";
37
96
  stepIndex: number;
38
97
  label: TimelineStep;
39
98
  }
99
+ type FailureStatusLabel = "Refunded" | "Expired" | "No market" | "Too small" | "Too large" | "Error" | "Unknown status";
40
100
  interface FailureStatusMapping {
41
101
  kind: "failure";
42
- label: string;
102
+ label: FailureStatusLabel;
43
103
  }
44
104
  type StatusMapping = StepStatusMapping | FailureStatusMapping;
45
105
  declare const STATUS_MAP: Record<TransactionStatus, StatusMapping>;
46
106
  interface StatusTimelineProps {
47
- status: TransactionStatus | undefined;
107
+ status: TransactionStatus | string | undefined;
48
108
  message?: string;
49
109
  labels?: Partial<Record<TimelineStep, string>>;
110
+ failureLabels?: Partial<Record<FailureStatusLabel, string>>;
111
+ theme?: ThemeMode;
112
+ className?: string;
113
+ style?: CSSProperties;
50
114
  }
51
- declare function StatusTimeline({ status, message, labels, }: StatusTimelineProps): ReactElement;
115
+ declare function StatusTimeline({ status, message, labels, failureLabels, theme, className, style, }: StatusTimelineProps): ReactElement;
116
+
117
+ interface UseRampQuoteOptions {
118
+ ramp?: Ramp;
119
+ sellAsset: string;
120
+ buyAsset: string;
121
+ sellAmount?: string;
122
+ buyAmount?: string;
123
+ context?: "sep6" | "sep24" | "sep31";
124
+ debounceMs?: number;
125
+ pollIntervalMs?: number;
126
+ enabled?: boolean;
127
+ }
128
+ interface UseRampQuoteResult {
129
+ quote: Quote | undefined;
130
+ loading: boolean;
131
+ error: NairaRampError | undefined;
132
+ refresh: () => Promise<void>;
133
+ }
134
+ declare function useRampQuote({ ramp: rampOption, sellAsset, buyAsset, sellAmount, buyAmount, context, debounceMs, pollIntervalMs, enabled, }: UseRampQuoteOptions): UseRampQuoteResult;
135
+
136
+ type SupportedSep = AnchorEntry["seps"][number];
137
+ interface UseAnchorsOptions extends ListAnchorsFilter {
138
+ /** Filter to anchors that support this Stellar asset code (e.g. "USDC", "SRT"). */
139
+ assetCode?: string;
140
+ /** Filter to anchors that advertise this Stellar Ecosystem Proposal (e.g. "sep24", "sep38"). */
141
+ sep?: SupportedSep;
142
+ }
143
+ interface UseAnchorsResult {
144
+ anchors: AnchorEntry[];
145
+ getAnchorById: (id: string) => AnchorEntry | undefined;
146
+ }
147
+ /**
148
+ * Discovers registered Stellar anchors from `@nairaramp/core`, optionally filtered
149
+ * by network, ISO country code, supported asset code, and supported SEP protocol.
150
+ */
151
+ declare function useAnchors(options?: UseAnchorsOptions): UseAnchorsResult;
152
+
153
+ /**
154
+ * Default user-facing error guidance mapped exhaustively across all
155
+ * `@nairaramp/core` `NairaRampErrorCode` values.
156
+ */
157
+ declare const ERROR_MESSAGES: Record<NairaRampErrorCode, string>;
158
+ /**
159
+ * Resolves a human-readable message for a `NairaRampError` using optional
160
+ * per-code overrides, falling back to `ERROR_MESSAGES` and then `error.message`.
161
+ */
162
+ declare function getErrorMessage(error: NairaRampError | undefined, overrides?: Partial<Record<NairaRampErrorCode, string>>): string | undefined;
163
+
164
+ /**
165
+ * Builds a Stellar Expert transaction explorer URL for a 64-char hex Stellar
166
+ * transaction hash. Returns `undefined` if `txHash` is not a valid hex hash.
167
+ */
168
+ declare function getStellarExplorerUrl(txHash: string | undefined, network?: "testnet" | "mainnet"): string | undefined;
52
169
 
53
- declare const VERSION = "0.1.0";
170
+ declare const VERSION = "0.2.0";
54
171
 
55
- export { PayWithNaira, STATUS_MAP, StatusTimeline, TIMELINE_STEPS, VERSION, usePayWithNaira };
56
- export type { FailureStatusMapping, PayWithNairaPhase, PayWithNairaProps, StatusMapping, StatusTimelineProps, StepStatusMapping, TimelineStep, UsePayWithNairaOptions, UsePayWithNairaResult };
172
+ export { CashOutToNaira, ERROR_MESSAGES, HAUSA_LABELS, IGBO_LABELS, NairaRampProvider, PIDGIN_LABELS, PayWithNaira, STATUS_MAP, StatusTimeline, TIMELINE_STEPS, VERSION, YORUBA_LABELS, getErrorMessage, getStellarExplorerUrl, useAnchors, useCashOutToNaira, useNairaRamp, usePayWithNaira, useRampQuote };
173
+ export type { CashOutToNairaPhase, CashOutToNairaProps, FailureStatusLabel, FailureStatusMapping, NairaRampProviderProps, PayWithNairaPhase, PayWithNairaProps, StatusMapping, StatusTimelineProps, StepStatusMapping, SupportedSep, ThemeMode, TimelineStep, UseAnchorsOptions, UseAnchorsResult, UseCashOutToNairaOptions, UseCashOutToNairaResult, UsePayWithNairaOptions, UsePayWithNairaResult, UseRampQuoteOptions, UseRampQuoteResult };