@rango-dev/widget-embedded 0.0.0-experimental-ce08124c-20260613 → 0.0.0-experimental-55d181be-20260613

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.
Files changed (53) hide show
  1. package/dist/components/ConfirmWalletsModal/ConfirmWalletsModal.d.ts.map +1 -1
  2. package/dist/components/CustomDestination/CustomDestination.d.ts.map +1 -1
  3. package/dist/components/Quote/QuoteCostDetails.d.ts.map +1 -1
  4. package/dist/components/Slippage/Slippage.d.ts.map +1 -1
  5. package/dist/components/SwapDetails/SwapDetails.d.ts.map +1 -1
  6. package/dist/containers/Settings/Lists.d.ts.map +1 -1
  7. package/dist/containers/Wallets/useUpdates.d.ts.map +1 -1
  8. package/dist/containers/Widget/Widget.d.ts.map +1 -1
  9. package/dist/hooks/useSwapInput.d.ts.map +1 -1
  10. package/dist/hooks/useSyncNotifications/useSyncNotifications.d.ts.map +1 -1
  11. package/dist/hooks/useWalletList.d.ts.map +1 -1
  12. package/dist/index.js +2 -2
  13. package/dist/index.js.map +4 -4
  14. package/dist/pages/ConfirmSwapPage.d.ts.map +1 -1
  15. package/dist/pages/Home.d.ts.map +1 -1
  16. package/dist/pages/LiquiditySourcePage.d.ts.map +1 -1
  17. package/dist/pages/SelectBlockchainPage.d.ts.map +1 -1
  18. package/dist/pages/SelectSwapItemPage/SelectSwapItemsPage.d.ts.map +1 -1
  19. package/dist/pages/SwapDetailsPage.d.ts.map +1 -1
  20. package/dist/store/slices/wallets.d.ts +1 -3
  21. package/dist/store/slices/wallets.d.ts.map +1 -1
  22. package/dist/types/event.d.ts +6 -135
  23. package/dist/types/event.d.ts.map +1 -1
  24. package/dist/utils/events.d.ts +5 -16
  25. package/dist/utils/events.d.ts.map +1 -1
  26. package/dist/widget-embedded.build.json +1 -1
  27. package/package.json +1 -1
  28. package/src/components/ConfirmWalletsModal/ConfirmWalletsModal.tsx +2 -53
  29. package/src/components/CustomDestination/CustomDestination.tsx +0 -18
  30. package/src/components/Quote/QuoteCostDetails.tsx +0 -8
  31. package/src/components/Slippage/Slippage.tsx +0 -21
  32. package/src/components/SwapDetails/SwapDetails.tsx +0 -6
  33. package/src/containers/Settings/Lists.tsx +1 -13
  34. package/src/containers/Wallets/useUpdates.ts +2 -5
  35. package/src/containers/Widget/Widget.tsx +2 -0
  36. package/src/hooks/useSwapInput.ts +1 -46
  37. package/src/hooks/useSyncNotifications/useSyncNotifications.ts +1 -26
  38. package/src/hooks/useWalletList.ts +0 -34
  39. package/src/pages/ConfirmSwapPage.tsx +1 -12
  40. package/src/pages/Home.tsx +4 -33
  41. package/src/pages/LiquiditySourcePage.tsx +0 -24
  42. package/src/pages/SelectBlockchainPage.tsx +0 -10
  43. package/src/pages/SelectSwapItemPage/SelectSwapItemsPage.tsx +0 -27
  44. package/src/pages/SwapDetailsPage.tsx +0 -6
  45. package/src/store/slices/wallets.ts +3 -11
  46. package/src/types/event.ts +6 -174
  47. package/src/utils/events.ts +6 -51
  48. package/dist/services/walletConnectionSource.d.ts +0 -4
  49. package/dist/services/walletConnectionSource.d.ts.map +0 -1
  50. package/dist/utils/eventPayloads.d.ts +0 -8
  51. package/dist/utils/eventPayloads.d.ts.map +0 -1
  52. package/src/services/walletConnectionSource.ts +0 -19
  53. package/src/utils/eventPayloads.ts +0 -37
@@ -9,8 +9,6 @@ import { SwapDetails } from '../components/SwapDetails';
9
9
  import { SwapDetailsPlaceholder } from '../components/SwapDetails/SwapDetails.Placeholder';
10
10
  import { useNavigateBack } from '../hooks/useNavigateBack';
11
11
  import { useAppStore } from '../store/AppStore';
12
- import { UiEventTypes } from '../types';
13
- import { emitUiEvent } from '../utils/events';
14
12
  import { getPendingSwaps } from '../utils/queue';
15
13
 
16
14
  export function SwapDetailsPage() {
@@ -43,10 +41,6 @@ export function SwapDetailsPage() {
43
41
  if (selectedSwap?.id) {
44
42
  const swap = manager?.get(selectedSwap.id);
45
43
  if (swap) {
46
- emitUiEvent({
47
- type: UiEventTypes.SWAP_CANCELLED,
48
- payload: { routeId: requestId },
49
- });
50
44
  cancelSwap(swap);
51
45
  }
52
46
  }
@@ -8,7 +8,6 @@ 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';
12
11
  import {
13
12
  type Balance,
14
13
  type Wallet,
@@ -115,8 +114,7 @@ export interface WalletsSlice {
115
114
  newWalletConnected: (
116
115
  accounts: Wallet[],
117
116
  namespace?: Namespace,
118
- derivationPath?: string,
119
- meta?: { walletName?: string }
117
+ derivationPath?: string
120
118
  ) => Promise<void>;
121
119
  disconnectNamespaces: (walletType: string, namespaces: Namespace[]) => void;
122
120
  /**
@@ -445,20 +443,14 @@ export const createWalletsSlice = keepLastUpdated<AppStoreState, WalletsSlice>(
445
443
  connectedWallets: nextConnectedWalletsWithUpdatedSelectedStatus,
446
444
  });
447
445
  },
448
- newWalletConnected: async (accounts, namespace, derivationPath, meta) => {
446
+ newWalletConnected: async (accounts, namespace, derivationPath) => {
449
447
  const newAccount = accounts[0];
450
448
  if (!newAccount) {
451
449
  return;
452
450
  }
453
451
  eventEmitter.emit(WidgetEvents.WalletEvent, {
454
452
  type: WalletEventTypes.CONNECT,
455
- payload: {
456
- walletType: newAccount.walletType,
457
- accounts,
458
- chain: newAccount.chain ?? null,
459
- walletName: meta?.walletName ?? newAccount.walletType,
460
- source: getWalletConnectionSource(),
461
- },
453
+ payload: { walletType: newAccount.walletType, accounts },
462
454
  });
463
455
 
464
456
  get().addConnectedWallet(accounts, namespace, derivationPath);
@@ -23,48 +23,19 @@ type Account = Wallet;
23
23
  export enum QuoteEventTypes {
24
24
  QUOTE_INPUT_UPDATE = 'quoteInputUpdate',
25
25
  QUOTE_OUTPUT_UPDATE = 'quoteOutputUpdate',
26
- /** A route/quote request was made with a valid source, destination and amount. */
27
- ROUTE_REQUESTED = 'routeRequested',
28
- /** The route API returned zero results for the requested pair. */
29
- ROUTE_NOT_FOUND = 'routeNotFound',
30
- /** The route API returned a 4xx/5xx error. */
31
- ROUTE_FETCH_FAILED = 'routeFetchFailed',
32
- /** The user overrode the auto-selected route. */
33
- ROUTE_CHANGED = 'routeChanged',
34
26
  }
35
27
 
36
28
  export enum WalletEventTypes {
37
29
  CONNECT = 'connect',
38
30
  DISCONNECT = 'disconnect',
39
- /** The user opened the wallet connection modal/flow. */
40
- CONNECT_INITIATED = 'connectInitiated',
41
- /** A wallet provider was detected on app load (one per detected wallet). */
42
- DETECTED = 'detected',
43
31
  }
44
32
 
45
- /** Where in the UI a wallet connection was triggered. */
46
- export type WalletConnectionSource = 'nav' | 'swap_button' | 'confirm_modal';
47
-
48
33
  /**
49
34
  * We use a prefix for interaction type and a name for defining the event name: INTERACTION_EVENT_NAME
50
35
  * e.g. CLICK_X_BUTTON or NAVIGATE_WALLET_PAGE
51
36
  */
52
37
  export enum UiEventTypes {
53
38
  CLICK_CONNECT_WALLET = 'clickConnectWallet',
54
- TOKEN_SELECTED = 'tokenSelected',
55
- CHAIN_FILTER_APPLIED = 'chainFilterApplied',
56
- SETTINGS_CHANGED = 'settingsChanged',
57
- ROUTE_FEE_VIEWED = 'routeFeeViewed',
58
- DESTINATION_ADDRESS_SET = 'destinationAddressSet',
59
- GAS_WARNING_SHOWN = 'gasWarningShown',
60
- GAS_WARNING_BYPASSED = 'gasWarningBypassed',
61
- SWAP_INITIATED = 'swapInitiated',
62
- SWAP_WALLETS_MODAL_SHOWN = 'swapWalletsModalShown',
63
- SWAP_WALLETS_CONFIRMED = 'swapWalletsConfirmed',
64
- SWAP_STARTED = 'swapStarted',
65
- SWAP_RESUMED = 'swapResumed',
66
- SWAP_RETRIED = 'swapRetried',
67
- SWAP_CANCELLED = 'swapCancelled',
68
39
  }
69
40
 
70
41
  export type QuoteInputUpdateEventPayload = {
@@ -83,165 +54,26 @@ export type QuoteUpdateEventPayload = Pick<
83
54
  export type ConnectWalletEventPayload = {
84
55
  walletType: string;
85
56
  accounts: Account[];
86
- /** Blockchain of the first connected account. */
87
- chain: string | null;
88
- /** Human-readable wallet name (e.g. "MetaMask"). */
89
- walletName: string;
90
- /** Where in the UI the connection was triggered, when known. */
91
- source: WalletConnectionSource | null;
92
57
  };
93
58
 
94
59
  export type DisconnectWalletEventPayload = {
95
60
  walletType: string;
96
61
  };
97
62
 
98
- export type ConnectInitiatedWalletEventPayload = {
99
- /** Where in the UI the connection flow was opened, when known. */
100
- source: WalletConnectionSource | null;
101
- };
102
-
103
- export type WalletDetectedEventPayload = {
104
- walletType: string;
105
- walletName: string;
106
- };
107
-
108
63
  export type ClickConnectWalletPayload = PreventableEventPayload;
109
64
 
110
- /** Shared shape describing a route/quote, used by several swap events. */
111
- export type SwapEstimateEventPayload = {
112
- sourceChain: string;
113
- destinationChain: string;
114
- sourceToken: string;
115
- destinationToken: string;
116
- inputAmountUsd: number | null;
117
- outputAmountUsd: number | null;
118
- sourceTokenAmount: number | null;
119
- destinationTokenAmount: number | null;
120
- routeId: string;
121
- };
122
-
123
- export type RouteRequestedEventPayload = SwapEstimateEventPayload & {
124
- routeCount: number;
125
- };
126
-
127
- export type RouteNotFoundEventPayload = {
128
- sourceChain: string;
129
- destinationChain: string;
130
- sourceToken: string;
131
- destinationToken: string;
132
- inputAmountUsd: number | null;
133
- };
134
-
135
- export type RouteFetchFailedEventPayload = {
136
- sourceChain: string;
137
- destinationChain: string;
138
- /** HTTP status code returned by the route API, as a string. */
139
- errorCode: string;
140
- };
141
-
142
- export type RouteChangedEventPayload = {
143
- sourceChain: string;
144
- destinationChain: string;
145
- fromRouteId: string;
146
- toRouteId: string;
147
- };
148
-
149
- export type TokenSelectedEventPayload = {
150
- side: 'from' | 'to';
151
- tokenName: string | null;
152
- tokenSymbol: string;
153
- tokenAddress: string | null;
154
- chain: string;
155
- selectionMethod: 'search' | 'popular' | 'recent';
156
- /** `all` when no chain filter is active, otherwise the filtered chain name. */
157
- activeChainFilter: string;
158
- };
159
-
160
- export type ChainFilterAppliedEventPayload = {
161
- side: 'from' | 'to';
162
- chain: string;
163
- filterSource: 'featured' | 'expanded';
164
- };
165
-
166
- export type SettingsChangedEventPayload = {
167
- settingName: 'slippage' | 'bridge_exclusion' | 'infinite_approval';
168
- previousValue: string;
169
- newValue: string;
170
- };
171
-
172
- export type RouteFeeViewedEventPayload = { routeId: string };
173
-
174
- export type DestinationAddressSetEventPayload = { destinationChain: string };
175
-
176
- export type GasWarningEventPayload = { routeId: string };
177
-
178
- export type SwapInitiatedEventPayload = SwapEstimateEventPayload & {
179
- walletConnected: boolean;
180
- };
181
-
182
- export type SwapStartedEventPayload = SwapEstimateEventPayload & {
183
- stepCount: number;
184
- };
185
-
186
- export type SwapWalletsModalShownEventPayload = {
187
- chainsRequired: number;
188
- chainsPending: number;
189
- };
190
-
191
- export type SwapWalletsConfirmedEventPayload = { routeId: string };
192
-
193
- export type SwapResumedEventPayload = {
194
- routeId: string;
195
- stepCount: number;
196
- stepNumber: number;
197
- };
198
-
199
- export type SwapRetriedEventPayload = { routeId: string };
200
-
201
- export type SwapCancelledEventPayload = { routeId: string };
202
-
203
65
  export type QuoteEventData =
204
66
  | EventData<QuoteEventTypes.QUOTE_INPUT_UPDATE, QuoteInputUpdateEventPayload>
205
- | EventData<QuoteEventTypes.QUOTE_OUTPUT_UPDATE, QuoteUpdateEventPayload>
206
- | EventData<QuoteEventTypes.ROUTE_REQUESTED, RouteRequestedEventPayload>
207
- | EventData<QuoteEventTypes.ROUTE_NOT_FOUND, RouteNotFoundEventPayload>
208
- | EventData<QuoteEventTypes.ROUTE_FETCH_FAILED, RouteFetchFailedEventPayload>
209
- | EventData<QuoteEventTypes.ROUTE_CHANGED, RouteChangedEventPayload>;
67
+ | EventData<QuoteEventTypes.QUOTE_OUTPUT_UPDATE, QuoteUpdateEventPayload>;
210
68
 
211
69
  export type WalletEventData =
212
70
  | EventData<WalletEventTypes.CONNECT, ConnectWalletEventPayload>
213
- | EventData<WalletEventTypes.DISCONNECT, DisconnectWalletEventPayload>
214
- | EventData<
215
- WalletEventTypes.CONNECT_INITIATED,
216
- ConnectInitiatedWalletEventPayload
217
- >
218
- | EventData<WalletEventTypes.DETECTED, WalletDetectedEventPayload>;
71
+ | EventData<WalletEventTypes.DISCONNECT, DisconnectWalletEventPayload>;
219
72
 
220
- export type UiEventData =
221
- | EventData<UiEventTypes.CLICK_CONNECT_WALLET, ClickConnectWalletPayload>
222
- | EventData<UiEventTypes.TOKEN_SELECTED, TokenSelectedEventPayload>
223
- | EventData<UiEventTypes.CHAIN_FILTER_APPLIED, ChainFilterAppliedEventPayload>
224
- | EventData<UiEventTypes.SETTINGS_CHANGED, SettingsChangedEventPayload>
225
- | EventData<UiEventTypes.ROUTE_FEE_VIEWED, RouteFeeViewedEventPayload>
226
- | EventData<
227
- UiEventTypes.DESTINATION_ADDRESS_SET,
228
- DestinationAddressSetEventPayload
229
- >
230
- | EventData<UiEventTypes.GAS_WARNING_SHOWN, GasWarningEventPayload>
231
- | EventData<UiEventTypes.GAS_WARNING_BYPASSED, GasWarningEventPayload>
232
- | EventData<UiEventTypes.SWAP_INITIATED, SwapInitiatedEventPayload>
233
- | EventData<
234
- UiEventTypes.SWAP_WALLETS_MODAL_SHOWN,
235
- SwapWalletsModalShownEventPayload
236
- >
237
- | EventData<
238
- UiEventTypes.SWAP_WALLETS_CONFIRMED,
239
- SwapWalletsConfirmedEventPayload
240
- >
241
- | EventData<UiEventTypes.SWAP_STARTED, SwapStartedEventPayload>
242
- | EventData<UiEventTypes.SWAP_RESUMED, SwapResumedEventPayload>
243
- | EventData<UiEventTypes.SWAP_RETRIED, SwapRetriedEventPayload>
244
- | EventData<UiEventTypes.SWAP_CANCELLED, SwapCancelledEventPayload>;
73
+ export type UiEventData = EventData<
74
+ UiEventTypes.CLICK_CONNECT_WALLET,
75
+ ClickConnectWalletPayload
76
+ >;
245
77
 
246
78
  export enum WidgetEvents {
247
79
  RouteEvent = QueueManagerEvents.RouteEvent,
@@ -1,32 +1,19 @@
1
1
  import { eventEmitter } from '../services/eventEmitter';
2
- import { setWalletConnectionSource } from '../services/walletConnectionSource';
3
- import {
4
- type ClickConnectWalletPayload,
5
- type QuoteEventData,
6
- type UiEventData,
7
- type UiEventTypes,
8
- type WalletConnectionSource,
9
- type WalletDetectedEventPayload,
10
- WalletEventTypes,
11
- WidgetEvents,
12
- } from '../types';
2
+ import { type UiEventData, WidgetEvents } from '../types';
13
3
 
14
- type PreventableUiEvent = {
15
- type: UiEventTypes.CLICK_CONNECT_WALLET;
16
- payload?: Omit<ClickConnectWalletPayload, 'preventDefault'>;
4
+ type UiEvent = {
5
+ type: UiEventData['type'];
6
+ payload?: Omit<UiEventData['payload'], 'preventDefault'>;
17
7
  };
18
8
 
19
- export function emitPreventableEvent(
20
- event: PreventableUiEvent,
21
- action: () => void
22
- ): void {
9
+ export function emitPreventableEvent(event: UiEvent, action: () => void): void {
23
10
  let defaultPrevented = false;
24
11
 
25
12
  const extendedPayload = {
26
- ...event.payload,
27
13
  preventDefault() {
28
14
  defaultPrevented = true;
29
15
  },
16
+ ...(event.payload === undefined && { payload: event.payload }),
30
17
  };
31
18
 
32
19
  eventEmitter.emit(WidgetEvents.UiEvent, {
@@ -38,35 +25,3 @@ export function emitPreventableEvent(
38
25
  action();
39
26
  }
40
27
  }
41
-
42
- export function emitUiEvent(
43
- event: Exclude<UiEventData, { type: UiEventTypes.CLICK_CONNECT_WALLET }>
44
- ): void {
45
- eventEmitter.emit(WidgetEvents.UiEvent, event);
46
- }
47
-
48
- /**
49
- * Records the source of the wallet connection the user is about to start and
50
- * emits a `connectInitiated` wallet event. The recorded source is later read
51
- * when the wallet finishes connecting to enrich the `connect` event.
52
- */
53
- export function emitWalletConnectInitiated(
54
- source: WalletConnectionSource | null
55
- ): void {
56
- setWalletConnectionSource(source);
57
- eventEmitter.emit(WidgetEvents.WalletEvent, {
58
- type: WalletEventTypes.CONNECT_INITIATED,
59
- payload: { source },
60
- });
61
- }
62
-
63
- export function emitQuoteEvent(event: QuoteEventData): void {
64
- eventEmitter.emit(WidgetEvents.QuoteEvent, event);
65
- }
66
-
67
- export function emitWalletDetected(payload: WalletDetectedEventPayload): void {
68
- eventEmitter.emit(WidgetEvents.WalletEvent, {
69
- type: WalletEventTypes.DETECTED,
70
- payload,
71
- });
72
- }
@@ -1,4 +0,0 @@
1
- import type { WalletConnectionSource } from '../types';
2
- export declare function setWalletConnectionSource(source: WalletConnectionSource | null): void;
3
- export declare function getWalletConnectionSource(): WalletConnectionSource | null;
4
- //# sourceMappingURL=walletConnectionSource.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"walletConnectionSource.d.ts","sourceRoot":"","sources":["../../src/services/walletConnectionSource.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAC;AAUvD,wBAAgB,yBAAyB,CACvC,MAAM,EAAE,sBAAsB,GAAG,IAAI,GACpC,IAAI,CAEN;AAED,wBAAgB,yBAAyB,IAAI,sBAAsB,GAAG,IAAI,CAEzE"}
@@ -1,8 +0,0 @@
1
- import type { SelectedQuote, SwapEstimateEventPayload } from '../types';
2
- /**
3
- * Derives the shared route/quote descriptor used by several swap
4
- * events (swapInitiated, swapStarted, routeRequested, ...) from a quote.
5
- * Amounts are estimates taken from the quote, not on-chain actuals.
6
- */
7
- export declare function buildSwapEstimatePayload(quote: SelectedQuote): SwapEstimateEventPayload;
8
- //# sourceMappingURL=eventPayloads.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"eventPayloads.d.ts","sourceRoot":"","sources":["../../src/utils/eventPayloads.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,wBAAwB,EAAE,MAAM,UAAU,CAAC;AAYxE;;;;GAIG;AACH,wBAAgB,wBAAwB,CACtC,KAAK,EAAE,aAAa,GACnB,wBAAwB,CAiB1B"}
@@ -1,19 +0,0 @@
1
- import type { WalletConnectionSource } from '../types';
2
-
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.
8
- */
9
- let currentSource: WalletConnectionSource | null = null;
10
-
11
- export function setWalletConnectionSource(
12
- source: WalletConnectionSource | null
13
- ): void {
14
- currentSource = source;
15
- }
16
-
17
- export function getWalletConnectionSource(): WalletConnectionSource | null {
18
- return currentSource;
19
- }
@@ -1,37 +0,0 @@
1
- import type { SelectedQuote, SwapEstimateEventPayload } from '../types';
2
-
3
- import { getUsdInputFrom, getUsdOutputFrom } from './swap';
4
-
5
- function toNumberOrNull(value: string | null | undefined): number | null {
6
- if (value === null || value === undefined || value === '') {
7
- return null;
8
- }
9
- const parsed = Number(value);
10
- return Number.isFinite(parsed) ? parsed : null;
11
- }
12
-
13
- /**
14
- * Derives the shared route/quote descriptor used by several swap
15
- * events (swapInitiated, swapStarted, routeRequested, ...) from a quote.
16
- * Amounts are estimates taken from the quote, not on-chain actuals.
17
- */
18
- export function buildSwapEstimatePayload(
19
- quote: SelectedQuote
20
- ): SwapEstimateEventPayload {
21
- const firstSwap = quote.swaps[0];
22
- const lastSwap = quote.swaps[quote.swaps.length - 1];
23
- const inputUsd = getUsdInputFrom(quote);
24
- const outputUsd = getUsdOutputFrom(quote);
25
-
26
- return {
27
- routeId: quote.requestId,
28
- sourceChain: firstSwap?.from.blockchain ?? '',
29
- destinationChain: lastSwap?.to.blockchain ?? '',
30
- sourceToken: firstSwap?.from.symbol ?? '',
31
- destinationToken: lastSwap?.to.symbol ?? '',
32
- sourceTokenAmount: toNumberOrNull(quote.requestAmount),
33
- destinationTokenAmount: toNumberOrNull(quote.outputAmount),
34
- inputAmountUsd: inputUsd ? inputUsd.toNumber() : null,
35
- outputAmountUsd: outputUsd ? outputUsd.toNumber() : null,
36
- };
37
- }