@mysten-incubation/dev-wallet 0.4.1 → 0.5.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.
Files changed (36) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/README.md +5 -4
  3. package/dist/adapters/build-managed-account.d.mts +15 -2
  4. package/dist/adapters/build-managed-account.d.mts.map +1 -1
  5. package/dist/adapters/build-managed-account.mjs +28 -4
  6. package/dist/adapters/build-managed-account.mjs.map +1 -1
  7. package/dist/adapters/devstack-adapter.d.mts +19 -7
  8. package/dist/adapters/devstack-adapter.d.mts.map +1 -1
  9. package/dist/adapters/devstack-adapter.mjs +16 -8
  10. package/dist/adapters/devstack-adapter.mjs.map +1 -1
  11. package/dist/inject/index.d.mts +41 -16
  12. package/dist/inject/index.d.mts.map +1 -1
  13. package/dist/inject/index.mjs +43 -4
  14. package/dist/inject/index.mjs.map +1 -1
  15. package/dist/standalone/assets/{base-adapter-DET6CP7z.js → base-adapter-C5w5q7XZ.js} +1 -1
  16. package/dist/standalone/assets/{in-memory-adapter-CX7xym4e.js → in-memory-adapter-Ban2kRYS.js} +1 -1
  17. package/dist/standalone/assets/{main-CuOnBmaa.js → main-xfzarPod.js} +3 -3
  18. package/dist/standalone/assets/{webcrypto-adapter-CUQmbHDy.js → webcrypto-adapter-Ddqn-RAu.js} +1 -1
  19. package/dist/standalone/index.html +2 -2
  20. package/dist/ui/dev-wallet-balances.d.mts +7 -0
  21. package/dist/ui/dev-wallet-balances.d.mts.map +1 -1
  22. package/dist/ui/dev-wallet-balances.mjs +50 -3
  23. package/dist/ui/dev-wallet-balances.mjs.map +1 -1
  24. package/dist/ui/wallet-controller.mjs +2 -1
  25. package/dist/ui/wallet-controller.mjs.map +1 -1
  26. package/dist/wallet/dev-wallet.d.mts +26 -2
  27. package/dist/wallet/dev-wallet.d.mts.map +1 -1
  28. package/dist/wallet/dev-wallet.mjs +35 -6
  29. package/dist/wallet/dev-wallet.mjs.map +1 -1
  30. package/package.json +1 -1
  31. package/src/adapters/build-managed-account.ts +28 -2
  32. package/src/adapters/devstack-adapter.ts +28 -8
  33. package/src/inject/index.ts +127 -24
  34. package/src/ui/dev-wallet-balances.ts +62 -3
  35. package/src/ui/wallet-controller.ts +2 -1
  36. package/src/wallet/dev-wallet.ts +47 -7
@@ -225,10 +225,11 @@ export class WalletController implements ReactiveController {
225
225
  ? html`
226
226
  <div class="section">
227
227
  <dev-wallet-balances
228
- exportparts="balance-list, loading: balances-loading, error-message: balances-error-message, empty-state: balances-empty-state"
228
+ exportparts="balance-list, loading: balances-loading, error-message: balances-error-message, empty-state: balances-empty-state, faucet-button: balances-faucet-button, faucet-error-message: balances-faucet-error-message"
229
229
  .address=${this.activeAddress}
230
230
  .client=${this.getActiveClient()}
231
231
  .network=${this.#wallet.activeNetwork}
232
+ .faucetHost=${this.#wallet.activeFaucet}
232
233
  .coins=${this.coins}
233
234
  ></dev-wallet-balances>
234
235
  </div>
@@ -19,8 +19,9 @@ import type {
19
19
  WalletAccount,
20
20
  WalletIcon,
21
21
  } from '@mysten/wallet-standard';
22
- import { getWallets, ReadonlyWalletAccount, SUI_CHAINS } from '@mysten/wallet-standard';
22
+ import { getWallets, ReadonlyWalletAccount } from '@mysten/wallet-standard';
23
23
 
24
+ import { chainsForNetworks } from '../adapters/build-managed-account.js';
24
25
  import type { SignerAdapter } from '../types.js';
25
26
  import { DEFAULT_WALLET_ICON, getNetworkFromChain, type WalletEventsMap } from './constants.js';
26
27
  import { type SigningResult, executeSigning } from './signing.js';
@@ -78,6 +79,12 @@ export interface DevWalletConfig {
78
79
  adapters: SignerAdapter[];
79
80
  /** Network URLs by name (network → gRPC endpoint). Defaults to devnet, testnet, and localnet. */
80
81
  networks?: Record<string, string>;
82
+ /** Optional per-network faucet endpoints (network → faucet URL). The
83
+ * active network's faucet is resolvable via {@link DevWallet.activeFaucet}
84
+ * / {@link DevWallet.getFaucet}, so a fund flow funds the SELECTED
85
+ * network's account. Networks without a faucet (live mainnet, fork
86
+ * stacks) simply omit a key. */
87
+ faucets?: Record<string, string>;
81
88
  /** Display name for the wallet. Defaults to 'Dev Wallet'. */
82
89
  name?: string;
83
90
  icon?: WalletIcon;
@@ -106,6 +113,7 @@ export interface DevWalletConfig {
106
113
  export class DevWallet implements Wallet {
107
114
  readonly #adapters: SignerAdapter[];
108
115
  #networkUrls: Record<string, string>;
116
+ #faucetUrls: Record<string, string>;
109
117
  #clients: Record<string, ClientWithCoreApi>;
110
118
  #activeNetwork: string;
111
119
  readonly #name: string;
@@ -137,6 +145,7 @@ export class DevWallet implements Wallet {
137
145
  this.#adapters = config.adapters;
138
146
  this.#persistNetworks = config.persistNetworks ?? false;
139
147
  this.#networkUrls = this.#loadNetworkUrls(config.networks ?? DEFAULT_NETWORK_URLS);
148
+ this.#faucetUrls = { ...config.faucets };
140
149
  this.#clients = {};
141
150
  this.#activeNetwork = config.activeNetwork ?? Object.keys(this.#networkUrls)[0] ?? '';
142
151
  this.#name = config.name ?? DEFAULT_WALLET_NAME;
@@ -169,8 +178,16 @@ export class DevWallet implements Wallet {
169
178
  return this.#icon;
170
179
  }
171
180
 
172
- get chains() {
173
- return SUI_CHAINS;
181
+ /**
182
+ * Wallet-standard chains this wallet advertises. Reflects the CONFIGURED
183
+ * networks — each network name is advertised as `sui:<name>` so dApp Kit's
184
+ * chain-gated paths work for fork networks (`testnet-fork`, …) and custom
185
+ * network names, not just the fixed standard set. Unioned with the standard
186
+ * Sui chains for safety, de-duplicated, with the standard chains first and
187
+ * configured-only chains appended in network-map order.
188
+ */
189
+ get chains(): `sui:${string}`[] {
190
+ return chainsForNetworks(Object.keys(this.#networkUrls));
174
191
  }
175
192
 
176
193
  get accounts(): readonly ReadonlyWalletAccount[] {
@@ -273,6 +290,25 @@ export class DevWallet implements Wallet {
273
290
  return { ...this.#networkUrls };
274
291
  }
275
292
 
293
+ /** Per-network faucet endpoints (network → faucet URL). Networks without
294
+ * a faucet are absent from the map. */
295
+ get faucetUrls(): Record<string, string> {
296
+ return { ...this.#faucetUrls };
297
+ }
298
+
299
+ /** Faucet endpoint for the named network, or `null` when that network has
300
+ * no faucet configured. */
301
+ getFaucet(network: string): string | null {
302
+ return this.#faucetUrls[network] ?? null;
303
+ }
304
+
305
+ /** Faucet endpoint for the currently-active network, or `null` when the
306
+ * active network has no faucet (live mainnet, fork stacks). Drives a
307
+ * fund flow against the SELECTED network. */
308
+ get activeFaucet(): string | null {
309
+ return this.getFaucet(this.#activeNetwork);
310
+ }
311
+
276
312
  get activeNetwork(): string {
277
313
  return this.#activeNetwork;
278
314
  }
@@ -294,10 +330,10 @@ export class DevWallet implements Wallet {
294
330
  );
295
331
  }
296
332
  this.#activeNetwork = network;
297
- this.#events.emit('change', { accounts: this.#accounts });
333
+ this.#events.emit('change', { accounts: this.#exposedAccounts() });
298
334
  }
299
335
 
300
- addNetwork(name: string, url: string): void {
336
+ addNetwork(name: string, url: string, faucet?: string | null): void {
301
337
  let parsed: URL;
302
338
  try {
303
339
  parsed = new URL(url);
@@ -309,18 +345,22 @@ export class DevWallet implements Wallet {
309
345
  }
310
346
  this.#networkUrls[name] = url;
311
347
  this.#clients[name] = this.#clientFactory(name, url);
348
+ if (faucet !== undefined && faucet !== null) {
349
+ this.#faucetUrls[name] = faucet;
350
+ }
312
351
  this.#saveNetworkUrls();
313
- this.#events.emit('change', { accounts: this.#accounts });
352
+ this.#events.emit('change', { accounts: this.#exposedAccounts() });
314
353
  }
315
354
 
316
355
  removeNetwork(name: string): void {
317
356
  delete this.#networkUrls[name];
357
+ delete this.#faucetUrls[name];
318
358
  delete this.#clients[name];
319
359
  if (this.#activeNetwork === name) {
320
360
  this.#activeNetwork = Object.keys(this.#networkUrls)[0] ?? '';
321
361
  }
322
362
  this.#saveNetworkUrls();
323
- this.#events.emit('change', { accounts: this.#accounts });
363
+ this.#events.emit('change', { accounts: this.#exposedAccounts() });
324
364
  }
325
365
 
326
366
  /** Register this wallet with the wallet-standard registry. Returns an unregister function. */