@embarkai/ui-kit 0.1.6 → 0.2.0
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/iframe/index.html +1 -1
- package/dist/iframe/main.js +1 -1
- package/dist/index.cjs +510 -94
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +75 -1
- package/dist/index.d.ts +75 -1
- package/dist/index.js +452 -39
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -150,7 +150,9 @@ var init_initial = __esm({
|
|
|
150
150
|
enabled: false,
|
|
151
151
|
supportedChains: [1, 137, 56],
|
|
152
152
|
requireSignature: true,
|
|
153
|
-
walletConnectProjectId: void 0
|
|
153
|
+
walletConnectProjectId: void 0,
|
|
154
|
+
mode: "linked",
|
|
155
|
+
allowedWallets: void 0
|
|
154
156
|
},
|
|
155
157
|
// preferedColorMode: 'light', // undefined means 'auto'
|
|
156
158
|
ui: {
|
|
@@ -15468,7 +15470,7 @@ var init_package = __esm({
|
|
|
15468
15470
|
"package.json"() {
|
|
15469
15471
|
package_default = {
|
|
15470
15472
|
name: "@embarkai/ui-kit",
|
|
15471
|
-
version: "0.
|
|
15473
|
+
version: "0.2.0",
|
|
15472
15474
|
description: "React UI components and hooks for EmbarkAI authentication and Account Abstraction",
|
|
15473
15475
|
type: "module",
|
|
15474
15476
|
main: "./dist/index.cjs",
|
|
@@ -16175,21 +16177,71 @@ async function unlinkWallet(address) {
|
|
|
16175
16177
|
throw new Error(errorData.message || `Failed to unlink wallet: ${response.statusText}`);
|
|
16176
16178
|
}
|
|
16177
16179
|
}
|
|
16178
|
-
function
|
|
16180
|
+
async function fetchProjectName(projectId) {
|
|
16181
|
+
const now = Date.now();
|
|
16182
|
+
if (metadataCache && now - metadataCache.timestamp < METADATA_CACHE_TTL) {
|
|
16183
|
+
return metadataCache.data.name;
|
|
16184
|
+
}
|
|
16185
|
+
try {
|
|
16186
|
+
const response = await fetch(`${METADATA_API_URL}/${projectId}/metadata`);
|
|
16187
|
+
if (!response.ok) return "EmbarkAI";
|
|
16188
|
+
const metadata = await response.json();
|
|
16189
|
+
metadataCache = { data: metadata, timestamp: now };
|
|
16190
|
+
return metadata.name;
|
|
16191
|
+
} catch {
|
|
16192
|
+
return "EmbarkAI";
|
|
16193
|
+
}
|
|
16194
|
+
}
|
|
16195
|
+
function createSignatureMessage(address, projectName, nonce) {
|
|
16179
16196
|
const timestamp = Date.now();
|
|
16180
16197
|
const nonceValue = nonce || Math.random().toString(36).substring(2, 15);
|
|
16181
|
-
return
|
|
16198
|
+
return `${projectName} Wallet Link
|
|
16182
16199
|
|
|
16183
16200
|
Address: ${address}
|
|
16184
16201
|
Nonce: ${nonceValue}
|
|
16185
16202
|
Timestamp: ${timestamp}
|
|
16186
16203
|
|
|
16187
|
-
Sign this message to link your wallet to
|
|
16204
|
+
Sign this message to link your wallet to ${projectName} Wallet`;
|
|
16188
16205
|
}
|
|
16206
|
+
var METADATA_API_URL, METADATA_CACHE_TTL, metadataCache;
|
|
16189
16207
|
var init_wallet = __esm({
|
|
16190
16208
|
"src/internal/auth/providers/wallet.ts"() {
|
|
16191
16209
|
init_auth();
|
|
16192
16210
|
init_types();
|
|
16211
|
+
METADATA_API_URL = "https://dashboard.lumiapassport.com/api/public/project";
|
|
16212
|
+
METADATA_CACHE_TTL = 36e5;
|
|
16213
|
+
metadataCache = null;
|
|
16214
|
+
}
|
|
16215
|
+
});
|
|
16216
|
+
|
|
16217
|
+
// src/internal/stores/useExternalWalletStore.ts
|
|
16218
|
+
import { create as create7 } from "zustand";
|
|
16219
|
+
var useExternalWalletStore;
|
|
16220
|
+
var init_useExternalWalletStore = __esm({
|
|
16221
|
+
"src/internal/stores/useExternalWalletStore.ts"() {
|
|
16222
|
+
useExternalWalletStore = create7((set) => ({
|
|
16223
|
+
configMode: "linked",
|
|
16224
|
+
activeMode: "linked",
|
|
16225
|
+
externalAddress: null,
|
|
16226
|
+
externalChainId: null,
|
|
16227
|
+
isExternalConnected: false,
|
|
16228
|
+
connectorName: null,
|
|
16229
|
+
setConfigMode: (mode) => set({ configMode: mode }),
|
|
16230
|
+
setActiveMode: (mode) => set({ activeMode: mode }),
|
|
16231
|
+
setExternalWallet: ({ address, chainId, connectorName }) => set({
|
|
16232
|
+
externalAddress: address,
|
|
16233
|
+
externalChainId: chainId,
|
|
16234
|
+
isExternalConnected: true,
|
|
16235
|
+
connectorName
|
|
16236
|
+
}),
|
|
16237
|
+
clearExternalWallet: () => set({
|
|
16238
|
+
externalAddress: null,
|
|
16239
|
+
externalChainId: null,
|
|
16240
|
+
isExternalConnected: false,
|
|
16241
|
+
connectorName: null
|
|
16242
|
+
}),
|
|
16243
|
+
setExternalChainId: (chainId) => set({ externalChainId: chainId })
|
|
16244
|
+
}));
|
|
16193
16245
|
}
|
|
16194
16246
|
});
|
|
16195
16247
|
|
|
@@ -16213,6 +16265,10 @@ function WalletConnectHandler() {
|
|
|
16213
16265
|
const setManageWalletLinkError = useManageWalletStore((st) => st.setLinkError);
|
|
16214
16266
|
const setLinkIsLoading = useManageWalletStore((st) => st.setLinkIsLoading);
|
|
16215
16267
|
const setProviderType = useManageWalletStore((st) => st.setProviderType);
|
|
16268
|
+
const providerConfig = useProviderConfig().config.current;
|
|
16269
|
+
const walletMode = providerConfig?.wallet?.mode || "linked";
|
|
16270
|
+
const projectId = providerConfig?.projectId;
|
|
16271
|
+
const setExternalWallet = useExternalWalletStore((st) => st.setExternalWallet);
|
|
16216
16272
|
const onLinkingComplete = useCallback23(
|
|
16217
16273
|
async (success) => {
|
|
16218
16274
|
setIsWalletLinking(false);
|
|
@@ -16243,24 +16299,42 @@ function WalletConnectHandler() {
|
|
|
16243
16299
|
const [hasStartedLinking, setHasStartedLinking] = React8.useState(false);
|
|
16244
16300
|
useEffect36(() => {
|
|
16245
16301
|
if (isWalletLinking && !hasStartedLinking) {
|
|
16302
|
+
console.log("[WalletConnectHandler] Starting wallet link flow:", {
|
|
16303
|
+
isConnected,
|
|
16304
|
+
openConnectModal: typeof openConnectModal,
|
|
16305
|
+
walletMode
|
|
16306
|
+
});
|
|
16246
16307
|
setHasStartedLinking(true);
|
|
16247
16308
|
setProviderType(null);
|
|
16248
16309
|
if (isConnected) {
|
|
16249
16310
|
disconnect();
|
|
16250
16311
|
setTimeout(() => {
|
|
16251
16312
|
setPage(null);
|
|
16252
|
-
openConnectModal
|
|
16313
|
+
if (openConnectModal) {
|
|
16314
|
+
openConnectModal();
|
|
16315
|
+
} else {
|
|
16316
|
+
console.error("[WalletConnectHandler] openConnectModal is undefined!");
|
|
16317
|
+
setIsWalletLinking(false);
|
|
16318
|
+
setHasStartedLinking(false);
|
|
16319
|
+
}
|
|
16253
16320
|
}, 500);
|
|
16254
16321
|
} else {
|
|
16255
16322
|
setPage(null);
|
|
16256
|
-
openConnectModal
|
|
16323
|
+
if (openConnectModal) {
|
|
16324
|
+
openConnectModal();
|
|
16325
|
+
} else {
|
|
16326
|
+
console.error("[WalletConnectHandler] openConnectModal is undefined!");
|
|
16327
|
+
setIsWalletLinking(false);
|
|
16328
|
+
setHasStartedLinking(false);
|
|
16329
|
+
}
|
|
16257
16330
|
}
|
|
16258
16331
|
}
|
|
16259
16332
|
if (!isWalletLinking && hasStartedLinking) {
|
|
16260
16333
|
setHasStartedLinking(false);
|
|
16261
|
-
|
|
16334
|
+
const shouldKeepConnected = walletMode === "direct" || walletMode === "both";
|
|
16335
|
+
if (isConnected && !shouldKeepConnected) disconnect();
|
|
16262
16336
|
}
|
|
16263
|
-
}, [isWalletLinking, hasStartedLinking, isConnected, openConnectModal, disconnect, setPage, setProviderType]);
|
|
16337
|
+
}, [isWalletLinking, hasStartedLinking, isConnected, openConnectModal, disconnect, setPage, setProviderType, walletMode]);
|
|
16264
16338
|
useEffect36(() => {
|
|
16265
16339
|
if (hasStartedLinking && !connectModalOpen && !isConnected && isWalletLinking) {
|
|
16266
16340
|
console.log("[WalletConnectHandler] Modal closed without connecting");
|
|
@@ -16268,6 +16342,16 @@ function WalletConnectHandler() {
|
|
|
16268
16342
|
setHasStartedLinking(false);
|
|
16269
16343
|
}
|
|
16270
16344
|
}, [connectModalOpen, hasStartedLinking, isConnected, isWalletLinking]);
|
|
16345
|
+
useEffect36(() => {
|
|
16346
|
+
if (isWalletLinking) {
|
|
16347
|
+
const timeout = setTimeout(() => {
|
|
16348
|
+
console.warn("[WalletConnectHandler] Wallet linking timed out, resetting state");
|
|
16349
|
+
setIsWalletLinking(false);
|
|
16350
|
+
setHasStartedLinking(false);
|
|
16351
|
+
}, 12e4);
|
|
16352
|
+
return () => clearTimeout(timeout);
|
|
16353
|
+
}
|
|
16354
|
+
}, [isWalletLinking, setIsWalletLinking]);
|
|
16271
16355
|
const { mutate: handleWalletSign, isPending: isWalletSigning } = useMutation16({
|
|
16272
16356
|
mutationFn: async (payload) => {
|
|
16273
16357
|
const { chainId, signingWalletAddress } = payload;
|
|
@@ -16285,7 +16369,8 @@ function WalletConnectHandler() {
|
|
|
16285
16369
|
return;
|
|
16286
16370
|
}
|
|
16287
16371
|
setLinkIsLoading(true);
|
|
16288
|
-
const
|
|
16372
|
+
const projectName = projectId ? await fetchProjectName(projectId) : "EmbarkAI";
|
|
16373
|
+
const message = createSignatureMessage(signingWalletAddress, projectName);
|
|
16289
16374
|
const signature = await signMessageAsync({ message, account: signingWalletAddress });
|
|
16290
16375
|
if (!signature) {
|
|
16291
16376
|
throw new Error("Failed to get signature");
|
|
@@ -16303,7 +16388,16 @@ function WalletConnectHandler() {
|
|
|
16303
16388
|
});
|
|
16304
16389
|
},
|
|
16305
16390
|
onSuccess: () => {
|
|
16306
|
-
|
|
16391
|
+
const shouldKeepConnected = walletMode === "direct" || walletMode === "both";
|
|
16392
|
+
if (shouldKeepConnected && walletAddress && chain?.id && connector) {
|
|
16393
|
+
setExternalWallet({
|
|
16394
|
+
address: walletAddress,
|
|
16395
|
+
chainId: chain.id,
|
|
16396
|
+
connectorName: connector.name || "Unknown Wallet"
|
|
16397
|
+
});
|
|
16398
|
+
} else {
|
|
16399
|
+
disconnect();
|
|
16400
|
+
}
|
|
16307
16401
|
setHasStartedLinking(false);
|
|
16308
16402
|
onLinkingComplete(true);
|
|
16309
16403
|
setLinkIsLoading(false);
|
|
@@ -16343,6 +16437,17 @@ function WalletConnectHandler() {
|
|
|
16343
16437
|
handleWalletSign({ chainId: chain.id, signingWalletAddress: walletAddress });
|
|
16344
16438
|
}
|
|
16345
16439
|
}, [chain, isConnected, walletAddress, isWalletLinking, hasStartedLinking]);
|
|
16440
|
+
useEffect36(() => {
|
|
16441
|
+
if (isConnected && !chain?.id && isWalletLinking && hasStartedLinking && !connectModalOpen && !isWalletSigning) {
|
|
16442
|
+
const timeout = setTimeout(() => {
|
|
16443
|
+
console.warn("[WalletConnectHandler] Wallet connected but chain info missing, resetting");
|
|
16444
|
+
onLinkingComplete(false);
|
|
16445
|
+
setHasStartedLinking(false);
|
|
16446
|
+
disconnect();
|
|
16447
|
+
}, 5e3);
|
|
16448
|
+
return () => clearTimeout(timeout);
|
|
16449
|
+
}
|
|
16450
|
+
}, [isConnected, chain?.id, isWalletLinking, hasStartedLinking, connectModalOpen, isWalletSigning, onLinkingComplete, disconnect]);
|
|
16346
16451
|
return null;
|
|
16347
16452
|
}
|
|
16348
16453
|
var init_WalletConnectHandler = __esm({
|
|
@@ -16353,10 +16458,67 @@ var init_WalletConnectHandler = __esm({
|
|
|
16353
16458
|
init_wallet();
|
|
16354
16459
|
init_AuthMenu2();
|
|
16355
16460
|
init_useLayoutDataStore();
|
|
16461
|
+
init_useExternalWalletStore();
|
|
16356
16462
|
init_ManageWalletMenu();
|
|
16357
16463
|
}
|
|
16358
16464
|
});
|
|
16359
16465
|
|
|
16466
|
+
// src/internal/components/DirectWalletHandler.tsx
|
|
16467
|
+
import { useEffect as useEffect37 } from "react";
|
|
16468
|
+
import { useAccount as useAccount2 } from "wagmi";
|
|
16469
|
+
function DirectWalletHandler() {
|
|
16470
|
+
const walletMode = useProviderConfig().config.current?.wallet?.mode || "linked";
|
|
16471
|
+
const { address, isConnected, chain, connector } = useAccount2();
|
|
16472
|
+
const isExternalConnected = useExternalWalletStore((st) => st.isExternalConnected);
|
|
16473
|
+
const externalAddress = useExternalWalletStore((st) => st.externalAddress);
|
|
16474
|
+
const setExternalWallet = useExternalWalletStore((st) => st.setExternalWallet);
|
|
16475
|
+
const clearExternalWallet = useExternalWalletStore((st) => st.clearExternalWallet);
|
|
16476
|
+
const setExternalChainId = useExternalWalletStore((st) => st.setExternalChainId);
|
|
16477
|
+
const setConfigMode = useExternalWalletStore((st) => st.setConfigMode);
|
|
16478
|
+
const setActiveMode = useExternalWalletStore((st) => st.setActiveMode);
|
|
16479
|
+
useEffect37(() => {
|
|
16480
|
+
setConfigMode(walletMode);
|
|
16481
|
+
if (walletMode !== "both") {
|
|
16482
|
+
setActiveMode(walletMode);
|
|
16483
|
+
}
|
|
16484
|
+
}, [walletMode, setConfigMode, setActiveMode]);
|
|
16485
|
+
useEffect37(() => {
|
|
16486
|
+
if (isConnected && address && !isExternalConnected && connector) {
|
|
16487
|
+
setExternalWallet({
|
|
16488
|
+
address,
|
|
16489
|
+
chainId: chain?.id || 1,
|
|
16490
|
+
connectorName: connector.name || "Unknown Wallet"
|
|
16491
|
+
});
|
|
16492
|
+
}
|
|
16493
|
+
}, [isConnected, address, isExternalConnected, connector, chain?.id, setExternalWallet]);
|
|
16494
|
+
useEffect37(() => {
|
|
16495
|
+
if (isExternalConnected && !isConnected) {
|
|
16496
|
+
clearExternalWallet();
|
|
16497
|
+
}
|
|
16498
|
+
}, [isConnected, isExternalConnected, clearExternalWallet]);
|
|
16499
|
+
useEffect37(() => {
|
|
16500
|
+
if (isExternalConnected && isConnected && chain?.id) {
|
|
16501
|
+
setExternalChainId(chain.id);
|
|
16502
|
+
}
|
|
16503
|
+
}, [chain?.id, isConnected, isExternalConnected, setExternalChainId]);
|
|
16504
|
+
useEffect37(() => {
|
|
16505
|
+
if (isExternalConnected && isConnected && address && address !== externalAddress && connector) {
|
|
16506
|
+
setExternalWallet({
|
|
16507
|
+
address,
|
|
16508
|
+
chainId: chain?.id || 1,
|
|
16509
|
+
connectorName: connector.name || "Unknown Wallet"
|
|
16510
|
+
});
|
|
16511
|
+
}
|
|
16512
|
+
}, [address, isConnected, isExternalConnected, externalAddress, chain?.id, connector, setExternalWallet]);
|
|
16513
|
+
return null;
|
|
16514
|
+
}
|
|
16515
|
+
var init_DirectWalletHandler = __esm({
|
|
16516
|
+
"src/internal/components/DirectWalletHandler.tsx"() {
|
|
16517
|
+
init_ProviderContext();
|
|
16518
|
+
init_useExternalWalletStore();
|
|
16519
|
+
}
|
|
16520
|
+
});
|
|
16521
|
+
|
|
16360
16522
|
// src/context/SessionContext.tsx
|
|
16361
16523
|
import {
|
|
16362
16524
|
createBundlerClientForChain,
|
|
@@ -16366,7 +16528,7 @@ import {
|
|
|
16366
16528
|
getViemChain as getViemChain2
|
|
16367
16529
|
} from "@embarkai/core/read";
|
|
16368
16530
|
import { Fragment as Fragment39 } from "react";
|
|
16369
|
-
import { create as
|
|
16531
|
+
import { create as create8 } from "zustand";
|
|
16370
16532
|
import { persist } from "zustand/middleware";
|
|
16371
16533
|
import { jsx as jsx93, jsxs as jsxs83 } from "react/jsx-runtime";
|
|
16372
16534
|
function getChainParams(chainCfg) {
|
|
@@ -16389,6 +16551,7 @@ function SessionProvider({ children }) {
|
|
|
16389
16551
|
return /* @__PURE__ */ jsxs83(Fragment39, { children: [
|
|
16390
16552
|
children,
|
|
16391
16553
|
config.current?.wallet?.enabled && /* @__PURE__ */ jsx93(WalletConnectHandler, {}),
|
|
16554
|
+
config.current?.wallet?.enabled && (config.current?.wallet?.mode === "direct" || config.current?.wallet?.mode === "both") && /* @__PURE__ */ jsx93(DirectWalletHandler, {}),
|
|
16392
16555
|
/* @__PURE__ */ jsx93(BalanceFeedProvider, {}),
|
|
16393
16556
|
/* @__PURE__ */ jsx93(ChainSync, {}),
|
|
16394
16557
|
/* @__PURE__ */ jsx93(
|
|
@@ -16408,8 +16571,9 @@ var init_SessionContext = __esm({
|
|
|
16408
16571
|
init_Dialog2();
|
|
16409
16572
|
init_TssManager();
|
|
16410
16573
|
init_WalletConnectHandler();
|
|
16574
|
+
init_DirectWalletHandler();
|
|
16411
16575
|
init_ProviderContext();
|
|
16412
|
-
useSession =
|
|
16576
|
+
useSession = create8()(
|
|
16413
16577
|
persist(
|
|
16414
16578
|
(set) => ({
|
|
16415
16579
|
isLoading: false,
|
|
@@ -17463,6 +17627,7 @@ __export(auth_exports, {
|
|
|
17463
17627
|
deriveDemoPrivateKey: () => deriveDemoPrivateKey,
|
|
17464
17628
|
ensureKeyshare: () => ensureKeyshare,
|
|
17465
17629
|
ensureValidToken: () => ensureValidToken,
|
|
17630
|
+
fetchProjectName: () => fetchProjectName,
|
|
17466
17631
|
formatDate: () => formatDate,
|
|
17467
17632
|
getKeyshareInfo: () => getKeyshareInfo,
|
|
17468
17633
|
getLinkedProviders: () => getLinkedProviders,
|
|
@@ -18745,27 +18910,45 @@ var init_iframe_manager = __esm({
|
|
|
18745
18910
|
// src/config/rainbowkit.ts
|
|
18746
18911
|
import { lumiaMainnetChain as lumiaMainnetChain2, lumiaTestnetChain as lumiaTestnetChain2 } from "@embarkai/core/read";
|
|
18747
18912
|
import { getDefaultConfig } from "@rainbow-me/rainbowkit";
|
|
18913
|
+
import {
|
|
18914
|
+
coinbaseWallet,
|
|
18915
|
+
metaMaskWallet,
|
|
18916
|
+
rainbowWallet,
|
|
18917
|
+
walletConnectWallet
|
|
18918
|
+
} from "@rainbow-me/rainbowkit/wallets";
|
|
18748
18919
|
import { arbitrum, avalanche, base, bsc, mainnet, optimism, polygon, zora } from "wagmi/chains";
|
|
18749
|
-
var getProjectId, createRainbowConfig, rainbowConfig, rainbowTheme;
|
|
18920
|
+
var getProjectId, WALLET_MAP, createRainbowConfig, rainbowConfig, rainbowTheme;
|
|
18750
18921
|
var init_rainbowkit = __esm({
|
|
18751
18922
|
"src/config/rainbowkit.ts"() {
|
|
18752
18923
|
getProjectId = (configProjectId) => {
|
|
18753
|
-
if (configProjectId)
|
|
18754
|
-
return configProjectId;
|
|
18755
|
-
}
|
|
18924
|
+
if (configProjectId) return configProjectId;
|
|
18756
18925
|
if (typeof window !== "undefined") {
|
|
18757
18926
|
return window.NEXT_PUBLIC_WALLET_CONNECT_PROJECT_ID || window.VITE_WALLET_CONNECT_PROJECT_ID || window.__WALLET_CONNECT_PROJECT_ID__ || "YOUR_PROJECT_ID";
|
|
18758
18927
|
}
|
|
18759
18928
|
return "YOUR_PROJECT_ID";
|
|
18760
18929
|
};
|
|
18761
|
-
|
|
18762
|
-
|
|
18930
|
+
WALLET_MAP = {
|
|
18931
|
+
walletconnect: walletConnectWallet,
|
|
18932
|
+
metamask: metaMaskWallet,
|
|
18933
|
+
coinbase: coinbaseWallet,
|
|
18934
|
+
rainbow: rainbowWallet
|
|
18935
|
+
};
|
|
18936
|
+
createRainbowConfig = (options) => {
|
|
18937
|
+
const opts = typeof options === "string" ? { projectId: options } : options || {};
|
|
18938
|
+
const config = {
|
|
18763
18939
|
appName: "Mbark Wallet",
|
|
18764
|
-
projectId: getProjectId(projectId),
|
|
18940
|
+
projectId: getProjectId(opts.projectId),
|
|
18765
18941
|
chains: [lumiaMainnetChain2, lumiaTestnetChain2, mainnet, polygon, bsc, arbitrum, optimism, avalanche, base, zora],
|
|
18766
18942
|
ssr: false
|
|
18767
|
-
|
|
18768
|
-
|
|
18943
|
+
};
|
|
18944
|
+
if (opts.allowedWallets && opts.allowedWallets.length > 0) {
|
|
18945
|
+
const wallets = opts.allowedWallets.map((id) => WALLET_MAP[id.toLowerCase()]).filter(Boolean);
|
|
18946
|
+
if (!opts.allowedWallets.some((id) => id.toLowerCase() === "walletconnect")) {
|
|
18947
|
+
wallets.push(walletConnectWallet);
|
|
18948
|
+
}
|
|
18949
|
+
config.wallets = [{ groupName: "Supported", wallets }];
|
|
18950
|
+
}
|
|
18951
|
+
return getDefaultConfig(config);
|
|
18769
18952
|
};
|
|
18770
18953
|
rainbowConfig = createRainbowConfig();
|
|
18771
18954
|
rainbowTheme = {
|
|
@@ -18968,7 +19151,13 @@ import { Fragment as Fragment40, jsx as jsx94 } from "react/jsx-runtime";
|
|
|
18968
19151
|
function RainbowKitProvider({ children }) {
|
|
18969
19152
|
const config = useProviderConfig().config;
|
|
18970
19153
|
const colorMode = useLayoutStore((st) => st.colorMode);
|
|
18971
|
-
const rainbowConfig2 = useMemo9(
|
|
19154
|
+
const rainbowConfig2 = useMemo9(
|
|
19155
|
+
() => createRainbowConfig({
|
|
19156
|
+
projectId: config.current?.wallet?.walletConnectProjectId,
|
|
19157
|
+
allowedWallets: config.current?.wallet?.allowedWallets
|
|
19158
|
+
}),
|
|
19159
|
+
[]
|
|
19160
|
+
);
|
|
18972
19161
|
const customTheme = useMemo9(() => {
|
|
18973
19162
|
if (!config.current?.wallet?.enabled) return {};
|
|
18974
19163
|
return colorMode === "dark" ? {
|
|
@@ -19064,7 +19253,7 @@ import {
|
|
|
19064
19253
|
createContext,
|
|
19065
19254
|
useCallback as useCallback24,
|
|
19066
19255
|
useContext,
|
|
19067
|
-
useEffect as
|
|
19256
|
+
useEffect as useEffect38,
|
|
19068
19257
|
useMemo as useMemo10,
|
|
19069
19258
|
useRef as useRef15
|
|
19070
19259
|
} from "react";
|
|
@@ -19072,11 +19261,11 @@ import { jsx as jsx96 } from "react/jsx-runtime";
|
|
|
19072
19261
|
function Provider(props) {
|
|
19073
19262
|
const { children, projectId, initialConfig = {}, callbacks } = props;
|
|
19074
19263
|
const callbacksRef = useRef15(callbacks);
|
|
19075
|
-
|
|
19264
|
+
useEffect38(() => {
|
|
19076
19265
|
callbacksRef.current = callbacks;
|
|
19077
19266
|
}, [callbacks]);
|
|
19078
|
-
|
|
19079
|
-
const config = useRef15({
|
|
19267
|
+
useEffect38(() => notifyNoProjetctId(projectId), [projectId]);
|
|
19268
|
+
const config = useRef15(merge3({}, DEFAULT_PROVIDER_CONFIG, { projectId }, initialConfig));
|
|
19080
19269
|
const updateConfig = useCallback24((updates) => {
|
|
19081
19270
|
const prev = config.current;
|
|
19082
19271
|
const next = { ...prev };
|
|
@@ -19110,7 +19299,7 @@ function Provider(props) {
|
|
|
19110
19299
|
if (updates.translations) next.translations = { ...next.translations, ...updates.translations };
|
|
19111
19300
|
config.current = next;
|
|
19112
19301
|
}, []);
|
|
19113
|
-
|
|
19302
|
+
useEffect38(() => {
|
|
19114
19303
|
if (typeof window === "undefined" || !projectId) return;
|
|
19115
19304
|
const mergedConfig = merge3(DEFAULT_PROVIDER_CONFIG, initialConfig);
|
|
19116
19305
|
updateConfig(mergedConfig);
|
|
@@ -19128,7 +19317,7 @@ function Provider(props) {
|
|
|
19128
19317
|
useSession.getState().setActiveChainId(mergedConfig.network.chainId);
|
|
19129
19318
|
}
|
|
19130
19319
|
}, [projectId, initialConfig]);
|
|
19131
|
-
|
|
19320
|
+
useEffect38(() => {
|
|
19132
19321
|
if (typeof window === "undefined" || !projectId) return;
|
|
19133
19322
|
try {
|
|
19134
19323
|
initSdkErrorTracking();
|
|
@@ -19183,7 +19372,7 @@ var init_ProviderContext = __esm({
|
|
|
19183
19372
|
// src/components/ConnectWalletButton.tsx
|
|
19184
19373
|
import { useQuery as useQuery22 } from "@tanstack/react-query";
|
|
19185
19374
|
import { Cloud as Cloud4, Laptop as Laptop2, Loader as Loader33, Shield as Shield3 } from "lucide-react";
|
|
19186
|
-
import { useEffect as
|
|
19375
|
+
import { useEffect as useEffect39, useMemo as useMemo11 } from "react";
|
|
19187
19376
|
import { Fragment as Fragment41, jsx as jsx97, jsxs as jsxs84 } from "react/jsx-runtime";
|
|
19188
19377
|
function getFormattedStatus(label, status, showStatus) {
|
|
19189
19378
|
const isStatus = showStatus && status && status !== "idle" && status !== "ready";
|
|
@@ -19203,7 +19392,7 @@ function ConnectWalletButton(props) {
|
|
|
19203
19392
|
const colorMode = useLayoutStore((st) => st.colorMode);
|
|
19204
19393
|
const { session, address, hasServerVault, isLoading, isIframeReady, status, setUsePaymaster } = useSession();
|
|
19205
19394
|
const connectButtonLabel = getFormattedStatus(label || "Connect", status, isIframeReady);
|
|
19206
|
-
|
|
19395
|
+
useEffect39(() => setUsePaymaster(usePaymaster), [setUsePaymaster, usePaymaster]);
|
|
19207
19396
|
const { data: profile, isLoading: isProfileLoading } = useQuery22({
|
|
19208
19397
|
retry: false,
|
|
19209
19398
|
enabled: !!address,
|
|
@@ -19990,7 +20179,7 @@ var init_Hash = __esm({
|
|
|
19990
20179
|
});
|
|
19991
20180
|
|
|
19992
20181
|
// src/internal/components/TransactionsMenu/TransactionsList.tsx
|
|
19993
|
-
import { useEffect as
|
|
20182
|
+
import { useEffect as useEffect41, useState as useState25 } from "react";
|
|
19994
20183
|
import { jsx as jsx103, jsxs as jsxs88 } from "react/jsx-runtime";
|
|
19995
20184
|
var TransactionsList;
|
|
19996
20185
|
var init_TransactionsList = __esm({
|
|
@@ -20000,7 +20189,7 @@ var init_TransactionsList = __esm({
|
|
|
20000
20189
|
const [transactions, setTransactions] = useState25([]);
|
|
20001
20190
|
const [loading, setLoading] = useState25(true);
|
|
20002
20191
|
const [error, setError] = useState25(null);
|
|
20003
|
-
|
|
20192
|
+
useEffect41(() => {
|
|
20004
20193
|
const fetchTransactions2 = async () => {
|
|
20005
20194
|
try {
|
|
20006
20195
|
setLoading(true);
|
|
@@ -20294,13 +20483,229 @@ var init_useUserOpStatus = __esm({
|
|
|
20294
20483
|
}
|
|
20295
20484
|
});
|
|
20296
20485
|
|
|
20486
|
+
// src/hooks/useWalletMode.ts
|
|
20487
|
+
import { useCallback as useCallback28 } from "react";
|
|
20488
|
+
function useWalletMode() {
|
|
20489
|
+
const configMode = useExternalWalletStore((st) => st.configMode);
|
|
20490
|
+
const activeMode = useExternalWalletStore((st) => st.activeMode);
|
|
20491
|
+
const setActiveMode = useExternalWalletStore((st) => st.setActiveMode);
|
|
20492
|
+
const switchMode = useCallback28(
|
|
20493
|
+
(mode) => {
|
|
20494
|
+
if (configMode !== "both") return;
|
|
20495
|
+
setActiveMode(mode);
|
|
20496
|
+
},
|
|
20497
|
+
[configMode, setActiveMode]
|
|
20498
|
+
);
|
|
20499
|
+
return {
|
|
20500
|
+
configMode,
|
|
20501
|
+
activeMode,
|
|
20502
|
+
switchMode,
|
|
20503
|
+
isDirect: activeMode === "direct"
|
|
20504
|
+
};
|
|
20505
|
+
}
|
|
20506
|
+
var init_useWalletMode = __esm({
|
|
20507
|
+
"src/hooks/useWalletMode.ts"() {
|
|
20508
|
+
init_useExternalWalletStore();
|
|
20509
|
+
}
|
|
20510
|
+
});
|
|
20511
|
+
|
|
20512
|
+
// src/hooks/useDirectWallet.ts
|
|
20513
|
+
import { useCallback as useCallback29 } from "react";
|
|
20514
|
+
import { useConnectModal as useConnectModal2 } from "@rainbow-me/rainbowkit";
|
|
20515
|
+
import { useDisconnect as useDisconnect2 } from "wagmi";
|
|
20516
|
+
function useDirectWallet() {
|
|
20517
|
+
const address = useExternalWalletStore((st) => st.externalAddress);
|
|
20518
|
+
const chainId = useExternalWalletStore((st) => st.externalChainId);
|
|
20519
|
+
const isConnected = useExternalWalletStore((st) => st.isExternalConnected);
|
|
20520
|
+
const connectorName = useExternalWalletStore((st) => st.connectorName);
|
|
20521
|
+
const clearExternalWallet = useExternalWalletStore((st) => st.clearExternalWallet);
|
|
20522
|
+
const { disconnect: wagmiDisconnect } = useDisconnect2();
|
|
20523
|
+
const { openConnectModal } = useConnectModal2();
|
|
20524
|
+
const setIsWalletLinking = useLayoutDataStore((st) => st.setIsWalletLinking);
|
|
20525
|
+
const connect = useCallback29(() => {
|
|
20526
|
+
setIsWalletLinking(true);
|
|
20527
|
+
}, [setIsWalletLinking]);
|
|
20528
|
+
const reconnect = useCallback29(() => {
|
|
20529
|
+
if (openConnectModal) openConnectModal();
|
|
20530
|
+
}, [openConnectModal]);
|
|
20531
|
+
const disconnect = useCallback29(() => {
|
|
20532
|
+
wagmiDisconnect();
|
|
20533
|
+
clearExternalWallet();
|
|
20534
|
+
}, [wagmiDisconnect, clearExternalWallet]);
|
|
20535
|
+
return {
|
|
20536
|
+
address,
|
|
20537
|
+
chainId,
|
|
20538
|
+
isConnected,
|
|
20539
|
+
connectorName,
|
|
20540
|
+
connect,
|
|
20541
|
+
reconnect,
|
|
20542
|
+
disconnect
|
|
20543
|
+
};
|
|
20544
|
+
}
|
|
20545
|
+
var init_useDirectWallet = __esm({
|
|
20546
|
+
"src/hooks/useDirectWallet.ts"() {
|
|
20547
|
+
init_useExternalWalletStore();
|
|
20548
|
+
init_useLayoutDataStore();
|
|
20549
|
+
}
|
|
20550
|
+
});
|
|
20551
|
+
|
|
20552
|
+
// src/hooks/useSendDirectTransaction.ts
|
|
20553
|
+
import { useCallback as useCallback30, useState as useState27 } from "react";
|
|
20554
|
+
import { isAddress as isAddress3, parseEther as parseEther4 } from "viem";
|
|
20555
|
+
import { useSendTransaction as useWagmiSendTransaction, useSwitchChain } from "wagmi";
|
|
20556
|
+
function useSendDirectTransaction() {
|
|
20557
|
+
const isConnected = useExternalWalletStore((st) => st.isExternalConnected);
|
|
20558
|
+
const externalChainId = useExternalWalletStore((st) => st.externalChainId);
|
|
20559
|
+
const { sendTransactionAsync } = useWagmiSendTransaction();
|
|
20560
|
+
const { switchChainAsync } = useSwitchChain();
|
|
20561
|
+
const [isPending, setIsPending] = useState27(false);
|
|
20562
|
+
const [error, setError] = useState27(null);
|
|
20563
|
+
const [txHash, setTxHash] = useState27(null);
|
|
20564
|
+
const sendTransaction = useCallback30(
|
|
20565
|
+
async (params) => {
|
|
20566
|
+
if (!isConnected) {
|
|
20567
|
+
setError("No external wallet connected");
|
|
20568
|
+
return null;
|
|
20569
|
+
}
|
|
20570
|
+
if (!isAddress3(params.to)) {
|
|
20571
|
+
setError("Invalid recipient address");
|
|
20572
|
+
return null;
|
|
20573
|
+
}
|
|
20574
|
+
setIsPending(true);
|
|
20575
|
+
setError(null);
|
|
20576
|
+
setTxHash(null);
|
|
20577
|
+
try {
|
|
20578
|
+
if (params.chainId && params.chainId !== externalChainId) {
|
|
20579
|
+
await switchChainAsync({ chainId: params.chainId });
|
|
20580
|
+
}
|
|
20581
|
+
const hash = await sendTransactionAsync({
|
|
20582
|
+
to: params.to,
|
|
20583
|
+
value: parseEther4(params.value),
|
|
20584
|
+
data: params.data
|
|
20585
|
+
});
|
|
20586
|
+
setTxHash(hash);
|
|
20587
|
+
return hash;
|
|
20588
|
+
} catch (err) {
|
|
20589
|
+
const message = err instanceof Error ? err.message : "Transaction failed";
|
|
20590
|
+
setError(message);
|
|
20591
|
+
return null;
|
|
20592
|
+
} finally {
|
|
20593
|
+
setIsPending(false);
|
|
20594
|
+
}
|
|
20595
|
+
},
|
|
20596
|
+
[isConnected, externalChainId, sendTransactionAsync, switchChainAsync]
|
|
20597
|
+
);
|
|
20598
|
+
const reset = useCallback30(() => {
|
|
20599
|
+
setError(null);
|
|
20600
|
+
setTxHash(null);
|
|
20601
|
+
setIsPending(false);
|
|
20602
|
+
}, []);
|
|
20603
|
+
return { sendTransaction, isPending, error, txHash, reset };
|
|
20604
|
+
}
|
|
20605
|
+
var init_useSendDirectTransaction = __esm({
|
|
20606
|
+
"src/hooks/useSendDirectTransaction.ts"() {
|
|
20607
|
+
init_useExternalWalletStore();
|
|
20608
|
+
}
|
|
20609
|
+
});
|
|
20610
|
+
|
|
20611
|
+
// src/hooks/useTransferToLinkedWallet.ts
|
|
20612
|
+
import { useCallback as useCallback31, useMemo as useMemo12, useState as useState28 } from "react";
|
|
20613
|
+
import { encodeFunctionData as encodeFunctionData4, isAddress as isAddress4, parseEther as parseEther5, parseUnits as parseUnits3 } from "viem";
|
|
20614
|
+
function useTransferToLinkedWallet() {
|
|
20615
|
+
const session = useSession((st) => st.session);
|
|
20616
|
+
const { profiles } = useLinkedProfiles();
|
|
20617
|
+
const [isPending, setIsPending] = useState28(false);
|
|
20618
|
+
const [error, setError] = useState28(null);
|
|
20619
|
+
const [userOpHash, setUserOpHash] = useState28(null);
|
|
20620
|
+
const linkedWallets = useMemo12(
|
|
20621
|
+
() => (profiles || []).filter((p) => p.provider === "wallet" && p.externalId).map((p) => p.externalId),
|
|
20622
|
+
[profiles]
|
|
20623
|
+
);
|
|
20624
|
+
const transfer = useCallback31(
|
|
20625
|
+
async (params) => {
|
|
20626
|
+
if (!session) {
|
|
20627
|
+
setError("No active session");
|
|
20628
|
+
return null;
|
|
20629
|
+
}
|
|
20630
|
+
const toAddress = params.toAddress || linkedWallets[0];
|
|
20631
|
+
if (!toAddress || !isAddress4(toAddress)) {
|
|
20632
|
+
setError("No linked wallet address available");
|
|
20633
|
+
return null;
|
|
20634
|
+
}
|
|
20635
|
+
setIsPending(true);
|
|
20636
|
+
setError(null);
|
|
20637
|
+
setUserOpHash(null);
|
|
20638
|
+
try {
|
|
20639
|
+
let to;
|
|
20640
|
+
let value;
|
|
20641
|
+
let data;
|
|
20642
|
+
if (params.token === "native") {
|
|
20643
|
+
to = toAddress;
|
|
20644
|
+
value = parseEther5(params.amount).toString();
|
|
20645
|
+
data = "0x";
|
|
20646
|
+
} else {
|
|
20647
|
+
const decimals = params.decimals ?? 18;
|
|
20648
|
+
to = params.token;
|
|
20649
|
+
value = "0";
|
|
20650
|
+
data = encodeFunctionData4({
|
|
20651
|
+
abi: ERC20_TRANSFER_ABI2,
|
|
20652
|
+
functionName: "transfer",
|
|
20653
|
+
args: [toAddress, parseUnits3(params.amount, decimals)]
|
|
20654
|
+
});
|
|
20655
|
+
}
|
|
20656
|
+
const hash = await sendUserOperation2(session, {
|
|
20657
|
+
to,
|
|
20658
|
+
value,
|
|
20659
|
+
data,
|
|
20660
|
+
feeType: "standard",
|
|
20661
|
+
chainId: params.chainId
|
|
20662
|
+
});
|
|
20663
|
+
setUserOpHash(hash);
|
|
20664
|
+
return hash;
|
|
20665
|
+
} catch (err) {
|
|
20666
|
+
const message = err instanceof Error ? err.message : "Transfer failed";
|
|
20667
|
+
setError(message);
|
|
20668
|
+
return null;
|
|
20669
|
+
} finally {
|
|
20670
|
+
setIsPending(false);
|
|
20671
|
+
}
|
|
20672
|
+
},
|
|
20673
|
+
[session, linkedWallets]
|
|
20674
|
+
);
|
|
20675
|
+
const reset = useCallback31(() => {
|
|
20676
|
+
setError(null);
|
|
20677
|
+
setUserOpHash(null);
|
|
20678
|
+
setIsPending(false);
|
|
20679
|
+
}, []);
|
|
20680
|
+
return { transfer, isPending, error, userOpHash, linkedWallets, reset };
|
|
20681
|
+
}
|
|
20682
|
+
var ERC20_TRANSFER_ABI2;
|
|
20683
|
+
var init_useTransferToLinkedWallet = __esm({
|
|
20684
|
+
"src/hooks/useTransferToLinkedWallet.ts"() {
|
|
20685
|
+
init_SessionContext();
|
|
20686
|
+
init_account();
|
|
20687
|
+
init_linkedProfiles();
|
|
20688
|
+
ERC20_TRANSFER_ABI2 = [
|
|
20689
|
+
{
|
|
20690
|
+
type: "function",
|
|
20691
|
+
name: "transfer",
|
|
20692
|
+
inputs: [
|
|
20693
|
+
{ name: "to", type: "address" },
|
|
20694
|
+
{ name: "amount", type: "uint256" }
|
|
20695
|
+
],
|
|
20696
|
+
outputs: [{ name: "", type: "bool" }]
|
|
20697
|
+
}
|
|
20698
|
+
];
|
|
20699
|
+
}
|
|
20700
|
+
});
|
|
20701
|
+
|
|
20297
20702
|
// src/hooks/useLogout.ts
|
|
20298
20703
|
import { logout as coreLogout, jwtTokenManager as jwtTokenManager3 } from "@embarkai/core/auth";
|
|
20299
|
-
import { useCallback as
|
|
20704
|
+
import { useCallback as useCallback32 } from "react";
|
|
20300
20705
|
function useLogout() {
|
|
20301
20706
|
const { setSession, setIsLoading, setAddress, setStatus, setError, address } = useSession();
|
|
20302
20707
|
const { callbacks } = useProviderConfig();
|
|
20303
|
-
const logout2 =
|
|
20708
|
+
const logout2 = useCallback32(async () => {
|
|
20304
20709
|
const prevAddress = address;
|
|
20305
20710
|
let userId = null;
|
|
20306
20711
|
setIsLoading(true);
|
|
@@ -20390,21 +20795,21 @@ var init_clients2 = __esm({
|
|
|
20390
20795
|
|
|
20391
20796
|
// src/modules/transactions.ts
|
|
20392
20797
|
import { getViemChain as getViemChain4 } from "@embarkai/core/read";
|
|
20393
|
-
import { parseEther as
|
|
20394
|
-
import { useAccount as
|
|
20798
|
+
import { parseEther as parseEther6 } from "viem";
|
|
20799
|
+
import { useAccount as useAccount3, usePublicClient, useWalletClient } from "wagmi";
|
|
20395
20800
|
function useTransactions() {
|
|
20396
20801
|
const chainId = requireActiveChainId();
|
|
20397
20802
|
const viemChain = getViemChain4(chainId);
|
|
20398
20803
|
const publicClient = usePublicClient({ chainId });
|
|
20399
20804
|
const { data: walletClient } = useWalletClient();
|
|
20400
|
-
const { address } =
|
|
20805
|
+
const { address } = useAccount3();
|
|
20401
20806
|
const sendTransaction = async (params) => {
|
|
20402
20807
|
if (!walletClient) {
|
|
20403
20808
|
throw new Error("Wallet not connected");
|
|
20404
20809
|
}
|
|
20405
20810
|
const txParams = {
|
|
20406
20811
|
to: params.to,
|
|
20407
|
-
value:
|
|
20812
|
+
value: parseEther6(params.value),
|
|
20408
20813
|
data: params.data,
|
|
20409
20814
|
chain: viemChain
|
|
20410
20815
|
};
|
|
@@ -20721,6 +21126,10 @@ var init_index = __esm({
|
|
|
20721
21126
|
init_useSendTransaction();
|
|
20722
21127
|
init_useUserOpStatus();
|
|
20723
21128
|
init_useErc3643Compliance();
|
|
21129
|
+
init_useWalletMode();
|
|
21130
|
+
init_useDirectWallet();
|
|
21131
|
+
init_useSendDirectTransaction();
|
|
21132
|
+
init_useTransferToLinkedWallet();
|
|
20724
21133
|
init_useLogout();
|
|
20725
21134
|
init_useNicknameResolve();
|
|
20726
21135
|
init_account();
|
|
@@ -20786,6 +21195,7 @@ export {
|
|
|
20786
21195
|
useAssets,
|
|
20787
21196
|
useBalance,
|
|
20788
21197
|
useColorMode,
|
|
21198
|
+
useDirectWallet,
|
|
20789
21199
|
useErc3643Compliance,
|
|
20790
21200
|
useError,
|
|
20791
21201
|
useHasServerVault,
|
|
@@ -20799,13 +21209,16 @@ export {
|
|
|
20799
21209
|
useOpenPage,
|
|
20800
21210
|
useProviderConfig,
|
|
20801
21211
|
useRecoveryUserId,
|
|
21212
|
+
useSendDirectTransaction,
|
|
20802
21213
|
useSendTransaction,
|
|
20803
21214
|
useSession,
|
|
20804
21215
|
useSmartAccountTransactions,
|
|
20805
21216
|
useTokenBalance,
|
|
20806
21217
|
useTokenInfo,
|
|
20807
21218
|
useTransactions,
|
|
21219
|
+
useTransferToLinkedWallet,
|
|
20808
21220
|
useUserOpStatus,
|
|
21221
|
+
useWalletMode,
|
|
20809
21222
|
verifyFingerprint,
|
|
20810
21223
|
verifyFingerprintDetailed,
|
|
20811
21224
|
wagmiConfig,
|