@mysten/dapp-kit-core 1.0.0

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.
Files changed (72) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/LICENSE +201 -0
  3. package/README.md +3 -0
  4. package/dist/index.d.mts +9 -0
  5. package/dist/index.d.mts.map +1 -0
  6. package/dist/index.mjs +793 -0
  7. package/dist/index.mjs.map +1 -0
  8. package/dist/types-x68aipir.d.mts +240 -0
  9. package/dist/types-x68aipir.d.mts.map +1 -0
  10. package/dist/web/index.d.mts +270 -0
  11. package/dist/web/index.d.mts.map +1 -0
  12. package/dist/web/index.mjs +1446 -0
  13. package/dist/web/index.mjs.map +1 -0
  14. package/package.json +83 -0
  15. package/src/core/actions/connect-wallet.ts +117 -0
  16. package/src/core/actions/disconnect-wallet.ts +43 -0
  17. package/src/core/actions/sign-and-execute-transaction.ts +119 -0
  18. package/src/core/actions/sign-personal-message.ts +42 -0
  19. package/src/core/actions/sign-transaction.ts +83 -0
  20. package/src/core/actions/switch-account.ts +32 -0
  21. package/src/core/actions/switch-network.ts +16 -0
  22. package/src/core/index.ts +119 -0
  23. package/src/core/initializers/autoconnect-wallet.ts +116 -0
  24. package/src/core/initializers/manage-connection.ts +50 -0
  25. package/src/core/initializers/registered-wallets.ts +68 -0
  26. package/src/core/initializers/sync-state-to-storage.ts +44 -0
  27. package/src/core/store.ts +130 -0
  28. package/src/core/types.ts +87 -0
  29. package/src/index.ts +19 -0
  30. package/src/types.ts +15 -0
  31. package/src/utils/errors.ts +29 -0
  32. package/src/utils/lit.ts +61 -0
  33. package/src/utils/name.ts +26 -0
  34. package/src/utils/networks.ts +35 -0
  35. package/src/utils/signer.ts +75 -0
  36. package/src/utils/storage.ts +40 -0
  37. package/src/utils/transaction-result.ts +50 -0
  38. package/src/utils/wallets.ts +82 -0
  39. package/src/wallets/index.ts +56 -0
  40. package/src/wallets/slush-web.ts +27 -0
  41. package/src/wallets/unsafe-burner.ts +165 -0
  42. package/src/web/dapp-kit-connect-button.stories.ts +88 -0
  43. package/src/web/dapp-kit-connect-button.ts +114 -0
  44. package/src/web/dapp-kit-connect-modal.stories.ts +62 -0
  45. package/src/web/dapp-kit-connect-modal.styles.ts +48 -0
  46. package/src/web/dapp-kit-connect-modal.ts +244 -0
  47. package/src/web/index.ts +12 -0
  48. package/src/web/internal/base-modal.ts +149 -0
  49. package/src/web/internal/button.styles.ts +54 -0
  50. package/src/web/internal/button.ts +49 -0
  51. package/src/web/internal/connected-account-menu-item.ts +116 -0
  52. package/src/web/internal/connected-account-menu.styles.ts +217 -0
  53. package/src/web/internal/connected-account-menu.ts +193 -0
  54. package/src/web/internal/connection-status.styles.ts +47 -0
  55. package/src/web/internal/connection-status.ts +31 -0
  56. package/src/web/internal/icons/arrow-right-up-icon.ts +19 -0
  57. package/src/web/internal/icons/back-icon.ts +19 -0
  58. package/src/web/internal/icons/chevron-down-icon.ts +18 -0
  59. package/src/web/internal/icons/circle-check-icon.ts +19 -0
  60. package/src/web/internal/icons/close-icon.ts +18 -0
  61. package/src/web/internal/icons/copy-icon.ts +18 -0
  62. package/src/web/internal/icons/download-icon.ts +24 -0
  63. package/src/web/internal/icons/plus-icon.ts +18 -0
  64. package/src/web/internal/icons/unlink-icon.ts +18 -0
  65. package/src/web/internal/wallet-list-item.styles.ts +41 -0
  66. package/src/web/internal/wallet-list-item.ts +45 -0
  67. package/src/web/internal/wallet-list.styles.ts +49 -0
  68. package/src/web/internal/wallet-list.ts +46 -0
  69. package/src/web/styles/icon-button.ts +28 -0
  70. package/src/web/styles/index.ts +7 -0
  71. package/src/web/styles/reset.ts +45 -0
  72. package/src/web/styles/theme.ts +56 -0
@@ -0,0 +1,41 @@
1
+ // Copyright (c) Mysten Labs, Inc.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { css } from 'lit';
5
+ import { sharedStyles } from '../styles/index.js';
6
+
7
+ export const styles = [
8
+ sharedStyles,
9
+ css`
10
+ .wallet-button {
11
+ transition-property: background-color;
12
+ transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
13
+ transition-duration: 0.15s;
14
+ text-decoration: none;
15
+ background-color: var(--dapp-kit-secondary);
16
+ border-radius: var(--dapp-kit-radius-lg);
17
+ display: flex;
18
+ align-items: center;
19
+ gap: 12px;
20
+ width: 100%;
21
+ padding: 12px;
22
+ }
23
+
24
+ .wallet-button:hover {
25
+ background-color: oklab(from var(--dapp-kit-secondary) calc(l - 0.01) a b);
26
+ }
27
+
28
+ img {
29
+ width: 32px;
30
+ height: 32px;
31
+ border-radius: var(--dapp-kit-radius-lg);
32
+ }
33
+
34
+ p {
35
+ overflow: hidden;
36
+ white-space: nowrap;
37
+ text-overflow: ellipsis;
38
+ font-weight: var(--dapp-kit-font-weight-medium);
39
+ }
40
+ `,
41
+ ];
@@ -0,0 +1,45 @@
1
+ // Copyright (c) Mysten Labs, Inc.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import type { UiWallet } from '@wallet-standard/ui';
5
+ import { html, LitElement } from 'lit';
6
+ import { property } from 'lit/decorators.js';
7
+ import { styles } from './wallet-list-item.styles.js';
8
+
9
+ export type WalletSelectedEvent = CustomEvent<{ wallet: UiWallet }>;
10
+
11
+ export class WalletListItem extends LitElement {
12
+ static override styles = styles;
13
+
14
+ @property()
15
+ wallet!: UiWallet;
16
+
17
+ @property({ type: Boolean, reflect: true })
18
+ override autofocus = false;
19
+
20
+ override render() {
21
+ return html`
22
+ <li>
23
+ <button
24
+ type="button"
25
+ class="wallet-button"
26
+ @click=${this.#walletClicked}
27
+ ?autofocus=${this.autofocus}
28
+ >
29
+ <img src=${this.wallet.icon} alt=${`${this.wallet.name} logo`} />
30
+ <p>${this.wallet.name}</p>
31
+ </button>
32
+ </li>
33
+ `;
34
+ }
35
+
36
+ #walletClicked() {
37
+ this.dispatchEvent(
38
+ new CustomEvent<WalletSelectedEvent['detail']>('wallet-selected', {
39
+ detail: { wallet: this.wallet },
40
+ bubbles: true,
41
+ composed: true,
42
+ }),
43
+ );
44
+ }
45
+ }
@@ -0,0 +1,49 @@
1
+ // Copyright (c) Mysten Labs, Inc.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { css } from 'lit';
5
+ import { sharedStyles } from '../styles/index.js';
6
+
7
+ export const styles = [
8
+ sharedStyles,
9
+ css`
10
+ :host {
11
+ display: flex;
12
+ flex-direction: column;
13
+ flex-grow: 1;
14
+ }
15
+
16
+ ul {
17
+ display: flex;
18
+ flex-direction: column;
19
+ gap: 12px;
20
+ }
21
+
22
+ .no-wallets-container {
23
+ display: flex;
24
+ flex-direction: column;
25
+ flex-grow: 1;
26
+ }
27
+
28
+ .no-wallets-content {
29
+ display: flex;
30
+ flex-direction: column;
31
+ align-items: center;
32
+ justify-content: center;
33
+ flex-grow: 1;
34
+ gap: 32px;
35
+ }
36
+
37
+ .title {
38
+ font-weight: var(--dapp-kit-font-weight-semibold);
39
+ text-align: center;
40
+ font-size: 28px;
41
+ }
42
+
43
+ .wallet-cta {
44
+ display: flex;
45
+ flex-direction: column;
46
+ width: 100%;
47
+ }
48
+ `,
49
+ ];
@@ -0,0 +1,46 @@
1
+ // Copyright (c) Mysten Labs, Inc.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { ScopedRegistryHost } from '@lit-labs/scoped-registry-mixin';
5
+ import type { UiWallet } from '@wallet-standard/ui';
6
+ import { html, LitElement } from 'lit';
7
+ import { property } from 'lit/decorators.js';
8
+ import { WalletListItem } from './wallet-list-item.js';
9
+ import { styles } from './wallet-list.styles.js';
10
+ import { Button } from './button.js';
11
+ import { downloadIcon } from './icons/download-icon.js';
12
+ import { arrowRightUpIcon } from './icons/arrow-right-up-icon.js';
13
+
14
+ export class WalletList extends ScopedRegistryHost(LitElement) {
15
+ static elementDefinitions = {
16
+ 'wallet-list-item': WalletListItem,
17
+ 'internal-button': Button,
18
+ };
19
+
20
+ static override styles = styles;
21
+
22
+ @property({ type: Object })
23
+ wallets: UiWallet[] = [];
24
+
25
+ override render() {
26
+ return this.wallets.length === 0
27
+ ? html`<div class="no-wallets-container">
28
+ <div class="no-wallets-content">
29
+ ${downloadIcon}
30
+ <h2 class="title">Install a wallet to get started on Sui</h2>
31
+ </div>
32
+ <internal-button class="wallet-cta" href="https://sui.io/get-started">
33
+ Select a wallet to install ${arrowRightUpIcon}
34
+ </internal-button>
35
+ </div>`
36
+ : html`<ul class="wallet-list">
37
+ ${this.wallets.map(
38
+ (wallet, index) =>
39
+ html`<wallet-list-item
40
+ .wallet=${wallet}
41
+ ?autofocus=${index === 0}
42
+ ></wallet-list-item>`,
43
+ )}
44
+ </ul>`;
45
+ }
46
+ }
@@ -0,0 +1,28 @@
1
+ // Copyright (c) Mysten Labs, Inc.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { css } from 'lit';
5
+
6
+ export const iconButtonStyles = css`
7
+ .icon-button {
8
+ width: 32px;
9
+ height: 32px;
10
+ border-radius: 50%;
11
+ background: inherit;
12
+ color: var(--dapp-kit-foreground);
13
+ display: inline-flex;
14
+ align-items: center;
15
+ justify-content: center;
16
+ transition:
17
+ background-color 200ms,
18
+ transform 100ms;
19
+ }
20
+
21
+ .icon-button:hover {
22
+ background-color: var(--dapp-kit-accent);
23
+ }
24
+
25
+ .icon-button:active {
26
+ transform: scale(0.9);
27
+ }
28
+ `;
@@ -0,0 +1,7 @@
1
+ // Copyright (c) Mysten Labs, Inc.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { resetStyles } from './reset.js';
5
+ import { themeStyles } from './theme.js';
6
+
7
+ export const sharedStyles = [themeStyles, resetStyles];
@@ -0,0 +1,45 @@
1
+ // Copyright (c) Mysten Labs, Inc.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { css } from 'lit';
5
+
6
+ export const resetStyles = css`
7
+ * {
8
+ box-sizing: border-box;
9
+ -webkit-font-smoothing: antialiased;
10
+ font-family: var(--dapp-kit-font-sans);
11
+ outline-color: color-mix(in oklab, var(--dapp-kit-ring) 50%, transparent);
12
+ }
13
+
14
+ button {
15
+ appearance: none;
16
+ background-color: transparent;
17
+ font-size: inherit;
18
+ font-family: inherit;
19
+ line-height: inherit;
20
+ letter-spacing: inherit;
21
+ color: inherit;
22
+ border: 0;
23
+ padding: 0;
24
+ margin: 0;
25
+ }
26
+
27
+ ul {
28
+ list-style: none;
29
+ margin: 0;
30
+ padding: 0;
31
+ }
32
+
33
+ p,
34
+ h1,
35
+ h2,
36
+ h3,
37
+ h4,
38
+ h5,
39
+ h6 {
40
+ font-size: inherit;
41
+ font-weight: inherit;
42
+ color: var(--dapp-kit-foreground);
43
+ margin: 0;
44
+ }
45
+ `;
@@ -0,0 +1,56 @@
1
+ // Copyright (c) Mysten Labs, Inc.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { css } from 'lit';
5
+
6
+ export const themeStyles = css`
7
+ :host {
8
+ /** Colors */
9
+ --dapp-kit-background: var(--background, oklch(1 0 0));
10
+ --dapp-kit-foreground: var(--foreground, oklch(0.145 0 0));
11
+ --dapp-kit-primary: var(--primary, oklch(0.216 0.006 56.043));
12
+ --dapp-kit-primary-foreground: var(--primary-foreground, oklch(0.985 0.001 106.423));
13
+ --dapp-kit-secondary: var(--secondary, oklch(0.97 0.001 106.424));
14
+ --dapp-kit-secondary-foreground: var(--secondary-foreground, oklch(0.216 0.006 56.043));
15
+ --dapp-kit-border: var(--border, oklch(0.922 0 0));
16
+ --dapp-kit-accent: var(--accent, oklch(0.97 0.001 106.424));
17
+ --dapp-kit-accent-foreground: var(--accent-foreground, oklch(0.205 0 0));
18
+ --dapp-kit-muted: var(--muted, oklch(0.97 0.001 106.424));
19
+ --dapp-kit-muted-foreground: var(--muted-foreground, oklch(0.553 0.013 58.071));
20
+ --dapp-kit-popover: var(--popover, oklch(1 0 0));
21
+ --dapp-kit-popover-foreground: var(--popover-foreground, oklch(0.145 0 0));
22
+ --dapp-kit-destructive: var(--destructive, oklch(0.577 0.245 27.325));
23
+ --dapp-kit-positive: var(--positive, oklch(0.862 0.127 146.2));
24
+ --dapp-kit-ring: var(--ring, oklch(0.708 0 0));
25
+ --dapp-kit-input: var(--input, oklch(0.922 0 0));
26
+
27
+ /** Radii */
28
+ --dapp-kit-radius: var(--radius, 12px);
29
+ --dapp-kit-radius-xs: calc(var(--dapp-kit-radius) - 4px);
30
+ --dapp-kit-radius-sm: calc(var(--dapp-kit-radius) - 4px);
31
+ --dapp-kit-radius-md: calc(var(--dapp-kit-radius) - 2px);
32
+ --dapp-kit-radius-lg: var(--dapp-kit-radius);
33
+ --dapp-kit-radius-xl: calc(var(--dapp-kit-radius) + 4px);
34
+
35
+ /** Typography */
36
+ --dapp-kit-font-sans: var(
37
+ --font-sans,
38
+ ui-sans-serif,
39
+ system-ui,
40
+ -apple-system,
41
+ BlinkMacSystemFont,
42
+ 'Segoe UI',
43
+ Roboto,
44
+ 'Helvetica Neue',
45
+ Arial,
46
+ 'Noto Sans',
47
+ sans-serif,
48
+ 'Apple Color Emoji',
49
+ 'Segoe UI Emoji',
50
+ 'Segoe UI Symbol',
51
+ 'Noto Color Emoji'
52
+ );
53
+ --dapp-kit-font-weight-medium: var(--font-medium, 500);
54
+ --dapp-kit-font-weight-semibold: var(--font-semibold, 600);
55
+ }
56
+ `;