@rango-dev/widget-embedded 0.30.1-next.4 → 0.30.1-next.6
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/index.d.ts +4 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +4 -4
- package/dist/pages/Home.d.ts.map +1 -1
- package/dist/store/notification.d.ts.map +1 -1
- package/dist/types/event.d.ts +21 -15
- package/dist/types/event.d.ts.map +1 -1
- package/dist/types/notification.d.ts +1 -0
- package/dist/types/notification.d.ts.map +1 -1
- package/dist/utils/events.d.ts +8 -0
- package/dist/utils/events.d.ts.map +1 -0
- package/dist/widget-embedded.build.json +1 -1
- package/package.json +1 -1
- package/src/index.ts +4 -0
- package/src/pages/Home.tsx +6 -3
- package/src/store/notification.ts +13 -1
- package/src/types/event.ts +32 -16
- package/src/types/notification.ts +1 -0
- package/src/utils/events.ts +27 -0
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -4,6 +4,7 @@ import type {
|
|
|
4
4
|
BlockchainAndTokenConfig,
|
|
5
5
|
QuoteEventData,
|
|
6
6
|
Tokens,
|
|
7
|
+
UiEventData,
|
|
7
8
|
WalletEventData,
|
|
8
9
|
WalletInfoWithExtra,
|
|
9
10
|
WidgetColors,
|
|
@@ -71,6 +72,7 @@ import { widgetEventEmitter } from './services/eventEmitter';
|
|
|
71
72
|
import {
|
|
72
73
|
WidgetEvents as MainEvents,
|
|
73
74
|
QuoteEventTypes,
|
|
75
|
+
UiEventTypes,
|
|
74
76
|
WalletEventTypes,
|
|
75
77
|
WidgetEvents,
|
|
76
78
|
} from './types';
|
|
@@ -108,6 +110,7 @@ export type {
|
|
|
108
110
|
WidgetVariant,
|
|
109
111
|
WalletEventData,
|
|
110
112
|
QuoteEventData,
|
|
113
|
+
UiEventData,
|
|
111
114
|
WalletInfoWithExtra,
|
|
112
115
|
};
|
|
113
116
|
export {
|
|
@@ -133,6 +136,7 @@ export {
|
|
|
133
136
|
MainEvents,
|
|
134
137
|
QuoteEventTypes,
|
|
135
138
|
WalletEventTypes,
|
|
139
|
+
UiEventTypes,
|
|
136
140
|
RouteEventType,
|
|
137
141
|
StepEventType,
|
|
138
142
|
StepExecutionEventStatus,
|
package/src/pages/Home.tsx
CHANGED
|
@@ -19,7 +19,9 @@ import { useAppStore } from '../store/AppStore';
|
|
|
19
19
|
import { useQuoteStore } from '../store/quote';
|
|
20
20
|
import { useUiStore } from '../store/ui';
|
|
21
21
|
import { useWalletsStore } from '../store/wallets';
|
|
22
|
+
import { UiEventTypes } from '../types';
|
|
22
23
|
import { isVariantExpandable } from '../utils/configs';
|
|
24
|
+
import { emitPreventableEvent } from '../utils/events';
|
|
23
25
|
import { getSwapButtonState, isTokensIdentical } from '../utils/swap';
|
|
24
26
|
|
|
25
27
|
const MainContainer = styled('div', {
|
|
@@ -115,14 +117,12 @@ export function Home() {
|
|
|
115
117
|
navigate(route);
|
|
116
118
|
}
|
|
117
119
|
};
|
|
118
|
-
|
|
119
120
|
const onClickOnQuote = (quote: SelectedQuote) => {
|
|
120
121
|
if (selectedQuote?.requestId !== quote.requestId) {
|
|
121
122
|
setShowQuoteWarningModal(false);
|
|
122
123
|
setSelectedQuote(quote);
|
|
123
124
|
}
|
|
124
125
|
};
|
|
125
|
-
|
|
126
126
|
return (
|
|
127
127
|
<MainContainer>
|
|
128
128
|
<Layout
|
|
@@ -138,7 +138,10 @@ export function Home() {
|
|
|
138
138
|
fullWidth
|
|
139
139
|
onClick={() => {
|
|
140
140
|
if (swapButtonState.action === 'connect-wallet') {
|
|
141
|
-
|
|
141
|
+
emitPreventableEvent(
|
|
142
|
+
{ type: UiEventTypes.CLICK_CONNECT_WALLET },
|
|
143
|
+
() => onHandleNavigation(navigationRoutes.wallets)
|
|
144
|
+
);
|
|
142
145
|
} else if (swapButtonState.action === 'confirm-warning') {
|
|
143
146
|
setShowQuoteWarningModal(true);
|
|
144
147
|
} else {
|
|
@@ -36,6 +36,7 @@ export const useNotificationStore = createSelectors(
|
|
|
36
36
|
creationTime: Date.now(),
|
|
37
37
|
requestId: route.requestId,
|
|
38
38
|
route: {
|
|
39
|
+
creationTime: parseInt(route.creationTime),
|
|
39
40
|
from: {
|
|
40
41
|
blockchain: fromStep.fromBlockchain,
|
|
41
42
|
address: fromStep.fromSymbolAddress,
|
|
@@ -67,7 +68,18 @@ export const useNotificationStore = createSelectors(
|
|
|
67
68
|
getNotifications: () => {
|
|
68
69
|
const { isSynced, notifications } = get();
|
|
69
70
|
return isSynced
|
|
70
|
-
? notifications.sort((a, b) =>
|
|
71
|
+
? notifications.sort((a, b) => {
|
|
72
|
+
if (a.route.creationTime && !b.route.creationTime) {
|
|
73
|
+
return -1;
|
|
74
|
+
}
|
|
75
|
+
if (!a.route.creationTime && b.route.creationTime) {
|
|
76
|
+
return 1;
|
|
77
|
+
}
|
|
78
|
+
if (!a.route.creationTime && !b.route.creationTime) {
|
|
79
|
+
return b.creationTime - a.creationTime;
|
|
80
|
+
}
|
|
81
|
+
return b.route.creationTime - a.route.creationTime;
|
|
82
|
+
})
|
|
71
83
|
: [];
|
|
72
84
|
},
|
|
73
85
|
syncNotifications: (swaps) => {
|
package/src/types/event.ts
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
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
|
+
}
|