@rango-dev/widget-embedded 0.30.1-next.5 → 0.30.1-next.7

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 (37) hide show
  1. package/dist/components/ConfirmWalletsModal/ConfirmWallets.styles.d.ts +1 -653
  2. package/dist/components/ConfirmWalletsModal/ConfirmWallets.styles.d.ts.map +1 -1
  3. package/dist/components/ConfirmWalletsModal/ConfirmWalletsModal.d.ts.map +1 -1
  4. package/dist/components/CustomDestination/CustomDestination.d.ts +4 -0
  5. package/dist/components/CustomDestination/CustomDestination.d.ts.map +1 -0
  6. package/dist/components/CustomDestination/CustomDestination.styles.d.ts +495 -0
  7. package/dist/components/CustomDestination/CustomDestination.styles.d.ts.map +1 -0
  8. package/dist/components/CustomDestination/CustomDestination.types.d.ts +7 -0
  9. package/dist/components/CustomDestination/CustomDestination.types.d.ts.map +1 -0
  10. package/dist/components/Quote/Quote.styles.d.ts +2 -2
  11. package/dist/components/RefreshModal/RefreshModal.styles.d.ts +2 -2
  12. package/dist/index.d.ts +4 -4
  13. package/dist/index.d.ts.map +1 -1
  14. package/dist/index.js +2 -2
  15. package/dist/index.js.map +4 -4
  16. package/dist/pages/Home.d.ts.map +1 -1
  17. package/dist/types/config.d.ts +5 -0
  18. package/dist/types/config.d.ts.map +1 -1
  19. package/dist/types/event.d.ts +21 -15
  20. package/dist/types/event.d.ts.map +1 -1
  21. package/dist/utils/events.d.ts +8 -0
  22. package/dist/utils/events.d.ts.map +1 -0
  23. package/dist/utils/swap.d.ts +1 -1
  24. package/dist/utils/swap.d.ts.map +1 -1
  25. package/dist/widget-embedded.build.json +1 -1
  26. package/package.json +1 -1
  27. package/src/components/ConfirmWalletsModal/ConfirmWallets.styles.ts +1 -49
  28. package/src/components/ConfirmWalletsModal/ConfirmWalletsModal.tsx +59 -178
  29. package/src/components/CustomDestination/CustomDestination.styles.ts +45 -0
  30. package/src/components/CustomDestination/CustomDestination.tsx +148 -0
  31. package/src/components/CustomDestination/CustomDestination.types.ts +7 -0
  32. package/src/index.ts +4 -0
  33. package/src/pages/Home.tsx +6 -3
  34. package/src/types/config.ts +3 -1
  35. package/src/types/event.ts +32 -16
  36. package/src/utils/events.ts +27 -0
  37. package/src/utils/swap.ts +4 -4
@@ -179,6 +179,8 @@ export type TrezorManifest = {
179
179
  * @property {boolean} customDestination - A boolean value indicating whether the user can input a custom
180
180
  * address for the transaction. If set to true, the widget will allow the user to input a custom
181
181
  * address for the destination.
182
+ * @property {{[blockchain: string]: string }} defaultCustomDestinations - The `defaultCustomDestinations` property is a map of supported `blockchain` names to an arbitrary blockchain address.
183
+ * You could use it to set a default custom destination for some blockchains. e.g. {'BSC': '0x2be.....c1','ETH': '0x2be.....c1'}
182
184
  * @property {string} language - The language property is an optional string that specifies the
183
185
  * default language in which the widget should be displayed. If not provided, the widget will default to the
184
186
  * language of the user's browser.
@@ -219,6 +221,7 @@ export type WidgetConfig = {
219
221
  wallets?: (WalletType | ProviderInterface)[];
220
222
  multiWallets?: boolean;
221
223
  customDestination?: boolean;
224
+ defaultCustomDestinations?: { [blockchain: string]: string };
222
225
  language?: Language;
223
226
  theme?: WidgetTheme;
224
227
  externalWallets?: boolean;
@@ -227,7 +230,6 @@ export type WidgetConfig = {
227
230
  variant?: WidgetVariant;
228
231
  enableCentralizedSwappers?: boolean;
229
232
  signers?: SignersConfig;
230
-
231
233
  // These are likely to change or remove at anytime. Please use with a caution.
232
234
  __UNSTABLE_OR_INTERNAL__?: {
233
235
  walletConnectListedDesktopWalletLink?: string;
@@ -7,6 +7,17 @@ import type {
7
7
 
8
8
  import { WidgetEvents as QueueManagerEvents } from '@rango-dev/queue-manager-rango-preset';
9
9
 
10
+ type EventData<
11
+ T extends QuoteEventTypes | WalletEventTypes | UiEventTypes,
12
+ U extends Record<string, unknown> | null
13
+ > = { type: T; payload: U };
14
+
15
+ export type PreventableEventPayload<
16
+ T extends Record<string, unknown> = Record<string, unknown>
17
+ > = {
18
+ preventDefault: () => void;
19
+ } & T;
20
+
10
21
  type Account = Wallet;
11
22
 
12
23
  export enum QuoteEventTypes {
@@ -19,6 +30,14 @@ export enum WalletEventTypes {
19
30
  DISCONNECT = 'disconnect',
20
31
  }
21
32
 
33
+ /**
34
+ * We use a prefix for interaction type and a name for defining the event name: INTERACTION_EVENT_NAME
35
+ * e.g. CLICK_X_BUTTON or NAVIGATE_WALLET_PAGE
36
+ */
37
+ export enum UiEventTypes {
38
+ CLICK_CONNECT_WALLET = 'clickConnectWallet',
39
+ }
40
+
22
41
  export type QuoteInputUpdateEventPayload = {
23
42
  fromBlockchain?: string;
24
43
  toBlockchain?: string;
@@ -41,31 +60,27 @@ export type DisconnectWalletEventPayload = {
41
60
  walletType: string;
42
61
  };
43
62
 
63
+ export type ClickConnectWalletPayload = PreventableEventPayload;
64
+
44
65
  export type QuoteEventData =
45
- | {
46
- type: QuoteEventTypes.QUOTE_INPUT_UPDATE;
47
- payload: QuoteInputUpdateEventPayload;
48
- }
49
- | {
50
- type: QuoteEventTypes.QUOTE_OUTPUT_UPDATE;
51
- payload: QuoteUpdateEventPayload;
52
- };
66
+ | EventData<QuoteEventTypes.QUOTE_INPUT_UPDATE, QuoteInputUpdateEventPayload>
67
+ | EventData<QuoteEventTypes.QUOTE_OUTPUT_UPDATE, QuoteUpdateEventPayload>;
53
68
 
54
69
  export type WalletEventData =
55
- | {
56
- type: WalletEventTypes.CONNECT;
57
- payload: ConnectWalletEventPayload;
58
- }
59
- | {
60
- type: WalletEventTypes.DISCONNECT;
61
- payload: DisconnectWalletEventPayload;
62
- };
70
+ | EventData<WalletEventTypes.CONNECT, ConnectWalletEventPayload>
71
+ | EventData<WalletEventTypes.DISCONNECT, DisconnectWalletEventPayload>;
72
+
73
+ export type UiEventData = EventData<
74
+ UiEventTypes.CLICK_CONNECT_WALLET,
75
+ ClickConnectWalletPayload
76
+ >;
63
77
 
64
78
  export enum WidgetEvents {
65
79
  RouteEvent = QueueManagerEvents.RouteEvent,
66
80
  StepEvent = QueueManagerEvents.StepEvent,
67
81
  QuoteEvent = 'quoteEvent',
68
82
  WalletEvent = 'walletEvent',
83
+ UiEvent = 'uiEvent',
69
84
  }
70
85
 
71
86
  export type Events = {
@@ -73,6 +88,7 @@ export type Events = {
73
88
  [WidgetEvents.StepEvent]: StepEventData;
74
89
  [WidgetEvents.QuoteEvent]: QuoteEventData;
75
90
  [WidgetEvents.WalletEvent]: WalletEventData;
91
+ [WidgetEvents.UiEvent]: UiEventData;
76
92
  };
77
93
 
78
94
  declare type EventHandler<T = unknown> = (event: T) => void;
@@ -0,0 +1,27 @@
1
+ import { eventEmitter } from '../services/eventEmitter';
2
+ import { type UiEventData, WidgetEvents } from '../types';
3
+
4
+ type UiEvent = {
5
+ type: UiEventData['type'];
6
+ payload?: Omit<UiEventData['payload'], 'preventDefault'>;
7
+ };
8
+
9
+ export function emitPreventableEvent(event: UiEvent, action: () => void): void {
10
+ let defaultPrevented = false;
11
+
12
+ const extendedPayload = {
13
+ preventDefault() {
14
+ defaultPrevented = true;
15
+ },
16
+ ...(event.payload === undefined && { payload: event.payload }),
17
+ };
18
+
19
+ eventEmitter.emit(WidgetEvents.UiEvent, {
20
+ type: event.type,
21
+ payload: extendedPayload,
22
+ });
23
+
24
+ if (!defaultPrevented) {
25
+ action();
26
+ }
27
+ }
package/src/utils/swap.ts CHANGED
@@ -722,7 +722,7 @@ export function shouldRetrySwap(pendingSwap: PendingSwap) {
722
722
 
723
723
  export function isConfirmSwapDisabled(
724
724
  fetching: boolean,
725
- showCustomDestination: boolean,
725
+ isCustomDestinationOpen: boolean,
726
726
  customDestination: string | null,
727
727
  quote: SelectedQuote | null,
728
728
  selectedWallets: { walletType: string; chain: string }[],
@@ -752,9 +752,9 @@ export function isConfirmSwapDisabled(
752
752
  : false;
753
753
 
754
754
  return (
755
- (!showCustomDestination && !everyWalletSelected) ||
756
- (showCustomDestination && !customDestination) ||
757
- (showCustomDestination &&
755
+ (!isCustomDestinationOpen && !everyWalletSelected) ||
756
+ (isCustomDestinationOpen && !customDestination) ||
757
+ (isCustomDestinationOpen &&
758
758
  !!customDestination &&
759
759
  (!customDestinationIsValid || !everyRequiredWalletSelected))
760
760
  );