@embarkai/ui-kit 0.1.6 → 0.2.1
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 +518 -94
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +76 -1
- package/dist/index.d.ts +76 -1
- package/dist/index.js +461 -40
- 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.1
|
|
15547
|
+
version: "0.2.1",
|
|
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,12 @@ function Provider(props) {
|
|
|
19158
19343
|
if (updates.translations) next.translations = { ...next.translations, ...updates.translations };
|
|
19159
19344
|
config.current = next;
|
|
19160
19345
|
}, []);
|
|
19161
|
-
(0,
|
|
19346
|
+
const updateCallbacks = (0, import_react67.useCallback)((updates) => {
|
|
19347
|
+
const prev = callbacksRef.current;
|
|
19348
|
+
const next = updates ? { ...prev, ...updates } : void 0;
|
|
19349
|
+
callbacksRef.current = next;
|
|
19350
|
+
}, []);
|
|
19351
|
+
(0, import_react67.useEffect)(() => {
|
|
19162
19352
|
if (typeof window === "undefined" || !projectId) return;
|
|
19163
19353
|
const mergedConfig = (0, import_lodash_es6.merge)(DEFAULT_PROVIDER_CONFIG, initialConfig);
|
|
19164
19354
|
updateConfig(mergedConfig);
|
|
@@ -19176,7 +19366,7 @@ function Provider(props) {
|
|
|
19176
19366
|
useSession.getState().setActiveChainId(mergedConfig.network.chainId);
|
|
19177
19367
|
}
|
|
19178
19368
|
}, [projectId, initialConfig]);
|
|
19179
|
-
(0,
|
|
19369
|
+
(0, import_react67.useEffect)(() => {
|
|
19180
19370
|
if (typeof window === "undefined" || !projectId) return;
|
|
19181
19371
|
try {
|
|
19182
19372
|
(0, import_error_tracking4.initSdkErrorTracking)();
|
|
@@ -19205,17 +19395,20 @@ function Provider(props) {
|
|
|
19205
19395
|
console.error("[PROVIDER] Error setting up iframe manager:", error);
|
|
19206
19396
|
}
|
|
19207
19397
|
}, [projectId]);
|
|
19208
|
-
const contextValue = (0,
|
|
19398
|
+
const contextValue = (0, import_react67.useMemo)(
|
|
19399
|
+
() => ({ config, updateConfig, callbacks, updateCallbacks }),
|
|
19400
|
+
[config, updateConfig, callbacks, updateCallbacks]
|
|
19401
|
+
);
|
|
19209
19402
|
if (!!initialConfig?.wallet?.enabled)
|
|
19210
19403
|
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
19404
|
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
19405
|
}
|
|
19213
|
-
var import_error_tracking4, import_lodash_es6,
|
|
19406
|
+
var import_error_tracking4, import_lodash_es6, import_react67, import_jsx_runtime96, UIContext, useProviderConfig;
|
|
19214
19407
|
var init_ProviderContext = __esm({
|
|
19215
19408
|
"src/context/ProviderContext.tsx"() {
|
|
19216
19409
|
import_error_tracking4 = require("@embarkai/core/internal/error-tracking");
|
|
19217
19410
|
import_lodash_es6 = require("lodash-es");
|
|
19218
|
-
|
|
19411
|
+
import_react67 = require("react");
|
|
19219
19412
|
init_initial();
|
|
19220
19413
|
init_iframe_manager();
|
|
19221
19414
|
init_RainbowKitContext();
|
|
@@ -19223,9 +19416,9 @@ var init_ProviderContext = __esm({
|
|
|
19223
19416
|
init_utils8();
|
|
19224
19417
|
init_WagmiContext();
|
|
19225
19418
|
import_jsx_runtime96 = require("react/jsx-runtime");
|
|
19226
|
-
UIContext = (0,
|
|
19419
|
+
UIContext = (0, import_react67.createContext)(void 0);
|
|
19227
19420
|
useProviderConfig = () => {
|
|
19228
|
-
const ctx = (0,
|
|
19421
|
+
const ctx = (0, import_react67.useContext)(UIContext);
|
|
19229
19422
|
if (!ctx) throw new Error("useProviderConfig must be used within a Provider");
|
|
19230
19423
|
return ctx;
|
|
19231
19424
|
};
|
|
@@ -19251,7 +19444,7 @@ function ConnectWalletButton(props) {
|
|
|
19251
19444
|
const colorMode = useLayoutStore((st) => st.colorMode);
|
|
19252
19445
|
const { session, address, hasServerVault, isLoading, isIframeReady, status, setUsePaymaster } = useSession();
|
|
19253
19446
|
const connectButtonLabel = getFormattedStatus(label || "Connect", status, isIframeReady);
|
|
19254
|
-
(0,
|
|
19447
|
+
(0, import_react68.useEffect)(() => setUsePaymaster(usePaymaster), [setUsePaymaster, usePaymaster]);
|
|
19255
19448
|
const { data: profile, isLoading: isProfileLoading } = (0, import_react_query42.useQuery)({
|
|
19256
19449
|
retry: false,
|
|
19257
19450
|
enabled: !!address,
|
|
@@ -19259,7 +19452,7 @@ function ConnectWalletButton(props) {
|
|
|
19259
19452
|
queryFn: getUserProfile
|
|
19260
19453
|
});
|
|
19261
19454
|
const displayName = profile?.nicknameDisplay || profile?.displayName || import_auth18.jwtTokenManager.getDisplayName();
|
|
19262
|
-
const indicators = (0,
|
|
19455
|
+
const indicators = (0, import_react68.useMemo)(() => {
|
|
19263
19456
|
const userId = session?.mpcUserId;
|
|
19264
19457
|
if (!userId) return { server: false, local: false, backup: false };
|
|
19265
19458
|
const server = import_auth18.jwtTokenManager.getHasKeyshare() ?? false;
|
|
@@ -19406,13 +19599,13 @@ function ConnectWalletButton(props) {
|
|
|
19406
19599
|
}
|
|
19407
19600
|
) });
|
|
19408
19601
|
}
|
|
19409
|
-
var import_react_query42, import_lucide_react61,
|
|
19602
|
+
var import_react_query42, import_lucide_react61, import_react68, import_jsx_runtime97;
|
|
19410
19603
|
var init_ConnectWalletButton = __esm({
|
|
19411
19604
|
"src/components/ConnectWalletButton.tsx"() {
|
|
19412
19605
|
init_LumiaIcon3();
|
|
19413
19606
|
import_react_query42 = require("@tanstack/react-query");
|
|
19414
19607
|
import_lucide_react61 = require("lucide-react");
|
|
19415
|
-
|
|
19608
|
+
import_react68 = require("react");
|
|
19416
19609
|
init_SessionContext();
|
|
19417
19610
|
init_auth();
|
|
19418
19611
|
init_profile();
|
|
@@ -19466,7 +19659,7 @@ function useOpenPage() {
|
|
|
19466
19659
|
const setPage = useLayoutDataStore((st) => st.setPage);
|
|
19467
19660
|
const setPageParams = useLayoutDataStore((st) => st.setPageParams);
|
|
19468
19661
|
const address = useSession((st) => st.address);
|
|
19469
|
-
const open = (0,
|
|
19662
|
+
const open = (0, import_react69.useCallback)(
|
|
19470
19663
|
(passportPage, params) => {
|
|
19471
19664
|
if (!address) return setPage("auth" /* AUTH */);
|
|
19472
19665
|
if (!!address && passportPage === "auth" /* AUTH */) return setPage("manage-wallet" /* MANAGE_WALLET */);
|
|
@@ -19475,13 +19668,13 @@ function useOpenPage() {
|
|
|
19475
19668
|
},
|
|
19476
19669
|
[setPage, setPageParams, address]
|
|
19477
19670
|
);
|
|
19478
|
-
const close = (0,
|
|
19671
|
+
const close = (0, import_react69.useCallback)(() => setPage(null), [setPage]);
|
|
19479
19672
|
return { open, close, isOpen: page !== null };
|
|
19480
19673
|
}
|
|
19481
|
-
var
|
|
19674
|
+
var import_react69;
|
|
19482
19675
|
var init_useOpenPage = __esm({
|
|
19483
19676
|
"src/hooks/useOpenPage.ts"() {
|
|
19484
|
-
|
|
19677
|
+
import_react69 = require("react");
|
|
19485
19678
|
init_SessionContext();
|
|
19486
19679
|
init_useLayoutDataStore();
|
|
19487
19680
|
}
|
|
@@ -20048,17 +20241,17 @@ var init_Hash = __esm({
|
|
|
20048
20241
|
});
|
|
20049
20242
|
|
|
20050
20243
|
// src/internal/components/TransactionsMenu/TransactionsList.tsx
|
|
20051
|
-
var
|
|
20244
|
+
var import_react70, import_jsx_runtime103, TransactionsList;
|
|
20052
20245
|
var init_TransactionsList = __esm({
|
|
20053
20246
|
"src/internal/components/TransactionsMenu/TransactionsList.tsx"() {
|
|
20054
|
-
|
|
20247
|
+
import_react70 = require("react");
|
|
20055
20248
|
init_base();
|
|
20056
20249
|
import_jsx_runtime103 = require("react/jsx-runtime");
|
|
20057
20250
|
TransactionsList = ({ address, itemsCount = 10 }) => {
|
|
20058
|
-
const [transactions, setTransactions] = (0,
|
|
20059
|
-
const [loading, setLoading] = (0,
|
|
20060
|
-
const [error, setError] = (0,
|
|
20061
|
-
(0,
|
|
20251
|
+
const [transactions, setTransactions] = (0, import_react70.useState)([]);
|
|
20252
|
+
const [loading, setLoading] = (0, import_react70.useState)(true);
|
|
20253
|
+
const [error, setError] = (0, import_react70.useState)(null);
|
|
20254
|
+
(0, import_react70.useEffect)(() => {
|
|
20062
20255
|
const fetchTransactions2 = async () => {
|
|
20063
20256
|
try {
|
|
20064
20257
|
setLoading(true);
|
|
@@ -20353,11 +20546,230 @@ var init_useUserOpStatus = __esm({
|
|
|
20353
20546
|
}
|
|
20354
20547
|
});
|
|
20355
20548
|
|
|
20549
|
+
// src/hooks/useWalletMode.ts
|
|
20550
|
+
function useWalletMode() {
|
|
20551
|
+
const configMode = useExternalWalletStore((st) => st.configMode);
|
|
20552
|
+
const activeMode = useExternalWalletStore((st) => st.activeMode);
|
|
20553
|
+
const setActiveMode = useExternalWalletStore((st) => st.setActiveMode);
|
|
20554
|
+
const switchMode = (0, import_react71.useCallback)(
|
|
20555
|
+
(mode) => {
|
|
20556
|
+
if (configMode !== "both") return;
|
|
20557
|
+
setActiveMode(mode);
|
|
20558
|
+
},
|
|
20559
|
+
[configMode, setActiveMode]
|
|
20560
|
+
);
|
|
20561
|
+
return {
|
|
20562
|
+
configMode,
|
|
20563
|
+
activeMode,
|
|
20564
|
+
switchMode,
|
|
20565
|
+
isDirect: activeMode === "direct"
|
|
20566
|
+
};
|
|
20567
|
+
}
|
|
20568
|
+
var import_react71;
|
|
20569
|
+
var init_useWalletMode = __esm({
|
|
20570
|
+
"src/hooks/useWalletMode.ts"() {
|
|
20571
|
+
import_react71 = require("react");
|
|
20572
|
+
init_useExternalWalletStore();
|
|
20573
|
+
}
|
|
20574
|
+
});
|
|
20575
|
+
|
|
20576
|
+
// src/hooks/useDirectWallet.ts
|
|
20577
|
+
function useDirectWallet() {
|
|
20578
|
+
const address = useExternalWalletStore((st) => st.externalAddress);
|
|
20579
|
+
const chainId = useExternalWalletStore((st) => st.externalChainId);
|
|
20580
|
+
const isConnected = useExternalWalletStore((st) => st.isExternalConnected);
|
|
20581
|
+
const connectorName = useExternalWalletStore((st) => st.connectorName);
|
|
20582
|
+
const clearExternalWallet = useExternalWalletStore((st) => st.clearExternalWallet);
|
|
20583
|
+
const { disconnect: wagmiDisconnect } = (0, import_wagmi8.useDisconnect)();
|
|
20584
|
+
const { openConnectModal } = (0, import_rainbowkit5.useConnectModal)();
|
|
20585
|
+
const setIsWalletLinking = useLayoutDataStore((st) => st.setIsWalletLinking);
|
|
20586
|
+
const connect = (0, import_react72.useCallback)(() => {
|
|
20587
|
+
setIsWalletLinking(true);
|
|
20588
|
+
}, [setIsWalletLinking]);
|
|
20589
|
+
const reconnect = (0, import_react72.useCallback)(() => {
|
|
20590
|
+
if (openConnectModal) openConnectModal();
|
|
20591
|
+
}, [openConnectModal]);
|
|
20592
|
+
const disconnect = (0, import_react72.useCallback)(() => {
|
|
20593
|
+
wagmiDisconnect();
|
|
20594
|
+
clearExternalWallet();
|
|
20595
|
+
}, [wagmiDisconnect, clearExternalWallet]);
|
|
20596
|
+
return {
|
|
20597
|
+
address,
|
|
20598
|
+
chainId,
|
|
20599
|
+
isConnected,
|
|
20600
|
+
connectorName,
|
|
20601
|
+
connect,
|
|
20602
|
+
reconnect,
|
|
20603
|
+
disconnect
|
|
20604
|
+
};
|
|
20605
|
+
}
|
|
20606
|
+
var import_react72, import_rainbowkit5, import_wagmi8;
|
|
20607
|
+
var init_useDirectWallet = __esm({
|
|
20608
|
+
"src/hooks/useDirectWallet.ts"() {
|
|
20609
|
+
import_react72 = require("react");
|
|
20610
|
+
import_rainbowkit5 = require("@rainbow-me/rainbowkit");
|
|
20611
|
+
import_wagmi8 = require("wagmi");
|
|
20612
|
+
init_useExternalWalletStore();
|
|
20613
|
+
init_useLayoutDataStore();
|
|
20614
|
+
}
|
|
20615
|
+
});
|
|
20616
|
+
|
|
20617
|
+
// src/hooks/useSendDirectTransaction.ts
|
|
20618
|
+
function useSendDirectTransaction() {
|
|
20619
|
+
const isConnected = useExternalWalletStore((st) => st.isExternalConnected);
|
|
20620
|
+
const externalChainId = useExternalWalletStore((st) => st.externalChainId);
|
|
20621
|
+
const { sendTransactionAsync } = (0, import_wagmi9.useSendTransaction)();
|
|
20622
|
+
const { switchChainAsync } = (0, import_wagmi9.useSwitchChain)();
|
|
20623
|
+
const [isPending, setIsPending] = (0, import_react73.useState)(false);
|
|
20624
|
+
const [error, setError] = (0, import_react73.useState)(null);
|
|
20625
|
+
const [txHash, setTxHash] = (0, import_react73.useState)(null);
|
|
20626
|
+
const sendTransaction = (0, import_react73.useCallback)(
|
|
20627
|
+
async (params) => {
|
|
20628
|
+
if (!isConnected) {
|
|
20629
|
+
setError("No external wallet connected");
|
|
20630
|
+
return null;
|
|
20631
|
+
}
|
|
20632
|
+
if (!(0, import_viem18.isAddress)(params.to)) {
|
|
20633
|
+
setError("Invalid recipient address");
|
|
20634
|
+
return null;
|
|
20635
|
+
}
|
|
20636
|
+
setIsPending(true);
|
|
20637
|
+
setError(null);
|
|
20638
|
+
setTxHash(null);
|
|
20639
|
+
try {
|
|
20640
|
+
if (params.chainId && params.chainId !== externalChainId) {
|
|
20641
|
+
await switchChainAsync({ chainId: params.chainId });
|
|
20642
|
+
}
|
|
20643
|
+
const hash = await sendTransactionAsync({
|
|
20644
|
+
to: params.to,
|
|
20645
|
+
value: (0, import_viem18.parseEther)(params.value),
|
|
20646
|
+
data: params.data
|
|
20647
|
+
});
|
|
20648
|
+
setTxHash(hash);
|
|
20649
|
+
return hash;
|
|
20650
|
+
} catch (err) {
|
|
20651
|
+
const message = err instanceof Error ? err.message : "Transaction failed";
|
|
20652
|
+
setError(message);
|
|
20653
|
+
return null;
|
|
20654
|
+
} finally {
|
|
20655
|
+
setIsPending(false);
|
|
20656
|
+
}
|
|
20657
|
+
},
|
|
20658
|
+
[isConnected, externalChainId, sendTransactionAsync, switchChainAsync]
|
|
20659
|
+
);
|
|
20660
|
+
const reset = (0, import_react73.useCallback)(() => {
|
|
20661
|
+
setError(null);
|
|
20662
|
+
setTxHash(null);
|
|
20663
|
+
setIsPending(false);
|
|
20664
|
+
}, []);
|
|
20665
|
+
return { sendTransaction, isPending, error, txHash, reset };
|
|
20666
|
+
}
|
|
20667
|
+
var import_react73, import_viem18, import_wagmi9;
|
|
20668
|
+
var init_useSendDirectTransaction = __esm({
|
|
20669
|
+
"src/hooks/useSendDirectTransaction.ts"() {
|
|
20670
|
+
import_react73 = require("react");
|
|
20671
|
+
import_viem18 = require("viem");
|
|
20672
|
+
import_wagmi9 = require("wagmi");
|
|
20673
|
+
init_useExternalWalletStore();
|
|
20674
|
+
}
|
|
20675
|
+
});
|
|
20676
|
+
|
|
20677
|
+
// src/hooks/useTransferToLinkedWallet.ts
|
|
20678
|
+
function useTransferToLinkedWallet() {
|
|
20679
|
+
const session = useSession((st) => st.session);
|
|
20680
|
+
const { profiles } = useLinkedProfiles();
|
|
20681
|
+
const [isPending, setIsPending] = (0, import_react74.useState)(false);
|
|
20682
|
+
const [error, setError] = (0, import_react74.useState)(null);
|
|
20683
|
+
const [userOpHash, setUserOpHash] = (0, import_react74.useState)(null);
|
|
20684
|
+
const linkedWallets = (0, import_react74.useMemo)(
|
|
20685
|
+
() => (profiles || []).filter((p) => p.provider === "wallet" && p.externalId).map((p) => p.externalId),
|
|
20686
|
+
[profiles]
|
|
20687
|
+
);
|
|
20688
|
+
const transfer = (0, import_react74.useCallback)(
|
|
20689
|
+
async (params) => {
|
|
20690
|
+
if (!session) {
|
|
20691
|
+
setError("No active session");
|
|
20692
|
+
return null;
|
|
20693
|
+
}
|
|
20694
|
+
const toAddress = params.toAddress || linkedWallets[0];
|
|
20695
|
+
if (!toAddress || !(0, import_viem19.isAddress)(toAddress)) {
|
|
20696
|
+
setError("No linked wallet address available");
|
|
20697
|
+
return null;
|
|
20698
|
+
}
|
|
20699
|
+
setIsPending(true);
|
|
20700
|
+
setError(null);
|
|
20701
|
+
setUserOpHash(null);
|
|
20702
|
+
try {
|
|
20703
|
+
let to;
|
|
20704
|
+
let value;
|
|
20705
|
+
let data;
|
|
20706
|
+
if (params.token === "native") {
|
|
20707
|
+
to = toAddress;
|
|
20708
|
+
value = (0, import_viem19.parseEther)(params.amount).toString();
|
|
20709
|
+
data = "0x";
|
|
20710
|
+
} else {
|
|
20711
|
+
const decimals = params.decimals ?? 18;
|
|
20712
|
+
to = params.token;
|
|
20713
|
+
value = "0";
|
|
20714
|
+
data = (0, import_viem19.encodeFunctionData)({
|
|
20715
|
+
abi: ERC20_TRANSFER_ABI2,
|
|
20716
|
+
functionName: "transfer",
|
|
20717
|
+
args: [toAddress, (0, import_viem19.parseUnits)(params.amount, decimals)]
|
|
20718
|
+
});
|
|
20719
|
+
}
|
|
20720
|
+
const hash = await sendUserOperation2(session, {
|
|
20721
|
+
to,
|
|
20722
|
+
value,
|
|
20723
|
+
data,
|
|
20724
|
+
feeType: "standard",
|
|
20725
|
+
chainId: params.chainId
|
|
20726
|
+
});
|
|
20727
|
+
setUserOpHash(hash);
|
|
20728
|
+
return hash;
|
|
20729
|
+
} catch (err) {
|
|
20730
|
+
const message = err instanceof Error ? err.message : "Transfer failed";
|
|
20731
|
+
setError(message);
|
|
20732
|
+
return null;
|
|
20733
|
+
} finally {
|
|
20734
|
+
setIsPending(false);
|
|
20735
|
+
}
|
|
20736
|
+
},
|
|
20737
|
+
[session, linkedWallets]
|
|
20738
|
+
);
|
|
20739
|
+
const reset = (0, import_react74.useCallback)(() => {
|
|
20740
|
+
setError(null);
|
|
20741
|
+
setUserOpHash(null);
|
|
20742
|
+
setIsPending(false);
|
|
20743
|
+
}, []);
|
|
20744
|
+
return { transfer, isPending, error, userOpHash, linkedWallets, reset };
|
|
20745
|
+
}
|
|
20746
|
+
var import_react74, import_viem19, ERC20_TRANSFER_ABI2;
|
|
20747
|
+
var init_useTransferToLinkedWallet = __esm({
|
|
20748
|
+
"src/hooks/useTransferToLinkedWallet.ts"() {
|
|
20749
|
+
import_react74 = require("react");
|
|
20750
|
+
import_viem19 = require("viem");
|
|
20751
|
+
init_SessionContext();
|
|
20752
|
+
init_account();
|
|
20753
|
+
init_linkedProfiles();
|
|
20754
|
+
ERC20_TRANSFER_ABI2 = [
|
|
20755
|
+
{
|
|
20756
|
+
type: "function",
|
|
20757
|
+
name: "transfer",
|
|
20758
|
+
inputs: [
|
|
20759
|
+
{ name: "to", type: "address" },
|
|
20760
|
+
{ name: "amount", type: "uint256" }
|
|
20761
|
+
],
|
|
20762
|
+
outputs: [{ name: "", type: "bool" }]
|
|
20763
|
+
}
|
|
20764
|
+
];
|
|
20765
|
+
}
|
|
20766
|
+
});
|
|
20767
|
+
|
|
20356
20768
|
// src/hooks/useLogout.ts
|
|
20357
20769
|
function useLogout() {
|
|
20358
20770
|
const { setSession, setIsLoading, setAddress, setStatus, setError, address } = useSession();
|
|
20359
20771
|
const { callbacks } = useProviderConfig();
|
|
20360
|
-
const logout2 = (0,
|
|
20772
|
+
const logout2 = (0, import_react75.useCallback)(async () => {
|
|
20361
20773
|
const prevAddress = address;
|
|
20362
20774
|
let userId = null;
|
|
20363
20775
|
setIsLoading(true);
|
|
@@ -20387,11 +20799,11 @@ function useLogout() {
|
|
|
20387
20799
|
}, [address, setAddress, setError, setSession, setStatus, callbacks]);
|
|
20388
20800
|
return { logout: logout2 };
|
|
20389
20801
|
}
|
|
20390
|
-
var import_auth20,
|
|
20802
|
+
var import_auth20, import_react75;
|
|
20391
20803
|
var init_useLogout = __esm({
|
|
20392
20804
|
"src/hooks/useLogout.ts"() {
|
|
20393
20805
|
import_auth20 = require("@embarkai/core/auth");
|
|
20394
|
-
|
|
20806
|
+
import_react75 = require("react");
|
|
20395
20807
|
init_ProviderContext();
|
|
20396
20808
|
init_SessionContext();
|
|
20397
20809
|
}
|
|
@@ -20452,16 +20864,16 @@ var init_clients2 = __esm({
|
|
|
20452
20864
|
function useTransactions() {
|
|
20453
20865
|
const chainId = requireActiveChainId();
|
|
20454
20866
|
const viemChain = (0, import_read17.getViemChain)(chainId);
|
|
20455
|
-
const publicClient = (0,
|
|
20456
|
-
const { data: walletClient } = (0,
|
|
20457
|
-
const { address } = (0,
|
|
20867
|
+
const publicClient = (0, import_wagmi10.usePublicClient)({ chainId });
|
|
20868
|
+
const { data: walletClient } = (0, import_wagmi10.useWalletClient)();
|
|
20869
|
+
const { address } = (0, import_wagmi10.useAccount)();
|
|
20458
20870
|
const sendTransaction = async (params) => {
|
|
20459
20871
|
if (!walletClient) {
|
|
20460
20872
|
throw new Error("Wallet not connected");
|
|
20461
20873
|
}
|
|
20462
20874
|
const txParams = {
|
|
20463
20875
|
to: params.to,
|
|
20464
|
-
value: (0,
|
|
20876
|
+
value: (0, import_viem20.parseEther)(params.value),
|
|
20465
20877
|
data: params.data,
|
|
20466
20878
|
chain: viemChain
|
|
20467
20879
|
};
|
|
@@ -20509,13 +20921,13 @@ function useTransactions() {
|
|
|
20509
20921
|
isConnected: !!address && !!walletClient
|
|
20510
20922
|
};
|
|
20511
20923
|
}
|
|
20512
|
-
var import_read17,
|
|
20924
|
+
var import_read17, import_viem20, import_wagmi10;
|
|
20513
20925
|
var init_transactions = __esm({
|
|
20514
20926
|
"src/modules/transactions.ts"() {
|
|
20515
20927
|
init_SessionContext();
|
|
20516
20928
|
import_read17 = require("@embarkai/core/read");
|
|
20517
|
-
|
|
20518
|
-
|
|
20929
|
+
import_viem20 = require("viem");
|
|
20930
|
+
import_wagmi10 = require("wagmi");
|
|
20519
20931
|
}
|
|
20520
20932
|
});
|
|
20521
20933
|
|
|
@@ -20526,7 +20938,7 @@ function useAssets(address) {
|
|
|
20526
20938
|
data: nativeBalance,
|
|
20527
20939
|
isLoading: nativeBalanceLoading,
|
|
20528
20940
|
refetch: refetchNativeBalance
|
|
20529
|
-
} = (0,
|
|
20941
|
+
} = (0, import_wagmi11.useBalance)({
|
|
20530
20942
|
address,
|
|
20531
20943
|
chainId,
|
|
20532
20944
|
query: {
|
|
@@ -20535,12 +20947,12 @@ function useAssets(address) {
|
|
|
20535
20947
|
});
|
|
20536
20948
|
const tokenContracts = COMMON_TOKENS.map((token) => ({
|
|
20537
20949
|
address: token.address,
|
|
20538
|
-
abi:
|
|
20950
|
+
abi: import_viem21.erc20Abi,
|
|
20539
20951
|
functionName: "balanceOf",
|
|
20540
20952
|
args: [address],
|
|
20541
20953
|
chainId
|
|
20542
20954
|
}));
|
|
20543
|
-
const readContractsResult = (0,
|
|
20955
|
+
const readContractsResult = (0, import_wagmi11.useReadContracts)({
|
|
20544
20956
|
contracts: tokenContracts,
|
|
20545
20957
|
query: {
|
|
20546
20958
|
enabled: !!address && COMMON_TOKENS.length > 0
|
|
@@ -20568,7 +20980,7 @@ function useAssets(address) {
|
|
|
20568
20980
|
const token = COMMON_TOKENS[index];
|
|
20569
20981
|
if (balance.status === "success" && balance.result) {
|
|
20570
20982
|
const balanceValue = balance.result;
|
|
20571
|
-
const formattedBalance = (0,
|
|
20983
|
+
const formattedBalance = (0, import_viem21.formatUnits)(balanceValue, token.decimals);
|
|
20572
20984
|
assets.push({
|
|
20573
20985
|
type: "erc20",
|
|
20574
20986
|
address: token.address,
|
|
@@ -20593,7 +21005,7 @@ function useAssets(address) {
|
|
|
20593
21005
|
const token = COMMON_TOKENS[tokenIndex];
|
|
20594
21006
|
if (balance.status === "success" && balance.result) {
|
|
20595
21007
|
const balanceValue = balance.result;
|
|
20596
|
-
const formattedBalance = (0,
|
|
21008
|
+
const formattedBalance = (0, import_viem21.formatUnits)(balanceValue, token.decimals);
|
|
20597
21009
|
return {
|
|
20598
21010
|
address: token.address,
|
|
20599
21011
|
name: token.name,
|
|
@@ -20621,11 +21033,11 @@ function useAssets(address) {
|
|
|
20621
21033
|
}
|
|
20622
21034
|
function useTokenInfo(tokenAddress) {
|
|
20623
21035
|
const chainId = requireActiveChainId();
|
|
20624
|
-
const readContractsResult = (0,
|
|
21036
|
+
const readContractsResult = (0, import_wagmi11.useReadContracts)({
|
|
20625
21037
|
contracts: [
|
|
20626
|
-
{ address: tokenAddress, abi:
|
|
20627
|
-
{ address: tokenAddress, abi:
|
|
20628
|
-
{ address: tokenAddress, abi:
|
|
21038
|
+
{ address: tokenAddress, abi: import_viem21.erc20Abi, functionName: "name", chainId },
|
|
21039
|
+
{ address: tokenAddress, abi: import_viem21.erc20Abi, functionName: "symbol", chainId },
|
|
21040
|
+
{ address: tokenAddress, abi: import_viem21.erc20Abi, functionName: "decimals", chainId }
|
|
20629
21041
|
]
|
|
20630
21042
|
});
|
|
20631
21043
|
const { data: tokenData, isLoading } = readContractsResult;
|
|
@@ -20652,9 +21064,9 @@ function useTokenBalance(tokenAddress, userAddress) {
|
|
|
20652
21064
|
data: balance,
|
|
20653
21065
|
isLoading,
|
|
20654
21066
|
refetch
|
|
20655
|
-
} = (0,
|
|
21067
|
+
} = (0, import_wagmi11.useReadContract)({
|
|
20656
21068
|
address: tokenAddress,
|
|
20657
|
-
abi:
|
|
21069
|
+
abi: import_viem21.erc20Abi,
|
|
20658
21070
|
functionName: "balanceOf",
|
|
20659
21071
|
args: userAddress ? [userAddress] : void 0,
|
|
20660
21072
|
chainId,
|
|
@@ -20663,9 +21075,9 @@ function useTokenBalance(tokenAddress, userAddress) {
|
|
|
20663
21075
|
}
|
|
20664
21076
|
});
|
|
20665
21077
|
const { tokenInfo } = useTokenInfo(tokenAddress);
|
|
20666
|
-
const formattedBalance =
|
|
21078
|
+
const formattedBalance = import_react76.default.useMemo(() => {
|
|
20667
21079
|
if (!balance || !tokenInfo) return "0";
|
|
20668
|
-
return (0,
|
|
21080
|
+
return (0, import_viem21.formatUnits)(balance, tokenInfo.decimals);
|
|
20669
21081
|
}, [balance, tokenInfo]);
|
|
20670
21082
|
return {
|
|
20671
21083
|
balance,
|
|
@@ -20675,13 +21087,13 @@ function useTokenBalance(tokenAddress, userAddress) {
|
|
|
20675
21087
|
refetch
|
|
20676
21088
|
};
|
|
20677
21089
|
}
|
|
20678
|
-
var
|
|
21090
|
+
var import_react76, import_viem21, import_wagmi11, COMMON_TOKENS;
|
|
20679
21091
|
var init_assets2 = __esm({
|
|
20680
21092
|
"src/modules/assets.ts"() {
|
|
20681
21093
|
init_SessionContext();
|
|
20682
|
-
|
|
20683
|
-
|
|
20684
|
-
|
|
21094
|
+
import_react76 = __toESM(require("react"), 1);
|
|
21095
|
+
import_viem21 = require("viem");
|
|
21096
|
+
import_wagmi11 = require("wagmi");
|
|
20685
21097
|
COMMON_TOKENS = [
|
|
20686
21098
|
// Add real token addresses here when available
|
|
20687
21099
|
// {
|
|
@@ -20737,12 +21149,12 @@ function useSmartAccountTransactions() {
|
|
|
20737
21149
|
getTransactionDetails
|
|
20738
21150
|
};
|
|
20739
21151
|
}
|
|
20740
|
-
var
|
|
21152
|
+
var import_viem22, USER_OP_EVENT;
|
|
20741
21153
|
var init_smartAccountTransactions = __esm({
|
|
20742
21154
|
"src/modules/smartAccountTransactions.ts"() {
|
|
20743
|
-
|
|
21155
|
+
import_viem22 = require("viem");
|
|
20744
21156
|
init_SessionContext();
|
|
20745
|
-
USER_OP_EVENT = (0,
|
|
21157
|
+
USER_OP_EVENT = (0, import_viem22.parseAbiItem)(
|
|
20746
21158
|
"event UserOperationEvent(bytes32 indexed userOpHash, address indexed sender, address indexed paymaster, uint256 nonce, bool success, uint256 actualGasCost, uint256 actualGasUsed)"
|
|
20747
21159
|
);
|
|
20748
21160
|
}
|
|
@@ -20795,6 +21207,7 @@ __export(index_exports, {
|
|
|
20795
21207
|
useAssets: () => useAssets,
|
|
20796
21208
|
useBalance: () => useBalance,
|
|
20797
21209
|
useColorMode: () => useColorMode,
|
|
21210
|
+
useDirectWallet: () => useDirectWallet,
|
|
20798
21211
|
useErc3643Compliance: () => useErc3643Compliance,
|
|
20799
21212
|
useError: () => useError,
|
|
20800
21213
|
useHasServerVault: () => useHasServerVault,
|
|
@@ -20808,13 +21221,16 @@ __export(index_exports, {
|
|
|
20808
21221
|
useOpenPage: () => useOpenPage,
|
|
20809
21222
|
useProviderConfig: () => useProviderConfig,
|
|
20810
21223
|
useRecoveryUserId: () => useRecoveryUserId,
|
|
21224
|
+
useSendDirectTransaction: () => useSendDirectTransaction,
|
|
20811
21225
|
useSendTransaction: () => useSendTransaction,
|
|
20812
21226
|
useSession: () => useSession,
|
|
20813
21227
|
useSmartAccountTransactions: () => useSmartAccountTransactions,
|
|
20814
21228
|
useTokenBalance: () => useTokenBalance,
|
|
20815
21229
|
useTokenInfo: () => useTokenInfo,
|
|
20816
21230
|
useTransactions: () => useTransactions,
|
|
21231
|
+
useTransferToLinkedWallet: () => useTransferToLinkedWallet,
|
|
20817
21232
|
useUserOpStatus: () => useUserOpStatus,
|
|
21233
|
+
useWalletMode: () => useWalletMode,
|
|
20818
21234
|
verifyFingerprint: () => verifyFingerprint,
|
|
20819
21235
|
verifyFingerprintDetailed: () => verifyFingerprintDetailed,
|
|
20820
21236
|
wagmiConfig: () => wagmiConfig,
|
|
@@ -20855,6 +21271,10 @@ var init_index = __esm({
|
|
|
20855
21271
|
init_useSendTransaction();
|
|
20856
21272
|
init_useUserOpStatus();
|
|
20857
21273
|
init_useErc3643Compliance();
|
|
21274
|
+
init_useWalletMode();
|
|
21275
|
+
init_useDirectWallet();
|
|
21276
|
+
init_useSendDirectTransaction();
|
|
21277
|
+
init_useTransferToLinkedWallet();
|
|
20858
21278
|
init_useLogout();
|
|
20859
21279
|
init_useNicknameResolve();
|
|
20860
21280
|
init_account();
|
|
@@ -20921,6 +21341,7 @@ init_index();
|
|
|
20921
21341
|
useAssets,
|
|
20922
21342
|
useBalance,
|
|
20923
21343
|
useColorMode,
|
|
21344
|
+
useDirectWallet,
|
|
20924
21345
|
useErc3643Compliance,
|
|
20925
21346
|
useError,
|
|
20926
21347
|
useHasServerVault,
|
|
@@ -20934,13 +21355,16 @@ init_index();
|
|
|
20934
21355
|
useOpenPage,
|
|
20935
21356
|
useProviderConfig,
|
|
20936
21357
|
useRecoveryUserId,
|
|
21358
|
+
useSendDirectTransaction,
|
|
20937
21359
|
useSendTransaction,
|
|
20938
21360
|
useSession,
|
|
20939
21361
|
useSmartAccountTransactions,
|
|
20940
21362
|
useTokenBalance,
|
|
20941
21363
|
useTokenInfo,
|
|
20942
21364
|
useTransactions,
|
|
21365
|
+
useTransferToLinkedWallet,
|
|
20943
21366
|
useUserOpStatus,
|
|
21367
|
+
useWalletMode,
|
|
20944
21368
|
verifyFingerprint,
|
|
20945
21369
|
verifyFingerprintDetailed,
|
|
20946
21370
|
wagmiConfig,
|