@unifold/core 0.1.13 → 0.1.15
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.mts +22 -3
- package/dist/index.d.ts +22 -3
- package/dist/index.js +29 -23
- package/dist/index.mjs +28 -23
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -98,10 +98,12 @@ interface AutoSwapResponse {
|
|
|
98
98
|
source_token_metadata?: {
|
|
99
99
|
icon_url: string;
|
|
100
100
|
icon_urls?: IconUrl[];
|
|
101
|
+
decimals?: number;
|
|
101
102
|
};
|
|
102
103
|
destination_token_metadata?: {
|
|
103
104
|
icon_url: string;
|
|
104
105
|
icon_urls?: IconUrl[];
|
|
106
|
+
decimals?: number;
|
|
105
107
|
};
|
|
106
108
|
deposit_wallet?: {
|
|
107
109
|
id: string;
|
|
@@ -283,24 +285,41 @@ interface ProjectConfigResponse {
|
|
|
283
285
|
payment_networks: {
|
|
284
286
|
networks: PaymentNetwork[];
|
|
285
287
|
};
|
|
288
|
+
blocked_country_codes?: string[];
|
|
286
289
|
}
|
|
287
290
|
/**
|
|
288
291
|
* Get project configuration
|
|
289
292
|
* @param publishableKey - Optional publishable key, defaults to configured key
|
|
290
293
|
*/
|
|
291
294
|
declare function getProjectConfig(publishableKey?: string): Promise<ProjectConfigResponse>;
|
|
295
|
+
interface IpAddressResponse {
|
|
296
|
+
alpha2: string;
|
|
297
|
+
alpha3: string;
|
|
298
|
+
country: string;
|
|
299
|
+
state: string | null;
|
|
300
|
+
ip_address: string;
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* Get IP address geolocation information
|
|
304
|
+
* Returns the user's IP address and associated country/state information
|
|
305
|
+
* This is a public endpoint that doesn't require authentication
|
|
306
|
+
*/
|
|
307
|
+
declare function getIpAddress(): Promise<IpAddressResponse>;
|
|
292
308
|
|
|
293
309
|
/**
|
|
294
310
|
* User IP information interface
|
|
295
311
|
*/
|
|
296
312
|
interface UserIpInfo {
|
|
297
313
|
alpha2: string;
|
|
298
|
-
|
|
314
|
+
alpha3?: string;
|
|
315
|
+
country?: string;
|
|
316
|
+
state?: string | null;
|
|
317
|
+
ipAddress?: string;
|
|
299
318
|
}
|
|
300
319
|
/**
|
|
301
320
|
* Hook to fetch user's IP-based location information
|
|
302
321
|
*
|
|
303
|
-
* Uses
|
|
322
|
+
* Uses the Unifold API to detect the user's country and state.
|
|
304
323
|
*
|
|
305
324
|
* The result is cached in-memory using React Query:
|
|
306
325
|
* - Data persists for the entire browser session
|
|
@@ -381,4 +400,4 @@ declare const i18n: {
|
|
|
381
400
|
};
|
|
382
401
|
type I18nStrings = typeof i18n;
|
|
383
402
|
|
|
384
|
-
export { type AutoSwapRequest, type AutoSwapResponse, type CreateDepositAddressRequest, type DepositAddressResponse, ExecutionStatus, type FeaturedToken, type FiatCurrenciesResponse, type FiatCurrency, type I18nStrings, type IconUrl, type MeldQuote, type MeldQuotesRequest, type MeldQuotesResponse, type MeldSessionRequest, type MeldSessionResponse, type PaymentNetwork, type ProjectConfigResponse, type QueryExecutionsRequest, type QueryExecutionsResponse, SOLANA_USDC_ADDRESS, type SupportedChain, type SupportedDepositTokensResponse, type SupportedToken, type TokenChain, type TokenChainIconUrl, type TokenChainsResponse, type UserIpInfo, type Wallet, createDepositAddress, createMeldSession, getApiBaseUrl, getChainName, getFiatCurrencies, getIconUrl, getIconUrlWithCdn, getMeldQuotes, getPreferredIconUrl, getProjectConfig, getSupportedDepositTokens, getTokenChains, getWalletByChainType, i18n, queryExecutions, setApiConfig, useUserIp };
|
|
403
|
+
export { type AutoSwapRequest, type AutoSwapResponse, type CreateDepositAddressRequest, type DepositAddressResponse, ExecutionStatus, type FeaturedToken, type FiatCurrenciesResponse, type FiatCurrency, type I18nStrings, type IconUrl, type IpAddressResponse, type MeldQuote, type MeldQuotesRequest, type MeldQuotesResponse, type MeldSessionRequest, type MeldSessionResponse, type PaymentNetwork, type ProjectConfigResponse, type QueryExecutionsRequest, type QueryExecutionsResponse, SOLANA_USDC_ADDRESS, type SupportedChain, type SupportedDepositTokensResponse, type SupportedToken, type TokenChain, type TokenChainIconUrl, type TokenChainsResponse, type UserIpInfo, type Wallet, createDepositAddress, createMeldSession, getApiBaseUrl, getChainName, getFiatCurrencies, getIconUrl, getIconUrlWithCdn, getIpAddress, getMeldQuotes, getPreferredIconUrl, getProjectConfig, getSupportedDepositTokens, getTokenChains, getWalletByChainType, i18n, queryExecutions, setApiConfig, useUserIp };
|
package/dist/index.d.ts
CHANGED
|
@@ -98,10 +98,12 @@ interface AutoSwapResponse {
|
|
|
98
98
|
source_token_metadata?: {
|
|
99
99
|
icon_url: string;
|
|
100
100
|
icon_urls?: IconUrl[];
|
|
101
|
+
decimals?: number;
|
|
101
102
|
};
|
|
102
103
|
destination_token_metadata?: {
|
|
103
104
|
icon_url: string;
|
|
104
105
|
icon_urls?: IconUrl[];
|
|
106
|
+
decimals?: number;
|
|
105
107
|
};
|
|
106
108
|
deposit_wallet?: {
|
|
107
109
|
id: string;
|
|
@@ -283,24 +285,41 @@ interface ProjectConfigResponse {
|
|
|
283
285
|
payment_networks: {
|
|
284
286
|
networks: PaymentNetwork[];
|
|
285
287
|
};
|
|
288
|
+
blocked_country_codes?: string[];
|
|
286
289
|
}
|
|
287
290
|
/**
|
|
288
291
|
* Get project configuration
|
|
289
292
|
* @param publishableKey - Optional publishable key, defaults to configured key
|
|
290
293
|
*/
|
|
291
294
|
declare function getProjectConfig(publishableKey?: string): Promise<ProjectConfigResponse>;
|
|
295
|
+
interface IpAddressResponse {
|
|
296
|
+
alpha2: string;
|
|
297
|
+
alpha3: string;
|
|
298
|
+
country: string;
|
|
299
|
+
state: string | null;
|
|
300
|
+
ip_address: string;
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* Get IP address geolocation information
|
|
304
|
+
* Returns the user's IP address and associated country/state information
|
|
305
|
+
* This is a public endpoint that doesn't require authentication
|
|
306
|
+
*/
|
|
307
|
+
declare function getIpAddress(): Promise<IpAddressResponse>;
|
|
292
308
|
|
|
293
309
|
/**
|
|
294
310
|
* User IP information interface
|
|
295
311
|
*/
|
|
296
312
|
interface UserIpInfo {
|
|
297
313
|
alpha2: string;
|
|
298
|
-
|
|
314
|
+
alpha3?: string;
|
|
315
|
+
country?: string;
|
|
316
|
+
state?: string | null;
|
|
317
|
+
ipAddress?: string;
|
|
299
318
|
}
|
|
300
319
|
/**
|
|
301
320
|
* Hook to fetch user's IP-based location information
|
|
302
321
|
*
|
|
303
|
-
* Uses
|
|
322
|
+
* Uses the Unifold API to detect the user's country and state.
|
|
304
323
|
*
|
|
305
324
|
* The result is cached in-memory using React Query:
|
|
306
325
|
* - Data persists for the entire browser session
|
|
@@ -381,4 +400,4 @@ declare const i18n: {
|
|
|
381
400
|
};
|
|
382
401
|
type I18nStrings = typeof i18n;
|
|
383
402
|
|
|
384
|
-
export { type AutoSwapRequest, type AutoSwapResponse, type CreateDepositAddressRequest, type DepositAddressResponse, ExecutionStatus, type FeaturedToken, type FiatCurrenciesResponse, type FiatCurrency, type I18nStrings, type IconUrl, type MeldQuote, type MeldQuotesRequest, type MeldQuotesResponse, type MeldSessionRequest, type MeldSessionResponse, type PaymentNetwork, type ProjectConfigResponse, type QueryExecutionsRequest, type QueryExecutionsResponse, SOLANA_USDC_ADDRESS, type SupportedChain, type SupportedDepositTokensResponse, type SupportedToken, type TokenChain, type TokenChainIconUrl, type TokenChainsResponse, type UserIpInfo, type Wallet, createDepositAddress, createMeldSession, getApiBaseUrl, getChainName, getFiatCurrencies, getIconUrl, getIconUrlWithCdn, getMeldQuotes, getPreferredIconUrl, getProjectConfig, getSupportedDepositTokens, getTokenChains, getWalletByChainType, i18n, queryExecutions, setApiConfig, useUserIp };
|
|
403
|
+
export { type AutoSwapRequest, type AutoSwapResponse, type CreateDepositAddressRequest, type DepositAddressResponse, ExecutionStatus, type FeaturedToken, type FiatCurrenciesResponse, type FiatCurrency, type I18nStrings, type IconUrl, type IpAddressResponse, type MeldQuote, type MeldQuotesRequest, type MeldQuotesResponse, type MeldSessionRequest, type MeldSessionResponse, type PaymentNetwork, type ProjectConfigResponse, type QueryExecutionsRequest, type QueryExecutionsResponse, SOLANA_USDC_ADDRESS, type SupportedChain, type SupportedDepositTokensResponse, type SupportedToken, type TokenChain, type TokenChainIconUrl, type TokenChainsResponse, type UserIpInfo, type Wallet, createDepositAddress, createMeldSession, getApiBaseUrl, getChainName, getFiatCurrencies, getIconUrl, getIconUrlWithCdn, getIpAddress, getMeldQuotes, getPreferredIconUrl, getProjectConfig, getSupportedDepositTokens, getTokenChains, getWalletByChainType, i18n, queryExecutions, setApiConfig, useUserIp };
|
package/dist/index.js
CHANGED
|
@@ -29,6 +29,7 @@ __export(index_exports, {
|
|
|
29
29
|
getFiatCurrencies: () => getFiatCurrencies,
|
|
30
30
|
getIconUrl: () => getIconUrl,
|
|
31
31
|
getIconUrlWithCdn: () => getIconUrlWithCdn,
|
|
32
|
+
getIpAddress: () => getIpAddress,
|
|
32
33
|
getMeldQuotes: () => getMeldQuotes,
|
|
33
34
|
getPreferredIconUrl: () => getPreferredIconUrl,
|
|
34
35
|
getProjectConfig: () => getProjectConfig,
|
|
@@ -267,7 +268,9 @@ function getChainName(chains, chainType, chainId) {
|
|
|
267
268
|
async function getProjectConfig(publishableKey) {
|
|
268
269
|
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
269
270
|
validatePublishableKey(pk);
|
|
270
|
-
const
|
|
271
|
+
const url = `${API_BASE_URL}/v1/public/projects/config`;
|
|
272
|
+
console.log("[getProjectConfig] Fetching from:", url, "with key:", pk);
|
|
273
|
+
const response = await fetch(url, {
|
|
271
274
|
method: "GET",
|
|
272
275
|
headers: {
|
|
273
276
|
accept: "application/json",
|
|
@@ -277,45 +280,47 @@ async function getProjectConfig(publishableKey) {
|
|
|
277
280
|
if (!response.ok) {
|
|
278
281
|
throw new Error(`Failed to fetch project config: ${response.statusText}`);
|
|
279
282
|
}
|
|
283
|
+
const data = await response.json();
|
|
284
|
+
return data;
|
|
285
|
+
}
|
|
286
|
+
async function getIpAddress() {
|
|
287
|
+
const response = await fetch(`${API_BASE_URL}/v1/public/ip_address`, {
|
|
288
|
+
method: "GET",
|
|
289
|
+
headers: {
|
|
290
|
+
accept: "application/json"
|
|
291
|
+
}
|
|
292
|
+
});
|
|
293
|
+
if (!response.ok) {
|
|
294
|
+
throw new Error(
|
|
295
|
+
`Failed to fetch IP address information: ${response.statusText}`
|
|
296
|
+
);
|
|
297
|
+
}
|
|
280
298
|
return response.json();
|
|
281
299
|
}
|
|
282
300
|
|
|
283
301
|
// src/hooks/use-user-ip.ts
|
|
284
302
|
var import_react_query = require("@tanstack/react-query");
|
|
285
|
-
async function getIpViaIpApi() {
|
|
286
|
-
const url = "https://ipapi.co/json";
|
|
287
|
-
const response = await fetch(url);
|
|
288
|
-
if (!response.ok) {
|
|
289
|
-
throw new Error(`ipapi.co failed: ${response.statusText}`);
|
|
290
|
-
}
|
|
291
|
-
const data = await response.json();
|
|
292
|
-
return {
|
|
293
|
-
alpha2: data.country_code.toLowerCase(),
|
|
294
|
-
state: data.region_code?.toLowerCase()
|
|
295
|
-
};
|
|
296
|
-
}
|
|
297
303
|
function useUserIp() {
|
|
298
304
|
const {
|
|
299
305
|
data: userIpInfo,
|
|
300
306
|
isLoading,
|
|
301
307
|
error
|
|
302
308
|
} = (0, import_react_query.useQuery)({
|
|
303
|
-
queryKey: ["
|
|
309
|
+
queryKey: ["unifold", "userIpInfo"],
|
|
304
310
|
queryFn: async () => {
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
}
|
|
311
|
+
const data = await getIpAddress();
|
|
312
|
+
return {
|
|
313
|
+
alpha2: data.alpha2.toLowerCase(),
|
|
314
|
+
alpha3: data.alpha3?.toLowerCase(),
|
|
315
|
+
country: data.country,
|
|
316
|
+
state: data.state?.toLowerCase() ?? null,
|
|
317
|
+
ipAddress: data.ip_address
|
|
318
|
+
};
|
|
313
319
|
},
|
|
314
320
|
// Cache configuration to reduce API calls
|
|
315
321
|
refetchOnMount: false,
|
|
316
322
|
refetchOnReconnect: true,
|
|
317
323
|
refetchOnWindowFocus: false,
|
|
318
|
-
// Optional: Increase cache duration to 1 hour for even better rate limit protection
|
|
319
324
|
staleTime: 1e3 * 60 * 60,
|
|
320
325
|
// 1 hour - data considered fresh for 1 hour
|
|
321
326
|
gcTime: 1e3 * 60 * 60 * 24
|
|
@@ -407,6 +412,7 @@ var i18n = en_default;
|
|
|
407
412
|
getFiatCurrencies,
|
|
408
413
|
getIconUrl,
|
|
409
414
|
getIconUrlWithCdn,
|
|
415
|
+
getIpAddress,
|
|
410
416
|
getMeldQuotes,
|
|
411
417
|
getPreferredIconUrl,
|
|
412
418
|
getProjectConfig,
|
package/dist/index.mjs
CHANGED
|
@@ -223,7 +223,9 @@ function getChainName(chains, chainType, chainId) {
|
|
|
223
223
|
async function getProjectConfig(publishableKey) {
|
|
224
224
|
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
225
225
|
validatePublishableKey(pk);
|
|
226
|
-
const
|
|
226
|
+
const url = `${API_BASE_URL}/v1/public/projects/config`;
|
|
227
|
+
console.log("[getProjectConfig] Fetching from:", url, "with key:", pk);
|
|
228
|
+
const response = await fetch(url, {
|
|
227
229
|
method: "GET",
|
|
228
230
|
headers: {
|
|
229
231
|
accept: "application/json",
|
|
@@ -233,45 +235,47 @@ async function getProjectConfig(publishableKey) {
|
|
|
233
235
|
if (!response.ok) {
|
|
234
236
|
throw new Error(`Failed to fetch project config: ${response.statusText}`);
|
|
235
237
|
}
|
|
238
|
+
const data = await response.json();
|
|
239
|
+
return data;
|
|
240
|
+
}
|
|
241
|
+
async function getIpAddress() {
|
|
242
|
+
const response = await fetch(`${API_BASE_URL}/v1/public/ip_address`, {
|
|
243
|
+
method: "GET",
|
|
244
|
+
headers: {
|
|
245
|
+
accept: "application/json"
|
|
246
|
+
}
|
|
247
|
+
});
|
|
248
|
+
if (!response.ok) {
|
|
249
|
+
throw new Error(
|
|
250
|
+
`Failed to fetch IP address information: ${response.statusText}`
|
|
251
|
+
);
|
|
252
|
+
}
|
|
236
253
|
return response.json();
|
|
237
254
|
}
|
|
238
255
|
|
|
239
256
|
// src/hooks/use-user-ip.ts
|
|
240
257
|
import { useQuery } from "@tanstack/react-query";
|
|
241
|
-
async function getIpViaIpApi() {
|
|
242
|
-
const url = "https://ipapi.co/json";
|
|
243
|
-
const response = await fetch(url);
|
|
244
|
-
if (!response.ok) {
|
|
245
|
-
throw new Error(`ipapi.co failed: ${response.statusText}`);
|
|
246
|
-
}
|
|
247
|
-
const data = await response.json();
|
|
248
|
-
return {
|
|
249
|
-
alpha2: data.country_code.toLowerCase(),
|
|
250
|
-
state: data.region_code?.toLowerCase()
|
|
251
|
-
};
|
|
252
|
-
}
|
|
253
258
|
function useUserIp() {
|
|
254
259
|
const {
|
|
255
260
|
data: userIpInfo,
|
|
256
261
|
isLoading,
|
|
257
262
|
error
|
|
258
263
|
} = useQuery({
|
|
259
|
-
queryKey: ["
|
|
264
|
+
queryKey: ["unifold", "userIpInfo"],
|
|
260
265
|
queryFn: async () => {
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
}
|
|
266
|
+
const data = await getIpAddress();
|
|
267
|
+
return {
|
|
268
|
+
alpha2: data.alpha2.toLowerCase(),
|
|
269
|
+
alpha3: data.alpha3?.toLowerCase(),
|
|
270
|
+
country: data.country,
|
|
271
|
+
state: data.state?.toLowerCase() ?? null,
|
|
272
|
+
ipAddress: data.ip_address
|
|
273
|
+
};
|
|
269
274
|
},
|
|
270
275
|
// Cache configuration to reduce API calls
|
|
271
276
|
refetchOnMount: false,
|
|
272
277
|
refetchOnReconnect: true,
|
|
273
278
|
refetchOnWindowFocus: false,
|
|
274
|
-
// Optional: Increase cache duration to 1 hour for even better rate limit protection
|
|
275
279
|
staleTime: 1e3 * 60 * 60,
|
|
276
280
|
// 1 hour - data considered fresh for 1 hour
|
|
277
281
|
gcTime: 1e3 * 60 * 60 * 24
|
|
@@ -362,6 +366,7 @@ export {
|
|
|
362
366
|
getFiatCurrencies,
|
|
363
367
|
getIconUrl,
|
|
364
368
|
getIconUrlWithCdn,
|
|
369
|
+
getIpAddress,
|
|
365
370
|
getMeldQuotes,
|
|
366
371
|
getPreferredIconUrl,
|
|
367
372
|
getProjectConfig,
|