@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.cjs
CHANGED
|
@@ -160,7 +160,9 @@ var init_initial = __esm({
|
|
|
160
160
|
enabled: false,
|
|
161
161
|
supportedChains: [1, 137, 56],
|
|
162
162
|
requireSignature: true,
|
|
163
|
-
walletConnectProjectId: void 0
|
|
163
|
+
walletConnectProjectId: void 0,
|
|
164
|
+
mode: "linked",
|
|
165
|
+
allowedWallets: void 0
|
|
164
166
|
},
|
|
165
167
|
// preferedColorMode: 'light', // undefined means 'auto'
|
|
166
168
|
ui: {
|
|
@@ -15542,7 +15544,7 @@ var init_package = __esm({
|
|
|
15542
15544
|
"package.json"() {
|
|
15543
15545
|
package_default = {
|
|
15544
15546
|
name: "@embarkai/ui-kit",
|
|
15545
|
-
version: "0.
|
|
15547
|
+
version: "0.2.0",
|
|
15546
15548
|
description: "React UI components and hooks for EmbarkAI authentication and Account Abstraction",
|
|
15547
15549
|
type: "module",
|
|
15548
15550
|
main: "./dist/index.cjs",
|
|
@@ -16252,21 +16254,71 @@ async function unlinkWallet(address) {
|
|
|
16252
16254
|
throw new Error(errorData.message || `Failed to unlink wallet: ${response.statusText}`);
|
|
16253
16255
|
}
|
|
16254
16256
|
}
|
|
16255
|
-
function
|
|
16257
|
+
async function fetchProjectName(projectId) {
|
|
16258
|
+
const now = Date.now();
|
|
16259
|
+
if (metadataCache && now - metadataCache.timestamp < METADATA_CACHE_TTL) {
|
|
16260
|
+
return metadataCache.data.name;
|
|
16261
|
+
}
|
|
16262
|
+
try {
|
|
16263
|
+
const response = await fetch(`${METADATA_API_URL}/${projectId}/metadata`);
|
|
16264
|
+
if (!response.ok) return "EmbarkAI";
|
|
16265
|
+
const metadata = await response.json();
|
|
16266
|
+
metadataCache = { data: metadata, timestamp: now };
|
|
16267
|
+
return metadata.name;
|
|
16268
|
+
} catch {
|
|
16269
|
+
return "EmbarkAI";
|
|
16270
|
+
}
|
|
16271
|
+
}
|
|
16272
|
+
function createSignatureMessage(address, projectName, nonce) {
|
|
16256
16273
|
const timestamp = Date.now();
|
|
16257
16274
|
const nonceValue = nonce || Math.random().toString(36).substring(2, 15);
|
|
16258
|
-
return
|
|
16275
|
+
return `${projectName} Wallet Link
|
|
16259
16276
|
|
|
16260
16277
|
Address: ${address}
|
|
16261
16278
|
Nonce: ${nonceValue}
|
|
16262
16279
|
Timestamp: ${timestamp}
|
|
16263
16280
|
|
|
16264
|
-
Sign this message to link your wallet to
|
|
16281
|
+
Sign this message to link your wallet to ${projectName} Wallet`;
|
|
16265
16282
|
}
|
|
16283
|
+
var METADATA_API_URL, METADATA_CACHE_TTL, metadataCache;
|
|
16266
16284
|
var init_wallet = __esm({
|
|
16267
16285
|
"src/internal/auth/providers/wallet.ts"() {
|
|
16268
16286
|
init_auth();
|
|
16269
16287
|
init_types();
|
|
16288
|
+
METADATA_API_URL = "https://dashboard.lumiapassport.com/api/public/project";
|
|
16289
|
+
METADATA_CACHE_TTL = 36e5;
|
|
16290
|
+
metadataCache = null;
|
|
16291
|
+
}
|
|
16292
|
+
});
|
|
16293
|
+
|
|
16294
|
+
// src/internal/stores/useExternalWalletStore.ts
|
|
16295
|
+
var import_zustand7, useExternalWalletStore;
|
|
16296
|
+
var init_useExternalWalletStore = __esm({
|
|
16297
|
+
"src/internal/stores/useExternalWalletStore.ts"() {
|
|
16298
|
+
import_zustand7 = require("zustand");
|
|
16299
|
+
useExternalWalletStore = (0, import_zustand7.create)((set) => ({
|
|
16300
|
+
configMode: "linked",
|
|
16301
|
+
activeMode: "linked",
|
|
16302
|
+
externalAddress: null,
|
|
16303
|
+
externalChainId: null,
|
|
16304
|
+
isExternalConnected: false,
|
|
16305
|
+
connectorName: null,
|
|
16306
|
+
setConfigMode: (mode) => set({ configMode: mode }),
|
|
16307
|
+
setActiveMode: (mode) => set({ activeMode: mode }),
|
|
16308
|
+
setExternalWallet: ({ address, chainId, connectorName }) => set({
|
|
16309
|
+
externalAddress: address,
|
|
16310
|
+
externalChainId: chainId,
|
|
16311
|
+
isExternalConnected: true,
|
|
16312
|
+
connectorName
|
|
16313
|
+
}),
|
|
16314
|
+
clearExternalWallet: () => set({
|
|
16315
|
+
externalAddress: null,
|
|
16316
|
+
externalChainId: null,
|
|
16317
|
+
isExternalConnected: false,
|
|
16318
|
+
connectorName: null
|
|
16319
|
+
}),
|
|
16320
|
+
setExternalChainId: (chainId) => set({ externalChainId: chainId })
|
|
16321
|
+
}));
|
|
16270
16322
|
}
|
|
16271
16323
|
});
|
|
16272
16324
|
|
|
@@ -16286,6 +16338,10 @@ function WalletConnectHandler() {
|
|
|
16286
16338
|
const setManageWalletLinkError = useManageWalletStore((st) => st.setLinkError);
|
|
16287
16339
|
const setLinkIsLoading = useManageWalletStore((st) => st.setLinkIsLoading);
|
|
16288
16340
|
const setProviderType = useManageWalletStore((st) => st.setProviderType);
|
|
16341
|
+
const providerConfig = useProviderConfig().config.current;
|
|
16342
|
+
const walletMode = providerConfig?.wallet?.mode || "linked";
|
|
16343
|
+
const projectId = providerConfig?.projectId;
|
|
16344
|
+
const setExternalWallet = useExternalWalletStore((st) => st.setExternalWallet);
|
|
16289
16345
|
const onLinkingComplete = (0, import_react63.useCallback)(
|
|
16290
16346
|
async (success) => {
|
|
16291
16347
|
setIsWalletLinking(false);
|
|
@@ -16316,24 +16372,42 @@ function WalletConnectHandler() {
|
|
|
16316
16372
|
const [hasStartedLinking, setHasStartedLinking] = import_react63.default.useState(false);
|
|
16317
16373
|
(0, import_react63.useEffect)(() => {
|
|
16318
16374
|
if (isWalletLinking && !hasStartedLinking) {
|
|
16375
|
+
console.log("[WalletConnectHandler] Starting wallet link flow:", {
|
|
16376
|
+
isConnected,
|
|
16377
|
+
openConnectModal: typeof openConnectModal,
|
|
16378
|
+
walletMode
|
|
16379
|
+
});
|
|
16319
16380
|
setHasStartedLinking(true);
|
|
16320
16381
|
setProviderType(null);
|
|
16321
16382
|
if (isConnected) {
|
|
16322
16383
|
disconnect();
|
|
16323
16384
|
setTimeout(() => {
|
|
16324
16385
|
setPage(null);
|
|
16325
|
-
openConnectModal
|
|
16386
|
+
if (openConnectModal) {
|
|
16387
|
+
openConnectModal();
|
|
16388
|
+
} else {
|
|
16389
|
+
console.error("[WalletConnectHandler] openConnectModal is undefined!");
|
|
16390
|
+
setIsWalletLinking(false);
|
|
16391
|
+
setHasStartedLinking(false);
|
|
16392
|
+
}
|
|
16326
16393
|
}, 500);
|
|
16327
16394
|
} else {
|
|
16328
16395
|
setPage(null);
|
|
16329
|
-
openConnectModal
|
|
16396
|
+
if (openConnectModal) {
|
|
16397
|
+
openConnectModal();
|
|
16398
|
+
} else {
|
|
16399
|
+
console.error("[WalletConnectHandler] openConnectModal is undefined!");
|
|
16400
|
+
setIsWalletLinking(false);
|
|
16401
|
+
setHasStartedLinking(false);
|
|
16402
|
+
}
|
|
16330
16403
|
}
|
|
16331
16404
|
}
|
|
16332
16405
|
if (!isWalletLinking && hasStartedLinking) {
|
|
16333
16406
|
setHasStartedLinking(false);
|
|
16334
|
-
|
|
16407
|
+
const shouldKeepConnected = walletMode === "direct" || walletMode === "both";
|
|
16408
|
+
if (isConnected && !shouldKeepConnected) disconnect();
|
|
16335
16409
|
}
|
|
16336
|
-
}, [isWalletLinking, hasStartedLinking, isConnected, openConnectModal, disconnect, setPage, setProviderType]);
|
|
16410
|
+
}, [isWalletLinking, hasStartedLinking, isConnected, openConnectModal, disconnect, setPage, setProviderType, walletMode]);
|
|
16337
16411
|
(0, import_react63.useEffect)(() => {
|
|
16338
16412
|
if (hasStartedLinking && !connectModalOpen && !isConnected && isWalletLinking) {
|
|
16339
16413
|
console.log("[WalletConnectHandler] Modal closed without connecting");
|
|
@@ -16341,6 +16415,16 @@ function WalletConnectHandler() {
|
|
|
16341
16415
|
setHasStartedLinking(false);
|
|
16342
16416
|
}
|
|
16343
16417
|
}, [connectModalOpen, hasStartedLinking, isConnected, isWalletLinking]);
|
|
16418
|
+
(0, import_react63.useEffect)(() => {
|
|
16419
|
+
if (isWalletLinking) {
|
|
16420
|
+
const timeout = setTimeout(() => {
|
|
16421
|
+
console.warn("[WalletConnectHandler] Wallet linking timed out, resetting state");
|
|
16422
|
+
setIsWalletLinking(false);
|
|
16423
|
+
setHasStartedLinking(false);
|
|
16424
|
+
}, 12e4);
|
|
16425
|
+
return () => clearTimeout(timeout);
|
|
16426
|
+
}
|
|
16427
|
+
}, [isWalletLinking, setIsWalletLinking]);
|
|
16344
16428
|
const { mutate: handleWalletSign, isPending: isWalletSigning } = (0, import_react_query41.useMutation)({
|
|
16345
16429
|
mutationFn: async (payload) => {
|
|
16346
16430
|
const { chainId, signingWalletAddress } = payload;
|
|
@@ -16358,7 +16442,8 @@ function WalletConnectHandler() {
|
|
|
16358
16442
|
return;
|
|
16359
16443
|
}
|
|
16360
16444
|
setLinkIsLoading(true);
|
|
16361
|
-
const
|
|
16445
|
+
const projectName = projectId ? await fetchProjectName(projectId) : "EmbarkAI";
|
|
16446
|
+
const message = createSignatureMessage(signingWalletAddress, projectName);
|
|
16362
16447
|
const signature = await signMessageAsync({ message, account: signingWalletAddress });
|
|
16363
16448
|
if (!signature) {
|
|
16364
16449
|
throw new Error("Failed to get signature");
|
|
@@ -16376,7 +16461,16 @@ function WalletConnectHandler() {
|
|
|
16376
16461
|
});
|
|
16377
16462
|
},
|
|
16378
16463
|
onSuccess: () => {
|
|
16379
|
-
|
|
16464
|
+
const shouldKeepConnected = walletMode === "direct" || walletMode === "both";
|
|
16465
|
+
if (shouldKeepConnected && walletAddress && chain?.id && connector) {
|
|
16466
|
+
setExternalWallet({
|
|
16467
|
+
address: walletAddress,
|
|
16468
|
+
chainId: chain.id,
|
|
16469
|
+
connectorName: connector.name || "Unknown Wallet"
|
|
16470
|
+
});
|
|
16471
|
+
} else {
|
|
16472
|
+
disconnect();
|
|
16473
|
+
}
|
|
16380
16474
|
setHasStartedLinking(false);
|
|
16381
16475
|
onLinkingComplete(true);
|
|
16382
16476
|
setLinkIsLoading(false);
|
|
@@ -16416,6 +16510,17 @@ function WalletConnectHandler() {
|
|
|
16416
16510
|
handleWalletSign({ chainId: chain.id, signingWalletAddress: walletAddress });
|
|
16417
16511
|
}
|
|
16418
16512
|
}, [chain, isConnected, walletAddress, isWalletLinking, hasStartedLinking]);
|
|
16513
|
+
(0, import_react63.useEffect)(() => {
|
|
16514
|
+
if (isConnected && !chain?.id && isWalletLinking && hasStartedLinking && !connectModalOpen && !isWalletSigning) {
|
|
16515
|
+
const timeout = setTimeout(() => {
|
|
16516
|
+
console.warn("[WalletConnectHandler] Wallet connected but chain info missing, resetting");
|
|
16517
|
+
onLinkingComplete(false);
|
|
16518
|
+
setHasStartedLinking(false);
|
|
16519
|
+
disconnect();
|
|
16520
|
+
}, 5e3);
|
|
16521
|
+
return () => clearTimeout(timeout);
|
|
16522
|
+
}
|
|
16523
|
+
}, [isConnected, chain?.id, isWalletLinking, hasStartedLinking, connectModalOpen, isWalletSigning, onLinkingComplete, disconnect]);
|
|
16419
16524
|
return null;
|
|
16420
16525
|
}
|
|
16421
16526
|
var import_rainbowkit, import_react_query41, import_react63, import_wagmi2;
|
|
@@ -16431,10 +16536,68 @@ var init_WalletConnectHandler = __esm({
|
|
|
16431
16536
|
init_wallet();
|
|
16432
16537
|
init_AuthMenu2();
|
|
16433
16538
|
init_useLayoutDataStore();
|
|
16539
|
+
init_useExternalWalletStore();
|
|
16434
16540
|
init_ManageWalletMenu();
|
|
16435
16541
|
}
|
|
16436
16542
|
});
|
|
16437
16543
|
|
|
16544
|
+
// src/internal/components/DirectWalletHandler.tsx
|
|
16545
|
+
function DirectWalletHandler() {
|
|
16546
|
+
const walletMode = useProviderConfig().config.current?.wallet?.mode || "linked";
|
|
16547
|
+
const { address, isConnected, chain, connector } = (0, import_wagmi3.useAccount)();
|
|
16548
|
+
const isExternalConnected = useExternalWalletStore((st) => st.isExternalConnected);
|
|
16549
|
+
const externalAddress = useExternalWalletStore((st) => st.externalAddress);
|
|
16550
|
+
const setExternalWallet = useExternalWalletStore((st) => st.setExternalWallet);
|
|
16551
|
+
const clearExternalWallet = useExternalWalletStore((st) => st.clearExternalWallet);
|
|
16552
|
+
const setExternalChainId = useExternalWalletStore((st) => st.setExternalChainId);
|
|
16553
|
+
const setConfigMode = useExternalWalletStore((st) => st.setConfigMode);
|
|
16554
|
+
const setActiveMode = useExternalWalletStore((st) => st.setActiveMode);
|
|
16555
|
+
(0, import_react64.useEffect)(() => {
|
|
16556
|
+
setConfigMode(walletMode);
|
|
16557
|
+
if (walletMode !== "both") {
|
|
16558
|
+
setActiveMode(walletMode);
|
|
16559
|
+
}
|
|
16560
|
+
}, [walletMode, setConfigMode, setActiveMode]);
|
|
16561
|
+
(0, import_react64.useEffect)(() => {
|
|
16562
|
+
if (isConnected && address && !isExternalConnected && connector) {
|
|
16563
|
+
setExternalWallet({
|
|
16564
|
+
address,
|
|
16565
|
+
chainId: chain?.id || 1,
|
|
16566
|
+
connectorName: connector.name || "Unknown Wallet"
|
|
16567
|
+
});
|
|
16568
|
+
}
|
|
16569
|
+
}, [isConnected, address, isExternalConnected, connector, chain?.id, setExternalWallet]);
|
|
16570
|
+
(0, import_react64.useEffect)(() => {
|
|
16571
|
+
if (isExternalConnected && !isConnected) {
|
|
16572
|
+
clearExternalWallet();
|
|
16573
|
+
}
|
|
16574
|
+
}, [isConnected, isExternalConnected, clearExternalWallet]);
|
|
16575
|
+
(0, import_react64.useEffect)(() => {
|
|
16576
|
+
if (isExternalConnected && isConnected && chain?.id) {
|
|
16577
|
+
setExternalChainId(chain.id);
|
|
16578
|
+
}
|
|
16579
|
+
}, [chain?.id, isConnected, isExternalConnected, setExternalChainId]);
|
|
16580
|
+
(0, import_react64.useEffect)(() => {
|
|
16581
|
+
if (isExternalConnected && isConnected && address && address !== externalAddress && connector) {
|
|
16582
|
+
setExternalWallet({
|
|
16583
|
+
address,
|
|
16584
|
+
chainId: chain?.id || 1,
|
|
16585
|
+
connectorName: connector.name || "Unknown Wallet"
|
|
16586
|
+
});
|
|
16587
|
+
}
|
|
16588
|
+
}, [address, isConnected, isExternalConnected, externalAddress, chain?.id, connector, setExternalWallet]);
|
|
16589
|
+
return null;
|
|
16590
|
+
}
|
|
16591
|
+
var import_react64, import_wagmi3;
|
|
16592
|
+
var init_DirectWalletHandler = __esm({
|
|
16593
|
+
"src/internal/components/DirectWalletHandler.tsx"() {
|
|
16594
|
+
import_react64 = require("react");
|
|
16595
|
+
import_wagmi3 = require("wagmi");
|
|
16596
|
+
init_ProviderContext();
|
|
16597
|
+
init_useExternalWalletStore();
|
|
16598
|
+
}
|
|
16599
|
+
});
|
|
16600
|
+
|
|
16438
16601
|
// src/context/SessionContext.tsx
|
|
16439
16602
|
function getChainParams(chainCfg) {
|
|
16440
16603
|
return {
|
|
@@ -16453,9 +16616,10 @@ function waitForStoreHydration() {
|
|
|
16453
16616
|
}
|
|
16454
16617
|
function SessionProvider({ children }) {
|
|
16455
16618
|
const config = useProviderConfig().config;
|
|
16456
|
-
return /* @__PURE__ */ (0, import_jsx_runtime93.jsxs)(
|
|
16619
|
+
return /* @__PURE__ */ (0, import_jsx_runtime93.jsxs)(import_react65.Fragment, { children: [
|
|
16457
16620
|
children,
|
|
16458
16621
|
config.current?.wallet?.enabled && /* @__PURE__ */ (0, import_jsx_runtime93.jsx)(WalletConnectHandler, {}),
|
|
16622
|
+
config.current?.wallet?.enabled && (config.current?.wallet?.mode === "direct" || config.current?.wallet?.mode === "both") && /* @__PURE__ */ (0, import_jsx_runtime93.jsx)(DirectWalletHandler, {}),
|
|
16459
16623
|
/* @__PURE__ */ (0, import_jsx_runtime93.jsx)(BalanceFeedProvider, {}),
|
|
16460
16624
|
/* @__PURE__ */ (0, import_jsx_runtime93.jsx)(ChainSync, {}),
|
|
16461
16625
|
/* @__PURE__ */ (0, import_jsx_runtime93.jsx)(
|
|
@@ -16467,21 +16631,22 @@ function SessionProvider({ children }) {
|
|
|
16467
16631
|
/* @__PURE__ */ (0, import_jsx_runtime93.jsx)(Dialog2, {})
|
|
16468
16632
|
] });
|
|
16469
16633
|
}
|
|
16470
|
-
var import_read11,
|
|
16634
|
+
var import_read11, import_react65, import_zustand8, import_middleware, import_jsx_runtime93, useSession, requireActiveChainId;
|
|
16471
16635
|
var init_SessionContext = __esm({
|
|
16472
16636
|
"src/context/SessionContext.tsx"() {
|
|
16473
16637
|
import_read11 = require("@embarkai/core/read");
|
|
16474
|
-
|
|
16475
|
-
|
|
16638
|
+
import_react65 = require("react");
|
|
16639
|
+
import_zustand8 = require("zustand");
|
|
16476
16640
|
import_middleware = require("zustand/middleware");
|
|
16477
16641
|
init_BalanceFeedProvider2();
|
|
16478
16642
|
init_ChainSync2();
|
|
16479
16643
|
init_Dialog2();
|
|
16480
16644
|
init_TssManager();
|
|
16481
16645
|
init_WalletConnectHandler();
|
|
16646
|
+
init_DirectWalletHandler();
|
|
16482
16647
|
init_ProviderContext();
|
|
16483
16648
|
import_jsx_runtime93 = require("react/jsx-runtime");
|
|
16484
|
-
useSession = (0,
|
|
16649
|
+
useSession = (0, import_zustand8.create)()(
|
|
16485
16650
|
(0, import_middleware.persist)(
|
|
16486
16651
|
(set) => ({
|
|
16487
16652
|
isLoading: false,
|
|
@@ -17535,6 +17700,7 @@ __export(auth_exports, {
|
|
|
17535
17700
|
deriveDemoPrivateKey: () => deriveDemoPrivateKey,
|
|
17536
17701
|
ensureKeyshare: () => ensureKeyshare,
|
|
17537
17702
|
ensureValidToken: () => import_auth18.ensureValidToken,
|
|
17703
|
+
fetchProjectName: () => fetchProjectName,
|
|
17538
17704
|
formatDate: () => formatDate,
|
|
17539
17705
|
getKeyshareInfo: () => getKeyshareInfo,
|
|
17540
17706
|
getLinkedProviders: () => getLinkedProviders,
|
|
@@ -18801,29 +18967,42 @@ var init_iframe_manager = __esm({
|
|
|
18801
18967
|
});
|
|
18802
18968
|
|
|
18803
18969
|
// src/config/rainbowkit.ts
|
|
18804
|
-
var import_read13, import_rainbowkit2, import_chains, getProjectId, createRainbowConfig, rainbowConfig, rainbowTheme;
|
|
18970
|
+
var import_read13, import_rainbowkit2, import_wallets, import_chains, getProjectId, WALLET_MAP, createRainbowConfig, rainbowConfig, rainbowTheme;
|
|
18805
18971
|
var init_rainbowkit = __esm({
|
|
18806
18972
|
"src/config/rainbowkit.ts"() {
|
|
18807
18973
|
import_read13 = require("@embarkai/core/read");
|
|
18808
18974
|
import_rainbowkit2 = require("@rainbow-me/rainbowkit");
|
|
18975
|
+
import_wallets = require("@rainbow-me/rainbowkit/wallets");
|
|
18809
18976
|
import_chains = require("wagmi/chains");
|
|
18810
18977
|
getProjectId = (configProjectId) => {
|
|
18811
|
-
if (configProjectId)
|
|
18812
|
-
return configProjectId;
|
|
18813
|
-
}
|
|
18978
|
+
if (configProjectId) return configProjectId;
|
|
18814
18979
|
if (typeof window !== "undefined") {
|
|
18815
18980
|
return window.NEXT_PUBLIC_WALLET_CONNECT_PROJECT_ID || window.VITE_WALLET_CONNECT_PROJECT_ID || window.__WALLET_CONNECT_PROJECT_ID__ || "YOUR_PROJECT_ID";
|
|
18816
18981
|
}
|
|
18817
18982
|
return "YOUR_PROJECT_ID";
|
|
18818
18983
|
};
|
|
18819
|
-
|
|
18820
|
-
|
|
18984
|
+
WALLET_MAP = {
|
|
18985
|
+
walletconnect: import_wallets.walletConnectWallet,
|
|
18986
|
+
metamask: import_wallets.metaMaskWallet,
|
|
18987
|
+
coinbase: import_wallets.coinbaseWallet,
|
|
18988
|
+
rainbow: import_wallets.rainbowWallet
|
|
18989
|
+
};
|
|
18990
|
+
createRainbowConfig = (options) => {
|
|
18991
|
+
const opts = typeof options === "string" ? { projectId: options } : options || {};
|
|
18992
|
+
const config = {
|
|
18821
18993
|
appName: "Mbark Wallet",
|
|
18822
|
-
projectId: getProjectId(projectId),
|
|
18994
|
+
projectId: getProjectId(opts.projectId),
|
|
18823
18995
|
chains: [import_read13.lumiaMainnetChain, import_read13.lumiaTestnetChain, import_chains.mainnet, import_chains.polygon, import_chains.bsc, import_chains.arbitrum, import_chains.optimism, import_chains.avalanche, import_chains.base, import_chains.zora],
|
|
18824
18996
|
ssr: false
|
|
18825
|
-
|
|
18826
|
-
|
|
18997
|
+
};
|
|
18998
|
+
if (opts.allowedWallets && opts.allowedWallets.length > 0) {
|
|
18999
|
+
const wallets = opts.allowedWallets.map((id) => WALLET_MAP[id.toLowerCase()]).filter(Boolean);
|
|
19000
|
+
if (!opts.allowedWallets.some((id) => id.toLowerCase() === "walletconnect")) {
|
|
19001
|
+
wallets.push(import_wallets.walletConnectWallet);
|
|
19002
|
+
}
|
|
19003
|
+
config.wallets = [{ groupName: "Supported", wallets }];
|
|
19004
|
+
}
|
|
19005
|
+
return (0, import_rainbowkit2.getDefaultConfig)(config);
|
|
18827
19006
|
};
|
|
18828
19007
|
rainbowConfig = createRainbowConfig();
|
|
18829
19008
|
rainbowTheme = {
|
|
@@ -19021,8 +19200,14 @@ var init_rainbowkit = __esm({
|
|
|
19021
19200
|
function RainbowKitProvider({ children }) {
|
|
19022
19201
|
const config = useProviderConfig().config;
|
|
19023
19202
|
const colorMode = useLayoutStore((st) => st.colorMode);
|
|
19024
|
-
const rainbowConfig2 = (0,
|
|
19025
|
-
|
|
19203
|
+
const rainbowConfig2 = (0, import_react66.useMemo)(
|
|
19204
|
+
() => createRainbowConfig({
|
|
19205
|
+
projectId: config.current?.wallet?.walletConnectProjectId,
|
|
19206
|
+
allowedWallets: config.current?.wallet?.allowedWallets
|
|
19207
|
+
}),
|
|
19208
|
+
[]
|
|
19209
|
+
);
|
|
19210
|
+
const customTheme = (0, import_react66.useMemo)(() => {
|
|
19026
19211
|
if (!config.current?.wallet?.enabled) return {};
|
|
19027
19212
|
return colorMode === "dark" ? {
|
|
19028
19213
|
...(0, import_rainbowkit3.darkTheme)(),
|
|
@@ -19037,14 +19222,14 @@ function RainbowKitProvider({ children }) {
|
|
|
19037
19222
|
};
|
|
19038
19223
|
}, [colorMode]);
|
|
19039
19224
|
if (!config.current?.wallet?.enabled) return /* @__PURE__ */ (0, import_jsx_runtime94.jsx)(import_jsx_runtime94.Fragment, { children });
|
|
19040
|
-
return /* @__PURE__ */ (0, import_jsx_runtime94.jsx)(
|
|
19225
|
+
return /* @__PURE__ */ (0, import_jsx_runtime94.jsx)(import_wagmi4.WagmiProvider, { config: rainbowConfig2, children: /* @__PURE__ */ (0, import_jsx_runtime94.jsx)(import_rainbowkit3.RainbowKitProvider, { theme: customTheme, modalSize: "compact", showRecentTransactions: true, children }) });
|
|
19041
19226
|
}
|
|
19042
|
-
var import_rainbowkit3,
|
|
19227
|
+
var import_rainbowkit3, import_react66, import_wagmi4, import_styles, import_jsx_runtime94;
|
|
19043
19228
|
var init_RainbowKitContext = __esm({
|
|
19044
19229
|
"src/context/RainbowKitContext.tsx"() {
|
|
19045
19230
|
import_rainbowkit3 = require("@rainbow-me/rainbowkit");
|
|
19046
|
-
|
|
19047
|
-
|
|
19231
|
+
import_react66 = require("react");
|
|
19232
|
+
import_wagmi4 = require("wagmi");
|
|
19048
19233
|
init_rainbowkit();
|
|
19049
19234
|
init_useLayoutStore();
|
|
19050
19235
|
init_ProviderContext();
|
|
@@ -19071,7 +19256,7 @@ var init_utils8 = __esm({
|
|
|
19071
19256
|
// src/config/wagmi.ts
|
|
19072
19257
|
function buildTransport(urls) {
|
|
19073
19258
|
const transports = urls.map(
|
|
19074
|
-
(url) => (0,
|
|
19259
|
+
(url) => (0, import_wagmi5.http)(url, {
|
|
19075
19260
|
timeout: 1e4,
|
|
19076
19261
|
retryCount: 0,
|
|
19077
19262
|
batch: false,
|
|
@@ -19087,13 +19272,13 @@ function buildTransport(urls) {
|
|
|
19087
19272
|
retryCount: 0
|
|
19088
19273
|
});
|
|
19089
19274
|
}
|
|
19090
|
-
var import_read14, import_viem17,
|
|
19275
|
+
var import_read14, import_viem17, import_wagmi5, wagmiConfig;
|
|
19091
19276
|
var init_wagmi = __esm({
|
|
19092
19277
|
"src/config/wagmi.ts"() {
|
|
19093
19278
|
import_read14 = require("@embarkai/core/read");
|
|
19094
19279
|
import_viem17 = require("viem");
|
|
19095
|
-
|
|
19096
|
-
wagmiConfig = (0,
|
|
19280
|
+
import_wagmi5 = require("wagmi");
|
|
19281
|
+
wagmiConfig = (0, import_wagmi5.createConfig)({
|
|
19097
19282
|
chains: [import_read14.lumiaMainnetChain, import_read14.lumiaTestnetChain],
|
|
19098
19283
|
transports: {
|
|
19099
19284
|
[import_read14.lumiaTestnetChain.id]: buildTransport(import_read14.lumiaTestnetChain.rpcUrls.default.http),
|
|
@@ -19104,14 +19289,14 @@ var init_wagmi = __esm({
|
|
|
19104
19289
|
});
|
|
19105
19290
|
|
|
19106
19291
|
// src/context/WagmiContext.tsx
|
|
19107
|
-
var
|
|
19292
|
+
var import_wagmi6, import_jsx_runtime95, WagmiProvider2;
|
|
19108
19293
|
var init_WagmiContext = __esm({
|
|
19109
19294
|
"src/context/WagmiContext.tsx"() {
|
|
19110
|
-
|
|
19295
|
+
import_wagmi6 = require("wagmi");
|
|
19111
19296
|
init_wagmi();
|
|
19112
19297
|
import_jsx_runtime95 = require("react/jsx-runtime");
|
|
19113
19298
|
WagmiProvider2 = ({ children }) => {
|
|
19114
|
-
return /* @__PURE__ */ (0, import_jsx_runtime95.jsx)(
|
|
19299
|
+
return /* @__PURE__ */ (0, import_jsx_runtime95.jsx)(import_wagmi6.WagmiProvider, { config: wagmiConfig, children });
|
|
19115
19300
|
};
|
|
19116
19301
|
}
|
|
19117
19302
|
});
|
|
@@ -19119,13 +19304,13 @@ var init_WagmiContext = __esm({
|
|
|
19119
19304
|
// src/context/ProviderContext.tsx
|
|
19120
19305
|
function Provider(props) {
|
|
19121
19306
|
const { children, projectId, initialConfig = {}, callbacks } = props;
|
|
19122
|
-
const callbacksRef = (0,
|
|
19123
|
-
(0,
|
|
19307
|
+
const callbacksRef = (0, import_react67.useRef)(callbacks);
|
|
19308
|
+
(0, import_react67.useEffect)(() => {
|
|
19124
19309
|
callbacksRef.current = callbacks;
|
|
19125
19310
|
}, [callbacks]);
|
|
19126
|
-
(0,
|
|
19127
|
-
const config = (0,
|
|
19128
|
-
const updateConfig = (0,
|
|
19311
|
+
(0, import_react67.useEffect)(() => notifyNoProjetctId(projectId), [projectId]);
|
|
19312
|
+
const config = (0, import_react67.useRef)((0, import_lodash_es6.merge)({}, DEFAULT_PROVIDER_CONFIG, { projectId }, initialConfig));
|
|
19313
|
+
const updateConfig = (0, import_react67.useCallback)((updates) => {
|
|
19129
19314
|
const prev = config.current;
|
|
19130
19315
|
const next = { ...prev };
|
|
19131
19316
|
if (updates.projectId !== void 0) next.projectId = updates.projectId;
|
|
@@ -19158,7 +19343,7 @@ function Provider(props) {
|
|
|
19158
19343
|
if (updates.translations) next.translations = { ...next.translations, ...updates.translations };
|
|
19159
19344
|
config.current = next;
|
|
19160
19345
|
}, []);
|
|
19161
|
-
(0,
|
|
19346
|
+
(0, import_react67.useEffect)(() => {
|
|
19162
19347
|
if (typeof window === "undefined" || !projectId) return;
|
|
19163
19348
|
const mergedConfig = (0, import_lodash_es6.merge)(DEFAULT_PROVIDER_CONFIG, initialConfig);
|
|
19164
19349
|
updateConfig(mergedConfig);
|
|
@@ -19176,7 +19361,7 @@ function Provider(props) {
|
|
|
19176
19361
|
useSession.getState().setActiveChainId(mergedConfig.network.chainId);
|
|
19177
19362
|
}
|
|
19178
19363
|
}, [projectId, initialConfig]);
|
|
19179
|
-
(0,
|
|
19364
|
+
(0, import_react67.useEffect)(() => {
|
|
19180
19365
|
if (typeof window === "undefined" || !projectId) return;
|
|
19181
19366
|
try {
|
|
19182
19367
|
(0, import_error_tracking4.initSdkErrorTracking)();
|
|
@@ -19205,17 +19390,17 @@ function Provider(props) {
|
|
|
19205
19390
|
console.error("[PROVIDER] Error setting up iframe manager:", error);
|
|
19206
19391
|
}
|
|
19207
19392
|
}, [projectId]);
|
|
19208
|
-
const contextValue = (0,
|
|
19393
|
+
const contextValue = (0, import_react67.useMemo)(() => ({ config, updateConfig, callbacks }), [config, updateConfig, callbacks]);
|
|
19209
19394
|
if (!!initialConfig?.wallet?.enabled)
|
|
19210
19395
|
return /* @__PURE__ */ (0, import_jsx_runtime96.jsx)(WagmiProvider2, { children: /* @__PURE__ */ (0, import_jsx_runtime96.jsx)(UIContext.Provider, { value: contextValue, children: /* @__PURE__ */ (0, import_jsx_runtime96.jsx)(RainbowKitProvider, { children: /* @__PURE__ */ (0, import_jsx_runtime96.jsx)(SessionProvider, { children }) }) }) });
|
|
19211
19396
|
return /* @__PURE__ */ (0, import_jsx_runtime96.jsx)(WagmiProvider2, { children: /* @__PURE__ */ (0, import_jsx_runtime96.jsx)(UIContext.Provider, { value: contextValue, children: /* @__PURE__ */ (0, import_jsx_runtime96.jsx)(SessionProvider, { children }) }) });
|
|
19212
19397
|
}
|
|
19213
|
-
var import_error_tracking4, import_lodash_es6,
|
|
19398
|
+
var import_error_tracking4, import_lodash_es6, import_react67, import_jsx_runtime96, UIContext, useProviderConfig;
|
|
19214
19399
|
var init_ProviderContext = __esm({
|
|
19215
19400
|
"src/context/ProviderContext.tsx"() {
|
|
19216
19401
|
import_error_tracking4 = require("@embarkai/core/internal/error-tracking");
|
|
19217
19402
|
import_lodash_es6 = require("lodash-es");
|
|
19218
|
-
|
|
19403
|
+
import_react67 = require("react");
|
|
19219
19404
|
init_initial();
|
|
19220
19405
|
init_iframe_manager();
|
|
19221
19406
|
init_RainbowKitContext();
|
|
@@ -19223,9 +19408,9 @@ var init_ProviderContext = __esm({
|
|
|
19223
19408
|
init_utils8();
|
|
19224
19409
|
init_WagmiContext();
|
|
19225
19410
|
import_jsx_runtime96 = require("react/jsx-runtime");
|
|
19226
|
-
UIContext = (0,
|
|
19411
|
+
UIContext = (0, import_react67.createContext)(void 0);
|
|
19227
19412
|
useProviderConfig = () => {
|
|
19228
|
-
const ctx = (0,
|
|
19413
|
+
const ctx = (0, import_react67.useContext)(UIContext);
|
|
19229
19414
|
if (!ctx) throw new Error("useProviderConfig must be used within a Provider");
|
|
19230
19415
|
return ctx;
|
|
19231
19416
|
};
|
|
@@ -19251,7 +19436,7 @@ function ConnectWalletButton(props) {
|
|
|
19251
19436
|
const colorMode = useLayoutStore((st) => st.colorMode);
|
|
19252
19437
|
const { session, address, hasServerVault, isLoading, isIframeReady, status, setUsePaymaster } = useSession();
|
|
19253
19438
|
const connectButtonLabel = getFormattedStatus(label || "Connect", status, isIframeReady);
|
|
19254
|
-
(0,
|
|
19439
|
+
(0, import_react68.useEffect)(() => setUsePaymaster(usePaymaster), [setUsePaymaster, usePaymaster]);
|
|
19255
19440
|
const { data: profile, isLoading: isProfileLoading } = (0, import_react_query42.useQuery)({
|
|
19256
19441
|
retry: false,
|
|
19257
19442
|
enabled: !!address,
|
|
@@ -19259,7 +19444,7 @@ function ConnectWalletButton(props) {
|
|
|
19259
19444
|
queryFn: getUserProfile
|
|
19260
19445
|
});
|
|
19261
19446
|
const displayName = profile?.nicknameDisplay || profile?.displayName || import_auth18.jwtTokenManager.getDisplayName();
|
|
19262
|
-
const indicators = (0,
|
|
19447
|
+
const indicators = (0, import_react68.useMemo)(() => {
|
|
19263
19448
|
const userId = session?.mpcUserId;
|
|
19264
19449
|
if (!userId) return { server: false, local: false, backup: false };
|
|
19265
19450
|
const server = import_auth18.jwtTokenManager.getHasKeyshare() ?? false;
|
|
@@ -19406,13 +19591,13 @@ function ConnectWalletButton(props) {
|
|
|
19406
19591
|
}
|
|
19407
19592
|
) });
|
|
19408
19593
|
}
|
|
19409
|
-
var import_react_query42, import_lucide_react61,
|
|
19594
|
+
var import_react_query42, import_lucide_react61, import_react68, import_jsx_runtime97;
|
|
19410
19595
|
var init_ConnectWalletButton = __esm({
|
|
19411
19596
|
"src/components/ConnectWalletButton.tsx"() {
|
|
19412
19597
|
init_LumiaIcon3();
|
|
19413
19598
|
import_react_query42 = require("@tanstack/react-query");
|
|
19414
19599
|
import_lucide_react61 = require("lucide-react");
|
|
19415
|
-
|
|
19600
|
+
import_react68 = require("react");
|
|
19416
19601
|
init_SessionContext();
|
|
19417
19602
|
init_auth();
|
|
19418
19603
|
init_profile();
|
|
@@ -19466,7 +19651,7 @@ function useOpenPage() {
|
|
|
19466
19651
|
const setPage = useLayoutDataStore((st) => st.setPage);
|
|
19467
19652
|
const setPageParams = useLayoutDataStore((st) => st.setPageParams);
|
|
19468
19653
|
const address = useSession((st) => st.address);
|
|
19469
|
-
const open = (0,
|
|
19654
|
+
const open = (0, import_react69.useCallback)(
|
|
19470
19655
|
(passportPage, params) => {
|
|
19471
19656
|
if (!address) return setPage("auth" /* AUTH */);
|
|
19472
19657
|
if (!!address && passportPage === "auth" /* AUTH */) return setPage("manage-wallet" /* MANAGE_WALLET */);
|
|
@@ -19475,13 +19660,13 @@ function useOpenPage() {
|
|
|
19475
19660
|
},
|
|
19476
19661
|
[setPage, setPageParams, address]
|
|
19477
19662
|
);
|
|
19478
|
-
const close = (0,
|
|
19663
|
+
const close = (0, import_react69.useCallback)(() => setPage(null), [setPage]);
|
|
19479
19664
|
return { open, close, isOpen: page !== null };
|
|
19480
19665
|
}
|
|
19481
|
-
var
|
|
19666
|
+
var import_react69;
|
|
19482
19667
|
var init_useOpenPage = __esm({
|
|
19483
19668
|
"src/hooks/useOpenPage.ts"() {
|
|
19484
|
-
|
|
19669
|
+
import_react69 = require("react");
|
|
19485
19670
|
init_SessionContext();
|
|
19486
19671
|
init_useLayoutDataStore();
|
|
19487
19672
|
}
|
|
@@ -20048,17 +20233,17 @@ var init_Hash = __esm({
|
|
|
20048
20233
|
});
|
|
20049
20234
|
|
|
20050
20235
|
// src/internal/components/TransactionsMenu/TransactionsList.tsx
|
|
20051
|
-
var
|
|
20236
|
+
var import_react70, import_jsx_runtime103, TransactionsList;
|
|
20052
20237
|
var init_TransactionsList = __esm({
|
|
20053
20238
|
"src/internal/components/TransactionsMenu/TransactionsList.tsx"() {
|
|
20054
|
-
|
|
20239
|
+
import_react70 = require("react");
|
|
20055
20240
|
init_base();
|
|
20056
20241
|
import_jsx_runtime103 = require("react/jsx-runtime");
|
|
20057
20242
|
TransactionsList = ({ address, itemsCount = 10 }) => {
|
|
20058
|
-
const [transactions, setTransactions] = (0,
|
|
20059
|
-
const [loading, setLoading] = (0,
|
|
20060
|
-
const [error, setError] = (0,
|
|
20061
|
-
(0,
|
|
20243
|
+
const [transactions, setTransactions] = (0, import_react70.useState)([]);
|
|
20244
|
+
const [loading, setLoading] = (0, import_react70.useState)(true);
|
|
20245
|
+
const [error, setError] = (0, import_react70.useState)(null);
|
|
20246
|
+
(0, import_react70.useEffect)(() => {
|
|
20062
20247
|
const fetchTransactions2 = async () => {
|
|
20063
20248
|
try {
|
|
20064
20249
|
setLoading(true);
|
|
@@ -20353,11 +20538,230 @@ var init_useUserOpStatus = __esm({
|
|
|
20353
20538
|
}
|
|
20354
20539
|
});
|
|
20355
20540
|
|
|
20541
|
+
// src/hooks/useWalletMode.ts
|
|
20542
|
+
function useWalletMode() {
|
|
20543
|
+
const configMode = useExternalWalletStore((st) => st.configMode);
|
|
20544
|
+
const activeMode = useExternalWalletStore((st) => st.activeMode);
|
|
20545
|
+
const setActiveMode = useExternalWalletStore((st) => st.setActiveMode);
|
|
20546
|
+
const switchMode = (0, import_react71.useCallback)(
|
|
20547
|
+
(mode) => {
|
|
20548
|
+
if (configMode !== "both") return;
|
|
20549
|
+
setActiveMode(mode);
|
|
20550
|
+
},
|
|
20551
|
+
[configMode, setActiveMode]
|
|
20552
|
+
);
|
|
20553
|
+
return {
|
|
20554
|
+
configMode,
|
|
20555
|
+
activeMode,
|
|
20556
|
+
switchMode,
|
|
20557
|
+
isDirect: activeMode === "direct"
|
|
20558
|
+
};
|
|
20559
|
+
}
|
|
20560
|
+
var import_react71;
|
|
20561
|
+
var init_useWalletMode = __esm({
|
|
20562
|
+
"src/hooks/useWalletMode.ts"() {
|
|
20563
|
+
import_react71 = require("react");
|
|
20564
|
+
init_useExternalWalletStore();
|
|
20565
|
+
}
|
|
20566
|
+
});
|
|
20567
|
+
|
|
20568
|
+
// src/hooks/useDirectWallet.ts
|
|
20569
|
+
function useDirectWallet() {
|
|
20570
|
+
const address = useExternalWalletStore((st) => st.externalAddress);
|
|
20571
|
+
const chainId = useExternalWalletStore((st) => st.externalChainId);
|
|
20572
|
+
const isConnected = useExternalWalletStore((st) => st.isExternalConnected);
|
|
20573
|
+
const connectorName = useExternalWalletStore((st) => st.connectorName);
|
|
20574
|
+
const clearExternalWallet = useExternalWalletStore((st) => st.clearExternalWallet);
|
|
20575
|
+
const { disconnect: wagmiDisconnect } = (0, import_wagmi8.useDisconnect)();
|
|
20576
|
+
const { openConnectModal } = (0, import_rainbowkit5.useConnectModal)();
|
|
20577
|
+
const setIsWalletLinking = useLayoutDataStore((st) => st.setIsWalletLinking);
|
|
20578
|
+
const connect = (0, import_react72.useCallback)(() => {
|
|
20579
|
+
setIsWalletLinking(true);
|
|
20580
|
+
}, [setIsWalletLinking]);
|
|
20581
|
+
const reconnect = (0, import_react72.useCallback)(() => {
|
|
20582
|
+
if (openConnectModal) openConnectModal();
|
|
20583
|
+
}, [openConnectModal]);
|
|
20584
|
+
const disconnect = (0, import_react72.useCallback)(() => {
|
|
20585
|
+
wagmiDisconnect();
|
|
20586
|
+
clearExternalWallet();
|
|
20587
|
+
}, [wagmiDisconnect, clearExternalWallet]);
|
|
20588
|
+
return {
|
|
20589
|
+
address,
|
|
20590
|
+
chainId,
|
|
20591
|
+
isConnected,
|
|
20592
|
+
connectorName,
|
|
20593
|
+
connect,
|
|
20594
|
+
reconnect,
|
|
20595
|
+
disconnect
|
|
20596
|
+
};
|
|
20597
|
+
}
|
|
20598
|
+
var import_react72, import_rainbowkit5, import_wagmi8;
|
|
20599
|
+
var init_useDirectWallet = __esm({
|
|
20600
|
+
"src/hooks/useDirectWallet.ts"() {
|
|
20601
|
+
import_react72 = require("react");
|
|
20602
|
+
import_rainbowkit5 = require("@rainbow-me/rainbowkit");
|
|
20603
|
+
import_wagmi8 = require("wagmi");
|
|
20604
|
+
init_useExternalWalletStore();
|
|
20605
|
+
init_useLayoutDataStore();
|
|
20606
|
+
}
|
|
20607
|
+
});
|
|
20608
|
+
|
|
20609
|
+
// src/hooks/useSendDirectTransaction.ts
|
|
20610
|
+
function useSendDirectTransaction() {
|
|
20611
|
+
const isConnected = useExternalWalletStore((st) => st.isExternalConnected);
|
|
20612
|
+
const externalChainId = useExternalWalletStore((st) => st.externalChainId);
|
|
20613
|
+
const { sendTransactionAsync } = (0, import_wagmi9.useSendTransaction)();
|
|
20614
|
+
const { switchChainAsync } = (0, import_wagmi9.useSwitchChain)();
|
|
20615
|
+
const [isPending, setIsPending] = (0, import_react73.useState)(false);
|
|
20616
|
+
const [error, setError] = (0, import_react73.useState)(null);
|
|
20617
|
+
const [txHash, setTxHash] = (0, import_react73.useState)(null);
|
|
20618
|
+
const sendTransaction = (0, import_react73.useCallback)(
|
|
20619
|
+
async (params) => {
|
|
20620
|
+
if (!isConnected) {
|
|
20621
|
+
setError("No external wallet connected");
|
|
20622
|
+
return null;
|
|
20623
|
+
}
|
|
20624
|
+
if (!(0, import_viem18.isAddress)(params.to)) {
|
|
20625
|
+
setError("Invalid recipient address");
|
|
20626
|
+
return null;
|
|
20627
|
+
}
|
|
20628
|
+
setIsPending(true);
|
|
20629
|
+
setError(null);
|
|
20630
|
+
setTxHash(null);
|
|
20631
|
+
try {
|
|
20632
|
+
if (params.chainId && params.chainId !== externalChainId) {
|
|
20633
|
+
await switchChainAsync({ chainId: params.chainId });
|
|
20634
|
+
}
|
|
20635
|
+
const hash = await sendTransactionAsync({
|
|
20636
|
+
to: params.to,
|
|
20637
|
+
value: (0, import_viem18.parseEther)(params.value),
|
|
20638
|
+
data: params.data
|
|
20639
|
+
});
|
|
20640
|
+
setTxHash(hash);
|
|
20641
|
+
return hash;
|
|
20642
|
+
} catch (err) {
|
|
20643
|
+
const message = err instanceof Error ? err.message : "Transaction failed";
|
|
20644
|
+
setError(message);
|
|
20645
|
+
return null;
|
|
20646
|
+
} finally {
|
|
20647
|
+
setIsPending(false);
|
|
20648
|
+
}
|
|
20649
|
+
},
|
|
20650
|
+
[isConnected, externalChainId, sendTransactionAsync, switchChainAsync]
|
|
20651
|
+
);
|
|
20652
|
+
const reset = (0, import_react73.useCallback)(() => {
|
|
20653
|
+
setError(null);
|
|
20654
|
+
setTxHash(null);
|
|
20655
|
+
setIsPending(false);
|
|
20656
|
+
}, []);
|
|
20657
|
+
return { sendTransaction, isPending, error, txHash, reset };
|
|
20658
|
+
}
|
|
20659
|
+
var import_react73, import_viem18, import_wagmi9;
|
|
20660
|
+
var init_useSendDirectTransaction = __esm({
|
|
20661
|
+
"src/hooks/useSendDirectTransaction.ts"() {
|
|
20662
|
+
import_react73 = require("react");
|
|
20663
|
+
import_viem18 = require("viem");
|
|
20664
|
+
import_wagmi9 = require("wagmi");
|
|
20665
|
+
init_useExternalWalletStore();
|
|
20666
|
+
}
|
|
20667
|
+
});
|
|
20668
|
+
|
|
20669
|
+
// src/hooks/useTransferToLinkedWallet.ts
|
|
20670
|
+
function useTransferToLinkedWallet() {
|
|
20671
|
+
const session = useSession((st) => st.session);
|
|
20672
|
+
const { profiles } = useLinkedProfiles();
|
|
20673
|
+
const [isPending, setIsPending] = (0, import_react74.useState)(false);
|
|
20674
|
+
const [error, setError] = (0, import_react74.useState)(null);
|
|
20675
|
+
const [userOpHash, setUserOpHash] = (0, import_react74.useState)(null);
|
|
20676
|
+
const linkedWallets = (0, import_react74.useMemo)(
|
|
20677
|
+
() => (profiles || []).filter((p) => p.provider === "wallet" && p.externalId).map((p) => p.externalId),
|
|
20678
|
+
[profiles]
|
|
20679
|
+
);
|
|
20680
|
+
const transfer = (0, import_react74.useCallback)(
|
|
20681
|
+
async (params) => {
|
|
20682
|
+
if (!session) {
|
|
20683
|
+
setError("No active session");
|
|
20684
|
+
return null;
|
|
20685
|
+
}
|
|
20686
|
+
const toAddress = params.toAddress || linkedWallets[0];
|
|
20687
|
+
if (!toAddress || !(0, import_viem19.isAddress)(toAddress)) {
|
|
20688
|
+
setError("No linked wallet address available");
|
|
20689
|
+
return null;
|
|
20690
|
+
}
|
|
20691
|
+
setIsPending(true);
|
|
20692
|
+
setError(null);
|
|
20693
|
+
setUserOpHash(null);
|
|
20694
|
+
try {
|
|
20695
|
+
let to;
|
|
20696
|
+
let value;
|
|
20697
|
+
let data;
|
|
20698
|
+
if (params.token === "native") {
|
|
20699
|
+
to = toAddress;
|
|
20700
|
+
value = (0, import_viem19.parseEther)(params.amount).toString();
|
|
20701
|
+
data = "0x";
|
|
20702
|
+
} else {
|
|
20703
|
+
const decimals = params.decimals ?? 18;
|
|
20704
|
+
to = params.token;
|
|
20705
|
+
value = "0";
|
|
20706
|
+
data = (0, import_viem19.encodeFunctionData)({
|
|
20707
|
+
abi: ERC20_TRANSFER_ABI2,
|
|
20708
|
+
functionName: "transfer",
|
|
20709
|
+
args: [toAddress, (0, import_viem19.parseUnits)(params.amount, decimals)]
|
|
20710
|
+
});
|
|
20711
|
+
}
|
|
20712
|
+
const hash = await sendUserOperation2(session, {
|
|
20713
|
+
to,
|
|
20714
|
+
value,
|
|
20715
|
+
data,
|
|
20716
|
+
feeType: "standard",
|
|
20717
|
+
chainId: params.chainId
|
|
20718
|
+
});
|
|
20719
|
+
setUserOpHash(hash);
|
|
20720
|
+
return hash;
|
|
20721
|
+
} catch (err) {
|
|
20722
|
+
const message = err instanceof Error ? err.message : "Transfer failed";
|
|
20723
|
+
setError(message);
|
|
20724
|
+
return null;
|
|
20725
|
+
} finally {
|
|
20726
|
+
setIsPending(false);
|
|
20727
|
+
}
|
|
20728
|
+
},
|
|
20729
|
+
[session, linkedWallets]
|
|
20730
|
+
);
|
|
20731
|
+
const reset = (0, import_react74.useCallback)(() => {
|
|
20732
|
+
setError(null);
|
|
20733
|
+
setUserOpHash(null);
|
|
20734
|
+
setIsPending(false);
|
|
20735
|
+
}, []);
|
|
20736
|
+
return { transfer, isPending, error, userOpHash, linkedWallets, reset };
|
|
20737
|
+
}
|
|
20738
|
+
var import_react74, import_viem19, ERC20_TRANSFER_ABI2;
|
|
20739
|
+
var init_useTransferToLinkedWallet = __esm({
|
|
20740
|
+
"src/hooks/useTransferToLinkedWallet.ts"() {
|
|
20741
|
+
import_react74 = require("react");
|
|
20742
|
+
import_viem19 = require("viem");
|
|
20743
|
+
init_SessionContext();
|
|
20744
|
+
init_account();
|
|
20745
|
+
init_linkedProfiles();
|
|
20746
|
+
ERC20_TRANSFER_ABI2 = [
|
|
20747
|
+
{
|
|
20748
|
+
type: "function",
|
|
20749
|
+
name: "transfer",
|
|
20750
|
+
inputs: [
|
|
20751
|
+
{ name: "to", type: "address" },
|
|
20752
|
+
{ name: "amount", type: "uint256" }
|
|
20753
|
+
],
|
|
20754
|
+
outputs: [{ name: "", type: "bool" }]
|
|
20755
|
+
}
|
|
20756
|
+
];
|
|
20757
|
+
}
|
|
20758
|
+
});
|
|
20759
|
+
|
|
20356
20760
|
// src/hooks/useLogout.ts
|
|
20357
20761
|
function useLogout() {
|
|
20358
20762
|
const { setSession, setIsLoading, setAddress, setStatus, setError, address } = useSession();
|
|
20359
20763
|
const { callbacks } = useProviderConfig();
|
|
20360
|
-
const logout2 = (0,
|
|
20764
|
+
const logout2 = (0, import_react75.useCallback)(async () => {
|
|
20361
20765
|
const prevAddress = address;
|
|
20362
20766
|
let userId = null;
|
|
20363
20767
|
setIsLoading(true);
|
|
@@ -20387,11 +20791,11 @@ function useLogout() {
|
|
|
20387
20791
|
}, [address, setAddress, setError, setSession, setStatus, callbacks]);
|
|
20388
20792
|
return { logout: logout2 };
|
|
20389
20793
|
}
|
|
20390
|
-
var import_auth20,
|
|
20794
|
+
var import_auth20, import_react75;
|
|
20391
20795
|
var init_useLogout = __esm({
|
|
20392
20796
|
"src/hooks/useLogout.ts"() {
|
|
20393
20797
|
import_auth20 = require("@embarkai/core/auth");
|
|
20394
|
-
|
|
20798
|
+
import_react75 = require("react");
|
|
20395
20799
|
init_ProviderContext();
|
|
20396
20800
|
init_SessionContext();
|
|
20397
20801
|
}
|
|
@@ -20452,16 +20856,16 @@ var init_clients2 = __esm({
|
|
|
20452
20856
|
function useTransactions() {
|
|
20453
20857
|
const chainId = requireActiveChainId();
|
|
20454
20858
|
const viemChain = (0, import_read17.getViemChain)(chainId);
|
|
20455
|
-
const publicClient = (0,
|
|
20456
|
-
const { data: walletClient } = (0,
|
|
20457
|
-
const { address } = (0,
|
|
20859
|
+
const publicClient = (0, import_wagmi10.usePublicClient)({ chainId });
|
|
20860
|
+
const { data: walletClient } = (0, import_wagmi10.useWalletClient)();
|
|
20861
|
+
const { address } = (0, import_wagmi10.useAccount)();
|
|
20458
20862
|
const sendTransaction = async (params) => {
|
|
20459
20863
|
if (!walletClient) {
|
|
20460
20864
|
throw new Error("Wallet not connected");
|
|
20461
20865
|
}
|
|
20462
20866
|
const txParams = {
|
|
20463
20867
|
to: params.to,
|
|
20464
|
-
value: (0,
|
|
20868
|
+
value: (0, import_viem20.parseEther)(params.value),
|
|
20465
20869
|
data: params.data,
|
|
20466
20870
|
chain: viemChain
|
|
20467
20871
|
};
|
|
@@ -20509,13 +20913,13 @@ function useTransactions() {
|
|
|
20509
20913
|
isConnected: !!address && !!walletClient
|
|
20510
20914
|
};
|
|
20511
20915
|
}
|
|
20512
|
-
var import_read17,
|
|
20916
|
+
var import_read17, import_viem20, import_wagmi10;
|
|
20513
20917
|
var init_transactions = __esm({
|
|
20514
20918
|
"src/modules/transactions.ts"() {
|
|
20515
20919
|
init_SessionContext();
|
|
20516
20920
|
import_read17 = require("@embarkai/core/read");
|
|
20517
|
-
|
|
20518
|
-
|
|
20921
|
+
import_viem20 = require("viem");
|
|
20922
|
+
import_wagmi10 = require("wagmi");
|
|
20519
20923
|
}
|
|
20520
20924
|
});
|
|
20521
20925
|
|
|
@@ -20526,7 +20930,7 @@ function useAssets(address) {
|
|
|
20526
20930
|
data: nativeBalance,
|
|
20527
20931
|
isLoading: nativeBalanceLoading,
|
|
20528
20932
|
refetch: refetchNativeBalance
|
|
20529
|
-
} = (0,
|
|
20933
|
+
} = (0, import_wagmi11.useBalance)({
|
|
20530
20934
|
address,
|
|
20531
20935
|
chainId,
|
|
20532
20936
|
query: {
|
|
@@ -20535,12 +20939,12 @@ function useAssets(address) {
|
|
|
20535
20939
|
});
|
|
20536
20940
|
const tokenContracts = COMMON_TOKENS.map((token) => ({
|
|
20537
20941
|
address: token.address,
|
|
20538
|
-
abi:
|
|
20942
|
+
abi: import_viem21.erc20Abi,
|
|
20539
20943
|
functionName: "balanceOf",
|
|
20540
20944
|
args: [address],
|
|
20541
20945
|
chainId
|
|
20542
20946
|
}));
|
|
20543
|
-
const readContractsResult = (0,
|
|
20947
|
+
const readContractsResult = (0, import_wagmi11.useReadContracts)({
|
|
20544
20948
|
contracts: tokenContracts,
|
|
20545
20949
|
query: {
|
|
20546
20950
|
enabled: !!address && COMMON_TOKENS.length > 0
|
|
@@ -20568,7 +20972,7 @@ function useAssets(address) {
|
|
|
20568
20972
|
const token = COMMON_TOKENS[index];
|
|
20569
20973
|
if (balance.status === "success" && balance.result) {
|
|
20570
20974
|
const balanceValue = balance.result;
|
|
20571
|
-
const formattedBalance = (0,
|
|
20975
|
+
const formattedBalance = (0, import_viem21.formatUnits)(balanceValue, token.decimals);
|
|
20572
20976
|
assets.push({
|
|
20573
20977
|
type: "erc20",
|
|
20574
20978
|
address: token.address,
|
|
@@ -20593,7 +20997,7 @@ function useAssets(address) {
|
|
|
20593
20997
|
const token = COMMON_TOKENS[tokenIndex];
|
|
20594
20998
|
if (balance.status === "success" && balance.result) {
|
|
20595
20999
|
const balanceValue = balance.result;
|
|
20596
|
-
const formattedBalance = (0,
|
|
21000
|
+
const formattedBalance = (0, import_viem21.formatUnits)(balanceValue, token.decimals);
|
|
20597
21001
|
return {
|
|
20598
21002
|
address: token.address,
|
|
20599
21003
|
name: token.name,
|
|
@@ -20621,11 +21025,11 @@ function useAssets(address) {
|
|
|
20621
21025
|
}
|
|
20622
21026
|
function useTokenInfo(tokenAddress) {
|
|
20623
21027
|
const chainId = requireActiveChainId();
|
|
20624
|
-
const readContractsResult = (0,
|
|
21028
|
+
const readContractsResult = (0, import_wagmi11.useReadContracts)({
|
|
20625
21029
|
contracts: [
|
|
20626
|
-
{ address: tokenAddress, abi:
|
|
20627
|
-
{ address: tokenAddress, abi:
|
|
20628
|
-
{ address: tokenAddress, abi:
|
|
21030
|
+
{ address: tokenAddress, abi: import_viem21.erc20Abi, functionName: "name", chainId },
|
|
21031
|
+
{ address: tokenAddress, abi: import_viem21.erc20Abi, functionName: "symbol", chainId },
|
|
21032
|
+
{ address: tokenAddress, abi: import_viem21.erc20Abi, functionName: "decimals", chainId }
|
|
20629
21033
|
]
|
|
20630
21034
|
});
|
|
20631
21035
|
const { data: tokenData, isLoading } = readContractsResult;
|
|
@@ -20652,9 +21056,9 @@ function useTokenBalance(tokenAddress, userAddress) {
|
|
|
20652
21056
|
data: balance,
|
|
20653
21057
|
isLoading,
|
|
20654
21058
|
refetch
|
|
20655
|
-
} = (0,
|
|
21059
|
+
} = (0, import_wagmi11.useReadContract)({
|
|
20656
21060
|
address: tokenAddress,
|
|
20657
|
-
abi:
|
|
21061
|
+
abi: import_viem21.erc20Abi,
|
|
20658
21062
|
functionName: "balanceOf",
|
|
20659
21063
|
args: userAddress ? [userAddress] : void 0,
|
|
20660
21064
|
chainId,
|
|
@@ -20663,9 +21067,9 @@ function useTokenBalance(tokenAddress, userAddress) {
|
|
|
20663
21067
|
}
|
|
20664
21068
|
});
|
|
20665
21069
|
const { tokenInfo } = useTokenInfo(tokenAddress);
|
|
20666
|
-
const formattedBalance =
|
|
21070
|
+
const formattedBalance = import_react76.default.useMemo(() => {
|
|
20667
21071
|
if (!balance || !tokenInfo) return "0";
|
|
20668
|
-
return (0,
|
|
21072
|
+
return (0, import_viem21.formatUnits)(balance, tokenInfo.decimals);
|
|
20669
21073
|
}, [balance, tokenInfo]);
|
|
20670
21074
|
return {
|
|
20671
21075
|
balance,
|
|
@@ -20675,13 +21079,13 @@ function useTokenBalance(tokenAddress, userAddress) {
|
|
|
20675
21079
|
refetch
|
|
20676
21080
|
};
|
|
20677
21081
|
}
|
|
20678
|
-
var
|
|
21082
|
+
var import_react76, import_viem21, import_wagmi11, COMMON_TOKENS;
|
|
20679
21083
|
var init_assets2 = __esm({
|
|
20680
21084
|
"src/modules/assets.ts"() {
|
|
20681
21085
|
init_SessionContext();
|
|
20682
|
-
|
|
20683
|
-
|
|
20684
|
-
|
|
21086
|
+
import_react76 = __toESM(require("react"), 1);
|
|
21087
|
+
import_viem21 = require("viem");
|
|
21088
|
+
import_wagmi11 = require("wagmi");
|
|
20685
21089
|
COMMON_TOKENS = [
|
|
20686
21090
|
// Add real token addresses here when available
|
|
20687
21091
|
// {
|
|
@@ -20737,12 +21141,12 @@ function useSmartAccountTransactions() {
|
|
|
20737
21141
|
getTransactionDetails
|
|
20738
21142
|
};
|
|
20739
21143
|
}
|
|
20740
|
-
var
|
|
21144
|
+
var import_viem22, USER_OP_EVENT;
|
|
20741
21145
|
var init_smartAccountTransactions = __esm({
|
|
20742
21146
|
"src/modules/smartAccountTransactions.ts"() {
|
|
20743
|
-
|
|
21147
|
+
import_viem22 = require("viem");
|
|
20744
21148
|
init_SessionContext();
|
|
20745
|
-
USER_OP_EVENT = (0,
|
|
21149
|
+
USER_OP_EVENT = (0, import_viem22.parseAbiItem)(
|
|
20746
21150
|
"event UserOperationEvent(bytes32 indexed userOpHash, address indexed sender, address indexed paymaster, uint256 nonce, bool success, uint256 actualGasCost, uint256 actualGasUsed)"
|
|
20747
21151
|
);
|
|
20748
21152
|
}
|
|
@@ -20795,6 +21199,7 @@ __export(index_exports, {
|
|
|
20795
21199
|
useAssets: () => useAssets,
|
|
20796
21200
|
useBalance: () => useBalance,
|
|
20797
21201
|
useColorMode: () => useColorMode,
|
|
21202
|
+
useDirectWallet: () => useDirectWallet,
|
|
20798
21203
|
useErc3643Compliance: () => useErc3643Compliance,
|
|
20799
21204
|
useError: () => useError,
|
|
20800
21205
|
useHasServerVault: () => useHasServerVault,
|
|
@@ -20808,13 +21213,16 @@ __export(index_exports, {
|
|
|
20808
21213
|
useOpenPage: () => useOpenPage,
|
|
20809
21214
|
useProviderConfig: () => useProviderConfig,
|
|
20810
21215
|
useRecoveryUserId: () => useRecoveryUserId,
|
|
21216
|
+
useSendDirectTransaction: () => useSendDirectTransaction,
|
|
20811
21217
|
useSendTransaction: () => useSendTransaction,
|
|
20812
21218
|
useSession: () => useSession,
|
|
20813
21219
|
useSmartAccountTransactions: () => useSmartAccountTransactions,
|
|
20814
21220
|
useTokenBalance: () => useTokenBalance,
|
|
20815
21221
|
useTokenInfo: () => useTokenInfo,
|
|
20816
21222
|
useTransactions: () => useTransactions,
|
|
21223
|
+
useTransferToLinkedWallet: () => useTransferToLinkedWallet,
|
|
20817
21224
|
useUserOpStatus: () => useUserOpStatus,
|
|
21225
|
+
useWalletMode: () => useWalletMode,
|
|
20818
21226
|
verifyFingerprint: () => verifyFingerprint,
|
|
20819
21227
|
verifyFingerprintDetailed: () => verifyFingerprintDetailed,
|
|
20820
21228
|
wagmiConfig: () => wagmiConfig,
|
|
@@ -20855,6 +21263,10 @@ var init_index = __esm({
|
|
|
20855
21263
|
init_useSendTransaction();
|
|
20856
21264
|
init_useUserOpStatus();
|
|
20857
21265
|
init_useErc3643Compliance();
|
|
21266
|
+
init_useWalletMode();
|
|
21267
|
+
init_useDirectWallet();
|
|
21268
|
+
init_useSendDirectTransaction();
|
|
21269
|
+
init_useTransferToLinkedWallet();
|
|
20858
21270
|
init_useLogout();
|
|
20859
21271
|
init_useNicknameResolve();
|
|
20860
21272
|
init_account();
|
|
@@ -20921,6 +21333,7 @@ init_index();
|
|
|
20921
21333
|
useAssets,
|
|
20922
21334
|
useBalance,
|
|
20923
21335
|
useColorMode,
|
|
21336
|
+
useDirectWallet,
|
|
20924
21337
|
useErc3643Compliance,
|
|
20925
21338
|
useError,
|
|
20926
21339
|
useHasServerVault,
|
|
@@ -20934,13 +21347,16 @@ init_index();
|
|
|
20934
21347
|
useOpenPage,
|
|
20935
21348
|
useProviderConfig,
|
|
20936
21349
|
useRecoveryUserId,
|
|
21350
|
+
useSendDirectTransaction,
|
|
20937
21351
|
useSendTransaction,
|
|
20938
21352
|
useSession,
|
|
20939
21353
|
useSmartAccountTransactions,
|
|
20940
21354
|
useTokenBalance,
|
|
20941
21355
|
useTokenInfo,
|
|
20942
21356
|
useTransactions,
|
|
21357
|
+
useTransferToLinkedWallet,
|
|
20943
21358
|
useUserOpStatus,
|
|
21359
|
+
useWalletMode,
|
|
20944
21360
|
verifyFingerprint,
|
|
20945
21361
|
verifyFingerprintDetailed,
|
|
20946
21362
|
wagmiConfig,
|