@unifold/core 0.1.21 → 0.1.23
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 +90 -1
- package/dist/index.d.ts +90 -1
- package/dist/index.js +75 -2
- package/dist/index.mjs +71 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -117,6 +117,7 @@ interface AutoSwapResponse {
|
|
|
117
117
|
};
|
|
118
118
|
source_currency?: string;
|
|
119
119
|
destination_currency?: string;
|
|
120
|
+
estimated_processing_time?: number | null;
|
|
120
121
|
}
|
|
121
122
|
declare const SOLANA_USDC_ADDRESS = "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v";
|
|
122
123
|
interface QueryExecutionsRequest {
|
|
@@ -307,6 +308,7 @@ interface DefaultTokenResponse {
|
|
|
307
308
|
destination_network: string;
|
|
308
309
|
destination_currency: string;
|
|
309
310
|
destination_token_metadata: DefaultTokenMetadata;
|
|
311
|
+
estimated_processing_time: number | null;
|
|
310
312
|
}
|
|
311
313
|
/**
|
|
312
314
|
* Get default onramp token for a given token/chain combination
|
|
@@ -384,6 +386,93 @@ interface IpAddressResponse {
|
|
|
384
386
|
* This is a public endpoint that doesn't require authentication
|
|
385
387
|
*/
|
|
386
388
|
declare function getIpAddress(): Promise<IpAddressResponse>;
|
|
389
|
+
interface TokenIconUrl {
|
|
390
|
+
url: string;
|
|
391
|
+
format: string;
|
|
392
|
+
}
|
|
393
|
+
interface TokenInfo {
|
|
394
|
+
symbol: string;
|
|
395
|
+
name: string;
|
|
396
|
+
icon_url: string;
|
|
397
|
+
icon_urls: TokenIconUrl[];
|
|
398
|
+
token_address: string;
|
|
399
|
+
chain_id: string;
|
|
400
|
+
chain_name: string;
|
|
401
|
+
chain_type: string;
|
|
402
|
+
decimals: number;
|
|
403
|
+
minimum_deposit_amount_usd: number;
|
|
404
|
+
chain_icon_url: string;
|
|
405
|
+
chain_icon_urls: TokenIconUrl[];
|
|
406
|
+
}
|
|
407
|
+
interface TokenBalance {
|
|
408
|
+
amount: string;
|
|
409
|
+
amount_usd: string | null;
|
|
410
|
+
exchange_rate: string | null;
|
|
411
|
+
is_eligible: boolean;
|
|
412
|
+
token: TokenInfo;
|
|
413
|
+
}
|
|
414
|
+
interface AddressBalancesResponse {
|
|
415
|
+
address: string;
|
|
416
|
+
chain_type: string;
|
|
417
|
+
balances: TokenBalance[];
|
|
418
|
+
}
|
|
419
|
+
/**
|
|
420
|
+
* Get token balances for a wallet address
|
|
421
|
+
* Returns balances for all supported deposit tokens on the specified chain type
|
|
422
|
+
* @param address - Wallet address to check balances for
|
|
423
|
+
* @param chainType - Chain type to fetch balances for ('ethereum', 'solana', or 'bitcoin')
|
|
424
|
+
* @param publishableKey - Optional publishable key, defaults to configured key
|
|
425
|
+
*/
|
|
426
|
+
declare function getAddressBalances(address: string, chainType: 'ethereum' | 'solana' | 'bitcoin', publishableKey?: string): Promise<AddressBalancesResponse>;
|
|
427
|
+
interface AddressBalanceResponse {
|
|
428
|
+
address: string;
|
|
429
|
+
chain_type: string;
|
|
430
|
+
chain_id: string;
|
|
431
|
+
token_address: string;
|
|
432
|
+
balance: TokenBalance | null;
|
|
433
|
+
}
|
|
434
|
+
/**
|
|
435
|
+
* Get balance for a specific token on a specific chain
|
|
436
|
+
* Returns the balance for a single token, or null if not found or zero balance
|
|
437
|
+
* @param address - Wallet address to check balance for
|
|
438
|
+
* @param chainType - Chain type ('ethereum', 'solana', or 'bitcoin')
|
|
439
|
+
* @param chainId - Chain ID (e.g., "1" for Ethereum mainnet)
|
|
440
|
+
* @param tokenAddress - Token contract address or "native" for native tokens
|
|
441
|
+
* @param publishableKey - Optional publishable key, defaults to configured key
|
|
442
|
+
*/
|
|
443
|
+
declare function getAddressBalance(address: string, chainType: 'ethereum' | 'solana' | 'bitcoin', chainId: string, tokenAddress: string, publishableKey?: string): Promise<AddressBalanceResponse>;
|
|
444
|
+
interface VerifyAddressRequest {
|
|
445
|
+
chain_type: string;
|
|
446
|
+
chain_id: string;
|
|
447
|
+
token_address: string;
|
|
448
|
+
recipient_address: string;
|
|
449
|
+
}
|
|
450
|
+
/**
|
|
451
|
+
* Standard error codes for address validation failures.
|
|
452
|
+
* Used by frontend to display localized error messages.
|
|
453
|
+
*/
|
|
454
|
+
type AddressValidationFailureCode = 'token_not_supported' | 'not_opted_in' | 'insufficient_balance' | 'account_not_found' | 'validation_error';
|
|
455
|
+
interface AddressValidationMetadata {
|
|
456
|
+
chain_name?: string;
|
|
457
|
+
token_symbol?: string;
|
|
458
|
+
}
|
|
459
|
+
interface VerifyAddressResponse {
|
|
460
|
+
valid: boolean;
|
|
461
|
+
/** Standardized error code for frontend i18n */
|
|
462
|
+
failure_code?: AddressValidationFailureCode;
|
|
463
|
+
/** Metadata for message interpolation */
|
|
464
|
+
metadata?: AddressValidationMetadata;
|
|
465
|
+
}
|
|
466
|
+
/**
|
|
467
|
+
* Verify if a recipient address can receive funds for a given chain/token
|
|
468
|
+
* This is useful to check before confirming a transfer, especially for Algorand
|
|
469
|
+
* where recipients must opt-in to assets before receiving them.
|
|
470
|
+
*
|
|
471
|
+
* @param request - Verification request with chain_type, chain_id, token_address, recipient_address
|
|
472
|
+
* @param publishableKey - Optional publishable key, defaults to configured key
|
|
473
|
+
* @returns Verification result with valid status and reason if invalid
|
|
474
|
+
*/
|
|
475
|
+
declare function verifyRecipientAddress(request: VerifyAddressRequest, publishableKey?: string): Promise<VerifyAddressResponse>;
|
|
387
476
|
|
|
388
477
|
/**
|
|
389
478
|
* User IP information interface
|
|
@@ -479,4 +568,4 @@ declare const i18n: {
|
|
|
479
568
|
};
|
|
480
569
|
type I18nStrings = typeof i18n;
|
|
481
570
|
|
|
482
|
-
export { type AutoSwapRequest, type AutoSwapResponse, type CreateDepositAddressRequest, type DefaultTokenChain, type DefaultTokenMetadata, type DefaultTokenResponse, type DepositAddressResponse, ExecutionStatus, type FeaturedToken, type FiatCurrenciesResponse, type FiatCurrency, type I18nStrings, type IconUrl, type IpAddressResponse, type OnrampQuote, type OnrampQuotesRequest, type OnrampQuotesResponse, type OnrampSessionRequest, type OnrampSessionResponse, type PaymentNetwork, type ProjectConfigResponse, type QueryExecutionsRequest, type QueryExecutionsResponse, SOLANA_USDC_ADDRESS, type SupportedChain, type SupportedDepositTokensResponse, type SupportedToken, type TokenChain, type TokenChainIconUrl, type TokenChainsResponse, type TokenMetadata, type UserIpInfo, type Wallet, createDepositAddress, createOnrampSession, getApiBaseUrl, getChainName, getDefaultOnrampToken, getFiatCurrencies, getIconUrl, getIconUrlWithCdn, getIpAddress, getOnrampQuotes, getOnrampSessionStartUrl, getPreferredIconUrl, getProjectConfig, getSupportedDepositTokens, getTokenChains, getTokenMetadata, getWalletByChainType, i18n, queryExecutions, setApiConfig, useUserIp };
|
|
571
|
+
export { type AddressBalanceResponse, type AddressBalancesResponse, type AddressValidationFailureCode, type AddressValidationMetadata, type AutoSwapRequest, type AutoSwapResponse, type CreateDepositAddressRequest, type DefaultTokenChain, type DefaultTokenMetadata, type DefaultTokenResponse, type DepositAddressResponse, ExecutionStatus, type FeaturedToken, type FiatCurrenciesResponse, type FiatCurrency, type I18nStrings, type IconUrl, type IpAddressResponse, type OnrampQuote, type OnrampQuotesRequest, type OnrampQuotesResponse, type OnrampSessionRequest, type OnrampSessionResponse, type PaymentNetwork, type ProjectConfigResponse, type QueryExecutionsRequest, type QueryExecutionsResponse, SOLANA_USDC_ADDRESS, type SupportedChain, type SupportedDepositTokensResponse, type SupportedToken, type TokenBalance, type TokenChain, type TokenChainIconUrl, type TokenChainsResponse, type TokenIconUrl, type TokenInfo, type TokenMetadata, type UserIpInfo, type VerifyAddressRequest, type VerifyAddressResponse, type Wallet, createDepositAddress, createOnrampSession, getAddressBalance, getAddressBalances, getApiBaseUrl, getChainName, getDefaultOnrampToken, getFiatCurrencies, getIconUrl, getIconUrlWithCdn, getIpAddress, getOnrampQuotes, getOnrampSessionStartUrl, getPreferredIconUrl, getProjectConfig, getSupportedDepositTokens, getTokenChains, getTokenMetadata, getWalletByChainType, i18n, queryExecutions, setApiConfig, useUserIp, verifyRecipientAddress };
|
package/dist/index.d.ts
CHANGED
|
@@ -117,6 +117,7 @@ interface AutoSwapResponse {
|
|
|
117
117
|
};
|
|
118
118
|
source_currency?: string;
|
|
119
119
|
destination_currency?: string;
|
|
120
|
+
estimated_processing_time?: number | null;
|
|
120
121
|
}
|
|
121
122
|
declare const SOLANA_USDC_ADDRESS = "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v";
|
|
122
123
|
interface QueryExecutionsRequest {
|
|
@@ -307,6 +308,7 @@ interface DefaultTokenResponse {
|
|
|
307
308
|
destination_network: string;
|
|
308
309
|
destination_currency: string;
|
|
309
310
|
destination_token_metadata: DefaultTokenMetadata;
|
|
311
|
+
estimated_processing_time: number | null;
|
|
310
312
|
}
|
|
311
313
|
/**
|
|
312
314
|
* Get default onramp token for a given token/chain combination
|
|
@@ -384,6 +386,93 @@ interface IpAddressResponse {
|
|
|
384
386
|
* This is a public endpoint that doesn't require authentication
|
|
385
387
|
*/
|
|
386
388
|
declare function getIpAddress(): Promise<IpAddressResponse>;
|
|
389
|
+
interface TokenIconUrl {
|
|
390
|
+
url: string;
|
|
391
|
+
format: string;
|
|
392
|
+
}
|
|
393
|
+
interface TokenInfo {
|
|
394
|
+
symbol: string;
|
|
395
|
+
name: string;
|
|
396
|
+
icon_url: string;
|
|
397
|
+
icon_urls: TokenIconUrl[];
|
|
398
|
+
token_address: string;
|
|
399
|
+
chain_id: string;
|
|
400
|
+
chain_name: string;
|
|
401
|
+
chain_type: string;
|
|
402
|
+
decimals: number;
|
|
403
|
+
minimum_deposit_amount_usd: number;
|
|
404
|
+
chain_icon_url: string;
|
|
405
|
+
chain_icon_urls: TokenIconUrl[];
|
|
406
|
+
}
|
|
407
|
+
interface TokenBalance {
|
|
408
|
+
amount: string;
|
|
409
|
+
amount_usd: string | null;
|
|
410
|
+
exchange_rate: string | null;
|
|
411
|
+
is_eligible: boolean;
|
|
412
|
+
token: TokenInfo;
|
|
413
|
+
}
|
|
414
|
+
interface AddressBalancesResponse {
|
|
415
|
+
address: string;
|
|
416
|
+
chain_type: string;
|
|
417
|
+
balances: TokenBalance[];
|
|
418
|
+
}
|
|
419
|
+
/**
|
|
420
|
+
* Get token balances for a wallet address
|
|
421
|
+
* Returns balances for all supported deposit tokens on the specified chain type
|
|
422
|
+
* @param address - Wallet address to check balances for
|
|
423
|
+
* @param chainType - Chain type to fetch balances for ('ethereum', 'solana', or 'bitcoin')
|
|
424
|
+
* @param publishableKey - Optional publishable key, defaults to configured key
|
|
425
|
+
*/
|
|
426
|
+
declare function getAddressBalances(address: string, chainType: 'ethereum' | 'solana' | 'bitcoin', publishableKey?: string): Promise<AddressBalancesResponse>;
|
|
427
|
+
interface AddressBalanceResponse {
|
|
428
|
+
address: string;
|
|
429
|
+
chain_type: string;
|
|
430
|
+
chain_id: string;
|
|
431
|
+
token_address: string;
|
|
432
|
+
balance: TokenBalance | null;
|
|
433
|
+
}
|
|
434
|
+
/**
|
|
435
|
+
* Get balance for a specific token on a specific chain
|
|
436
|
+
* Returns the balance for a single token, or null if not found or zero balance
|
|
437
|
+
* @param address - Wallet address to check balance for
|
|
438
|
+
* @param chainType - Chain type ('ethereum', 'solana', or 'bitcoin')
|
|
439
|
+
* @param chainId - Chain ID (e.g., "1" for Ethereum mainnet)
|
|
440
|
+
* @param tokenAddress - Token contract address or "native" for native tokens
|
|
441
|
+
* @param publishableKey - Optional publishable key, defaults to configured key
|
|
442
|
+
*/
|
|
443
|
+
declare function getAddressBalance(address: string, chainType: 'ethereum' | 'solana' | 'bitcoin', chainId: string, tokenAddress: string, publishableKey?: string): Promise<AddressBalanceResponse>;
|
|
444
|
+
interface VerifyAddressRequest {
|
|
445
|
+
chain_type: string;
|
|
446
|
+
chain_id: string;
|
|
447
|
+
token_address: string;
|
|
448
|
+
recipient_address: string;
|
|
449
|
+
}
|
|
450
|
+
/**
|
|
451
|
+
* Standard error codes for address validation failures.
|
|
452
|
+
* Used by frontend to display localized error messages.
|
|
453
|
+
*/
|
|
454
|
+
type AddressValidationFailureCode = 'token_not_supported' | 'not_opted_in' | 'insufficient_balance' | 'account_not_found' | 'validation_error';
|
|
455
|
+
interface AddressValidationMetadata {
|
|
456
|
+
chain_name?: string;
|
|
457
|
+
token_symbol?: string;
|
|
458
|
+
}
|
|
459
|
+
interface VerifyAddressResponse {
|
|
460
|
+
valid: boolean;
|
|
461
|
+
/** Standardized error code for frontend i18n */
|
|
462
|
+
failure_code?: AddressValidationFailureCode;
|
|
463
|
+
/** Metadata for message interpolation */
|
|
464
|
+
metadata?: AddressValidationMetadata;
|
|
465
|
+
}
|
|
466
|
+
/**
|
|
467
|
+
* Verify if a recipient address can receive funds for a given chain/token
|
|
468
|
+
* This is useful to check before confirming a transfer, especially for Algorand
|
|
469
|
+
* where recipients must opt-in to assets before receiving them.
|
|
470
|
+
*
|
|
471
|
+
* @param request - Verification request with chain_type, chain_id, token_address, recipient_address
|
|
472
|
+
* @param publishableKey - Optional publishable key, defaults to configured key
|
|
473
|
+
* @returns Verification result with valid status and reason if invalid
|
|
474
|
+
*/
|
|
475
|
+
declare function verifyRecipientAddress(request: VerifyAddressRequest, publishableKey?: string): Promise<VerifyAddressResponse>;
|
|
387
476
|
|
|
388
477
|
/**
|
|
389
478
|
* User IP information interface
|
|
@@ -479,4 +568,4 @@ declare const i18n: {
|
|
|
479
568
|
};
|
|
480
569
|
type I18nStrings = typeof i18n;
|
|
481
570
|
|
|
482
|
-
export { type AutoSwapRequest, type AutoSwapResponse, type CreateDepositAddressRequest, type DefaultTokenChain, type DefaultTokenMetadata, type DefaultTokenResponse, type DepositAddressResponse, ExecutionStatus, type FeaturedToken, type FiatCurrenciesResponse, type FiatCurrency, type I18nStrings, type IconUrl, type IpAddressResponse, type OnrampQuote, type OnrampQuotesRequest, type OnrampQuotesResponse, type OnrampSessionRequest, type OnrampSessionResponse, type PaymentNetwork, type ProjectConfigResponse, type QueryExecutionsRequest, type QueryExecutionsResponse, SOLANA_USDC_ADDRESS, type SupportedChain, type SupportedDepositTokensResponse, type SupportedToken, type TokenChain, type TokenChainIconUrl, type TokenChainsResponse, type TokenMetadata, type UserIpInfo, type Wallet, createDepositAddress, createOnrampSession, getApiBaseUrl, getChainName, getDefaultOnrampToken, getFiatCurrencies, getIconUrl, getIconUrlWithCdn, getIpAddress, getOnrampQuotes, getOnrampSessionStartUrl, getPreferredIconUrl, getProjectConfig, getSupportedDepositTokens, getTokenChains, getTokenMetadata, getWalletByChainType, i18n, queryExecutions, setApiConfig, useUserIp };
|
|
571
|
+
export { type AddressBalanceResponse, type AddressBalancesResponse, type AddressValidationFailureCode, type AddressValidationMetadata, type AutoSwapRequest, type AutoSwapResponse, type CreateDepositAddressRequest, type DefaultTokenChain, type DefaultTokenMetadata, type DefaultTokenResponse, type DepositAddressResponse, ExecutionStatus, type FeaturedToken, type FiatCurrenciesResponse, type FiatCurrency, type I18nStrings, type IconUrl, type IpAddressResponse, type OnrampQuote, type OnrampQuotesRequest, type OnrampQuotesResponse, type OnrampSessionRequest, type OnrampSessionResponse, type PaymentNetwork, type ProjectConfigResponse, type QueryExecutionsRequest, type QueryExecutionsResponse, SOLANA_USDC_ADDRESS, type SupportedChain, type SupportedDepositTokensResponse, type SupportedToken, type TokenBalance, type TokenChain, type TokenChainIconUrl, type TokenChainsResponse, type TokenIconUrl, type TokenInfo, type TokenMetadata, type UserIpInfo, type VerifyAddressRequest, type VerifyAddressResponse, type Wallet, createDepositAddress, createOnrampSession, getAddressBalance, getAddressBalances, getApiBaseUrl, getChainName, getDefaultOnrampToken, getFiatCurrencies, getIconUrl, getIconUrlWithCdn, getIpAddress, getOnrampQuotes, getOnrampSessionStartUrl, getPreferredIconUrl, getProjectConfig, getSupportedDepositTokens, getTokenChains, getTokenMetadata, getWalletByChainType, i18n, queryExecutions, setApiConfig, useUserIp, verifyRecipientAddress };
|
package/dist/index.js
CHANGED
|
@@ -24,6 +24,8 @@ __export(index_exports, {
|
|
|
24
24
|
SOLANA_USDC_ADDRESS: () => SOLANA_USDC_ADDRESS,
|
|
25
25
|
createDepositAddress: () => createDepositAddress,
|
|
26
26
|
createOnrampSession: () => createOnrampSession,
|
|
27
|
+
getAddressBalance: () => getAddressBalance,
|
|
28
|
+
getAddressBalances: () => getAddressBalances,
|
|
27
29
|
getApiBaseUrl: () => getApiBaseUrl,
|
|
28
30
|
getChainName: () => getChainName,
|
|
29
31
|
getDefaultOnrampToken: () => getDefaultOnrampToken,
|
|
@@ -42,7 +44,8 @@ __export(index_exports, {
|
|
|
42
44
|
i18n: () => i18n,
|
|
43
45
|
queryExecutions: () => queryExecutions,
|
|
44
46
|
setApiConfig: () => setApiConfig,
|
|
45
|
-
useUserIp: () => useUserIp
|
|
47
|
+
useUserIp: () => useUserIp,
|
|
48
|
+
verifyRecipientAddress: () => verifyRecipientAddress
|
|
46
49
|
});
|
|
47
50
|
module.exports = __toCommonJS(index_exports);
|
|
48
51
|
|
|
@@ -330,12 +333,14 @@ async function getTokenChains() {
|
|
|
330
333
|
return response.json();
|
|
331
334
|
}
|
|
332
335
|
function getChainName(chains, chainType, chainId) {
|
|
336
|
+
if (!chainType && !chainId) return "Unknown";
|
|
333
337
|
const target = chains.find((c) => c.chain_id === chainId && c.chain_type === chainType);
|
|
334
338
|
if (target) return target.chain_name;
|
|
335
339
|
const byId = chains.find((c) => c.chain_id === chainId);
|
|
336
340
|
if (byId) return byId.chain_name;
|
|
337
341
|
const byType = chains.find((c) => c.chain_type === chainType);
|
|
338
342
|
if (byType) return byType.chain_name;
|
|
343
|
+
if (!chainType) return chainId || "Unknown";
|
|
339
344
|
return chainType.charAt(0).toUpperCase() + chainType.slice(1);
|
|
340
345
|
}
|
|
341
346
|
async function getProjectConfig(publishableKey) {
|
|
@@ -369,6 +374,71 @@ async function getIpAddress() {
|
|
|
369
374
|
}
|
|
370
375
|
return response.json();
|
|
371
376
|
}
|
|
377
|
+
async function getAddressBalances(address, chainType, publishableKey) {
|
|
378
|
+
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
379
|
+
validatePublishableKey(pk);
|
|
380
|
+
const url = `${API_BASE_URL}/v1/public/addresses/balances`;
|
|
381
|
+
const response = await fetch(url, {
|
|
382
|
+
method: "POST",
|
|
383
|
+
headers: {
|
|
384
|
+
"Content-Type": "application/json",
|
|
385
|
+
accept: "application/json",
|
|
386
|
+
"x-publishable-key": pk
|
|
387
|
+
},
|
|
388
|
+
body: JSON.stringify({
|
|
389
|
+
address,
|
|
390
|
+
chain_type: chainType
|
|
391
|
+
})
|
|
392
|
+
});
|
|
393
|
+
if (!response.ok) {
|
|
394
|
+
throw new Error(`Failed to fetch address balances: ${response.statusText}`);
|
|
395
|
+
}
|
|
396
|
+
const data = await response.json();
|
|
397
|
+
return data;
|
|
398
|
+
}
|
|
399
|
+
async function getAddressBalance(address, chainType, chainId, tokenAddress, publishableKey) {
|
|
400
|
+
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
401
|
+
validatePublishableKey(pk);
|
|
402
|
+
const url = `${API_BASE_URL}/v1/public/addresses/balance`;
|
|
403
|
+
const response = await fetch(url, {
|
|
404
|
+
method: "POST",
|
|
405
|
+
headers: {
|
|
406
|
+
"Content-Type": "application/json",
|
|
407
|
+
accept: "application/json",
|
|
408
|
+
"x-publishable-key": pk
|
|
409
|
+
},
|
|
410
|
+
body: JSON.stringify({
|
|
411
|
+
address,
|
|
412
|
+
chain_type: chainType,
|
|
413
|
+
chain_id: chainId,
|
|
414
|
+
token_address: tokenAddress
|
|
415
|
+
})
|
|
416
|
+
});
|
|
417
|
+
if (!response.ok) {
|
|
418
|
+
throw new Error(`Failed to fetch address balance: ${response.statusText}`);
|
|
419
|
+
}
|
|
420
|
+
const data = await response.json();
|
|
421
|
+
return data;
|
|
422
|
+
}
|
|
423
|
+
async function verifyRecipientAddress(request, publishableKey) {
|
|
424
|
+
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
425
|
+
validatePublishableKey(pk);
|
|
426
|
+
const response = await fetch(`${API_BASE_URL}/v1/public/addresses/verify`, {
|
|
427
|
+
method: "POST",
|
|
428
|
+
headers: {
|
|
429
|
+
accept: "application/json",
|
|
430
|
+
"x-publishable-key": pk,
|
|
431
|
+
"Content-Type": "application/json"
|
|
432
|
+
},
|
|
433
|
+
body: JSON.stringify(request)
|
|
434
|
+
});
|
|
435
|
+
if (!response.ok) {
|
|
436
|
+
throw new Error(
|
|
437
|
+
`Failed to verify recipient address: ${response.statusText}`
|
|
438
|
+
);
|
|
439
|
+
}
|
|
440
|
+
return response.json();
|
|
441
|
+
}
|
|
372
442
|
|
|
373
443
|
// src/hooks/use-user-ip.ts
|
|
374
444
|
var import_react_query = require("@tanstack/react-query");
|
|
@@ -479,6 +549,8 @@ var i18n = en_default;
|
|
|
479
549
|
SOLANA_USDC_ADDRESS,
|
|
480
550
|
createDepositAddress,
|
|
481
551
|
createOnrampSession,
|
|
552
|
+
getAddressBalance,
|
|
553
|
+
getAddressBalances,
|
|
482
554
|
getApiBaseUrl,
|
|
483
555
|
getChainName,
|
|
484
556
|
getDefaultOnrampToken,
|
|
@@ -497,5 +569,6 @@ var i18n = en_default;
|
|
|
497
569
|
i18n,
|
|
498
570
|
queryExecutions,
|
|
499
571
|
setApiConfig,
|
|
500
|
-
useUserIp
|
|
572
|
+
useUserIp,
|
|
573
|
+
verifyRecipientAddress
|
|
501
574
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -282,12 +282,14 @@ async function getTokenChains() {
|
|
|
282
282
|
return response.json();
|
|
283
283
|
}
|
|
284
284
|
function getChainName(chains, chainType, chainId) {
|
|
285
|
+
if (!chainType && !chainId) return "Unknown";
|
|
285
286
|
const target = chains.find((c) => c.chain_id === chainId && c.chain_type === chainType);
|
|
286
287
|
if (target) return target.chain_name;
|
|
287
288
|
const byId = chains.find((c) => c.chain_id === chainId);
|
|
288
289
|
if (byId) return byId.chain_name;
|
|
289
290
|
const byType = chains.find((c) => c.chain_type === chainType);
|
|
290
291
|
if (byType) return byType.chain_name;
|
|
292
|
+
if (!chainType) return chainId || "Unknown";
|
|
291
293
|
return chainType.charAt(0).toUpperCase() + chainType.slice(1);
|
|
292
294
|
}
|
|
293
295
|
async function getProjectConfig(publishableKey) {
|
|
@@ -321,6 +323,71 @@ async function getIpAddress() {
|
|
|
321
323
|
}
|
|
322
324
|
return response.json();
|
|
323
325
|
}
|
|
326
|
+
async function getAddressBalances(address, chainType, publishableKey) {
|
|
327
|
+
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
328
|
+
validatePublishableKey(pk);
|
|
329
|
+
const url = `${API_BASE_URL}/v1/public/addresses/balances`;
|
|
330
|
+
const response = await fetch(url, {
|
|
331
|
+
method: "POST",
|
|
332
|
+
headers: {
|
|
333
|
+
"Content-Type": "application/json",
|
|
334
|
+
accept: "application/json",
|
|
335
|
+
"x-publishable-key": pk
|
|
336
|
+
},
|
|
337
|
+
body: JSON.stringify({
|
|
338
|
+
address,
|
|
339
|
+
chain_type: chainType
|
|
340
|
+
})
|
|
341
|
+
});
|
|
342
|
+
if (!response.ok) {
|
|
343
|
+
throw new Error(`Failed to fetch address balances: ${response.statusText}`);
|
|
344
|
+
}
|
|
345
|
+
const data = await response.json();
|
|
346
|
+
return data;
|
|
347
|
+
}
|
|
348
|
+
async function getAddressBalance(address, chainType, chainId, tokenAddress, publishableKey) {
|
|
349
|
+
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
350
|
+
validatePublishableKey(pk);
|
|
351
|
+
const url = `${API_BASE_URL}/v1/public/addresses/balance`;
|
|
352
|
+
const response = await fetch(url, {
|
|
353
|
+
method: "POST",
|
|
354
|
+
headers: {
|
|
355
|
+
"Content-Type": "application/json",
|
|
356
|
+
accept: "application/json",
|
|
357
|
+
"x-publishable-key": pk
|
|
358
|
+
},
|
|
359
|
+
body: JSON.stringify({
|
|
360
|
+
address,
|
|
361
|
+
chain_type: chainType,
|
|
362
|
+
chain_id: chainId,
|
|
363
|
+
token_address: tokenAddress
|
|
364
|
+
})
|
|
365
|
+
});
|
|
366
|
+
if (!response.ok) {
|
|
367
|
+
throw new Error(`Failed to fetch address balance: ${response.statusText}`);
|
|
368
|
+
}
|
|
369
|
+
const data = await response.json();
|
|
370
|
+
return data;
|
|
371
|
+
}
|
|
372
|
+
async function verifyRecipientAddress(request, publishableKey) {
|
|
373
|
+
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
374
|
+
validatePublishableKey(pk);
|
|
375
|
+
const response = await fetch(`${API_BASE_URL}/v1/public/addresses/verify`, {
|
|
376
|
+
method: "POST",
|
|
377
|
+
headers: {
|
|
378
|
+
accept: "application/json",
|
|
379
|
+
"x-publishable-key": pk,
|
|
380
|
+
"Content-Type": "application/json"
|
|
381
|
+
},
|
|
382
|
+
body: JSON.stringify(request)
|
|
383
|
+
});
|
|
384
|
+
if (!response.ok) {
|
|
385
|
+
throw new Error(
|
|
386
|
+
`Failed to verify recipient address: ${response.statusText}`
|
|
387
|
+
);
|
|
388
|
+
}
|
|
389
|
+
return response.json();
|
|
390
|
+
}
|
|
324
391
|
|
|
325
392
|
// src/hooks/use-user-ip.ts
|
|
326
393
|
import { useQuery } from "@tanstack/react-query";
|
|
@@ -430,6 +497,8 @@ export {
|
|
|
430
497
|
SOLANA_USDC_ADDRESS,
|
|
431
498
|
createDepositAddress,
|
|
432
499
|
createOnrampSession,
|
|
500
|
+
getAddressBalance,
|
|
501
|
+
getAddressBalances,
|
|
433
502
|
getApiBaseUrl,
|
|
434
503
|
getChainName,
|
|
435
504
|
getDefaultOnrampToken,
|
|
@@ -448,5 +517,6 @@ export {
|
|
|
448
517
|
i18n,
|
|
449
518
|
queryExecutions,
|
|
450
519
|
setApiConfig,
|
|
451
|
-
useUserIp
|
|
520
|
+
useUserIp,
|
|
521
|
+
verifyRecipientAddress
|
|
452
522
|
};
|