@octanejs/rainbowkit 0.0.43 → 0.0.45

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@octanejs/rainbowkit",
3
- "version": "0.0.43",
3
+ "version": "0.0.45",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "engines": {
@@ -35,20 +35,20 @@
35
35
  "./styles.css": "./src/styles.css"
36
36
  },
37
37
  "dependencies": {
38
- "@octanejs/wagmi": "0.0.43",
38
+ "@octanejs/wagmi": "0.0.45",
39
39
  "@wagmi/core": "3.6.5"
40
40
  },
41
41
  "peerDependencies": {
42
- "@octanejs/tanstack-query": "0.1.61",
43
- "octane": "^0.10.0"
42
+ "@octanejs/tanstack-query": "0.1.63",
43
+ "octane": "^0.11.0"
44
44
  },
45
45
  "devDependencies": {
46
46
  "@rainbow-me/rainbowkit": "2.2.11",
47
- "@octanejs/tanstack-query": "0.1.61",
47
+ "@octanejs/tanstack-query": "0.1.63",
48
48
  "@testing-library/jest-dom": "^6.9.1",
49
- "@tsrx/react": "^0.3.7",
49
+ "@tsrx/react": "^0.4.5",
50
50
  "@wagmi/connectors": "8.2.0",
51
- "octane": "0.10.0",
51
+ "octane": "0.11.0",
52
52
  "react": "19.2.7",
53
53
  "react-dom": "19.2.7",
54
54
  "viem": "2.55.10",
@@ -38,17 +38,19 @@ function useConnectButtonState(): ConnectButtonRendererProps {
38
38
  const connected = connection.status === 'connected' && Boolean(connection.address);
39
39
  const mounted = rainbowKit?.mounted ?? false;
40
40
  return {
41
- account: mounted && connected
42
- ? {
43
- address: connection.address!,
44
- displayName: formatAddress(connection.address!),
45
- }
46
- : undefined,
41
+ account:
42
+ mounted && connected
43
+ ? {
44
+ address: connection.address!,
45
+ displayName: formatAddress(connection.address!),
46
+ }
47
+ : undefined,
47
48
  accountModalOpen: accountModal.accountModalOpen,
48
49
  authenticationStatus: undefined,
49
- chain: mounted && connected
50
- ? { id: connection.chainId!, name: chain?.name, unsupported: chain === undefined }
51
- : undefined,
50
+ chain:
51
+ mounted && connected
52
+ ? { id: connection.chainId!, name: chain?.name, unsupported: chain === undefined }
53
+ : undefined,
52
54
  chainModalOpen: chainModal.chainModalOpen,
53
55
  connectModalOpen: connectModal.connectModalOpen,
54
56
  connectionStatus: !mounted
@@ -90,11 +92,9 @@ export function ConnectButton(props: ConnectButtonProps = {}) @{
90
92
  </button>
91
93
  }
92
94
  }
93
- <button
94
- type="button"
95
- className="rk-connect-button"
96
- onClick={state.openAccountModal}
97
- >{state.account.displayName}</button>
95
+ <button type="button" className="rk-connect-button" onClick={state.openAccountModal}>
96
+ {state.account.displayName}
97
+ </button>
98
98
  <button
99
99
  type="button"
100
100
  className="rk-connect-button"
package/src/provider.tsrx CHANGED
@@ -45,9 +45,9 @@ function walletEntries(
45
45
  connectors: readonly Connector[],
46
46
  descriptors: readonly WalletDescriptor[],
47
47
  ): readonly WalletEntry[] {
48
- const byIdentity = new Map(connectors.map(
49
- (connector) => [connectorIdentity(connector), connector],
50
- ));
48
+ const byIdentity = new Map(
49
+ connectors.map((connector) => [connectorIdentity(connector), connector]),
50
+ );
51
51
  const consumed = new Set<string>();
52
52
  const entries: WalletEntry[] = [];
53
53
  for (const descriptor of descriptors) {
@@ -55,10 +55,11 @@ function walletEntries(
55
55
  (connector) => connector.id === descriptor.id || connector.name === descriptor.name,
56
56
  );
57
57
  const connector = descriptor.connectorUid
58
- ? byIdentity.get(descriptor.connectorUid) ?? fallback
58
+ ? (byIdentity.get(descriptor.connectorUid) ?? fallback)
59
59
  : fallback;
60
- const identity =
61
- connector ? connectorIdentity(connector) : descriptor.connectorUid || descriptor.id;
60
+ const identity = connector
61
+ ? connectorIdentity(connector)
62
+ : descriptor.connectorUid || descriptor.id;
62
63
  if (consumed.has(identity)) continue;
63
64
  consumed.add(identity);
64
65
  entries.push({ ...descriptor, connector, identity });
@@ -102,7 +103,7 @@ function Modal(props: {
102
103
  const fallback = focusScope?.querySelector<HTMLElement>(
103
104
  '.rk-connect-button:not([disabled]), .rk-wallet-button:not([disabled])',
104
105
  );
105
- ((props.opener?.isConnected ? props.opener : fallback))?.focus();
106
+ (props.opener?.isConnected ? props.opener : fallback)?.focus();
106
107
  });
107
108
  };
108
109
  const title =
@@ -125,11 +126,12 @@ function Modal(props: {
125
126
  pushModal(props.token, ownerDocument);
126
127
  lockBody(ownerDocument);
127
128
  registerModal(props.token, dialog);
128
- const focusable = () => Array.from(
129
- dialog.querySelectorAll<HTMLElement>(
130
- 'button:not([disabled]), [href], input:not([disabled]), [tabindex]:not([tabindex="-1"])',
131
- ),
132
- );
129
+ const focusable = () =>
130
+ Array.from(
131
+ dialog.querySelectorAll<HTMLElement>(
132
+ 'button:not([disabled]), [href], input:not([disabled]), [tabindex]:not([tabindex="-1"])',
133
+ ),
134
+ );
133
135
  focusable()[0]?.focus();
134
136
  const onKeyDown = (event: KeyboardEvent) => {
135
137
  if (!isTopModal(props.token)) return;
@@ -149,10 +151,10 @@ function Modal(props: {
149
151
  const last = items.at(-1)!;
150
152
  if (
151
153
  !dialog.contains(ownerDocument.activeElement) ||
152
- !items.includes(ownerDocument.activeElement as HTMLElement)
154
+ !items.includes(ownerDocument.activeElement as HTMLElement)
153
155
  ) {
154
156
  event.preventDefault();
155
- ((event.shiftKey ? last : first)).focus();
157
+ (event.shiftKey ? last : first).focus();
156
158
  } else if (event.shiftKey && ownerDocument.activeElement === first) {
157
159
  event.preventDefault();
158
160
  last.focus();
@@ -174,13 +176,17 @@ function Modal(props: {
174
176
  if (!entry.connector) return;
175
177
  const pendingToken = props.beginConnecting();
176
178
  setPendingWalletIdentity(entry.identity);
177
- void connect.connectAsync({ connector: entry.connector }).then(() => {
178
- props.close(props.token);
179
- restoreFocus();
180
- }).catch(() => {}).finally(() => {
181
- setPendingWalletIdentity(null);
182
- props.endConnecting(pendingToken);
183
- });
179
+ void connect
180
+ .connectAsync({ connector: entry.connector })
181
+ .then(() => {
182
+ props.close(props.token);
183
+ restoreFocus();
184
+ })
185
+ .catch(() => {})
186
+ .finally(() => {
187
+ setPendingWalletIdentity(null);
188
+ props.endConnecting(pendingToken);
189
+ });
184
190
  };
185
191
 
186
192
  <div
@@ -259,10 +265,17 @@ function Modal(props: {
259
265
  type="button"
260
266
  className="rk-action"
261
267
  disabled={switchChain.isPending || connection.chainId === chain.id}
262
- onClick={() => switchChain.mutate({ chainId: chain.id }, {
263
- onSuccess: () => props.close(props.token),
264
- })}
265
- >{chain.name}</button>
268
+ onClick={() =>
269
+ switchChain.mutate(
270
+ { chainId: chain.id },
271
+ {
272
+ onSuccess: () => props.close(props.token),
273
+ },
274
+ )
275
+ }
276
+ >
277
+ {chain.name}
278
+ </button>
266
279
  </li>
267
280
  }
268
281
  </ul>
@@ -277,9 +290,11 @@ function Modal(props: {
277
290
  type="button"
278
291
  className="rk-action"
279
292
  disabled={disconnect.isPending || connection.status !== 'connected'}
280
- onClick={() => disconnect.mutate(undefined, {
281
- onSuccess: () => props.close(props.token),
282
- })}
293
+ onClick={() =>
294
+ disconnect.mutate(undefined, {
295
+ onSuccess: () => props.close(props.token),
296
+ })
297
+ }
283
298
  >
284
299
  Disconnect
285
300
  </button>
@@ -294,16 +309,13 @@ function Modal(props: {
294
309
  }
295
310
 
296
311
  export function RainbowKitProvider(props: RainbowKitProviderProps) @{
297
- const [activeModal, setActiveModal] = useState<
298
- | {
299
- kind: ModalKind;
300
- token: ModalToken;
301
- chainId: number | undefined;
302
- opener: HTMLElement | null;
303
- ownerDocument: Document | null;
304
- }
305
- | null
306
- >(null);
312
+ const [activeModal, setActiveModal] = useState<{
313
+ kind: ModalKind;
314
+ token: ModalToken;
315
+ chainId: number | undefined;
316
+ opener: HTMLElement | null;
317
+ ownerDocument: Document | null;
318
+ } | null>(null);
307
319
  const connection = useConnection();
308
320
  const [mounted, setMounted] = useState(false);
309
321
  const connectingTokens = useRef(new Set<symbol>());
@@ -323,15 +335,15 @@ export function RainbowKitProvider(props: RainbowKitProviderProps) @{
323
335
  }
324
336
  }, []);
325
337
  const connectors = useConnect().connectors;
326
- const wallets = useMemo(() => walletEntries(connectors, props.wallets ?? []), [
327
- connectors,
328
- props.wallets,
329
- ]);
338
+ const wallets = useMemo(
339
+ () => walletEntries(connectors, props.wallets ?? []),
340
+ [connectors, props.wallets],
341
+ );
330
342
  const selectedTheme = props.theme ?? lightTheme();
331
343
  const providerId = useId();
332
344
  const closeModal = useCallback((token?: ModalToken) => {
333
345
  setActiveModal((current) => {
334
- if (!current || token && current.token !== token) return current;
346
+ if (!current || (token && current.token !== token)) return current;
335
347
  return null;
336
348
  });
337
349
  }, []);
@@ -341,30 +353,37 @@ export function RainbowKitProvider(props: RainbowKitProviderProps) @{
341
353
  activeModal.kind === 'connect'
342
354
  ? connection.status === 'connected'
343
355
  : connection.status !== 'connected' ||
344
- activeModal.kind === 'chain' && activeModal.chainId !== connection.chainId;
356
+ (activeModal.kind === 'chain' && activeModal.chainId !== connection.chainId);
345
357
  if (modalNoLongerApplies) closeModal(activeModal.token);
346
358
  }, [activeModal, closeModal, connection.chainId, connection.status]);
347
- const openModal = useCallback((kind: ModalKind, nextOpener?: HTMLElement | null) => {
348
- const token = `${providerId}:${++modalGeneration.current}`;
349
- const fallbackDocument = rootRef.current?.ownerDocument;
350
- const ownerDocument =
351
- nextOpener?.ownerDocument ?? fallbackDocument ??
359
+ const openModal = useCallback(
360
+ (kind: ModalKind, nextOpener?: HTMLElement | null) => {
361
+ const token = `${providerId}:${++modalGeneration.current}`;
362
+ const fallbackDocument = rootRef.current?.ownerDocument;
363
+ const ownerDocument =
364
+ nextOpener?.ownerDocument ??
365
+ fallbackDocument ??
352
366
  (typeof document === 'undefined' ? null : document);
353
- setActiveModal({
354
- kind,
355
- token,
356
- chainId: connection.chainId,
357
- opener: nextOpener ?? ownerDocument?.activeElement as HTMLElement | null | undefined ?? null,
358
- ownerDocument,
359
- });
360
- }, [connection.chainId, providerId]);
367
+ setActiveModal({
368
+ kind,
369
+ token,
370
+ chainId: connection.chainId,
371
+ opener:
372
+ nextOpener ?? (ownerDocument?.activeElement as HTMLElement | null | undefined) ?? null,
373
+ ownerDocument,
374
+ });
375
+ },
376
+ [connection.chainId, providerId],
377
+ );
361
378
  const context = useMemo(
362
379
  () => ({
363
380
  activeModal,
364
381
  beginConnecting,
365
382
  closeModal,
366
383
  connected: connection.status === 'connected',
367
- connecting: connectingCount > 0 || connection.status === 'connecting' ||
384
+ connecting:
385
+ connectingCount > 0 ||
386
+ connection.status === 'connecting' ||
368
387
  connection.status === 'reconnecting',
369
388
  endConnecting,
370
389
  mounted,
@@ -4,12 +4,9 @@ import type { OctaneNode } from 'octane';
4
4
  import { RainbowKitContext } from './internal';
5
5
 
6
6
  export type WalletButtonProps = {
7
- children?: | OctaneNode
8
- | ((props: {
9
- ready: boolean;
10
- connect: () => void;
11
- error: unknown | null;
12
- }) => OctaneNode);
7
+ children?:
8
+ | OctaneNode
9
+ | ((props: { ready: boolean; connect: () => void; error: unknown | null }) => OctaneNode);
13
10
  wallet: string;
14
11
  };
15
12
 
@@ -18,17 +15,19 @@ export function WalletButton(props: WalletButtonProps) {
18
15
  const mutation = useConnect();
19
16
  const entry = context?.wallets.find(
20
17
  (candidate) =>
21
- candidate.identity === props.wallet || candidate.id === props.wallet ||
22
- candidate.name === props.wallet,
18
+ candidate.identity === props.wallet ||
19
+ candidate.id === props.wallet ||
20
+ candidate.name === props.wallet,
23
21
  );
24
22
  const connector = entry?.connector;
25
23
  const ready = Boolean(context?.mounted && connector);
26
24
  const connect = () => {
27
25
  if (!context?.mounted || !connector) return;
28
26
  const token = context.beginConnecting();
29
- void mutation.connectAsync({ connector }).catch(() => {}).finally(
30
- () => context.endConnecting(token),
31
- );
27
+ void mutation
28
+ .connectAsync({ connector })
29
+ .catch(() => {})
30
+ .finally(() => context.endConnecting(token));
32
31
  };
33
32
  if (props.children != null) {
34
33
  return typeof props.children === 'function' && !isChildrenBlock(props.children)