@suilend/sui-fe-next 2.0.26 → 2.0.28

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.
@@ -57,7 +57,7 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
57
57
  var _a, _b;
58
58
  import { useRouter } from "next/router";
59
59
  import { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState, } from "react";
60
- import { createDAppKit } from "@mysten/dapp-kit-core";
60
+ import { createDAppKit, getWalletUniqueIdentifier, } from "@mysten/dapp-kit-core";
61
61
  import { DAppKitProvider, useCurrentAccount, useCurrentWallet, useDAppKit, useWalletConnection, useWallets, } from "@mysten/dapp-kit-react";
62
62
  import { SuiJsonRpcClient, } from "@mysten/sui/jsonRpc";
63
63
  import { Transaction } from "@mysten/sui/transactions";
@@ -212,16 +212,16 @@ export var useWalletContext = function () { return useContext(WalletContext); };
212
212
  function Inner(_a) {
213
213
  var _b;
214
214
  var _this = this;
215
- var _c, _d, _e;
215
+ var _c, _d;
216
216
  var appName = _a.appName, children = _a.children;
217
217
  var router = useRouter();
218
218
  var queryParams = (_b = {},
219
219
  _b[WalletContextQueryParams.WALLET] = router.query[WalletContextQueryParams.WALLET],
220
220
  _b);
221
- var _f = useSettingsContext(), rpc = _f.rpc, suiClient = _f.suiClient;
221
+ var _e = useSettingsContext(), rpc = _e.rpc, suiClient = _e.suiClient;
222
222
  // WalletConnect via @walletconnect/universal-provider
223
223
  // Matches the reference implementation: https://github.com/WalletConnect/react-core-up-sui
224
- var _g = useState(), wcSession = _g[0], setWcSession = _g[1];
224
+ var _f = useState(), wcSession = _f[0], setWcSession = _f[1];
225
225
  // Raw address as returned by the wallet (e.g. Fireblocks returns an
226
226
  // EVM-length address). We must send this back in WalletConnect request
227
227
  // params so the wallet recognises it as its own account.
@@ -369,7 +369,7 @@ function Inner(_a) {
369
369
  wallets__web,
370
370
  ]);
371
371
  // Wallet
372
- var _h = useState(false), isConnectWalletDropdownOpen = _h[0], setIsConnectWalletDropdownOpen = _h[1];
372
+ var _g = useState(false), isConnectWalletDropdownOpen = _g[0], setIsConnectWalletDropdownOpen = _g[1];
373
373
  var rawWallet = useCurrentWallet();
374
374
  var wallet = useMemo(function () {
375
375
  if (sessionAddress) {
@@ -540,14 +540,24 @@ function Inner(_a) {
540
540
  ? walletConnectSignPersonalMessage
541
541
  : function (message) { return signPersonalMessageRaw({ message: message }); };
542
542
  }, [sessionAddress, walletConnectSignPersonalMessage, signPersonalMessageRaw]);
543
+ var DAPP_KIT_STORAGE_KEY = "mysten-dapp-kit:selected-wallet-and-address";
543
544
  var switchAccountWrapper = useCallback(function (_account, addressNameServiceName) {
544
- var _a, _b, _c;
545
+ var _a, _b, _c, _d;
545
546
  var accountLabel = (_b = (_a = _account === null || _account === void 0 ? void 0 : _account.label) !== null && _a !== void 0 ? _a : addressNameServiceName) !== null && _b !== void 0 ? _b : formatAddress(_account.address);
546
547
  try {
547
548
  var matchingAccount = (_c = walletConnection.wallet) === null || _c === void 0 ? void 0 : _c.accounts.find(function (a) { return a.address === _account.address; });
548
549
  if (!matchingAccount)
549
550
  throw new Error("Account not found");
550
551
  dAppKit.switchAccount({ account: matchingAccount });
552
+ // Persist to dapp-kit's own storage key so autoconnect restores
553
+ // the correct account on page reload.
554
+ try {
555
+ var walletId = getWalletUniqueIdentifier(matchingAccount);
556
+ var intents = (_d = walletConnection.supportedIntents) !== null && _d !== void 0 ? _d : [];
557
+ var storageValue = "".concat(walletId.replace(":", "_"), ":").concat(matchingAccount.address, ":").concat(intents.join(","), ":");
558
+ localStorage.setItem(DAPP_KIT_STORAGE_KEY, storageValue);
559
+ }
560
+ catch (_e) { }
551
561
  showInfoToast("Switched to ".concat(accountLabel), {
552
562
  description: (_account === null || _account === void 0 ? void 0 : _account.label)
553
563
  ? (addressNameServiceName !== null && addressNameServiceName !== void 0 ? addressNameServiceName : formatAddress(_account.address))
@@ -558,7 +568,7 @@ function Inner(_a) {
558
568
  showErrorToast("Failed to switch to ".concat(accountLabel), err);
559
569
  console.error(err);
560
570
  }
561
- }, [dAppKit, (_e = walletConnection.wallet) === null || _e === void 0 ? void 0 : _e.accounts]);
571
+ }, [dAppKit, walletConnection]);
562
572
  // LaunchDarkly
563
573
  var ldClient = useLDClient();
564
574
  var ldKeyRef = useRef(undefined);
@@ -908,7 +918,7 @@ function Inner(_a) {
908
918
  waitForTransactionWithCheck,
909
919
  ]);
910
920
  // Using Ledger
911
- var _j = useLocalStorage("isUsingLedger-".concat(impersonatedAddress !== null && impersonatedAddress !== void 0 ? impersonatedAddress : account === null || account === void 0 ? void 0 : account.address), false), isUsingLedger = _j[0], setIsUsingLedger = _j[1];
921
+ var _h = useLocalStorage("isUsingLedger-".concat(impersonatedAddress !== null && impersonatedAddress !== void 0 ? impersonatedAddress : account === null || account === void 0 ? void 0 : account.address), false), isUsingLedger = _h[0], setIsUsingLedger = _h[1];
912
922
  // Context
913
923
  var contextValue = useMemo(function () {
914
924
  return {
package/package.json CHANGED
@@ -1 +1 @@
1
- {"name":"@suilend/sui-fe-next","version":"2.0.26","private":false,"description":"A collection of TypeScript frontend components and hooks","author":"Suilend","license":"MIT","main":"./index.js","exports":{".":"./index.js","./contexts/WalletContext":"./contexts/WalletContext.jsx","./contexts/SettingsContext":"./contexts/SettingsContext.jsx","./contexts":"./contexts/index.js","./fetchers":"./fetchers/index.js","./fetchers/useFetchBalances":"./fetchers/useFetchBalances.js","./hooks/useRefreshOnBalancesChange":"./hooks/useRefreshOnBalancesChange.js","./hooks/useLedgerHashDialog":"./hooks/useLedgerHashDialog.js","./hooks/useIsAndroid":"./hooks/useIsAndroid.jsx","./hooks/useCoinMetadataMap":"./hooks/useCoinMetadataMap.js","./hooks":"./hooks/index.js","./hooks/useIsTouchscreen":"./hooks/useIsTouchscreen.jsx","./hooks/useIsiOS":"./hooks/useIsiOS.jsx","./hooks/keypair":"./hooks/keypair.js","./lib/track":"./lib/track.js","./lib":"./lib/index.js","./lib/router":"./lib/router.js","./lib/toasts":"./lib/toasts.jsx","./lib/connector":"./lib/connector.js"},"types":"./index.js","scripts":{"build":"rm -rf ./dist && bun tsc","eslint":"eslint --fix src/","prettier":"prettier --write src/","lint":"bun eslint && bun prettier && bun tsc --noEmit","release":"bun run build && bun ./release.js && cd ./dist && npm publish --access public"},"repository":{"type":"git","url":"git+https://github.com/suilend/sui-fe.git"},"bugs":{"url":"https://github.com/suilend/sui-fe/issues"},"dependencies":{"@reown/appkit":"1.8.2","@tanstack/react-query":"^5.60.2","@wallet-standard/app":"^1.1.0","@walletconnect/universal-provider":"2.21.1","bignumber.js":"^9.1.2","launchdarkly-react-client-sdk":"^3.6.0","lodash":"^4.17.21","mixpanel-browser":"^2.72.0","next":"^15.0.3","react":"18.3.1","react-dom":"18.3.1","react-responsive":"^10.0.0","sonner":"1.4.41","swr":"^2.2.5","tailwind-merge":"^2.5.4","usehooks-ts":"^3.1.1"},"devDependencies":{"@tsconfig/next":"^2.0.3","@types/lodash":"^4.17.13","@types/node":"^22.9.0","@types/react":"^18.3.12","@types/react-dom":"^18.3.1","@typescript-eslint/eslint-plugin":"^8.14.0","@typescript-eslint/parser":"^8.14.0","eslint":"^9.14.0","eslint-config-next":"^15.0.3","eslint-config-prettier":"^9.1.0","eslint-plugin-import":"^2.31.0","eslint-plugin-prettier":"^5.2.1","prettier":"^3.3.3","ts-node":"^10.9.2","typescript":"^5.6.3"},"peerDependencies":{"@mysten/dapp-kit-core":"1.0.3","@mysten/dapp-kit-react":"1.0.1","@mysten/sui":"2.3.1","@mysten/wallet-standard":"0.20.0","@suilend/sui-fe":"^2.0.10"}}
1
+ {"name":"@suilend/sui-fe-next","version":"2.0.28","private":false,"description":"A collection of TypeScript frontend components and hooks","author":"Suilend","license":"MIT","main":"./index.js","exports":{".":"./index.js","./contexts/WalletContext":"./contexts/WalletContext.jsx","./contexts/SettingsContext":"./contexts/SettingsContext.jsx","./contexts":"./contexts/index.js","./fetchers":"./fetchers/index.js","./fetchers/useFetchBalances":"./fetchers/useFetchBalances.js","./hooks/useRefreshOnBalancesChange":"./hooks/useRefreshOnBalancesChange.js","./hooks/useLedgerHashDialog":"./hooks/useLedgerHashDialog.js","./hooks/useIsAndroid":"./hooks/useIsAndroid.jsx","./hooks/useCoinMetadataMap":"./hooks/useCoinMetadataMap.js","./hooks":"./hooks/index.js","./hooks/useIsTouchscreen":"./hooks/useIsTouchscreen.jsx","./hooks/useIsiOS":"./hooks/useIsiOS.jsx","./hooks/keypair":"./hooks/keypair.js","./lib/track":"./lib/track.js","./lib":"./lib/index.js","./lib/router":"./lib/router.js","./lib/toasts":"./lib/toasts.jsx","./lib/connector":"./lib/connector.js"},"types":"./index.js","scripts":{"build":"rm -rf ./dist && bun tsc","eslint":"eslint --fix src/","prettier":"prettier --write src/","lint":"bun eslint && bun prettier && bun tsc --noEmit","release":"bun run build && bun ./release.js && cd ./dist && npm publish --access public"},"repository":{"type":"git","url":"git+https://github.com/suilend/sui-fe.git"},"bugs":{"url":"https://github.com/suilend/sui-fe/issues"},"dependencies":{"@reown/appkit":"1.8.2","@tanstack/react-query":"^5.60.2","@wallet-standard/app":"^1.1.0","@walletconnect/universal-provider":"2.21.1","bignumber.js":"^9.1.2","launchdarkly-react-client-sdk":"^3.6.0","lodash":"^4.17.21","mixpanel-browser":"^2.72.0","next":"^15.0.3","react":"18.3.1","react-dom":"18.3.1","react-responsive":"^10.0.0","sonner":"1.4.41","swr":"^2.2.5","tailwind-merge":"^2.5.4","usehooks-ts":"^3.1.1"},"devDependencies":{"@tsconfig/next":"^2.0.3","@types/lodash":"^4.17.13","@types/node":"^22.9.0","@types/react":"^18.3.12","@types/react-dom":"^18.3.1","@typescript-eslint/eslint-plugin":"^8.14.0","@typescript-eslint/parser":"^8.14.0","eslint":"^9.14.0","eslint-config-next":"^15.0.3","eslint-config-prettier":"^9.1.0","eslint-plugin-import":"^2.31.0","eslint-plugin-prettier":"^5.2.1","prettier":"^3.3.3","ts-node":"^10.9.2","typescript":"^5.6.3"},"peerDependencies":{"@mysten/dapp-kit-core":"1.0.3","@mysten/dapp-kit-react":"1.0.1","@mysten/sui":"2.3.1","@mysten/wallet-standard":"0.20.0","@suilend/sui-fe":"^2.0.10"}}