@rango-dev/widget-embedded 0.28.2 → 0.28.3-next.1

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 (74) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/dist/components/BlockchainList/BlockchainList.helpers.d.ts +1 -2
  3. package/dist/components/BlockchainList/BlockchainList.helpers.d.ts.map +1 -1
  4. package/dist/components/HeaderButtons/HeaderButtons.d.ts.map +1 -1
  5. package/dist/components/HeaderButtons/NotificationsBadge.d.ts +3 -0
  6. package/dist/components/HeaderButtons/NotificationsBadge.d.ts.map +1 -0
  7. package/dist/components/NotificationContent/NotificationContent.d.ts.map +1 -1
  8. package/dist/components/NotificationContent/NotificationContent.styles.d.ts +769 -0
  9. package/dist/components/NotificationContent/NotificationContent.styles.d.ts.map +1 -1
  10. package/dist/components/SwapDetails/SwapDetails.d.ts.map +1 -1
  11. package/dist/constants/fonts.d.ts +5 -0
  12. package/dist/constants/fonts.d.ts.map +1 -1
  13. package/dist/containers/WidgetProvider/WidgetProvider.d.ts.map +1 -1
  14. package/dist/globalStyles.d.ts.map +1 -1
  15. package/dist/hooks/useBootstrap/useBootstrap.d.ts.map +1 -1
  16. package/dist/hooks/useFontLoader.d.ts +5 -0
  17. package/dist/hooks/useFontLoader.d.ts.map +1 -0
  18. package/dist/hooks/useSyncNotifications/index.d.ts +2 -0
  19. package/dist/hooks/useSyncNotifications/index.d.ts.map +1 -0
  20. package/dist/hooks/useSyncNotifications/useSyncNotifications.d.ts +2 -0
  21. package/dist/hooks/useSyncNotifications/useSyncNotifications.d.ts.map +1 -0
  22. package/dist/hooks/useTheme.d.ts.map +1 -1
  23. package/dist/index.d.ts +2 -1
  24. package/dist/index.d.ts.map +1 -1
  25. package/dist/index.js +2 -2
  26. package/dist/index.js.map +4 -4
  27. package/dist/pages/WalletsPage.d.ts.map +1 -1
  28. package/dist/store/notification.d.ts +27 -7
  29. package/dist/store/notification.d.ts.map +1 -1
  30. package/dist/types/config.d.ts +5 -1
  31. package/dist/types/config.d.ts.map +1 -1
  32. package/dist/types/notification.d.ts +0 -1
  33. package/dist/types/notification.d.ts.map +1 -1
  34. package/dist/utils/common.d.ts +3 -0
  35. package/dist/utils/common.d.ts.map +1 -1
  36. package/dist/utils/configs.d.ts +0 -1
  37. package/dist/utils/configs.d.ts.map +1 -1
  38. package/dist/utils/swap.d.ts +2 -0
  39. package/dist/utils/swap.d.ts.map +1 -1
  40. package/dist/utils/wallets.d.ts +2 -0
  41. package/dist/utils/wallets.d.ts.map +1 -1
  42. package/dist/widget-embedded.build.json +1 -0
  43. package/package.json +9 -8
  44. package/src/components/BlockchainList/BlockchainList.helpers.ts +6 -25
  45. package/src/components/ConfirmWalletsModal/ConfirmWallets.styles.ts +4 -4
  46. package/src/components/HeaderButtons/HeaderButtons.styles.ts +1 -1
  47. package/src/components/HeaderButtons/HeaderButtons.tsx +3 -2
  48. package/src/components/HeaderButtons/{UnreadNotificationsBadge.tsx → NotificationsBadge.tsx} +3 -3
  49. package/src/components/NotificationContent/NotificationContent.styles.ts +17 -2
  50. package/src/components/NotificationContent/NotificationContent.tsx +28 -3
  51. package/src/components/Quote/Quote.styles.ts +1 -1
  52. package/src/components/Slippage/Slippage.tsx +1 -1
  53. package/src/components/SwapDetails/SwapDetails.tsx +5 -6
  54. package/src/constants/fonts.ts +84 -0
  55. package/src/containers/WidgetInfo/WidgetInfo.tsx +1 -1
  56. package/src/containers/WidgetProvider/WidgetProvider.tsx +20 -2
  57. package/src/globalStyles.ts +1 -3
  58. package/src/hooks/useBootstrap/useBootstrap.ts +3 -1
  59. package/src/hooks/useFontLoader.ts +40 -0
  60. package/src/hooks/useSyncNotifications/index.ts +1 -0
  61. package/src/hooks/useSyncNotifications/useSyncNotifications.ts +25 -0
  62. package/src/hooks/useTheme.ts +1 -1
  63. package/src/index.ts +2 -0
  64. package/src/pages/SelectBlockchainPage.tsx +3 -3
  65. package/src/pages/WalletsPage.tsx +34 -2
  66. package/src/store/notification.ts +62 -17
  67. package/src/types/config.ts +6 -1
  68. package/src/types/notification.ts +0 -1
  69. package/src/utils/common.ts +29 -0
  70. package/src/utils/configs.ts +0 -1
  71. package/src/utils/swap.ts +12 -0
  72. package/src/utils/wallets.ts +53 -2
  73. package/dist/components/HeaderButtons/UnreadNotificationsBadge.d.ts +0 -3
  74. package/dist/components/HeaderButtons/UnreadNotificationsBadge.d.ts.map +0 -1
@@ -1,7 +1,15 @@
1
1
  import type { Namespace, WalletType } from '@rango-dev/wallets-shared';
2
2
 
3
3
  import { i18n } from '@lingui/core';
4
- import { styled, Typography, Wallet, WalletState } from '@rango-dev/ui';
4
+ import {
5
+ Divider,
6
+ getCategoriesCount,
7
+ SelectableCategoryList,
8
+ styled,
9
+ Typography,
10
+ Wallet,
11
+ WalletState,
12
+ } from '@rango-dev/ui';
5
13
  import React, { useState } from 'react';
6
14
 
7
15
  import { Layout, PageContainer } from '../components/Layout';
@@ -11,6 +19,10 @@ import { useWalletList } from '../hooks/useWalletList';
11
19
  import { useAppStore } from '../store/AppStore';
12
20
  import { useUiStore } from '../store/ui';
13
21
  import { getContainer } from '../utils/common';
22
+ import {
23
+ filterBlockchainsByWalletTypes,
24
+ filterWalletsByCategory,
25
+ } from '../utils/wallets';
14
26
 
15
27
  interface NamespacesModalState {
16
28
  providerType: string;
@@ -37,6 +49,9 @@ export const TIME_TO_IGNORE_MODAL = 300;
37
49
 
38
50
  export function WalletsPage() {
39
51
  const { fetchStatus: fetchMetaStatus } = useAppStore();
52
+ const [blockchainCategory, setBlockchainCategory] = useState<string>('ALL');
53
+ const blockchains = useAppStore().blockchains();
54
+
40
55
  const [openModal, setOpenModal] = useState(false);
41
56
  const [namespacesModalState, setNamespacesModalState] =
42
57
  useState<NamespacesModalState | null>(null);
@@ -74,17 +89,34 @@ export function WalletsPage() {
74
89
  const selectedWalletState =
75
90
  selectedWallet?.state || WalletState.NOT_INSTALLED;
76
91
 
92
+ const filteredBlockchains = filterBlockchainsByWalletTypes(list, blockchains);
93
+ const activeCategoriesCount = getCategoriesCount(filteredBlockchains);
94
+ const showCategory = activeCategoriesCount !== 1;
95
+
96
+ const filteredWallets = filterWalletsByCategory(list, blockchainCategory);
97
+
77
98
  return (
78
99
  <Layout
79
100
  header={{
80
101
  title: i18n.t('Connect Wallets'),
81
102
  }}>
82
103
  <Container>
104
+ {showCategory && (
105
+ <>
106
+ <SelectableCategoryList
107
+ setCategory={setBlockchainCategory}
108
+ category={blockchainCategory}
109
+ blockchains={filteredBlockchains}
110
+ isLoading={fetchMetaStatus === 'loading'}
111
+ />
112
+ <Divider size={24} />
113
+ </>
114
+ )}
83
115
  <Typography variant="title" size="xmedium" align="center">
84
116
  {i18n.t('Choose a wallet to connect.')}
85
117
  </Typography>
86
118
  <ListContainer>
87
- {list.map((wallet, index) => {
119
+ {filteredWallets.map((wallet, index) => {
88
120
  const key = `wallet-${index}-${wallet.type}`;
89
121
  return (
90
122
  <Wallet
@@ -1,26 +1,31 @@
1
1
  import type { Notification } from '../types/notification';
2
- import type {
3
- Route,
4
- RouteEvent,
5
- StepEvent,
6
- } from '@rango-dev/queue-manager-rango-preset';
7
2
 
3
+ import {
4
+ type PendingSwapWithQueueID,
5
+ type Route,
6
+ type RouteEvent,
7
+ type StepEvent,
8
+ } from '@rango-dev/queue-manager-rango-preset';
8
9
  import { create } from 'zustand';
9
10
  import { persist, subscribeWithSelector } from 'zustand/middleware';
10
11
 
11
12
  import createSelectors from './selectors';
12
13
 
13
14
  export interface NotificationState {
15
+ isSynced: boolean;
14
16
  notifications: Notification[];
15
17
  setNotification: (event: RouteEvent | StepEvent, route: Route) => void;
16
- setAsRead: (requestId: Notification['requestId']) => void;
17
- getUnreadNotifications: () => Notification[];
18
+ removeNotification: (requestId: Notification['requestId']) => void;
19
+ getNotifications: () => Notification[];
20
+ syncNotifications: (swaps: PendingSwapWithQueueID[]) => void;
21
+ clearNotifications: () => void;
18
22
  }
19
23
 
20
24
  export const useNotificationStore = createSelectors(
21
25
  create<NotificationState>()(
22
26
  persist(
23
27
  subscribeWithSelector((set, get) => ({
28
+ isSynced: false,
24
29
  notifications: [],
25
30
  setNotification: (event, route) => {
26
31
  const fromStep = route.steps[0];
@@ -29,7 +34,6 @@ export const useNotificationStore = createSelectors(
29
34
  const notification: Notification = {
30
35
  event,
31
36
  creationTime: Date.now(),
32
- read: false,
33
37
  requestId: route.requestId,
34
38
  route: {
35
39
  from: {
@@ -53,24 +57,65 @@ export const useNotificationStore = createSelectors(
53
57
  notifications: [...excludedList, notification],
54
58
  }));
55
59
  },
56
- setAsRead: (requestId) => {
60
+ removeNotification: (requestId) => {
57
61
  set((state) => ({
58
- notifications: state.notifications.map((notificationItem) =>
59
- notificationItem.requestId === requestId
60
- ? { ...notificationItem, read: true }
61
- : notificationItem
62
+ notifications: state.notifications.filter(
63
+ (notification) => notification.requestId !== requestId
62
64
  ),
63
65
  }));
64
66
  },
65
- getUnreadNotifications: () => {
66
- return get().notifications.filter(
67
- (notificationItem) => !notificationItem.read
68
- );
67
+ getNotifications: () => {
68
+ const { isSynced, notifications } = get();
69
+ return isSynced ? notifications : [];
70
+ },
71
+ syncNotifications: (swaps) => {
72
+ const { isSynced, notifications } = get();
73
+
74
+ if (!isSynced) {
75
+ const nextNotifications: Notification[] = [];
76
+ notifications.forEach((notification) => {
77
+ const swapExist = swaps.some(
78
+ (swap) => swap.swap.requestId === notification.requestId
79
+ );
80
+ if (swapExist) {
81
+ nextNotifications.push(notification);
82
+ }
83
+ });
84
+
85
+ set({ isSynced: true, notifications: nextNotifications });
86
+ }
69
87
  },
88
+ clearNotifications: () => set({ notifications: [] }),
70
89
  })),
90
+
71
91
  {
72
92
  name: 'notification',
73
93
  skipHydration: true,
94
+ partialize: ({ isSynced, ...otherProps }) => otherProps,
95
+ version: 1,
96
+ migrate: (persistedState, version) => {
97
+ if (version === 0) {
98
+ /**
99
+ * Eliminate the persistence of read notifications,
100
+ * and remove the "read" flag from other notifications to align with the current modifications in the notification store structure.
101
+ */
102
+ const oldNotifications = (
103
+ persistedState as {
104
+ notifications: (Notification & { read: boolean })[];
105
+ }
106
+ ).notifications;
107
+
108
+ (persistedState as NotificationState).notifications =
109
+ oldNotifications
110
+ .filter(
111
+ (notification: Notification & { read: boolean }) =>
112
+ !notification.read
113
+ )
114
+ .map(({ read, ...otherProps }) => otherProps);
115
+ }
116
+
117
+ return persistedState as NotificationState;
118
+ },
74
119
  }
75
120
  )
76
121
  )
@@ -28,7 +28,7 @@ export type WidgetColors = {
28
28
  * radius, width, and height.
29
29
  * @property {'auto' | 'light' | 'dark'} mode - The mode property is used to specify the default theme for
30
30
  * the widget.
31
- * @property {string} fontFamily - The font family to be used in the widget.
31
+ * @property {string} fontFamily - The font family to be used in the widget. If you want to do this, include the font of your choice in your HTML file.
32
32
  * @property {{ light?: WidgetColors; dark?: WidgetColors }} colors - The `colors` property is a sub-property of the `WidgetTheme` object that
33
33
  * defines the color scheme for the widget. It is of type `Colors`, which is likely another object that
34
34
  * contains specific color values for various parts of the widget (e.g. background color, text color,
@@ -103,6 +103,10 @@ export type BlockchainAndTokenConfig = {
103
103
  tokens?: Asset[] | { [blockchain: string]: Tokens };
104
104
  };
105
105
 
106
+ export type SignersConfig = {
107
+ customSolanaRPC?: string;
108
+ };
109
+
106
110
  /**
107
111
  * `Features`
108
112
  *
@@ -209,4 +213,5 @@ export type WidgetConfig = {
209
213
  features?: Features;
210
214
  variant?: WidgetVariant;
211
215
  enableCentralizedSwappers?: boolean;
216
+ signers?: SignersConfig;
212
217
  };
@@ -21,6 +21,5 @@ type NotificationRoute = {
21
21
  export type Notification = Pick<Route, 'requestId'> & {
22
22
  event: RouteEvent | StepEvent;
23
23
  creationTime: number;
24
- read: boolean;
25
24
  route: NotificationRoute;
26
25
  };
@@ -1,6 +1,10 @@
1
1
  import type { Token } from 'rango-sdk';
2
2
 
3
+ import { BlockchainCategories } from '@rango-dev/ui';
4
+ import { TransactionType } from 'rango-sdk';
5
+
3
6
  import { WIDGET_UI_ID } from '../constants';
7
+ import { SUPPORTED_FONTS } from '../constants/fonts';
4
8
  import {
5
9
  MIN_LENGTH_SYMBOL_CONTAINS,
6
10
  MIN_LENGTH_SYMBOL_START_WITH,
@@ -218,3 +222,28 @@ export function compareWithSearchFor(
218
222
 
219
223
  return 0;
220
224
  }
225
+
226
+ export const isBlockchainTypeInCategory = (
227
+ blockchainType: TransactionType,
228
+ category: string
229
+ ): boolean => {
230
+ switch (category) {
231
+ case BlockchainCategories.ALL:
232
+ return true;
233
+ case BlockchainCategories.UTXO:
234
+ return blockchainType === TransactionType.TRANSFER;
235
+ case BlockchainCategories.OTHER:
236
+ return (
237
+ blockchainType !== TransactionType.TRANSFER &&
238
+ blockchainType !== TransactionType.COSMOS &&
239
+ blockchainType !== TransactionType.EVM
240
+ );
241
+ default:
242
+ return blockchainType === category;
243
+ }
244
+ };
245
+
246
+ export const getFontUrlByName = (fontName: string) => {
247
+ const font = SUPPORTED_FONTS.find((font) => font.value === fontName);
248
+ return font?.url;
249
+ };
@@ -46,7 +46,6 @@ export function initConfig(nextConfigs: Configs) {
46
46
 
47
47
  export const DEFAULT_PRIMARY_RADIUS = 20;
48
48
  export const DEFAULT_SECONDARY_RADIUS = 25;
49
- export const DEFAULT_FONT_FAMILY = 'Roboto';
50
49
 
51
50
  export const THEME_CLASS_NAME_PREFIX = `theme-widget`;
52
51
 
package/src/utils/swap.ts CHANGED
@@ -23,6 +23,11 @@ import type {
23
23
  import type { PendingSwap, PendingSwapStep } from 'rango-types';
24
24
 
25
25
  import { i18n } from '@lingui/core';
26
+ import {
27
+ type RouteEvent,
28
+ RouteEventType,
29
+ type StepEvent,
30
+ } from '@rango-dev/queue-manager-rango-preset';
26
31
  import BigNumber from 'bignumber.js';
27
32
  import { PendingSwapNetworkStatus } from 'rango-types';
28
33
 
@@ -782,3 +787,10 @@ export function isTokensIdentical(tokenA: Token, tokenB: Token) {
782
787
  tokenA.address === tokenB.address
783
788
  );
784
789
  }
790
+
791
+ export function isSwapFinished(event: RouteEvent | StepEvent) {
792
+ return (
793
+ event.type === RouteEventType.FAILED ||
794
+ event.type === RouteEventType.SUCCEEDED
795
+ );
796
+ }
@@ -16,9 +16,17 @@ import type {
16
16
  WalletType,
17
17
  WalletTypes,
18
18
  } from '@rango-dev/wallets-shared';
19
- import type { BlockchainMeta, Token, WalletDetail } from 'rango-sdk';
19
+ import type {
20
+ BlockchainMeta,
21
+ Token,
22
+ TransactionType,
23
+ WalletDetail,
24
+ } from 'rango-sdk';
20
25
 
21
- import { WalletState as WalletStatus } from '@rango-dev/ui';
26
+ import {
27
+ BlockchainCategories,
28
+ WalletState as WalletStatus,
29
+ } from '@rango-dev/ui';
22
30
  import { readAccountAddress } from '@rango-dev/wallets-react';
23
31
  import {
24
32
  detectInstallLink,
@@ -39,6 +47,7 @@ import {
39
47
  } from '../constants/routing';
40
48
  import { EXCLUDED_WALLETS } from '../constants/wallets';
41
49
 
50
+ import { isBlockchainTypeInCategory, removeDuplicateFrom } from './common';
42
51
  import { numberToString } from './numbers';
43
52
 
44
53
  export function mapStatusToWalletState(state: WalletState): WalletStatus {
@@ -64,6 +73,7 @@ export function mapWalletTypesToWalletInfo(
64
73
  .filter((wallet) => !EXCLUDED_WALLETS.includes(wallet as WalletTypes))
65
74
  .filter((wallet) => {
66
75
  const { supportedChains, isContractWallet } = getWalletInfo(wallet);
76
+
67
77
  const { installed, network } = getState(wallet);
68
78
  const filterContractWallets =
69
79
  isContractWallet && (!installed || (!!chain && network !== chain));
@@ -85,7 +95,12 @@ export function mapWalletTypesToWalletInfo(
85
95
  showOnMobile,
86
96
  namespaces,
87
97
  singleNamespace,
98
+ supportedChains,
88
99
  } = getWalletInfo(type);
100
+ const blockchainTypes = removeDuplicateFrom(
101
+ supportedChains.map((item) => item.type)
102
+ );
103
+
89
104
  const state = mapStatusToWalletState(getState(type));
90
105
  return {
91
106
  title: name,
@@ -96,6 +111,7 @@ export function mapWalletTypesToWalletInfo(
96
111
  showOnMobile,
97
112
  namespaces,
98
113
  singleNamespace,
114
+ blockchainTypes,
99
115
  };
100
116
  });
101
117
  }
@@ -538,3 +554,38 @@ export const isFetchingBalance = (
538
554
  export function hashWalletsState(walletsInfo: ModalWalletInfo[]) {
539
555
  return walletsInfo.map((w) => w.state).join('-');
540
556
  }
557
+
558
+ export function filterBlockchainsByWalletTypes(
559
+ wallets: ModalWalletInfo[],
560
+ blockchains: BlockchainMeta[]
561
+ ) {
562
+ const uniqueBlockchainTypes = new Set<TransactionType>();
563
+ wallets.forEach((wallet) => {
564
+ wallet.blockchainTypes.forEach((type) => {
565
+ uniqueBlockchainTypes.add(type);
566
+ });
567
+ });
568
+ const filteredBlockchains = blockchains.filter((blockchain) =>
569
+ uniqueBlockchainTypes.has(blockchain.type)
570
+ );
571
+
572
+ return filteredBlockchains;
573
+ }
574
+
575
+ export function filterWalletsByCategory(
576
+ wallets: WalletInfoWithNamespaces[],
577
+ category: string
578
+ ) {
579
+ if (category === BlockchainCategories.ALL) {
580
+ return wallets;
581
+ }
582
+
583
+ return wallets.filter((wallet) => {
584
+ for (const type of wallet.blockchainTypes) {
585
+ if (isBlockchainTypeInCategory(type, category)) {
586
+ return true;
587
+ }
588
+ }
589
+ return false;
590
+ });
591
+ }
@@ -1,3 +0,0 @@
1
- import React from 'react';
2
- export declare function UnreadNotificationsBadge(): React.JSX.Element | null;
3
- //# sourceMappingURL=UnreadNotificationsBadge.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"UnreadNotificationsBadge.d.ts","sourceRoot":"","sources":["../../../src/components/HeaderButtons/UnreadNotificationsBadge.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,MAAM,OAAO,CAAC;AAM1B,wBAAgB,wBAAwB,6BAmBvC"}