@b3dotfun/sdk 0.0.43 → 0.0.44-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/dist/cjs/anyspend/react/components/AnySpend.js +82 -24
  2. package/dist/cjs/anyspend/react/components/common/OrderDetails.js +2 -7
  3. package/dist/cjs/anyspend/react/components/common/OrderHistoryItem.js +1 -6
  4. package/dist/cjs/anyspend/react/hooks/useAnyspendFlow.d.ts +1 -0
  5. package/dist/cjs/anyspend/react/hooks/useAnyspendFlow.js +3 -3
  6. package/dist/cjs/anyspend/react/hooks/useAnyspendOrderAndTransactions.d.ts +2 -0
  7. package/dist/cjs/anyspend/react/hooks/useAnyspendOrderHistory.d.ts +48 -0
  8. package/dist/cjs/anyspend/types/api.d.ts +15 -20
  9. package/dist/cjs/anyspend/utils/orderPayload.js +0 -4
  10. package/dist/cjs/shared/react/hooks/useCurrencyConversion.d.ts +1 -1
  11. package/dist/cjs/shared/react/hooks/useCurrencyConversion.js +30 -12
  12. package/dist/esm/anyspend/react/components/AnySpend.js +82 -24
  13. package/dist/esm/anyspend/react/components/common/OrderDetails.js +2 -7
  14. package/dist/esm/anyspend/react/components/common/OrderHistoryItem.js +1 -6
  15. package/dist/esm/anyspend/react/hooks/useAnyspendFlow.d.ts +1 -0
  16. package/dist/esm/anyspend/react/hooks/useAnyspendFlow.js +3 -3
  17. package/dist/esm/anyspend/react/hooks/useAnyspendOrderAndTransactions.d.ts +2 -0
  18. package/dist/esm/anyspend/react/hooks/useAnyspendOrderHistory.d.ts +48 -0
  19. package/dist/esm/anyspend/types/api.d.ts +15 -20
  20. package/dist/esm/anyspend/utils/orderPayload.js +0 -4
  21. package/dist/esm/shared/react/hooks/useCurrencyConversion.d.ts +1 -1
  22. package/dist/esm/shared/react/hooks/useCurrencyConversion.js +30 -12
  23. package/dist/types/anyspend/react/hooks/useAnyspendFlow.d.ts +1 -0
  24. package/dist/types/anyspend/react/hooks/useAnyspendOrderAndTransactions.d.ts +2 -0
  25. package/dist/types/anyspend/react/hooks/useAnyspendOrderHistory.d.ts +48 -0
  26. package/dist/types/anyspend/types/api.d.ts +15 -20
  27. package/dist/types/shared/react/hooks/useCurrencyConversion.d.ts +1 -1
  28. package/package.json +1 -1
  29. package/src/anyspend/react/components/AnySpend.tsx +93 -28
  30. package/src/anyspend/react/components/common/OrderDetails.tsx +3 -9
  31. package/src/anyspend/react/components/common/OrderHistoryItem.tsx +1 -7
  32. package/src/anyspend/react/hooks/useAnyspendFlow.ts +3 -3
  33. package/src/anyspend/types/api.ts +15 -20
  34. package/src/anyspend/utils/orderPayload.ts +0 -4
  35. package/src/shared/react/hooks/useCurrencyConversion.ts +39 -12
@@ -5,8 +5,6 @@ export const buildPayload = (orderType, params) => {
5
5
  case "swap":
6
6
  return {
7
7
  expectedDstAmount,
8
- actualDstAmount: null,
9
- amountInAfterFee: null,
10
8
  };
11
9
  case "mint_nft":
12
10
  if (nft?.type === "erc1155") {
@@ -43,8 +41,6 @@ export const buildPayload = (orderType, params) => {
43
41
  case "hype_duel":
44
42
  return {
45
43
  expectedDstAmount,
46
- actualDstAmount: null,
47
- amountInAfterFee: null,
48
44
  };
49
45
  default:
50
46
  throw new Error(`Invalid order type: ${orderType}`);
@@ -20,7 +20,7 @@ export declare function useCurrencyConversion(): {
20
20
  /** Base currency used for conversion (typically B3) */
21
21
  baseCurrency: import("../stores/currencyStore").SupportedCurrency;
22
22
  /** Current exchange rate from base to selected currency (undefined while loading) */
23
- exchangeRate: number;
23
+ exchangeRate: number | undefined;
24
24
  /** Format a value with currency conversion and proper symbol/decimal handling */
25
25
  formatCurrencyValue: (value: number, options?: {
26
26
  decimals?: number;
@@ -1,6 +1,23 @@
1
- import { useExchangeRate } from "../../../global-account/react/index.js";
1
+ import { useQuery } from "@tanstack/react-query";
2
2
  import { formatDisplayNumber } from "../../../shared/utils/number.js";
3
3
  import { CURRENCY_SYMBOLS, useCurrencyStore } from "../stores/currencyStore.js";
4
+ const COINBASE_API_URL = "https://api.coinbase.com/v2/exchange-rates";
5
+ const REFETCH_INTERVAL_MS = 30000;
6
+ /**
7
+ * Fetches all exchange rates for a given base currency from Coinbase API.
8
+ */
9
+ async function fetchAllExchangeRates(baseCurrency) {
10
+ const response = await fetch(`${COINBASE_API_URL}?currency=${baseCurrency}`);
11
+ if (!response.ok) {
12
+ throw new Error(`Failed to fetch exchange rates for ${baseCurrency}: ${response.status}`);
13
+ }
14
+ const data = await response.json();
15
+ const rates = {};
16
+ for (const [currency, rate] of Object.entries(data.data.rates)) {
17
+ rates[currency] = parseFloat(rate);
18
+ }
19
+ return rates;
20
+ }
4
21
  /**
5
22
  * Hook for currency conversion and formatting with real-time exchange rates.
6
23
  *
@@ -20,16 +37,18 @@ import { CURRENCY_SYMBOLS, useCurrencyStore } from "../stores/currencyStore.js";
20
37
  export function useCurrencyConversion() {
21
38
  const selectedCurrency = useCurrencyStore(state => state.selectedCurrency);
22
39
  const baseCurrency = useCurrencyStore(state => state.baseCurrency);
23
- // Get exchange rate for the selected currency
24
- const { rate: exchangeRate } = useExchangeRate({
25
- baseCurrency,
26
- quoteCurrency: selectedCurrency === baseCurrency ? "USD" : selectedCurrency,
27
- });
28
- // Always fetch USD rate for tooltip purposes
29
- const { rate: usdRate } = useExchangeRate({
30
- baseCurrency,
31
- quoteCurrency: "USD",
40
+ // Fetch all exchange rates for the base currency
41
+ const { data: exchangeRates } = useQuery({
42
+ queryKey: ["exchangeRates", baseCurrency],
43
+ queryFn: () => fetchAllExchangeRates(baseCurrency),
44
+ refetchInterval: REFETCH_INTERVAL_MS,
45
+ staleTime: REFETCH_INTERVAL_MS / 2,
46
+ retry: 3,
47
+ retryDelay: attemptIndex => Math.min(1000 * 2 ** attemptIndex, REFETCH_INTERVAL_MS),
32
48
  });
49
+ // Extract specific rates from the full rates object
50
+ const exchangeRate = exchangeRates?.[selectedCurrency];
51
+ const usdRate = exchangeRates?.["USD"];
33
52
  /**
34
53
  * Formats a numeric value as a currency string with proper conversion and formatting.
35
54
  *
@@ -75,8 +94,7 @@ export function useCurrencyConversion() {
75
94
  });
76
95
  return `${formatted} ${baseCurrency}`;
77
96
  }
78
- // If no exchange rate available, show base currency to prevent showing
79
- // incorrect values with wrong currency symbols during rate fetching
97
+ // If showing base currency, no conversion needed
80
98
  if (selectedCurrency === baseCurrency || !exchangeRate) {
81
99
  const formatted = formatDisplayNumber(value, {
82
100
  significantDigits: baseCurrency === "B3" ? 6 : 8,
@@ -36,6 +36,7 @@ export declare function useAnyspendFlow({ paymentType, recipientAddress, loadOrd
36
36
  relayTxs: components["schemas"]["RelayTx"][];
37
37
  executeTx: components["schemas"]["ExecuteTx"] | null;
38
38
  refundTxs: components["schemas"]["RefundTx"][];
39
+ points: number | null;
39
40
  };
40
41
  statusCode: number;
41
42
  } | undefined;
@@ -8,6 +8,7 @@ export declare function useAnyspendOrderAndTransactions(orderId: string | undefi
8
8
  relayTxs: import("../..").components["schemas"]["RelayTx"][];
9
9
  executeTx: import("../..").components["schemas"]["ExecuteTx"] | null;
10
10
  refundTxs: import("../..").components["schemas"]["RefundTx"][];
11
+ points: number | null;
11
12
  };
12
13
  statusCode: number;
13
14
  } | undefined;
@@ -22,6 +23,7 @@ export declare function useAnyspendOrderAndTransactions(orderId: string | undefi
22
23
  relayTxs: import("../..").components["schemas"]["RelayTx"][];
23
24
  executeTx: import("../..").components["schemas"]["ExecuteTx"] | null;
24
25
  refundTxs: import("../..").components["schemas"]["RefundTx"][];
26
+ points: number | null;
25
27
  };
26
28
  statusCode: number;
27
29
  }, Error>>;
@@ -12,11 +12,15 @@ export declare function useAnyspendOrderHistory(creatorAddress: string | undefin
12
12
  errorDetails: string | null;
13
13
  createdAt: number;
14
14
  expiredAt: number;
15
+ filledAt: number | null;
15
16
  creatorAddress: string | null;
16
17
  partnerId: string | null;
17
18
  onrampMetadata: import("../..").components["schemas"]["OnrampMetadata"] | null;
18
19
  oneClickBuyUrl: string | null;
19
20
  stripePaymentIntentId: string | null;
21
+ settlement: {
22
+ actualDstAmount: string | null;
23
+ } | null;
20
24
  } & {
21
25
  type: "swap";
22
26
  payload: import("../..").components["schemas"]["SwapPayload"];
@@ -34,11 +38,15 @@ export declare function useAnyspendOrderHistory(creatorAddress: string | undefin
34
38
  errorDetails: string | null;
35
39
  createdAt: number;
36
40
  expiredAt: number;
41
+ filledAt: number | null;
37
42
  creatorAddress: string | null;
38
43
  partnerId: string | null;
39
44
  onrampMetadata: import("../..").components["schemas"]["OnrampMetadata"] | null;
40
45
  oneClickBuyUrl: string | null;
41
46
  stripePaymentIntentId: string | null;
47
+ settlement: {
48
+ actualDstAmount: string | null;
49
+ } | null;
42
50
  } & {
43
51
  type: "hype_duel";
44
52
  payload: import("../..").components["schemas"]["HypeDuelPayload"];
@@ -56,11 +64,15 @@ export declare function useAnyspendOrderHistory(creatorAddress: string | undefin
56
64
  errorDetails: string | null;
57
65
  createdAt: number;
58
66
  expiredAt: number;
67
+ filledAt: number | null;
59
68
  creatorAddress: string | null;
60
69
  partnerId: string | null;
61
70
  onrampMetadata: import("../..").components["schemas"]["OnrampMetadata"] | null;
62
71
  oneClickBuyUrl: string | null;
63
72
  stripePaymentIntentId: string | null;
73
+ settlement: {
74
+ actualDstAmount: string | null;
75
+ } | null;
64
76
  } & {
65
77
  type: "custom";
66
78
  payload: import("../..").components["schemas"]["CustomPayload"];
@@ -78,11 +90,15 @@ export declare function useAnyspendOrderHistory(creatorAddress: string | undefin
78
90
  errorDetails: string | null;
79
91
  createdAt: number;
80
92
  expiredAt: number;
93
+ filledAt: number | null;
81
94
  creatorAddress: string | null;
82
95
  partnerId: string | null;
83
96
  onrampMetadata: import("../..").components["schemas"]["OnrampMetadata"] | null;
84
97
  oneClickBuyUrl: string | null;
85
98
  stripePaymentIntentId: string | null;
99
+ settlement: {
100
+ actualDstAmount: string | null;
101
+ } | null;
86
102
  } & {
87
103
  type: "mint_nft";
88
104
  payload: import("../..").components["schemas"]["MintNftPayload"];
@@ -100,11 +116,15 @@ export declare function useAnyspendOrderHistory(creatorAddress: string | undefin
100
116
  errorDetails: string | null;
101
117
  createdAt: number;
102
118
  expiredAt: number;
119
+ filledAt: number | null;
103
120
  creatorAddress: string | null;
104
121
  partnerId: string | null;
105
122
  onrampMetadata: import("../..").components["schemas"]["OnrampMetadata"] | null;
106
123
  oneClickBuyUrl: string | null;
107
124
  stripePaymentIntentId: string | null;
125
+ settlement: {
126
+ actualDstAmount: string | null;
127
+ } | null;
108
128
  } & {
109
129
  type: "join_tournament";
110
130
  payload: import("../..").components["schemas"]["JoinTournamentPayload"];
@@ -122,11 +142,15 @@ export declare function useAnyspendOrderHistory(creatorAddress: string | undefin
122
142
  errorDetails: string | null;
123
143
  createdAt: number;
124
144
  expiredAt: number;
145
+ filledAt: number | null;
125
146
  creatorAddress: string | null;
126
147
  partnerId: string | null;
127
148
  onrampMetadata: import("../..").components["schemas"]["OnrampMetadata"] | null;
128
149
  oneClickBuyUrl: string | null;
129
150
  stripePaymentIntentId: string | null;
151
+ settlement: {
152
+ actualDstAmount: string | null;
153
+ } | null;
130
154
  } & {
131
155
  type: "fund_tournament";
132
156
  payload: import("../..").components["schemas"]["FundTournamentPayload"];
@@ -147,11 +171,15 @@ export declare function useAnyspendOrderHistory(creatorAddress: string | undefin
147
171
  errorDetails: string | null;
148
172
  createdAt: number;
149
173
  expiredAt: number;
174
+ filledAt: number | null;
150
175
  creatorAddress: string | null;
151
176
  partnerId: string | null;
152
177
  onrampMetadata: import("../..").components["schemas"]["OnrampMetadata"] | null;
153
178
  oneClickBuyUrl: string | null;
154
179
  stripePaymentIntentId: string | null;
180
+ settlement: {
181
+ actualDstAmount: string | null;
182
+ } | null;
155
183
  } & {
156
184
  type: "swap";
157
185
  payload: import("../..").components["schemas"]["SwapPayload"];
@@ -169,11 +197,15 @@ export declare function useAnyspendOrderHistory(creatorAddress: string | undefin
169
197
  errorDetails: string | null;
170
198
  createdAt: number;
171
199
  expiredAt: number;
200
+ filledAt: number | null;
172
201
  creatorAddress: string | null;
173
202
  partnerId: string | null;
174
203
  onrampMetadata: import("../..").components["schemas"]["OnrampMetadata"] | null;
175
204
  oneClickBuyUrl: string | null;
176
205
  stripePaymentIntentId: string | null;
206
+ settlement: {
207
+ actualDstAmount: string | null;
208
+ } | null;
177
209
  } & {
178
210
  type: "hype_duel";
179
211
  payload: import("../..").components["schemas"]["HypeDuelPayload"];
@@ -191,11 +223,15 @@ export declare function useAnyspendOrderHistory(creatorAddress: string | undefin
191
223
  errorDetails: string | null;
192
224
  createdAt: number;
193
225
  expiredAt: number;
226
+ filledAt: number | null;
194
227
  creatorAddress: string | null;
195
228
  partnerId: string | null;
196
229
  onrampMetadata: import("../..").components["schemas"]["OnrampMetadata"] | null;
197
230
  oneClickBuyUrl: string | null;
198
231
  stripePaymentIntentId: string | null;
232
+ settlement: {
233
+ actualDstAmount: string | null;
234
+ } | null;
199
235
  } & {
200
236
  type: "custom";
201
237
  payload: import("../..").components["schemas"]["CustomPayload"];
@@ -213,11 +249,15 @@ export declare function useAnyspendOrderHistory(creatorAddress: string | undefin
213
249
  errorDetails: string | null;
214
250
  createdAt: number;
215
251
  expiredAt: number;
252
+ filledAt: number | null;
216
253
  creatorAddress: string | null;
217
254
  partnerId: string | null;
218
255
  onrampMetadata: import("../..").components["schemas"]["OnrampMetadata"] | null;
219
256
  oneClickBuyUrl: string | null;
220
257
  stripePaymentIntentId: string | null;
258
+ settlement: {
259
+ actualDstAmount: string | null;
260
+ } | null;
221
261
  } & {
222
262
  type: "mint_nft";
223
263
  payload: import("../..").components["schemas"]["MintNftPayload"];
@@ -235,11 +275,15 @@ export declare function useAnyspendOrderHistory(creatorAddress: string | undefin
235
275
  errorDetails: string | null;
236
276
  createdAt: number;
237
277
  expiredAt: number;
278
+ filledAt: number | null;
238
279
  creatorAddress: string | null;
239
280
  partnerId: string | null;
240
281
  onrampMetadata: import("../..").components["schemas"]["OnrampMetadata"] | null;
241
282
  oneClickBuyUrl: string | null;
242
283
  stripePaymentIntentId: string | null;
284
+ settlement: {
285
+ actualDstAmount: string | null;
286
+ } | null;
243
287
  } & {
244
288
  type: "join_tournament";
245
289
  payload: import("../..").components["schemas"]["JoinTournamentPayload"];
@@ -257,11 +301,15 @@ export declare function useAnyspendOrderHistory(creatorAddress: string | undefin
257
301
  errorDetails: string | null;
258
302
  createdAt: number;
259
303
  expiredAt: number;
304
+ filledAt: number | null;
260
305
  creatorAddress: string | null;
261
306
  partnerId: string | null;
262
307
  onrampMetadata: import("../..").components["schemas"]["OnrampMetadata"] | null;
263
308
  oneClickBuyUrl: string | null;
264
309
  stripePaymentIntentId: string | null;
310
+ settlement: {
311
+ actualDstAmount: string | null;
312
+ } | null;
265
313
  } & {
266
314
  type: "fund_tournament";
267
315
  payload: import("../..").components["schemas"]["FundTournamentPayload"];
@@ -434,6 +434,11 @@ export interface paths {
434
434
  executeTx: components["schemas"]["ExecuteTx"] | null;
435
435
  /** @description Refund transactions if order failed */
436
436
  refundTxs: components["schemas"]["RefundTx"][];
437
+ /**
438
+ * @description Points awarded for this order (only present when order status is executed)
439
+ * @example 100
440
+ */
441
+ points: number | null;
437
442
  };
438
443
  /** @example 200 */
439
444
  statusCode: number;
@@ -1112,16 +1117,6 @@ export interface components {
1112
1117
  * @example 990000
1113
1118
  */
1114
1119
  expectedDstAmount: string;
1115
- /**
1116
- * @description Actual received amount (null for new orders)
1117
- * @example 990000
1118
- */
1119
- actualDstAmount: string | null;
1120
- /**
1121
- * @description Amount in after fee
1122
- * @example 990000
1123
- */
1124
- amountInAfterFee: string | null;
1125
1120
  };
1126
1121
  /** @description HypeDuel-specific payload */
1127
1122
  HypeDuelPayload: {
@@ -1130,16 +1125,6 @@ export interface components {
1130
1125
  * @example 990000
1131
1126
  */
1132
1127
  expectedDstAmount: string;
1133
- /**
1134
- * @description Actual received amount (null for new orders)
1135
- * @example 990000
1136
- */
1137
- actualDstAmount: string | null;
1138
- /**
1139
- * @description Amount in after fee
1140
- * @example 990000
1141
- */
1142
- amountInAfterFee: string | null;
1143
1128
  };
1144
1129
  /** @description Custom execution payload */
1145
1130
  CustomPayload: {
@@ -1307,6 +1292,8 @@ export interface components {
1307
1292
  * @example 1752506694679
1308
1293
  */
1309
1294
  expiredAt: number;
1295
+ /** @description Timestamp when the order was filled/executed */
1296
+ filledAt: number | null;
1310
1297
  /**
1311
1298
  * @description Optional creator address
1312
1299
  * @example 0xb34facb90a200251318e8841c05102366f2158cf
@@ -1323,6 +1310,14 @@ export interface components {
1323
1310
  * @example pi_3Rko0sJnoDg53PsP0PDLsHkR
1324
1311
  */
1325
1312
  stripePaymentIntentId: string | null;
1313
+ /** @description Settlement information for executed orders */
1314
+ settlement: {
1315
+ /**
1316
+ * @description Actual received amount after execution
1317
+ * @example 990000
1318
+ */
1319
+ actualDstAmount: string | null;
1320
+ } | null;
1326
1321
  };
1327
1322
  SwapOrder: components["schemas"]["BaseOrder"] & {
1328
1323
  /**
@@ -20,7 +20,7 @@ export declare function useCurrencyConversion(): {
20
20
  /** Base currency used for conversion (typically B3) */
21
21
  baseCurrency: import("../stores/currencyStore").SupportedCurrency;
22
22
  /** Current exchange rate from base to selected currency (undefined while loading) */
23
- exchangeRate: number;
23
+ exchangeRate: number | undefined;
24
24
  /** Format a value with currency conversion and proper symbol/decimal handling */
25
25
  formatCurrencyValue: (value: number, options?: {
26
26
  decimals?: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@b3dotfun/sdk",
3
- "version": "0.0.43",
3
+ "version": "0.0.44-alpha.1",
4
4
  "source": "src/index.ts",
5
5
  "main": "./dist/cjs/index.js",
6
6
  "react-native": "./dist/cjs/index.native.js",