@embarkai/ui-kit 0.4.112 → 0.4.114

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.
@@ -15,7 +15,7 @@
15
15
  <meta http-equiv="X-Content-Type-Options" content="nosniff" />
16
16
  <meta http-equiv="Referrer-Policy" content="strict-origin-when-cross-origin" />
17
17
 
18
- <title>EmbarkAI Secure Wallet - iframe version 0.4.112</title>
18
+ <title>EmbarkAI Secure Wallet - iframe version 0.4.114</title>
19
19
 
20
20
  <!-- Styles will be injected by build process -->
21
21
  <style>
@@ -6342,7 +6342,7 @@ var SigningManager = class extends TokenRefreshApiClient {
6342
6342
  };
6343
6343
 
6344
6344
  // src/iframe/main.ts
6345
- var IFRAME_VERSION = "0.4.112";
6345
+ var IFRAME_VERSION = "0.4.114";
6346
6346
  var IframeWallet = class {
6347
6347
  // private finchpay: FinchPayRampAPI
6348
6348
  // private rampnow: RampnowOnrampAPI
package/dist/index.cjs CHANGED
@@ -17394,6 +17394,7 @@ function ConnectExternalWalletMenu() {
17394
17394
  const connectors = (0, import_wagmi3.useConnectors)();
17395
17395
  const hasInjectedWallet2 = useHasInjectedWallet();
17396
17396
  const wagmiConfig3 = (0, import_wagmi3.useConfig)();
17397
+ const chains = (0, import_wagmi3.useChains)();
17397
17398
  const connections = (0, import_wagmi3.useConnections)();
17398
17399
  const { mutate: disconnect, mutateAsync: disconnectAsync } = (0, import_wagmi3.useDisconnect)();
17399
17400
  const { mutateAsync: signMessageAsync } = (0, import_wagmi3.useSignMessage)();
@@ -17404,7 +17405,8 @@ function ConnectExternalWalletMenu() {
17404
17405
  const { connector, account, message } = params;
17405
17406
  const signOnce = async (viaFallback = false) => {
17406
17407
  let chainId = await connector.getChainId();
17407
- if (viaFallback) {
17408
+ const isUnsupportedMetaMaskChain = connector.type === "metaMask" && !chains.some((chain) => chain.id === chainId);
17409
+ if (viaFallback || isUnsupportedMetaMaskChain) {
17408
17410
  await switchChainAsync({ connector, chainId: SIGN_FALLBACK_CHAIN_ID });
17409
17411
  chainId = SIGN_FALLBACK_CHAIN_ID;
17410
17412
  }
@@ -30068,7 +30070,7 @@ var init_package = __esm({
30068
30070
  "package.json"() {
30069
30071
  package_default = {
30070
30072
  name: "@embarkai/ui-kit",
30071
- version: "0.4.112",
30073
+ version: "0.4.114",
30072
30074
  description: "React UI components and hooks for EmbarkAI authentication and Account Abstraction",
30073
30075
  type: "module",
30074
30076
  main: "./dist/index.cjs",
@@ -30835,8 +30837,10 @@ var init_Dialog2 = __esm({
30835
30837
  function DirectWalletHandler() {
30836
30838
  const walletMode = useProviderConfig().config.current?.wallet?.mode || "both";
30837
30839
  const externalAddress = useExternalWalletStore((st) => st.externalAddress);
30840
+ const externalChainId = useExternalWalletStore((st) => st.externalChainId);
30841
+ const externalConnectorName = useExternalWalletStore((st) => st.connectorName);
30838
30842
  const isExternalConnected = useExternalWalletStore((st) => st.isExternalConnected);
30839
- const { address, isConnected, chain, connector } = (0, import_wagmi10.useConnection)();
30843
+ const { address, isConnected, chainId, connector } = (0, import_wagmi10.useConnection)();
30840
30844
  (0, import_react105.useEffect)(() => {
30841
30845
  const { setConfigMode, setActiveMode } = useExternalWalletStore.getState();
30842
30846
  setConfigMode(walletMode);
@@ -30847,14 +30851,21 @@ function DirectWalletHandler() {
30847
30851
  useExternalWalletStore.getState().clearExternalWallet();
30848
30852
  return;
30849
30853
  }
30850
- if (isConnected && address && connector && chain?.id && externalAddress !== address) {
30851
- useExternalWalletStore.getState().setExternalWallet({
30852
- address,
30853
- chainId: chain.id,
30854
- connectorName: connector.name || "Unknown Wallet"
30855
- });
30854
+ if (!isConnected || !address || !connector || !chainId) return;
30855
+ const connectorName = connector.name || "Unknown Wallet";
30856
+ if (externalAddress !== address || externalChainId !== chainId || externalConnectorName !== connectorName) {
30857
+ useExternalWalletStore.getState().setExternalWallet({ address, chainId, connectorName });
30856
30858
  }
30857
- }, [isConnected, address, isExternalConnected, externalAddress, connector, chain]);
30859
+ }, [
30860
+ isConnected,
30861
+ address,
30862
+ isExternalConnected,
30863
+ externalAddress,
30864
+ externalChainId,
30865
+ externalConnectorName,
30866
+ connector,
30867
+ chainId
30868
+ ]);
30858
30869
  return null;
30859
30870
  }
30860
30871
  var import_react105, import_wagmi10;
@@ -34689,55 +34700,82 @@ function useDirectWallet() {
34689
34700
  var import_react113 = require("react");
34690
34701
  var import_viem23 = require("viem");
34691
34702
  var import_wagmi13 = require("wagmi");
34703
+
34704
+ // src/internal/lib/direct-transaction.ts
34705
+ async function submitDirectTransaction(request, deps) {
34706
+ const { connector, switchChain, send } = deps;
34707
+ if (request.chainId) {
34708
+ const walletChainId = await connector.getChainId();
34709
+ if (walletChainId !== request.chainId) {
34710
+ await switchChain({ connector, chainId: request.chainId });
34711
+ }
34712
+ }
34713
+ return send({ ...request, connector });
34714
+ }
34715
+
34716
+ // src/hooks/useSendDirectTransaction.ts
34692
34717
  init_useExternalWalletStore();
34693
34718
  function useSendDirectTransaction() {
34694
34719
  const isConnected = useExternalWalletStore((st) => st.isExternalConnected);
34695
- const externalChainId = useExternalWalletStore((st) => st.externalChainId);
34696
- const { sendTransactionAsync } = (0, import_wagmi13.useSendTransaction)();
34720
+ const { connector } = (0, import_wagmi13.useConnection)();
34721
+ const { sendTransactionAsync: sendWagmiTransactionAsync } = (0, import_wagmi13.useSendTransaction)();
34697
34722
  const { switchChainAsync } = (0, import_wagmi13.useSwitchChain)();
34698
34723
  const [isPending, setIsPending] = (0, import_react113.useState)(false);
34699
34724
  const [error, setError] = (0, import_react113.useState)(null);
34700
34725
  const [txHash, setTxHash] = (0, import_react113.useState)(null);
34701
- const sendTransaction = (0, import_react113.useCallback)(
34726
+ const sendTransactionAsync = (0, import_react113.useCallback)(
34702
34727
  async (params) => {
34703
- if (!isConnected) {
34704
- setError("No external wallet connected");
34705
- return null;
34728
+ if (!isConnected || !connector) {
34729
+ const message = "No external wallet connected";
34730
+ setError(message);
34731
+ throw new Error(message);
34706
34732
  }
34707
34733
  if (!(0, import_viem23.isAddress)(params.to)) {
34708
- setError("Invalid recipient address");
34709
- return null;
34734
+ const message = "Invalid recipient address";
34735
+ setError(message);
34736
+ throw new Error(message);
34710
34737
  }
34711
34738
  setIsPending(true);
34712
34739
  setError(null);
34713
34740
  setTxHash(null);
34714
34741
  try {
34715
- if (params.chainId && params.chainId !== externalChainId) {
34716
- await switchChainAsync({ chainId: params.chainId });
34717
- }
34718
- const hash = await sendTransactionAsync({
34719
- to: params.to,
34720
- value: (0, import_viem23.parseEther)(params.value),
34721
- data: params.data
34722
- });
34742
+ const hash = await submitDirectTransaction(
34743
+ {
34744
+ to: params.to,
34745
+ value: (0, import_viem23.parseEther)(params.value),
34746
+ data: params.data,
34747
+ chainId: params.chainId,
34748
+ gas: params.gas
34749
+ },
34750
+ { connector, switchChain: switchChainAsync, send: sendWagmiTransactionAsync }
34751
+ );
34723
34752
  setTxHash(hash);
34724
34753
  return hash;
34725
34754
  } catch (err) {
34726
- const message = err instanceof Error ? err.message : "Transaction failed";
34727
- setError(message);
34728
- return null;
34755
+ setError(err instanceof Error ? err.message : "Transaction failed");
34756
+ throw err;
34729
34757
  } finally {
34730
34758
  setIsPending(false);
34731
34759
  }
34732
34760
  },
34733
- [isConnected, externalChainId, sendTransactionAsync, switchChainAsync]
34761
+ [isConnected, connector, sendWagmiTransactionAsync, switchChainAsync]
34762
+ );
34763
+ const sendTransaction = (0, import_react113.useCallback)(
34764
+ async (params) => {
34765
+ try {
34766
+ return await sendTransactionAsync(params);
34767
+ } catch {
34768
+ return null;
34769
+ }
34770
+ },
34771
+ [sendTransactionAsync]
34734
34772
  );
34735
34773
  const reset = (0, import_react113.useCallback)(() => {
34736
34774
  setError(null);
34737
34775
  setTxHash(null);
34738
34776
  setIsPending(false);
34739
34777
  }, []);
34740
- return { sendTransaction, isPending, error, txHash, reset };
34778
+ return { sendTransaction, sendTransactionAsync, isPending, error, txHash, reset };
34741
34779
  }
34742
34780
 
34743
34781
  // src/hooks/useTransferToLinkedWallet.ts
package/dist/index.d.cts CHANGED
@@ -1597,9 +1597,12 @@ interface DirectTransactionParams {
1597
1597
  value: string;
1598
1598
  data?: `0x${string}`;
1599
1599
  chainId?: number;
1600
+ /** Gas limit override. When omitted, it is estimated via eth_estimateGas with no safety margin. */
1601
+ gas?: bigint;
1600
1602
  }
1601
1603
  interface UseSendDirectTransactionReturn {
1602
1604
  sendTransaction: (params: DirectTransactionParams) => Promise<`0x${string}` | null>;
1605
+ sendTransactionAsync: (params: DirectTransactionParams) => Promise<`0x${string}`>;
1603
1606
  isPending: boolean;
1604
1607
  error: string | null;
1605
1608
  txHash: `0x${string}` | null;
package/dist/index.d.ts CHANGED
@@ -1597,9 +1597,12 @@ interface DirectTransactionParams {
1597
1597
  value: string;
1598
1598
  data?: `0x${string}`;
1599
1599
  chainId?: number;
1600
+ /** Gas limit override. When omitted, it is estimated via eth_estimateGas with no safety margin. */
1601
+ gas?: bigint;
1600
1602
  }
1601
1603
  interface UseSendDirectTransactionReturn {
1602
1604
  sendTransaction: (params: DirectTransactionParams) => Promise<`0x${string}` | null>;
1605
+ sendTransactionAsync: (params: DirectTransactionParams) => Promise<`0x${string}`>;
1603
1606
  isPending: boolean;
1604
1607
  error: string | null;
1605
1608
  txHash: `0x${string}` | null;
package/dist/index.js CHANGED
@@ -17329,6 +17329,7 @@ import { useMutation as useMutation10, useQuery as useQuery9, useQueryClient as
17329
17329
  import { ArrowLeft as ArrowLeft8, Loader as Loader11, Wallet2Icon as Wallet2Icon2 } from "lucide-react";
17330
17330
  import { useCallback as useCallback17, useMemo as useMemo9, useState as useState14 } from "react";
17331
17331
  import {
17332
+ useChains,
17332
17333
  useConfig,
17333
17334
  useConnect,
17334
17335
  useConnections as useConnections2,
@@ -17357,6 +17358,7 @@ function ConnectExternalWalletMenu() {
17357
17358
  const connectors = useConnectors();
17358
17359
  const hasInjectedWallet2 = useHasInjectedWallet();
17359
17360
  const wagmiConfig3 = useConfig();
17361
+ const chains = useChains();
17360
17362
  const connections = useConnections2();
17361
17363
  const { mutate: disconnect, mutateAsync: disconnectAsync } = useDisconnect2();
17362
17364
  const { mutateAsync: signMessageAsync } = useSignMessage();
@@ -17367,7 +17369,8 @@ function ConnectExternalWalletMenu() {
17367
17369
  const { connector, account, message } = params;
17368
17370
  const signOnce = async (viaFallback = false) => {
17369
17371
  let chainId = await connector.getChainId();
17370
- if (viaFallback) {
17372
+ const isUnsupportedMetaMaskChain = connector.type === "metaMask" && !chains.some((chain) => chain.id === chainId);
17373
+ if (viaFallback || isUnsupportedMetaMaskChain) {
17371
17374
  await switchChainAsync({ connector, chainId: SIGN_FALLBACK_CHAIN_ID });
17372
17375
  chainId = SIGN_FALLBACK_CHAIN_ID;
17373
17376
  }
@@ -29975,7 +29978,7 @@ var init_package = __esm({
29975
29978
  "package.json"() {
29976
29979
  package_default = {
29977
29980
  name: "@embarkai/ui-kit",
29978
- version: "0.4.112",
29981
+ version: "0.4.114",
29979
29982
  description: "React UI components and hooks for EmbarkAI authentication and Account Abstraction",
29980
29983
  type: "module",
29981
29984
  main: "./dist/index.cjs",
@@ -30742,8 +30745,10 @@ import { useConnection } from "wagmi";
30742
30745
  function DirectWalletHandler() {
30743
30746
  const walletMode = useProviderConfig().config.current?.wallet?.mode || "both";
30744
30747
  const externalAddress = useExternalWalletStore((st) => st.externalAddress);
30748
+ const externalChainId = useExternalWalletStore((st) => st.externalChainId);
30749
+ const externalConnectorName = useExternalWalletStore((st) => st.connectorName);
30745
30750
  const isExternalConnected = useExternalWalletStore((st) => st.isExternalConnected);
30746
- const { address, isConnected, chain, connector } = useConnection();
30751
+ const { address, isConnected, chainId, connector } = useConnection();
30747
30752
  useEffect56(() => {
30748
30753
  const { setConfigMode, setActiveMode } = useExternalWalletStore.getState();
30749
30754
  setConfigMode(walletMode);
@@ -30754,14 +30759,21 @@ function DirectWalletHandler() {
30754
30759
  useExternalWalletStore.getState().clearExternalWallet();
30755
30760
  return;
30756
30761
  }
30757
- if (isConnected && address && connector && chain?.id && externalAddress !== address) {
30758
- useExternalWalletStore.getState().setExternalWallet({
30759
- address,
30760
- chainId: chain.id,
30761
- connectorName: connector.name || "Unknown Wallet"
30762
- });
30762
+ if (!isConnected || !address || !connector || !chainId) return;
30763
+ const connectorName = connector.name || "Unknown Wallet";
30764
+ if (externalAddress !== address || externalChainId !== chainId || externalConnectorName !== connectorName) {
30765
+ useExternalWalletStore.getState().setExternalWallet({ address, chainId, connectorName });
30763
30766
  }
30764
- }, [isConnected, address, isExternalConnected, externalAddress, connector, chain]);
30767
+ }, [
30768
+ isConnected,
30769
+ address,
30770
+ isExternalConnected,
30771
+ externalAddress,
30772
+ externalChainId,
30773
+ externalConnectorName,
30774
+ connector,
30775
+ chainId
30776
+ ]);
30765
30777
  return null;
30766
30778
  }
30767
30779
  var init_DirectWalletHandler = __esm({
@@ -34514,58 +34526,85 @@ function useDirectWallet() {
34514
34526
  }
34515
34527
 
34516
34528
  // src/hooks/useSendDirectTransaction.ts
34517
- init_useExternalWalletStore();
34518
34529
  import { useCallback as useCallback40, useState as useState39 } from "react";
34519
34530
  import { isAddress as isAddress4, parseEther as parseEther3 } from "viem";
34520
- import { useSendTransaction as useWagmiSendTransaction, useSwitchChain as useSwitchChain4 } from "wagmi";
34531
+ import { useConnection as useConnection2, useSwitchChain as useSwitchChain4, useSendTransaction as useWagmiSendTransaction } from "wagmi";
34532
+
34533
+ // src/internal/lib/direct-transaction.ts
34534
+ async function submitDirectTransaction(request, deps) {
34535
+ const { connector, switchChain, send } = deps;
34536
+ if (request.chainId) {
34537
+ const walletChainId = await connector.getChainId();
34538
+ if (walletChainId !== request.chainId) {
34539
+ await switchChain({ connector, chainId: request.chainId });
34540
+ }
34541
+ }
34542
+ return send({ ...request, connector });
34543
+ }
34544
+
34545
+ // src/hooks/useSendDirectTransaction.ts
34546
+ init_useExternalWalletStore();
34521
34547
  function useSendDirectTransaction() {
34522
34548
  const isConnected = useExternalWalletStore((st) => st.isExternalConnected);
34523
- const externalChainId = useExternalWalletStore((st) => st.externalChainId);
34524
- const { sendTransactionAsync } = useWagmiSendTransaction();
34549
+ const { connector } = useConnection2();
34550
+ const { sendTransactionAsync: sendWagmiTransactionAsync } = useWagmiSendTransaction();
34525
34551
  const { switchChainAsync } = useSwitchChain4();
34526
34552
  const [isPending, setIsPending] = useState39(false);
34527
34553
  const [error, setError] = useState39(null);
34528
34554
  const [txHash, setTxHash] = useState39(null);
34529
- const sendTransaction = useCallback40(
34555
+ const sendTransactionAsync = useCallback40(
34530
34556
  async (params) => {
34531
- if (!isConnected) {
34532
- setError("No external wallet connected");
34533
- return null;
34557
+ if (!isConnected || !connector) {
34558
+ const message = "No external wallet connected";
34559
+ setError(message);
34560
+ throw new Error(message);
34534
34561
  }
34535
34562
  if (!isAddress4(params.to)) {
34536
- setError("Invalid recipient address");
34537
- return null;
34563
+ const message = "Invalid recipient address";
34564
+ setError(message);
34565
+ throw new Error(message);
34538
34566
  }
34539
34567
  setIsPending(true);
34540
34568
  setError(null);
34541
34569
  setTxHash(null);
34542
34570
  try {
34543
- if (params.chainId && params.chainId !== externalChainId) {
34544
- await switchChainAsync({ chainId: params.chainId });
34545
- }
34546
- const hash = await sendTransactionAsync({
34547
- to: params.to,
34548
- value: parseEther3(params.value),
34549
- data: params.data
34550
- });
34571
+ const hash = await submitDirectTransaction(
34572
+ {
34573
+ to: params.to,
34574
+ value: parseEther3(params.value),
34575
+ data: params.data,
34576
+ chainId: params.chainId,
34577
+ gas: params.gas
34578
+ },
34579
+ { connector, switchChain: switchChainAsync, send: sendWagmiTransactionAsync }
34580
+ );
34551
34581
  setTxHash(hash);
34552
34582
  return hash;
34553
34583
  } catch (err) {
34554
- const message = err instanceof Error ? err.message : "Transaction failed";
34555
- setError(message);
34556
- return null;
34584
+ setError(err instanceof Error ? err.message : "Transaction failed");
34585
+ throw err;
34557
34586
  } finally {
34558
34587
  setIsPending(false);
34559
34588
  }
34560
34589
  },
34561
- [isConnected, externalChainId, sendTransactionAsync, switchChainAsync]
34590
+ [isConnected, connector, sendWagmiTransactionAsync, switchChainAsync]
34591
+ );
34592
+ const sendTransaction = useCallback40(
34593
+ async (params) => {
34594
+ try {
34595
+ return await sendTransactionAsync(params);
34596
+ } catch {
34597
+ return null;
34598
+ }
34599
+ },
34600
+ [sendTransactionAsync]
34562
34601
  );
34563
34602
  const reset = useCallback40(() => {
34564
34603
  setError(null);
34565
34604
  setTxHash(null);
34566
34605
  setIsPending(false);
34567
34606
  }, []);
34568
- return { sendTransaction, isPending, error, txHash, reset };
34607
+ return { sendTransaction, sendTransactionAsync, isPending, error, txHash, reset };
34569
34608
  }
34570
34609
 
34571
34610
  // src/hooks/useTransferToLinkedWallet.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@embarkai/ui-kit",
3
- "version": "0.4.112",
3
+ "version": "0.4.114",
4
4
  "description": "React UI components and hooks for EmbarkAI authentication and Account Abstraction",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",