@mysten/dapp-kit-core 1.0.4 → 1.1.1

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/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "author": "Mysten Labs <build@mystenlabs.com>",
4
4
  "description": "Framework-agnostic toolkit for building decentralized applications on Sui.",
5
5
  "homepage": "https://sdk.mystenlabs.com/sui",
6
- "version": "1.0.4",
6
+ "version": "1.1.1",
7
7
  "license": "Apache-2.0",
8
8
  "files": [
9
9
  "CHANGELOG.md",
@@ -39,15 +39,13 @@
39
39
  "access": "public"
40
40
  },
41
41
  "devDependencies": {
42
- "@storybook/addon-essentials": "^8.6.14",
43
- "@storybook/blocks": "^8.6.14",
44
42
  "@storybook/web-components": "^10.1.11",
45
43
  "@storybook/web-components-vite": "^10.1.11",
46
- "storybook": "^10.1.11",
44
+ "storybook": "^10.2.12",
47
45
  "tsdown": "0.20.0-beta.1",
48
46
  "typescript": "^5.9.3",
49
47
  "vitest": "^4.0.17",
50
- "@mysten/sui": "^2.3.2"
48
+ "@mysten/sui": "^2.5.0"
51
49
  },
52
50
  "dependencies": {
53
51
  "@floating-ui/dom": "^1.7.4",
@@ -64,7 +62,7 @@
64
62
  "@mysten/wallet-standard": "^0.20.1"
65
63
  },
66
64
  "peerDependencies": {
67
- "@mysten/sui": "^2.3.2"
65
+ "@mysten/sui": "^2.5.0"
68
66
  },
69
67
  "scripts": {
70
68
  "clean": "rm -rf tsconfig.tsbuildinfo ./dist",
@@ -28,9 +28,14 @@ export function syncStateToStorage({
28
28
  storageKey,
29
29
  getSavedAccountStorageKey(connection.account, connection.supportedIntents),
30
30
  );
31
- } else {
32
- storage.removeItem(storageKey);
33
31
  }
32
+ // Storage is intentionally NOT cleared on disconnect. When a wallet
33
+ // unregisters and re-registers (HMR, React strict mode, effect re-runs),
34
+ // the autoconnect initializer uses the persisted session to seamlessly
35
+ // reconnect once the wallet reappears. Clearing storage here would
36
+ // permanently lose the session. Stale entries are harmless — autoconnect
37
+ // ignores them when the wallet is not found, and connecting to a new
38
+ // wallet overwrites the entry.
34
39
  });
35
40
  });
36
41
  }
package/src/core/store.ts CHANGED
@@ -2,15 +2,12 @@
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
4
  import type { UiWallet, UiWalletAccount } from '@wallet-standard/ui';
5
+ import { uiWalletAccountBelongsToUiWallet } from '@wallet-standard/ui';
5
6
  import type { StoreValue } from 'nanostores';
6
7
  import { atom, computed, map } from 'nanostores';
7
8
  import { getChain } from '../utils/networks.js';
8
9
  import type { Networks } from '../utils/networks.js';
9
- import {
10
- getAssociatedWalletOrThrow,
11
- requiredWalletFeatures,
12
- signingFeatures,
13
- } from '../utils/wallets.js';
10
+ import { requiredWalletFeatures, signingFeatures } from '../utils/wallets.js';
14
11
  import type { DAppKitCompatibleClient } from './types.js';
15
12
 
16
13
  type InternalWalletConnection =
@@ -78,9 +75,24 @@ export function createStores<
78
75
  $currentClient: computed($currentNetwork, getClient),
79
76
  $connection: computed([$baseConnection, $compatibleWallets], (connection, wallets) => {
80
77
  switch (connection.status) {
81
- case 'connected':
78
+ case 'connected': {
79
+ const wallet = wallets.find((w) =>
80
+ uiWalletAccountBelongsToUiWallet(connection.currentAccount, w),
81
+ );
82
+ if (!wallet) {
83
+ return {
84
+ wallet: null,
85
+ account: null,
86
+ status: 'disconnected',
87
+ supportedIntents: [],
88
+ isConnected: false,
89
+ isConnecting: false,
90
+ isReconnecting: false,
91
+ isDisconnected: true,
92
+ } as const;
93
+ }
82
94
  return {
83
- wallet: getAssociatedWalletOrThrow(connection.currentAccount, wallets),
95
+ wallet,
84
96
  account: connection.currentAccount,
85
97
  status: connection.status,
86
98
  supportedIntents: connection.supportedIntents,
@@ -89,6 +101,7 @@ export function createStores<
89
101
  isReconnecting: false,
90
102
  isDisconnected: false,
91
103
  } as const;
104
+ }
92
105
  case 'connecting':
93
106
  return {
94
107
  wallet: null,
@@ -100,9 +113,24 @@ export function createStores<
100
113
  isReconnecting: false,
101
114
  isDisconnected: false,
102
115
  } as const;
103
- case 'reconnecting':
116
+ case 'reconnecting': {
117
+ const wallet = wallets.find((w) =>
118
+ uiWalletAccountBelongsToUiWallet(connection.currentAccount, w),
119
+ );
120
+ if (!wallet) {
121
+ return {
122
+ wallet: null,
123
+ account: null,
124
+ status: 'disconnected',
125
+ supportedIntents: [],
126
+ isConnected: false,
127
+ isConnecting: false,
128
+ isReconnecting: false,
129
+ isDisconnected: true,
130
+ } as const;
131
+ }
104
132
  return {
105
- wallet: getAssociatedWalletOrThrow(connection.currentAccount, wallets),
133
+ wallet,
106
134
  account: connection.currentAccount,
107
135
  status: connection.status,
108
136
  supportedIntents: connection.supportedIntents,
@@ -111,6 +139,7 @@ export function createStores<
111
139
  isReconnecting: true,
112
140
  isDisconnected: false,
113
141
  } as const;
142
+ }
114
143
  case 'disconnected':
115
144
  return {
116
145
  wallet: null,
package/src/index.ts CHANGED
@@ -16,4 +16,5 @@ export type { StateStorage } from './utils/storage.js';
16
16
  export type { ClientWithCoreApi } from '@mysten/sui/client';
17
17
 
18
18
  export { getWalletUniqueIdentifier } from './utils/wallets.js';
19
+ export { CurrentAccountSigner } from './utils/signer.js';
19
20
  export type { UiWallet, UiWalletAccount } from '@wallet-standard/ui';
@@ -9,23 +9,15 @@ import {
9
9
  WALLET_STANDARD_ERROR__FEATURES__WALLET_ACCOUNT_CHAIN_UNSUPPORTED,
10
10
  WalletStandardError,
11
11
  } from '@mysten/wallet-standard';
12
- import type { UiWallet, UiWalletAccount, UiWalletHandle } from '@wallet-standard/ui';
13
- import { getWalletAccountFeature, uiWalletAccountBelongsToUiWallet } from '@wallet-standard/ui';
12
+ import type { UiWalletAccount, UiWalletHandle } from '@wallet-standard/ui';
13
+ import { getWalletAccountFeature } from '@wallet-standard/ui';
14
14
  import { getWalletForHandle_DO_NOT_USE_OR_YOU_WILL_BE_FIRED as getWalletForHandle } from '@wallet-standard/ui-registry';
15
- import { ChainNotSupportedError, DAppKitError, FeatureNotSupportedError } from './errors.js';
15
+ import { ChainNotSupportedError, FeatureNotSupportedError } from './errors.js';
16
16
 
17
17
  export const requiredWalletFeatures = [StandardConnect, StandardEvents] as const;
18
18
 
19
19
  export const signingFeatures = [SuiSignTransaction, SuiSignTransactionBlock] as const;
20
20
 
21
- export function getAssociatedWalletOrThrow(account: UiWalletAccount, wallets: UiWallet[]) {
22
- const wallet = wallets.find((wallet) => uiWalletAccountBelongsToUiWallet(account, wallet));
23
- if (!wallet) {
24
- throw new DAppKitError(`Wallet not found for account ${account.address}.`);
25
- }
26
- return wallet;
27
- }
28
-
29
21
  export function getWalletUniqueIdentifier(walletHandle: UiWalletHandle) {
30
22
  const underlyingWallet = getWalletForHandle(walletHandle);
31
23
  return underlyingWallet.id ?? underlyingWallet.name;
@@ -71,6 +71,25 @@ export const WithCustomTheme: StoryObj<DAppKitConnectButton> = {
71
71
  `,
72
72
  };
73
73
 
74
+ export const WithCustomTriggerPart: StoryObj<DAppKitConnectButton> = {
75
+ render: () => html`
76
+ <style>
77
+ .custom-part-demo::part(trigger) {
78
+ height: 56px;
79
+ padding: 12px 32px;
80
+ border-radius: 999px;
81
+ background-color: #e63946;
82
+ color: #f1faee;
83
+ font-size: 18px;
84
+ letter-spacing: 0.5px;
85
+ }
86
+ </style>
87
+ <mysten-dapp-kit-connect-button class="custom-part-demo" .instance=${dAppKit}>
88
+ Connect
89
+ </mysten-dapp-kit-connect-button>
90
+ `,
91
+ };
92
+
74
93
  export const WithRandomSort: StoryObj<DAppKitConnectButton> = {
75
94
  args: {
76
95
  modalOptions: {
@@ -43,6 +43,8 @@ import type { AccountSelectedEvent } from './internal/connected-account-menu-ite
43
43
  * @cssprop --font-sans - Font family used for text content.
44
44
  * @cssprop --font-weight-medium - Medium font weight for text (typically used for buttons and interactive elements).
45
45
  * @cssprop --font-weight-semibold - Semibold font weight for text (typically used for headings or emphasized text).
46
+ *
47
+ * @csspart trigger - The underlying button element. Use `::part(trigger)` to customize sizing, padding, border-radius, etc.
46
48
  */
47
49
  @customElement('mysten-dapp-kit-connect-button')
48
50
  export class DAppKitConnectButton extends ScopedRegistryHost(LitElement) {
@@ -80,6 +82,7 @@ export class DAppKitConnectButton extends ScopedRegistryHost(LitElement) {
80
82
 
81
83
  return connection.account
82
84
  ? html`<connected-account-menu
85
+ exportparts="trigger"
83
86
  .connection=${connection}
84
87
  .client=${client}
85
88
  @account-selected=${(event: AccountSelectedEvent) => {
@@ -92,7 +95,7 @@ export class DAppKitConnectButton extends ScopedRegistryHost(LitElement) {
92
95
  this.instance.connectWallet({ wallet: connection.wallet });
93
96
  }}
94
97
  ></connected-account-menu>`
95
- : html`<internal-button @click=${this.#openModal}>
98
+ : html`<internal-button exportparts="trigger" @click=${this.#openModal}>
96
99
  <slot>Connect Wallet</slot>
97
100
  </internal-button>
98
101
  <mysten-dapp-kit-connect-modal
@@ -27,6 +27,7 @@ export class Button extends LitElement {
27
27
  return this.href
28
28
  ? html`
29
29
  <a
30
+ part="trigger"
30
31
  href=${this.href}
31
32
  ?disabled=${this.disabled}
32
33
  target="_blank"
@@ -38,6 +39,7 @@ export class Button extends LitElement {
38
39
  `
39
40
  : html`
40
41
  <button
42
+ part="trigger"
41
43
  type="button"
42
44
  ?disabled=${this.disabled}
43
45
  class=${classMap({ button: true, [this.variant]: true })}
@@ -63,6 +63,7 @@ export class ConnectedAccountMenu extends ScopedRegistryHost(LitElement) {
63
63
 
64
64
  override render() {
65
65
  return html`<internal-button
66
+ exportparts="trigger"
66
67
  id="menu-button"
67
68
  aria-haspopup="true"
68
69
  aria-controls="menu"