@embarkai/ui-kit 0.4.105 → 0.4.106
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 +208 -153
- package/dist/index.d.cts +3 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +160 -95
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -2736,6 +2736,7 @@ declare const PASSPORT_TRANSLATIONS: {
|
|
|
2736
2736
|
connectMenu: {
|
|
2737
2737
|
connectWallet: string;
|
|
2738
2738
|
noWallets: string;
|
|
2739
|
+
requestPending: string;
|
|
2739
2740
|
instructions: {
|
|
2740
2741
|
follow: string;
|
|
2741
2742
|
confirm: string;
|
|
@@ -3323,6 +3324,7 @@ declare const PASSPORT_TRANSLATIONS: {
|
|
|
3323
3324
|
connectMenu: {
|
|
3324
3325
|
connectWallet: string;
|
|
3325
3326
|
noWallets: string;
|
|
3327
|
+
requestPending: string;
|
|
3326
3328
|
instructions: {
|
|
3327
3329
|
follow: string;
|
|
3328
3330
|
confirm: string;
|
|
@@ -3910,6 +3912,7 @@ declare const PASSPORT_TRANSLATIONS: {
|
|
|
3910
3912
|
connectMenu: {
|
|
3911
3913
|
connectWallet: string;
|
|
3912
3914
|
noWallets: string;
|
|
3915
|
+
requestPending: string;
|
|
3913
3916
|
instructions: {
|
|
3914
3917
|
follow: string;
|
|
3915
3918
|
confirm: string;
|
package/dist/index.d.ts
CHANGED
|
@@ -2736,6 +2736,7 @@ declare const PASSPORT_TRANSLATIONS: {
|
|
|
2736
2736
|
connectMenu: {
|
|
2737
2737
|
connectWallet: string;
|
|
2738
2738
|
noWallets: string;
|
|
2739
|
+
requestPending: string;
|
|
2739
2740
|
instructions: {
|
|
2740
2741
|
follow: string;
|
|
2741
2742
|
confirm: string;
|
|
@@ -3323,6 +3324,7 @@ declare const PASSPORT_TRANSLATIONS: {
|
|
|
3323
3324
|
connectMenu: {
|
|
3324
3325
|
connectWallet: string;
|
|
3325
3326
|
noWallets: string;
|
|
3327
|
+
requestPending: string;
|
|
3326
3328
|
instructions: {
|
|
3327
3329
|
follow: string;
|
|
3328
3330
|
confirm: string;
|
|
@@ -3910,6 +3912,7 @@ declare const PASSPORT_TRANSLATIONS: {
|
|
|
3910
3912
|
connectMenu: {
|
|
3911
3913
|
connectWallet: string;
|
|
3912
3914
|
noWallets: string;
|
|
3915
|
+
requestPending: string;
|
|
3913
3916
|
instructions: {
|
|
3914
3917
|
follow: string;
|
|
3915
3918
|
confirm: string;
|
package/dist/index.js
CHANGED
|
@@ -7554,6 +7554,7 @@ var init_en = __esm({
|
|
|
7554
7554
|
connectMenu: {
|
|
7555
7555
|
connectWallet: "Connect Wallet Profile",
|
|
7556
7556
|
noWallets: "No wallets available to connect",
|
|
7557
|
+
requestPending: "{{wallet}} already has a pending request from this site. Open {{wallet}}, reject or close that request, then try again.",
|
|
7557
7558
|
instructions: {
|
|
7558
7559
|
follow: "Watch your connecting wallet app.\nYou will be asked to:\n {{steps}}",
|
|
7559
7560
|
confirm: "- 1. Confirm your wallet connection into embarkAI",
|
|
@@ -8146,6 +8147,7 @@ var init_ru = __esm({
|
|
|
8146
8147
|
connectMenu: {
|
|
8147
8148
|
connectWallet: "\u041F\u043E\u0434\u043A\u043B\u044E\u0447\u0438\u0442\u044C \u043F\u0440\u043E\u0444\u0438\u043B\u044C \u043A\u043E\u0448\u0435\u043B\u044C\u043A\u0430",
|
|
8148
8149
|
noWallets: "\u041D\u0435\u0442 \u0434\u043E\u0441\u0442\u0443\u043F\u043D\u044B\u0445 \u043A\u043E\u0448\u0435\u043B\u044C\u043A\u043E\u0432 \u0434\u043B\u044F \u043F\u043E\u0434\u043A\u043B\u044E\u0447\u0435\u043D\u0438\u044F",
|
|
8150
|
+
requestPending: "\u0412 {{wallet}} \u0443\u0436\u0435 \u0432\u0438\u0441\u0438\u0442 \u0437\u0430\u043F\u0440\u043E\u0441 \u043E\u0442 \u044D\u0442\u043E\u0433\u043E \u0441\u0430\u0439\u0442\u0430. \u041E\u0442\u043A\u0440\u043E\u0439\u0442\u0435 {{wallet}}, \u043E\u0442\u043A\u043B\u043E\u043D\u0438\u0442\u0435 \u0438\u043B\u0438 \u0437\u0430\u043A\u0440\u043E\u0439\u0442\u0435 \u044D\u0442\u043E\u0442 \u0437\u0430\u043F\u0440\u043E\u0441 \u0438 \u043F\u043E\u043F\u0440\u043E\u0431\u0443\u0439\u0442\u0435 \u0441\u043D\u043E\u0432\u0430.",
|
|
8149
8151
|
instructions: {
|
|
8150
8152
|
follow: "\u0421\u043B\u0435\u0434\u0438\u0442\u0435 \u0437\u0430 \u043F\u043E\u0434\u043A\u043B\u044E\u0447\u0430\u0435\u043C\u044B\u043C \u043F\u0440\u0438\u043B\u043E\u0436\u0435\u043D\u0438\u0435\u043C \u043A\u043E\u0448\u0435\u043B\u044C\u043A\u0430.\n\u0412\u0430\u043C \u0431\u0443\u0434\u0435\u0442 \u043F\u0440\u0435\u0434\u043B\u043E\u0436\u0435\u043D\u043E:\n {{steps}}",
|
|
8151
8153
|
confirm: "- 1. \u041F\u043E\u0434\u0442\u0432\u0435\u0440\u0434\u0438\u0442\u044C \u043F\u043E\u0434\u043A\u043B\u044E\u0447\u0435\u043D\u0438\u0435 \u043A\u043E\u0448\u0435\u043B\u044C\u043A\u0430 \u043A embarkAI",
|
|
@@ -8738,6 +8740,7 @@ var init_zh = __esm({
|
|
|
8738
8740
|
connectMenu: {
|
|
8739
8741
|
connectWallet: "\u8FDE\u63A5\u94B1\u5305\u914D\u7F6E\u6587\u4EF6",
|
|
8740
8742
|
noWallets: "\u6CA1\u6709\u53EF\u8FDE\u63A5\u7684\u94B1\u5305",
|
|
8743
|
+
requestPending: "{{wallet}} \u4E2D\u5DF2\u6709\u6765\u81EA\u672C\u7F51\u7AD9\u7684\u5F85\u5904\u7406\u8BF7\u6C42\u3002\u8BF7\u6253\u5F00 {{wallet}}\uFF0C\u62D2\u7EDD\u6216\u5173\u95ED\u8BE5\u8BF7\u6C42\uFF0C\u7136\u540E\u91CD\u8BD5\u3002",
|
|
8741
8744
|
instructions: {
|
|
8742
8745
|
follow: "\u8BF7\u67E5\u770B\u60A8\u6B63\u5728\u8FDE\u63A5\u7684\u94B1\u5305\u5E94\u7528\u3002\n\u60A8\u5C06\u88AB\u8981\u6C42\uFF1A\n {{steps}}",
|
|
8743
8746
|
confirm: "- 1. \u786E\u8BA4\u5C06\u60A8\u7684\u94B1\u5305\u8FDE\u63A5\u5230 embarkAI",
|
|
@@ -16737,6 +16740,7 @@ var init_useLinkTelegram = __esm({
|
|
|
16737
16740
|
|
|
16738
16741
|
// src/internal/components/ManageWalletMenu/ProviderCard.tsx
|
|
16739
16742
|
import { Clock, Link2Icon, LoaderIcon as LoaderIcon8, Trash2Icon, UnplugIcon } from "lucide-react";
|
|
16743
|
+
import { useConnections } from "wagmi";
|
|
16740
16744
|
import { Fragment as Fragment18, jsx as jsx71, jsxs as jsxs62 } from "react/jsx-runtime";
|
|
16741
16745
|
function getProviderCaption(provider) {
|
|
16742
16746
|
const providerName = provider.provider;
|
|
@@ -16759,7 +16763,7 @@ function getProviderCaption(provider) {
|
|
|
16759
16763
|
function ProviderCard(props) {
|
|
16760
16764
|
const { provider, meta, externalId, disabled } = props;
|
|
16761
16765
|
const { t } = useT();
|
|
16762
|
-
const
|
|
16766
|
+
const connections = useConnections();
|
|
16763
16767
|
const {
|
|
16764
16768
|
mutate: connectExternalWallet,
|
|
16765
16769
|
disconnect: disconnectExternalWallet,
|
|
@@ -16781,7 +16785,7 @@ function ProviderCard(props) {
|
|
|
16781
16785
|
};
|
|
16782
16786
|
const info = getProviderDisplayInfo(provider);
|
|
16783
16787
|
const allowUnlink = canUnlink(props);
|
|
16784
|
-
const isWalletProviderConnected =
|
|
16788
|
+
const isWalletProviderConnected = provider === "wallet" && connections.some((c) => c.accounts.includes(externalId));
|
|
16785
16789
|
const IconComponent = provider === "wallet" ? WALLET_ICONS[meta?.walletType || "default"] || WALLET_ICONS.default : info.icon;
|
|
16786
16790
|
return /* @__PURE__ */ jsxs62("div", { className: "w-full flex items-center justify-between gap-[var(--ui-kit-gap)]", children: [
|
|
16787
16791
|
/* @__PURE__ */ jsx71(
|
|
@@ -16874,7 +16878,6 @@ var init_ProviderCard = __esm({
|
|
|
16874
16878
|
init_useT();
|
|
16875
16879
|
init_wallets();
|
|
16876
16880
|
init_types();
|
|
16877
|
-
init_useExternalWalletStore();
|
|
16878
16881
|
init_cn();
|
|
16879
16882
|
init_ConnectExternalWalletMenu2();
|
|
16880
16883
|
init_button();
|
|
@@ -17269,26 +17272,67 @@ var init_useHasInjectedWallet = __esm({
|
|
|
17269
17272
|
import { useMutation as useMutation10, useQuery as useQuery9, useQueryClient as useQueryClient14 } from "@tanstack/react-query";
|
|
17270
17273
|
import { ArrowLeft as ArrowLeft8, Loader as Loader11, Wallet2Icon as Wallet2Icon2 } from "lucide-react";
|
|
17271
17274
|
import { useCallback as useCallback17, useMemo as useMemo9, useState as useState14 } from "react";
|
|
17272
|
-
import {
|
|
17275
|
+
import {
|
|
17276
|
+
useConfig,
|
|
17277
|
+
useConnect,
|
|
17278
|
+
useConnections as useConnections2,
|
|
17279
|
+
useConnectors,
|
|
17280
|
+
useDisconnect as useDisconnect2,
|
|
17281
|
+
useSignMessage,
|
|
17282
|
+
useSwitchChain,
|
|
17283
|
+
useSwitchConnection
|
|
17284
|
+
} from "wagmi";
|
|
17285
|
+
import { mainnet } from "wagmi/chains";
|
|
17273
17286
|
import { jsx as jsx74, jsxs as jsxs65 } from "react/jsx-runtime";
|
|
17274
17287
|
function getConnectFlowType(params) {
|
|
17275
17288
|
const { isEmbarkAI, connectFlow } = params;
|
|
17276
17289
|
if (!isEmbarkAI) return "auth";
|
|
17277
17290
|
return connectFlow;
|
|
17278
17291
|
}
|
|
17292
|
+
function someInErrorChain(error, predicate) {
|
|
17293
|
+
let current = error;
|
|
17294
|
+
for (let depth = 0; current && depth < 10; depth++) {
|
|
17295
|
+
if (predicate(current)) return true;
|
|
17296
|
+
current = current.cause;
|
|
17297
|
+
}
|
|
17298
|
+
return false;
|
|
17299
|
+
}
|
|
17279
17300
|
function ConnectExternalWalletMenu() {
|
|
17280
17301
|
const { config, callbacksRef } = useProviderConfig();
|
|
17281
17302
|
const allowedWallets = config.current?.wallet?.allowedWallets;
|
|
17282
17303
|
const walletMode = config.current?.wallet?.mode || "both";
|
|
17283
17304
|
const qc = useQueryClient14();
|
|
17284
17305
|
const { t } = useT();
|
|
17285
|
-
const
|
|
17286
|
-
const {
|
|
17306
|
+
const embarkAiAddress = useSession((st) => st.address);
|
|
17307
|
+
const { close: closeEmbarkAI } = useOpenPage();
|
|
17287
17308
|
const menuParams = useConnectExternalWalletMenuParams();
|
|
17288
17309
|
const connectors = useConnectors();
|
|
17289
17310
|
const hasInjectedWallet2 = useHasInjectedWallet();
|
|
17290
|
-
const
|
|
17311
|
+
const wagmiConfig3 = useConfig();
|
|
17312
|
+
const connections = useConnections2();
|
|
17313
|
+
const { mutate: disconnect, mutateAsync: disconnectAsync } = useDisconnect2();
|
|
17291
17314
|
const { mutateAsync: signMessageAsync } = useSignMessage();
|
|
17315
|
+
const { mutateAsync: switchChainAsync } = useSwitchChain();
|
|
17316
|
+
const { mutateAsync: switchConnectionAsync } = useSwitchConnection();
|
|
17317
|
+
const [isPreparingConnect, setIsPreparingConnect] = useState14(false);
|
|
17318
|
+
const signOnSupportedChain = async (params) => {
|
|
17319
|
+
const { connector, account, message } = params;
|
|
17320
|
+
const signOnce = async (viaFallback = false) => {
|
|
17321
|
+
let chainId = await connector.getChainId();
|
|
17322
|
+
if (viaFallback) {
|
|
17323
|
+
await switchChainAsync({ connector, chainId: SIGN_FALLBACK_CHAIN_ID });
|
|
17324
|
+
chainId = SIGN_FALLBACK_CHAIN_ID;
|
|
17325
|
+
}
|
|
17326
|
+
const signature = await signMessageAsync({ connector, account, message });
|
|
17327
|
+
return { chainId, signature };
|
|
17328
|
+
};
|
|
17329
|
+
try {
|
|
17330
|
+
return await signOnce(false);
|
|
17331
|
+
} catch (error) {
|
|
17332
|
+
if (!isUnsupportedChainError(error)) throw error;
|
|
17333
|
+
return await signOnce(true);
|
|
17334
|
+
}
|
|
17335
|
+
};
|
|
17292
17336
|
const walletMenuOpenedFrom = useLayoutDataStore((st) => st.walletMenuOpenedFrom);
|
|
17293
17337
|
const { data: providers = [] } = useQuery9({
|
|
17294
17338
|
retry: false,
|
|
@@ -17308,7 +17352,24 @@ function ConnectExternalWalletMenu() {
|
|
|
17308
17352
|
callbacksRef.current?.onAccountUpdate?.({ providers: providers2 });
|
|
17309
17353
|
}
|
|
17310
17354
|
});
|
|
17311
|
-
const
|
|
17355
|
+
const keepOrReleaseExternalWallet = (connector, address, chainId) => {
|
|
17356
|
+
if (walletMode === "direct" || walletMode === "both") {
|
|
17357
|
+
useExternalWalletStore.getState().setExternalWallet({
|
|
17358
|
+
address,
|
|
17359
|
+
chainId,
|
|
17360
|
+
connectorName: connector.name || "Unknown Wallet"
|
|
17361
|
+
});
|
|
17362
|
+
} else {
|
|
17363
|
+
disconnect();
|
|
17364
|
+
const { externalAddress, clearExternalWallet } = useExternalWalletStore.getState();
|
|
17365
|
+
if (!!externalAddress) clearExternalWallet();
|
|
17366
|
+
}
|
|
17367
|
+
};
|
|
17368
|
+
const completeExternalConnect = (connector, address, chainId) => {
|
|
17369
|
+
useLayoutDataStore.getState().setPage(walletMenuOpenedFrom || "main-menu" /* MAIN_MENU */);
|
|
17370
|
+
keepOrReleaseExternalWallet(connector, address, chainId);
|
|
17371
|
+
};
|
|
17372
|
+
const { mutateAsync: loginOrLinkWallet, isPending: isLoginOrLinkWallet } = useMutation10({
|
|
17312
17373
|
mutationFn: async (payload) => {
|
|
17313
17374
|
const { walletData, connectFlowType } = payload;
|
|
17314
17375
|
switch (connectFlowType) {
|
|
@@ -17323,13 +17384,9 @@ function ConnectExternalWalletMenu() {
|
|
|
17323
17384
|
await linkWallet(walletData);
|
|
17324
17385
|
await onLinkingComplete(true);
|
|
17325
17386
|
return { linked: true, message: `Address ${walletData.address} linked` };
|
|
17326
|
-
// Connect external wallet flow, only if embarkAI is connected
|
|
17327
|
-
case "connect":
|
|
17328
|
-
return null;
|
|
17329
17387
|
}
|
|
17330
17388
|
},
|
|
17331
17389
|
onSuccess: async (response, { walletData, connector, connectFlowType }) => {
|
|
17332
|
-
let shouldKeepConnected = walletMode === "direct" || walletMode === "both";
|
|
17333
17390
|
switch (connectFlowType) {
|
|
17334
17391
|
case "auth":
|
|
17335
17392
|
useLayoutDataStore.getState().setPendingWalletLogin(response);
|
|
@@ -17339,23 +17396,11 @@ function ConnectExternalWalletMenu() {
|
|
|
17339
17396
|
const { linked, message } = response || {};
|
|
17340
17397
|
if (!linked && message.includes("already linked")) {
|
|
17341
17398
|
console.warn("[LINK STATUS] already linked", response);
|
|
17342
|
-
|
|
17343
|
-
useLayoutDataStore.getState().setPage(walletMenuOpenedFrom || "manage-wallet" /* MANAGE_WALLET */);
|
|
17399
|
+
await onLinkingComplete(false);
|
|
17344
17400
|
}
|
|
17345
17401
|
break;
|
|
17346
|
-
case "connect":
|
|
17347
|
-
useLayoutDataStore.getState().setPage(walletMenuOpenedFrom || "main-menu" /* MAIN_MENU */);
|
|
17348
|
-
break;
|
|
17349
|
-
}
|
|
17350
|
-
if (shouldKeepConnected && walletData.chainId && connector) {
|
|
17351
|
-
useExternalWalletStore.getState().setExternalWallet({
|
|
17352
|
-
address: walletData.address,
|
|
17353
|
-
chainId: walletData.chainId,
|
|
17354
|
-
connectorName: connector.name || "Unknown Wallet"
|
|
17355
|
-
});
|
|
17356
|
-
} else {
|
|
17357
|
-
disconnect();
|
|
17358
17402
|
}
|
|
17403
|
+
keepOrReleaseExternalWallet(connector, walletData.address, walletData.chainId);
|
|
17359
17404
|
useLayoutStore.getState().setIsDialogForced(false);
|
|
17360
17405
|
},
|
|
17361
17406
|
onError: async (err, { walletData, connectFlowType }) => {
|
|
@@ -17370,9 +17415,6 @@ function ConnectExternalWalletMenu() {
|
|
|
17370
17415
|
useManageWalletStore.getState().setAlert({ title: "Error", message: errorMsg });
|
|
17371
17416
|
await onLinkingComplete(false);
|
|
17372
17417
|
break;
|
|
17373
|
-
case "connect":
|
|
17374
|
-
openEmbarkAI(walletMenuOpenedFrom || "main-menu" /* MAIN_MENU */);
|
|
17375
|
-
break;
|
|
17376
17418
|
}
|
|
17377
17419
|
}
|
|
17378
17420
|
});
|
|
@@ -17382,75 +17424,75 @@ function ConnectExternalWalletMenu() {
|
|
|
17382
17424
|
variables: pendingConnectVariables
|
|
17383
17425
|
} = useConnect({
|
|
17384
17426
|
mutation: {
|
|
17385
|
-
onSuccess: async (
|
|
17386
|
-
const
|
|
17387
|
-
const projectId = config.current?.projectId;
|
|
17388
|
-
const projectName = projectId ? await fetchProjectName(projectId) : "EmbarkAI";
|
|
17427
|
+
onSuccess: async ({ chainId, accounts }, variables) => {
|
|
17428
|
+
const connector = variables.connector;
|
|
17389
17429
|
const signingWalletAddress = accounts[0];
|
|
17390
17430
|
const connectFlowType = getConnectFlowType({
|
|
17391
17431
|
isEmbarkAI: !!embarkAiAddress,
|
|
17392
17432
|
connectFlow: menuParams.current?.connectFlowType || "auth"
|
|
17393
17433
|
});
|
|
17394
|
-
|
|
17395
|
-
|
|
17396
|
-
|
|
17397
|
-
|
|
17398
|
-
message = createLoginMessage(signingWalletAddress, projectName);
|
|
17399
|
-
signature = await signMessageAsync({ message, account: signingWalletAddress });
|
|
17400
|
-
break;
|
|
17401
|
-
case "link":
|
|
17402
|
-
message = createSignatureMessage(signingWalletAddress, projectName);
|
|
17403
|
-
signature = await signMessageAsync({ message, account: signingWalletAddress });
|
|
17404
|
-
break;
|
|
17405
|
-
case "connect":
|
|
17406
|
-
message = "UNUSED_MESSAGE";
|
|
17407
|
-
signature = "0xUNUSED_SIGNATURE";
|
|
17408
|
-
break;
|
|
17409
|
-
}
|
|
17410
|
-
if (!message || !signature) {
|
|
17411
|
-
throw new Error("Failed to get sign message & signature");
|
|
17434
|
+
if (connectFlowType === "connect") {
|
|
17435
|
+
completeExternalConnect(connector, signingWalletAddress, chainId);
|
|
17436
|
+
useLayoutStore.getState().setIsDialogForced(false);
|
|
17437
|
+
return;
|
|
17412
17438
|
}
|
|
17413
|
-
|
|
17439
|
+
const projectId = config.current?.projectId;
|
|
17440
|
+
const projectName = projectId ? await fetchProjectName(projectId) : "EmbarkAI";
|
|
17441
|
+
const createMessage = connectFlowType === "auth" ? createLoginMessage : createSignatureMessage;
|
|
17442
|
+
const message = createMessage(signingWalletAddress, projectName);
|
|
17443
|
+
const { signature, chainId: signedChainId } = await signOnSupportedChain({
|
|
17444
|
+
connector,
|
|
17445
|
+
account: signingWalletAddress,
|
|
17446
|
+
message
|
|
17447
|
+
});
|
|
17448
|
+
await loginOrLinkWallet({
|
|
17414
17449
|
connector,
|
|
17415
17450
|
connectFlowType,
|
|
17416
17451
|
walletData: {
|
|
17417
|
-
chainId,
|
|
17452
|
+
chainId: signedChainId,
|
|
17418
17453
|
address: signingWalletAddress,
|
|
17419
17454
|
signature,
|
|
17420
17455
|
message,
|
|
17421
|
-
walletName: connector
|
|
17422
|
-
|
|
17423
|
-
walletType: connector?.id || "unknown"
|
|
17456
|
+
walletName: connector.name || "Unknown Wallet",
|
|
17457
|
+
walletType: connector.id || "unknown"
|
|
17424
17458
|
}
|
|
17425
17459
|
});
|
|
17426
17460
|
},
|
|
17427
|
-
onError: (error, { connector }) =>
|
|
17428
|
-
const connectFlowType = getConnectFlowType({
|
|
17429
|
-
isEmbarkAI: !!embarkAiAddress,
|
|
17430
|
-
connectFlow: menuParams.current?.connectFlowType || "auth"
|
|
17431
|
-
});
|
|
17432
|
-
const setPage = useLayoutDataStore.getState().setPage;
|
|
17433
|
-
setTimeout(() => {
|
|
17434
|
-
switch (connectFlowType) {
|
|
17435
|
-
case "auth":
|
|
17436
|
-
setConnectError(error?.message || "Failed to connect wallet");
|
|
17437
|
-
break;
|
|
17438
|
-
case "link":
|
|
17439
|
-
setPage("manage-wallet" /* MANAGE_WALLET */);
|
|
17440
|
-
useManageWalletStore.getState().setAlert({
|
|
17441
|
-
title: `Failed to connect: ${connector.name}`,
|
|
17442
|
-
message: error?.message || "Failed to connect wallet before linking"
|
|
17443
|
-
});
|
|
17444
|
-
break;
|
|
17445
|
-
case "connect":
|
|
17446
|
-
setConnectError(error?.message || "Failed to connect wallet");
|
|
17447
|
-
break;
|
|
17448
|
-
}
|
|
17449
|
-
useLayoutStore.getState().setIsDialogForced(false);
|
|
17450
|
-
}, 100);
|
|
17451
|
-
}
|
|
17461
|
+
onError: (error, { connector }) => reportConnectError(error, connector)
|
|
17452
17462
|
}
|
|
17453
17463
|
});
|
|
17464
|
+
function reportConnectError(error, connector) {
|
|
17465
|
+
const connectFlowType = getConnectFlowType({
|
|
17466
|
+
isEmbarkAI: !!embarkAiAddress,
|
|
17467
|
+
connectFlow: menuParams.current?.connectFlowType || "auth"
|
|
17468
|
+
});
|
|
17469
|
+
const isRequestPending = isRequestPendingError(error);
|
|
17470
|
+
if (!isRequestPending && connectFlowType !== "connect" && wagmiConfig3.state.connections.has(connector.uid)) {
|
|
17471
|
+
disconnect({ connector });
|
|
17472
|
+
}
|
|
17473
|
+
const errorMessage = isRequestPending ? (
|
|
17474
|
+
// @ts-expect-error i18n typing
|
|
17475
|
+
t("passport:connectMenu.requestPending", { wallet: connector.name })
|
|
17476
|
+
) : error?.message;
|
|
17477
|
+
setTimeout(() => {
|
|
17478
|
+
switch (connectFlowType) {
|
|
17479
|
+
case "auth":
|
|
17480
|
+
setConnectError(errorMessage || "Failed to connect wallet");
|
|
17481
|
+
break;
|
|
17482
|
+
case "link":
|
|
17483
|
+
useLayoutDataStore.getState().setPage("manage-wallet" /* MANAGE_WALLET */);
|
|
17484
|
+
useManageWalletStore.getState().setAlert({
|
|
17485
|
+
title: `Failed to connect: ${connector.name}`,
|
|
17486
|
+
message: errorMessage || "Failed to connect wallet before linking"
|
|
17487
|
+
});
|
|
17488
|
+
break;
|
|
17489
|
+
case "connect":
|
|
17490
|
+
setConnectError(errorMessage || "Failed to connect wallet");
|
|
17491
|
+
break;
|
|
17492
|
+
}
|
|
17493
|
+
useLayoutStore.getState().setIsDialogForced(false);
|
|
17494
|
+
}, 100);
|
|
17495
|
+
}
|
|
17454
17496
|
const visibleConnectors = useMemo9(() => {
|
|
17455
17497
|
const seen = /* @__PURE__ */ new Set();
|
|
17456
17498
|
const unique = connectors.filter((connector) => {
|
|
@@ -17490,7 +17532,7 @@ function ConnectExternalWalletMenu() {
|
|
|
17490
17532
|
variant: "ghost",
|
|
17491
17533
|
size: "icon",
|
|
17492
17534
|
title: t("passport:common.back"),
|
|
17493
|
-
disabled: isConnectingExternalWallet ||
|
|
17535
|
+
disabled: isConnectingExternalWallet || isLoginOrLinkWallet,
|
|
17494
17536
|
onClick: () => useLayoutDataStore.getState().setPage(walletMenuOpenedFrom ?? "main-menu" /* MAIN_MENU */),
|
|
17495
17537
|
children: /* @__PURE__ */ jsx74(ArrowLeft8, { className: "h-4 w-4" })
|
|
17496
17538
|
}
|
|
@@ -17507,14 +17549,32 @@ function ConnectExternalWalletMenu() {
|
|
|
17507
17549
|
variant: "secondary",
|
|
17508
17550
|
size: "large",
|
|
17509
17551
|
className: "w-full justify-center",
|
|
17510
|
-
disabled: isConnectingExternalWallet,
|
|
17552
|
+
disabled: isConnectingExternalWallet || isPreparingConnect || isLoginOrLinkWallet,
|
|
17511
17553
|
onClick: async () => {
|
|
17512
17554
|
if (connectError) setConnectError(null);
|
|
17555
|
+
const connectFlowType = getConnectFlowType({
|
|
17556
|
+
isEmbarkAI: !!embarkAiAddress,
|
|
17557
|
+
connectFlow: menuParams.current?.connectFlowType || "auth"
|
|
17558
|
+
});
|
|
17559
|
+
setIsPreparingConnect(true);
|
|
17513
17560
|
try {
|
|
17514
|
-
|
|
17515
|
-
|
|
17561
|
+
const existingConnection = connections.find((c) => c.connector.uid === connector.uid);
|
|
17562
|
+
if (connectFlowType === "connect" && existingConnection?.accounts[0]) {
|
|
17563
|
+
await switchConnectionAsync({ connector });
|
|
17564
|
+
completeExternalConnect(connector, existingConnection.accounts[0], existingConnection.chainId);
|
|
17565
|
+
useLayoutStore.getState().setIsDialogForced(false);
|
|
17566
|
+
return;
|
|
17567
|
+
}
|
|
17568
|
+
const connectionsToDrop = connections.filter((c) => c.connector.uid === connector.uid);
|
|
17569
|
+
for (const { connector: connectedConnector } of connectionsToDrop) {
|
|
17570
|
+
await disconnectAsync({ connector: connectedConnector });
|
|
17571
|
+
}
|
|
17572
|
+
} catch (error) {
|
|
17573
|
+
reportConnectError(error, connector);
|
|
17574
|
+
return;
|
|
17575
|
+
} finally {
|
|
17576
|
+
setIsPreparingConnect(false);
|
|
17516
17577
|
}
|
|
17517
|
-
await new Promise((resolve) => setTimeout(resolve, 500));
|
|
17518
17578
|
switch (true) {
|
|
17519
17579
|
case (connector.id === "metaMaskSDK" && !hasInjectedWallet2):
|
|
17520
17580
|
closeEmbarkAI();
|
|
@@ -17566,6 +17626,7 @@ function ConnectExternalWalletMenu() {
|
|
|
17566
17626
|
] })
|
|
17567
17627
|
] });
|
|
17568
17628
|
}
|
|
17629
|
+
var SIGN_FALLBACK_CHAIN_ID, REQUEST_PENDING_ERROR_CODE, isRequestPendingError, isUnsupportedChainError;
|
|
17569
17630
|
var init_ConnectExternalWalletMenu = __esm({
|
|
17570
17631
|
"src/internal/components/ConnectExternalWalletMenu/ConnectExternalWalletMenu.tsx"() {
|
|
17571
17632
|
init_ProviderContext();
|
|
@@ -17585,6 +17646,10 @@ var init_ConnectExternalWalletMenu = __esm({
|
|
|
17585
17646
|
init_highlight();
|
|
17586
17647
|
init_useConnectExternalWalletMenuParams();
|
|
17587
17648
|
init_useHasInjectedWallet();
|
|
17649
|
+
SIGN_FALLBACK_CHAIN_ID = mainnet.id;
|
|
17650
|
+
REQUEST_PENDING_ERROR_CODE = -32002;
|
|
17651
|
+
isRequestPendingError = (error) => someInErrorChain(error, (e) => e.code === REQUEST_PENDING_ERROR_CODE);
|
|
17652
|
+
isUnsupportedChainError = (error) => someInErrorChain(error, (e) => typeof e.message === "string" && e.message.includes("supportedNetworks"));
|
|
17588
17653
|
}
|
|
17589
17654
|
});
|
|
17590
17655
|
|
|
@@ -25340,13 +25405,13 @@ var init_useOperationHashesStore = __esm({
|
|
|
25340
25405
|
// src/internal/components/SendMenu/hyperbridge/hooks/useBridge.ts
|
|
25341
25406
|
import { useMutation as useMutation20, useQueryClient as useQueryClient25 } from "@tanstack/react-query";
|
|
25342
25407
|
import { useCallback as useCallback28 } from "react";
|
|
25343
|
-
import { useSwitchChain, useWalletClient } from "wagmi";
|
|
25408
|
+
import { useSwitchChain as useSwitchChain2, useWalletClient } from "wagmi";
|
|
25344
25409
|
function useBridge() {
|
|
25345
25410
|
const qc = useQueryClient25();
|
|
25346
25411
|
const { t } = useT();
|
|
25347
25412
|
const address = useSession((st) => st.address);
|
|
25348
25413
|
const { data: walletClient } = useWalletClient();
|
|
25349
|
-
const { mutateAsync: switchChainAsync } =
|
|
25414
|
+
const { mutateAsync: switchChainAsync } = useSwitchChain2();
|
|
25350
25415
|
const swapDirection = useCallback28(() => {
|
|
25351
25416
|
const {
|
|
25352
25417
|
// bridgeStep,
|
|
@@ -25818,7 +25883,7 @@ import { CHAINS_BROWSERS_TRANSPORTS as CHAINS_BROWSERS_TRANSPORTS2 } from "@emba
|
|
|
25818
25883
|
import { useQuery as useQuery25, useQueryClient as useQueryClient26 } from "@tanstack/react-query";
|
|
25819
25884
|
import { useCallback as useCallback29, useEffect as useEffect45 } from "react";
|
|
25820
25885
|
import { createPublicClient as createPublicClient2, erc20Abi as erc20Abi3, formatUnits as formatUnits9, http as http3 } from "viem";
|
|
25821
|
-
import { useSwitchChain as
|
|
25886
|
+
import { useSwitchChain as useSwitchChain3 } from "wagmi";
|
|
25822
25887
|
function useBridgeBalance(isLoadingWarpRoutes, hyperlaneWarpRoutes) {
|
|
25823
25888
|
const qc = useQueryClient26();
|
|
25824
25889
|
const { t } = useT();
|
|
@@ -25826,7 +25891,7 @@ function useBridgeBalance(isLoadingWarpRoutes, hyperlaneWarpRoutes) {
|
|
|
25826
25891
|
const activeChainId = useSession((st) => st.activeChainId);
|
|
25827
25892
|
const directWalletAddress = useExternalWalletStore((st) => st.externalAddress);
|
|
25828
25893
|
const directWalletChainId = useExternalWalletStore((st) => st.externalChainId);
|
|
25829
|
-
const { mutateAsync: switchChainAsync } =
|
|
25894
|
+
const { mutateAsync: switchChainAsync } = useSwitchChain3();
|
|
25830
25895
|
const hyperRoute = useBridgeStore((st) => st.hyperRoute);
|
|
25831
25896
|
const bridgeSender = useBridgeStore((st) => st.bridgeSender);
|
|
25832
25897
|
const originChain = useBridgeStore((st) => st.originChain);
|
|
@@ -29847,7 +29912,7 @@ var init_package = __esm({
|
|
|
29847
29912
|
"package.json"() {
|
|
29848
29913
|
package_default = {
|
|
29849
29914
|
name: "@embarkai/ui-kit",
|
|
29850
|
-
version: "0.4.
|
|
29915
|
+
version: "0.4.106",
|
|
29851
29916
|
description: "React UI components and hooks for EmbarkAI authentication and Account Abstraction",
|
|
29852
29917
|
type: "module",
|
|
29853
29918
|
main: "./dist/index.cjs",
|
|
@@ -30608,12 +30673,12 @@ var init_Dialog2 = __esm({
|
|
|
30608
30673
|
|
|
30609
30674
|
// src/internal/components/DirectWalletHandler.tsx
|
|
30610
30675
|
import { useEffect as useEffect55 } from "react";
|
|
30611
|
-
import { useConnection
|
|
30676
|
+
import { useConnection } from "wagmi";
|
|
30612
30677
|
function DirectWalletHandler() {
|
|
30613
30678
|
const walletMode = useProviderConfig().config.current?.wallet?.mode || "both";
|
|
30614
30679
|
const externalAddress = useExternalWalletStore((st) => st.externalAddress);
|
|
30615
30680
|
const isExternalConnected = useExternalWalletStore((st) => st.isExternalConnected);
|
|
30616
|
-
const { address, isConnected, chain, connector } =
|
|
30681
|
+
const { address, isConnected, chain, connector } = useConnection();
|
|
30617
30682
|
useEffect55(() => {
|
|
30618
30683
|
const { setConfigMode, setActiveMode } = useExternalWalletStore.getState();
|
|
30619
30684
|
setConfigMode(walletMode);
|
|
@@ -34387,12 +34452,12 @@ function useDirectWallet() {
|
|
|
34387
34452
|
init_useExternalWalletStore();
|
|
34388
34453
|
import { useCallback as useCallback40, useState as useState39 } from "react";
|
|
34389
34454
|
import { isAddress as isAddress4, parseEther as parseEther3 } from "viem";
|
|
34390
|
-
import { useSendTransaction as useWagmiSendTransaction, useSwitchChain as
|
|
34455
|
+
import { useSendTransaction as useWagmiSendTransaction, useSwitchChain as useSwitchChain4 } from "wagmi";
|
|
34391
34456
|
function useSendDirectTransaction() {
|
|
34392
34457
|
const isConnected = useExternalWalletStore((st) => st.isExternalConnected);
|
|
34393
34458
|
const externalChainId = useExternalWalletStore((st) => st.externalChainId);
|
|
34394
34459
|
const { sendTransactionAsync } = useWagmiSendTransaction();
|
|
34395
|
-
const { switchChainAsync } =
|
|
34460
|
+
const { switchChainAsync } = useSwitchChain4();
|
|
34396
34461
|
const [isPending, setIsPending] = useState39(false);
|
|
34397
34462
|
const [error, setError] = useState39(null);
|
|
34398
34463
|
const [txHash, setTxHash] = useState39(null);
|