@unifold/core 0.1.52 → 0.1.54
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 +86 -3
- package/dist/index.d.ts +86 -3
- package/dist/index.js +109 -19
- package/dist/index.mjs +105 -19
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -76,6 +76,7 @@ interface IconUrl {
|
|
|
76
76
|
url: string;
|
|
77
77
|
format: "svg" | "png";
|
|
78
78
|
}
|
|
79
|
+
type ProductType = "deposit" | "payment";
|
|
79
80
|
interface AutoSwapResponse {
|
|
80
81
|
id: string;
|
|
81
82
|
project_id: string;
|
|
@@ -157,6 +158,7 @@ interface SupportedChain {
|
|
|
157
158
|
chain_type: string;
|
|
158
159
|
icon_url: string;
|
|
159
160
|
token_address: string;
|
|
161
|
+
decimals: number;
|
|
160
162
|
estimated_price_impact_percent: number;
|
|
161
163
|
max_slippage_percent: number;
|
|
162
164
|
estimated_processing_time: number | null;
|
|
@@ -184,13 +186,17 @@ interface SupportedDestinationTokensResponse {
|
|
|
184
186
|
/**
|
|
185
187
|
* Get supported destination tokens (used for withdraw flow)
|
|
186
188
|
* @param publishableKey - Optional publishable key, defaults to configured key
|
|
189
|
+
* @param options - Optional query parameters
|
|
187
190
|
*/
|
|
188
|
-
declare function getSupportedDestinationTokens(publishableKey?: string
|
|
191
|
+
declare function getSupportedDestinationTokens(publishableKey?: string, options?: {
|
|
192
|
+
product_type?: ProductType;
|
|
193
|
+
}): Promise<SupportedDestinationTokensResponse>;
|
|
189
194
|
interface SupportedToken {
|
|
190
195
|
symbol: string;
|
|
191
196
|
name: string;
|
|
192
197
|
icon_url: string;
|
|
193
198
|
is_newly_added: boolean;
|
|
199
|
+
is_stablecoin: boolean;
|
|
194
200
|
chains: SupportedChain[];
|
|
195
201
|
}
|
|
196
202
|
interface SupportedDepositTokensResponse {
|
|
@@ -204,6 +210,7 @@ declare function getSupportedDepositTokens(publishableKey?: string, options?: {
|
|
|
204
210
|
destination_token_address?: string;
|
|
205
211
|
destination_chain_id?: string;
|
|
206
212
|
destination_chain_type?: string;
|
|
213
|
+
product_type?: ProductType;
|
|
207
214
|
}): Promise<SupportedDepositTokensResponse>;
|
|
208
215
|
interface TokenMetadata {
|
|
209
216
|
symbol: string;
|
|
@@ -242,7 +249,7 @@ interface FiatCurrency {
|
|
|
242
249
|
icon_url: string;
|
|
243
250
|
icon_urls: IconUrl[];
|
|
244
251
|
country_codes: string[];
|
|
245
|
-
default_amount: number;
|
|
252
|
+
default_amount: number | null;
|
|
246
253
|
minimum_amount: number;
|
|
247
254
|
maximum_amount: number;
|
|
248
255
|
suggested_amounts: number[];
|
|
@@ -406,12 +413,20 @@ interface BlockedCountrySubdivision {
|
|
|
406
413
|
country_code: string;
|
|
407
414
|
subdivision_codes: string[];
|
|
408
415
|
}
|
|
416
|
+
interface FeaturedWallet {
|
|
417
|
+
name: string;
|
|
418
|
+
position: number;
|
|
419
|
+
icon_urls: IconUrl[];
|
|
420
|
+
}
|
|
409
421
|
interface ProjectConfigResponse {
|
|
410
422
|
project_name?: string;
|
|
411
423
|
asset_cdn_url: string;
|
|
412
424
|
transfer_crypto: {
|
|
413
425
|
networks: FeaturedToken[];
|
|
414
426
|
};
|
|
427
|
+
connect_wallet: {
|
|
428
|
+
wallets: FeaturedWallet[];
|
|
429
|
+
};
|
|
415
430
|
payment_networks: {
|
|
416
431
|
networks: PaymentNetwork[];
|
|
417
432
|
};
|
|
@@ -752,6 +767,8 @@ interface PaymentIntent {
|
|
|
752
767
|
description: string | null;
|
|
753
768
|
livemode: boolean;
|
|
754
769
|
settlement_tolerance_percent: number;
|
|
770
|
+
/** When true, stablecoin deposits are credited at par (1:1) regardless of swap slippage. */
|
|
771
|
+
stablecoin_parity: boolean;
|
|
755
772
|
canceled_at: string | null;
|
|
756
773
|
cancellation_reason: string | null;
|
|
757
774
|
expires_at: string | null;
|
|
@@ -882,6 +899,16 @@ interface DepositQuoteRequest {
|
|
|
882
899
|
destination_chain_type: string;
|
|
883
900
|
destination_chain_id: string;
|
|
884
901
|
destination_token_address: string;
|
|
902
|
+
/**
|
|
903
|
+
* When true, the source amount is inflated by the expected slippage to
|
|
904
|
+
* reduce stuck payments. Typically set by the checkout flow.
|
|
905
|
+
*/
|
|
906
|
+
adjust_for_slippage?: boolean;
|
|
907
|
+
/**
|
|
908
|
+
* When true and both tokens are stablecoins, returns a 1:1 quote
|
|
909
|
+
* without calling the swap provider. Ignored if source is not a stablecoin.
|
|
910
|
+
*/
|
|
911
|
+
stablecoin_parity?: boolean;
|
|
885
912
|
}
|
|
886
913
|
interface DepositQuote {
|
|
887
914
|
/**
|
|
@@ -901,6 +928,17 @@ interface DepositQuote {
|
|
|
901
928
|
destination_token_symbol: string;
|
|
902
929
|
estimated_price_impact_percent: number | null;
|
|
903
930
|
estimated_fees_usd: string | null;
|
|
931
|
+
/**
|
|
932
|
+
* The slippage buffer percentage applied to the source amount.
|
|
933
|
+
* Present when `adjust_for_slippage` was true; null otherwise.
|
|
934
|
+
*/
|
|
935
|
+
slippage_buffer_percent: number | null;
|
|
936
|
+
/**
|
|
937
|
+
* Expected slippage for this route (from Relay or token config).
|
|
938
|
+
* Always present when slippage data is available, regardless of
|
|
939
|
+
* `adjust_for_slippage`.
|
|
940
|
+
*/
|
|
941
|
+
expected_slippage_percent: number | null;
|
|
904
942
|
}
|
|
905
943
|
/**
|
|
906
944
|
* Get a deposit quote: how much source token is needed to receive a
|
|
@@ -942,8 +980,53 @@ declare function buildHypercoreTransaction(request: BuildHypercoreTransactionReq
|
|
|
942
980
|
* Pass the action + nonce from buildHypercoreTransaction and
|
|
943
981
|
* the signature from eth_signTypedData_v4.
|
|
944
982
|
*/
|
|
983
|
+
interface CashAppSessionRequest {
|
|
984
|
+
external_user_id: string;
|
|
985
|
+
destination_chain_type: string;
|
|
986
|
+
destination_chain_id: string;
|
|
987
|
+
destination_token_address: string;
|
|
988
|
+
recipient_address: string;
|
|
989
|
+
source_amount: string;
|
|
990
|
+
external_id?: string;
|
|
991
|
+
}
|
|
992
|
+
interface CashAppSessionResponse {
|
|
993
|
+
id: string;
|
|
994
|
+
external_id: string;
|
|
995
|
+
url: string;
|
|
996
|
+
status: string;
|
|
997
|
+
destination_amount: string;
|
|
998
|
+
expires_at: string;
|
|
999
|
+
}
|
|
1000
|
+
interface CashAppSessionStatusResponse {
|
|
1001
|
+
status: string;
|
|
1002
|
+
updated_at?: string;
|
|
1003
|
+
}
|
|
1004
|
+
interface CashAppLimits {
|
|
1005
|
+
minimum_amount: number;
|
|
1006
|
+
maximum_amount: number | null;
|
|
1007
|
+
currency: string;
|
|
1008
|
+
}
|
|
1009
|
+
declare function getCashAppLimits(currency?: string, publishableKey?: string): Promise<CashAppLimits>;
|
|
1010
|
+
declare function createCashAppSession(request: CashAppSessionRequest, publishableKey?: string): Promise<CashAppSessionResponse>;
|
|
1011
|
+
declare function getCashAppSessionStatus(externalId: string, publishableKey?: string): Promise<CashAppSessionStatusResponse>;
|
|
945
1012
|
declare function sendHypercoreTransaction(request: SendHypercoreTransactionRequest, publishableKey?: string): Promise<SendHypercoreTransactionResponse>;
|
|
946
1013
|
|
|
1014
|
+
/**
|
|
1015
|
+
* Format a stablecoin amount to 2 decimal places, ceiling any fractional
|
|
1016
|
+
* value beyond the 2nd decimal. This ensures the displayed amount is always
|
|
1017
|
+
* >= the real amount, so the user never underpays.
|
|
1018
|
+
*
|
|
1019
|
+
* @param baseUnits - Amount in base units (e.g. "5123456")
|
|
1020
|
+
* @param decimals - Token decimals (e.g. 6 for USDC)
|
|
1021
|
+
* @returns Formatted string with exactly 2 decimal places (e.g. "5.13")
|
|
1022
|
+
*
|
|
1023
|
+
* @example
|
|
1024
|
+
* formatStablecoinAmount("5123456", 6) // "5.13" (5.123456 → ceil)
|
|
1025
|
+
* formatStablecoinAmount("5120000", 6) // "5.12" (exact, no rounding)
|
|
1026
|
+
* formatStablecoinAmount("3450050", 6) // "3.46" (3.450050 → ceil)
|
|
1027
|
+
* formatStablecoinAmount("10000000", 6) // "10.00" (whole number)
|
|
1028
|
+
*/
|
|
1029
|
+
declare function formatStablecoinAmount(baseUnits: string, decimals: number): string;
|
|
947
1030
|
/**
|
|
948
1031
|
* Generate a KSUID-like prefixed ID without external dependencies.
|
|
949
1032
|
* Format: `{prefix}_{base62(4-byte-timestamp + 16-random-bytes)}` (27 chars after prefix).
|
|
@@ -1106,4 +1189,4 @@ declare const i18n: {
|
|
|
1106
1189
|
};
|
|
1107
1190
|
type I18nStrings = typeof i18n;
|
|
1108
1191
|
|
|
1109
|
-
export { ActionType, type AddressBalanceResponse, type AddressBalancesResponse, type AddressValidationFailureCode, type AddressValidationMetadata, type AutoSwapRequest, type AutoSwapResponse, type BlockedCountrySubdivision, type BuildHypercoreTransactionRequest, type BuildHypercoreTransactionResponse, type BuildSolanaTransactionRequest, type BuildSolanaTransactionResponse, type ChainType, type CreateDepositAddressRequest, type CreateExchangeSessionRequest, type CreateExchangeSessionResponse, type DefaultTokenChain, type DefaultTokenMetadata, type DefaultTokenResponse, type DepositAddressResponse, type DepositEvent, DepositEventType, type DepositQuote, type DepositQuoteRequest, type DestinationToken, type DestinationTokenChain, type ExchangeProviderInfo, type ExchangeProvidersResponse, type ExchangeSessionStartParams, type ExchangeWalletAddress, ExecutionStatus, type FeaturedToken, type FiatCurrenciesResponse, type FiatCurrency, type GetExchangesQuery, type HypercoreActionType, type HypercoreActivationRequest, type HypercoreActivationResponse, type I18nStrings, type IconUrl, IneligibilityReason, type IpAddressResponse, type LockedQuoteLimits, type LockedQuotePreview, type LockedQuotePreviewRequest, type OnrampQuote, type OnrampQuotesRequest, type OnrampQuotesResponse, type OnrampSessionCreatedData, type OnrampSessionCreatedEvent, type OnrampSessionRequest, type OnrampSessionResponse, type PaymentIntent, type PaymentIntentDepositAddress, type PaymentIntentExecutionsResponse, type PaymentIntentStatus, type PaymentIntentType, type PaymentNetwork, type PollExecutionsRequest, type PollExecutionsResponse, type ProjectConfigResponse, type QueryExecutionsRequest, type QueryExecutionsResponse, SOLANA_USDC_ADDRESS, type SendHypercoreTransactionRequest, type SendHypercoreTransactionResponse, type SendSolanaTransactionRequest, type SendSolanaTransactionResponse, type SourceToken, type SourceTokenNetwork, type SupportedChain, type SupportedDepositTokensResponse, type SupportedDestinationTokensResponse, type SupportedSourceTokensQuery, type SupportedSourceTokensResponse, type SupportedToken, type TokenBalance, type TokenChain, type TokenChainIconUrl, type TokenChainsResponse, type TokenIconUrl, type TokenInfo, type TokenMetadata, type UserIpInfo, type VerifyAddressRequest, type VerifyAddressResponse, type Wallet, buildHypercoreTransaction, buildSolanaTransaction, checkHypercoreActivation, createDepositAddress, createExchangeSession, createOnrampSession, generatePrefixedKSUID, getAddressBalance, getAddressBalances, getApiBaseUrl, getChainName, getDefaultOnrampToken, getDepositQuote, getExchangeSessionStartUrl, getExchanges, getFiatCurrencies, getIconUrl, getIconUrlWithCdn, getIpAddress, getOnrampQuotes, getOnrampSessionStartUrl, getPreferredIconUrl, getProjectConfig, getSupportedDepositTokens, getSupportedDestinationTokens, getTokenChains, getTokenMetadata, getWalletByChainType, i18n, listPaymentIntentExecutions, pollDirectExecutions, queryExecutions, retrievePaymentIntent, sendHypercoreTransaction, sendSolanaTransaction, setApiConfig, useUserIp, verifyRecipientAddress };
|
|
1192
|
+
export { ActionType, type AddressBalanceResponse, type AddressBalancesResponse, type AddressValidationFailureCode, type AddressValidationMetadata, type AutoSwapRequest, type AutoSwapResponse, type BlockedCountrySubdivision, type BuildHypercoreTransactionRequest, type BuildHypercoreTransactionResponse, type BuildSolanaTransactionRequest, type BuildSolanaTransactionResponse, type CashAppLimits, type CashAppSessionRequest, type CashAppSessionResponse, type CashAppSessionStatusResponse, type ChainType, type CreateDepositAddressRequest, type CreateExchangeSessionRequest, type CreateExchangeSessionResponse, type DefaultTokenChain, type DefaultTokenMetadata, type DefaultTokenResponse, type DepositAddressResponse, type DepositEvent, DepositEventType, type DepositQuote, type DepositQuoteRequest, type DestinationToken, type DestinationTokenChain, type ExchangeProviderInfo, type ExchangeProvidersResponse, type ExchangeSessionStartParams, type ExchangeWalletAddress, ExecutionStatus, type FeaturedToken, type FeaturedWallet, type FiatCurrenciesResponse, type FiatCurrency, type GetExchangesQuery, type HypercoreActionType, type HypercoreActivationRequest, type HypercoreActivationResponse, type I18nStrings, type IconUrl, IneligibilityReason, type IpAddressResponse, type LockedQuoteLimits, type LockedQuotePreview, type LockedQuotePreviewRequest, type OnrampQuote, type OnrampQuotesRequest, type OnrampQuotesResponse, type OnrampSessionCreatedData, type OnrampSessionCreatedEvent, type OnrampSessionRequest, type OnrampSessionResponse, type PaymentIntent, type PaymentIntentDepositAddress, type PaymentIntentExecutionsResponse, type PaymentIntentStatus, type PaymentIntentType, type PaymentNetwork, type PollExecutionsRequest, type PollExecutionsResponse, type ProductType, type ProjectConfigResponse, type QueryExecutionsRequest, type QueryExecutionsResponse, SOLANA_USDC_ADDRESS, type SendHypercoreTransactionRequest, type SendHypercoreTransactionResponse, type SendSolanaTransactionRequest, type SendSolanaTransactionResponse, type SourceToken, type SourceTokenNetwork, type SupportedChain, type SupportedDepositTokensResponse, type SupportedDestinationTokensResponse, type SupportedSourceTokensQuery, type SupportedSourceTokensResponse, type SupportedToken, type TokenBalance, type TokenChain, type TokenChainIconUrl, type TokenChainsResponse, type TokenIconUrl, type TokenInfo, type TokenMetadata, type UserIpInfo, type VerifyAddressRequest, type VerifyAddressResponse, type Wallet, buildHypercoreTransaction, buildSolanaTransaction, checkHypercoreActivation, createCashAppSession, createDepositAddress, createExchangeSession, createOnrampSession, formatStablecoinAmount, generatePrefixedKSUID, getAddressBalance, getAddressBalances, getApiBaseUrl, getCashAppLimits, getCashAppSessionStatus, getChainName, getDefaultOnrampToken, getDepositQuote, getExchangeSessionStartUrl, getExchanges, getFiatCurrencies, getIconUrl, getIconUrlWithCdn, getIpAddress, getOnrampQuotes, getOnrampSessionStartUrl, getPreferredIconUrl, getProjectConfig, getSupportedDepositTokens, getSupportedDestinationTokens, getTokenChains, getTokenMetadata, getWalletByChainType, i18n, listPaymentIntentExecutions, pollDirectExecutions, queryExecutions, retrievePaymentIntent, sendHypercoreTransaction, sendSolanaTransaction, setApiConfig, useUserIp, verifyRecipientAddress };
|
package/dist/index.d.ts
CHANGED
|
@@ -76,6 +76,7 @@ interface IconUrl {
|
|
|
76
76
|
url: string;
|
|
77
77
|
format: "svg" | "png";
|
|
78
78
|
}
|
|
79
|
+
type ProductType = "deposit" | "payment";
|
|
79
80
|
interface AutoSwapResponse {
|
|
80
81
|
id: string;
|
|
81
82
|
project_id: string;
|
|
@@ -157,6 +158,7 @@ interface SupportedChain {
|
|
|
157
158
|
chain_type: string;
|
|
158
159
|
icon_url: string;
|
|
159
160
|
token_address: string;
|
|
161
|
+
decimals: number;
|
|
160
162
|
estimated_price_impact_percent: number;
|
|
161
163
|
max_slippage_percent: number;
|
|
162
164
|
estimated_processing_time: number | null;
|
|
@@ -184,13 +186,17 @@ interface SupportedDestinationTokensResponse {
|
|
|
184
186
|
/**
|
|
185
187
|
* Get supported destination tokens (used for withdraw flow)
|
|
186
188
|
* @param publishableKey - Optional publishable key, defaults to configured key
|
|
189
|
+
* @param options - Optional query parameters
|
|
187
190
|
*/
|
|
188
|
-
declare function getSupportedDestinationTokens(publishableKey?: string
|
|
191
|
+
declare function getSupportedDestinationTokens(publishableKey?: string, options?: {
|
|
192
|
+
product_type?: ProductType;
|
|
193
|
+
}): Promise<SupportedDestinationTokensResponse>;
|
|
189
194
|
interface SupportedToken {
|
|
190
195
|
symbol: string;
|
|
191
196
|
name: string;
|
|
192
197
|
icon_url: string;
|
|
193
198
|
is_newly_added: boolean;
|
|
199
|
+
is_stablecoin: boolean;
|
|
194
200
|
chains: SupportedChain[];
|
|
195
201
|
}
|
|
196
202
|
interface SupportedDepositTokensResponse {
|
|
@@ -204,6 +210,7 @@ declare function getSupportedDepositTokens(publishableKey?: string, options?: {
|
|
|
204
210
|
destination_token_address?: string;
|
|
205
211
|
destination_chain_id?: string;
|
|
206
212
|
destination_chain_type?: string;
|
|
213
|
+
product_type?: ProductType;
|
|
207
214
|
}): Promise<SupportedDepositTokensResponse>;
|
|
208
215
|
interface TokenMetadata {
|
|
209
216
|
symbol: string;
|
|
@@ -242,7 +249,7 @@ interface FiatCurrency {
|
|
|
242
249
|
icon_url: string;
|
|
243
250
|
icon_urls: IconUrl[];
|
|
244
251
|
country_codes: string[];
|
|
245
|
-
default_amount: number;
|
|
252
|
+
default_amount: number | null;
|
|
246
253
|
minimum_amount: number;
|
|
247
254
|
maximum_amount: number;
|
|
248
255
|
suggested_amounts: number[];
|
|
@@ -406,12 +413,20 @@ interface BlockedCountrySubdivision {
|
|
|
406
413
|
country_code: string;
|
|
407
414
|
subdivision_codes: string[];
|
|
408
415
|
}
|
|
416
|
+
interface FeaturedWallet {
|
|
417
|
+
name: string;
|
|
418
|
+
position: number;
|
|
419
|
+
icon_urls: IconUrl[];
|
|
420
|
+
}
|
|
409
421
|
interface ProjectConfigResponse {
|
|
410
422
|
project_name?: string;
|
|
411
423
|
asset_cdn_url: string;
|
|
412
424
|
transfer_crypto: {
|
|
413
425
|
networks: FeaturedToken[];
|
|
414
426
|
};
|
|
427
|
+
connect_wallet: {
|
|
428
|
+
wallets: FeaturedWallet[];
|
|
429
|
+
};
|
|
415
430
|
payment_networks: {
|
|
416
431
|
networks: PaymentNetwork[];
|
|
417
432
|
};
|
|
@@ -752,6 +767,8 @@ interface PaymentIntent {
|
|
|
752
767
|
description: string | null;
|
|
753
768
|
livemode: boolean;
|
|
754
769
|
settlement_tolerance_percent: number;
|
|
770
|
+
/** When true, stablecoin deposits are credited at par (1:1) regardless of swap slippage. */
|
|
771
|
+
stablecoin_parity: boolean;
|
|
755
772
|
canceled_at: string | null;
|
|
756
773
|
cancellation_reason: string | null;
|
|
757
774
|
expires_at: string | null;
|
|
@@ -882,6 +899,16 @@ interface DepositQuoteRequest {
|
|
|
882
899
|
destination_chain_type: string;
|
|
883
900
|
destination_chain_id: string;
|
|
884
901
|
destination_token_address: string;
|
|
902
|
+
/**
|
|
903
|
+
* When true, the source amount is inflated by the expected slippage to
|
|
904
|
+
* reduce stuck payments. Typically set by the checkout flow.
|
|
905
|
+
*/
|
|
906
|
+
adjust_for_slippage?: boolean;
|
|
907
|
+
/**
|
|
908
|
+
* When true and both tokens are stablecoins, returns a 1:1 quote
|
|
909
|
+
* without calling the swap provider. Ignored if source is not a stablecoin.
|
|
910
|
+
*/
|
|
911
|
+
stablecoin_parity?: boolean;
|
|
885
912
|
}
|
|
886
913
|
interface DepositQuote {
|
|
887
914
|
/**
|
|
@@ -901,6 +928,17 @@ interface DepositQuote {
|
|
|
901
928
|
destination_token_symbol: string;
|
|
902
929
|
estimated_price_impact_percent: number | null;
|
|
903
930
|
estimated_fees_usd: string | null;
|
|
931
|
+
/**
|
|
932
|
+
* The slippage buffer percentage applied to the source amount.
|
|
933
|
+
* Present when `adjust_for_slippage` was true; null otherwise.
|
|
934
|
+
*/
|
|
935
|
+
slippage_buffer_percent: number | null;
|
|
936
|
+
/**
|
|
937
|
+
* Expected slippage for this route (from Relay or token config).
|
|
938
|
+
* Always present when slippage data is available, regardless of
|
|
939
|
+
* `adjust_for_slippage`.
|
|
940
|
+
*/
|
|
941
|
+
expected_slippage_percent: number | null;
|
|
904
942
|
}
|
|
905
943
|
/**
|
|
906
944
|
* Get a deposit quote: how much source token is needed to receive a
|
|
@@ -942,8 +980,53 @@ declare function buildHypercoreTransaction(request: BuildHypercoreTransactionReq
|
|
|
942
980
|
* Pass the action + nonce from buildHypercoreTransaction and
|
|
943
981
|
* the signature from eth_signTypedData_v4.
|
|
944
982
|
*/
|
|
983
|
+
interface CashAppSessionRequest {
|
|
984
|
+
external_user_id: string;
|
|
985
|
+
destination_chain_type: string;
|
|
986
|
+
destination_chain_id: string;
|
|
987
|
+
destination_token_address: string;
|
|
988
|
+
recipient_address: string;
|
|
989
|
+
source_amount: string;
|
|
990
|
+
external_id?: string;
|
|
991
|
+
}
|
|
992
|
+
interface CashAppSessionResponse {
|
|
993
|
+
id: string;
|
|
994
|
+
external_id: string;
|
|
995
|
+
url: string;
|
|
996
|
+
status: string;
|
|
997
|
+
destination_amount: string;
|
|
998
|
+
expires_at: string;
|
|
999
|
+
}
|
|
1000
|
+
interface CashAppSessionStatusResponse {
|
|
1001
|
+
status: string;
|
|
1002
|
+
updated_at?: string;
|
|
1003
|
+
}
|
|
1004
|
+
interface CashAppLimits {
|
|
1005
|
+
minimum_amount: number;
|
|
1006
|
+
maximum_amount: number | null;
|
|
1007
|
+
currency: string;
|
|
1008
|
+
}
|
|
1009
|
+
declare function getCashAppLimits(currency?: string, publishableKey?: string): Promise<CashAppLimits>;
|
|
1010
|
+
declare function createCashAppSession(request: CashAppSessionRequest, publishableKey?: string): Promise<CashAppSessionResponse>;
|
|
1011
|
+
declare function getCashAppSessionStatus(externalId: string, publishableKey?: string): Promise<CashAppSessionStatusResponse>;
|
|
945
1012
|
declare function sendHypercoreTransaction(request: SendHypercoreTransactionRequest, publishableKey?: string): Promise<SendHypercoreTransactionResponse>;
|
|
946
1013
|
|
|
1014
|
+
/**
|
|
1015
|
+
* Format a stablecoin amount to 2 decimal places, ceiling any fractional
|
|
1016
|
+
* value beyond the 2nd decimal. This ensures the displayed amount is always
|
|
1017
|
+
* >= the real amount, so the user never underpays.
|
|
1018
|
+
*
|
|
1019
|
+
* @param baseUnits - Amount in base units (e.g. "5123456")
|
|
1020
|
+
* @param decimals - Token decimals (e.g. 6 for USDC)
|
|
1021
|
+
* @returns Formatted string with exactly 2 decimal places (e.g. "5.13")
|
|
1022
|
+
*
|
|
1023
|
+
* @example
|
|
1024
|
+
* formatStablecoinAmount("5123456", 6) // "5.13" (5.123456 → ceil)
|
|
1025
|
+
* formatStablecoinAmount("5120000", 6) // "5.12" (exact, no rounding)
|
|
1026
|
+
* formatStablecoinAmount("3450050", 6) // "3.46" (3.450050 → ceil)
|
|
1027
|
+
* formatStablecoinAmount("10000000", 6) // "10.00" (whole number)
|
|
1028
|
+
*/
|
|
1029
|
+
declare function formatStablecoinAmount(baseUnits: string, decimals: number): string;
|
|
947
1030
|
/**
|
|
948
1031
|
* Generate a KSUID-like prefixed ID without external dependencies.
|
|
949
1032
|
* Format: `{prefix}_{base62(4-byte-timestamp + 16-random-bytes)}` (27 chars after prefix).
|
|
@@ -1106,4 +1189,4 @@ declare const i18n: {
|
|
|
1106
1189
|
};
|
|
1107
1190
|
type I18nStrings = typeof i18n;
|
|
1108
1191
|
|
|
1109
|
-
export { ActionType, type AddressBalanceResponse, type AddressBalancesResponse, type AddressValidationFailureCode, type AddressValidationMetadata, type AutoSwapRequest, type AutoSwapResponse, type BlockedCountrySubdivision, type BuildHypercoreTransactionRequest, type BuildHypercoreTransactionResponse, type BuildSolanaTransactionRequest, type BuildSolanaTransactionResponse, type ChainType, type CreateDepositAddressRequest, type CreateExchangeSessionRequest, type CreateExchangeSessionResponse, type DefaultTokenChain, type DefaultTokenMetadata, type DefaultTokenResponse, type DepositAddressResponse, type DepositEvent, DepositEventType, type DepositQuote, type DepositQuoteRequest, type DestinationToken, type DestinationTokenChain, type ExchangeProviderInfo, type ExchangeProvidersResponse, type ExchangeSessionStartParams, type ExchangeWalletAddress, ExecutionStatus, type FeaturedToken, type FiatCurrenciesResponse, type FiatCurrency, type GetExchangesQuery, type HypercoreActionType, type HypercoreActivationRequest, type HypercoreActivationResponse, type I18nStrings, type IconUrl, IneligibilityReason, type IpAddressResponse, type LockedQuoteLimits, type LockedQuotePreview, type LockedQuotePreviewRequest, type OnrampQuote, type OnrampQuotesRequest, type OnrampQuotesResponse, type OnrampSessionCreatedData, type OnrampSessionCreatedEvent, type OnrampSessionRequest, type OnrampSessionResponse, type PaymentIntent, type PaymentIntentDepositAddress, type PaymentIntentExecutionsResponse, type PaymentIntentStatus, type PaymentIntentType, type PaymentNetwork, type PollExecutionsRequest, type PollExecutionsResponse, type ProjectConfigResponse, type QueryExecutionsRequest, type QueryExecutionsResponse, SOLANA_USDC_ADDRESS, type SendHypercoreTransactionRequest, type SendHypercoreTransactionResponse, type SendSolanaTransactionRequest, type SendSolanaTransactionResponse, type SourceToken, type SourceTokenNetwork, type SupportedChain, type SupportedDepositTokensResponse, type SupportedDestinationTokensResponse, type SupportedSourceTokensQuery, type SupportedSourceTokensResponse, type SupportedToken, type TokenBalance, type TokenChain, type TokenChainIconUrl, type TokenChainsResponse, type TokenIconUrl, type TokenInfo, type TokenMetadata, type UserIpInfo, type VerifyAddressRequest, type VerifyAddressResponse, type Wallet, buildHypercoreTransaction, buildSolanaTransaction, checkHypercoreActivation, createDepositAddress, createExchangeSession, createOnrampSession, generatePrefixedKSUID, getAddressBalance, getAddressBalances, getApiBaseUrl, getChainName, getDefaultOnrampToken, getDepositQuote, getExchangeSessionStartUrl, getExchanges, getFiatCurrencies, getIconUrl, getIconUrlWithCdn, getIpAddress, getOnrampQuotes, getOnrampSessionStartUrl, getPreferredIconUrl, getProjectConfig, getSupportedDepositTokens, getSupportedDestinationTokens, getTokenChains, getTokenMetadata, getWalletByChainType, i18n, listPaymentIntentExecutions, pollDirectExecutions, queryExecutions, retrievePaymentIntent, sendHypercoreTransaction, sendSolanaTransaction, setApiConfig, useUserIp, verifyRecipientAddress };
|
|
1192
|
+
export { ActionType, type AddressBalanceResponse, type AddressBalancesResponse, type AddressValidationFailureCode, type AddressValidationMetadata, type AutoSwapRequest, type AutoSwapResponse, type BlockedCountrySubdivision, type BuildHypercoreTransactionRequest, type BuildHypercoreTransactionResponse, type BuildSolanaTransactionRequest, type BuildSolanaTransactionResponse, type CashAppLimits, type CashAppSessionRequest, type CashAppSessionResponse, type CashAppSessionStatusResponse, type ChainType, type CreateDepositAddressRequest, type CreateExchangeSessionRequest, type CreateExchangeSessionResponse, type DefaultTokenChain, type DefaultTokenMetadata, type DefaultTokenResponse, type DepositAddressResponse, type DepositEvent, DepositEventType, type DepositQuote, type DepositQuoteRequest, type DestinationToken, type DestinationTokenChain, type ExchangeProviderInfo, type ExchangeProvidersResponse, type ExchangeSessionStartParams, type ExchangeWalletAddress, ExecutionStatus, type FeaturedToken, type FeaturedWallet, type FiatCurrenciesResponse, type FiatCurrency, type GetExchangesQuery, type HypercoreActionType, type HypercoreActivationRequest, type HypercoreActivationResponse, type I18nStrings, type IconUrl, IneligibilityReason, type IpAddressResponse, type LockedQuoteLimits, type LockedQuotePreview, type LockedQuotePreviewRequest, type OnrampQuote, type OnrampQuotesRequest, type OnrampQuotesResponse, type OnrampSessionCreatedData, type OnrampSessionCreatedEvent, type OnrampSessionRequest, type OnrampSessionResponse, type PaymentIntent, type PaymentIntentDepositAddress, type PaymentIntentExecutionsResponse, type PaymentIntentStatus, type PaymentIntentType, type PaymentNetwork, type PollExecutionsRequest, type PollExecutionsResponse, type ProductType, type ProjectConfigResponse, type QueryExecutionsRequest, type QueryExecutionsResponse, SOLANA_USDC_ADDRESS, type SendHypercoreTransactionRequest, type SendHypercoreTransactionResponse, type SendSolanaTransactionRequest, type SendSolanaTransactionResponse, type SourceToken, type SourceTokenNetwork, type SupportedChain, type SupportedDepositTokensResponse, type SupportedDestinationTokensResponse, type SupportedSourceTokensQuery, type SupportedSourceTokensResponse, type SupportedToken, type TokenBalance, type TokenChain, type TokenChainIconUrl, type TokenChainsResponse, type TokenIconUrl, type TokenInfo, type TokenMetadata, type UserIpInfo, type VerifyAddressRequest, type VerifyAddressResponse, type Wallet, buildHypercoreTransaction, buildSolanaTransaction, checkHypercoreActivation, createCashAppSession, createDepositAddress, createExchangeSession, createOnrampSession, formatStablecoinAmount, generatePrefixedKSUID, getAddressBalance, getAddressBalances, getApiBaseUrl, getCashAppLimits, getCashAppSessionStatus, getChainName, getDefaultOnrampToken, getDepositQuote, getExchangeSessionStartUrl, getExchanges, getFiatCurrencies, getIconUrl, getIconUrlWithCdn, getIpAddress, getOnrampQuotes, getOnrampSessionStartUrl, getPreferredIconUrl, getProjectConfig, getSupportedDepositTokens, getSupportedDestinationTokens, getTokenChains, getTokenMetadata, getWalletByChainType, i18n, listPaymentIntentExecutions, pollDirectExecutions, queryExecutions, retrievePaymentIntent, sendHypercoreTransaction, sendSolanaTransaction, setApiConfig, useUserIp, verifyRecipientAddress };
|
package/dist/index.js
CHANGED
|
@@ -28,13 +28,17 @@ __export(index_exports, {
|
|
|
28
28
|
buildHypercoreTransaction: () => buildHypercoreTransaction,
|
|
29
29
|
buildSolanaTransaction: () => buildSolanaTransaction,
|
|
30
30
|
checkHypercoreActivation: () => checkHypercoreActivation,
|
|
31
|
+
createCashAppSession: () => createCashAppSession,
|
|
31
32
|
createDepositAddress: () => createDepositAddress,
|
|
32
33
|
createExchangeSession: () => createExchangeSession,
|
|
33
34
|
createOnrampSession: () => createOnrampSession,
|
|
35
|
+
formatStablecoinAmount: () => formatStablecoinAmount,
|
|
34
36
|
generatePrefixedKSUID: () => generatePrefixedKSUID,
|
|
35
37
|
getAddressBalance: () => getAddressBalance,
|
|
36
38
|
getAddressBalances: () => getAddressBalances,
|
|
37
39
|
getApiBaseUrl: () => getApiBaseUrl,
|
|
40
|
+
getCashAppLimits: () => getCashAppLimits,
|
|
41
|
+
getCashAppSessionStatus: () => getCashAppSessionStatus,
|
|
38
42
|
getChainName: () => getChainName,
|
|
39
43
|
getDefaultOnrampToken: () => getDefaultOnrampToken,
|
|
40
44
|
getDepositQuote: () => getDepositQuote,
|
|
@@ -210,19 +214,25 @@ async function pollDirectExecutions(request, publishableKey) {
|
|
|
210
214
|
}
|
|
211
215
|
return response.json();
|
|
212
216
|
}
|
|
213
|
-
async function getSupportedDestinationTokens(publishableKey) {
|
|
217
|
+
async function getSupportedDestinationTokens(publishableKey, options) {
|
|
214
218
|
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
215
219
|
validatePublishableKey(pk);
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
220
|
+
let url = `${API_BASE_URL}/v1/public/tokens/supported_destination_tokens`;
|
|
221
|
+
const params = new URLSearchParams();
|
|
222
|
+
if (options?.product_type) {
|
|
223
|
+
params.set("product_type", options.product_type);
|
|
224
|
+
}
|
|
225
|
+
const qs = params.toString();
|
|
226
|
+
if (qs) {
|
|
227
|
+
url = `${url}?${qs}`;
|
|
228
|
+
}
|
|
229
|
+
const response = await fetch(url, {
|
|
230
|
+
method: "GET",
|
|
231
|
+
headers: {
|
|
232
|
+
accept: "application/json",
|
|
233
|
+
"x-publishable-key": pk
|
|
224
234
|
}
|
|
225
|
-
);
|
|
235
|
+
});
|
|
226
236
|
if (!response.ok) {
|
|
227
237
|
throw new Error(
|
|
228
238
|
`Failed to fetch supported destination tokens: ${response.statusText}`
|
|
@@ -234,13 +244,18 @@ async function getSupportedDepositTokens(publishableKey, options) {
|
|
|
234
244
|
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
235
245
|
validatePublishableKey(pk);
|
|
236
246
|
let url = `${API_BASE_URL}/v1/public/tokens/supported_deposit_tokens`;
|
|
247
|
+
const params = new URLSearchParams();
|
|
237
248
|
if (options?.destination_token_address && options?.destination_chain_id && options?.destination_chain_type) {
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
249
|
+
params.set("destination_token_address", options.destination_token_address);
|
|
250
|
+
params.set("destination_chain_id", options.destination_chain_id);
|
|
251
|
+
params.set("destination_chain_type", options.destination_chain_type);
|
|
252
|
+
}
|
|
253
|
+
if (options?.product_type) {
|
|
254
|
+
params.set("product_type", options.product_type);
|
|
255
|
+
}
|
|
256
|
+
const qs = params.toString();
|
|
257
|
+
if (qs) {
|
|
258
|
+
url = `${url}?${qs}`;
|
|
244
259
|
}
|
|
245
260
|
const response = await fetch(url, {
|
|
246
261
|
method: "GET",
|
|
@@ -732,6 +747,71 @@ async function buildHypercoreTransaction(request, publishableKey) {
|
|
|
732
747
|
}
|
|
733
748
|
return response.json();
|
|
734
749
|
}
|
|
750
|
+
async function getCashAppLimits(currency = "usd", publishableKey) {
|
|
751
|
+
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
752
|
+
validatePublishableKey(pk);
|
|
753
|
+
const response = await fetch(
|
|
754
|
+
`${API_BASE_URL}/v1/public/onramps/cashapp/limits?currency=${encodeURIComponent(currency)}`,
|
|
755
|
+
{
|
|
756
|
+
method: "GET",
|
|
757
|
+
headers: {
|
|
758
|
+
accept: "application/json",
|
|
759
|
+
"x-publishable-key": pk
|
|
760
|
+
}
|
|
761
|
+
}
|
|
762
|
+
);
|
|
763
|
+
if (!response.ok) {
|
|
764
|
+
const error = await response.json().catch(() => ({ message: response.statusText }));
|
|
765
|
+
throw new Error(
|
|
766
|
+
`Failed to get Cash App limits: ${error.message || response.statusText}`
|
|
767
|
+
);
|
|
768
|
+
}
|
|
769
|
+
return response.json();
|
|
770
|
+
}
|
|
771
|
+
async function createCashAppSession(request, publishableKey) {
|
|
772
|
+
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
773
|
+
validatePublishableKey(pk);
|
|
774
|
+
const response = await fetch(
|
|
775
|
+
`${API_BASE_URL}/v1/public/onramps/cashapp/sessions`,
|
|
776
|
+
{
|
|
777
|
+
method: "POST",
|
|
778
|
+
headers: {
|
|
779
|
+
accept: "application/json",
|
|
780
|
+
"x-publishable-key": pk,
|
|
781
|
+
"Content-Type": "application/json"
|
|
782
|
+
},
|
|
783
|
+
body: JSON.stringify(request)
|
|
784
|
+
}
|
|
785
|
+
);
|
|
786
|
+
if (!response.ok) {
|
|
787
|
+
const error = await response.json().catch(() => ({ message: response.statusText }));
|
|
788
|
+
throw new Error(
|
|
789
|
+
`Failed to create Cash App session: ${error.message || response.statusText}`
|
|
790
|
+
);
|
|
791
|
+
}
|
|
792
|
+
return response.json();
|
|
793
|
+
}
|
|
794
|
+
async function getCashAppSessionStatus(externalId, publishableKey) {
|
|
795
|
+
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
796
|
+
validatePublishableKey(pk);
|
|
797
|
+
const response = await fetch(
|
|
798
|
+
`${API_BASE_URL}/v1/public/onramps/cashapp/sessions/${encodeURIComponent(externalId)}/status`,
|
|
799
|
+
{
|
|
800
|
+
method: "GET",
|
|
801
|
+
headers: {
|
|
802
|
+
accept: "application/json",
|
|
803
|
+
"x-publishable-key": pk
|
|
804
|
+
}
|
|
805
|
+
}
|
|
806
|
+
);
|
|
807
|
+
if (!response.ok) {
|
|
808
|
+
const error = await response.json().catch(() => ({ message: response.statusText }));
|
|
809
|
+
throw new Error(
|
|
810
|
+
`Failed to get Cash App session status: ${error.message || response.statusText}`
|
|
811
|
+
);
|
|
812
|
+
}
|
|
813
|
+
return response.json();
|
|
814
|
+
}
|
|
735
815
|
async function sendHypercoreTransaction(request, publishableKey) {
|
|
736
816
|
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
737
817
|
validatePublishableKey(pk);
|
|
@@ -757,6 +837,12 @@ async function sendHypercoreTransaction(request, publishableKey) {
|
|
|
757
837
|
}
|
|
758
838
|
|
|
759
839
|
// src/lib/utils.ts
|
|
840
|
+
function formatStablecoinAmount(baseUnits, decimals) {
|
|
841
|
+
const raw = Number(baseUnits) / 10 ** decimals;
|
|
842
|
+
const floored = Math.floor(raw * 100) / 100;
|
|
843
|
+
const ceiled = raw > floored ? floored + 0.01 : raw;
|
|
844
|
+
return ceiled.toFixed(2);
|
|
845
|
+
}
|
|
760
846
|
function generatePrefixedKSUID(prefix) {
|
|
761
847
|
const BASE62 = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
|
762
848
|
const KSUID_EPOCH = 14e8;
|
|
@@ -803,10 +889,10 @@ function useUserIp() {
|
|
|
803
889
|
queryKey: ["unifold", "userIpInfo"],
|
|
804
890
|
queryFn: async () => {
|
|
805
891
|
const data = await getIpAddress();
|
|
806
|
-
const subdivision =
|
|
892
|
+
const subdivision = data.subdivision_code || data.state || "" || null;
|
|
807
893
|
return {
|
|
808
|
-
alpha2: data.alpha2
|
|
809
|
-
alpha3: data.alpha3
|
|
894
|
+
alpha2: data.alpha2,
|
|
895
|
+
alpha3: data.alpha3,
|
|
810
896
|
country: data.country,
|
|
811
897
|
state: subdivision,
|
|
812
898
|
subdivisionCode: subdivision,
|
|
@@ -933,13 +1019,17 @@ var i18n = en_default;
|
|
|
933
1019
|
buildHypercoreTransaction,
|
|
934
1020
|
buildSolanaTransaction,
|
|
935
1021
|
checkHypercoreActivation,
|
|
1022
|
+
createCashAppSession,
|
|
936
1023
|
createDepositAddress,
|
|
937
1024
|
createExchangeSession,
|
|
938
1025
|
createOnrampSession,
|
|
1026
|
+
formatStablecoinAmount,
|
|
939
1027
|
generatePrefixedKSUID,
|
|
940
1028
|
getAddressBalance,
|
|
941
1029
|
getAddressBalances,
|
|
942
1030
|
getApiBaseUrl,
|
|
1031
|
+
getCashAppLimits,
|
|
1032
|
+
getCashAppSessionStatus,
|
|
943
1033
|
getChainName,
|
|
944
1034
|
getDefaultOnrampToken,
|
|
945
1035
|
getDepositQuote,
|
package/dist/index.mjs
CHANGED
|
@@ -142,19 +142,25 @@ async function pollDirectExecutions(request, publishableKey) {
|
|
|
142
142
|
}
|
|
143
143
|
return response.json();
|
|
144
144
|
}
|
|
145
|
-
async function getSupportedDestinationTokens(publishableKey) {
|
|
145
|
+
async function getSupportedDestinationTokens(publishableKey, options) {
|
|
146
146
|
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
147
147
|
validatePublishableKey(pk);
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
148
|
+
let url = `${API_BASE_URL}/v1/public/tokens/supported_destination_tokens`;
|
|
149
|
+
const params = new URLSearchParams();
|
|
150
|
+
if (options?.product_type) {
|
|
151
|
+
params.set("product_type", options.product_type);
|
|
152
|
+
}
|
|
153
|
+
const qs = params.toString();
|
|
154
|
+
if (qs) {
|
|
155
|
+
url = `${url}?${qs}`;
|
|
156
|
+
}
|
|
157
|
+
const response = await fetch(url, {
|
|
158
|
+
method: "GET",
|
|
159
|
+
headers: {
|
|
160
|
+
accept: "application/json",
|
|
161
|
+
"x-publishable-key": pk
|
|
156
162
|
}
|
|
157
|
-
);
|
|
163
|
+
});
|
|
158
164
|
if (!response.ok) {
|
|
159
165
|
throw new Error(
|
|
160
166
|
`Failed to fetch supported destination tokens: ${response.statusText}`
|
|
@@ -166,13 +172,18 @@ async function getSupportedDepositTokens(publishableKey, options) {
|
|
|
166
172
|
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
167
173
|
validatePublishableKey(pk);
|
|
168
174
|
let url = `${API_BASE_URL}/v1/public/tokens/supported_deposit_tokens`;
|
|
175
|
+
const params = new URLSearchParams();
|
|
169
176
|
if (options?.destination_token_address && options?.destination_chain_id && options?.destination_chain_type) {
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
177
|
+
params.set("destination_token_address", options.destination_token_address);
|
|
178
|
+
params.set("destination_chain_id", options.destination_chain_id);
|
|
179
|
+
params.set("destination_chain_type", options.destination_chain_type);
|
|
180
|
+
}
|
|
181
|
+
if (options?.product_type) {
|
|
182
|
+
params.set("product_type", options.product_type);
|
|
183
|
+
}
|
|
184
|
+
const qs = params.toString();
|
|
185
|
+
if (qs) {
|
|
186
|
+
url = `${url}?${qs}`;
|
|
176
187
|
}
|
|
177
188
|
const response = await fetch(url, {
|
|
178
189
|
method: "GET",
|
|
@@ -664,6 +675,71 @@ async function buildHypercoreTransaction(request, publishableKey) {
|
|
|
664
675
|
}
|
|
665
676
|
return response.json();
|
|
666
677
|
}
|
|
678
|
+
async function getCashAppLimits(currency = "usd", publishableKey) {
|
|
679
|
+
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
680
|
+
validatePublishableKey(pk);
|
|
681
|
+
const response = await fetch(
|
|
682
|
+
`${API_BASE_URL}/v1/public/onramps/cashapp/limits?currency=${encodeURIComponent(currency)}`,
|
|
683
|
+
{
|
|
684
|
+
method: "GET",
|
|
685
|
+
headers: {
|
|
686
|
+
accept: "application/json",
|
|
687
|
+
"x-publishable-key": pk
|
|
688
|
+
}
|
|
689
|
+
}
|
|
690
|
+
);
|
|
691
|
+
if (!response.ok) {
|
|
692
|
+
const error = await response.json().catch(() => ({ message: response.statusText }));
|
|
693
|
+
throw new Error(
|
|
694
|
+
`Failed to get Cash App limits: ${error.message || response.statusText}`
|
|
695
|
+
);
|
|
696
|
+
}
|
|
697
|
+
return response.json();
|
|
698
|
+
}
|
|
699
|
+
async function createCashAppSession(request, publishableKey) {
|
|
700
|
+
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
701
|
+
validatePublishableKey(pk);
|
|
702
|
+
const response = await fetch(
|
|
703
|
+
`${API_BASE_URL}/v1/public/onramps/cashapp/sessions`,
|
|
704
|
+
{
|
|
705
|
+
method: "POST",
|
|
706
|
+
headers: {
|
|
707
|
+
accept: "application/json",
|
|
708
|
+
"x-publishable-key": pk,
|
|
709
|
+
"Content-Type": "application/json"
|
|
710
|
+
},
|
|
711
|
+
body: JSON.stringify(request)
|
|
712
|
+
}
|
|
713
|
+
);
|
|
714
|
+
if (!response.ok) {
|
|
715
|
+
const error = await response.json().catch(() => ({ message: response.statusText }));
|
|
716
|
+
throw new Error(
|
|
717
|
+
`Failed to create Cash App session: ${error.message || response.statusText}`
|
|
718
|
+
);
|
|
719
|
+
}
|
|
720
|
+
return response.json();
|
|
721
|
+
}
|
|
722
|
+
async function getCashAppSessionStatus(externalId, publishableKey) {
|
|
723
|
+
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
724
|
+
validatePublishableKey(pk);
|
|
725
|
+
const response = await fetch(
|
|
726
|
+
`${API_BASE_URL}/v1/public/onramps/cashapp/sessions/${encodeURIComponent(externalId)}/status`,
|
|
727
|
+
{
|
|
728
|
+
method: "GET",
|
|
729
|
+
headers: {
|
|
730
|
+
accept: "application/json",
|
|
731
|
+
"x-publishable-key": pk
|
|
732
|
+
}
|
|
733
|
+
}
|
|
734
|
+
);
|
|
735
|
+
if (!response.ok) {
|
|
736
|
+
const error = await response.json().catch(() => ({ message: response.statusText }));
|
|
737
|
+
throw new Error(
|
|
738
|
+
`Failed to get Cash App session status: ${error.message || response.statusText}`
|
|
739
|
+
);
|
|
740
|
+
}
|
|
741
|
+
return response.json();
|
|
742
|
+
}
|
|
667
743
|
async function sendHypercoreTransaction(request, publishableKey) {
|
|
668
744
|
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
669
745
|
validatePublishableKey(pk);
|
|
@@ -689,6 +765,12 @@ async function sendHypercoreTransaction(request, publishableKey) {
|
|
|
689
765
|
}
|
|
690
766
|
|
|
691
767
|
// src/lib/utils.ts
|
|
768
|
+
function formatStablecoinAmount(baseUnits, decimals) {
|
|
769
|
+
const raw = Number(baseUnits) / 10 ** decimals;
|
|
770
|
+
const floored = Math.floor(raw * 100) / 100;
|
|
771
|
+
const ceiled = raw > floored ? floored + 0.01 : raw;
|
|
772
|
+
return ceiled.toFixed(2);
|
|
773
|
+
}
|
|
692
774
|
function generatePrefixedKSUID(prefix) {
|
|
693
775
|
const BASE62 = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
|
694
776
|
const KSUID_EPOCH = 14e8;
|
|
@@ -735,10 +817,10 @@ function useUserIp() {
|
|
|
735
817
|
queryKey: ["unifold", "userIpInfo"],
|
|
736
818
|
queryFn: async () => {
|
|
737
819
|
const data = await getIpAddress();
|
|
738
|
-
const subdivision =
|
|
820
|
+
const subdivision = data.subdivision_code || data.state || "" || null;
|
|
739
821
|
return {
|
|
740
|
-
alpha2: data.alpha2
|
|
741
|
-
alpha3: data.alpha3
|
|
822
|
+
alpha2: data.alpha2,
|
|
823
|
+
alpha3: data.alpha3,
|
|
742
824
|
country: data.country,
|
|
743
825
|
state: subdivision,
|
|
744
826
|
subdivisionCode: subdivision,
|
|
@@ -864,13 +946,17 @@ export {
|
|
|
864
946
|
buildHypercoreTransaction,
|
|
865
947
|
buildSolanaTransaction,
|
|
866
948
|
checkHypercoreActivation,
|
|
949
|
+
createCashAppSession,
|
|
867
950
|
createDepositAddress,
|
|
868
951
|
createExchangeSession,
|
|
869
952
|
createOnrampSession,
|
|
953
|
+
formatStablecoinAmount,
|
|
870
954
|
generatePrefixedKSUID,
|
|
871
955
|
getAddressBalance,
|
|
872
956
|
getAddressBalances,
|
|
873
957
|
getApiBaseUrl,
|
|
958
|
+
getCashAppLimits,
|
|
959
|
+
getCashAppSessionStatus,
|
|
874
960
|
getChainName,
|
|
875
961
|
getDefaultOnrampToken,
|
|
876
962
|
getDepositQuote,
|