@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/dist/components/ConfirmWalletsModal/WalletList.d.ts.map +1 -1
- package/dist/containers/Widget/Widget.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +3 -3
- package/dist/pages/SelectSwapItemPage/SelectSwapItemPage.helpers.d.ts +1 -0
- package/dist/pages/SelectSwapItemPage/SelectSwapItemPage.helpers.d.ts.map +1 -1
- package/dist/pages/SelectSwapItemPage/SelectSwapItemsPage.d.ts.map +1 -1
- package/dist/services/walletConnectionSource.d.ts +7 -2
- package/dist/services/walletConnectionSource.d.ts.map +1 -1
- package/dist/types/event.d.ts +7 -1
- package/dist/types/event.d.ts.map +1 -1
- package/dist/widget-embedded.build.json +1 -1
- package/package.json +1 -1
- package/src/components/ConfirmWalletsModal/WalletList.tsx +3 -0
- package/src/containers/Widget/Widget.tsx +0 -2
- package/src/pages/SelectSwapItemPage/SelectSwapItemPage.helpers.ts +13 -0
- package/src/pages/SelectSwapItemPage/SelectSwapItemsPage.tsx +5 -5
- package/src/services/walletConnectionSource.ts +22 -9
- package/src/store/slices/wallets.ts +2 -2
- package/src/types/event.ts +9 -5
- package/src/utils/events.ts +2 -2
package/package.json
CHANGED
|
@@ -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:
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
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
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
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
|
|
15
|
+
let pendingSource: WalletConnectionSource | null = null;
|
|
10
16
|
|
|
11
|
-
|
|
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
|
-
|
|
21
|
+
pendingSource = source;
|
|
15
22
|
}
|
|
16
23
|
|
|
17
|
-
|
|
18
|
-
|
|
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 {
|
|
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:
|
|
460
|
+
source: consumeWalletConnectionSource(),
|
|
461
461
|
},
|
|
462
462
|
});
|
|
463
463
|
|
package/src/types/event.ts
CHANGED
|
@@ -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
|
-
/**
|
|
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 =
|
|
248
|
-
StepEvent =
|
|
251
|
+
RouteEvent = 'routeEvent',
|
|
252
|
+
StepEvent = 'stepEvent',
|
|
249
253
|
QuoteEvent = 'quoteEvent',
|
|
250
254
|
WalletEvent = 'walletEvent',
|
|
251
255
|
UiEvent = 'uiEvent',
|
package/src/utils/events.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { eventEmitter } from '../services/eventEmitter';
|
|
2
|
-
import {
|
|
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
|
-
|
|
56
|
+
setPendingWalletConnectionSource(source);
|
|
57
57
|
eventEmitter.emit(WidgetEvents.WalletEvent, {
|
|
58
58
|
type: WalletEventTypes.CONNECT_INITIATED,
|
|
59
59
|
payload: { source },
|