@unifold/connect-react 0.1.46 → 0.1.48
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 +16 -1
- package/dist/index.d.ts +16 -1
- package/dist/index.js +68 -4
- package/dist/index.mjs +66 -4
- package/package.json +4 -9
package/dist/index.d.mts
CHANGED
|
@@ -2,7 +2,8 @@ import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import { ThemeMode, ThemeConfig, FontConfig, ComponentConfig, DepositModalInitialScreen, ChainType, DepositConfirmationMode, WithdrawTransactionInfo, AllowedCountryResult } from '@unifold/ui-react';
|
|
4
4
|
export { AllowedCountryResult, BrowserWalletAmountQuickSelect, Button, ButtonProps, ButtonTokens, CardTokens, ComponentConfig, ComponentTokens, ConfirmingView, ContainerTokens, CustomThemeColors, DepositConfirmationMode, DepositModalInitialScreen as DepositInitialScreen, FontConfig, HeaderTokens, InputTokens, ListTokens, SearchTokens, ThemeColors, ThemeConfig, ThemeMode, WithdrawTransactionInfo } from '@unifold/ui-react';
|
|
5
|
-
|
|
5
|
+
import { DepositEvent } from '@unifold/core';
|
|
6
|
+
export { ActionType, AutoSwapRequest, AutoSwapResponse, ChainType, CreateDepositAddressRequest, DefaultTokenChain, DefaultTokenMetadata, DefaultTokenResponse, DepositAddressResponse, DepositEvent, DepositEventType, DestinationToken, DestinationTokenChain, ExecutionStatus, FeaturedToken, FiatCurrenciesResponse, FiatCurrency, I18nStrings, IconUrl, IpAddressResponse, OnrampQuote, OnrampQuotesRequest, OnrampQuotesResponse, OnrampSessionCreatedData, OnrampSessionCreatedEvent, OnrampSessionRequest, OnrampSessionResponse, PaymentIntent, PaymentIntentDepositAddress, PaymentNetwork, ProjectConfigResponse, QueryExecutionsRequest, QueryExecutionsResponse, SOLANA_USDC_ADDRESS, SendSolanaTransactionRequest, SendSolanaTransactionResponse, SupportedChain, SupportedDepositTokensResponse, SupportedDestinationTokensResponse, SupportedToken, TokenChain, TokenChainIconUrl, TokenChainsResponse, UserIpInfo, Wallet, createDepositAddress, createOnrampSession, generatePrefixedKSUID, getApiBaseUrl, getChainName, getDefaultOnrampToken, getFiatCurrencies, getIconUrl, getIconUrlWithCdn, getIpAddress, getOnrampQuotes, getPreferredIconUrl, getProjectConfig, getSupportedDepositTokens, getSupportedDestinationTokens, getTokenChains, getWalletByChainType, i18n, queryExecutions, sendSolanaTransaction, setApiConfig, useUserIp } from '@unifold/core';
|
|
6
7
|
|
|
7
8
|
interface UnifoldConnectProviderConfig {
|
|
8
9
|
publishableKey: string;
|
|
@@ -86,6 +87,8 @@ interface DepositConfig {
|
|
|
86
87
|
onError?: (error: DepositError) => void;
|
|
87
88
|
/** Called when the user dismisses the deposit dialog (X button, Escape key, or programmatic close) */
|
|
88
89
|
onClose?: () => void;
|
|
90
|
+
/** Called when deposit lifecycle events occur. Use {@link DepositEventType} to narrow the event type. See {@link DepositEvent} for the full union. */
|
|
91
|
+
onEvent?: (event: DepositEvent) => void;
|
|
89
92
|
/**
|
|
90
93
|
* Which screen opens first: menu (`main`, default), `transfer`, `card`, or `tracker`.
|
|
91
94
|
* `transfer` and `card` run the same geo / recipient checks as the menu before the flow. `tracker` does not
|
|
@@ -115,6 +118,18 @@ interface WithdrawError {
|
|
|
115
118
|
interface CheckoutConfig {
|
|
116
119
|
/** The client_secret from a PaymentIntent created on your server */
|
|
117
120
|
clientSecret: string;
|
|
121
|
+
/**
|
|
122
|
+
* Pre-select source token/chain in the Transfer Crypto view.
|
|
123
|
+
* All four props are optional. To match a specific token, provide `chainType` + `chainId` + (`symbol` OR `tokenAddress`).
|
|
124
|
+
* If omitted or no match is found in `/supported_deposit_tokens`, the first available token and chain are used.
|
|
125
|
+
*/
|
|
126
|
+
defaultSourceChainType?: ChainType;
|
|
127
|
+
/** Source chain ID (e.g. `"mainnet"`, `"137"`). Must be paired with `defaultSourceChainType` + symbol or token address. */
|
|
128
|
+
defaultSourceChainId?: string;
|
|
129
|
+
/** Source token contract address. Must be paired with `defaultSourceChainType` + `defaultSourceChainId`. */
|
|
130
|
+
defaultSourceTokenAddress?: string;
|
|
131
|
+
/** Source token symbol (e.g. `"USDC"`). Must be paired with `defaultSourceChainType` + `defaultSourceChainId`. */
|
|
132
|
+
defaultSourceSymbol?: string;
|
|
118
133
|
/** Optional callbacks (fired immediately when events occur) */
|
|
119
134
|
onSuccess?: (data: CheckoutResult) => void;
|
|
120
135
|
onError?: (error: CheckoutError) => void;
|
package/dist/index.d.ts
CHANGED
|
@@ -2,7 +2,8 @@ import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import { ThemeMode, ThemeConfig, FontConfig, ComponentConfig, DepositModalInitialScreen, ChainType, DepositConfirmationMode, WithdrawTransactionInfo, AllowedCountryResult } from '@unifold/ui-react';
|
|
4
4
|
export { AllowedCountryResult, BrowserWalletAmountQuickSelect, Button, ButtonProps, ButtonTokens, CardTokens, ComponentConfig, ComponentTokens, ConfirmingView, ContainerTokens, CustomThemeColors, DepositConfirmationMode, DepositModalInitialScreen as DepositInitialScreen, FontConfig, HeaderTokens, InputTokens, ListTokens, SearchTokens, ThemeColors, ThemeConfig, ThemeMode, WithdrawTransactionInfo } from '@unifold/ui-react';
|
|
5
|
-
|
|
5
|
+
import { DepositEvent } from '@unifold/core';
|
|
6
|
+
export { ActionType, AutoSwapRequest, AutoSwapResponse, ChainType, CreateDepositAddressRequest, DefaultTokenChain, DefaultTokenMetadata, DefaultTokenResponse, DepositAddressResponse, DepositEvent, DepositEventType, DestinationToken, DestinationTokenChain, ExecutionStatus, FeaturedToken, FiatCurrenciesResponse, FiatCurrency, I18nStrings, IconUrl, IpAddressResponse, OnrampQuote, OnrampQuotesRequest, OnrampQuotesResponse, OnrampSessionCreatedData, OnrampSessionCreatedEvent, OnrampSessionRequest, OnrampSessionResponse, PaymentIntent, PaymentIntentDepositAddress, PaymentNetwork, ProjectConfigResponse, QueryExecutionsRequest, QueryExecutionsResponse, SOLANA_USDC_ADDRESS, SendSolanaTransactionRequest, SendSolanaTransactionResponse, SupportedChain, SupportedDepositTokensResponse, SupportedDestinationTokensResponse, SupportedToken, TokenChain, TokenChainIconUrl, TokenChainsResponse, UserIpInfo, Wallet, createDepositAddress, createOnrampSession, generatePrefixedKSUID, getApiBaseUrl, getChainName, getDefaultOnrampToken, getFiatCurrencies, getIconUrl, getIconUrlWithCdn, getIpAddress, getOnrampQuotes, getPreferredIconUrl, getProjectConfig, getSupportedDepositTokens, getSupportedDestinationTokens, getTokenChains, getWalletByChainType, i18n, queryExecutions, sendSolanaTransaction, setApiConfig, useUserIp } from '@unifold/core';
|
|
6
7
|
|
|
7
8
|
interface UnifoldConnectProviderConfig {
|
|
8
9
|
publishableKey: string;
|
|
@@ -86,6 +87,8 @@ interface DepositConfig {
|
|
|
86
87
|
onError?: (error: DepositError) => void;
|
|
87
88
|
/** Called when the user dismisses the deposit dialog (X button, Escape key, or programmatic close) */
|
|
88
89
|
onClose?: () => void;
|
|
90
|
+
/** Called when deposit lifecycle events occur. Use {@link DepositEventType} to narrow the event type. See {@link DepositEvent} for the full union. */
|
|
91
|
+
onEvent?: (event: DepositEvent) => void;
|
|
89
92
|
/**
|
|
90
93
|
* Which screen opens first: menu (`main`, default), `transfer`, `card`, or `tracker`.
|
|
91
94
|
* `transfer` and `card` run the same geo / recipient checks as the menu before the flow. `tracker` does not
|
|
@@ -115,6 +118,18 @@ interface WithdrawError {
|
|
|
115
118
|
interface CheckoutConfig {
|
|
116
119
|
/** The client_secret from a PaymentIntent created on your server */
|
|
117
120
|
clientSecret: string;
|
|
121
|
+
/**
|
|
122
|
+
* Pre-select source token/chain in the Transfer Crypto view.
|
|
123
|
+
* All four props are optional. To match a specific token, provide `chainType` + `chainId` + (`symbol` OR `tokenAddress`).
|
|
124
|
+
* If omitted or no match is found in `/supported_deposit_tokens`, the first available token and chain are used.
|
|
125
|
+
*/
|
|
126
|
+
defaultSourceChainType?: ChainType;
|
|
127
|
+
/** Source chain ID (e.g. `"mainnet"`, `"137"`). Must be paired with `defaultSourceChainType` + symbol or token address. */
|
|
128
|
+
defaultSourceChainId?: string;
|
|
129
|
+
/** Source token contract address. Must be paired with `defaultSourceChainType` + `defaultSourceChainId`. */
|
|
130
|
+
defaultSourceTokenAddress?: string;
|
|
131
|
+
/** Source token symbol (e.g. `"USDC"`). Must be paired with `defaultSourceChainType` + `defaultSourceChainId`. */
|
|
132
|
+
defaultSourceSymbol?: string;
|
|
118
133
|
/** Optional callbacks (fired immediately when events occur) */
|
|
119
134
|
onSuccess?: (data: CheckoutResult) => void;
|
|
120
135
|
onError?: (error: CheckoutError) => void;
|
package/dist/index.js
CHANGED
|
@@ -1155,11 +1155,13 @@ __export(index_exports, {
|
|
|
1155
1155
|
ActionType: () => ActionType,
|
|
1156
1156
|
Button: () => Button,
|
|
1157
1157
|
ConfirmingView: () => ConfirmingView,
|
|
1158
|
+
DepositEventType: () => DepositEventType,
|
|
1158
1159
|
ExecutionStatus: () => ExecutionStatus,
|
|
1159
1160
|
SOLANA_USDC_ADDRESS: () => SOLANA_USDC_ADDRESS,
|
|
1160
1161
|
UnifoldProvider: () => UnifoldProvider2,
|
|
1161
1162
|
createDepositAddress: () => createDepositAddress,
|
|
1162
1163
|
createOnrampSession: () => createOnrampSession,
|
|
1164
|
+
generatePrefixedKSUID: () => generatePrefixedKSUID,
|
|
1163
1165
|
getApiBaseUrl: () => getApiBaseUrl,
|
|
1164
1166
|
getChainName: () => getChainName,
|
|
1165
1167
|
getDefaultOnrampToken: () => getDefaultOnrampToken,
|
|
@@ -6392,6 +6394,9 @@ function getOnrampSessionStartUrl(request, publishableKey) {
|
|
|
6392
6394
|
if (request.subdivision_code) {
|
|
6393
6395
|
params.append("subdivision_code", request.subdivision_code);
|
|
6394
6396
|
}
|
|
6397
|
+
if (request.external_id) {
|
|
6398
|
+
params.append("external_id", request.external_id);
|
|
6399
|
+
}
|
|
6395
6400
|
return `${API_BASE_URL}/v1/public/onramps/sessions/start?${params.toString()}`;
|
|
6396
6401
|
}
|
|
6397
6402
|
async function getDefaultOnrampToken(params, publishableKey) {
|
|
@@ -6715,6 +6720,38 @@ async function getDepositQuote(request, publishableKey) {
|
|
|
6715
6720
|
const json = await response.json();
|
|
6716
6721
|
return json.data;
|
|
6717
6722
|
}
|
|
6723
|
+
function generatePrefixedKSUID(prefix) {
|
|
6724
|
+
const BASE62 = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
|
6725
|
+
const KSUID_EPOCH = 14e8;
|
|
6726
|
+
const timestampSeconds = Math.floor(Date.now() / 1e3) - KSUID_EPOCH;
|
|
6727
|
+
const payload = new Uint8Array(20);
|
|
6728
|
+
payload[0] = timestampSeconds >>> 24 & 255;
|
|
6729
|
+
payload[1] = timestampSeconds >>> 16 & 255;
|
|
6730
|
+
payload[2] = timestampSeconds >>> 8 & 255;
|
|
6731
|
+
payload[3] = timestampSeconds & 255;
|
|
6732
|
+
if (typeof crypto !== "undefined" && crypto.getRandomValues) {
|
|
6733
|
+
crypto.getRandomValues(payload.subarray(4));
|
|
6734
|
+
} else {
|
|
6735
|
+
for (let i = 4; i < 20; i++) {
|
|
6736
|
+
payload[i] = Math.floor(Math.random() * 256);
|
|
6737
|
+
}
|
|
6738
|
+
}
|
|
6739
|
+
let value = 0n;
|
|
6740
|
+
for (const byte of payload) {
|
|
6741
|
+
value = value << 8n | BigInt(byte);
|
|
6742
|
+
}
|
|
6743
|
+
let encoded = "";
|
|
6744
|
+
while (value > 0n) {
|
|
6745
|
+
encoded = BASE62[Number(value % 62n)] + encoded;
|
|
6746
|
+
value = value / 62n;
|
|
6747
|
+
}
|
|
6748
|
+
encoded = encoded.padStart(27, "0");
|
|
6749
|
+
return `${prefix}_${encoded}`;
|
|
6750
|
+
}
|
|
6751
|
+
var DepositEventType = /* @__PURE__ */ ((DepositEventType2) => {
|
|
6752
|
+
DepositEventType2["ONRAMP_SESSION_CREATED"] = "onramp_session.created";
|
|
6753
|
+
return DepositEventType2;
|
|
6754
|
+
})(DepositEventType || {});
|
|
6718
6755
|
function useUserIp() {
|
|
6719
6756
|
const {
|
|
6720
6757
|
data: userIpInfo,
|
|
@@ -13360,6 +13397,7 @@ function BuyWithCard({
|
|
|
13360
13397
|
destinationTokenAddress,
|
|
13361
13398
|
onDepositSuccess,
|
|
13362
13399
|
onDepositError,
|
|
13400
|
+
onEvent,
|
|
13363
13401
|
themeClass = "",
|
|
13364
13402
|
wallets: externalWallets,
|
|
13365
13403
|
assetCdnUrl,
|
|
@@ -13713,6 +13751,7 @@ function BuyWithCard({
|
|
|
13713
13751
|
setQuotesError("Wallet address not available");
|
|
13714
13752
|
return;
|
|
13715
13753
|
}
|
|
13754
|
+
const externalId = generatePrefixedKSUID("orsext");
|
|
13716
13755
|
const sessionRequest = {
|
|
13717
13756
|
service_provider: selectedProvider.service_provider,
|
|
13718
13757
|
country_code: selectedProvider.country_code.toUpperCase() || "US",
|
|
@@ -13721,7 +13760,8 @@ function BuyWithCard({
|
|
|
13721
13760
|
destination_currency: selectedProvider.destination_currency,
|
|
13722
13761
|
destination_network: selectedProvider.destination_network,
|
|
13723
13762
|
wallet_address: wallet.address,
|
|
13724
|
-
subdivision_code: userIpInfo?.state || void 0
|
|
13763
|
+
subdivision_code: userIpInfo?.state || void 0,
|
|
13764
|
+
external_id: externalId
|
|
13725
13765
|
};
|
|
13726
13766
|
const sessionStartUrl = getOnrampSessionStartUrl(
|
|
13727
13767
|
sessionRequest,
|
|
@@ -13731,7 +13771,14 @@ function BuyWithCard({
|
|
|
13731
13771
|
provider: selectedProvider,
|
|
13732
13772
|
sourceCurrency: currency,
|
|
13733
13773
|
sourceAmount: amount,
|
|
13734
|
-
sessionUrl: sessionStartUrl
|
|
13774
|
+
sessionUrl: sessionStartUrl,
|
|
13775
|
+
externalId
|
|
13776
|
+
});
|
|
13777
|
+
onEvent?.({
|
|
13778
|
+
id: generatePrefixedKSUID("sevt"),
|
|
13779
|
+
type: DepositEventType.ONRAMP_SESSION_CREATED,
|
|
13780
|
+
created: Math.floor(Date.now() / 1e3),
|
|
13781
|
+
data: { object: { externalId } }
|
|
13735
13782
|
});
|
|
13736
13783
|
window.open(sessionStartUrl, "_blank");
|
|
13737
13784
|
handleViewChange("onramp");
|
|
@@ -22494,6 +22541,7 @@ function DepositModal({
|
|
|
22494
22541
|
hideDisplayDescription = false,
|
|
22495
22542
|
onDepositSuccess,
|
|
22496
22543
|
onDepositError,
|
|
22544
|
+
onEvent,
|
|
22497
22545
|
theme = "dark",
|
|
22498
22546
|
hideOverlay = false,
|
|
22499
22547
|
initialScreen = "main",
|
|
@@ -23008,6 +23056,7 @@ function DepositModal({
|
|
|
23008
23056
|
destinationTokenAddress,
|
|
23009
23057
|
onDepositSuccess,
|
|
23010
23058
|
onDepositError,
|
|
23059
|
+
onEvent,
|
|
23011
23060
|
themeClass,
|
|
23012
23061
|
wallets,
|
|
23013
23062
|
assetCdnUrl: projectConfig?.asset_cdn_url,
|
|
@@ -23191,6 +23240,10 @@ function CheckoutModal({
|
|
|
23191
23240
|
publishableKey,
|
|
23192
23241
|
modalTitle,
|
|
23193
23242
|
enableConnectWallet = false,
|
|
23243
|
+
defaultSourceChainType,
|
|
23244
|
+
defaultSourceChainId,
|
|
23245
|
+
defaultSourceTokenAddress,
|
|
23246
|
+
defaultSourceSymbol,
|
|
23194
23247
|
theme = "dark",
|
|
23195
23248
|
onCheckoutSuccess,
|
|
23196
23249
|
onCheckoutError
|
|
@@ -23688,6 +23741,10 @@ function CheckoutModal({
|
|
|
23688
23741
|
destinationChainType: paymentIntent.destination_chain_type,
|
|
23689
23742
|
destinationChainId: paymentIntent.destination_chain_id,
|
|
23690
23743
|
destinationTokenAddress: paymentIntent.destination_token_address,
|
|
23744
|
+
defaultSourceChainType,
|
|
23745
|
+
defaultSourceChainId,
|
|
23746
|
+
defaultSourceTokenAddress,
|
|
23747
|
+
defaultSourceSymbol,
|
|
23691
23748
|
depositConfirmationMode: "auto_ui",
|
|
23692
23749
|
wallets,
|
|
23693
23750
|
onSourceTokenChange: setSelectedSource,
|
|
@@ -24340,8 +24397,8 @@ function WithdrawForm({
|
|
|
24340
24397
|
setAmount(fiat.toFixed(2));
|
|
24341
24398
|
setInputUnit("fiat");
|
|
24342
24399
|
} else {
|
|
24343
|
-
const
|
|
24344
|
-
setAmount(
|
|
24400
|
+
const crypto2 = val / exchangeRate;
|
|
24401
|
+
setAmount(crypto2.toFixed(sourceDecimals > 6 ? 6 : sourceDecimals));
|
|
24345
24402
|
setInputUnit("crypto");
|
|
24346
24403
|
}
|
|
24347
24404
|
}, [amount, inputUnit, exchangeRate, sourceDecimals]);
|
|
@@ -25541,6 +25598,10 @@ function UnifoldProvider2({
|
|
|
25541
25598
|
clientSecret: checkoutConfig.clientSecret,
|
|
25542
25599
|
publishableKey,
|
|
25543
25600
|
enableConnectWallet: config?.enableConnectWallet,
|
|
25601
|
+
defaultSourceChainType: checkoutConfig.defaultSourceChainType,
|
|
25602
|
+
defaultSourceChainId: checkoutConfig.defaultSourceChainId,
|
|
25603
|
+
defaultSourceTokenAddress: checkoutConfig.defaultSourceTokenAddress,
|
|
25604
|
+
defaultSourceSymbol: checkoutConfig.defaultSourceSymbol,
|
|
25544
25605
|
theme: resolvedTheme,
|
|
25545
25606
|
onCheckoutSuccess: handleCheckoutSuccess,
|
|
25546
25607
|
onCheckoutError: handleCheckoutError
|
|
@@ -25591,6 +25652,7 @@ function UnifoldProvider2({
|
|
|
25591
25652
|
enablePayWithExchange: config?.enablePayWithExchange,
|
|
25592
25653
|
onDepositSuccess: handleDepositSuccess,
|
|
25593
25654
|
onDepositError: handleDepositError,
|
|
25655
|
+
onEvent: depositConfig.onEvent,
|
|
25594
25656
|
theme: resolvedTheme,
|
|
25595
25657
|
initialScreen: depositConfig.initialScreen ?? config?.defaultInitialScreen,
|
|
25596
25658
|
transferCryptoTitle: config?.transferCryptoTitle,
|
|
@@ -25647,11 +25709,13 @@ function useAllowedCountry2() {
|
|
|
25647
25709
|
ActionType,
|
|
25648
25710
|
Button,
|
|
25649
25711
|
ConfirmingView,
|
|
25712
|
+
DepositEventType,
|
|
25650
25713
|
ExecutionStatus,
|
|
25651
25714
|
SOLANA_USDC_ADDRESS,
|
|
25652
25715
|
UnifoldProvider,
|
|
25653
25716
|
createDepositAddress,
|
|
25654
25717
|
createOnrampSession,
|
|
25718
|
+
generatePrefixedKSUID,
|
|
25655
25719
|
getApiBaseUrl,
|
|
25656
25720
|
getChainName,
|
|
25657
25721
|
getDefaultOnrampToken,
|
package/dist/index.mjs
CHANGED
|
@@ -6370,6 +6370,9 @@ function getOnrampSessionStartUrl(request, publishableKey) {
|
|
|
6370
6370
|
if (request.subdivision_code) {
|
|
6371
6371
|
params.append("subdivision_code", request.subdivision_code);
|
|
6372
6372
|
}
|
|
6373
|
+
if (request.external_id) {
|
|
6374
|
+
params.append("external_id", request.external_id);
|
|
6375
|
+
}
|
|
6373
6376
|
return `${API_BASE_URL}/v1/public/onramps/sessions/start?${params.toString()}`;
|
|
6374
6377
|
}
|
|
6375
6378
|
async function getDefaultOnrampToken(params, publishableKey) {
|
|
@@ -6693,6 +6696,38 @@ async function getDepositQuote(request, publishableKey) {
|
|
|
6693
6696
|
const json = await response.json();
|
|
6694
6697
|
return json.data;
|
|
6695
6698
|
}
|
|
6699
|
+
function generatePrefixedKSUID(prefix) {
|
|
6700
|
+
const BASE62 = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
|
6701
|
+
const KSUID_EPOCH = 14e8;
|
|
6702
|
+
const timestampSeconds = Math.floor(Date.now() / 1e3) - KSUID_EPOCH;
|
|
6703
|
+
const payload = new Uint8Array(20);
|
|
6704
|
+
payload[0] = timestampSeconds >>> 24 & 255;
|
|
6705
|
+
payload[1] = timestampSeconds >>> 16 & 255;
|
|
6706
|
+
payload[2] = timestampSeconds >>> 8 & 255;
|
|
6707
|
+
payload[3] = timestampSeconds & 255;
|
|
6708
|
+
if (typeof crypto !== "undefined" && crypto.getRandomValues) {
|
|
6709
|
+
crypto.getRandomValues(payload.subarray(4));
|
|
6710
|
+
} else {
|
|
6711
|
+
for (let i = 4; i < 20; i++) {
|
|
6712
|
+
payload[i] = Math.floor(Math.random() * 256);
|
|
6713
|
+
}
|
|
6714
|
+
}
|
|
6715
|
+
let value = 0n;
|
|
6716
|
+
for (const byte of payload) {
|
|
6717
|
+
value = value << 8n | BigInt(byte);
|
|
6718
|
+
}
|
|
6719
|
+
let encoded = "";
|
|
6720
|
+
while (value > 0n) {
|
|
6721
|
+
encoded = BASE62[Number(value % 62n)] + encoded;
|
|
6722
|
+
value = value / 62n;
|
|
6723
|
+
}
|
|
6724
|
+
encoded = encoded.padStart(27, "0");
|
|
6725
|
+
return `${prefix}_${encoded}`;
|
|
6726
|
+
}
|
|
6727
|
+
var DepositEventType = /* @__PURE__ */ ((DepositEventType2) => {
|
|
6728
|
+
DepositEventType2["ONRAMP_SESSION_CREATED"] = "onramp_session.created";
|
|
6729
|
+
return DepositEventType2;
|
|
6730
|
+
})(DepositEventType || {});
|
|
6696
6731
|
function useUserIp() {
|
|
6697
6732
|
const {
|
|
6698
6733
|
data: userIpInfo,
|
|
@@ -13351,6 +13386,7 @@ function BuyWithCard({
|
|
|
13351
13386
|
destinationTokenAddress,
|
|
13352
13387
|
onDepositSuccess,
|
|
13353
13388
|
onDepositError,
|
|
13389
|
+
onEvent,
|
|
13354
13390
|
themeClass = "",
|
|
13355
13391
|
wallets: externalWallets,
|
|
13356
13392
|
assetCdnUrl,
|
|
@@ -13704,6 +13740,7 @@ function BuyWithCard({
|
|
|
13704
13740
|
setQuotesError("Wallet address not available");
|
|
13705
13741
|
return;
|
|
13706
13742
|
}
|
|
13743
|
+
const externalId = generatePrefixedKSUID("orsext");
|
|
13707
13744
|
const sessionRequest = {
|
|
13708
13745
|
service_provider: selectedProvider.service_provider,
|
|
13709
13746
|
country_code: selectedProvider.country_code.toUpperCase() || "US",
|
|
@@ -13712,7 +13749,8 @@ function BuyWithCard({
|
|
|
13712
13749
|
destination_currency: selectedProvider.destination_currency,
|
|
13713
13750
|
destination_network: selectedProvider.destination_network,
|
|
13714
13751
|
wallet_address: wallet.address,
|
|
13715
|
-
subdivision_code: userIpInfo?.state || void 0
|
|
13752
|
+
subdivision_code: userIpInfo?.state || void 0,
|
|
13753
|
+
external_id: externalId
|
|
13716
13754
|
};
|
|
13717
13755
|
const sessionStartUrl = getOnrampSessionStartUrl(
|
|
13718
13756
|
sessionRequest,
|
|
@@ -13722,7 +13760,14 @@ function BuyWithCard({
|
|
|
13722
13760
|
provider: selectedProvider,
|
|
13723
13761
|
sourceCurrency: currency,
|
|
13724
13762
|
sourceAmount: amount,
|
|
13725
|
-
sessionUrl: sessionStartUrl
|
|
13763
|
+
sessionUrl: sessionStartUrl,
|
|
13764
|
+
externalId
|
|
13765
|
+
});
|
|
13766
|
+
onEvent?.({
|
|
13767
|
+
id: generatePrefixedKSUID("sevt"),
|
|
13768
|
+
type: DepositEventType.ONRAMP_SESSION_CREATED,
|
|
13769
|
+
created: Math.floor(Date.now() / 1e3),
|
|
13770
|
+
data: { object: { externalId } }
|
|
13726
13771
|
});
|
|
13727
13772
|
window.open(sessionStartUrl, "_blank");
|
|
13728
13773
|
handleViewChange("onramp");
|
|
@@ -22485,6 +22530,7 @@ function DepositModal({
|
|
|
22485
22530
|
hideDisplayDescription = false,
|
|
22486
22531
|
onDepositSuccess,
|
|
22487
22532
|
onDepositError,
|
|
22533
|
+
onEvent,
|
|
22488
22534
|
theme = "dark",
|
|
22489
22535
|
hideOverlay = false,
|
|
22490
22536
|
initialScreen = "main",
|
|
@@ -22999,6 +23045,7 @@ function DepositModal({
|
|
|
22999
23045
|
destinationTokenAddress,
|
|
23000
23046
|
onDepositSuccess,
|
|
23001
23047
|
onDepositError,
|
|
23048
|
+
onEvent,
|
|
23002
23049
|
themeClass,
|
|
23003
23050
|
wallets,
|
|
23004
23051
|
assetCdnUrl: projectConfig?.asset_cdn_url,
|
|
@@ -23182,6 +23229,10 @@ function CheckoutModal({
|
|
|
23182
23229
|
publishableKey,
|
|
23183
23230
|
modalTitle,
|
|
23184
23231
|
enableConnectWallet = false,
|
|
23232
|
+
defaultSourceChainType,
|
|
23233
|
+
defaultSourceChainId,
|
|
23234
|
+
defaultSourceTokenAddress,
|
|
23235
|
+
defaultSourceSymbol,
|
|
23185
23236
|
theme = "dark",
|
|
23186
23237
|
onCheckoutSuccess,
|
|
23187
23238
|
onCheckoutError
|
|
@@ -23679,6 +23730,10 @@ function CheckoutModal({
|
|
|
23679
23730
|
destinationChainType: paymentIntent.destination_chain_type,
|
|
23680
23731
|
destinationChainId: paymentIntent.destination_chain_id,
|
|
23681
23732
|
destinationTokenAddress: paymentIntent.destination_token_address,
|
|
23733
|
+
defaultSourceChainType,
|
|
23734
|
+
defaultSourceChainId,
|
|
23735
|
+
defaultSourceTokenAddress,
|
|
23736
|
+
defaultSourceSymbol,
|
|
23682
23737
|
depositConfirmationMode: "auto_ui",
|
|
23683
23738
|
wallets,
|
|
23684
23739
|
onSourceTokenChange: setSelectedSource,
|
|
@@ -24331,8 +24386,8 @@ function WithdrawForm({
|
|
|
24331
24386
|
setAmount(fiat.toFixed(2));
|
|
24332
24387
|
setInputUnit("fiat");
|
|
24333
24388
|
} else {
|
|
24334
|
-
const
|
|
24335
|
-
setAmount(
|
|
24389
|
+
const crypto2 = val / exchangeRate;
|
|
24390
|
+
setAmount(crypto2.toFixed(sourceDecimals > 6 ? 6 : sourceDecimals));
|
|
24336
24391
|
setInputUnit("crypto");
|
|
24337
24392
|
}
|
|
24338
24393
|
}, [amount, inputUnit, exchangeRate, sourceDecimals]);
|
|
@@ -25532,6 +25587,10 @@ function UnifoldProvider2({
|
|
|
25532
25587
|
clientSecret: checkoutConfig.clientSecret,
|
|
25533
25588
|
publishableKey,
|
|
25534
25589
|
enableConnectWallet: config?.enableConnectWallet,
|
|
25590
|
+
defaultSourceChainType: checkoutConfig.defaultSourceChainType,
|
|
25591
|
+
defaultSourceChainId: checkoutConfig.defaultSourceChainId,
|
|
25592
|
+
defaultSourceTokenAddress: checkoutConfig.defaultSourceTokenAddress,
|
|
25593
|
+
defaultSourceSymbol: checkoutConfig.defaultSourceSymbol,
|
|
25535
25594
|
theme: resolvedTheme,
|
|
25536
25595
|
onCheckoutSuccess: handleCheckoutSuccess,
|
|
25537
25596
|
onCheckoutError: handleCheckoutError
|
|
@@ -25582,6 +25641,7 @@ function UnifoldProvider2({
|
|
|
25582
25641
|
enablePayWithExchange: config?.enablePayWithExchange,
|
|
25583
25642
|
onDepositSuccess: handleDepositSuccess,
|
|
25584
25643
|
onDepositError: handleDepositError,
|
|
25644
|
+
onEvent: depositConfig.onEvent,
|
|
25585
25645
|
theme: resolvedTheme,
|
|
25586
25646
|
initialScreen: depositConfig.initialScreen ?? config?.defaultInitialScreen,
|
|
25587
25647
|
transferCryptoTitle: config?.transferCryptoTitle,
|
|
@@ -25637,11 +25697,13 @@ export {
|
|
|
25637
25697
|
ActionType,
|
|
25638
25698
|
Button,
|
|
25639
25699
|
ConfirmingView,
|
|
25700
|
+
DepositEventType,
|
|
25640
25701
|
ExecutionStatus,
|
|
25641
25702
|
SOLANA_USDC_ADDRESS,
|
|
25642
25703
|
UnifoldProvider2 as UnifoldProvider,
|
|
25643
25704
|
createDepositAddress,
|
|
25644
25705
|
createOnrampSession,
|
|
25706
|
+
generatePrefixedKSUID,
|
|
25645
25707
|
getApiBaseUrl,
|
|
25646
25708
|
getChainName,
|
|
25647
25709
|
getDefaultOnrampToken,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unifold/connect-react",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.48",
|
|
4
4
|
"description": "Unifold Connect React - Complete React SDK with UI components for crypto deposits",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -24,16 +24,11 @@
|
|
|
24
24
|
"react-dom": "^18.2.0 || ^19.0.0",
|
|
25
25
|
"@solana/web3.js": "^1.87.0"
|
|
26
26
|
},
|
|
27
|
-
"peerDependenciesMeta": {
|
|
28
|
-
"@solana/web3.js": {
|
|
29
|
-
"optional": true
|
|
30
|
-
}
|
|
31
|
-
},
|
|
32
27
|
"dependencies": {
|
|
33
28
|
"@tanstack/react-query": "^5.90.11",
|
|
34
|
-
"@unifold/core": "0.1.
|
|
35
|
-
"@unifold/react-provider": "0.1.
|
|
36
|
-
"@unifold/ui-react": "0.1.
|
|
29
|
+
"@unifold/core": "0.1.48",
|
|
30
|
+
"@unifold/react-provider": "0.1.48",
|
|
31
|
+
"@unifold/ui-react": "0.1.48"
|
|
37
32
|
},
|
|
38
33
|
"devDependencies": {
|
|
39
34
|
"@types/react": "^19.0.0",
|