@unlink-xyz/react 0.1.3-canary.a96530d → 0.1.3-canary.b0ad588
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.ts +52 -17
- package/dist/index.js +109 -45
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import { ReactNode } from 'react';
|
|
3
|
-
import { BrowserWalletOptions,
|
|
4
|
-
export { Account, AccountInfo, Chain, HistoryEntry, NoteRecord, ParsedZkAddress, TransferPlanResult, TransferResult, TxStatusChangedEvent, UnlinkWallet, WalletSDKEvent, WithdrawPlanResult, WithdrawResult, computeBalances, decodeAddress, encodeAddress, formatAmount, normalizeAddress, parseAmount, parseZkAddress, randomHex, shortenHex } from '@unlink-xyz/core';
|
|
3
|
+
import { BrowserWalletOptions, SupportedChain, UnlinkWallet, AccountInfo, Account, NoteRecord, HistoryStatus, TransferResult, TransferPlanResult, DepositRelayResult, WithdrawalInput, WithdrawResult, WithdrawPlanResult, SimpleAdapterExecuteParams, AdapterExecuteResult, RelayState, HistoryEntry } from '@unlink-xyz/core';
|
|
4
|
+
export { Account, AccountInfo, AdapterExecuteResult, AdapterExecutionCall, Chain, HistoryEntry, InputTokenSpec, NoteRecord, ParsedZkAddress, ReshieldInput, SimpleAdapterExecuteParams, SupportedChain, TransferPlanResult, TransferResult, TxStatusChangedEvent, UnlinkWallet, WalletSDKEvent, WithdrawPlanResult, WithdrawResult, computeBalances, decodeAddress, encodeAddress, formatAmount, normalizeAddress, parseAmount, parseZkAddress, randomHex, shortenHex } from '@unlink-xyz/core';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Wallet note with value as bigint for convenience.
|
|
@@ -33,8 +33,6 @@ type PendingWithdrawJob = PendingJobBase & {
|
|
|
33
33
|
* Base configuration shared by all UnlinkProvider variants.
|
|
34
34
|
*/
|
|
35
35
|
type UnlinkConfigBase = {
|
|
36
|
-
/** Chain ID for the target blockchain */
|
|
37
|
-
chainId: number;
|
|
38
36
|
/** Auto-sync interval in milliseconds (default: 5000) */
|
|
39
37
|
syncInterval?: number;
|
|
40
38
|
/** Whether to start auto-sync on mount (default: true) */
|
|
@@ -44,19 +42,22 @@ type UnlinkConfigBase = {
|
|
|
44
42
|
};
|
|
45
43
|
/**
|
|
46
44
|
* Configuration for the UnlinkProvider.
|
|
47
|
-
* Either provide
|
|
45
|
+
* Either provide a chain name to auto-resolve, or explicit gatewayUrl + poolAddress.
|
|
48
46
|
*/
|
|
49
47
|
type UnlinkConfig = UnlinkConfigBase & ({
|
|
48
|
+
/** Supported chain name — resolves chainId, gateway, pool, artifacts */
|
|
49
|
+
chain: SupportedChain;
|
|
50
|
+
/** Override pool address from chain config */
|
|
51
|
+
poolAddress?: string;
|
|
52
|
+
chainId?: never;
|
|
53
|
+
gatewayUrl?: never;
|
|
54
|
+
} | {
|
|
55
|
+
/** Chain ID for the target blockchain */
|
|
56
|
+
chainId: number;
|
|
50
57
|
/** Explicit gateway URL - requires poolAddress */
|
|
51
58
|
gatewayUrl: string;
|
|
52
59
|
poolAddress: string;
|
|
53
|
-
|
|
54
|
-
} | {
|
|
55
|
-
/** Environment to use from the config file */
|
|
56
|
-
environment: Environment;
|
|
57
|
-
/** Pool contract address - optional, defaults to environment config */
|
|
58
|
-
poolAddress?: string;
|
|
59
|
-
gatewayUrl?: never;
|
|
60
|
+
chain?: never;
|
|
60
61
|
});
|
|
61
62
|
/**
|
|
62
63
|
* State exposed by the useUnlink hook.
|
|
@@ -72,8 +73,8 @@ type UnlinkState = {
|
|
|
72
73
|
activeAccount: Account | null;
|
|
73
74
|
/** Current active account index (null if none) */
|
|
74
75
|
activeAccountIndex: number | null;
|
|
75
|
-
/** Chain ID
|
|
76
|
-
chainId: number;
|
|
76
|
+
/** Chain ID (resolved from chain config or provided explicitly, null before init) */
|
|
77
|
+
chainId: number | null;
|
|
77
78
|
/** User's notes with value as bigint */
|
|
78
79
|
notes: WalletNote[];
|
|
79
80
|
/** Token balances by address */
|
|
@@ -181,6 +182,10 @@ type UnlinkActions = {
|
|
|
181
182
|
planWithdraw(params: WithdrawInput[]): Promise<WithdrawPlanResult>;
|
|
182
183
|
/** Execute a pre-built withdrawal plan */
|
|
183
184
|
executeWithdraw(plans: WithdrawPlanResult): Promise<WithdrawResult>;
|
|
185
|
+
/**
|
|
186
|
+
* Execute an atomic private adapter flow (unshield -> calls -> reshield).
|
|
187
|
+
*/
|
|
188
|
+
executeAdapter(params: SimpleAdapterExecuteParams): Promise<AdapterExecuteResult>;
|
|
184
189
|
/** Refresh notes and balances */
|
|
185
190
|
refresh(): Promise<void>;
|
|
186
191
|
/** Force full resync from chain */
|
|
@@ -269,7 +274,7 @@ type UnlinkErrorCode = "UNKNOWN" | "SDK_NOT_INITIALIZED" | "NETWORK_ERROR" | "VA
|
|
|
269
274
|
/**
|
|
270
275
|
* Operations that can trigger an error in the Unlink context.
|
|
271
276
|
*/
|
|
272
|
-
type UnlinkErrorOperation = "init" | "createWallet" | "importWallet" | "clearWallet" | "createAccount" | "switchAccount" | "send" | "executeTransfer" | "requestDeposit" | "requestWithdraw" | "executeWithdraw" | "refresh" | "forceResync";
|
|
277
|
+
type UnlinkErrorOperation = "init" | "createWallet" | "importWallet" | "clearWallet" | "createAccount" | "switchAccount" | "send" | "executeTransfer" | "requestDeposit" | "requestWithdraw" | "executeAdapter" | "executeWithdraw" | "refresh" | "forceResync";
|
|
273
278
|
/**
|
|
274
279
|
* Structured error type for the Unlink context.
|
|
275
280
|
*/
|
|
@@ -284,7 +289,7 @@ type UnlinkError = {
|
|
|
284
289
|
type UnlinkProviderProps = UnlinkConfig & {
|
|
285
290
|
children: ReactNode;
|
|
286
291
|
};
|
|
287
|
-
declare function UnlinkProvider({ children,
|
|
292
|
+
declare function UnlinkProvider({ children, poolAddress, syncInterval, autoSync, prover, ...configProps }: UnlinkProviderProps): react_jsx_runtime.JSX.Element;
|
|
288
293
|
|
|
289
294
|
/**
|
|
290
295
|
* Hook to access the Unlink wallet SDK.
|
|
@@ -549,4 +554,34 @@ declare function useTransfer(): UseOperationMutationResult<TransferInput[], Tran
|
|
|
549
554
|
*/
|
|
550
555
|
declare function useWithdraw(): UseOperationMutationResult<WithdrawInput[], WithdrawResult>;
|
|
551
556
|
|
|
552
|
-
|
|
557
|
+
/**
|
|
558
|
+
* Hook for executing private DeFi adapter operations with loading/error state.
|
|
559
|
+
*
|
|
560
|
+
* Performs atomic unshield → DeFi call(s) → reshield flows through an adapter contract.
|
|
561
|
+
*
|
|
562
|
+
* @example
|
|
563
|
+
* ```tsx
|
|
564
|
+
* function SwapButton() {
|
|
565
|
+
* const { mutate: executeAdapter, isPending, error } = useAdapter();
|
|
566
|
+
*
|
|
567
|
+
* const handleSwap = async () => {
|
|
568
|
+
* const result = await executeAdapter({
|
|
569
|
+
* adapterAddress: "0x...",
|
|
570
|
+
* inputs: [{ token: "0x...", amount: 1000n }],
|
|
571
|
+
* calls: [approveCall, swapCall],
|
|
572
|
+
* reshields: [{ token: "0x...", minAmount: 500n }],
|
|
573
|
+
* });
|
|
574
|
+
* console.log("Relay ID:", result.relayId);
|
|
575
|
+
* };
|
|
576
|
+
*
|
|
577
|
+
* return (
|
|
578
|
+
* <button onClick={handleSwap} disabled={isPending}>
|
|
579
|
+
* {isPending ? "Executing..." : "Swap"}
|
|
580
|
+
* </button>
|
|
581
|
+
* );
|
|
582
|
+
* }
|
|
583
|
+
* ```
|
|
584
|
+
*/
|
|
585
|
+
declare function useAdapter(): UseOperationMutationResult<SimpleAdapterExecuteParams, AdapterExecuteResult>;
|
|
586
|
+
|
|
587
|
+
export { CONFIRMATION_POLL_INTERVAL_MS, DEFAULT_CONFIRMATION_TIMEOUT_MS, type DepositInput, type PendingDepositJob, type PendingTransferJob, type PendingWithdrawJob, TERMINAL_TX_STATES, TimeoutError, TransactionFailedError, type TransferInput, type TxState, type TxStatus, type UnlinkActions, type UnlinkConfig, type UnlinkContextValue, type UnlinkError, type UnlinkErrorCode, type UnlinkErrorOperation, UnlinkProvider, type UnlinkProviderProps, type UnlinkState, type UseOperationMutationResult, type UseTxStatusResult, type UseUnlinkBalanceResult, type UseUnlinkHistoryOptions, type UseUnlinkHistoryResult, type WaitForConfirmationOptions, type WalletNote, type WithdrawInput, useAdapter, useDeposit, useOperationMutation, useTransfer, useTxStatus, useUnlink, useUnlinkBalance, useUnlinkBalances, useUnlinkHistory, useWithdraw };
|
package/dist/index.js
CHANGED
|
@@ -35871,63 +35871,79 @@ var Runtime = {
|
|
|
35871
35871
|
}
|
|
35872
35872
|
};
|
|
35873
35873
|
var CONFIG_URL = "https://config.unlink.xyz/networks.json";
|
|
35874
|
-
function parseRequiredString(
|
|
35874
|
+
function parseRequiredString(chain2, field, value) {
|
|
35875
35875
|
if (typeof value !== "string" || value.trim().length === 0) {
|
|
35876
35876
|
throw new InitializationError(
|
|
35877
|
-
`Invalid SDK config for ${
|
|
35877
|
+
`Invalid SDK config for ${chain2}: ${field} must be a non-empty string`
|
|
35878
35878
|
);
|
|
35879
35879
|
}
|
|
35880
35880
|
return value.trim();
|
|
35881
35881
|
}
|
|
35882
|
-
function parseOptionalString(
|
|
35882
|
+
function parseOptionalString(chain2, field, value) {
|
|
35883
35883
|
if (value === void 0) return void 0;
|
|
35884
35884
|
if (typeof value !== "string" || value.trim().length === 0) {
|
|
35885
35885
|
throw new InitializationError(
|
|
35886
|
-
`Invalid SDK config for ${
|
|
35886
|
+
`Invalid SDK config for ${chain2}: ${field} must be a non-empty string when provided`
|
|
35887
35887
|
);
|
|
35888
35888
|
}
|
|
35889
35889
|
return value.trim();
|
|
35890
35890
|
}
|
|
35891
|
-
function
|
|
35891
|
+
function parseRequiredChainId(chain2, value) {
|
|
35892
|
+
if (typeof value !== "number" || !Number.isInteger(value) || value <= 0) {
|
|
35893
|
+
throw new InitializationError(
|
|
35894
|
+
`Invalid SDK config for ${chain2}: chainId must be a positive integer`
|
|
35895
|
+
);
|
|
35896
|
+
}
|
|
35897
|
+
return value;
|
|
35898
|
+
}
|
|
35899
|
+
function parseChainConfig(chain2, value) {
|
|
35892
35900
|
if (value === null || typeof value !== "object" || Array.isArray(value)) {
|
|
35893
35901
|
throw new InitializationError(
|
|
35894
|
-
`Invalid SDK config for ${
|
|
35902
|
+
`Invalid SDK config for ${chain2}: expected object`
|
|
35895
35903
|
);
|
|
35896
35904
|
}
|
|
35897
35905
|
const raw = value;
|
|
35906
|
+
const chainId = parseRequiredChainId(chain2, raw.chainId);
|
|
35898
35907
|
const gatewayUrl = parseRequiredString(
|
|
35899
|
-
|
|
35908
|
+
chain2,
|
|
35900
35909
|
"gatewayUrl",
|
|
35901
35910
|
raw.gatewayUrl
|
|
35902
35911
|
).replace(/\/+$/, "");
|
|
35903
|
-
const poolAddress = parseRequiredString(
|
|
35912
|
+
const poolAddress = parseRequiredString(
|
|
35913
|
+
chain2,
|
|
35914
|
+
"poolAddress",
|
|
35915
|
+
raw.poolAddress
|
|
35916
|
+
);
|
|
35904
35917
|
const artifactVersion = parseRequiredString(
|
|
35905
|
-
|
|
35918
|
+
chain2,
|
|
35906
35919
|
"artifactVersion",
|
|
35907
35920
|
raw.artifactVersion
|
|
35908
35921
|
).replace(/^\/+|\/+$/g, "");
|
|
35909
35922
|
const artifactBaseUrl = parseOptionalString(
|
|
35910
|
-
|
|
35923
|
+
chain2,
|
|
35911
35924
|
"artifactBaseUrl",
|
|
35912
35925
|
raw.artifactBaseUrl
|
|
35913
35926
|
)?.replace(/\/+$/, "");
|
|
35914
35927
|
return {
|
|
35928
|
+
chainId,
|
|
35915
35929
|
gatewayUrl,
|
|
35916
35930
|
poolAddress,
|
|
35917
35931
|
artifactVersion,
|
|
35918
35932
|
...artifactBaseUrl !== void 0 ? { artifactBaseUrl } : { artifactBaseUrl: DEFAULT_ARTIFACT_BASE_URL }
|
|
35919
35933
|
};
|
|
35920
35934
|
}
|
|
35921
|
-
async function
|
|
35935
|
+
async function fetchChainConfig(chain2) {
|
|
35922
35936
|
const res = await fetch(CONFIG_URL);
|
|
35923
35937
|
if (!res.ok) {
|
|
35924
35938
|
throw new InitializationError(`Failed to fetch SDK config: ${res.status}`);
|
|
35925
35939
|
}
|
|
35926
35940
|
const config22 = await res.json();
|
|
35927
|
-
if (!config22[
|
|
35928
|
-
throw new InitializationError(
|
|
35941
|
+
if (!config22[chain2]) {
|
|
35942
|
+
throw new InitializationError(
|
|
35943
|
+
`Unknown chain: "${chain2}". Supported chains: ${Object.keys(config22).join(", ")}`
|
|
35944
|
+
);
|
|
35929
35945
|
}
|
|
35930
|
-
return
|
|
35946
|
+
return parseChainConfig(chain2, config22[chain2]);
|
|
35931
35947
|
}
|
|
35932
35948
|
function createServiceConfig(gatewayUrl) {
|
|
35933
35949
|
const baseUrl = gatewayUrl.replace(/\/+$/, "");
|
|
@@ -56536,34 +56552,37 @@ var UnlinkWallet = class _UnlinkWallet {
|
|
|
56536
56552
|
* Create a new UnlinkWallet instance.
|
|
56537
56553
|
*
|
|
56538
56554
|
* Handles all initialization internally:
|
|
56539
|
-
* - Resolves
|
|
56555
|
+
* - Resolves chain config (if using `chain` instead of explicit URLs)
|
|
56540
56556
|
* - Auto-detects storage (IndexedDB in browser) and rng (crypto.getRandomValues)
|
|
56541
56557
|
* - Runs schema migration via `initCore()`
|
|
56542
56558
|
* - Creates the internal SDK
|
|
56543
56559
|
*/
|
|
56544
56560
|
static async create(config22) {
|
|
56561
|
+
let chainId;
|
|
56545
56562
|
let gatewayUrl;
|
|
56546
56563
|
let poolAddress;
|
|
56547
56564
|
let proverConfig = config22.prover;
|
|
56548
|
-
if ("
|
|
56565
|
+
if ("chain" in config22) {
|
|
56566
|
+
const chainConfig = await fetchChainConfig(config22.chain);
|
|
56567
|
+
chainId = chainConfig.chainId;
|
|
56568
|
+
gatewayUrl = chainConfig.gatewayUrl;
|
|
56569
|
+
poolAddress = config22.poolAddress ?? chainConfig.poolAddress;
|
|
56570
|
+
proverConfig = {
|
|
56571
|
+
artifactSource: {
|
|
56572
|
+
baseUrl: config22.prover?.artifactSource?.baseUrl ?? chainConfig.artifactBaseUrl,
|
|
56573
|
+
version: config22.prover?.artifactSource?.version ?? chainConfig.artifactVersion,
|
|
56574
|
+
preferLocalFiles: config22.prover?.artifactSource?.preferLocalFiles
|
|
56575
|
+
}
|
|
56576
|
+
};
|
|
56577
|
+
} else {
|
|
56578
|
+
chainId = config22.chainId;
|
|
56549
56579
|
gatewayUrl = config22.gatewayUrl;
|
|
56550
56580
|
poolAddress = config22.poolAddress;
|
|
56551
56581
|
if (typeof window !== "undefined" && !config22.prover?.artifactSource?.version) {
|
|
56552
56582
|
throw new InitializationError(
|
|
56553
|
-
"prover.artifactSource.version is required in browser when using explicit gatewayUrl mode. Use
|
|
56583
|
+
"prover.artifactSource.version is required in browser when using explicit gatewayUrl mode. Use chain mode or provide a pinned artifact version."
|
|
56554
56584
|
);
|
|
56555
56585
|
}
|
|
56556
|
-
} else {
|
|
56557
|
-
const envConfig = await fetchEnvironmentConfig(config22.environment);
|
|
56558
|
-
gatewayUrl = envConfig.gatewayUrl;
|
|
56559
|
-
poolAddress = config22.poolAddress ?? envConfig.poolAddress;
|
|
56560
|
-
proverConfig = {
|
|
56561
|
-
artifactSource: {
|
|
56562
|
-
baseUrl: config22.prover?.artifactSource?.baseUrl ?? envConfig.artifactBaseUrl,
|
|
56563
|
-
version: config22.prover?.artifactSource?.version ?? envConfig.artifactVersion,
|
|
56564
|
-
preferLocalFiles: config22.prover?.artifactSource?.preferLocalFiles
|
|
56565
|
-
}
|
|
56566
|
-
};
|
|
56567
56586
|
}
|
|
56568
56587
|
const storage = config22.storage ?? detectStorage();
|
|
56569
56588
|
const rng = config22.rng ?? defaultRng;
|
|
@@ -56572,14 +56591,14 @@ var UnlinkWallet = class _UnlinkWallet {
|
|
|
56572
56591
|
const sdk = createWalletSDK(
|
|
56573
56592
|
{ core, fetch: fetchImpl },
|
|
56574
56593
|
{
|
|
56575
|
-
chainId
|
|
56594
|
+
chainId,
|
|
56576
56595
|
gatewayUrl,
|
|
56577
56596
|
chainRpcUrl: config22.chainRpcUrl,
|
|
56578
56597
|
prover: proverConfig,
|
|
56579
56598
|
autoSync: config22.autoSync
|
|
56580
56599
|
}
|
|
56581
56600
|
);
|
|
56582
|
-
return new _UnlinkWallet(sdk,
|
|
56601
|
+
return new _UnlinkWallet(sdk, chainId, poolAddress);
|
|
56583
56602
|
}
|
|
56584
56603
|
// ===== Seed Lifecycle =====
|
|
56585
56604
|
/** Seed management (create, import, export, delete mnemonic). */
|
|
@@ -56935,6 +56954,7 @@ var initialState = {
|
|
|
56935
56954
|
accounts: [],
|
|
56936
56955
|
activeAccount: null,
|
|
56937
56956
|
activeAccountIndex: null,
|
|
56957
|
+
chainId: null,
|
|
56938
56958
|
notes: [],
|
|
56939
56959
|
balances: {},
|
|
56940
56960
|
pendingDeposits: [],
|
|
@@ -56954,14 +56974,15 @@ function convertNotes(noteRecords) {
|
|
|
56954
56974
|
}
|
|
56955
56975
|
function UnlinkProvider({
|
|
56956
56976
|
children,
|
|
56957
|
-
chainId,
|
|
56958
56977
|
poolAddress,
|
|
56959
56978
|
syncInterval = 5e3,
|
|
56960
56979
|
autoSync = true,
|
|
56961
|
-
|
|
56962
|
-
|
|
56963
|
-
prover
|
|
56980
|
+
prover,
|
|
56981
|
+
...configProps
|
|
56964
56982
|
}) {
|
|
56983
|
+
const chain2 = "chain" in configProps ? configProps.chain : void 0;
|
|
56984
|
+
const chainId = "chainId" in configProps ? configProps.chainId : void 0;
|
|
56985
|
+
const gatewayUrl = "gatewayUrl" in configProps ? configProps.gatewayUrl : void 0;
|
|
56965
56986
|
const [state, setState] = useState(initialState);
|
|
56966
56987
|
const walletRef = useRef(null);
|
|
56967
56988
|
const proverKey = JSON.stringify(prover ?? null);
|
|
@@ -56991,13 +57012,13 @@ function UnlinkProvider({
|
|
|
56991
57012
|
}
|
|
56992
57013
|
}, []);
|
|
56993
57014
|
useEffect(() => {
|
|
56994
|
-
if (!
|
|
57015
|
+
if (!chain2 && !gatewayUrl) {
|
|
56995
57016
|
const configError = new ValidationError(
|
|
56996
|
-
"Either
|
|
57017
|
+
"Either chain or gatewayUrl is required"
|
|
56997
57018
|
);
|
|
56998
57019
|
setState((prev2) => ({
|
|
56999
57020
|
...prev2,
|
|
57000
|
-
status: "Error: Either
|
|
57021
|
+
status: "Error: Either chain or gatewayUrl is required",
|
|
57001
57022
|
error: createUnlinkError(configError, "init")
|
|
57002
57023
|
}));
|
|
57003
57024
|
return;
|
|
@@ -57011,14 +57032,13 @@ function UnlinkProvider({
|
|
|
57011
57032
|
status: "Initializing SDK..."
|
|
57012
57033
|
}));
|
|
57013
57034
|
const wallet = await UnlinkWallet.create(
|
|
57014
|
-
|
|
57015
|
-
|
|
57016
|
-
gatewayUrl,
|
|
57035
|
+
chain2 ? {
|
|
57036
|
+
chain: chain2,
|
|
57017
57037
|
poolAddress,
|
|
57018
57038
|
...prover ? { prover } : {}
|
|
57019
57039
|
} : {
|
|
57020
57040
|
chainId,
|
|
57021
|
-
|
|
57041
|
+
gatewayUrl,
|
|
57022
57042
|
poolAddress,
|
|
57023
57043
|
...prover ? { prover } : {}
|
|
57024
57044
|
}
|
|
@@ -57059,6 +57079,7 @@ function UnlinkProvider({
|
|
|
57059
57079
|
accounts,
|
|
57060
57080
|
activeAccount,
|
|
57061
57081
|
activeAccountIndex,
|
|
57082
|
+
chainId: wallet.chainId,
|
|
57062
57083
|
notes,
|
|
57063
57084
|
balances,
|
|
57064
57085
|
ready: true,
|
|
@@ -57069,7 +57090,7 @@ function UnlinkProvider({
|
|
|
57069
57090
|
wallet.startAutoSync(syncInterval);
|
|
57070
57091
|
}
|
|
57071
57092
|
unsubscribe = wallet.on((event) => {
|
|
57072
|
-
if (event.type === "notes-updated" && event.chainId === chainId) {
|
|
57093
|
+
if (event.type === "notes-updated" && event.chainId === wallet.chainId) {
|
|
57073
57094
|
setState((prev2) => ({ ...prev2, syncError: null }));
|
|
57074
57095
|
void refreshState(wallet);
|
|
57075
57096
|
}
|
|
@@ -57103,13 +57124,13 @@ function UnlinkProvider({
|
|
|
57103
57124
|
walletRef.current?.stopAutoSync();
|
|
57104
57125
|
};
|
|
57105
57126
|
}, [
|
|
57127
|
+
chain2,
|
|
57106
57128
|
chainId,
|
|
57107
57129
|
autoSync,
|
|
57108
57130
|
syncInterval,
|
|
57109
57131
|
refreshState,
|
|
57110
57132
|
refreshAccounts,
|
|
57111
57133
|
gatewayUrl,
|
|
57112
|
-
environment,
|
|
57113
57134
|
poolAddress,
|
|
57114
57135
|
proverKey
|
|
57115
57136
|
]);
|
|
@@ -57475,6 +57496,36 @@ function UnlinkProvider({
|
|
|
57475
57496
|
},
|
|
57476
57497
|
[]
|
|
57477
57498
|
);
|
|
57499
|
+
const executeAdapter = useCallback(
|
|
57500
|
+
async (params) => {
|
|
57501
|
+
const wallet = walletRef.current;
|
|
57502
|
+
if (!wallet) throw new Error("SDK not initialized");
|
|
57503
|
+
setState((prev2) => ({
|
|
57504
|
+
...prev2,
|
|
57505
|
+
busy: true,
|
|
57506
|
+
status: "Executing adapter..."
|
|
57507
|
+
}));
|
|
57508
|
+
try {
|
|
57509
|
+
const result = await wallet.adapter.execute(params);
|
|
57510
|
+
setState((prev2) => ({
|
|
57511
|
+
...prev2,
|
|
57512
|
+
busy: false,
|
|
57513
|
+
status: "Adapter execution submitted",
|
|
57514
|
+
error: null
|
|
57515
|
+
}));
|
|
57516
|
+
return result;
|
|
57517
|
+
} catch (err) {
|
|
57518
|
+
setState((prev2) => ({
|
|
57519
|
+
...prev2,
|
|
57520
|
+
busy: false,
|
|
57521
|
+
status: `Error: ${err instanceof Error ? err.message : "Unknown"}`,
|
|
57522
|
+
error: createUnlinkError(err, "executeAdapter")
|
|
57523
|
+
}));
|
|
57524
|
+
throw err;
|
|
57525
|
+
}
|
|
57526
|
+
},
|
|
57527
|
+
[]
|
|
57528
|
+
);
|
|
57478
57529
|
const planWithdraw = useCallback(
|
|
57479
57530
|
async (params) => {
|
|
57480
57531
|
const wallet = walletRef.current;
|
|
@@ -57631,7 +57682,6 @@ function UnlinkProvider({
|
|
|
57631
57682
|
const value = useMemo(
|
|
57632
57683
|
() => ({
|
|
57633
57684
|
...state,
|
|
57634
|
-
chainId,
|
|
57635
57685
|
// Wallet actions
|
|
57636
57686
|
createWallet,
|
|
57637
57687
|
importWallet,
|
|
@@ -57648,6 +57698,8 @@ function UnlinkProvider({
|
|
|
57648
57698
|
requestDeposit,
|
|
57649
57699
|
// Withdraw actions
|
|
57650
57700
|
requestWithdraw,
|
|
57701
|
+
// Adapter actions
|
|
57702
|
+
executeAdapter,
|
|
57651
57703
|
planWithdraw,
|
|
57652
57704
|
executeWithdraw,
|
|
57653
57705
|
// Sync actions
|
|
@@ -57661,7 +57713,6 @@ function UnlinkProvider({
|
|
|
57661
57713
|
}),
|
|
57662
57714
|
[
|
|
57663
57715
|
state,
|
|
57664
|
-
chainId,
|
|
57665
57716
|
createWallet,
|
|
57666
57717
|
importWallet,
|
|
57667
57718
|
exportMnemonic,
|
|
@@ -57673,6 +57724,7 @@ function UnlinkProvider({
|
|
|
57673
57724
|
executeTransfer,
|
|
57674
57725
|
requestDeposit,
|
|
57675
57726
|
requestWithdraw,
|
|
57727
|
+
executeAdapter,
|
|
57676
57728
|
planWithdraw,
|
|
57677
57729
|
executeWithdraw,
|
|
57678
57730
|
refresh,
|
|
@@ -57910,6 +57962,17 @@ function useWithdraw() {
|
|
|
57910
57962
|
);
|
|
57911
57963
|
return useOperationMutation(op);
|
|
57912
57964
|
}
|
|
57965
|
+
|
|
57966
|
+
// src/useAdapter.ts
|
|
57967
|
+
import { useCallback as useCallback8 } from "react";
|
|
57968
|
+
function useAdapter() {
|
|
57969
|
+
const { executeAdapter } = useUnlink();
|
|
57970
|
+
const op = useCallback8(
|
|
57971
|
+
(params) => executeAdapter(params),
|
|
57972
|
+
[executeAdapter]
|
|
57973
|
+
);
|
|
57974
|
+
return useOperationMutation(op);
|
|
57975
|
+
}
|
|
57913
57976
|
export {
|
|
57914
57977
|
CONFIRMATION_POLL_INTERVAL_MS,
|
|
57915
57978
|
DEFAULT_CONFIRMATION_TIMEOUT_MS,
|
|
@@ -57926,6 +57989,7 @@ export {
|
|
|
57926
57989
|
parseZkAddress,
|
|
57927
57990
|
randomHex,
|
|
57928
57991
|
shortenHex,
|
|
57992
|
+
useAdapter,
|
|
57929
57993
|
useDeposit,
|
|
57930
57994
|
useOperationMutation,
|
|
57931
57995
|
useTransfer,
|