@embarkai/ui-kit 0.4.105 → 0.4.107
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 +226 -161
- package/dist/index.d.cts +3 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +178 -103
- 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,16 +16763,19 @@ 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,
|
|
16766
16770
|
isPending: isConnectingExternalWallet,
|
|
16767
16771
|
variables: pendingConnectVariables,
|
|
16768
16772
|
isAvailable: isConnectExternalWalletAvailable
|
|
16769
|
-
} = useExternalWalletConnnect(
|
|
16770
|
-
|
|
16771
|
-
|
|
16773
|
+
} = useExternalWalletConnnect({
|
|
16774
|
+
// onSuccess: undefined,
|
|
16775
|
+
onError: ({ connector, error }) => {
|
|
16776
|
+
console.warn("[useExternalWalletConnect]", connector, error);
|
|
16777
|
+
}
|
|
16778
|
+
});
|
|
16772
16779
|
const { data: providers = [] } = useProvidersList();
|
|
16773
16780
|
if (!provider) {
|
|
16774
16781
|
console.warn("[ProviderCard] Received undefined provider");
|
|
@@ -16781,7 +16788,7 @@ function ProviderCard(props) {
|
|
|
16781
16788
|
};
|
|
16782
16789
|
const info = getProviderDisplayInfo(provider);
|
|
16783
16790
|
const allowUnlink = canUnlink(props);
|
|
16784
|
-
const isWalletProviderConnected =
|
|
16791
|
+
const isWalletProviderConnected = provider === "wallet" && connections.some((c) => c.accounts.includes(externalId));
|
|
16785
16792
|
const IconComponent = provider === "wallet" ? WALLET_ICONS[meta?.walletType || "default"] || WALLET_ICONS.default : info.icon;
|
|
16786
16793
|
return /* @__PURE__ */ jsxs62("div", { className: "w-full flex items-center justify-between gap-[var(--ui-kit-gap)]", children: [
|
|
16787
16794
|
/* @__PURE__ */ jsx71(
|
|
@@ -16859,8 +16866,8 @@ function ProviderCard(props) {
|
|
|
16859
16866
|
disabled: disabled || isConnectingExternalWallet,
|
|
16860
16867
|
title: t("passport:common.delete"),
|
|
16861
16868
|
onClick: () => {
|
|
16862
|
-
setConfirmUnlink({ provider, providerName: info.name, externalId });
|
|
16863
|
-
setPage("unlink-provider" /* UNLINK_PROVIDER */);
|
|
16869
|
+
useManageWalletStore.getState().setConfirmUnlink({ provider, providerName: info.name, externalId });
|
|
16870
|
+
useLayoutDataStore.getState().setPage("unlink-provider" /* UNLINK_PROVIDER */);
|
|
16864
16871
|
},
|
|
16865
16872
|
children: /* @__PURE__ */ jsx71(Trash2Icon, { className: "w-4 h-4 text-[var(--ui-kit-bg-error)]" })
|
|
16866
16873
|
}
|
|
@@ -16874,7 +16881,6 @@ var init_ProviderCard = __esm({
|
|
|
16874
16881
|
init_useT();
|
|
16875
16882
|
init_wallets();
|
|
16876
16883
|
init_types();
|
|
16877
|
-
init_useExternalWalletStore();
|
|
16878
16884
|
init_cn();
|
|
16879
16885
|
init_ConnectExternalWalletMenu2();
|
|
16880
16886
|
init_button();
|
|
@@ -17269,26 +17275,67 @@ var init_useHasInjectedWallet = __esm({
|
|
|
17269
17275
|
import { useMutation as useMutation10, useQuery as useQuery9, useQueryClient as useQueryClient14 } from "@tanstack/react-query";
|
|
17270
17276
|
import { ArrowLeft as ArrowLeft8, Loader as Loader11, Wallet2Icon as Wallet2Icon2 } from "lucide-react";
|
|
17271
17277
|
import { useCallback as useCallback17, useMemo as useMemo9, useState as useState14 } from "react";
|
|
17272
|
-
import {
|
|
17278
|
+
import {
|
|
17279
|
+
useConfig,
|
|
17280
|
+
useConnect,
|
|
17281
|
+
useConnections as useConnections2,
|
|
17282
|
+
useConnectors,
|
|
17283
|
+
useDisconnect as useDisconnect2,
|
|
17284
|
+
useSignMessage,
|
|
17285
|
+
useSwitchChain,
|
|
17286
|
+
useSwitchConnection
|
|
17287
|
+
} from "wagmi";
|
|
17288
|
+
import { mainnet } from "wagmi/chains";
|
|
17273
17289
|
import { jsx as jsx74, jsxs as jsxs65 } from "react/jsx-runtime";
|
|
17274
17290
|
function getConnectFlowType(params) {
|
|
17275
17291
|
const { isEmbarkAI, connectFlow } = params;
|
|
17276
17292
|
if (!isEmbarkAI) return "auth";
|
|
17277
17293
|
return connectFlow;
|
|
17278
17294
|
}
|
|
17295
|
+
function someInErrorChain(error, predicate) {
|
|
17296
|
+
let current = error;
|
|
17297
|
+
for (let depth = 0; current && depth < 10; depth++) {
|
|
17298
|
+
if (predicate(current)) return true;
|
|
17299
|
+
current = current.cause;
|
|
17300
|
+
}
|
|
17301
|
+
return false;
|
|
17302
|
+
}
|
|
17279
17303
|
function ConnectExternalWalletMenu() {
|
|
17280
17304
|
const { config, callbacksRef } = useProviderConfig();
|
|
17281
17305
|
const allowedWallets = config.current?.wallet?.allowedWallets;
|
|
17282
17306
|
const walletMode = config.current?.wallet?.mode || "both";
|
|
17283
17307
|
const qc = useQueryClient14();
|
|
17284
17308
|
const { t } = useT();
|
|
17285
|
-
const
|
|
17286
|
-
const {
|
|
17309
|
+
const embarkAiAddress = useSession((st) => st.address);
|
|
17310
|
+
const { close: closeEmbarkAI } = useOpenPage();
|
|
17287
17311
|
const menuParams = useConnectExternalWalletMenuParams();
|
|
17288
17312
|
const connectors = useConnectors();
|
|
17289
17313
|
const hasInjectedWallet2 = useHasInjectedWallet();
|
|
17290
|
-
const
|
|
17314
|
+
const wagmiConfig3 = useConfig();
|
|
17315
|
+
const connections = useConnections2();
|
|
17316
|
+
const { mutate: disconnect, mutateAsync: disconnectAsync } = useDisconnect2();
|
|
17291
17317
|
const { mutateAsync: signMessageAsync } = useSignMessage();
|
|
17318
|
+
const { mutateAsync: switchChainAsync } = useSwitchChain();
|
|
17319
|
+
const { mutateAsync: switchConnectionAsync } = useSwitchConnection();
|
|
17320
|
+
const [isPreparingConnect, setIsPreparingConnect] = useState14(false);
|
|
17321
|
+
const signOnSupportedChain = async (params) => {
|
|
17322
|
+
const { connector, account, message } = params;
|
|
17323
|
+
const signOnce = async (viaFallback = false) => {
|
|
17324
|
+
let chainId = await connector.getChainId();
|
|
17325
|
+
if (viaFallback) {
|
|
17326
|
+
await switchChainAsync({ connector, chainId: SIGN_FALLBACK_CHAIN_ID });
|
|
17327
|
+
chainId = SIGN_FALLBACK_CHAIN_ID;
|
|
17328
|
+
}
|
|
17329
|
+
const signature = await signMessageAsync({ connector, account, message });
|
|
17330
|
+
return { chainId, signature };
|
|
17331
|
+
};
|
|
17332
|
+
try {
|
|
17333
|
+
return await signOnce(false);
|
|
17334
|
+
} catch (error) {
|
|
17335
|
+
if (!isUnsupportedChainError(error)) throw error;
|
|
17336
|
+
return await signOnce(true);
|
|
17337
|
+
}
|
|
17338
|
+
};
|
|
17292
17339
|
const walletMenuOpenedFrom = useLayoutDataStore((st) => st.walletMenuOpenedFrom);
|
|
17293
17340
|
const { data: providers = [] } = useQuery9({
|
|
17294
17341
|
retry: false,
|
|
@@ -17308,7 +17355,24 @@ function ConnectExternalWalletMenu() {
|
|
|
17308
17355
|
callbacksRef.current?.onAccountUpdate?.({ providers: providers2 });
|
|
17309
17356
|
}
|
|
17310
17357
|
});
|
|
17311
|
-
const
|
|
17358
|
+
const keepOrReleaseExternalWallet = (connector, address, chainId) => {
|
|
17359
|
+
if (walletMode === "direct" || walletMode === "both") {
|
|
17360
|
+
useExternalWalletStore.getState().setExternalWallet({
|
|
17361
|
+
address,
|
|
17362
|
+
chainId,
|
|
17363
|
+
connectorName: connector.name || "Unknown Wallet"
|
|
17364
|
+
});
|
|
17365
|
+
} else {
|
|
17366
|
+
disconnect();
|
|
17367
|
+
const { externalAddress, clearExternalWallet } = useExternalWalletStore.getState();
|
|
17368
|
+
if (!!externalAddress) clearExternalWallet();
|
|
17369
|
+
}
|
|
17370
|
+
};
|
|
17371
|
+
const completeExternalConnect = (connector, address, chainId) => {
|
|
17372
|
+
useLayoutDataStore.getState().setPage(walletMenuOpenedFrom || "manage-wallet" /* MANAGE_WALLET */);
|
|
17373
|
+
keepOrReleaseExternalWallet(connector, address, chainId);
|
|
17374
|
+
};
|
|
17375
|
+
const { mutateAsync: loginOrLinkWallet, isPending: isLoginOrLinkWallet } = useMutation10({
|
|
17312
17376
|
mutationFn: async (payload) => {
|
|
17313
17377
|
const { walletData, connectFlowType } = payload;
|
|
17314
17378
|
switch (connectFlowType) {
|
|
@@ -17323,13 +17387,9 @@ function ConnectExternalWalletMenu() {
|
|
|
17323
17387
|
await linkWallet(walletData);
|
|
17324
17388
|
await onLinkingComplete(true);
|
|
17325
17389
|
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
17390
|
}
|
|
17330
17391
|
},
|
|
17331
17392
|
onSuccess: async (response, { walletData, connector, connectFlowType }) => {
|
|
17332
|
-
let shouldKeepConnected = walletMode === "direct" || walletMode === "both";
|
|
17333
17393
|
switch (connectFlowType) {
|
|
17334
17394
|
case "auth":
|
|
17335
17395
|
useLayoutDataStore.getState().setPendingWalletLogin(response);
|
|
@@ -17339,23 +17399,11 @@ function ConnectExternalWalletMenu() {
|
|
|
17339
17399
|
const { linked, message } = response || {};
|
|
17340
17400
|
if (!linked && message.includes("already linked")) {
|
|
17341
17401
|
console.warn("[LINK STATUS] already linked", response);
|
|
17342
|
-
|
|
17343
|
-
useLayoutDataStore.getState().setPage(walletMenuOpenedFrom || "manage-wallet" /* MANAGE_WALLET */);
|
|
17402
|
+
await onLinkingComplete(false);
|
|
17344
17403
|
}
|
|
17345
17404
|
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
17405
|
}
|
|
17406
|
+
keepOrReleaseExternalWallet(connector, walletData.address, walletData.chainId);
|
|
17359
17407
|
useLayoutStore.getState().setIsDialogForced(false);
|
|
17360
17408
|
},
|
|
17361
17409
|
onError: async (err, { walletData, connectFlowType }) => {
|
|
@@ -17370,9 +17418,6 @@ function ConnectExternalWalletMenu() {
|
|
|
17370
17418
|
useManageWalletStore.getState().setAlert({ title: "Error", message: errorMsg });
|
|
17371
17419
|
await onLinkingComplete(false);
|
|
17372
17420
|
break;
|
|
17373
|
-
case "connect":
|
|
17374
|
-
openEmbarkAI(walletMenuOpenedFrom || "main-menu" /* MAIN_MENU */);
|
|
17375
|
-
break;
|
|
17376
17421
|
}
|
|
17377
17422
|
}
|
|
17378
17423
|
});
|
|
@@ -17382,75 +17427,75 @@ function ConnectExternalWalletMenu() {
|
|
|
17382
17427
|
variables: pendingConnectVariables
|
|
17383
17428
|
} = useConnect({
|
|
17384
17429
|
mutation: {
|
|
17385
|
-
onSuccess: async (
|
|
17386
|
-
const
|
|
17387
|
-
const projectId = config.current?.projectId;
|
|
17388
|
-
const projectName = projectId ? await fetchProjectName(projectId) : "EmbarkAI";
|
|
17430
|
+
onSuccess: async ({ chainId, accounts }, variables) => {
|
|
17431
|
+
const connector = variables.connector;
|
|
17389
17432
|
const signingWalletAddress = accounts[0];
|
|
17390
17433
|
const connectFlowType = getConnectFlowType({
|
|
17391
17434
|
isEmbarkAI: !!embarkAiAddress,
|
|
17392
17435
|
connectFlow: menuParams.current?.connectFlowType || "auth"
|
|
17393
17436
|
});
|
|
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");
|
|
17437
|
+
if (connectFlowType === "connect") {
|
|
17438
|
+
completeExternalConnect(connector, signingWalletAddress, chainId);
|
|
17439
|
+
useLayoutStore.getState().setIsDialogForced(false);
|
|
17440
|
+
return;
|
|
17412
17441
|
}
|
|
17413
|
-
|
|
17442
|
+
const projectId = config.current?.projectId;
|
|
17443
|
+
const projectName = projectId ? await fetchProjectName(projectId) : "EmbarkAI";
|
|
17444
|
+
const createMessage = connectFlowType === "auth" ? createLoginMessage : createSignatureMessage;
|
|
17445
|
+
const message = createMessage(signingWalletAddress, projectName);
|
|
17446
|
+
const { signature, chainId: signedChainId } = await signOnSupportedChain({
|
|
17447
|
+
connector,
|
|
17448
|
+
account: signingWalletAddress,
|
|
17449
|
+
message
|
|
17450
|
+
});
|
|
17451
|
+
await loginOrLinkWallet({
|
|
17414
17452
|
connector,
|
|
17415
17453
|
connectFlowType,
|
|
17416
17454
|
walletData: {
|
|
17417
|
-
chainId,
|
|
17455
|
+
chainId: signedChainId,
|
|
17418
17456
|
address: signingWalletAddress,
|
|
17419
17457
|
signature,
|
|
17420
17458
|
message,
|
|
17421
|
-
walletName: connector
|
|
17422
|
-
|
|
17423
|
-
walletType: connector?.id || "unknown"
|
|
17459
|
+
walletName: connector.name || "Unknown Wallet",
|
|
17460
|
+
walletType: connector.id || "unknown"
|
|
17424
17461
|
}
|
|
17425
17462
|
});
|
|
17426
17463
|
},
|
|
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
|
-
}
|
|
17464
|
+
onError: (error, { connector }) => reportConnectError(error, connector)
|
|
17452
17465
|
}
|
|
17453
17466
|
});
|
|
17467
|
+
function reportConnectError(error, connector) {
|
|
17468
|
+
const connectFlowType = getConnectFlowType({
|
|
17469
|
+
isEmbarkAI: !!embarkAiAddress,
|
|
17470
|
+
connectFlow: menuParams.current?.connectFlowType || "auth"
|
|
17471
|
+
});
|
|
17472
|
+
const isRequestPending = isRequestPendingError(error);
|
|
17473
|
+
if (!isRequestPending && connectFlowType !== "connect" && wagmiConfig3.state.connections.has(connector.uid)) {
|
|
17474
|
+
disconnect({ connector });
|
|
17475
|
+
}
|
|
17476
|
+
const errorMessage = isRequestPending ? (
|
|
17477
|
+
// @ts-expect-error i18n typing
|
|
17478
|
+
t("passport:connectMenu.requestPending", { wallet: connector.name })
|
|
17479
|
+
) : error?.message;
|
|
17480
|
+
setTimeout(() => {
|
|
17481
|
+
switch (connectFlowType) {
|
|
17482
|
+
case "auth":
|
|
17483
|
+
setConnectError(errorMessage || "Failed to connect wallet");
|
|
17484
|
+
break;
|
|
17485
|
+
case "link":
|
|
17486
|
+
useLayoutDataStore.getState().setPage("manage-wallet" /* MANAGE_WALLET */);
|
|
17487
|
+
useManageWalletStore.getState().setAlert({
|
|
17488
|
+
title: `Failed to connect: ${connector.name}`,
|
|
17489
|
+
message: errorMessage || "Failed to connect wallet before linking"
|
|
17490
|
+
});
|
|
17491
|
+
break;
|
|
17492
|
+
case "connect":
|
|
17493
|
+
setConnectError(errorMessage || "Failed to connect wallet");
|
|
17494
|
+
break;
|
|
17495
|
+
}
|
|
17496
|
+
useLayoutStore.getState().setIsDialogForced(false);
|
|
17497
|
+
}, 100);
|
|
17498
|
+
}
|
|
17454
17499
|
const visibleConnectors = useMemo9(() => {
|
|
17455
17500
|
const seen = /* @__PURE__ */ new Set();
|
|
17456
17501
|
const unique = connectors.filter((connector) => {
|
|
@@ -17490,8 +17535,8 @@ function ConnectExternalWalletMenu() {
|
|
|
17490
17535
|
variant: "ghost",
|
|
17491
17536
|
size: "icon",
|
|
17492
17537
|
title: t("passport:common.back"),
|
|
17493
|
-
disabled: isConnectingExternalWallet ||
|
|
17494
|
-
onClick: () => useLayoutDataStore.getState().setPage(walletMenuOpenedFrom ?? "
|
|
17538
|
+
disabled: isConnectingExternalWallet || isLoginOrLinkWallet,
|
|
17539
|
+
onClick: () => useLayoutDataStore.getState().setPage(walletMenuOpenedFrom ?? "manage-wallet" /* MANAGE_WALLET */),
|
|
17495
17540
|
children: /* @__PURE__ */ jsx74(ArrowLeft8, { className: "h-4 w-4" })
|
|
17496
17541
|
}
|
|
17497
17542
|
),
|
|
@@ -17507,14 +17552,32 @@ function ConnectExternalWalletMenu() {
|
|
|
17507
17552
|
variant: "secondary",
|
|
17508
17553
|
size: "large",
|
|
17509
17554
|
className: "w-full justify-center",
|
|
17510
|
-
disabled: isConnectingExternalWallet,
|
|
17555
|
+
disabled: isConnectingExternalWallet || isPreparingConnect || isLoginOrLinkWallet,
|
|
17511
17556
|
onClick: async () => {
|
|
17512
17557
|
if (connectError) setConnectError(null);
|
|
17558
|
+
const connectFlowType = getConnectFlowType({
|
|
17559
|
+
isEmbarkAI: !!embarkAiAddress,
|
|
17560
|
+
connectFlow: menuParams.current?.connectFlowType || "auth"
|
|
17561
|
+
});
|
|
17562
|
+
setIsPreparingConnect(true);
|
|
17513
17563
|
try {
|
|
17514
|
-
|
|
17515
|
-
|
|
17564
|
+
const existingConnection = connections.find((c) => c.connector.uid === connector.uid);
|
|
17565
|
+
if (connectFlowType === "connect" && existingConnection?.accounts[0]) {
|
|
17566
|
+
await switchConnectionAsync({ connector });
|
|
17567
|
+
completeExternalConnect(connector, existingConnection.accounts[0], existingConnection.chainId);
|
|
17568
|
+
useLayoutStore.getState().setIsDialogForced(false);
|
|
17569
|
+
return;
|
|
17570
|
+
}
|
|
17571
|
+
const connectionsToDrop = connections.filter((c) => c.connector.uid === connector.uid);
|
|
17572
|
+
for (const { connector: connectedConnector } of connectionsToDrop) {
|
|
17573
|
+
await disconnectAsync({ connector: connectedConnector });
|
|
17574
|
+
}
|
|
17575
|
+
} catch (error) {
|
|
17576
|
+
reportConnectError(error, connector);
|
|
17577
|
+
return;
|
|
17578
|
+
} finally {
|
|
17579
|
+
setIsPreparingConnect(false);
|
|
17516
17580
|
}
|
|
17517
|
-
await new Promise((resolve) => setTimeout(resolve, 500));
|
|
17518
17581
|
switch (true) {
|
|
17519
17582
|
case (connector.id === "metaMaskSDK" && !hasInjectedWallet2):
|
|
17520
17583
|
closeEmbarkAI();
|
|
@@ -17566,6 +17629,7 @@ function ConnectExternalWalletMenu() {
|
|
|
17566
17629
|
] })
|
|
17567
17630
|
] });
|
|
17568
17631
|
}
|
|
17632
|
+
var SIGN_FALLBACK_CHAIN_ID, REQUEST_PENDING_ERROR_CODE, isRequestPendingError, isUnsupportedChainError;
|
|
17569
17633
|
var init_ConnectExternalWalletMenu = __esm({
|
|
17570
17634
|
"src/internal/components/ConnectExternalWalletMenu/ConnectExternalWalletMenu.tsx"() {
|
|
17571
17635
|
init_ProviderContext();
|
|
@@ -17585,13 +17649,18 @@ var init_ConnectExternalWalletMenu = __esm({
|
|
|
17585
17649
|
init_highlight();
|
|
17586
17650
|
init_useConnectExternalWalletMenuParams();
|
|
17587
17651
|
init_useHasInjectedWallet();
|
|
17652
|
+
SIGN_FALLBACK_CHAIN_ID = mainnet.id;
|
|
17653
|
+
REQUEST_PENDING_ERROR_CODE = -32002;
|
|
17654
|
+
isRequestPendingError = (error) => someInErrorChain(error, (e) => e.code === REQUEST_PENDING_ERROR_CODE);
|
|
17655
|
+
isUnsupportedChainError = (error) => someInErrorChain(error, (e) => typeof e.message === "string" && e.message.includes("supportedNetworks"));
|
|
17588
17656
|
}
|
|
17589
17657
|
});
|
|
17590
17658
|
|
|
17591
17659
|
// src/internal/components/ConnectExternalWalletMenu/useExternalWalletConnect.ts
|
|
17592
17660
|
import { useCallback as useCallback18 } from "react";
|
|
17593
17661
|
import { useConnect as useConnect2, useConnectors as useConnectors2, useDisconnect as useDisconnect3 } from "wagmi";
|
|
17594
|
-
function useExternalWalletConnnect() {
|
|
17662
|
+
function useExternalWalletConnnect(options) {
|
|
17663
|
+
const { onSuccess, onError } = options || {};
|
|
17595
17664
|
const { config } = useProviderConfig();
|
|
17596
17665
|
const walletMode = config.current?.wallet?.mode;
|
|
17597
17666
|
const connectors = useConnectors2();
|
|
@@ -17606,9 +17675,15 @@ function useExternalWalletConnnect() {
|
|
|
17606
17675
|
chainId,
|
|
17607
17676
|
connectorName: connector.name || "Unknown Wallet"
|
|
17608
17677
|
});
|
|
17678
|
+
onSuccess?.({ connected: true, address: signingWalletAddress });
|
|
17609
17679
|
useLayoutStore.getState().setIsDialogForced(false);
|
|
17610
17680
|
},
|
|
17611
|
-
onError: (error,
|
|
17681
|
+
onError: (error, { connector }) => {
|
|
17682
|
+
onError?.({
|
|
17683
|
+
connected: false,
|
|
17684
|
+
connector: connector?.name || "Unknown Wallet",
|
|
17685
|
+
error
|
|
17686
|
+
});
|
|
17612
17687
|
useLayoutStore.getState().setIsDialogForced(false);
|
|
17613
17688
|
}
|
|
17614
17689
|
}
|
|
@@ -25340,13 +25415,13 @@ var init_useOperationHashesStore = __esm({
|
|
|
25340
25415
|
// src/internal/components/SendMenu/hyperbridge/hooks/useBridge.ts
|
|
25341
25416
|
import { useMutation as useMutation20, useQueryClient as useQueryClient25 } from "@tanstack/react-query";
|
|
25342
25417
|
import { useCallback as useCallback28 } from "react";
|
|
25343
|
-
import { useSwitchChain, useWalletClient } from "wagmi";
|
|
25418
|
+
import { useSwitchChain as useSwitchChain2, useWalletClient } from "wagmi";
|
|
25344
25419
|
function useBridge() {
|
|
25345
25420
|
const qc = useQueryClient25();
|
|
25346
25421
|
const { t } = useT();
|
|
25347
25422
|
const address = useSession((st) => st.address);
|
|
25348
25423
|
const { data: walletClient } = useWalletClient();
|
|
25349
|
-
const { mutateAsync: switchChainAsync } =
|
|
25424
|
+
const { mutateAsync: switchChainAsync } = useSwitchChain2();
|
|
25350
25425
|
const swapDirection = useCallback28(() => {
|
|
25351
25426
|
const {
|
|
25352
25427
|
// bridgeStep,
|
|
@@ -25818,7 +25893,7 @@ import { CHAINS_BROWSERS_TRANSPORTS as CHAINS_BROWSERS_TRANSPORTS2 } from "@emba
|
|
|
25818
25893
|
import { useQuery as useQuery25, useQueryClient as useQueryClient26 } from "@tanstack/react-query";
|
|
25819
25894
|
import { useCallback as useCallback29, useEffect as useEffect45 } from "react";
|
|
25820
25895
|
import { createPublicClient as createPublicClient2, erc20Abi as erc20Abi3, formatUnits as formatUnits9, http as http3 } from "viem";
|
|
25821
|
-
import { useSwitchChain as
|
|
25896
|
+
import { useSwitchChain as useSwitchChain3 } from "wagmi";
|
|
25822
25897
|
function useBridgeBalance(isLoadingWarpRoutes, hyperlaneWarpRoutes) {
|
|
25823
25898
|
const qc = useQueryClient26();
|
|
25824
25899
|
const { t } = useT();
|
|
@@ -25826,7 +25901,7 @@ function useBridgeBalance(isLoadingWarpRoutes, hyperlaneWarpRoutes) {
|
|
|
25826
25901
|
const activeChainId = useSession((st) => st.activeChainId);
|
|
25827
25902
|
const directWalletAddress = useExternalWalletStore((st) => st.externalAddress);
|
|
25828
25903
|
const directWalletChainId = useExternalWalletStore((st) => st.externalChainId);
|
|
25829
|
-
const { mutateAsync: switchChainAsync } =
|
|
25904
|
+
const { mutateAsync: switchChainAsync } = useSwitchChain3();
|
|
25830
25905
|
const hyperRoute = useBridgeStore((st) => st.hyperRoute);
|
|
25831
25906
|
const bridgeSender = useBridgeStore((st) => st.bridgeSender);
|
|
25832
25907
|
const originChain = useBridgeStore((st) => st.originChain);
|
|
@@ -29847,7 +29922,7 @@ var init_package = __esm({
|
|
|
29847
29922
|
"package.json"() {
|
|
29848
29923
|
package_default = {
|
|
29849
29924
|
name: "@embarkai/ui-kit",
|
|
29850
|
-
version: "0.4.
|
|
29925
|
+
version: "0.4.107",
|
|
29851
29926
|
description: "React UI components and hooks for EmbarkAI authentication and Account Abstraction",
|
|
29852
29927
|
type: "module",
|
|
29853
29928
|
main: "./dist/index.cjs",
|
|
@@ -30608,12 +30683,12 @@ var init_Dialog2 = __esm({
|
|
|
30608
30683
|
|
|
30609
30684
|
// src/internal/components/DirectWalletHandler.tsx
|
|
30610
30685
|
import { useEffect as useEffect55 } from "react";
|
|
30611
|
-
import { useConnection
|
|
30686
|
+
import { useConnection } from "wagmi";
|
|
30612
30687
|
function DirectWalletHandler() {
|
|
30613
30688
|
const walletMode = useProviderConfig().config.current?.wallet?.mode || "both";
|
|
30614
30689
|
const externalAddress = useExternalWalletStore((st) => st.externalAddress);
|
|
30615
30690
|
const isExternalConnected = useExternalWalletStore((st) => st.isExternalConnected);
|
|
30616
|
-
const { address, isConnected, chain, connector } =
|
|
30691
|
+
const { address, isConnected, chain, connector } = useConnection();
|
|
30617
30692
|
useEffect55(() => {
|
|
30618
30693
|
const { setConfigMode, setActiveMode } = useExternalWalletStore.getState();
|
|
30619
30694
|
setConfigMode(walletMode);
|
|
@@ -34387,12 +34462,12 @@ function useDirectWallet() {
|
|
|
34387
34462
|
init_useExternalWalletStore();
|
|
34388
34463
|
import { useCallback as useCallback40, useState as useState39 } from "react";
|
|
34389
34464
|
import { isAddress as isAddress4, parseEther as parseEther3 } from "viem";
|
|
34390
|
-
import { useSendTransaction as useWagmiSendTransaction, useSwitchChain as
|
|
34465
|
+
import { useSendTransaction as useWagmiSendTransaction, useSwitchChain as useSwitchChain4 } from "wagmi";
|
|
34391
34466
|
function useSendDirectTransaction() {
|
|
34392
34467
|
const isConnected = useExternalWalletStore((st) => st.isExternalConnected);
|
|
34393
34468
|
const externalChainId = useExternalWalletStore((st) => st.externalChainId);
|
|
34394
34469
|
const { sendTransactionAsync } = useWagmiSendTransaction();
|
|
34395
|
-
const { switchChainAsync } =
|
|
34470
|
+
const { switchChainAsync } = useSwitchChain4();
|
|
34396
34471
|
const [isPending, setIsPending] = useState39(false);
|
|
34397
34472
|
const [error, setError] = useState39(null);
|
|
34398
34473
|
const [txHash, setTxHash] = useState39(null);
|