@oasisprotocol/privana-sdk 0.5.4 → 0.5.6
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/README.md +28 -19
- package/dist/{chunk-QQG4RPYZ.js → chunk-DLGIPF4N.js} +919 -367
- package/dist/chunk-DLGIPF4N.js.map +1 -0
- package/dist/{chunk-FGWMLLEC.cjs → chunk-TNR7AA52.cjs} +918 -366
- package/dist/chunk-TNR7AA52.cjs.map +1 -0
- package/dist/index.cjs +288 -255
- package/dist/index.cjs.map +1 -1
- package/dist/index.css +1 -1
- package/dist/index.css.map +1 -1
- package/dist/index.d.cts +7 -6
- package/dist/index.d.ts +7 -6
- package/dist/index.js +47 -14
- package/dist/index.js.map +1 -1
- package/dist/on-ramp.cjs +3 -3
- package/dist/on-ramp.d.cts +81 -52
- package/dist/on-ramp.d.ts +81 -52
- package/dist/on-ramp.js +1 -1
- package/dist/{pending-lock-DSEqUHOw.d.cts → pending-lock-BIMYw4gd.d.cts} +25 -20
- package/dist/{pending-lock-DSEqUHOw.d.ts → pending-lock-BIMYw4gd.d.ts} +25 -20
- package/package.json +1 -1
- package/dist/chunk-FGWMLLEC.cjs.map +0 -1
- package/dist/chunk-QQG4RPYZ.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { usePrivanaContext, createHostedAuthPendingStorageKey, clearHostedAuthPendingTransaction, HostedAuthRequiredError, HostedAuthError, createPkceVerifier, createPkceChallenge, createHostedAuthState, persistHostedAuthPendingTransaction, parseHostedAuthCallback, readHostedAuthPendingTransaction, HostedAuthStateMismatchError, buildHostedAuthSession, useSafePrivanaContext, usePrivateReadRequest, formatTokenAmount, submitPendingLock, PostDepositLockError, useDepositVerification, useEnsureCorrectChain, getTransactionReceipt, getBlockNumber, waitForTransactionReceipt, canUseBrowserStorage, clampLockAmount, requireDepositLockOwner, getWalletClient, createSignedLockRequest, requireServiceAddress, signWithdrawMessage, signLockMessage, signTransferMessage, signTransferLockedMessage, signModifyLockMessage, cn, stripHostedAuthCallbackParams, AccountingApiError, getBrowserStorageItem, removeBrowserStorageItem, isSignedLockUsable, setBrowserStorageItem, canUseSharedBrowserStorage, DEFAULT_LOCK_DURATION_SECONDS, parseTokenAmount, Skeleton, shortenAddress, formatCountdown, FiatOnRampForm, getExplorerAddressUrl, getExplorerLabel, formatTimeRemaining, getSharedBrowserStorageItem, removeSharedBrowserStorageItem, setSharedBrowserStorageItem } from './chunk-
|
|
3
|
-
export { AccountingApiError, Button, DEFAULT_LOCK_DURATION_SECONDS, DEFAULT_ONRAMP_LOCK_BUFFER, HOSTED_AUTH_CLOCK_SKEW_MS, HostedAuthError, HostedAuthRequiredError, HostedAuthStateMismatchError, HttpClient, LOCK_TYPES, MODIFY_LOCK_TYPES, NETWORK_CONFIG, NetworkError, PostDepositLockError, PrivanaClient, PrivanaProvider, SUPPORTED_CHAINS, SiweAuthProvider, Skeleton, TRANSFER_LOCKED_TYPES, TRANSFER_TYPES, ValidationError, WITHDRAW_FROM_LOCK_TYPES, WITHDRAW_TYPES, applyLockBuffer, applyRefreshResponse, buildHostedAuthSession, buildSiweStatement, buttonVariants, clampLockAmount, clearHostedAuthPendingTransaction, clearPendingLock, createDomain, createHostedAuthPendingStorageKey, createHostedAuthState, createHostedAuthStorageKey, createLockExpiry, createPkceChallenge, createPkceVerifier, createSignedLockRequest, getAccountingContract, getApiUrl, getChainById, getChainId, getExplorerAddressUrl, getExplorerLabel, isHostedAuthRefreshActive, isHostedAuthSessionActive, isSignedLockUsable, loadPendingLock, normalizeAddress, normalizeHex, parseHostedAuthCallback, persistHostedAuthPendingTransaction, readHostedAuthPendingTransaction, readStoredHostedAuthSession, requireDepositLockOwner, requireServiceAddress, savePendingLock, signLockMessage, signModifyLockMessage, signTransferLockedMessage, signTransferMessage, signWithdrawFromLockMessage, signWithdrawMessage, stripHostedAuthCallbackParams, submitPendingLock, syncHostedAuthSessionToClient, useDepositVerification, usePrivanaContext, useSafeAccount, useSafePrivanaContext, useSiweAuth } from './chunk-
|
|
2
|
+
import { usePrivanaContext, createHostedAuthPendingStorageKey, clearHostedAuthPendingTransaction, HostedAuthRequiredError, HostedAuthError, createPkceVerifier, createPkceChallenge, createHostedAuthState, persistHostedAuthPendingTransaction, parseHostedAuthCallback, readHostedAuthPendingTransaction, HostedAuthStateMismatchError, buildHostedAuthSession, useSafePrivanaContext, usePrivateReadRequest, formatTokenAmount, submitPendingLock, PostDepositLockError, useDepositVerification, useEnsureCorrectChain, getTransactionReceipt, getBlockNumber, waitForTransactionReceipt, canUseBrowserStorage, clampLockAmount, requireDepositLockOwner, getWalletClient, createSignedLockRequest, requireServiceAddress, signWithdrawMessage, signLockMessage, signTransferMessage, signTransferLockedMessage, signModifyLockMessage, cn, stripHostedAuthCallbackParams, AccountingApiError, getBrowserStorageItem, removeBrowserStorageItem, isSignedLockUsable, setBrowserStorageItem, canUseSharedBrowserStorage, DEFAULT_LOCK_DURATION_SECONDS, parseTokenAmount, Skeleton, shortenAddress, formatCountdown, FiatOnRampForm, getExplorerAddressUrl, getExplorerLabel, formatTimeRemaining, getSharedBrowserStorageItem, removeSharedBrowserStorageItem, setSharedBrowserStorageItem } from './chunk-DLGIPF4N.js';
|
|
3
|
+
export { AccountingApiError, Button, DEFAULT_LOCK_DURATION_SECONDS, DEFAULT_ONRAMP_LOCK_BUFFER, HOSTED_AUTH_CLOCK_SKEW_MS, HostedAuthError, HostedAuthRequiredError, HostedAuthStateMismatchError, HttpClient, LOCK_TYPES, MODIFY_LOCK_TYPES, NETWORK_CONFIG, NetworkError, PostDepositLockError, PrivanaClient, PrivanaProvider, SUPPORTED_CHAINS, SiweAuthProvider, Skeleton, TRANSFER_LOCKED_TYPES, TRANSFER_TYPES, ValidationError, WITHDRAW_FROM_LOCK_TYPES, WITHDRAW_TYPES, applyLockBuffer, applyRefreshResponse, buildHostedAuthSession, buildSiweStatement, buttonVariants, clampLockAmount, clearHostedAuthPendingTransaction, clearPendingLock, createDomain, createHostedAuthPendingStorageKey, createHostedAuthState, createHostedAuthStorageKey, createLockExpiry, createPkceChallenge, createPkceVerifier, createSignedLockRequest, getAccountingContract, getApiUrl, getChainById, getChainId, getExplorerAddressUrl, getExplorerLabel, isHostedAuthRefreshActive, isHostedAuthSessionActive, isSignedLockUsable, loadPendingLock, normalizeAddress, normalizeHex, parseHostedAuthCallback, persistHostedAuthPendingTransaction, readHostedAuthPendingTransaction, readStoredHostedAuthSession, requireDepositLockOwner, requireServiceAddress, savePendingLock, signLockMessage, signModifyLockMessage, signTransferLockedMessage, signTransferMessage, signWithdrawFromLockMessage, signWithdrawMessage, stripHostedAuthCallbackParams, submitPendingLock, syncHostedAuthSessionToClient, useDepositVerification, usePrivanaContext, useSafeAccount, useSafePrivanaContext, useSiweAuth } from './chunk-DLGIPF4N.js';
|
|
4
4
|
import { useState, useRef, useMemo, useCallback, useContext, useEffect, useId } from 'react';
|
|
5
5
|
import { QueryClientContext, useQuery, useQueryClient, useMutation, keepPreviousData } from '@tanstack/react-query';
|
|
6
6
|
import { useAccount, useWalletClient, useConfig, useWriteContract, useSendTransaction, useBalance as useBalance$1, useReadContract } from 'wagmi';
|
|
@@ -275,6 +275,13 @@ function useBatchBalances(options) {
|
|
|
275
275
|
};
|
|
276
276
|
}
|
|
277
277
|
var STALE_MS = 30 * 60 * 1e3;
|
|
278
|
+
function resolveConfirmations(depositAddress, chainId) {
|
|
279
|
+
const confirmations = depositAddress.finality_depth?.[String(chainId)];
|
|
280
|
+
if (confirmations === void 0) {
|
|
281
|
+
throw new Error(`Deposits are not supported on chain ${chainId}`);
|
|
282
|
+
}
|
|
283
|
+
return confirmations;
|
|
284
|
+
}
|
|
278
285
|
function storageKey(address) {
|
|
279
286
|
return `privana:pending-deposit:${address.toLowerCase()}`;
|
|
280
287
|
}
|
|
@@ -318,7 +325,6 @@ function useDeposit(options = {}) {
|
|
|
318
325
|
const { executePrivateRead, privateReadAddress } = usePrivateReadRequest();
|
|
319
326
|
const privateReadAddressRef = useRef(privateReadAddress);
|
|
320
327
|
privateReadAddressRef.current = privateReadAddress;
|
|
321
|
-
const confirmations = options.confirmations ?? 15;
|
|
322
328
|
const [depositAddress, setDepositAddress] = useState(null);
|
|
323
329
|
const [txHash, setTxHash] = useState();
|
|
324
330
|
const [isSwitchingChain, setIsSwitchingChain] = useState(false);
|
|
@@ -481,6 +487,7 @@ function useDeposit(options = {}) {
|
|
|
481
487
|
const isStale = () => generation !== generationRef.current;
|
|
482
488
|
(async () => {
|
|
483
489
|
try {
|
|
490
|
+
const confirmations = resolveConfirmations(persisted.depositAddress, persisted.chainId);
|
|
484
491
|
let confirmed = false;
|
|
485
492
|
try {
|
|
486
493
|
const receipt = await getTransactionReceipt(config, {
|
|
@@ -512,7 +519,7 @@ function useDeposit(options = {}) {
|
|
|
512
519
|
onErrorRef.current?.(error2);
|
|
513
520
|
}
|
|
514
521
|
})();
|
|
515
|
-
}, [address, config,
|
|
522
|
+
}, [address, config, queryClient, verify]);
|
|
516
523
|
const deposit = useCallback(
|
|
517
524
|
async (params) => {
|
|
518
525
|
if (verificationContextRef.current) {
|
|
@@ -543,6 +550,7 @@ function useDeposit(options = {}) {
|
|
|
543
550
|
`Amount is below the minimum deposit (${minAmountStr}) for ${isNative ? "native" : "ERC-20"} on chain ${sourceChain.id}`
|
|
544
551
|
);
|
|
545
552
|
}
|
|
553
|
+
const confirmations = resolveConfirmations(addrResponse, sourceChain.id);
|
|
546
554
|
if (params.postDepositLock && !canUseBrowserStorage()) {
|
|
547
555
|
throw new Error("Browser storage is required for locked deposit recovery");
|
|
548
556
|
}
|
|
@@ -653,7 +661,6 @@ function useDeposit(options = {}) {
|
|
|
653
661
|
client,
|
|
654
662
|
getChainById2,
|
|
655
663
|
config,
|
|
656
|
-
confirmations,
|
|
657
664
|
enabledTokens,
|
|
658
665
|
ensureCorrectChain,
|
|
659
666
|
networkConfig,
|
|
@@ -4058,7 +4065,8 @@ function WithdrawView({
|
|
|
4058
4065
|
amount,
|
|
4059
4066
|
onAmountChange,
|
|
4060
4067
|
onSelectToken,
|
|
4061
|
-
onPendingChange
|
|
4068
|
+
onPendingChange,
|
|
4069
|
+
onWithdrawSuccess
|
|
4062
4070
|
}) {
|
|
4063
4071
|
const { chains, getChainById: getChainById2 } = usePrivanaContext();
|
|
4064
4072
|
const { isConnected, address } = useAccount();
|
|
@@ -4078,7 +4086,12 @@ function WithdrawView({
|
|
|
4078
4086
|
const { withdraw, isPending, currentStep, error, reset } = useWithdraw({
|
|
4079
4087
|
onProcessingSuccess: () => {
|
|
4080
4088
|
onAmountChange("");
|
|
4081
|
-
|
|
4089
|
+
if (onWithdrawSuccess) {
|
|
4090
|
+
reset();
|
|
4091
|
+
onWithdrawSuccess();
|
|
4092
|
+
} else {
|
|
4093
|
+
setShowSuccess(true);
|
|
4094
|
+
}
|
|
4082
4095
|
},
|
|
4083
4096
|
onProcessingTimeout: () => {
|
|
4084
4097
|
onAmountChange("");
|
|
@@ -4251,7 +4264,8 @@ function WithdrawView({
|
|
|
4251
4264
|
function WithdrawModalContent({
|
|
4252
4265
|
onClose,
|
|
4253
4266
|
onPendingChange,
|
|
4254
|
-
onBack
|
|
4267
|
+
onBack,
|
|
4268
|
+
onWithdrawSuccess
|
|
4255
4269
|
}) {
|
|
4256
4270
|
const { serviceName, enabledTokens, defaultToken, hostedAuthConfig } = usePrivanaContext();
|
|
4257
4271
|
const { address } = useAccount();
|
|
@@ -4317,7 +4331,8 @@ function WithdrawModalContent({
|
|
|
4317
4331
|
amount,
|
|
4318
4332
|
onAmountChange: setAmount,
|
|
4319
4333
|
onSelectToken: () => setView("select-token"),
|
|
4320
|
-
onPendingChange: handlePendingChange
|
|
4334
|
+
onPendingChange: handlePendingChange,
|
|
4335
|
+
onWithdrawSuccess
|
|
4321
4336
|
}
|
|
4322
4337
|
),
|
|
4323
4338
|
view === "select-token" && /* @__PURE__ */ jsx(
|
|
@@ -4332,7 +4347,7 @@ function WithdrawModalContent({
|
|
|
4332
4347
|
)
|
|
4333
4348
|
] });
|
|
4334
4349
|
}
|
|
4335
|
-
function WithdrawModal({ open, onClose }) {
|
|
4350
|
+
function WithdrawModal({ open, onClose, onWithdrawSuccess }) {
|
|
4336
4351
|
const titleId = useId();
|
|
4337
4352
|
const descId = useId();
|
|
4338
4353
|
const [isCloseBlocked, setIsCloseBlocked] = useState(false);
|
|
@@ -4359,14 +4374,21 @@ function WithdrawModal({ open, onClose }) {
|
|
|
4359
4374
|
children: [
|
|
4360
4375
|
/* @__PURE__ */ jsx(DialogTitle, { id: titleId, className: "sr-only", children: "Withdraw" }),
|
|
4361
4376
|
/* @__PURE__ */ jsx(DialogDescription, { id: descId, className: "sr-only", children: "Withdraw funds from your account." }),
|
|
4362
|
-
/* @__PURE__ */ jsx(
|
|
4377
|
+
/* @__PURE__ */ jsx(
|
|
4378
|
+
WithdrawModalContent,
|
|
4379
|
+
{
|
|
4380
|
+
onClose: handleClose,
|
|
4381
|
+
onPendingChange: setIsCloseBlocked,
|
|
4382
|
+
onWithdrawSuccess
|
|
4383
|
+
}
|
|
4384
|
+
)
|
|
4363
4385
|
]
|
|
4364
4386
|
}
|
|
4365
4387
|
)
|
|
4366
4388
|
}
|
|
4367
4389
|
);
|
|
4368
4390
|
}
|
|
4369
|
-
function WithdrawInlineModal({ className }) {
|
|
4391
|
+
function WithdrawInlineModal({ className, onWithdrawSuccess }) {
|
|
4370
4392
|
return /* @__PURE__ */ jsx(
|
|
4371
4393
|
"div",
|
|
4372
4394
|
{
|
|
@@ -4375,7 +4397,7 @@ function WithdrawInlineModal({ className }) {
|
|
|
4375
4397
|
"bg-card relative flex w-[560px] max-w-full flex-col gap-2 overflow-hidden rounded-2xl p-2 shadow-lg",
|
|
4376
4398
|
className
|
|
4377
4399
|
),
|
|
4378
|
-
children: /* @__PURE__ */ jsx(WithdrawModalContent, {})
|
|
4400
|
+
children: /* @__PURE__ */ jsx(WithdrawModalContent, { onWithdrawSuccess })
|
|
4379
4401
|
}
|
|
4380
4402
|
);
|
|
4381
4403
|
}
|
|
@@ -4627,6 +4649,7 @@ function WalletModalContent({
|
|
|
4627
4649
|
onFundSession,
|
|
4628
4650
|
onEndSession,
|
|
4629
4651
|
onDepositSuccess,
|
|
4652
|
+
onWithdrawSuccess,
|
|
4630
4653
|
onClose,
|
|
4631
4654
|
onCloseBlockedChange,
|
|
4632
4655
|
...depositHandlers
|
|
@@ -4791,7 +4814,17 @@ function WalletModalContent({
|
|
|
4791
4814
|
retryLabel: "Try again"
|
|
4792
4815
|
}
|
|
4793
4816
|
) }),
|
|
4794
|
-
view === "withdraw" && /* @__PURE__ */ jsx(
|
|
4817
|
+
view === "withdraw" && /* @__PURE__ */ jsx(
|
|
4818
|
+
WithdrawModalContent,
|
|
4819
|
+
{
|
|
4820
|
+
onBack: exitWithdraw,
|
|
4821
|
+
onPendingChange: setWithdrawPending,
|
|
4822
|
+
onWithdrawSuccess: () => {
|
|
4823
|
+
exitWithdraw();
|
|
4824
|
+
onWithdrawSuccess?.();
|
|
4825
|
+
}
|
|
4826
|
+
}
|
|
4827
|
+
),
|
|
4795
4828
|
view === "deposit" && /* @__PURE__ */ jsx(
|
|
4796
4829
|
DepositModalContent,
|
|
4797
4830
|
{
|