@rango-dev/widget-embedded 0.0.0-experimental-01e2a135-20260613 → 0.0.0-experimental-e5c14f42-20260614

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": "@rango-dev/widget-embedded",
3
- "version": "0.0.0-experimental-01e2a135-20260613",
3
+ "version": "0.0.0-experimental-e5c14f42-20260614",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "source": "./src/index.ts",
@@ -16,6 +16,7 @@ import { Events } from '@rango-dev/wallets-react';
16
16
  import { type Network } from '@rango-dev/wallets-shared';
17
17
  import { isEvmBlockchain } from 'rango-sdk';
18
18
 
19
+ import { markWalletConnecting } from '../../services/walletConnectionSource';
19
20
  import { useAppStore } from '../../store/AppStore';
20
21
  import {
21
22
  prepareAccountsForWalletStore,
@@ -235,6 +236,11 @@ export function useUpdates(params: UseUpdatesParams): UseUpdates {
235
236
  };
236
237
 
237
238
  const handler: EventHandler = (type, event, value, state, info) => {
239
+ if (event === Events.CONNECTING) {
240
+ // Lock in the pending connection source for this specific wallet.
241
+ markWalletConnecting(type);
242
+ }
243
+
238
244
  if (info.isHub) {
239
245
  handleUpdatesForHub(type, event, value, state, info);
240
246
  } else {
@@ -11,8 +11,6 @@ import { WidgetProvider } from '../WidgetProvider';
11
11
  export function Widget(props: PropsWithChildren<WidgetProps>) {
12
12
  const isExternalWalletsEnabled = props.config?.externalWallets;
13
13
 
14
- console.log('Widget props', props);
15
-
16
14
  return (
17
15
  <AppRouter>
18
16
  {isExternalWalletsEnabled ? (
@@ -7,6 +7,19 @@ import {
7
7
  MIN_SEARCH_LENGTH,
8
8
  } from './SelectSwapItemPage.constants';
9
9
 
10
+ export function getTokenSelectionMethod(
11
+ searchedFor: string,
12
+ isPopular: boolean | undefined
13
+ ): 'search' | 'popular' | 'recent' {
14
+ if (searchedFor.trim()) {
15
+ return 'search';
16
+ }
17
+ if (isPopular) {
18
+ return 'popular';
19
+ }
20
+ return 'recent';
21
+ }
22
+
10
23
  export function shouldSearchForCustomTokens(
11
24
  metaSearchResultTokens: Token[],
12
25
  query: string,
@@ -18,6 +18,7 @@ import { UiEventTypes } from '../../types';
18
18
  import { emitUiEvent } from '../../utils/events';
19
19
 
20
20
  import {
21
+ getTokenSelectionMethod,
21
22
  prepareTokensList,
22
23
  shouldSearchForCustomTokens,
23
24
  } from './SelectSwapItemPage.helpers';
@@ -160,11 +161,10 @@ export function SelectSwapItemsPage(props: PropTypes) {
160
161
  tokenSymbol: token.symbol,
161
162
  tokenAddress: token.address,
162
163
  chain: token.blockchain,
163
- selectionMethod: searchedFor.trim()
164
- ? 'search'
165
- : token.isPopular
166
- ? 'popular'
167
- : 'recent',
164
+ selectionMethod: getTokenSelectionMethod(
165
+ searchedFor,
166
+ token.isPopular
167
+ ),
168
168
  activeChainFilter: selectedBlockchainName || 'all',
169
169
  },
170
170
  });
@@ -1,19 +1,41 @@
1
1
  import type { WalletConnectionSource } from '../types';
2
2
 
3
3
  /**
4
- * Tracks where in the UI the in-flight wallet connection was triggered, so the
5
- * `walletConnected` event can be enriched with a `source` once the wallet
6
- * actually connects (the connection completes asynchronously, far from the
7
- * click site). Best-effort: the most recently initiated source wins.
4
+ * Source of the connection the user is about to start, recorded when an
5
+ * in-widget connection flow is initiated (e.g. the nav or swap button). This is
6
+ * only "pending" until a specific wallet actually starts connecting — see
7
+ * `markWalletConnecting`.
8
8
  */
9
- let currentSource: WalletConnectionSource | null = null;
9
+ let pendingSource: WalletConnectionSource | null = null;
10
10
 
11
- export function setWalletConnectionSource(
11
+ /**
12
+ * Source captured per wallet type at the moment that wallet began connecting.
13
+ * Keying by wallet type (rather than a single global value) means interleaved
14
+ * or abandoned connection attempts can't misattribute each other: e.g.
15
+ * initiating from the nav, leaving the wallet popup, then connecting a
16
+ * different wallet from the swap button no longer overwrites the first wallet's
17
+ * source. The connection completes asynchronously, far from the click site, so
18
+ * the source has to be remembered until `walletConnected` is emitted.
19
+ */
20
+ const sourceByWallet = new Map<string, WalletConnectionSource | null>();
21
+
22
+ export function setPendingWalletConnectionSource(
12
23
  source: WalletConnectionSource | null
13
24
  ): void {
14
- currentSource = source;
25
+ pendingSource = source;
26
+ }
27
+
28
+ /**
29
+ * Snapshots the current pending source for a wallet as it starts connecting.
30
+ * Called on the wallet's `connecting` event.
31
+ */
32
+ export function markWalletConnecting(walletType: string): void {
33
+ sourceByWallet.set(walletType, pendingSource);
15
34
  }
16
35
 
17
- export function getWalletConnectionSource(): WalletConnectionSource | null {
18
- return currentSource;
36
+ /** Reads the source captured for a wallet when it began connecting. */
37
+ export function getWalletConnectionSource(
38
+ walletType: string
39
+ ): WalletConnectionSource | null {
40
+ return sourceByWallet.get(walletType) ?? null;
19
41
  }
@@ -457,7 +457,7 @@ export const createWalletsSlice = keepLastUpdated<AppStoreState, WalletsSlice>(
457
457
  accounts,
458
458
  chain: newAccount.chain ?? null,
459
459
  walletName: meta?.walletName ?? newAccount.walletType,
460
- source: getWalletConnectionSource(),
460
+ source: getWalletConnectionSource(newAccount.walletType),
461
461
  },
462
462
  });
463
463
 
@@ -5,8 +5,6 @@ import type {
5
5
  StepEventData,
6
6
  } from '@rango-dev/queue-manager-rango-preset';
7
7
 
8
- import { WidgetEvents as QueueManagerEvents } from '@rango-dev/queue-manager-rango-preset';
9
-
10
8
  type EventData<
11
9
  T extends QuoteEventTypes | WalletEventTypes | UiEventTypes,
12
10
  U extends Record<string, unknown> | null
@@ -85,7 +83,7 @@ export type ConnectWalletEventPayload = {
85
83
  accounts: Account[];
86
84
  /** Blockchain of the first connected account. */
87
85
  chain: string | null;
88
- /** Human-readable wallet name (e.g. "MetaMask"). */
86
+ /** wallet type (e.g. "metamask"). */
89
87
  walletName: string;
90
88
  /** Where in the UI the connection was triggered, when known. */
91
89
  source: WalletConnectionSource | null;
@@ -243,9 +241,15 @@ export type UiEventData =
243
241
  | EventData<UiEventTypes.SWAP_RETRIED, SwapRetriedEventPayload>
244
242
  | EventData<UiEventTypes.SWAP_CANCELLED, SwapCancelledEventPayload>;
245
243
 
244
+ /**
245
+ * RouteEvent/StepEvent must match the queue-manager's `WidgetEvents` string
246
+ * values (`QueueManagerEvents`) so events route correctly. They're inlined as
247
+ * literals rather than referencing the other enum to keep this a pure string
248
+ * enum (a cross-enum reference makes `no-mixed-enums` read them as numeric).
249
+ */
246
250
  export enum WidgetEvents {
247
- RouteEvent = QueueManagerEvents.RouteEvent,
248
- StepEvent = QueueManagerEvents.StepEvent,
251
+ RouteEvent = 'routeEvent',
252
+ StepEvent = 'stepEvent',
249
253
  QuoteEvent = 'quoteEvent',
250
254
  WalletEvent = 'walletEvent',
251
255
  UiEvent = 'uiEvent',
@@ -1,5 +1,5 @@
1
1
  import { eventEmitter } from '../services/eventEmitter';
2
- import { setWalletConnectionSource } from '../services/walletConnectionSource';
2
+ import { setPendingWalletConnectionSource } from '../services/walletConnectionSource';
3
3
  import {
4
4
  type ClickConnectWalletPayload,
5
5
  type QuoteEventData,
@@ -53,7 +53,7 @@ export function emitUiEvent(
53
53
  export function emitWalletConnectInitiated(
54
54
  source: WalletConnectionSource | null
55
55
  ): void {
56
- setWalletConnectionSource(source);
56
+ setPendingWalletConnectionSource(source);
57
57
  eventEmitter.emit(WidgetEvents.WalletEvent, {
58
58
  type: WalletEventTypes.CONNECT_INITIATED,
59
59
  payload: { source },