@rango-dev/widget-embedded 0.21.1-next.8 → 0.22.0

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 (58) hide show
  1. package/dist/components/ConfirmWalletsModal/ConfirmWalletsModal.d.ts.map +1 -1
  2. package/dist/components/ConfirmWalletsModal/WalletList.d.ts.map +1 -1
  3. package/dist/components/HistoryGroupedList/HistoryGroupedList.d.ts.map +1 -1
  4. package/dist/components/Layout/Layout.d.ts.map +1 -1
  5. package/dist/components/Layout/Layout.styles.d.ts.map +1 -1
  6. package/dist/components/Layout/Layout.types.d.ts +0 -1
  7. package/dist/components/Layout/Layout.types.d.ts.map +1 -1
  8. package/dist/components/Quote/QuoteCostDetails.d.ts.map +1 -1
  9. package/dist/components/QuoteWarningsAndErrors/HighValueLossWarningModal.d.ts.map +1 -1
  10. package/dist/components/QuoteWarningsAndErrors/SlippageWariningModal.d.ts.map +1 -1
  11. package/dist/components/QuoteWarningsAndErrors/UnknownPriceWarningModal.d.ts.map +1 -1
  12. package/dist/components/SwapDetailsModal/SwapDetailsCompleteModal.d.ts.map +1 -1
  13. package/dist/components/SwapDetailsModal/SwapDetailsModal.WalletState.d.ts.map +1 -1
  14. package/dist/components/SwapDetailsModal/SwapDetailsModal.d.ts.map +1 -1
  15. package/dist/components/WalletModal/WalletModal.d.ts.map +1 -1
  16. package/dist/components/common/ActivateTabModal/ActivateTabModal.d.ts.map +1 -1
  17. package/dist/components/common/WatermarkedModal/WatermarkedModal.d.ts +5 -0
  18. package/dist/components/common/WatermarkedModal/WatermarkedModal.d.ts.map +1 -0
  19. package/dist/components/common/WatermarkedModal/index.d.ts +2 -0
  20. package/dist/components/common/WatermarkedModal/index.d.ts.map +1 -0
  21. package/dist/containers/App/App.d.ts.map +1 -1
  22. package/dist/hooks/useFetchApiConfig.d.ts +7 -0
  23. package/dist/hooks/useFetchApiConfig.d.ts.map +1 -0
  24. package/dist/hooks/useWalletList.d.ts +0 -1
  25. package/dist/hooks/useWalletList.d.ts.map +1 -1
  26. package/dist/index.js +2 -2
  27. package/dist/index.js.map +4 -4
  28. package/dist/pages/Home.d.ts.map +1 -1
  29. package/dist/pages/WalletsPage.d.ts.map +1 -1
  30. package/dist/store/ui.d.ts +5 -0
  31. package/dist/store/ui.d.ts.map +1 -1
  32. package/dist/utils/wallets.d.ts +0 -1
  33. package/dist/utils/wallets.d.ts.map +1 -1
  34. package/package.json +3 -3
  35. package/src/components/ConfirmWalletsModal/ConfirmWalletsModal.tsx +7 -5
  36. package/src/components/ConfirmWalletsModal/WalletList.tsx +23 -29
  37. package/src/components/HistoryGroupedList/HistoryGroupedList.tsx +25 -31
  38. package/src/components/Layout/Layout.styles.ts +11 -4
  39. package/src/components/Layout/Layout.tsx +24 -20
  40. package/src/components/Layout/Layout.types.ts +0 -1
  41. package/src/components/Quote/QuoteCostDetails.tsx +3 -3
  42. package/src/components/QuoteWarningsAndErrors/HighValueLossWarningModal.tsx +4 -3
  43. package/src/components/QuoteWarningsAndErrors/SlippageWariningModal.tsx +5 -3
  44. package/src/components/QuoteWarningsAndErrors/UnknownPriceWarningModal.tsx +4 -4
  45. package/src/components/SwapDetailsModal/SwapDetailsCompleteModal.tsx +3 -3
  46. package/src/components/SwapDetailsModal/SwapDetailsModal.WalletState.tsx +3 -29
  47. package/src/components/SwapDetailsModal/SwapDetailsModal.tsx +3 -3
  48. package/src/components/WalletModal/WalletModal.tsx +4 -3
  49. package/src/components/common/ActivateTabModal/ActivateTabModal.tsx +9 -3
  50. package/src/components/common/WatermarkedModal/WatermarkedModal.tsx +18 -0
  51. package/src/components/common/WatermarkedModal/index.ts +1 -0
  52. package/src/containers/App/App.tsx +3 -1
  53. package/src/hooks/useFetchApiConfig.ts +33 -0
  54. package/src/hooks/useWalletList.ts +4 -20
  55. package/src/pages/Home.tsx +0 -1
  56. package/src/pages/WalletsPage.tsx +18 -24
  57. package/src/store/ui.ts +8 -0
  58. package/src/utils/wallets.ts +0 -4
@@ -1,10 +1,10 @@
1
1
  import type { ModalPropTypes } from './SwapDetailsModal.types';
2
2
 
3
- import { Modal } from '@rango-dev/ui';
4
3
  import { PendingSwapNetworkStatus } from 'rango-types';
5
4
  import React from 'react';
6
5
 
7
6
  import { WIDGET_UI_ID } from '../../constants';
7
+ import { WatermarkedModal } from '../common/WatermarkedModal';
8
8
 
9
9
  import { CancelContent } from './SwapDetailsModal.Cancel';
10
10
  import { DeleteContent } from './SwapDetailsModal.Delete';
@@ -28,7 +28,7 @@ export function SwapDetailsModal(props: ModalPropTypes) {
28
28
  state === PendingSwapNetworkStatus.NetworkChanged;
29
29
 
30
30
  return (
31
- <Modal
31
+ <WatermarkedModal
32
32
  open={!!state}
33
33
  onClose={onClose}
34
34
  container={
@@ -52,6 +52,6 @@ export function SwapDetailsModal(props: ModalPropTypes) {
52
52
  {state === 'cancel' && (
53
53
  <CancelContent onClose={onClose} onCancel={onCancel} />
54
54
  )}
55
- </Modal>
55
+ </WatermarkedModal>
56
56
  );
57
57
  }
@@ -1,9 +1,10 @@
1
1
  import type { PropTypes } from './WalletModal.types';
2
2
 
3
- import { Divider, Modal } from '@rango-dev/ui';
3
+ import { Divider } from '@rango-dev/ui';
4
4
  import React from 'react';
5
5
 
6
6
  import { WIDGET_UI_ID } from '../../constants';
7
+ import { WatermarkedModal } from '../common/WatermarkedModal';
7
8
 
8
9
  import { ModalContent } from './WalletModalContent';
9
10
 
@@ -11,7 +12,7 @@ export function WalletModal(props: PropTypes) {
11
12
  const { open, onClose, ...otherProps } = props;
12
13
 
13
14
  return (
14
- <Modal
15
+ <WatermarkedModal
15
16
  open={open}
16
17
  onClose={onClose}
17
18
  container={
@@ -19,6 +20,6 @@ export function WalletModal(props: PropTypes) {
19
20
  }>
20
21
  <ModalContent {...otherProps} />
21
22
  <Divider direction="vertical" size={32} />
22
- </Modal>
23
+ </WatermarkedModal>
23
24
  );
24
25
  }
@@ -1,15 +1,21 @@
1
1
  import type { PropTypes } from './ActivateTabModal.types';
2
2
 
3
3
  import { i18n } from '@lingui/core';
4
- import { Button, Divider, MessageBox, Modal } from '@rango-dev/ui';
4
+ import { Button, Divider, MessageBox } from '@rango-dev/ui';
5
5
  import React from 'react';
6
6
 
7
7
  import { getContainer } from '../../../utils/common';
8
+ import { WatermarkedModal } from '../WatermarkedModal';
8
9
 
9
10
  export function ActivateTabModal(props: PropTypes) {
10
11
  const { open, onClose, onConfirm } = props;
12
+
11
13
  return (
12
- <Modal open={open} dismissible onClose={onClose} container={getContainer()}>
14
+ <WatermarkedModal
15
+ open={open}
16
+ dismissible
17
+ onClose={onClose}
18
+ container={getContainer()}>
13
19
  <MessageBox
14
20
  title={i18n.t('Activate current tab')}
15
21
  type="warning"
@@ -26,6 +32,6 @@ export function ActivateTabModal(props: PropTypes) {
26
32
  {i18n.t('Confirm')}
27
33
  </Button>
28
34
  </MessageBox>
29
- </Modal>
35
+ </WatermarkedModal>
30
36
  );
31
37
  }
@@ -0,0 +1,18 @@
1
+ import type { ModalPropTypes } from '@rango-dev/ui';
2
+ import type { PropsWithChildren } from 'react';
3
+
4
+ import { Modal } from '@rango-dev/ui';
5
+ import React from 'react';
6
+
7
+ import { useUiStore } from '../../../store/ui';
8
+
9
+ export function WatermarkedModal(props: PropsWithChildren<ModalPropTypes>) {
10
+ const { watermark } = useUiStore();
11
+
12
+ const hasWatermark = watermark === 'FULL';
13
+ return (
14
+ <Modal hasWatermark={hasWatermark} {...props}>
15
+ {props.children}
16
+ </Modal>
17
+ );
18
+ }
@@ -0,0 +1 @@
1
+ export { WatermarkedModal } from './WatermarkedModal';
@@ -7,6 +7,7 @@ import { AppRouter } from '../../components/AppRouter';
7
7
  import { AppRoutes } from '../../components/AppRoutes';
8
8
  import { WidgetEvents } from '../../components/WidgetEvents';
9
9
  import { globalFont } from '../../globalStyles';
10
+ import { useFetchApiConfig } from '../../hooks/useFetchApiConfig';
10
11
  import { useLanguage } from '../../hooks/useLanguage';
11
12
  import { useTheme } from '../../hooks/useTheme';
12
13
  import { useAppStore } from '../../store/AppStore';
@@ -25,10 +26,11 @@ export function Main() {
25
26
  useState<string>('');
26
27
  const [disconnectedWallet, setDisconnectedWallet] = useState<WalletType>();
27
28
  const widgetContext = useContext(WidgetContext);
28
-
29
+ const { fetchApiConfig } = useFetchApiConfig();
29
30
  useEffect(() => {
30
31
  void useNotificationStore.persist.rehydrate();
31
32
  widgetContext.onConnectWallet(setLastConnectedWalletWithNetwork);
33
+ void fetchApiConfig().catch(console.log);
32
34
  }, []);
33
35
 
34
36
  return (
@@ -0,0 +1,33 @@
1
+ import { useUiStore } from '../store/ui';
2
+ import { getConfig } from '../utils/configs';
3
+
4
+ export type Watermark = 'NONE' | 'FULL';
5
+
6
+ type ConfigResponse = {
7
+ config: {
8
+ watermark: Watermark;
9
+ };
10
+ };
11
+
12
+ interface UseFetchApiConfig {
13
+ fetchApiConfig: () => Promise<void>;
14
+ }
15
+
16
+ export function useFetchApiConfig(): UseFetchApiConfig {
17
+ const { setWatermark } = useUiStore();
18
+
19
+ const fetchApiConfig: UseFetchApiConfig['fetchApiConfig'] = async () => {
20
+ const response = await fetch(
21
+ `${getConfig('BASE_URL')}/meta/dapp/config?apiKey=${getConfig('API_KEY')}`
22
+ );
23
+
24
+ if (!response.ok) {
25
+ throw new Error(`Request failed with status: ${response.status} `);
26
+ }
27
+
28
+ const data: ConfigResponse = await response.json();
29
+
30
+ setWatermark(data.config.watermark);
31
+ };
32
+ return { fetchApiConfig };
33
+ }
@@ -9,13 +9,12 @@ import {
9
9
  type WalletType,
10
10
  WalletTypes,
11
11
  } from '@rango-dev/wallets-shared';
12
- import { useCallback, useEffect, useRef, useState } from 'react';
12
+ import { useEffect, useState } from 'react';
13
13
 
14
14
  import { useAppStore } from '../store/AppStore';
15
15
  import { useWalletsStore } from '../store/wallets';
16
16
  import { configWalletsToWalletName } from '../utils/providers';
17
17
  import {
18
- hashWalletsState,
19
18
  isExperimentalChain,
20
19
  mapWalletTypesToWalletInfo,
21
20
  sortWalletsBasedOnConnectionState,
@@ -40,7 +39,6 @@ export function useWalletList(params: Params) {
40
39
  const { state, disconnect, getWalletInfo, connect } = useWallets();
41
40
  const { connectedWallets } = useWalletsStore();
42
41
  const blockchains = useAppStore().blockchains();
43
- const componentWillUnmount = useRef(false);
44
42
 
45
43
  /** It can be what has been set by widget config or as a fallback we use all the supported wallets by our library */
46
44
  const listAvailableWalletTypes =
@@ -89,34 +87,21 @@ export function useWalletList(params: Params) {
89
87
  }
90
88
  };
91
89
 
92
- const disconnectConnectingWallets = useCallback(() => {
90
+ const disconnectConnectingWallets = () => {
93
91
  const connectingWallets =
94
92
  wallets?.filter((wallet) => wallet.state === WalletState.CONNECTING) ||
95
93
  [];
96
94
  for (const wallet of connectingWallets) {
97
95
  void disconnect(wallet.type);
98
96
  }
99
- }, [hashWalletsState(wallets)]);
97
+ };
100
98
 
101
- /*
102
- * The order of useEffects is crucial.
103
- * 1- The first useEffect for componentWillUnmount sets its value to true
104
- */
105
99
  useEffect(() => {
106
100
  return () => {
107
- componentWillUnmount.current = true;
101
+ disconnectConnectingWallets();
108
102
  };
109
103
  }, []);
110
104
 
111
- // 2- The second useEffect checks if componentWillUnmount is true then it disconnects connecting wallets
112
- useEffect(() => {
113
- return () => {
114
- if (componentWillUnmount.current) {
115
- disconnectConnectingWallets();
116
- }
117
- };
118
- }, [disconnectConnectingWallets]);
119
-
120
105
  /*
121
106
  * Atm, we only support default injected wallet for the EVM
122
107
  * so we show default wallet when there is no other evm wallet installed
@@ -156,6 +141,5 @@ export function useWalletList(params: Params) {
156
141
  ),
157
142
  error,
158
143
  handleClick,
159
- disconnectConnectingWallets,
160
144
  };
161
145
  }
@@ -125,7 +125,6 @@ export function Home() {
125
125
  return (
126
126
  <Layout
127
127
  height="auto"
128
- hasLogo
129
128
  footer={
130
129
  <Button
131
130
  type="primary"
@@ -35,29 +35,23 @@ export function WalletsPage() {
35
35
  let modalTimerId: ReturnType<typeof setTimeout> | null = null;
36
36
  const isActiveTab = useUiStore.use.isActiveTab();
37
37
 
38
- const { list, handleClick, error, disconnectConnectingWallets } =
39
- useWalletList({
40
- config,
41
- onBeforeConnect: (type) => {
42
- modalTimerId = setTimeout(() => {
43
- setOpenModal(true);
44
- setSelectedWalletType(type);
45
- }, TIME_TO_IGNORE_MODAL);
46
- },
47
- onConnect: () => {
48
- if (modalTimerId) {
49
- clearTimeout(modalTimerId);
50
- }
51
- setTimeout(() => {
52
- setOpenModal(false);
53
- }, TIME_TO_CLOSE_MODAL);
54
- },
55
- });
56
-
57
- const handleCloseWalletModal = () => {
58
- disconnectConnectingWallets();
59
- setOpenModal(false);
60
- };
38
+ const { list, handleClick, error } = useWalletList({
39
+ config,
40
+ onBeforeConnect: (type) => {
41
+ modalTimerId = setTimeout(() => {
42
+ setOpenModal(true);
43
+ setSelectedWalletType(type);
44
+ }, TIME_TO_IGNORE_MODAL);
45
+ },
46
+ onConnect: () => {
47
+ if (modalTimerId) {
48
+ clearTimeout(modalTimerId);
49
+ }
50
+ setTimeout(() => {
51
+ setOpenModal(false);
52
+ }, TIME_TO_CLOSE_MODAL);
53
+ },
54
+ });
61
55
 
62
56
  const selectedWallet = list.find(
63
57
  (wallet) => wallet.type === selectedWalletType
@@ -93,7 +87,7 @@ export function WalletsPage() {
93
87
  })}
94
88
  <WalletModal
95
89
  open={!!openModal}
96
- onClose={handleCloseWalletModal}
90
+ onClose={() => setOpenModal(false)}
97
91
  image={selectedWalletImage}
98
92
  state={selectedWalletState}
99
93
  error={error}
package/src/store/ui.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import type { Watermark } from '../hooks/useFetchApiConfig';
1
2
  import type { TabManagerInterface } from '../libs/tabManager';
2
3
 
3
4
  import { create } from 'zustand';
@@ -10,11 +11,13 @@ interface UiState {
10
11
  isActiveTab: boolean;
11
12
  tabManagerInitiated: boolean;
12
13
  showActivateTabModal: boolean;
14
+ watermark: Watermark;
13
15
  activateCurrentTab: (
14
16
  setCurrentTabAsActive: () => void,
15
17
  hasRunningSwaps: boolean
16
18
  ) => void;
17
19
  setShowActivateTabModal: (flag: boolean) => void;
20
+ setWatermark: (watermark: Watermark) => void;
18
21
  }
19
22
 
20
23
  export const useUiStore = createSelectors(
@@ -22,6 +25,8 @@ export const useUiStore = createSelectors(
22
25
  isActiveTab: false,
23
26
  tabManagerInitiated: false,
24
27
  showActivateTabModal: false,
28
+ watermark: 'NONE',
29
+ fetchingApiConfig: false,
25
30
  activateCurrentTab: (setCurrentTabAsActive, hasRunningSwaps) => {
26
31
  const { showActivateTabModal } = get();
27
32
 
@@ -34,6 +39,9 @@ export const useUiStore = createSelectors(
34
39
  setShowActivateTabModal: (flag) => {
35
40
  set({ showActivateTabModal: flag });
36
41
  },
42
+ setWatermark: (watermark) => {
43
+ set({ watermark });
44
+ },
37
45
  }))
38
46
  );
39
47
 
@@ -551,7 +551,3 @@ export const isFetchingBalance = (
551
551
  !!connectedWallets.find(
552
552
  (wallet) => wallet.chain === blockchain && wallet.loading
553
553
  );
554
-
555
- export function hashWalletsState(walletsInfo: ModalWalletInfo[]) {
556
- return walletsInfo.map((w) => w.state).join('-');
557
- }