@trustware/sdk-staging 1.1.8-staging.4 → 1.1.8-staging.6

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/index.mjs CHANGED
@@ -420,7 +420,7 @@ var init_constants = __esm({
420
420
  "src/constants.ts"() {
421
421
  "use strict";
422
422
  SDK_NAME = "@trustware/sdk";
423
- SDK_VERSION = "1.1.8-staging.4";
423
+ SDK_VERSION = "1.1.8-staging.6";
424
424
  API_ROOT = "https://bv-staging-api.trustware.io";
425
425
  GTM_ID = "GTM-TZDGNCXB";
426
426
  API_PREFIX = "/api";
@@ -662,6 +662,134 @@ var init_sdkRpc = __esm({
662
662
  });
663
663
 
664
664
  // src/wallets/solana.ts
665
+ function encodeBase58(bytes) {
666
+ const digits = [0];
667
+ for (const byte of bytes) {
668
+ let carry = byte;
669
+ for (let i = 0; i < digits.length; i++) {
670
+ carry += digits[i] << 8;
671
+ digits[i] = carry % 58;
672
+ carry = carry / 58 | 0;
673
+ }
674
+ while (carry > 0) {
675
+ digits.push(carry % 58);
676
+ carry = carry / 58 | 0;
677
+ }
678
+ }
679
+ let result = "";
680
+ for (let i = 0; i < bytes.length && bytes[i] === 0; i++) {
681
+ result += "1";
682
+ }
683
+ for (let i = digits.length - 1; i >= 0; i--) {
684
+ result += BASE58_ALPHABET[digits[i]];
685
+ }
686
+ return result;
687
+ }
688
+ function collectWalletStandardWallets() {
689
+ if (typeof window === "undefined") return [];
690
+ const collected = [];
691
+ const api = {
692
+ register(...wallets) {
693
+ collected.push(...wallets);
694
+ return () => {
695
+ };
696
+ }
697
+ };
698
+ try {
699
+ window.dispatchEvent(
700
+ Object.assign(
701
+ new Event("wallet-standard:app-ready", { bubbles: false }),
702
+ {
703
+ detail: api
704
+ }
705
+ )
706
+ );
707
+ } catch {
708
+ }
709
+ return collected;
710
+ }
711
+ function walletStandardToSolanaProvider(wallet) {
712
+ let currentAccount = wallet.accounts[0] ?? null;
713
+ const provider = {
714
+ get isConnected() {
715
+ return !!currentAccount;
716
+ },
717
+ get publicKey() {
718
+ if (!currentAccount) return void 0;
719
+ const addr = currentAccount.address;
720
+ return { toString: () => addr };
721
+ },
722
+ async connect() {
723
+ const feature = wallet.features["standard:connect"];
724
+ if (!feature?.connect)
725
+ throw new Error("Wallet Standard connect not available");
726
+ const result = await feature.connect({ silent: false });
727
+ currentAccount = result.accounts[0] ?? null;
728
+ if (!currentAccount)
729
+ throw new Error("No Solana account returned from MetaMask");
730
+ return { publicKey: { toString: () => currentAccount.address } };
731
+ },
732
+ async disconnect() {
733
+ const feature = wallet.features["standard:disconnect"];
734
+ await feature?.disconnect?.();
735
+ currentAccount = null;
736
+ },
737
+ async signAndSendTransaction(transaction, options) {
738
+ const feature = wallet.features["solana:signAndSendTransaction"];
739
+ if (!feature?.signAndSendTransaction || !currentAccount) {
740
+ throw new Error("signAndSendTransaction not available");
741
+ }
742
+ const txBytes = transaction.serialize();
743
+ const results = await feature.signAndSendTransaction({
744
+ account: currentAccount,
745
+ transaction: txBytes,
746
+ chain: SOLANA_MAINNET_CHAIN,
747
+ options
748
+ });
749
+ const sig = results[0]?.signature;
750
+ if (!sig) throw new Error("No signature returned");
751
+ return typeof sig === "string" ? sig : encodeBase58(sig);
752
+ },
753
+ async signTransaction(transaction) {
754
+ const feature = wallet.features["solana:signTransaction"];
755
+ if (!feature?.signTransaction || !currentAccount) {
756
+ throw new Error("signTransaction not available");
757
+ }
758
+ const txBytes = transaction.serialize();
759
+ const results = await feature.signTransaction({
760
+ account: currentAccount,
761
+ transaction: txBytes,
762
+ chain: SOLANA_MAINNET_CHAIN
763
+ });
764
+ const signed = results[0]?.signedTransaction;
765
+ if (!signed) throw new Error("No signed transaction returned");
766
+ return { serialize: () => signed };
767
+ },
768
+ on() {
769
+ },
770
+ off() {
771
+ },
772
+ removeListener() {
773
+ }
774
+ };
775
+ return provider;
776
+ }
777
+ function detectMetaMaskSolanaWallet(wallets) {
778
+ const meta = wallets.find((w) => w.id === "metamask-solana");
779
+ if (!meta) return [];
780
+ const standardWallets = collectWalletStandardWallets();
781
+ const mmWallet = standardWallets.find(
782
+ (w) => w.name.toLowerCase().includes("metamask") && w.chains.some((c) => c.startsWith("solana:"))
783
+ );
784
+ if (!mmWallet) return [];
785
+ return [
786
+ {
787
+ meta,
788
+ provider: walletStandardToSolanaProvider(mmWallet),
789
+ via: "solana-window"
790
+ }
791
+ ];
792
+ }
665
793
  function getPublicKeyString(provider) {
666
794
  const publicKey = provider?.publicKey;
667
795
  if (!publicKey) return null;
@@ -723,12 +851,13 @@ function getSolanaProviders() {
723
851
  }
724
852
  function detectSolanaWallets(wallets) {
725
853
  const providers = getSolanaProviders();
726
- return SOLANA_WALLET_IDS.flatMap((walletId) => {
854
+ const windowDetected = SOLANA_WALLET_IDS.flatMap((walletId) => {
727
855
  const provider = providers[walletId];
728
856
  const meta = wallets.find((item) => item.id === walletId);
729
857
  if (!provider || !meta) return [];
730
858
  return [{ meta, provider, via: "solana-window" }];
731
859
  });
860
+ return [...windowDetected, ...detectMetaMaskSolanaWallet(wallets)];
732
861
  }
733
862
  function bindSolanaProviderEvents(provider, handlers) {
734
863
  const onConnect = () => handlers.onConnect?.();
@@ -793,7 +922,7 @@ function toSolanaWalletInterface(provider) {
793
922
  }
794
923
  };
795
924
  }
796
- var SOLANA_WALLET_IDS;
925
+ var SOLANA_WALLET_IDS, SOLANA_MAINNET_CHAIN, BASE58_ALPHABET;
797
926
  var init_solana = __esm({
798
927
  "src/wallets/solana.ts"() {
799
928
  "use strict";
@@ -803,6 +932,8 @@ var init_solana = __esm({
803
932
  "solflare",
804
933
  "backpack"
805
934
  ];
935
+ SOLANA_MAINNET_CHAIN = "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp";
936
+ BASE58_ALPHABET = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
806
937
  }
807
938
  });
808
939
 
@@ -976,6 +1107,15 @@ var init_metadata = __esm({
976
1107
  ios: "https://apps.apple.com/app/phantom-crypto-wallet/id1598432977",
977
1108
  deepLink: (url) => `phantom://browse/${encodeURIComponent(url)}`
978
1109
  },
1110
+ {
1111
+ id: "metamask-solana",
1112
+ name: "MetaMask (Solana)",
1113
+ category: "injected",
1114
+ ecosystem: "solana",
1115
+ logo: `${ASSETS_BASE_URL}/assets/wallets/metamask.svg`,
1116
+ emoji: "\u{1F98A}",
1117
+ homepage: "https://metamask.io/"
1118
+ },
979
1119
  {
980
1120
  id: "solflare",
981
1121
  name: "Solflare",
@@ -7260,7 +7400,9 @@ function applyWalletTokenState({
7260
7400
  const selectedTokenStillExists = selectedToken && sortedTokens.some(
7261
7401
  (token) => normalizeChainKey2(token.chainId) === normalizeChainKey2(selectedToken.chainId) && token.address === selectedToken.address
7262
7402
  );
7263
- const nextSelectedToken = selectedTokenStillExists && selectedToken ? selectedToken : sortedTokens.find((token) => Number(token.balance) > 0) ?? null;
7403
+ const nextSelectedToken = selectedTokenStillExists && selectedToken ? sortedTokens.find(
7404
+ (token) => normalizeChainKey2(token.chainId) === normalizeChainKey2(selectedToken.chainId) && token.address === selectedToken.address
7405
+ ) ?? selectedToken : sortedTokens.find((token) => Number(token.balance) > 0) ?? null;
7264
7406
  setSelectedToken(nextSelectedToken);
7265
7407
  if (nextSelectedToken && (!selectedChain || normalizeChainKey2(selectedChain.chainId) !== normalizeChainKey2(
7266
7408
  hasChainData(nextSelectedToken) ? nextSelectedToken.chainData?.chainId ?? null : nextSelectedToken.chainId
@@ -13547,10 +13689,12 @@ function useDepositAmountModel({
13547
13689
  ]);
13548
13690
  const amountWei = amountValidationError ? 0n : amountComputation.fromAmountWei ?? 0n;
13549
13691
  const parsedAmount = parseFloat(fixedFromAmountString ?? amount) || 0;
13550
- const maxTokenAmount = useMemo14(
13551
- () => Math.min(normalizedTokenBalance, 1e4),
13552
- [normalizedTokenBalance]
13553
- );
13692
+ const maxTokenAmount = useMemo14(() => {
13693
+ const cap = Math.min(normalizedTokenBalance, 1e4);
13694
+ const token = selectedToken;
13695
+ const isSolNative = token?.category === "native" && typeof token.chain_key === "string" && token.chain_key.toLowerCase().includes("solana");
13696
+ return isSolNative ? Math.max(0, cap - 0.01) : cap;
13697
+ }, [normalizedTokenBalance, selectedToken]);
13554
13698
  const maxUsdAmount = useMemo14(() => {
13555
13699
  if (!hasUsdPrice) return void 0;
13556
13700
  return Math.min(maxTokenAmount * tokenPriceUSD, 1e4);
@@ -30496,7 +30640,8 @@ function sleep3(ms) {
30496
30640
  }
30497
30641
  function isUserRejection(err) {
30498
30642
  if (!err) return false;
30499
- const code = err?.code;
30643
+ const e2 = err;
30644
+ const code = e2?.code ?? e2?.data?.code;
30500
30645
  if (code === 4001) return true;
30501
30646
  const msg = (err instanceof Error ? err.message : String(err)).toLowerCase();
30502
30647
  return msg.includes("user rejected") || msg.includes("user denied") || msg.includes("cancelled");
@@ -30645,6 +30790,26 @@ function useSwapExecution(fromChain) {
30645
30790
  );
30646
30791
  const canUseSA = !!routeResult.sponsorship && Date.now() >= saFailedUntilRef.current && wallet?.ecosystem === "evm" && wallet.type === "eip1193" && !isNative && !!walletAddress && Number.isFinite(numericChainId);
30647
30792
  if (canUseSA) {
30793
+ if (numericChainId && wallet) {
30794
+ try {
30795
+ const currentChainId = await wallet.getChainId();
30796
+ if (currentChainId !== numericChainId) {
30797
+ await wallet.switchChain(numericChainId);
30798
+ }
30799
+ } catch (switchErr) {
30800
+ if (isUserRejection(switchErr)) {
30801
+ const msg = mapTxError(switchErr);
30802
+ setState((p) => ({
30803
+ ...p,
30804
+ isSubmitting: false,
30805
+ txStatus: "error",
30806
+ errorMessage: msg
30807
+ }));
30808
+ onError(msg);
30809
+ return;
30810
+ }
30811
+ }
30812
+ }
30648
30813
  try {
30649
30814
  const mod = await Promise.resolve().then(() => (init_smart_account2(), smart_account_exports));
30650
30815
  const result = await mod.sendRouteAsUserOperation({
@@ -31182,8 +31347,8 @@ var init_SwapTokenSelect = __esm({
31182
31347
  });
31183
31348
 
31184
31349
  // src/modes/swap/components/SwapWalletSelector.tsx
31185
- import { useEffect as useEffect29, useRef as useRef16, useState as useState27 } from "react";
31186
- import { jsx as jsx55, jsxs as jsxs44 } from "react/jsx-runtime";
31350
+ import { useEffect as useEffect29, useMemo as useMemo25, useRef as useRef16, useState as useState27 } from "react";
31351
+ import { Fragment as Fragment7, jsx as jsx55, jsxs as jsxs44 } from "react/jsx-runtime";
31187
31352
  function SwapWalletSelector({
31188
31353
  walletStatus,
31189
31354
  walletAddress,
@@ -31191,11 +31356,18 @@ function SwapWalletSelector({
31191
31356
  onBack
31192
31357
  }) {
31193
31358
  const { detected } = useWalletDetection();
31359
+ const {
31360
+ isConnected: managerConnected,
31361
+ walletMetaId,
31362
+ connectedVia,
31363
+ disconnect
31364
+ } = useWalletInfo();
31365
+ const walletConnectCfg = TrustwareConfigStore.peek()?.walletConnect;
31366
+ const connectWC = useWalletConnectConnect(walletConnectCfg);
31367
+ const [wcConnecting, setWcConnecting] = useState27(false);
31194
31368
  const [connectingId, setConnectingId] = useState27(null);
31195
- const [connectedWalletId, setConnectedWalletId] = useState27(
31196
- null
31197
- );
31198
31369
  const [timerExpired, setTimerExpired] = useState27(false);
31370
+ const [selectedNamespace, setSelectedNamespace] = useState27("evm");
31199
31371
  const prevStatusRef = useRef16(walletStatus);
31200
31372
  useEffect29(() => {
31201
31373
  const t = setTimeout(() => setTimerExpired(true), 450);
@@ -31210,16 +31382,48 @@ function SwapWalletSelector({
31210
31382
  prevStatusRef.current = walletStatus;
31211
31383
  }
31212
31384
  }, [walletStatus]);
31385
+ const filteredWallets = useMemo25(
31386
+ () => detected.filter(
31387
+ (w) => (w.meta?.ecosystem ?? "").toLowerCase() === selectedNamespace
31388
+ ),
31389
+ [detected, selectedNamespace]
31390
+ );
31391
+ const isDetecting = detected.length === 0 && !timerExpired;
31392
+ const handleDisconnect = () => {
31393
+ void disconnect();
31394
+ };
31395
+ const handleWalletConnect = async () => {
31396
+ if (wcConnecting) return;
31397
+ if (connectedVia === "walletconnect" && managerConnected) {
31398
+ onBack();
31399
+ return;
31400
+ }
31401
+ setWcConnecting(true);
31402
+ try {
31403
+ const { error } = await connectWC();
31404
+ if (error) {
31405
+ toast.error("WalletConnect Failed", error);
31406
+ }
31407
+ } catch (err) {
31408
+ const msg = err instanceof Error ? err.message : "WalletConnect failed";
31409
+ toast.error("WalletConnect Failed", msg);
31410
+ } finally {
31411
+ setWcConnecting(false);
31412
+ }
31413
+ };
31213
31414
  const handleClick = async (wallet) => {
31214
31415
  if (walletStatus === "connecting") return;
31215
31416
  if (wallet.meta.id === "walletconnect" || wallet.via === "walletconnect") {
31216
31417
  toast.error("Not Available", "WalletConnect is not currently available.");
31217
31418
  return;
31218
31419
  }
31420
+ if (managerConnected && walletMetaId === wallet.meta.id) {
31421
+ onBack();
31422
+ return;
31423
+ }
31219
31424
  setConnectingId(wallet.meta.id);
31220
31425
  try {
31221
31426
  await connectWallet(wallet);
31222
- setConnectedWalletId(wallet.meta.id);
31223
31427
  } catch (err) {
31224
31428
  setConnectingId(null);
31225
31429
  const msg = err instanceof Error ? err.message : "Failed to connect wallet";
@@ -31233,7 +31437,10 @@ function SwapWalletSelector({
31233
31437
  }
31234
31438
  }
31235
31439
  };
31236
- const isDetecting = detected.length === 0 && !timerExpired;
31440
+ const tabs = [
31441
+ { id: "evm", label: "EVM" },
31442
+ { id: "solana", label: "Solana" }
31443
+ ];
31237
31444
  return /* @__PURE__ */ jsxs44("div", { style: { display: "flex", flexDirection: "column" }, children: [
31238
31445
  /* @__PURE__ */ jsxs44(
31239
31446
  "div",
@@ -31290,134 +31497,348 @@ function SwapWalletSelector({
31290
31497
  fontSize: fontSize.lg,
31291
31498
  fontWeight: fontWeight.semibold,
31292
31499
  color: colors.foreground,
31293
- textAlign: "center",
31294
- marginRight: "1.75rem"
31500
+ textAlign: "center"
31295
31501
  },
31296
31502
  children: "Connect Wallet"
31297
31503
  }
31298
- )
31299
- ]
31300
- }
31301
- ),
31302
- /* @__PURE__ */ jsx55("div", { style: { padding: spacing[4] }, children: isDetecting ? /* @__PURE__ */ jsxs44(
31303
- "div",
31304
- {
31305
- style: {
31306
- display: "flex",
31307
- flexDirection: "column",
31308
- gap: spacing[3]
31309
- },
31310
- children: [
31311
- [1, 2].map((i) => /* @__PURE__ */ jsxs44(
31504
+ ),
31505
+ /* @__PURE__ */ jsxs44(
31312
31506
  "div",
31313
31507
  {
31314
31508
  style: {
31509
+ position: "relative",
31315
31510
  display: "flex",
31316
31511
  alignItems: "center",
31317
- gap: spacing[4],
31318
- padding: spacing[4],
31319
- borderRadius: borderRadius["2xl"],
31320
- backgroundColor: colors.muted,
31321
- animation: "tw-pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite"
31512
+ borderRadius: "9999px",
31513
+ background: colors.background,
31514
+ border: `1px solid ${colors.mutedForeground}`,
31515
+ padding: "3px"
31322
31516
  },
31323
31517
  children: [
31324
31518
  /* @__PURE__ */ jsx55(
31325
31519
  "div",
31326
31520
  {
31327
31521
  style: {
31328
- width: "3rem",
31329
- height: "3rem",
31330
- borderRadius: borderRadius.xl,
31331
- backgroundColor: "rgba(161,161,170,0.2)"
31522
+ position: "absolute",
31523
+ top: 3,
31524
+ bottom: 3,
31525
+ width: "calc(50% - 3px)",
31526
+ borderRadius: "9999px",
31527
+ background: `linear-gradient(to bottom, ${colors.zinc[100]}, ${colors.zinc[200]})`,
31528
+ border: `1px solid ${colors.mutedForeground}`,
31529
+ transition: "transform 300ms ease-out",
31530
+ transform: selectedNamespace === "evm" ? "translateX(0)" : "translateX(100%)"
31332
31531
  }
31333
31532
  }
31334
31533
  ),
31335
- /* @__PURE__ */ jsx55(
31336
- "div",
31534
+ tabs.map((t) => /* @__PURE__ */ jsx55(
31535
+ "button",
31337
31536
  {
31537
+ onClick: () => setSelectedNamespace(t.id),
31338
31538
  style: {
31339
- height: "1rem",
31340
- width: "6rem",
31341
- borderRadius: borderRadius.md,
31342
- backgroundColor: "rgba(161,161,170,0.2)"
31343
- }
31344
- }
31345
- )
31539
+ position: "relative",
31540
+ zIndex: 10,
31541
+ padding: "4px 11px",
31542
+ fontSize: "10px",
31543
+ outline: "none",
31544
+ fontWeight: 600,
31545
+ borderRadius: "9999px",
31546
+ background: "transparent",
31547
+ border: "none",
31548
+ cursor: "pointer",
31549
+ transition: "color 200ms",
31550
+ color: selectedNamespace === t.id ? colors.black : colors.mutedForeground
31551
+ },
31552
+ children: t.label
31553
+ },
31554
+ t.id
31555
+ ))
31346
31556
  ]
31347
- },
31348
- i
31349
- )),
31350
- /* @__PURE__ */ jsx55(
31351
- "p",
31352
- {
31353
- style: {
31354
- textAlign: "center",
31355
- fontSize: fontSize.sm,
31356
- color: colors.mutedForeground,
31357
- marginTop: spacing[4]
31358
- },
31359
- children: "Detecting wallets..."
31360
31557
  }
31361
31558
  )
31362
31559
  ]
31363
31560
  }
31364
- ) : detected.length === 0 ? /* @__PURE__ */ jsxs44("div", { style: { textAlign: "center", padding: `${spacing[8]} 0` }, children: [
31365
- /* @__PURE__ */ jsx55("div", { style: { fontSize: "2.5rem", marginBottom: spacing[4] }, children: "\u{1F45B}" }),
31366
- /* @__PURE__ */ jsx55(
31367
- "h3",
31561
+ ),
31562
+ /* @__PURE__ */ jsxs44("div", { style: { padding: spacing[4] }, children: [
31563
+ isDetecting ? /* @__PURE__ */ jsxs44(
31564
+ "div",
31368
31565
  {
31369
31566
  style: {
31370
- fontSize: fontSize.lg,
31371
- fontWeight: fontWeight.semibold,
31372
- color: colors.foreground,
31373
- marginBottom: spacing[2]
31567
+ display: "flex",
31568
+ flexDirection: "column",
31569
+ gap: spacing[3]
31374
31570
  },
31375
- children: "No Wallets Found"
31571
+ children: [
31572
+ [1, 2].map((i) => /* @__PURE__ */ jsxs44(
31573
+ "div",
31574
+ {
31575
+ style: {
31576
+ display: "flex",
31577
+ alignItems: "center",
31578
+ gap: spacing[4],
31579
+ padding: spacing[4],
31580
+ borderRadius: borderRadius["2xl"],
31581
+ backgroundColor: colors.muted,
31582
+ animation: "tw-pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite"
31583
+ },
31584
+ children: [
31585
+ /* @__PURE__ */ jsx55(
31586
+ "div",
31587
+ {
31588
+ style: {
31589
+ width: "3rem",
31590
+ height: "3rem",
31591
+ borderRadius: borderRadius.xl,
31592
+ backgroundColor: "rgba(161,161,170,0.2)"
31593
+ }
31594
+ }
31595
+ ),
31596
+ /* @__PURE__ */ jsx55(
31597
+ "div",
31598
+ {
31599
+ style: {
31600
+ height: "1rem",
31601
+ width: "6rem",
31602
+ borderRadius: borderRadius.md,
31603
+ backgroundColor: "rgba(161,161,170,0.2)"
31604
+ }
31605
+ }
31606
+ )
31607
+ ]
31608
+ },
31609
+ i
31610
+ )),
31611
+ /* @__PURE__ */ jsx55(
31612
+ "p",
31613
+ {
31614
+ style: {
31615
+ textAlign: "center",
31616
+ fontSize: fontSize.sm,
31617
+ color: colors.mutedForeground,
31618
+ marginTop: spacing[4]
31619
+ },
31620
+ children: "Detecting wallets..."
31621
+ }
31622
+ )
31623
+ ]
31376
31624
  }
31377
- ),
31378
- /* @__PURE__ */ jsx55(
31379
- "p",
31625
+ ) : filteredWallets.length === 0 ? /* @__PURE__ */ jsxs44("div", { style: { textAlign: "center", padding: `${spacing[8]} 0` }, children: [
31626
+ /* @__PURE__ */ jsx55("div", { style: { fontSize: "2.5rem", marginBottom: spacing[4] }, children: "\u{1F45B}" }),
31627
+ /* @__PURE__ */ jsx55(
31628
+ "h3",
31629
+ {
31630
+ style: {
31631
+ fontSize: fontSize.lg,
31632
+ fontWeight: fontWeight.semibold,
31633
+ color: colors.foreground,
31634
+ marginBottom: spacing[2]
31635
+ },
31636
+ children: "No Wallets Found"
31637
+ }
31638
+ ),
31639
+ /* @__PURE__ */ jsx55(
31640
+ "p",
31641
+ {
31642
+ style: {
31643
+ fontSize: fontSize.sm,
31644
+ color: colors.mutedForeground,
31645
+ marginBottom: spacing[4]
31646
+ },
31647
+ children: "Please install a web3 wallet to continue."
31648
+ }
31649
+ ),
31650
+ /* @__PURE__ */ jsx55(
31651
+ "a",
31652
+ {
31653
+ href: "https://metamask.io/download/",
31654
+ target: "_blank",
31655
+ rel: "noopener noreferrer",
31656
+ style: {
31657
+ display: "inline-flex",
31658
+ alignItems: "center",
31659
+ justifyContent: "center",
31660
+ padding: `${spacing[2]} ${spacing[4]}`,
31661
+ borderRadius: borderRadius.lg,
31662
+ backgroundColor: colors.primary,
31663
+ color: colors.primaryForeground,
31664
+ fontSize: fontSize.sm,
31665
+ fontWeight: fontWeight.medium,
31666
+ textDecoration: "none"
31667
+ },
31668
+ children: "Install MetaMask"
31669
+ }
31670
+ )
31671
+ ] }) : /* @__PURE__ */ jsx55(
31672
+ "div",
31380
31673
  {
31381
31674
  style: {
31382
- fontSize: fontSize.sm,
31383
- color: colors.mutedForeground,
31384
- marginBottom: spacing[4]
31675
+ display: "flex",
31676
+ flexDirection: "column",
31677
+ gap: spacing[3]
31385
31678
  },
31386
- children: "Please install a web3 wallet to continue."
31679
+ children: filteredWallets.map((wallet) => {
31680
+ const isWalletConnected = managerConnected && walletMetaId === wallet.meta.id;
31681
+ const isConnecting = connectingId === wallet.meta.id && walletStatus === "connecting";
31682
+ return /* @__PURE__ */ jsxs44(
31683
+ "div",
31684
+ {
31685
+ style: mergeStyles(
31686
+ {
31687
+ width: "100%",
31688
+ display: "flex",
31689
+ alignItems: "center",
31690
+ gap: spacing[4],
31691
+ padding: spacing[4],
31692
+ borderRadius: borderRadius["2xl"],
31693
+ backgroundColor: colors.card,
31694
+ border: `1px solid ${colors.border}`
31695
+ },
31696
+ isWalletConnected && {
31697
+ boxShadow: `0 0 0 2px ${colors.primary}`,
31698
+ border: `1px solid ${colors.primary}`
31699
+ }
31700
+ ),
31701
+ children: [
31702
+ /* @__PURE__ */ jsx55(
31703
+ "div",
31704
+ {
31705
+ style: {
31706
+ width: "3rem",
31707
+ height: "3rem",
31708
+ borderRadius: borderRadius.xl,
31709
+ backgroundColor: colors.muted,
31710
+ display: "flex",
31711
+ alignItems: "center",
31712
+ justifyContent: "center",
31713
+ overflow: "hidden",
31714
+ flexShrink: 0
31715
+ },
31716
+ children: wallet.meta.logo ? /* @__PURE__ */ jsx55(
31717
+ "img",
31718
+ {
31719
+ src: wallet.meta.logo,
31720
+ alt: wallet.meta.name,
31721
+ style: {
31722
+ width: "2rem",
31723
+ height: "2rem",
31724
+ objectFit: "contain"
31725
+ }
31726
+ }
31727
+ ) : wallet.detail?.info?.icon ? /* @__PURE__ */ jsx55(
31728
+ "img",
31729
+ {
31730
+ src: wallet.detail.info.icon,
31731
+ alt: wallet.meta.name,
31732
+ style: {
31733
+ width: "2rem",
31734
+ height: "2rem",
31735
+ objectFit: "contain"
31736
+ }
31737
+ }
31738
+ ) : /* @__PURE__ */ jsx55("span", { style: { fontSize: "1.5rem" }, children: wallet.meta.emoji || "\u{1F45B}" })
31739
+ }
31740
+ ),
31741
+ /* @__PURE__ */ jsxs44("div", { style: { flex: 1, minWidth: 0 }, children: [
31742
+ /* @__PURE__ */ jsx55(
31743
+ "p",
31744
+ {
31745
+ style: {
31746
+ fontWeight: fontWeight.semibold,
31747
+ color: colors.foreground
31748
+ },
31749
+ children: wallet.meta.name
31750
+ }
31751
+ ),
31752
+ isWalletConnected && walletAddress && /* @__PURE__ */ jsxs44(
31753
+ "p",
31754
+ {
31755
+ style: {
31756
+ fontSize: fontSize.xs,
31757
+ color: colors.mutedForeground
31758
+ },
31759
+ children: [
31760
+ walletAddress.slice(0, 6),
31761
+ "...",
31762
+ walletAddress.slice(-4)
31763
+ ]
31764
+ }
31765
+ )
31766
+ ] }),
31767
+ isConnecting ? /* @__PURE__ */ jsx55(
31768
+ "div",
31769
+ {
31770
+ style: {
31771
+ width: "1.25rem",
31772
+ height: "1.25rem",
31773
+ border: `2px solid ${colors.mutedForeground}`,
31774
+ borderTopColor: "transparent",
31775
+ borderRadius: "9999px",
31776
+ animation: "tw-spin 1s linear infinite",
31777
+ flexShrink: 0
31778
+ }
31779
+ }
31780
+ ) : isWalletConnected ? /* @__PURE__ */ jsx55(
31781
+ "button",
31782
+ {
31783
+ onClick: handleDisconnect,
31784
+ style: {
31785
+ padding: `${spacing[1.5]} ${spacing[3]}`,
31786
+ borderRadius: "9999px",
31787
+ backgroundColor: "rgba(239,68,68,0.1)",
31788
+ color: "#ef4444",
31789
+ fontSize: fontSize.xs,
31790
+ fontWeight: fontWeight.medium,
31791
+ border: 0,
31792
+ cursor: "pointer",
31793
+ flexShrink: 0
31794
+ },
31795
+ children: "Disconnect"
31796
+ }
31797
+ ) : /* @__PURE__ */ jsx55(
31798
+ "button",
31799
+ {
31800
+ onClick: () => void handleClick(wallet),
31801
+ disabled: walletStatus === "connecting",
31802
+ style: mergeStyles(
31803
+ {
31804
+ padding: `${spacing[1.5]} ${spacing[3]}`,
31805
+ borderRadius: "9999px",
31806
+ backgroundColor: "rgba(59,130,246,0.1)",
31807
+ color: colors.primary,
31808
+ fontSize: fontSize.xs,
31809
+ fontWeight: fontWeight.medium,
31810
+ border: 0,
31811
+ cursor: "pointer",
31812
+ flexShrink: 0
31813
+ },
31814
+ walletStatus === "connecting" && {
31815
+ opacity: 0.5,
31816
+ cursor: "not-allowed"
31817
+ }
31818
+ ),
31819
+ children: "Connect"
31820
+ }
31821
+ )
31822
+ ]
31823
+ },
31824
+ wallet.meta.id
31825
+ );
31826
+ })
31387
31827
  }
31388
31828
  ),
31389
- /* @__PURE__ */ jsx55(
31390
- "a",
31391
- {
31392
- href: "https://metamask.io/download/",
31393
- target: "_blank",
31394
- rel: "noopener noreferrer",
31395
- style: {
31396
- display: "inline-flex",
31397
- alignItems: "center",
31398
- justifyContent: "center",
31399
- padding: `${spacing[2]} ${spacing[4]}`,
31400
- borderRadius: borderRadius.lg,
31401
- backgroundColor: colors.primary,
31402
- color: colors.primaryForeground,
31403
- fontSize: fontSize.sm,
31404
- fontWeight: fontWeight.medium,
31405
- textDecoration: "none"
31406
- },
31407
- children: "Install MetaMask"
31408
- }
31409
- )
31410
- ] }) : /* @__PURE__ */ jsx55(
31411
- "div",
31412
- {
31413
- style: {
31414
- display: "flex",
31415
- flexDirection: "column",
31416
- gap: spacing[3]
31417
- },
31418
- children: detected.map((wallet) => {
31419
- const isConnecting = connectingId === wallet.meta.id;
31420
- const isConnected = walletStatus === "connected" && connectingId === null && walletAddress !== null && connectedWalletId === wallet.meta.id;
31829
+ selectedNamespace === "evm" && /* @__PURE__ */ jsxs44(Fragment7, { children: [
31830
+ /* @__PURE__ */ jsx55(
31831
+ "div",
31832
+ {
31833
+ style: {
31834
+ height: 1,
31835
+ backgroundColor: colors.border,
31836
+ margin: `${spacing[3]} 0`
31837
+ }
31838
+ }
31839
+ ),
31840
+ (() => {
31841
+ const wcConnected = managerConnected && connectedVia === "walletconnect";
31421
31842
  return /* @__PURE__ */ jsxs44(
31422
31843
  "div",
31423
31844
  {
@@ -31430,13 +31851,15 @@ function SwapWalletSelector({
31430
31851
  padding: spacing[4],
31431
31852
  borderRadius: borderRadius["2xl"],
31432
31853
  backgroundColor: colors.card,
31433
- border: `1px solid ${colors.border}`
31854
+ border: `1px solid ${colors.border}`,
31855
+ cursor: "pointer"
31434
31856
  },
31435
- isConnected && {
31857
+ wcConnected && {
31436
31858
  boxShadow: `0 0 0 2px ${colors.primary}`,
31437
31859
  border: `1px solid ${colors.primary}`
31438
31860
  }
31439
31861
  ),
31862
+ onClick: !wcConnected ? () => void handleWalletConnect() : void 0,
31440
31863
  children: [
31441
31864
  /* @__PURE__ */ jsx55(
31442
31865
  "div",
@@ -31449,35 +31872,24 @@ function SwapWalletSelector({
31449
31872
  display: "flex",
31450
31873
  alignItems: "center",
31451
31874
  justifyContent: "center",
31452
- overflow: "hidden",
31453
31875
  flexShrink: 0
31454
31876
  },
31455
- children: wallet.meta.logo ? /* @__PURE__ */ jsx55(
31456
- "img",
31457
- {
31458
- src: wallet.meta.logo,
31459
- alt: wallet.meta.name,
31460
- style: {
31461
- width: "2rem",
31462
- height: "2rem",
31463
- objectFit: "contain"
31464
- }
31465
- }
31466
- ) : wallet.detail?.info?.icon ? /* @__PURE__ */ jsx55(
31467
- "img",
31877
+ children: /* @__PURE__ */ jsx55(
31878
+ "svg",
31468
31879
  {
31469
- src: wallet.detail.info.icon,
31470
- alt: wallet.meta.name,
31471
31880
  style: {
31472
- width: "2rem",
31473
- height: "2rem",
31474
- objectFit: "contain"
31475
- }
31881
+ width: "1.5rem",
31882
+ height: "1.5rem",
31883
+ color: colors.blue[500]
31884
+ },
31885
+ viewBox: "0 0 24 24",
31886
+ fill: "currentColor",
31887
+ children: /* @__PURE__ */ jsx55("path", { d: "M6.09 10.56c3.26-3.2 8.56-3.2 11.82 0l.39.39a.4.4 0 010 .58l-1.34 1.31a.21.21 0 01-.3 0l-.54-.53c-2.28-2.23-5.97-2.23-8.24 0l-.58.56a.21.21 0 01-.3 0L5.66 11.6a.4.4 0 010-.58l.43-.46zm14.6 2.72l1.2 1.17a.4.4 0 010 .58l-5.38 5.27a.43.43 0 01-.6 0l-3.82-3.74a.11.11 0 00-.15 0l-3.82 3.74a.43.43 0 01-.6 0L2.15 15.03a.4.4 0 010-.58l1.2-1.17a.43.43 0 01.6 0l3.82 3.74c.04.04.1.04.15 0l3.82-3.74a.43.43 0 01.6 0l3.82 3.74c.04.04.1.04.15 0l3.82-3.74a.43.43 0 01.6 0z" })
31476
31888
  }
31477
- ) : /* @__PURE__ */ jsx55("span", { style: { fontSize: "1.5rem" }, children: wallet.meta.emoji || "\u{1F45B}" })
31889
+ )
31478
31890
  }
31479
31891
  ),
31480
- /* @__PURE__ */ jsxs44("div", { style: { flex: 1 }, children: [
31892
+ /* @__PURE__ */ jsxs44("div", { style: { flex: 1, minWidth: 0 }, children: [
31481
31893
  /* @__PURE__ */ jsx55(
31482
31894
  "p",
31483
31895
  {
@@ -31485,10 +31897,10 @@ function SwapWalletSelector({
31485
31897
  fontWeight: fontWeight.semibold,
31486
31898
  color: colors.foreground
31487
31899
  },
31488
- children: wallet.meta.name
31900
+ children: "WalletConnect"
31489
31901
  }
31490
31902
  ),
31491
- isConnected && walletAddress && /* @__PURE__ */ jsxs44(
31903
+ wcConnected && walletAddress && /* @__PURE__ */ jsxs44(
31492
31904
  "p",
31493
31905
  {
31494
31906
  style: {
@@ -31503,7 +31915,7 @@ function SwapWalletSelector({
31503
31915
  }
31504
31916
  )
31505
31917
  ] }),
31506
- isConnecting ? /* @__PURE__ */ jsx55(
31918
+ wcConnecting ? /* @__PURE__ */ jsx55(
31507
31919
  "div",
31508
31920
  {
31509
31921
  style: {
@@ -31512,40 +31924,58 @@ function SwapWalletSelector({
31512
31924
  border: `2px solid ${colors.mutedForeground}`,
31513
31925
  borderTopColor: "transparent",
31514
31926
  borderRadius: "9999px",
31515
- animation: "tw-spin 1s linear infinite"
31927
+ animation: "tw-spin 1s linear infinite",
31928
+ flexShrink: 0
31516
31929
  }
31517
31930
  }
31931
+ ) : wcConnected ? /* @__PURE__ */ jsx55(
31932
+ "button",
31933
+ {
31934
+ onClick: (e2) => {
31935
+ e2.stopPropagation();
31936
+ handleDisconnect();
31937
+ },
31938
+ style: {
31939
+ padding: `${spacing[1.5]} ${spacing[3]}`,
31940
+ borderRadius: "9999px",
31941
+ backgroundColor: "rgba(239,68,68,0.1)",
31942
+ color: "#ef4444",
31943
+ fontSize: fontSize.xs,
31944
+ fontWeight: fontWeight.medium,
31945
+ border: 0,
31946
+ cursor: "pointer",
31947
+ flexShrink: 0
31948
+ },
31949
+ children: "Disconnect"
31950
+ }
31518
31951
  ) : /* @__PURE__ */ jsx55(
31519
31952
  "button",
31520
31953
  {
31521
- onClick: () => handleClick(wallet),
31522
- disabled: walletStatus === "connecting",
31523
- style: mergeStyles(
31524
- {
31525
- padding: `${spacing[1.5]} ${spacing[3]}`,
31526
- borderRadius: "9999px",
31527
- backgroundColor: "rgba(59,130,246,0.1)",
31528
- color: colors.primary,
31529
- fontSize: fontSize.xs,
31530
- fontWeight: fontWeight.medium,
31531
- border: 0,
31532
- cursor: "pointer"
31533
- },
31534
- walletStatus === "connecting" && {
31535
- opacity: 0.5,
31536
- cursor: "not-allowed"
31537
- }
31538
- ),
31954
+ onClick: (e2) => {
31955
+ e2.stopPropagation();
31956
+ void handleWalletConnect();
31957
+ },
31958
+ disabled: wcConnecting,
31959
+ style: {
31960
+ padding: `${spacing[1.5]} ${spacing[3]}`,
31961
+ borderRadius: "9999px",
31962
+ backgroundColor: "rgba(59,130,246,0.1)",
31963
+ color: colors.primary,
31964
+ fontSize: fontSize.xs,
31965
+ fontWeight: fontWeight.medium,
31966
+ border: 0,
31967
+ cursor: "pointer",
31968
+ flexShrink: 0
31969
+ },
31539
31970
  children: "Connect"
31540
31971
  }
31541
31972
  )
31542
31973
  ]
31543
- },
31544
- wallet.meta.id
31974
+ }
31545
31975
  );
31546
- })
31547
- }
31548
- ) })
31976
+ })()
31977
+ ] })
31978
+ ] })
31549
31979
  ] });
31550
31980
  }
31551
31981
  var init_SwapWalletSelector = __esm({
@@ -31554,6 +31984,7 @@ var init_SwapWalletSelector = __esm({
31554
31984
  init_styles();
31555
31985
  init_utils();
31556
31986
  init_wallets();
31987
+ init_config2();
31557
31988
  init_Toast();
31558
31989
  }
31559
31990
  });
@@ -31637,11 +32068,11 @@ import {
31637
32068
  Suspense as Suspense2,
31638
32069
  useCallback as useCallback22,
31639
32070
  useEffect as useEffect30,
31640
- useMemo as useMemo25,
32071
+ useMemo as useMemo26,
31641
32072
  useRef as useRef17,
31642
32073
  useState as useState28
31643
32074
  } from "react";
31644
- import { Fragment as Fragment7, jsx as jsx56, jsxs as jsxs45 } from "react/jsx-runtime";
32075
+ import { Fragment as Fragment8, jsx as jsx56, jsxs as jsxs45 } from "react/jsx-runtime";
31645
32076
  function fmtAmount(n, max = 6) {
31646
32077
  if (!isFinite(n) || n === 0) return "0";
31647
32078
  return n.toLocaleString(void 0, { maximumFractionDigits: max });
@@ -31778,6 +32209,7 @@ function SwapMode({
31778
32209
  );
31779
32210
  const settingsRef = useRef17(null);
31780
32211
  const currencyDropdownRef = useRef17(null);
32212
+ const { emitEvent } = useTrustware();
31781
32213
  const { features } = useTrustwareConfig();
31782
32214
  const defaultDestRef = features.swapDefaultDestToken;
31783
32215
  const lockDestToken = features.swapLockDestToken && !!defaultDestRef;
@@ -31788,21 +32220,21 @@ function SwapMode({
31788
32220
  isLoading: chainsLoading,
31789
32221
  error: chainsError
31790
32222
  } = useChains();
31791
- const allowedDestChainIds = useMemo25(() => {
32223
+ const allowedDestChainIds = useMemo26(() => {
31792
32224
  if (!allowedDestTokens || allowedDestTokens.length === 0) return null;
31793
32225
  return new Set(allowedDestTokens.map((t) => t.chainId));
31794
32226
  }, [allowedDestTokens]);
31795
- const toPopularChains = useMemo25(
32227
+ const toPopularChains = useMemo26(
31796
32228
  () => allowedDestChainIds ? popularChains.filter(
31797
32229
  (c) => allowedDestChainIds.has(Number(c.chainId))
31798
32230
  ) : popularChains,
31799
32231
  [popularChains, allowedDestChainIds]
31800
32232
  );
31801
- const toOtherChains = useMemo25(
32233
+ const toOtherChains = useMemo26(
31802
32234
  () => allowedDestChainIds ? otherChains.filter((c) => allowedDestChainIds.has(Number(c.chainId))) : otherChains,
31803
32235
  [otherChains, allowedDestChainIds]
31804
32236
  );
31805
- const allChains = useMemo25(
32237
+ const allChains = useMemo26(
31806
32238
  () => [...popularChains, ...otherChains],
31807
32239
  [popularChains, otherChains]
31808
32240
  );
@@ -31846,7 +32278,7 @@ function SwapMode({
31846
32278
  (c) => setFromChain(c),
31847
32279
  []
31848
32280
  );
31849
- const { yourWalletTokens } = useWalletTokenState({
32281
+ const { yourWalletTokens, reloadWalletTokens } = useWalletTokenState({
31850
32282
  walletAddress,
31851
32283
  selectedChain: fromChain,
31852
32284
  setSelectedChain: setFromChainStable,
@@ -31855,18 +32287,18 @@ function SwapMode({
31855
32287
  });
31856
32288
  const route = useSwapRoute();
31857
32289
  const execution = useSwapExecution(fromChain);
31858
- const fromTokenPriceUSD = useMemo25(() => {
32290
+ const fromTokenPriceUSD = useMemo26(() => {
31859
32291
  const p = fromToken?.usdPrice;
31860
32292
  return typeof p === "number" && Number.isFinite(p) && p > 0 ? p : 0;
31861
32293
  }, [fromToken]);
31862
32294
  const hasFromUsdPrice = fromTokenPriceUSD > 0;
31863
- const toTokenPriceUSD = useMemo25(() => {
32295
+ const toTokenPriceUSD = useMemo26(() => {
31864
32296
  const p = toToken?.usdPrice;
31865
32297
  return typeof p === "number" && Number.isFinite(p) && p > 0 ? p : 0;
31866
32298
  }, [toToken]);
31867
32299
  const hasToUsdPrice = toTokenPriceUSD > 0;
31868
32300
  const rawSellNum = parseFloat(amount) || 0;
31869
- const usdSellNum = useMemo25(() => {
32301
+ const usdSellNum = useMemo26(() => {
31870
32302
  if (amountInputMode === "usd") return rawSellNum / currencyRate;
31871
32303
  return hasFromUsdPrice ? rawSellNum * fromTokenPriceUSD : 0;
31872
32304
  }, [
@@ -31876,7 +32308,7 @@ function SwapMode({
31876
32308
  hasFromUsdPrice,
31877
32309
  fromTokenPriceUSD
31878
32310
  ]);
31879
- const tokenSellNum = useMemo25(() => {
32311
+ const tokenSellNum = useMemo26(() => {
31880
32312
  if (amountInputMode === "usd") {
31881
32313
  return hasFromUsdPrice && fromTokenPriceUSD > 0 ? usdSellNum / fromTokenPriceUSD : 0;
31882
32314
  }
@@ -31888,7 +32320,7 @@ function SwapMode({
31888
32320
  hasFromUsdPrice,
31889
32321
  fromTokenPriceUSD
31890
32322
  ]);
31891
- const tokenAmountStr = useMemo25(() => {
32323
+ const tokenAmountStr = useMemo26(() => {
31892
32324
  if (tokenSellNum <= 0) return "";
31893
32325
  const decimals = fromToken?.decimals ?? 18;
31894
32326
  return truncateDecimal(tokenSellNum, Math.min(decimals, 18));
@@ -31918,8 +32350,16 @@ function SwapMode({
31918
32350
  setAmountInputMode("usd");
31919
32351
  }
31920
32352
  setStage("home");
32353
+ emitEvent?.({
32354
+ type: "swap_route_changed",
32355
+ fromChain: String(chain.chainId),
32356
+ fromToken: token.address,
32357
+ toChain: String(toChain?.chainId ?? ""),
32358
+ toToken: toToken?.address ?? "",
32359
+ ...amount ? { amount } : {}
32360
+ });
31921
32361
  },
31922
- [route]
32362
+ [route, emitEvent, toToken, toChain, amount]
31923
32363
  );
31924
32364
  const handleSelectToToken = useCallback22(
31925
32365
  (token, chain) => {
@@ -31927,18 +32367,35 @@ function SwapMode({
31927
32367
  setToChain(chain);
31928
32368
  route.clear();
31929
32369
  setStage("home");
32370
+ emitEvent?.({
32371
+ type: "swap_route_changed",
32372
+ fromChain: String(fromChain?.chainId ?? ""),
32373
+ fromToken: fromToken?.address ?? "",
32374
+ toChain: String(chain.chainId),
32375
+ toToken: token.address,
32376
+ ...amount ? { amount } : {}
32377
+ });
31930
32378
  },
31931
- [route]
32379
+ [route, emitEvent, fromToken, fromChain, amount]
31932
32380
  );
31933
32381
  const handleFlip = useCallback22(() => {
31934
32382
  if (lockDestToken) return;
32383
+ const newFrom = toToken ?? fromToken;
32384
+ const newFromChain = toChain ?? fromChain;
31935
32385
  setFromToken((prev) => toToken ?? prev);
31936
32386
  setFromChain((prev) => toChain ?? prev);
31937
32387
  setToToken(fromToken);
31938
32388
  setToChain(fromChain);
31939
32389
  setAmount("");
31940
32390
  route.clear();
31941
- }, [lockDestToken, fromToken, fromChain, toToken, toChain, route]);
32391
+ emitEvent?.({
32392
+ type: "swap_route_changed",
32393
+ fromChain: String(newFromChain?.chainId ?? ""),
32394
+ fromToken: newFrom?.address ?? "",
32395
+ toChain: String(fromChain?.chainId ?? ""),
32396
+ toToken: fromToken?.address ?? ""
32397
+ });
32398
+ }, [lockDestToken, fromToken, fromChain, toToken, toChain, route, emitEvent]);
31942
32399
  const fromChainType = normalizeChainType2(fromChain);
31943
32400
  const toChainType = normalizeChainType2(toChain);
31944
32401
  const needsDestAddress = !!fromChainType && !!toChainType && fromChainType !== toChainType;
@@ -32011,7 +32468,8 @@ function SwapMode({
32011
32468
  setCompletedAt(null);
32012
32469
  setCopiedHash(null);
32013
32470
  setStage("home");
32014
- }, [execution, route]);
32471
+ reloadWalletTokens();
32472
+ }, [execution, route, reloadWalletTokens]);
32015
32473
  const handleSwapBack = useCallback22(() => {
32016
32474
  const prevFrom = fromToken;
32017
32475
  const prevFromChain = fromChain;
@@ -32026,7 +32484,16 @@ function SwapMode({
32026
32484
  setCompletedAt(null);
32027
32485
  setCopiedHash(null);
32028
32486
  setStage("home");
32029
- }, [fromToken, fromChain, toToken, toChain, execution, route]);
32487
+ reloadWalletTokens();
32488
+ }, [
32489
+ fromToken,
32490
+ fromChain,
32491
+ toToken,
32492
+ toChain,
32493
+ execution,
32494
+ route,
32495
+ reloadWalletTokens
32496
+ ]);
32030
32497
  const handleCopyHash = useCallback22((hash) => {
32031
32498
  if (!navigator?.clipboard?.writeText) return;
32032
32499
  void navigator.clipboard.writeText(hash).then(() => {
@@ -32060,7 +32527,7 @@ function SwapMode({
32060
32527
  fromToken?.decimals,
32061
32528
  route
32062
32529
  ]);
32063
- const fromBalance = useMemo25(() => {
32530
+ const fromBalance = useMemo26(() => {
32064
32531
  const walletToken = fromToken;
32065
32532
  if (!walletToken || !("balance" in walletToken)) return null;
32066
32533
  const raw = walletToken.balance;
@@ -32070,7 +32537,7 @@ function SwapMode({
32070
32537
  return Number.isFinite(n) ? n : null;
32071
32538
  }, [fromToken]);
32072
32539
  const balanceUsd = fromBalance !== null && hasFromUsdPrice ? fromBalance * fromTokenPriceUSD : null;
32073
- const estimatedToAmount = useMemo25(() => {
32540
+ const estimatedToAmount = useMemo26(() => {
32074
32541
  if (tokenSellNum <= 0 || !hasFromUsdPrice || !hasToUsdPrice) return null;
32075
32542
  return tokenSellNum * (fromTokenPriceUSD / toTokenPriceUSD);
32076
32543
  }, [
@@ -32080,10 +32547,10 @@ function SwapMode({
32080
32547
  hasFromUsdPrice,
32081
32548
  hasToUsdPrice
32082
32549
  ]);
32083
- const backendToUsdStr = useMemo25(() => {
32550
+ const backendToUsdStr = useMemo26(() => {
32084
32551
  return route.data?.finalExchangeRate?.toAmountMinUSD ?? route.data?.route?.estimate?.toAmountMinUsd ?? route.data?.route?.estimate?.toAmountUsd ?? null;
32085
32552
  }, [route.data]);
32086
- const toAmount = useMemo25(() => {
32553
+ const toAmount = useMemo26(() => {
32087
32554
  if (backendToUsdStr && toTokenPriceUSD > 0) {
32088
32555
  const usd = parseFloat(backendToUsdStr);
32089
32556
  if (Number.isFinite(usd) && usd > 0) return usd / toTokenPriceUSD;
@@ -32109,7 +32576,7 @@ function SwapMode({
32109
32576
  estimatedToAmount
32110
32577
  ]);
32111
32578
  const fromUsd = usdSellNum;
32112
- const toUsd = useMemo25(() => {
32579
+ const toUsd = useMemo26(() => {
32113
32580
  if (backendToUsdStr) {
32114
32581
  const n = parseFloat(backendToUsdStr);
32115
32582
  if (Number.isFinite(n) && n > 0) return n;
@@ -32120,12 +32587,12 @@ function SwapMode({
32120
32587
  const isEstimate = !route.data;
32121
32588
  const USD_EPSILON = 1e-3;
32122
32589
  const displayToUsd = toUsd > USD_EPSILON ? toUsd : estimatedToAmount !== null && hasToUsdPrice ? estimatedToAmount * toTokenPriceUSD : 0;
32123
- const priceImpact = useMemo25(() => {
32590
+ const priceImpact = useMemo26(() => {
32124
32591
  if (!route.data || fromUsd < 0.01 || displayToUsd < 0.01) return null;
32125
32592
  const impact = 1 - displayToUsd / fromUsd;
32126
32593
  return impact > 1e-3 ? impact : null;
32127
32594
  }, [route.data, fromUsd, displayToUsd]);
32128
- const routePath = useMemo25(() => {
32595
+ const routePath = useMemo26(() => {
32129
32596
  if (!route.data) return null;
32130
32597
  const provider = route.data.route?.provider;
32131
32598
  const steps = route.data.route?.steps;
@@ -32152,19 +32619,19 @@ function SwapMode({
32152
32619
  return null;
32153
32620
  }, [route.data, fromToken?.symbol, toToken?.symbol]);
32154
32621
  const isGasSponsored = !!route.data?.sponsorship;
32155
- const networkCostUsd = useMemo25(() => {
32622
+ const networkCostUsd = useMemo26(() => {
32156
32623
  const fees = route.data?.route?.estimate?.fees;
32157
32624
  if (!fees?.length) return null;
32158
32625
  const gasTotal = fees.filter((f) => f.type?.toLowerCase().includes("gas")).reduce((sum, f) => sum + (Number(f.amountUsd) || 0), 0);
32159
32626
  return gasTotal > 0 ? gasTotal : null;
32160
32627
  }, [route.data]);
32161
- const protocolFeeUsd = useMemo25(() => {
32628
+ const protocolFeeUsd = useMemo26(() => {
32162
32629
  const fees = route.data?.route?.estimate?.fees;
32163
32630
  if (!fees?.length) return null;
32164
32631
  const total = fees.filter((f) => !f.type?.toLowerCase().includes("gas")).reduce((sum, f) => sum + (Number(f.amountUsd) || 0), 0);
32165
32632
  return total > 0 ? total : null;
32166
32633
  }, [route.data]);
32167
- const exchangeRate = useMemo25(() => {
32634
+ const exchangeRate = useMemo26(() => {
32168
32635
  if (!hasFromUsdPrice || !hasToUsdPrice) return null;
32169
32636
  return toTokenPriceUSD / fromTokenPriceUSD;
32170
32637
  }, [fromTokenPriceUSD, toTokenPriceUSD, hasFromUsdPrice, hasToUsdPrice]);
@@ -32785,7 +33252,7 @@ function SwapMode({
32785
33252
  padding: 0,
32786
33253
  transition: "color 0.15s"
32787
33254
  },
32788
- children: isCopied ? "Copied!" : /* @__PURE__ */ jsxs45(Fragment7, { children: [
33255
+ children: isCopied ? "Copied!" : /* @__PURE__ */ jsxs45(Fragment8, { children: [
32789
33256
  txHash.slice(0, 6),
32790
33257
  "\u2026",
32791
33258
  txHash.slice(-4),
@@ -33834,7 +34301,7 @@ function SwapMode({
33834
34301
  ) : /* @__PURE__ */ jsx56("span", { style: { color: colors.mutedForeground }, children: "\u2014" })
33835
34302
  }
33836
34303
  ),
33837
- showReviewDetails && /* @__PURE__ */ jsxs45(Fragment7, { children: [
34304
+ showReviewDetails && /* @__PURE__ */ jsxs45(Fragment8, { children: [
33838
34305
  /* @__PURE__ */ jsx56(
33839
34306
  ReviewDetailRow,
33840
34307
  {
@@ -34408,9 +34875,15 @@ function SwapMode({
34408
34875
  fromToken.address,
34409
34876
  fromChainType ?? ""
34410
34877
  ) || isZeroAddrLike(fromToken.address, fromChainType));
34411
- const effectivePct = isNative && p.value === 1 ? 0.995 : p.value;
34878
+ const isSolana = normalizeChainType2(fromChain) === "solana";
34879
+ const effectiveAmount = (() => {
34880
+ if (!isNative || p.value !== 1)
34881
+ return fromBalance * p.value;
34882
+ if (isSolana) return Math.max(0, fromBalance - 0.01);
34883
+ return fromBalance * 0.995;
34884
+ })();
34412
34885
  if (amountInputMode === "usd" && hasFromUsdPrice) {
34413
- const fiatVal = fromBalance * effectivePct * fromTokenPriceUSD * currencyRate;
34886
+ const fiatVal = effectiveAmount * fromTokenPriceUSD * currencyRate;
34414
34887
  const dp = fiatVal > 0 ? Math.min(
34415
34888
  8,
34416
34889
  Math.max(
@@ -34422,7 +34895,7 @@ function SwapMode({
34422
34895
  } else {
34423
34896
  setAmount(
34424
34897
  truncateDecimal(
34425
- fromBalance * effectivePct,
34898
+ effectiveAmount,
34426
34899
  Math.min(decimals, 6)
34427
34900
  )
34428
34901
  );
@@ -35680,6 +36153,7 @@ var init_SwapMode = __esm({
35680
36153
  init_tokenAmount();
35681
36154
  init_chainHelpers();
35682
36155
  init_hooks();
36156
+ init_provider();
35683
36157
  init_useSwapRoute();
35684
36158
  init_useSwapExecution();
35685
36159
  init_useForex();
@@ -35716,7 +36190,7 @@ import {
35716
36190
  useImperativeHandle,
35717
36191
  forwardRef
35718
36192
  } from "react";
35719
- import { Fragment as Fragment8, jsx as jsx57, jsxs as jsxs46 } from "react/jsx-runtime";
36193
+ import { Fragment as Fragment9, jsx as jsx57, jsxs as jsxs46 } from "react/jsx-runtime";
35720
36194
  function WidgetContent({
35721
36195
  style,
35722
36196
  onStateChange,
@@ -35798,7 +36272,7 @@ function WidgetInner({
35798
36272
  const handleRefresh = useCallback23(() => {
35799
36273
  revalidate?.();
35800
36274
  }, [revalidate]);
35801
- return /* @__PURE__ */ jsxs46(Fragment8, { children: [
36275
+ return /* @__PURE__ */ jsxs46(Fragment9, { children: [
35802
36276
  /* @__PURE__ */ jsxs46(WidgetContainer, { theme: effectiveTheme, style, children: [
35803
36277
  /* @__PURE__ */ jsx57(
35804
36278
  WidgetContent,