@rango-dev/widget-embedded 0.12.1-next.13 → 0.12.1-next.14

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rango-dev/widget-embedded",
3
- "version": "0.12.1-next.13",
3
+ "version": "0.12.1-next.14",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -6,8 +6,7 @@ import { useNotificationStore } from '../../store/notification';
6
6
  import { NotificationsBadgeContainer } from './HeaderButtons.styles';
7
7
 
8
8
  export function UnreadNotificationsBadge() {
9
- const getUnreadNotifications =
10
- useNotificationStore.use.getUnreadNotifications();
9
+ const { getUnreadNotifications } = useNotificationStore();
11
10
 
12
11
  const notificationsCount = getUnreadNotifications().length;
13
12
 
@@ -22,20 +22,15 @@ export function NotificationContent() {
22
22
  const navigate = useNavigate();
23
23
  const setSelectedSwap = useUiStore.use.setSelectedSwap();
24
24
 
25
- const getUnreadNotifications =
26
- useNotificationStore.use.getUnreadNotifications();
25
+ const { getUnreadNotifications } = useNotificationStore();
27
26
 
28
27
  const notifications: Notification[] = getUnreadNotifications();
29
-
30
- const setAsRead = useNotificationStore.use.setAsRead();
31
-
32
28
  const { tokens, blockchains } = useMetaStore.use.meta();
33
29
  const sortedNotification = notifications
34
30
  .sort((a, b) => b.creationTime - a.creationTime)
35
31
  .slice(0, MAX_NOTIFICATIONS_DISPLAYED);
36
32
 
37
33
  const handleOnClick = (requestId: Notification['requestId']) => {
38
- setAsRead(requestId);
39
34
  setSelectedSwap(requestId);
40
35
  navigate(`/swaps/${requestId}`);
41
36
  };
@@ -39,6 +39,7 @@ import {
39
39
  import { useNavigateBack } from '../../hooks/useNavigateBack';
40
40
  import { useBestRouteStore } from '../../store/bestRoute';
41
41
  import { useMetaStore } from '../../store/meta';
42
+ import { useNotificationStore } from '../../store/notification';
42
43
  import { numberToString } from '../../utils/numbers';
43
44
  import { getPriceImpactLevel } from '../../utils/routing';
44
45
  import {
@@ -90,12 +91,22 @@ export function SwapDetails(props: SwapDetailsProps) {
90
91
  setModalState(null);
91
92
  };
92
93
 
94
+ const getUnreadNotifications =
95
+ useNotificationStore.use.getUnreadNotifications();
96
+ const setAsRead = useNotificationStore.use.setAsRead();
97
+ const unreadNotifications = getUnreadNotifications();
93
98
  const currentStep = getCurrentStep(swap);
94
99
  const currentStepNetworkStatus = currentStep?.networkStatus;
95
100
 
96
101
  useEffect(() => {
97
- if (swap.status === 'success' || swap.status === 'failed') {
98
- setShowCompletedModal(swap.status);
102
+ const existNotification = unreadNotifications.find(
103
+ (n) => n.requestId === swap.requestId
104
+ );
105
+ if (existNotification) {
106
+ if (swap.status === 'success' || swap.status === 'failed') {
107
+ setShowCompletedModal(swap.status);
108
+ setAsRead(swap.requestId);
109
+ }
99
110
  }
100
111
  }, [swap.status]);
101
112
 
@@ -207,7 +218,7 @@ export function SwapDetails(props: SwapDetailsProps) {
207
218
  const percentageChange = getPercentageChange(inputUsdValue, outputUsdValue);
208
219
 
209
220
  const completeModalDesc =
210
- showCompletedModal === 'success'
221
+ swap.status === 'success'
211
222
  ? `You have received ${numberToString(
212
223
  outputAmount,
213
224
  TOKEN_AMOUNT_MIN_DECIMALS,
@@ -389,7 +400,7 @@ export function SwapDetails(props: SwapDetailsProps) {
389
400
  open={!!showCompletedModal}
390
401
  diagnosisUrl={diagnosisUrl}
391
402
  onClose={() => setShowCompletedModal(null)}
392
- status={showCompletedModal}
403
+ status={swap.status === 'success' ? 'success' : 'failed'}
393
404
  priceValue={numberToString(
394
405
  outputAmount,
395
406
  TOKEN_AMOUNT_MIN_DECIMALS,
@@ -22,7 +22,7 @@ export interface ModalPropTypes {
22
22
  export interface CompleteModalPropTypes {
23
23
  open: boolean;
24
24
  onClose: () => void;
25
- status: 'success' | 'failed' | null;
25
+ status: 'success' | 'failed';
26
26
  priceValue: string;
27
27
  usdValue: string;
28
28
  percentageChange: string;
@@ -16,7 +16,7 @@ export function WidgetEvents() {
16
16
  const connectedWallets = useWalletsStore.use.connectedWallets();
17
17
  const getWalletsDetails = useWalletsStore.use.getWalletsDetails();
18
18
  const setNotification = useNotificationStore.use.setNotification();
19
-
19
+ const setAsRead = useNotificationStore.use.setAsRead();
20
20
  const widgetEvents = useEvents();
21
21
 
22
22
  useEffect(() => {
@@ -42,10 +42,16 @@ export function WidgetEvents() {
42
42
  toAccount && getWalletsDetails([toAccount]);
43
43
  }
44
44
  if (
45
- event.type === StepEventType.TX_EXECUTION_BLOCKED &&
46
- validBlockedStatuses.includes(event.status)
45
+ (event.type === StepEventType.TX_EXECUTION_BLOCKED &&
46
+ validBlockedStatuses.includes(event.status)) ||
47
+ event.type === StepEventType.FAILED
47
48
  ) {
48
49
  setNotification(event, route);
50
+ } else if (
51
+ event.type === StepEventType.TX_EXECUTION ||
52
+ event.type === StepEventType.CHECK_STATUS
53
+ ) {
54
+ setAsRead(route.requestId);
49
55
  }
50
56
  });
51
57