@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.
- package/CHANGELOG.md +27 -0
- package/LICENSE +201 -0
- package/README.md +3 -0
- package/dist/index.d.mts +9 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +793 -0
- package/dist/index.mjs.map +1 -0
- package/dist/types-x68aipir.d.mts +240 -0
- package/dist/types-x68aipir.d.mts.map +1 -0
- package/dist/web/index.d.mts +270 -0
- package/dist/web/index.d.mts.map +1 -0
- package/dist/web/index.mjs +1446 -0
- package/dist/web/index.mjs.map +1 -0
- package/package.json +83 -0
- package/src/core/actions/connect-wallet.ts +117 -0
- package/src/core/actions/disconnect-wallet.ts +43 -0
- package/src/core/actions/sign-and-execute-transaction.ts +119 -0
- package/src/core/actions/sign-personal-message.ts +42 -0
- package/src/core/actions/sign-transaction.ts +83 -0
- package/src/core/actions/switch-account.ts +32 -0
- package/src/core/actions/switch-network.ts +16 -0
- package/src/core/index.ts +119 -0
- package/src/core/initializers/autoconnect-wallet.ts +116 -0
- package/src/core/initializers/manage-connection.ts +50 -0
- package/src/core/initializers/registered-wallets.ts +68 -0
- package/src/core/initializers/sync-state-to-storage.ts +44 -0
- package/src/core/store.ts +130 -0
- package/src/core/types.ts +87 -0
- package/src/index.ts +19 -0
- package/src/types.ts +15 -0
- package/src/utils/errors.ts +29 -0
- package/src/utils/lit.ts +61 -0
- package/src/utils/name.ts +26 -0
- package/src/utils/networks.ts +35 -0
- package/src/utils/signer.ts +75 -0
- package/src/utils/storage.ts +40 -0
- package/src/utils/transaction-result.ts +50 -0
- package/src/utils/wallets.ts +82 -0
- package/src/wallets/index.ts +56 -0
- package/src/wallets/slush-web.ts +27 -0
- package/src/wallets/unsafe-burner.ts +165 -0
- package/src/web/dapp-kit-connect-button.stories.ts +88 -0
- package/src/web/dapp-kit-connect-button.ts +114 -0
- package/src/web/dapp-kit-connect-modal.stories.ts +62 -0
- package/src/web/dapp-kit-connect-modal.styles.ts +48 -0
- package/src/web/dapp-kit-connect-modal.ts +244 -0
- package/src/web/index.ts +12 -0
- package/src/web/internal/base-modal.ts +149 -0
- package/src/web/internal/button.styles.ts +54 -0
- package/src/web/internal/button.ts +49 -0
- package/src/web/internal/connected-account-menu-item.ts +116 -0
- package/src/web/internal/connected-account-menu.styles.ts +217 -0
- package/src/web/internal/connected-account-menu.ts +193 -0
- package/src/web/internal/connection-status.styles.ts +47 -0
- package/src/web/internal/connection-status.ts +31 -0
- package/src/web/internal/icons/arrow-right-up-icon.ts +19 -0
- package/src/web/internal/icons/back-icon.ts +19 -0
- package/src/web/internal/icons/chevron-down-icon.ts +18 -0
- package/src/web/internal/icons/circle-check-icon.ts +19 -0
- package/src/web/internal/icons/close-icon.ts +18 -0
- package/src/web/internal/icons/copy-icon.ts +18 -0
- package/src/web/internal/icons/download-icon.ts +24 -0
- package/src/web/internal/icons/plus-icon.ts +18 -0
- package/src/web/internal/icons/unlink-icon.ts +18 -0
- package/src/web/internal/wallet-list-item.styles.ts +41 -0
- package/src/web/internal/wallet-list-item.ts +45 -0
- package/src/web/internal/wallet-list.styles.ts +49 -0
- package/src/web/internal/wallet-list.ts +46 -0
- package/src/web/styles/icon-button.ts +28 -0
- package/src/web/styles/index.ts +7 -0
- package/src/web/styles/reset.ts +45 -0
- package/src/web/styles/theme.ts +56 -0
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
// Copyright (c) Mysten Labs, Inc.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { Ed25519Keypair } from '@mysten/sui/keypairs/ed25519';
|
|
5
|
+
import { Transaction } from '@mysten/sui/transactions';
|
|
6
|
+
import type {
|
|
7
|
+
IdentifierArray,
|
|
8
|
+
IdentifierString,
|
|
9
|
+
StandardConnectFeature,
|
|
10
|
+
StandardConnectMethod,
|
|
11
|
+
StandardEventsFeature,
|
|
12
|
+
StandardEventsOnMethod,
|
|
13
|
+
SuiFeatures,
|
|
14
|
+
SuiSignAndExecuteTransactionMethod,
|
|
15
|
+
SuiSignPersonalMessageMethod,
|
|
16
|
+
SuiSignTransactionMethod,
|
|
17
|
+
} from '@mysten/wallet-standard';
|
|
18
|
+
import {
|
|
19
|
+
getWallets,
|
|
20
|
+
ReadonlyWalletAccount,
|
|
21
|
+
StandardConnect,
|
|
22
|
+
StandardEvents,
|
|
23
|
+
SuiSignAndExecuteTransaction,
|
|
24
|
+
SuiSignPersonalMessage,
|
|
25
|
+
SuiSignTransaction,
|
|
26
|
+
} from '@mysten/wallet-standard';
|
|
27
|
+
import type { Wallet } from '@mysten/wallet-standard';
|
|
28
|
+
import { toBase64 } from '@mysten/utils';
|
|
29
|
+
import type { ClientWithCoreApi } from '@mysten/sui/client';
|
|
30
|
+
import type { WalletInitializer } from './index.js';
|
|
31
|
+
import { getChain } from '../utils/networks.js';
|
|
32
|
+
|
|
33
|
+
export function unsafeBurnerWalletInitializer(): WalletInitializer {
|
|
34
|
+
return {
|
|
35
|
+
id: 'unsafe-burner-initalizer',
|
|
36
|
+
async initialize({ networks, getClient }) {
|
|
37
|
+
const wallet = new UnsafeBurnerWallet({ clients: networks.map(getClient) });
|
|
38
|
+
const unregister = getWallets().register(wallet);
|
|
39
|
+
return { unregister };
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export class UnsafeBurnerWallet implements Wallet {
|
|
45
|
+
#chainConfig: Record<IdentifierString, ClientWithCoreApi>;
|
|
46
|
+
#keypair = new Ed25519Keypair();
|
|
47
|
+
#account: ReadonlyWalletAccount;
|
|
48
|
+
|
|
49
|
+
constructor({ clients }: { clients: ClientWithCoreApi[] }) {
|
|
50
|
+
this.#chainConfig = clients.reduce<Record<IdentifierString, ClientWithCoreApi>>(
|
|
51
|
+
(accumulator, client) => {
|
|
52
|
+
const chain = getChain(client.network);
|
|
53
|
+
accumulator[chain] = client;
|
|
54
|
+
return accumulator;
|
|
55
|
+
},
|
|
56
|
+
{},
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
this.#account = new ReadonlyWalletAccount({
|
|
60
|
+
address: this.#keypair.getPublicKey().toSuiAddress(),
|
|
61
|
+
publicKey: this.#keypair.getPublicKey().toSuiBytes(),
|
|
62
|
+
chains: this.chains,
|
|
63
|
+
features: [SuiSignTransaction, SuiSignAndExecuteTransaction, SuiSignPersonalMessage],
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
console.warn(
|
|
67
|
+
'Your application is currently using the unsafe burner wallet. Make sure that this wallet is disabled in production.',
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
get version() {
|
|
72
|
+
return '1.0.0' as const;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
get name() {
|
|
76
|
+
return 'Unsafe Burner Wallet' as const;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
get icon() {
|
|
80
|
+
return 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADwAAAA8CAYAAAA6/NlyAAAJrElEQVR42tWbe2xT1x3H7UxAyD3XrdrSbGXlUbKWsq5rWdVuVOMRSEqSOmnVRZMmJqZNYv1nf3R/jWmVmVrtRRM/YwPd1nVTNcrE3pQCoikrIRAC4VVNY0hlD9ZOo1uCfe3ra9979v0dcy3s5Pper76Oh/STE+495/4+5/c85zqe2f7HAx5vKsS+monJj/CdHi/f4/HWW4f6AwdblmXjTM0NyS+movKtw9v+j6C5gKhyTMTTpA2x15Qwy+Pz75motOGdgKep8WF5ATgVZIt5NeO2wMqD0hfVGNPh3oYaYflsjG0l63PeyLCDnqbsLpZIhaRNFI+Ox+Le5KB0RybK8gDmJOkI07U4i/FhT1NDQl8Me5rUIfaDfELOJ0NsFa/SJQHm1WLsHcDqRWiy9BCL8s0N5t6UWWFVvxplejYm60hC91cNjPtzCTZsAptCVoeLP8PDDQJNCSodap6H+LtE8ZcdkvVkkD38vwDn4/Jvy4EhBhZ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oNg4Qi6MviE0FpRVqjGXILYoJ4tCjdYU1rWeMdPLc/ochj3B9pGNGL4NupGPRlUl35KMVxFLNO6ZnxYlBsUPqoMkbUqAb6VhMVKQ7MVT1dYdrL8hzEAcjpmvjHKphgaFb0ZVJZw7dwVD9q5fkgPTRbBxnzmGfgRLQsMCkG+moQdcp6GzzZsL2MGyllvBNGWM9RqMCk26kI7aBK526csVShZTfzid6FEzeiNAGP92jpCPQEbrW7EW5MbZxAz/fN9lg0IbQaaxrQ83/VoKPb/HqJx67Hw+43CDQBPsX0gm6ufXNvH4vP9rZapzx7+Nn+oxZAjfo2caZ3n350c5W6FSEdQ86sNarj3c/jRV+H42AXsdGRBfPPIlnb/mUtxzWXfALn/PmRze2Gud6E/xsXwYtnlsWN8Tc5/oyxjn/jvyJrlY82xLUfWuPr/TqxzuXQZkIP9M7CXiyuP4B4WmsTnNhzinjrD+WO9bRhmdZWLXe4EKRtV5tpN3Hx3s2G+d79/MJf4qff0LnE72kfFEs4ITQvWLMab8C131dP9n9Je1Yx000Nz2jAf+UJwCBchc3NvGR1Qx71XXY2Ww1Jvx7YalzAPkX9rp5E5Z+pv+ja8bE43uN491b9dHO9Xx4lUxziLn21Nai/wXWM6t9vkvtrwAAAABJRU5ErkJggg==' as const;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
get chains() {
|
|
84
|
+
return Object.keys(this.#chainConfig) as IdentifierArray;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
get accounts() {
|
|
88
|
+
return [this.#account];
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
get features(): StandardConnectFeature & StandardEventsFeature & SuiFeatures {
|
|
92
|
+
return {
|
|
93
|
+
[StandardConnect]: {
|
|
94
|
+
version: '1.0.0',
|
|
95
|
+
connect: this.#connect,
|
|
96
|
+
},
|
|
97
|
+
[StandardEvents]: {
|
|
98
|
+
version: '1.0.0',
|
|
99
|
+
on: this.#on,
|
|
100
|
+
},
|
|
101
|
+
[SuiSignPersonalMessage]: {
|
|
102
|
+
version: '1.1.0',
|
|
103
|
+
signPersonalMessage: this.#signPersonalMessage,
|
|
104
|
+
},
|
|
105
|
+
[SuiSignTransaction]: {
|
|
106
|
+
version: '2.0.0',
|
|
107
|
+
signTransaction: this.#signTransaction,
|
|
108
|
+
},
|
|
109
|
+
[SuiSignAndExecuteTransaction]: {
|
|
110
|
+
version: '2.0.0',
|
|
111
|
+
signAndExecuteTransaction: this.#signAndExecuteTransaction,
|
|
112
|
+
},
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
#on: StandardEventsOnMethod = () => {
|
|
117
|
+
return () => {};
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
#connect: StandardConnectMethod = async () => {
|
|
121
|
+
return { accounts: this.accounts };
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
#signPersonalMessage: SuiSignPersonalMessageMethod = async (messageInput) => {
|
|
125
|
+
return await this.#keypair.signPersonalMessage(messageInput.message);
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
#signTransaction: SuiSignTransactionMethod = async ({ transaction, signal, chain }) => {
|
|
129
|
+
signal?.throwIfAborted();
|
|
130
|
+
|
|
131
|
+
const client = this.#chainConfig[chain];
|
|
132
|
+
if (!client) throw new Error(`Invalid chain "${chain}" specified.`);
|
|
133
|
+
|
|
134
|
+
const parsedTransaction = Transaction.from(await transaction.toJSON());
|
|
135
|
+
const builtTransaction = await parsedTransaction.build({ client });
|
|
136
|
+
return await this.#keypair.signTransaction(builtTransaction);
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
#signAndExecuteTransaction: SuiSignAndExecuteTransactionMethod = async ({
|
|
140
|
+
transaction,
|
|
141
|
+
signal,
|
|
142
|
+
chain,
|
|
143
|
+
}) => {
|
|
144
|
+
signal?.throwIfAborted();
|
|
145
|
+
|
|
146
|
+
const client = this.#chainConfig[chain];
|
|
147
|
+
if (!client) throw new Error(`Invalid chain "${chain}" specified.`);
|
|
148
|
+
|
|
149
|
+
const parsedTransaction = Transaction.from(await transaction.toJSON());
|
|
150
|
+
const bytes = await parsedTransaction.build({ client });
|
|
151
|
+
|
|
152
|
+
const result = await this.#keypair.signAndExecuteTransaction({
|
|
153
|
+
transaction: parsedTransaction,
|
|
154
|
+
client,
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
const tx = result.Transaction ?? result.FailedTransaction;
|
|
158
|
+
return {
|
|
159
|
+
bytes: toBase64(bytes),
|
|
160
|
+
signature: tx.signatures[0],
|
|
161
|
+
digest: tx.digest,
|
|
162
|
+
effects: toBase64(tx.effects.bcs!),
|
|
163
|
+
};
|
|
164
|
+
};
|
|
165
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
// Copyright (c) Mysten Labs, Inc.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import type { Meta, StoryObj } from '@storybook/web-components';
|
|
5
|
+
import { html } from 'lit';
|
|
6
|
+
import type { DAppKitConnectButton } from './dapp-kit-connect-button.js';
|
|
7
|
+
import { createDAppKit } from '../core/index.js';
|
|
8
|
+
import { SuiGrpcClient } from '@mysten/sui/grpc';
|
|
9
|
+
|
|
10
|
+
const GRPC_URLS = {
|
|
11
|
+
testnet: 'https://fullnode.testnet.sui.io:443',
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const dAppKit = createDAppKit({
|
|
15
|
+
networks: ['testnet'],
|
|
16
|
+
createClient(network) {
|
|
17
|
+
return new SuiGrpcClient({ network, baseUrl: GRPC_URLS[network] });
|
|
18
|
+
},
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
const meta = {
|
|
22
|
+
title: 'Connect Button',
|
|
23
|
+
component: 'mysten-dapp-kit-connect-button',
|
|
24
|
+
render: (args) =>
|
|
25
|
+
html`<mysten-dapp-kit-connect-button
|
|
26
|
+
.modalOptions=${args['modalOptions']}
|
|
27
|
+
.instance=${dAppKit}
|
|
28
|
+
></mysten-dapp-kit-connect-button>`,
|
|
29
|
+
tags: ['autodocs'],
|
|
30
|
+
} satisfies Meta;
|
|
31
|
+
|
|
32
|
+
export default meta;
|
|
33
|
+
|
|
34
|
+
export const Default: StoryObj<DAppKitConnectButton> = {};
|
|
35
|
+
|
|
36
|
+
export const WithCustomLabel: StoryObj<DAppKitConnectButton> = {
|
|
37
|
+
render: () =>
|
|
38
|
+
html`<mysten-dapp-kit-connect-button .instance=${dAppKit}>
|
|
39
|
+
Sign In
|
|
40
|
+
</mysten-dapp-kit-connect-button>`,
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export const WithCustomTheme: StoryObj<DAppKitConnectButton> = {
|
|
44
|
+
render: () => html`
|
|
45
|
+
<div>
|
|
46
|
+
<style>
|
|
47
|
+
:root {
|
|
48
|
+
--background: oklch(0.2161 0.0061 56.0434);
|
|
49
|
+
--foreground: oklch(0.9299 0.0334 272.7879);
|
|
50
|
+
--card: oklch(0.2805 0.0309 307.2326);
|
|
51
|
+
--card-foreground: oklch(0.9299 0.0334 272.7879);
|
|
52
|
+
--primary: oklch(0.7874 0.1179 295.7538);
|
|
53
|
+
--primary-foreground: oklch(0.2161 0.0061 56.0434);
|
|
54
|
+
--secondary: oklch(0.3416 0.0444 308.8496);
|
|
55
|
+
--secondary-foreground: oklch(0.8717 0.0093 258.3382);
|
|
56
|
+
--muted: oklch(0.2805 0.0309 307.2326);
|
|
57
|
+
--muted-foreground: oklch(0.7137 0.0192 261.3246);
|
|
58
|
+
--accent: oklch(0.3858 0.0509 304.6383);
|
|
59
|
+
--accent-foreground: oklch(0.8717 0.0093 258.3382);
|
|
60
|
+
--popover: oklch(0.2284 0.0384 282.9324);
|
|
61
|
+
--popover-foreground: oklch(0.9185 0.0257 285.8834);
|
|
62
|
+
--border: oklch(0.3416 0.0444 308.8496);
|
|
63
|
+
--input: oklch(0.3416 0.0444 308.8496);
|
|
64
|
+
--ring: oklch(0.7874 0.1179 295.7538);
|
|
65
|
+
--font-sans: Open Sans, sans-serif;
|
|
66
|
+
--radius: 1.5rem;
|
|
67
|
+
}
|
|
68
|
+
</style>
|
|
69
|
+
<mysten-dapp-kit-connect-button .instance=${dAppKit}></mysten-dapp-kit-connect-button>
|
|
70
|
+
</div>
|
|
71
|
+
`,
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
export const WithRandomSort: StoryObj<DAppKitConnectButton> = {
|
|
75
|
+
args: {
|
|
76
|
+
modalOptions: {
|
|
77
|
+
sortFn: () => 0.5 - Math.random(),
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
export const WithRandomFilter: StoryObj<DAppKitConnectButton> = {
|
|
83
|
+
args: {
|
|
84
|
+
modalOptions: {
|
|
85
|
+
filterFn: () => Math.random() > 0.5,
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
};
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
// Copyright (c) Mysten Labs, Inc.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { html, LitElement } from 'lit';
|
|
5
|
+
import { customElement, property, query } from 'lit/decorators.js';
|
|
6
|
+
import { storeProperty } from '../utils/lit.js';
|
|
7
|
+
import type { DAppKitConnectModalOptions } from './dapp-kit-connect-modal.js';
|
|
8
|
+
import { DAppKitConnectModal } from './dapp-kit-connect-modal.js';
|
|
9
|
+
import { ScopedRegistryHost } from '@lit-labs/scoped-registry-mixin';
|
|
10
|
+
import { Button } from './internal/button.js';
|
|
11
|
+
import { sharedStyles } from './styles/index.js';
|
|
12
|
+
import type { DefaultExpectedDppKit } from '../types.js';
|
|
13
|
+
import { ConnectedAccountMenu } from './internal/connected-account-menu.js';
|
|
14
|
+
import type { AccountSelectedEvent } from './internal/connected-account-menu-item.js';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* A button component for connecting to a Sui wallet.
|
|
18
|
+
*
|
|
19
|
+
* Displays a "Connect Wallet" button when no wallet is connected or a connected account menu when a wallet is active.
|
|
20
|
+
*
|
|
21
|
+
* @element mysten-dapp-kit-connect-button
|
|
22
|
+
*
|
|
23
|
+
* @prop {DAppKitConnectModalOptions} modalOptions - Options to configure the connect modal.
|
|
24
|
+
* @prop {RegisteredDAppKit} instance - The dApp Kit instance used for state management.
|
|
25
|
+
*
|
|
26
|
+
* @slot - The default slot used to customize the button content (shown when not connected).
|
|
27
|
+
*
|
|
28
|
+
* @cssprop --background - Background color of the component. Used as the default background for UI elements.
|
|
29
|
+
* @cssprop --foreground - Foreground color of the component. Used as the default text color.
|
|
30
|
+
* @cssprop --primary - Primary color used for interactive elements such as buttons and links.
|
|
31
|
+
* @cssprop --primary-foreground - Text or icon color placed on top of primary elements.
|
|
32
|
+
* @cssprop --secondary - Secondary color used for less prominent interactive elements.
|
|
33
|
+
* @cssprop --secondary-foreground - Text or icon color placed on top of secondary elements.
|
|
34
|
+
* @cssprop --border - Border color for UI elements.
|
|
35
|
+
* @cssprop --accent - Accent color used for highlights and decorative elements.
|
|
36
|
+
* @cssprop --accent-foreground - Text or icon color placed on top of accent elements.
|
|
37
|
+
* @cssprop --muted - Background color for subtle or muted UI elements (e.g., placeholders, disabled states).
|
|
38
|
+
* @cssprop --muted-foreground - Text or icon color for muted UI elements.
|
|
39
|
+
* @cssprop --popover - Background color for floating elements such as popovers, dropdowns, or tooltips.
|
|
40
|
+
* @cssprop --popover-foreground - Text or icon color inside popover elements.
|
|
41
|
+
* @cssprop --ring - Color used for focus rings (visible focus indicators on interactive elements).
|
|
42
|
+
* @cssprop --radius - Border radius used for UI elements.
|
|
43
|
+
* @cssprop --font-sans - Font family used for text content.
|
|
44
|
+
* @cssprop --font-weight-medium - Medium font weight for text (typically used for buttons and interactive elements).
|
|
45
|
+
* @cssprop --font-weight-semibold - Semibold font weight for text (typically used for headings or emphasized text).
|
|
46
|
+
*/
|
|
47
|
+
@customElement('mysten-dapp-kit-connect-button')
|
|
48
|
+
export class DAppKitConnectButton extends ScopedRegistryHost(LitElement) {
|
|
49
|
+
static elementDefinitions = {
|
|
50
|
+
'internal-button': Button,
|
|
51
|
+
'mysten-dapp-kit-connect-modal': DAppKitConnectModal,
|
|
52
|
+
'connected-account-menu': ConnectedAccountMenu,
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
static override shadowRootOptions = {
|
|
56
|
+
...LitElement.shadowRootOptions,
|
|
57
|
+
delegatesFocus: true,
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
static override styles = sharedStyles;
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Options to configure the connect modal.
|
|
64
|
+
*/
|
|
65
|
+
@property({ type: Object })
|
|
66
|
+
modalOptions?: DAppKitConnectModalOptions;
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* The dApp Kit instance used for state management.
|
|
70
|
+
*/
|
|
71
|
+
@storeProperty()
|
|
72
|
+
instance!: DefaultExpectedDppKit;
|
|
73
|
+
|
|
74
|
+
@query('mysten-dapp-kit-connect-modal')
|
|
75
|
+
private readonly _modal!: DAppKitConnectModal;
|
|
76
|
+
|
|
77
|
+
override render() {
|
|
78
|
+
const connection = this.instance.stores.$connection.get();
|
|
79
|
+
const client = this.instance.stores.$currentClient.get();
|
|
80
|
+
|
|
81
|
+
return connection.account
|
|
82
|
+
? html`<connected-account-menu
|
|
83
|
+
.connection=${connection}
|
|
84
|
+
.client=${client}
|
|
85
|
+
@account-selected=${(event: AccountSelectedEvent) => {
|
|
86
|
+
this.instance.switchAccount({ account: event.detail.account });
|
|
87
|
+
}}
|
|
88
|
+
@disconnect-click=${() => {
|
|
89
|
+
this.instance.disconnectWallet();
|
|
90
|
+
}}
|
|
91
|
+
@manage-connection-click=${() => {
|
|
92
|
+
this.instance.connectWallet({ wallet: connection.wallet });
|
|
93
|
+
}}
|
|
94
|
+
></connected-account-menu>`
|
|
95
|
+
: html`<internal-button @click=${this.#openModal}>
|
|
96
|
+
<slot>Connect Wallet</slot>
|
|
97
|
+
</internal-button>
|
|
98
|
+
<mysten-dapp-kit-connect-modal
|
|
99
|
+
.instance=${this.instance}
|
|
100
|
+
.filterFn=${this.modalOptions?.filterFn}
|
|
101
|
+
.sortFn=${this.modalOptions?.sortFn}
|
|
102
|
+
></mysten-dapp-kit-connect-modal>`;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
#openModal() {
|
|
106
|
+
this._modal.show();
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
declare global {
|
|
111
|
+
interface HTMLElementTagNameMap {
|
|
112
|
+
'mysten-dapp-kit-connect-button': DAppKitConnectButton;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
// Copyright (c) Mysten Labs, Inc.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import type { Meta, StoryObj } from '@storybook/web-components';
|
|
5
|
+
import { html } from 'lit';
|
|
6
|
+
import type { DAppKitConnectModal } from './dapp-kit-connect-modal.js';
|
|
7
|
+
import { createDAppKit } from '../core/index.js';
|
|
8
|
+
import { SuiGrpcClient } from '@mysten/sui/grpc';
|
|
9
|
+
|
|
10
|
+
const GRPC_URLS = {
|
|
11
|
+
testnet: 'https://fullnode.testnet.sui.io:443',
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const dAppKit = createDAppKit({
|
|
15
|
+
networks: ['testnet'],
|
|
16
|
+
createClient(network) {
|
|
17
|
+
return new SuiGrpcClient({ network, baseUrl: GRPC_URLS[network] });
|
|
18
|
+
},
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
const meta = {
|
|
22
|
+
title: 'Connect Modal',
|
|
23
|
+
component: 'mysten-dapp-kit-connect-modal',
|
|
24
|
+
render: (args) => html`
|
|
25
|
+
<mysten-dapp-kit-connect-modal
|
|
26
|
+
?open="${args['open']}"
|
|
27
|
+
.sortFn=${args['sortFn']}
|
|
28
|
+
.filterFn=${args['filterFn']}
|
|
29
|
+
.instance=${dAppKit}
|
|
30
|
+
></mysten-dapp-kit-connect-modal>
|
|
31
|
+
`,
|
|
32
|
+
tags: ['autodocs'],
|
|
33
|
+
} satisfies Meta;
|
|
34
|
+
|
|
35
|
+
export default meta;
|
|
36
|
+
|
|
37
|
+
export const Default: StoryObj<DAppKitConnectModal> = {
|
|
38
|
+
args: {
|
|
39
|
+
open: true,
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export const WithRandomSort: StoryObj<DAppKitConnectModal> = {
|
|
44
|
+
args: {
|
|
45
|
+
open: true,
|
|
46
|
+
sortFn: () => 0.5 - Math.random(),
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
export const WithRandomFilter: StoryObj<DAppKitConnectModal> = {
|
|
51
|
+
args: {
|
|
52
|
+
open: true,
|
|
53
|
+
filterFn: () => Math.random() > 0.5,
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
export const NoDetectedWallets: StoryObj<DAppKitConnectModal> = {
|
|
58
|
+
args: {
|
|
59
|
+
open: true,
|
|
60
|
+
filterFn: () => false,
|
|
61
|
+
},
|
|
62
|
+
};
|
|
@@ -0,0 +1,48 @@
|
|
|
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
|
+
dialog {
|
|
11
|
+
width: 360px;
|
|
12
|
+
height: 480px;
|
|
13
|
+
border: 1px solid var(--dapp-kit-border);
|
|
14
|
+
padding: 0;
|
|
15
|
+
background: var(--dapp-kit-background);
|
|
16
|
+
border-radius: var(--dapp-kit-radius-lg);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
.content {
|
|
20
|
+
display: flex;
|
|
21
|
+
flex-direction: column;
|
|
22
|
+
height: 100%;
|
|
23
|
+
gap: 32px;
|
|
24
|
+
padding: 24px;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
.connect-header {
|
|
28
|
+
display: flex;
|
|
29
|
+
justify-content: space-between;
|
|
30
|
+
align-items: center;
|
|
31
|
+
gap: 8px;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
.title {
|
|
35
|
+
font-size: 18px;
|
|
36
|
+
font-weight: var(--dapp-kit-font-weight-semibold);
|
|
37
|
+
white-space: nowrap;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
.close-button {
|
|
41
|
+
margin-left: auto;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
.cancel-button {
|
|
45
|
+
margin-top: auto;
|
|
46
|
+
}
|
|
47
|
+
`,
|
|
48
|
+
];
|