@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/dist/containers/Wallets/useUpdates.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 +8 -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/containers/Wallets/useUpdates.ts +6 -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 +31 -9
- package/src/store/slices/wallets.ts +1 -1
- package/src/types/event.ts +9 -5
- package/src/utils/events.ts +2 -2
package/package.json
CHANGED
|
@@ -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:
|
|
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,41 @@
|
|
|
1
1
|
import type { WalletConnectionSource } from '../types';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
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
|
|
9
|
+
let pendingSource: WalletConnectionSource | null = null;
|
|
10
10
|
|
|
11
|
-
|
|
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
|
-
|
|
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
|
-
|
|
18
|
-
|
|
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
|
|
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 },
|