@unifold/core 0.1.27 → 0.1.29
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 +73 -3
- package/dist/index.d.ts +73 -3
- package/dist/index.js +70 -0
- package/dist/index.mjs +67 -0
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
type ChainType = 'ethereum' | 'solana' | 'bitcoin' | 'algorand' | 'xrpl';
|
|
2
|
+
|
|
1
3
|
declare function setApiConfig(config: {
|
|
2
4
|
baseUrl?: string;
|
|
3
5
|
publishableKey?: string;
|
|
@@ -383,6 +385,9 @@ interface ProjectConfigResponse {
|
|
|
383
385
|
networks: PaymentNetwork[];
|
|
384
386
|
};
|
|
385
387
|
blocked_country_codes?: string[];
|
|
388
|
+
pay_with_exchange?: {
|
|
389
|
+
enabled: boolean;
|
|
390
|
+
};
|
|
386
391
|
}
|
|
387
392
|
/**
|
|
388
393
|
* Get project configuration
|
|
@@ -444,7 +449,7 @@ interface AddressBalancesResponse {
|
|
|
444
449
|
* @param chainType - Chain type to fetch balances for ('ethereum', 'solana', or 'bitcoin')
|
|
445
450
|
* @param publishableKey - Optional publishable key, defaults to configured key
|
|
446
451
|
*/
|
|
447
|
-
declare function getAddressBalances(address: string, chainType:
|
|
452
|
+
declare function getAddressBalances(address: string, chainType: ChainType, publishableKey?: string): Promise<AddressBalancesResponse>;
|
|
448
453
|
interface AddressBalanceResponse {
|
|
449
454
|
address: string;
|
|
450
455
|
chain_type: string;
|
|
@@ -461,7 +466,7 @@ interface AddressBalanceResponse {
|
|
|
461
466
|
* @param tokenAddress - Token contract address or "native" for native tokens
|
|
462
467
|
* @param publishableKey - Optional publishable key, defaults to configured key
|
|
463
468
|
*/
|
|
464
|
-
declare function getAddressBalance(address: string, chainType:
|
|
469
|
+
declare function getAddressBalance(address: string, chainType: ChainType, chainId: string, tokenAddress: string, publishableKey?: string): Promise<AddressBalanceResponse>;
|
|
465
470
|
interface VerifyAddressRequest {
|
|
466
471
|
chain_type: string;
|
|
467
472
|
chain_id: string;
|
|
@@ -494,6 +499,71 @@ interface VerifyAddressResponse {
|
|
|
494
499
|
* @returns Verification result with valid status and reason if invalid
|
|
495
500
|
*/
|
|
496
501
|
declare function verifyRecipientAddress(request: VerifyAddressRequest, publishableKey?: string): Promise<VerifyAddressResponse>;
|
|
502
|
+
interface ExchangeProviderInfo {
|
|
503
|
+
service_provider: string;
|
|
504
|
+
service_provider_display_name: string;
|
|
505
|
+
description: string;
|
|
506
|
+
icon_url: string;
|
|
507
|
+
icon_urls: IconUrl[];
|
|
508
|
+
enabled: boolean;
|
|
509
|
+
supported_networks: string[];
|
|
510
|
+
supported_currencies: string[];
|
|
511
|
+
}
|
|
512
|
+
interface ExchangeProvidersResponse {
|
|
513
|
+
data: ExchangeProviderInfo[];
|
|
514
|
+
}
|
|
515
|
+
interface GetExchangesQuery {
|
|
516
|
+
country_code?: string;
|
|
517
|
+
destination_currency?: string;
|
|
518
|
+
destination_network?: string;
|
|
519
|
+
source_amount?: string;
|
|
520
|
+
source_currency?: string;
|
|
521
|
+
}
|
|
522
|
+
/**
|
|
523
|
+
* Get available exchange providers for "Pay with Exchange"
|
|
524
|
+
* @param query - Optional filters (destination_currency, destination_network)
|
|
525
|
+
* @param publishableKey - Optional publishable key, defaults to configured key
|
|
526
|
+
*/
|
|
527
|
+
declare function getExchanges(query?: GetExchangesQuery, publishableKey?: string): Promise<ExchangeProvidersResponse>;
|
|
528
|
+
interface ExchangeWalletAddress {
|
|
529
|
+
address: string;
|
|
530
|
+
chain_type: string;
|
|
531
|
+
}
|
|
532
|
+
interface CreateExchangeSessionRequest {
|
|
533
|
+
service_provider: string;
|
|
534
|
+
wallet_addresses: ExchangeWalletAddress[];
|
|
535
|
+
preferred_destination_currency?: string;
|
|
536
|
+
preferred_destination_network?: string;
|
|
537
|
+
source_currency?: string;
|
|
538
|
+
source_amount?: string;
|
|
539
|
+
external_id?: string;
|
|
540
|
+
}
|
|
541
|
+
interface CreateExchangeSessionResponse {
|
|
542
|
+
url: string;
|
|
543
|
+
service_provider: string;
|
|
544
|
+
external_id: string;
|
|
545
|
+
}
|
|
546
|
+
/**
|
|
547
|
+
* Create an exchange session for "Pay with Exchange"
|
|
548
|
+
* @param request - Exchange session request
|
|
549
|
+
* @param publishableKey - Optional publishable key, defaults to configured key
|
|
550
|
+
*/
|
|
551
|
+
declare function createExchangeSession(request: CreateExchangeSessionRequest, publishableKey?: string): Promise<CreateExchangeSessionResponse>;
|
|
552
|
+
interface ExchangeSessionStartParams {
|
|
553
|
+
service_provider: string;
|
|
554
|
+
chain_type: string;
|
|
555
|
+
address: string;
|
|
556
|
+
preferred_destination_currency?: string;
|
|
557
|
+
preferred_destination_network?: string;
|
|
558
|
+
source_currency?: string;
|
|
559
|
+
source_amount?: string;
|
|
560
|
+
external_id?: string;
|
|
561
|
+
}
|
|
562
|
+
/**
|
|
563
|
+
* Generate a URL for the exchanges/sessions/start endpoint that redirects to the exchange provider.
|
|
564
|
+
* This avoids popup blockers in Safari by opening the URL directly via anchor tag or window.open().
|
|
565
|
+
*/
|
|
566
|
+
declare function getExchangeSessionStartUrl(request: ExchangeSessionStartParams, publishableKey: string): string;
|
|
497
567
|
interface BuildSolanaTransactionRequest {
|
|
498
568
|
chain_id: string;
|
|
499
569
|
token_address: string;
|
|
@@ -631,4 +701,4 @@ declare const i18n: {
|
|
|
631
701
|
};
|
|
632
702
|
type I18nStrings = typeof i18n;
|
|
633
703
|
|
|
634
|
-
export { type AddressBalanceResponse, type AddressBalancesResponse, type AddressValidationFailureCode, type AddressValidationMetadata, type AutoSwapRequest, type AutoSwapResponse, type BuildSolanaTransactionRequest, type BuildSolanaTransactionResponse, type CreateDepositAddressRequest, type DefaultTokenChain, type DefaultTokenMetadata, type DefaultTokenResponse, type DepositAddressResponse, ExecutionStatus, type FeaturedToken, type FiatCurrenciesResponse, type FiatCurrency, type I18nStrings, type IconUrl, IneligibilityReason, type IpAddressResponse, type OnrampQuote, type OnrampQuotesRequest, type OnrampQuotesResponse, type OnrampSessionRequest, type OnrampSessionResponse, type PaymentNetwork, type PollExecutionsRequest, type PollExecutionsResponse, type ProjectConfigResponse, type QueryExecutionsRequest, type QueryExecutionsResponse, SOLANA_USDC_ADDRESS, type SendSolanaTransactionRequest, type SendSolanaTransactionResponse, 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, buildSolanaTransaction, createDepositAddress, createOnrampSession, getAddressBalance, getAddressBalances, getApiBaseUrl, getChainName, getDefaultOnrampToken, getFiatCurrencies, getIconUrl, getIconUrlWithCdn, getIpAddress, getOnrampQuotes, getOnrampSessionStartUrl, getPreferredIconUrl, getProjectConfig, getSupportedDepositTokens, getTokenChains, getTokenMetadata, getWalletByChainType, i18n, pollDirectExecutions, queryExecutions, sendSolanaTransaction, setApiConfig, useUserIp, verifyRecipientAddress };
|
|
704
|
+
export { type AddressBalanceResponse, type AddressBalancesResponse, type AddressValidationFailureCode, type AddressValidationMetadata, type AutoSwapRequest, type AutoSwapResponse, type BuildSolanaTransactionRequest, type BuildSolanaTransactionResponse, type ChainType, type CreateDepositAddressRequest, type CreateExchangeSessionRequest, type CreateExchangeSessionResponse, type DefaultTokenChain, type DefaultTokenMetadata, type DefaultTokenResponse, type DepositAddressResponse, type ExchangeProviderInfo, type ExchangeProvidersResponse, type ExchangeSessionStartParams, type ExchangeWalletAddress, ExecutionStatus, type FeaturedToken, type FiatCurrenciesResponse, type FiatCurrency, type GetExchangesQuery, type I18nStrings, type IconUrl, IneligibilityReason, type IpAddressResponse, type OnrampQuote, type OnrampQuotesRequest, type OnrampQuotesResponse, type OnrampSessionRequest, type OnrampSessionResponse, type PaymentNetwork, type PollExecutionsRequest, type PollExecutionsResponse, type ProjectConfigResponse, type QueryExecutionsRequest, type QueryExecutionsResponse, SOLANA_USDC_ADDRESS, type SendSolanaTransactionRequest, type SendSolanaTransactionResponse, 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, buildSolanaTransaction, createDepositAddress, createExchangeSession, createOnrampSession, getAddressBalance, getAddressBalances, getApiBaseUrl, getChainName, getDefaultOnrampToken, getExchangeSessionStartUrl, getExchanges, getFiatCurrencies, getIconUrl, getIconUrlWithCdn, getIpAddress, getOnrampQuotes, getOnrampSessionStartUrl, getPreferredIconUrl, getProjectConfig, getSupportedDepositTokens, getTokenChains, getTokenMetadata, getWalletByChainType, i18n, pollDirectExecutions, queryExecutions, sendSolanaTransaction, setApiConfig, useUserIp, verifyRecipientAddress };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
type ChainType = 'ethereum' | 'solana' | 'bitcoin' | 'algorand' | 'xrpl';
|
|
2
|
+
|
|
1
3
|
declare function setApiConfig(config: {
|
|
2
4
|
baseUrl?: string;
|
|
3
5
|
publishableKey?: string;
|
|
@@ -383,6 +385,9 @@ interface ProjectConfigResponse {
|
|
|
383
385
|
networks: PaymentNetwork[];
|
|
384
386
|
};
|
|
385
387
|
blocked_country_codes?: string[];
|
|
388
|
+
pay_with_exchange?: {
|
|
389
|
+
enabled: boolean;
|
|
390
|
+
};
|
|
386
391
|
}
|
|
387
392
|
/**
|
|
388
393
|
* Get project configuration
|
|
@@ -444,7 +449,7 @@ interface AddressBalancesResponse {
|
|
|
444
449
|
* @param chainType - Chain type to fetch balances for ('ethereum', 'solana', or 'bitcoin')
|
|
445
450
|
* @param publishableKey - Optional publishable key, defaults to configured key
|
|
446
451
|
*/
|
|
447
|
-
declare function getAddressBalances(address: string, chainType:
|
|
452
|
+
declare function getAddressBalances(address: string, chainType: ChainType, publishableKey?: string): Promise<AddressBalancesResponse>;
|
|
448
453
|
interface AddressBalanceResponse {
|
|
449
454
|
address: string;
|
|
450
455
|
chain_type: string;
|
|
@@ -461,7 +466,7 @@ interface AddressBalanceResponse {
|
|
|
461
466
|
* @param tokenAddress - Token contract address or "native" for native tokens
|
|
462
467
|
* @param publishableKey - Optional publishable key, defaults to configured key
|
|
463
468
|
*/
|
|
464
|
-
declare function getAddressBalance(address: string, chainType:
|
|
469
|
+
declare function getAddressBalance(address: string, chainType: ChainType, chainId: string, tokenAddress: string, publishableKey?: string): Promise<AddressBalanceResponse>;
|
|
465
470
|
interface VerifyAddressRequest {
|
|
466
471
|
chain_type: string;
|
|
467
472
|
chain_id: string;
|
|
@@ -494,6 +499,71 @@ interface VerifyAddressResponse {
|
|
|
494
499
|
* @returns Verification result with valid status and reason if invalid
|
|
495
500
|
*/
|
|
496
501
|
declare function verifyRecipientAddress(request: VerifyAddressRequest, publishableKey?: string): Promise<VerifyAddressResponse>;
|
|
502
|
+
interface ExchangeProviderInfo {
|
|
503
|
+
service_provider: string;
|
|
504
|
+
service_provider_display_name: string;
|
|
505
|
+
description: string;
|
|
506
|
+
icon_url: string;
|
|
507
|
+
icon_urls: IconUrl[];
|
|
508
|
+
enabled: boolean;
|
|
509
|
+
supported_networks: string[];
|
|
510
|
+
supported_currencies: string[];
|
|
511
|
+
}
|
|
512
|
+
interface ExchangeProvidersResponse {
|
|
513
|
+
data: ExchangeProviderInfo[];
|
|
514
|
+
}
|
|
515
|
+
interface GetExchangesQuery {
|
|
516
|
+
country_code?: string;
|
|
517
|
+
destination_currency?: string;
|
|
518
|
+
destination_network?: string;
|
|
519
|
+
source_amount?: string;
|
|
520
|
+
source_currency?: string;
|
|
521
|
+
}
|
|
522
|
+
/**
|
|
523
|
+
* Get available exchange providers for "Pay with Exchange"
|
|
524
|
+
* @param query - Optional filters (destination_currency, destination_network)
|
|
525
|
+
* @param publishableKey - Optional publishable key, defaults to configured key
|
|
526
|
+
*/
|
|
527
|
+
declare function getExchanges(query?: GetExchangesQuery, publishableKey?: string): Promise<ExchangeProvidersResponse>;
|
|
528
|
+
interface ExchangeWalletAddress {
|
|
529
|
+
address: string;
|
|
530
|
+
chain_type: string;
|
|
531
|
+
}
|
|
532
|
+
interface CreateExchangeSessionRequest {
|
|
533
|
+
service_provider: string;
|
|
534
|
+
wallet_addresses: ExchangeWalletAddress[];
|
|
535
|
+
preferred_destination_currency?: string;
|
|
536
|
+
preferred_destination_network?: string;
|
|
537
|
+
source_currency?: string;
|
|
538
|
+
source_amount?: string;
|
|
539
|
+
external_id?: string;
|
|
540
|
+
}
|
|
541
|
+
interface CreateExchangeSessionResponse {
|
|
542
|
+
url: string;
|
|
543
|
+
service_provider: string;
|
|
544
|
+
external_id: string;
|
|
545
|
+
}
|
|
546
|
+
/**
|
|
547
|
+
* Create an exchange session for "Pay with Exchange"
|
|
548
|
+
* @param request - Exchange session request
|
|
549
|
+
* @param publishableKey - Optional publishable key, defaults to configured key
|
|
550
|
+
*/
|
|
551
|
+
declare function createExchangeSession(request: CreateExchangeSessionRequest, publishableKey?: string): Promise<CreateExchangeSessionResponse>;
|
|
552
|
+
interface ExchangeSessionStartParams {
|
|
553
|
+
service_provider: string;
|
|
554
|
+
chain_type: string;
|
|
555
|
+
address: string;
|
|
556
|
+
preferred_destination_currency?: string;
|
|
557
|
+
preferred_destination_network?: string;
|
|
558
|
+
source_currency?: string;
|
|
559
|
+
source_amount?: string;
|
|
560
|
+
external_id?: string;
|
|
561
|
+
}
|
|
562
|
+
/**
|
|
563
|
+
* Generate a URL for the exchanges/sessions/start endpoint that redirects to the exchange provider.
|
|
564
|
+
* This avoids popup blockers in Safari by opening the URL directly via anchor tag or window.open().
|
|
565
|
+
*/
|
|
566
|
+
declare function getExchangeSessionStartUrl(request: ExchangeSessionStartParams, publishableKey: string): string;
|
|
497
567
|
interface BuildSolanaTransactionRequest {
|
|
498
568
|
chain_id: string;
|
|
499
569
|
token_address: string;
|
|
@@ -631,4 +701,4 @@ declare const i18n: {
|
|
|
631
701
|
};
|
|
632
702
|
type I18nStrings = typeof i18n;
|
|
633
703
|
|
|
634
|
-
export { type AddressBalanceResponse, type AddressBalancesResponse, type AddressValidationFailureCode, type AddressValidationMetadata, type AutoSwapRequest, type AutoSwapResponse, type BuildSolanaTransactionRequest, type BuildSolanaTransactionResponse, type CreateDepositAddressRequest, type DefaultTokenChain, type DefaultTokenMetadata, type DefaultTokenResponse, type DepositAddressResponse, ExecutionStatus, type FeaturedToken, type FiatCurrenciesResponse, type FiatCurrency, type I18nStrings, type IconUrl, IneligibilityReason, type IpAddressResponse, type OnrampQuote, type OnrampQuotesRequest, type OnrampQuotesResponse, type OnrampSessionRequest, type OnrampSessionResponse, type PaymentNetwork, type PollExecutionsRequest, type PollExecutionsResponse, type ProjectConfigResponse, type QueryExecutionsRequest, type QueryExecutionsResponse, SOLANA_USDC_ADDRESS, type SendSolanaTransactionRequest, type SendSolanaTransactionResponse, 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, buildSolanaTransaction, createDepositAddress, createOnrampSession, getAddressBalance, getAddressBalances, getApiBaseUrl, getChainName, getDefaultOnrampToken, getFiatCurrencies, getIconUrl, getIconUrlWithCdn, getIpAddress, getOnrampQuotes, getOnrampSessionStartUrl, getPreferredIconUrl, getProjectConfig, getSupportedDepositTokens, getTokenChains, getTokenMetadata, getWalletByChainType, i18n, pollDirectExecutions, queryExecutions, sendSolanaTransaction, setApiConfig, useUserIp, verifyRecipientAddress };
|
|
704
|
+
export { type AddressBalanceResponse, type AddressBalancesResponse, type AddressValidationFailureCode, type AddressValidationMetadata, type AutoSwapRequest, type AutoSwapResponse, type BuildSolanaTransactionRequest, type BuildSolanaTransactionResponse, type ChainType, type CreateDepositAddressRequest, type CreateExchangeSessionRequest, type CreateExchangeSessionResponse, type DefaultTokenChain, type DefaultTokenMetadata, type DefaultTokenResponse, type DepositAddressResponse, type ExchangeProviderInfo, type ExchangeProvidersResponse, type ExchangeSessionStartParams, type ExchangeWalletAddress, ExecutionStatus, type FeaturedToken, type FiatCurrenciesResponse, type FiatCurrency, type GetExchangesQuery, type I18nStrings, type IconUrl, IneligibilityReason, type IpAddressResponse, type OnrampQuote, type OnrampQuotesRequest, type OnrampQuotesResponse, type OnrampSessionRequest, type OnrampSessionResponse, type PaymentNetwork, type PollExecutionsRequest, type PollExecutionsResponse, type ProjectConfigResponse, type QueryExecutionsRequest, type QueryExecutionsResponse, SOLANA_USDC_ADDRESS, type SendSolanaTransactionRequest, type SendSolanaTransactionResponse, 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, buildSolanaTransaction, createDepositAddress, createExchangeSession, createOnrampSession, getAddressBalance, getAddressBalances, getApiBaseUrl, getChainName, getDefaultOnrampToken, getExchangeSessionStartUrl, getExchanges, getFiatCurrencies, getIconUrl, getIconUrlWithCdn, getIpAddress, getOnrampQuotes, getOnrampSessionStartUrl, getPreferredIconUrl, getProjectConfig, getSupportedDepositTokens, getTokenChains, getTokenMetadata, getWalletByChainType, i18n, pollDirectExecutions, queryExecutions, sendSolanaTransaction, setApiConfig, useUserIp, verifyRecipientAddress };
|
package/dist/index.js
CHANGED
|
@@ -25,12 +25,15 @@ __export(index_exports, {
|
|
|
25
25
|
SOLANA_USDC_ADDRESS: () => SOLANA_USDC_ADDRESS,
|
|
26
26
|
buildSolanaTransaction: () => buildSolanaTransaction,
|
|
27
27
|
createDepositAddress: () => createDepositAddress,
|
|
28
|
+
createExchangeSession: () => createExchangeSession,
|
|
28
29
|
createOnrampSession: () => createOnrampSession,
|
|
29
30
|
getAddressBalance: () => getAddressBalance,
|
|
30
31
|
getAddressBalances: () => getAddressBalances,
|
|
31
32
|
getApiBaseUrl: () => getApiBaseUrl,
|
|
32
33
|
getChainName: () => getChainName,
|
|
33
34
|
getDefaultOnrampToken: () => getDefaultOnrampToken,
|
|
35
|
+
getExchangeSessionStartUrl: () => getExchangeSessionStartUrl,
|
|
36
|
+
getExchanges: () => getExchanges,
|
|
34
37
|
getFiatCurrencies: () => getFiatCurrencies,
|
|
35
38
|
getIconUrl: () => getIconUrl,
|
|
36
39
|
getIconUrlWithCdn: () => getIconUrlWithCdn,
|
|
@@ -468,6 +471,70 @@ async function verifyRecipientAddress(request, publishableKey) {
|
|
|
468
471
|
}
|
|
469
472
|
return response.json();
|
|
470
473
|
}
|
|
474
|
+
async function getExchanges(query, publishableKey) {
|
|
475
|
+
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
476
|
+
validatePublishableKey(pk);
|
|
477
|
+
const params = new URLSearchParams();
|
|
478
|
+
if (query?.destination_currency) params.append("destination_currency", query.destination_currency);
|
|
479
|
+
if (query?.destination_network) params.append("destination_network", query.destination_network);
|
|
480
|
+
const queryString = params.toString();
|
|
481
|
+
const url = `${API_BASE_URL}/v1/public/onramps/exchanges${queryString ? `?${queryString}` : ""}`;
|
|
482
|
+
const response = await fetch(url, {
|
|
483
|
+
method: "GET",
|
|
484
|
+
headers: {
|
|
485
|
+
accept: "application/json",
|
|
486
|
+
"x-publishable-key": pk,
|
|
487
|
+
"Content-Type": "application/json"
|
|
488
|
+
}
|
|
489
|
+
});
|
|
490
|
+
if (!response.ok) {
|
|
491
|
+
throw new Error(`Failed to fetch exchanges: ${response.statusText}`);
|
|
492
|
+
}
|
|
493
|
+
return response.json();
|
|
494
|
+
}
|
|
495
|
+
async function createExchangeSession(request, publishableKey) {
|
|
496
|
+
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
497
|
+
validatePublishableKey(pk);
|
|
498
|
+
const response = await fetch(
|
|
499
|
+
`${API_BASE_URL}/v1/public/onramps/exchanges/sessions`,
|
|
500
|
+
{
|
|
501
|
+
method: "POST",
|
|
502
|
+
headers: {
|
|
503
|
+
accept: "application/json",
|
|
504
|
+
"x-publishable-key": pk,
|
|
505
|
+
"Content-Type": "application/json"
|
|
506
|
+
},
|
|
507
|
+
body: JSON.stringify(request)
|
|
508
|
+
}
|
|
509
|
+
);
|
|
510
|
+
if (!response.ok) {
|
|
511
|
+
throw new Error(`Failed to create exchange session: ${response.statusText}`);
|
|
512
|
+
}
|
|
513
|
+
return response.json();
|
|
514
|
+
}
|
|
515
|
+
function getExchangeSessionStartUrl(request, publishableKey) {
|
|
516
|
+
const params = new URLSearchParams();
|
|
517
|
+
params.append("publishable_key", publishableKey);
|
|
518
|
+
params.append("service_provider", request.service_provider);
|
|
519
|
+
params.append("chain_type", request.chain_type);
|
|
520
|
+
params.append("address", request.address);
|
|
521
|
+
if (request.preferred_destination_currency) {
|
|
522
|
+
params.append("preferred_destination_currency", request.preferred_destination_currency);
|
|
523
|
+
}
|
|
524
|
+
if (request.preferred_destination_network) {
|
|
525
|
+
params.append("preferred_destination_network", request.preferred_destination_network);
|
|
526
|
+
}
|
|
527
|
+
if (request.source_currency) {
|
|
528
|
+
params.append("source_currency", request.source_currency);
|
|
529
|
+
}
|
|
530
|
+
if (request.source_amount) {
|
|
531
|
+
params.append("source_amount", request.source_amount);
|
|
532
|
+
}
|
|
533
|
+
if (request.external_id) {
|
|
534
|
+
params.append("external_id", request.external_id);
|
|
535
|
+
}
|
|
536
|
+
return `${API_BASE_URL}/v1/public/onramps/exchanges/sessions/start?${params.toString()}`;
|
|
537
|
+
}
|
|
471
538
|
async function buildSolanaTransaction(request, publishableKey) {
|
|
472
539
|
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
473
540
|
validatePublishableKey(pk);
|
|
@@ -619,12 +686,15 @@ var i18n = en_default;
|
|
|
619
686
|
SOLANA_USDC_ADDRESS,
|
|
620
687
|
buildSolanaTransaction,
|
|
621
688
|
createDepositAddress,
|
|
689
|
+
createExchangeSession,
|
|
622
690
|
createOnrampSession,
|
|
623
691
|
getAddressBalance,
|
|
624
692
|
getAddressBalances,
|
|
625
693
|
getApiBaseUrl,
|
|
626
694
|
getChainName,
|
|
627
695
|
getDefaultOnrampToken,
|
|
696
|
+
getExchangeSessionStartUrl,
|
|
697
|
+
getExchanges,
|
|
628
698
|
getFiatCurrencies,
|
|
629
699
|
getIconUrl,
|
|
630
700
|
getIconUrlWithCdn,
|
package/dist/index.mjs
CHANGED
|
@@ -413,6 +413,70 @@ async function verifyRecipientAddress(request, publishableKey) {
|
|
|
413
413
|
}
|
|
414
414
|
return response.json();
|
|
415
415
|
}
|
|
416
|
+
async function getExchanges(query, publishableKey) {
|
|
417
|
+
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
418
|
+
validatePublishableKey(pk);
|
|
419
|
+
const params = new URLSearchParams();
|
|
420
|
+
if (query?.destination_currency) params.append("destination_currency", query.destination_currency);
|
|
421
|
+
if (query?.destination_network) params.append("destination_network", query.destination_network);
|
|
422
|
+
const queryString = params.toString();
|
|
423
|
+
const url = `${API_BASE_URL}/v1/public/onramps/exchanges${queryString ? `?${queryString}` : ""}`;
|
|
424
|
+
const response = await fetch(url, {
|
|
425
|
+
method: "GET",
|
|
426
|
+
headers: {
|
|
427
|
+
accept: "application/json",
|
|
428
|
+
"x-publishable-key": pk,
|
|
429
|
+
"Content-Type": "application/json"
|
|
430
|
+
}
|
|
431
|
+
});
|
|
432
|
+
if (!response.ok) {
|
|
433
|
+
throw new Error(`Failed to fetch exchanges: ${response.statusText}`);
|
|
434
|
+
}
|
|
435
|
+
return response.json();
|
|
436
|
+
}
|
|
437
|
+
async function createExchangeSession(request, publishableKey) {
|
|
438
|
+
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
439
|
+
validatePublishableKey(pk);
|
|
440
|
+
const response = await fetch(
|
|
441
|
+
`${API_BASE_URL}/v1/public/onramps/exchanges/sessions`,
|
|
442
|
+
{
|
|
443
|
+
method: "POST",
|
|
444
|
+
headers: {
|
|
445
|
+
accept: "application/json",
|
|
446
|
+
"x-publishable-key": pk,
|
|
447
|
+
"Content-Type": "application/json"
|
|
448
|
+
},
|
|
449
|
+
body: JSON.stringify(request)
|
|
450
|
+
}
|
|
451
|
+
);
|
|
452
|
+
if (!response.ok) {
|
|
453
|
+
throw new Error(`Failed to create exchange session: ${response.statusText}`);
|
|
454
|
+
}
|
|
455
|
+
return response.json();
|
|
456
|
+
}
|
|
457
|
+
function getExchangeSessionStartUrl(request, publishableKey) {
|
|
458
|
+
const params = new URLSearchParams();
|
|
459
|
+
params.append("publishable_key", publishableKey);
|
|
460
|
+
params.append("service_provider", request.service_provider);
|
|
461
|
+
params.append("chain_type", request.chain_type);
|
|
462
|
+
params.append("address", request.address);
|
|
463
|
+
if (request.preferred_destination_currency) {
|
|
464
|
+
params.append("preferred_destination_currency", request.preferred_destination_currency);
|
|
465
|
+
}
|
|
466
|
+
if (request.preferred_destination_network) {
|
|
467
|
+
params.append("preferred_destination_network", request.preferred_destination_network);
|
|
468
|
+
}
|
|
469
|
+
if (request.source_currency) {
|
|
470
|
+
params.append("source_currency", request.source_currency);
|
|
471
|
+
}
|
|
472
|
+
if (request.source_amount) {
|
|
473
|
+
params.append("source_amount", request.source_amount);
|
|
474
|
+
}
|
|
475
|
+
if (request.external_id) {
|
|
476
|
+
params.append("external_id", request.external_id);
|
|
477
|
+
}
|
|
478
|
+
return `${API_BASE_URL}/v1/public/onramps/exchanges/sessions/start?${params.toString()}`;
|
|
479
|
+
}
|
|
416
480
|
async function buildSolanaTransaction(request, publishableKey) {
|
|
417
481
|
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
418
482
|
validatePublishableKey(pk);
|
|
@@ -563,12 +627,15 @@ export {
|
|
|
563
627
|
SOLANA_USDC_ADDRESS,
|
|
564
628
|
buildSolanaTransaction,
|
|
565
629
|
createDepositAddress,
|
|
630
|
+
createExchangeSession,
|
|
566
631
|
createOnrampSession,
|
|
567
632
|
getAddressBalance,
|
|
568
633
|
getAddressBalances,
|
|
569
634
|
getApiBaseUrl,
|
|
570
635
|
getChainName,
|
|
571
636
|
getDefaultOnrampToken,
|
|
637
|
+
getExchangeSessionStartUrl,
|
|
638
|
+
getExchanges,
|
|
572
639
|
getFiatCurrencies,
|
|
573
640
|
getIconUrl,
|
|
574
641
|
getIconUrlWithCdn,
|