@rango-dev/widget-embedded 0.0.0-experimental-01e2a135-20260613 → 0.0.0-experimental-248dbf7f-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-248dbf7f-20260614",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "source": "./src/index.ts",
@@ -18,6 +18,7 @@ import { WIDGET_UI_ID } from '../../constants';
18
18
  import { useWalletList } from '../../hooks/useWalletList';
19
19
  import { useAppStore } from '../../store/AppStore';
20
20
  import { useUiStore } from '../../store/ui';
21
+ import { emitWalletConnectInitiated } from '../../utils/events';
21
22
  import { getBlockchainDisplayNameFor } from '../../utils/meta';
22
23
  import {
23
24
  getAddress,
@@ -176,6 +177,8 @@ export function WalletList(props: PropTypes) {
176
177
  (isConnectedButDifferentThanTargetNamespace &&
177
178
  !couldAddExperimentalChain)
178
179
  ) {
180
+ // The user is starting a connection from the confirm-wallets modal.
181
+ emitWalletConnectInitiated('confirm_modal');
179
182
  setSelectedWalletToConnect(wallet);
180
183
  } else if (couldAddExperimentalChain) {
181
184
  setExperimentalChainWallet({
@@ -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,32 @@
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
+ * Tracks where the user started a wallet connection inside the widget (the swap
5
+ * button, the nav, or the confirm-wallets modal) so the `walletConnected` event
6
+ * can carry a `source`.
7
+ *
8
+ * The initiation and the resulting connection are far apart (the user still has
9
+ * to pick a wallet and approve a popup), so the source is stashed when the flow
10
+ * is initiated and consumed by the next connection that completes:
11
+ *
12
+ * 1. connection initiated -> setPendingWalletConnectionSource(source)
13
+ * 2. a wallet connects -> newWalletConnected reads consumeWalletConnectionSource()
8
14
  */
9
- let currentSource: WalletConnectionSource | null = null;
15
+ let pendingSource: WalletConnectionSource | null = null;
10
16
 
11
- export function setWalletConnectionSource(
17
+ /** Records the source for the connection the user is about to start. */
18
+ export function setPendingWalletConnectionSource(
12
19
  source: WalletConnectionSource | null
13
20
  ): void {
14
- currentSource = source;
21
+ pendingSource = source;
15
22
  }
16
23
 
17
- export function getWalletConnectionSource(): WalletConnectionSource | null {
18
- return currentSource;
24
+ /**
25
+ * Returns the pending source and clears it, so it's applied to exactly one
26
+ * connection and can't leak to later, unrelated ones.
27
+ */
28
+ export function consumeWalletConnectionSource(): WalletConnectionSource | null {
29
+ const source = pendingSource;
30
+ pendingSource = null;
31
+ return source;
19
32
  }
@@ -8,7 +8,7 @@ import { ZERO } from '../../constants/numbers';
8
8
  import { BALANCE_SEPARATOR } from '../../constants/wallets';
9
9
  import { eventEmitter } from '../../services/eventEmitter';
10
10
  import { httpService } from '../../services/httpService';
11
- import { getWalletConnectionSource } from '../../services/walletConnectionSource';
11
+ import { consumeWalletConnectionSource } from '../../services/walletConnectionSource';
12
12
  import {
13
13
  type Balance,
14
14
  type Wallet,
@@ -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: consumeWalletConnectionSource(),
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 },