@rango-dev/widget-embedded 0.45.1-next.3 → 0.45.1-next.4

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 (83) hide show
  1. package/dist/components/NamespaceItem/NamespaceItem.d.ts +4 -0
  2. package/dist/components/NamespaceItem/NamespaceItem.d.ts.map +1 -0
  3. package/dist/components/{WalletStatefulConnect/Namespaces.helpers.d.ts → NamespaceItem/NamespaceItem.helpers.d.ts} +1 -1
  4. package/dist/components/NamespaceItem/NamespaceItem.helpers.d.ts.map +1 -0
  5. package/dist/components/NamespaceItem/NamespaceItem.styles.d.ts +1450 -0
  6. package/dist/components/NamespaceItem/NamespaceItem.styles.d.ts.map +1 -0
  7. package/dist/components/NamespaceItem/NamespaceItem.types.d.ts +13 -0
  8. package/dist/components/NamespaceItem/NamespaceItem.types.d.ts.map +1 -0
  9. package/dist/components/{WalletStatefulConnect → NamespaceItem}/NamespaceUnsupportedItem.d.ts +1 -1
  10. package/dist/components/NamespaceItem/NamespaceUnsupportedItem.d.ts.map +1 -0
  11. package/dist/components/NamespaceItem/SupportedChainsList.d.ts.map +1 -0
  12. package/dist/components/NamespaceItem/SupportedChainsList.styles.d.ts.map +1 -0
  13. package/dist/components/NamespaceItem/SupportedChainsList.types.d.ts.map +1 -0
  14. package/dist/components/NamespaceItem/index.d.ts +2 -0
  15. package/dist/components/NamespaceItem/index.d.ts.map +1 -0
  16. package/dist/components/SwapDetails/RequestIdRow.d.ts +4 -0
  17. package/dist/components/SwapDetails/RequestIdRow.d.ts.map +1 -0
  18. package/dist/components/SwapDetails/SwapDateRow.d.ts +4 -0
  19. package/dist/components/SwapDetails/SwapDateRow.d.ts.map +1 -0
  20. package/dist/components/SwapDetails/SwapDetails.d.ts.map +1 -1
  21. package/dist/components/SwapDetails/SwapDetails.types.d.ts +7 -0
  22. package/dist/components/SwapDetails/SwapDetails.types.d.ts.map +1 -1
  23. package/dist/components/SwapDetailsModal/SwapDetailsModal.ConnectWallet.d.ts +4 -0
  24. package/dist/components/SwapDetailsModal/SwapDetailsModal.ConnectWallet.d.ts.map +1 -0
  25. package/dist/components/SwapDetailsModal/SwapDetailsModal.InstallWallet.d.ts +4 -0
  26. package/dist/components/SwapDetailsModal/SwapDetailsModal.InstallWallet.d.ts.map +1 -0
  27. package/dist/components/SwapDetailsModal/SwapDetailsModal.NetworkState.d.ts +4 -0
  28. package/dist/components/SwapDetailsModal/SwapDetailsModal.NetworkState.d.ts.map +1 -0
  29. package/dist/components/SwapDetailsModal/SwapDetailsModal.WalletState.d.ts +1 -1
  30. package/dist/components/SwapDetailsModal/SwapDetailsModal.WalletState.d.ts.map +1 -1
  31. package/dist/components/SwapDetailsModal/SwapDetailsModal.d.ts.map +1 -1
  32. package/dist/components/SwapDetailsModal/SwapDetailsModal.styles.d.ts +320 -0
  33. package/dist/components/SwapDetailsModal/SwapDetailsModal.styles.d.ts.map +1 -1
  34. package/dist/components/SwapDetailsModal/SwapDetailsModal.types.d.ts +29 -10
  35. package/dist/components/SwapDetailsModal/SwapDetailsModal.types.d.ts.map +1 -1
  36. package/dist/components/WalletStatefulConnect/Detached.d.ts.map +1 -1
  37. package/dist/components/WalletStatefulConnect/NamespaceDetachedItem.d.ts.map +1 -1
  38. package/dist/components/WalletStatefulConnect/NamespaceListItem.d.ts.map +1 -1
  39. package/dist/components/WalletStatefulConnect/Namespaces.styles.d.ts +281 -1730
  40. package/dist/components/WalletStatefulConnect/Namespaces.styles.d.ts.map +1 -1
  41. package/dist/components/WalletStatefulConnect/Namespaces.types.d.ts +0 -3
  42. package/dist/components/WalletStatefulConnect/Namespaces.types.d.ts.map +1 -1
  43. package/dist/index.js +2 -2
  44. package/dist/index.js.map +4 -4
  45. package/dist/widget-embedded.build.json +1 -1
  46. package/package.json +2 -2
  47. package/src/components/{WalletStatefulConnect/Namespaces.helpers.ts → NamespaceItem/NamespaceItem.helpers.ts} +1 -1
  48. package/src/components/NamespaceItem/NamespaceItem.styles.ts +93 -0
  49. package/src/components/NamespaceItem/NamespaceItem.tsx +117 -0
  50. package/src/components/NamespaceItem/NamespaceItem.types.ts +14 -0
  51. package/src/components/{WalletStatefulConnect → NamespaceItem}/NamespaceUnsupportedItem.tsx +3 -3
  52. package/src/components/NamespaceItem/index.ts +1 -0
  53. package/src/components/SwapDetails/RequestIdRow.tsx +73 -0
  54. package/src/components/SwapDetails/SwapDateRow.tsx +21 -0
  55. package/src/components/SwapDetails/SwapDetails.tsx +39 -83
  56. package/src/components/SwapDetails/SwapDetails.types.ts +7 -0
  57. package/src/components/SwapDetailsModal/SwapDetailsModal.ConnectWallet.tsx +177 -0
  58. package/src/components/SwapDetailsModal/SwapDetailsModal.InstallWallet.tsx +52 -0
  59. package/src/components/SwapDetailsModal/SwapDetailsModal.NetworkState.tsx +17 -0
  60. package/src/components/SwapDetailsModal/SwapDetailsModal.WalletState.tsx +22 -62
  61. package/src/components/SwapDetailsModal/SwapDetailsModal.styles.ts +20 -1
  62. package/src/components/SwapDetailsModal/SwapDetailsModal.tsx +24 -35
  63. package/src/components/SwapDetailsModal/SwapDetailsModal.types.ts +31 -10
  64. package/src/components/WalletStatefulConnect/Detached.tsx +2 -1
  65. package/src/components/WalletStatefulConnect/NamespaceDetachedItem.tsx +19 -105
  66. package/src/components/WalletStatefulConnect/NamespaceListItem.tsx +9 -34
  67. package/src/components/WalletStatefulConnect/Namespaces.styles.ts +1 -93
  68. package/src/components/WalletStatefulConnect/Namespaces.tsx +1 -1
  69. package/src/components/WalletStatefulConnect/Namespaces.types.tsx +0 -4
  70. package/dist/components/SwapDetailsModal/SwapDetailsModal.helpers.d.ts +0 -4
  71. package/dist/components/SwapDetailsModal/SwapDetailsModal.helpers.d.ts.map +0 -1
  72. package/dist/components/WalletStatefulConnect/NamespaceUnsupportedItem.d.ts.map +0 -1
  73. package/dist/components/WalletStatefulConnect/Namespaces.helpers.d.ts.map +0 -1
  74. package/dist/components/WalletStatefulConnect/SupportedChainsList.d.ts.map +0 -1
  75. package/dist/components/WalletStatefulConnect/SupportedChainsList.styles.d.ts.map +0 -1
  76. package/dist/components/WalletStatefulConnect/SupportedChainsList.types.d.ts.map +0 -1
  77. package/src/components/SwapDetailsModal/SwapDetailsModal.helpers.tsx +0 -26
  78. /package/dist/components/{WalletStatefulConnect → NamespaceItem}/SupportedChainsList.d.ts +0 -0
  79. /package/dist/components/{WalletStatefulConnect → NamespaceItem}/SupportedChainsList.styles.d.ts +0 -0
  80. /package/dist/components/{WalletStatefulConnect → NamespaceItem}/SupportedChainsList.types.d.ts +0 -0
  81. /package/src/components/{WalletStatefulConnect → NamespaceItem}/SupportedChainsList.styles.ts +0 -0
  82. /package/src/components/{WalletStatefulConnect → NamespaceItem}/SupportedChainsList.tsx +0 -0
  83. /package/src/components/{WalletStatefulConnect → NamespaceItem}/SupportedChainsList.types.ts +0 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rango-dev/widget-embedded",
3
- "version": "0.45.1-next.3",
3
+ "version": "0.45.1-next.4",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "source": "./src/index.ts",
@@ -27,7 +27,7 @@
27
27
  "@rango-dev/logging-core": "^0.9.1-next.0",
28
28
  "@rango-dev/provider-all": "^0.48.1-next.2",
29
29
  "@rango-dev/queue-manager-core": "^0.30.1-next.0",
30
- "@rango-dev/queue-manager-rango-preset": "^0.47.1-next.2",
30
+ "@rango-dev/queue-manager-rango-preset": "^0.47.1-next.3",
31
31
  "@rango-dev/queue-manager-react": "^0.30.1-next.0",
32
32
  "@rango-dev/signer-solana": "^0.41.1-next.0",
33
33
  "@rango-dev/ui": "^0.48.1-next.3",
@@ -3,7 +3,7 @@ import type { BlockchainMeta } from 'rango-types';
3
3
  export function getBlockchainLogo(
4
4
  blockchains: BlockchainMeta[],
5
5
  blockchainName: string
6
- ) {
6
+ ): string | undefined {
7
7
  return blockchains.find((blockchain) => blockchain.name === blockchainName)
8
8
  ?.logo;
9
9
  }
@@ -0,0 +1,93 @@
1
+ import { darkTheme, Image, styled, Typography } from '@rango-dev/ui';
2
+
3
+ export const NamespaceItemContainer = styled('li', {
4
+ backgroundColor: '$neutral200',
5
+ padding: '$16',
6
+ borderRadius: '$sm',
7
+ variants: {
8
+ clickable: {
9
+ true: {
10
+ cursor: 'pointer',
11
+ },
12
+ },
13
+ hasError: {
14
+ true: {
15
+ background: '$error100',
16
+ [`.${darkTheme} &`]: {
17
+ backgroundColor: '$error700',
18
+ },
19
+ },
20
+ },
21
+ unsupported: {
22
+ true: {
23
+ cursor: 'not-allowed',
24
+ paddingTop: '$8',
25
+ paddingBottom: '$8',
26
+ },
27
+ },
28
+ },
29
+ });
30
+
31
+ export const NamespaceItemContent = styled('div', {
32
+ display: 'flex',
33
+ gap: '$8',
34
+ alignItems: 'center',
35
+ });
36
+
37
+ export const NamespaceItemInnerContent = styled('div', {
38
+ flex: '1',
39
+ display: 'flex',
40
+ flexDirection: 'column',
41
+ justifyContent: 'space-between',
42
+ height: '$40',
43
+ variants: {
44
+ showSupportedChains: {
45
+ true: {
46
+ justifyContent: 'space-between',
47
+ },
48
+ false: {
49
+ justifyContent: 'center',
50
+ },
51
+ },
52
+ },
53
+ });
54
+
55
+ export const UnsupportedNamespaceItemInnerContent = styled('div', {
56
+ flex: '1',
57
+ display: 'flex',
58
+ alignItems: 'center',
59
+ gap: '$4',
60
+ opacity: '0.5',
61
+ });
62
+
63
+ export const NamespaceItemInfo = styled('div', {
64
+ display: 'flex',
65
+ gap: '$6',
66
+ alignItems: 'center',
67
+ });
68
+
69
+ export const NamespaceItemError = styled('div', {
70
+ paddingLeft: '48px',
71
+ });
72
+
73
+ export const NamespaceItemErrorDropdownToggle = styled('div', {
74
+ display: 'flex',
75
+ gap: '$2',
76
+ cursor: 'pointer',
77
+ alignItems: 'center',
78
+ width: 'fit-content',
79
+ });
80
+
81
+ export const NamespaceAccountAddress = styled(Typography, {
82
+ maxWidth: '100px',
83
+ });
84
+
85
+ export const NamespaceLogo = styled(Image, {
86
+ variants: {
87
+ disabled: {
88
+ true: {
89
+ opacity: '0.5',
90
+ },
91
+ },
92
+ },
93
+ });
@@ -0,0 +1,117 @@
1
+ import type { PropTypes } from './NamespaceItem.types';
2
+
3
+ import { i18n } from '@lingui/core';
4
+ import {
5
+ ChevronDownIcon,
6
+ ChevronUpIcon,
7
+ Divider,
8
+ Typography,
9
+ } from '@rango-dev/ui';
10
+ import React, { useEffect, useState } from 'react';
11
+
12
+ import { useAppStore } from '../../store/AppStore';
13
+
14
+ import { getBlockchainLogo } from './NamespaceItem.helpers';
15
+ import {
16
+ NamespaceAccountAddress,
17
+ NamespaceItemContainer,
18
+ NamespaceItemContent,
19
+ NamespaceItemError,
20
+ NamespaceItemErrorDropdownToggle,
21
+ NamespaceItemInfo,
22
+ NamespaceItemInnerContent,
23
+ NamespaceLogo,
24
+ } from './NamespaceItem.styles';
25
+ import { SupportedChainsList } from './SupportedChainsList';
26
+
27
+ export function NamespaceItem(props: PropTypes) {
28
+ const { namespace, error, suffix, connected, address, onClick } = props;
29
+
30
+ const [errorIsExpanded, setErrorIsExpanded] = useState(false);
31
+ const blockchains = useAppStore().blockchains();
32
+
33
+ useEffect(() => setErrorIsExpanded(false), [error]);
34
+
35
+ const supportedChains = namespace.getSupportedChains(blockchains);
36
+ const isSupportedChainsDisplayed =
37
+ !error && !connected && supportedChains.length > 1;
38
+
39
+ return (
40
+ <NamespaceItemContainer
41
+ hasError={!!error}
42
+ clickable={!!onClick}
43
+ onClick={onClick}>
44
+ <NamespaceItemContent>
45
+ <NamespaceLogo
46
+ src={getBlockchainLogo(blockchains, namespace.id)}
47
+ size={40}
48
+ />
49
+ <NamespaceItemInnerContent
50
+ showSupportedChains={
51
+ isSupportedChainsDisplayed || connected || !!error
52
+ }>
53
+ <NamespaceItemInfo>
54
+ <Typography variant="label" size="large">
55
+ {namespace.label}
56
+ </Typography>
57
+ {connected && (
58
+ <Typography variant="body" size="small" color="success500">
59
+ {i18n.t('Connected')}
60
+ </Typography>
61
+ )}
62
+ {!!error && (
63
+ <Typography variant="body" size="small" color="error500">
64
+ {i18n.t('Connection failed')}
65
+ </Typography>
66
+ )}
67
+ </NamespaceItemInfo>
68
+ {isSupportedChainsDisplayed && (
69
+ <SupportedChainsList chains={supportedChains} />
70
+ )}
71
+ {connected && (
72
+ <NamespaceAccountAddress
73
+ variant="body"
74
+ size="small"
75
+ color="neutral700">
76
+ {address}
77
+ </NamespaceAccountAddress>
78
+ )}
79
+ {error && (
80
+ <NamespaceItemErrorDropdownToggle
81
+ onClick={() =>
82
+ setErrorIsExpanded((errorIsExpanded) => !errorIsExpanded)
83
+ }>
84
+ <Typography
85
+ variant="body"
86
+ size="small"
87
+ color="neutral700"
88
+ style={{
89
+ textDecoration: 'underline',
90
+ userSelect: 'none',
91
+ textDecorationSkipInk: 'none',
92
+ }}>
93
+ {i18n.t('See why')}
94
+ </Typography>
95
+ {errorIsExpanded ? (
96
+ <ChevronUpIcon size={12} color="gray" />
97
+ ) : (
98
+ <ChevronDownIcon size={12} color="gray" />
99
+ )}
100
+ </NamespaceItemErrorDropdownToggle>
101
+ )}
102
+ </NamespaceItemInnerContent>
103
+ {suffix}
104
+ </NamespaceItemContent>
105
+ {!!error && errorIsExpanded && (
106
+ <>
107
+ <Divider size={4} />
108
+ <NamespaceItemError>
109
+ <Typography variant="body" size="small" color="neutral700">
110
+ {error}
111
+ </Typography>
112
+ </NamespaceItemError>
113
+ </>
114
+ )}
115
+ </NamespaceItemContainer>
116
+ );
117
+ }
@@ -0,0 +1,14 @@
1
+ import type { LegacyNamespaceMeta } from '@rango-dev/wallets-core/legacy';
2
+
3
+ export type PropTypes = {
4
+ namespace: LegacyNamespaceMeta;
5
+ error?: string;
6
+ suffix?: React.ReactNode;
7
+ connected?: boolean;
8
+ address?: string | null;
9
+ onClick?: () => void;
10
+ };
11
+
12
+ export type NamespaceUnsupportedItemPropTypes = {
13
+ namespace: LegacyNamespaceMeta;
14
+ };
@@ -1,4 +1,4 @@
1
- import type { NamespaceUnsupportedItemPropTypes } from './Namespaces.types';
1
+ import type { NamespaceUnsupportedItemPropTypes } from './NamespaceItem.types';
2
2
 
3
3
  import { i18n } from '@lingui/core';
4
4
  import { Typography } from '@rango-dev/ui';
@@ -6,13 +6,13 @@ import React from 'react';
6
6
 
7
7
  import { useAppStore } from '../../store/AppStore';
8
8
 
9
- import { getBlockchainLogo } from './Namespaces.helpers';
9
+ import { getBlockchainLogo } from './NamespaceItem.helpers';
10
10
  import {
11
11
  NamespaceItemContainer,
12
12
  NamespaceItemContent,
13
13
  NamespaceLogo,
14
14
  UnsupportedNamespaceItemInnerContent,
15
- } from './Namespaces.styles';
15
+ } from './NamespaceItem.styles';
16
16
 
17
17
  export function NamespaceUnsupportedItem(
18
18
  props: NamespaceUnsupportedItemPropTypes
@@ -0,0 +1 @@
1
+ export { NamespaceItem } from './NamespaceItem';
@@ -0,0 +1,73 @@
1
+ import type { RequestIdProps } from './SwapDetails.types';
2
+
3
+ import { i18n } from '@lingui/core';
4
+ import {
5
+ CopyIcon,
6
+ DoneIcon,
7
+ IconButton,
8
+ RangoExplorerIcon,
9
+ Tooltip,
10
+ Typography,
11
+ useCopyToClipboard,
12
+ } from '@rango-dev/ui';
13
+ import React from 'react';
14
+
15
+ import { SCANNER_BASE_URL } from '../../constants';
16
+ import { getContainer } from '../../utils/common';
17
+
18
+ import { RESET_INTERVAL } from './SwapDetails.helpers';
19
+ import {
20
+ RequestIdContainer,
21
+ requestIdStyles,
22
+ rowStyles,
23
+ StyledLink,
24
+ } from './SwapDetails.styles';
25
+
26
+ export function RequestIdRow(props: RequestIdProps) {
27
+ const { requestId } = props;
28
+ const [isCopied, handleCopy] = useCopyToClipboard(RESET_INTERVAL);
29
+
30
+ return (
31
+ <RequestIdContainer className={rowStyles()}>
32
+ <Typography variant="label" size="large" color="neutral700">
33
+ {i18n.t('Request ID')}
34
+ </Typography>
35
+ <div className={requestIdStyles()}>
36
+ <Typography variant="label" size="small" color="neutral700">
37
+ {requestId}
38
+ </Typography>
39
+ <Tooltip
40
+ container={getContainer()}
41
+ content={
42
+ isCopied ? i18n.t('Copied To Clipboard') : i18n.t('Copy Request ID')
43
+ }
44
+ open={isCopied || undefined}
45
+ side="bottom"
46
+ alignOffset={-16}
47
+ align="end">
48
+ <IconButton
49
+ id="widget-swap-details-done-copy-icon-btn"
50
+ variant="ghost"
51
+ onClick={handleCopy.bind(null, requestId || '')}>
52
+ {isCopied ? (
53
+ <DoneIcon size={16} color="secondary" />
54
+ ) : (
55
+ <CopyIcon size={16} color="gray" />
56
+ )}
57
+ </IconButton>
58
+ </Tooltip>
59
+
60
+ <StyledLink
61
+ target="_blank"
62
+ href={`${SCANNER_BASE_URL}/swap/${requestId}`}>
63
+ <Tooltip
64
+ container={getContainer()}
65
+ content={i18n.t('View on Rango Explorer')}
66
+ side="bottom">
67
+ <RangoExplorerIcon size={20} />
68
+ </Tooltip>
69
+ </StyledLink>
70
+ </div>
71
+ </RequestIdContainer>
72
+ );
73
+ }
@@ -0,0 +1,21 @@
1
+ import type { SwapDateRowProps } from './SwapDetails.types';
2
+
3
+ import { i18n } from '@lingui/core';
4
+ import { Typography } from '@rango-dev/ui';
5
+ import React from 'react';
6
+
7
+ import { rowStyles } from './SwapDetails.styles';
8
+
9
+ export function SwapDateRow(props: SwapDateRowProps) {
10
+ const { date, isFinished } = props;
11
+ return (
12
+ <div className={rowStyles()}>
13
+ <Typography variant="label" size="large" color="neutral700">
14
+ {isFinished ? i18n.t('Finished at') : i18n.t('Created at')}
15
+ </Typography>
16
+ <Typography variant="label" size="small" color="neutral700">
17
+ {date}
18
+ </Typography>
19
+ </div>
20
+ );
21
+ }
@@ -9,16 +9,10 @@ import {
9
9
  } from '@rango-dev/queue-manager-rango-preset';
10
10
  import {
11
11
  Button,
12
- CopyIcon,
13
12
  Divider,
14
- DoneIcon,
15
- IconButton,
16
13
  QuoteCost,
17
- RangoExplorerIcon,
18
14
  StepDetails,
19
- Tooltip,
20
15
  Typography,
21
- useCopyToClipboard,
22
16
  } from '@rango-dev/ui';
23
17
  import { useWallets } from '@rango-dev/wallets-react';
24
18
  import BigNumber from 'bignumber.js';
@@ -26,7 +20,6 @@ import { PendingSwapNetworkStatus } from 'rango-types';
26
20
  import React, { useEffect, useRef, useState } from 'react';
27
21
  import { useNavigate } from 'react-router-dom';
28
22
 
29
- import { SCANNER_BASE_URL } from '../../constants';
30
23
  import {
31
24
  GAS_FEE_MAX_DECIMALS,
32
25
  GAS_FEE_MIN_DECIMALS,
@@ -40,7 +33,6 @@ import {
40
33
  import { useAppStore } from '../../store/AppStore';
41
34
  import { useNotificationStore } from '../../store/notification';
42
35
  import { useQuoteStore } from '../../store/quote';
43
- import { useUiStore } from '../../store/ui';
44
36
  import { getContainer } from '../../utils/common';
45
37
  import {
46
38
  numberToString,
@@ -67,40 +59,33 @@ import {
67
59
  SwapDetailsModal,
68
60
  } from '../SwapDetailsModal';
69
61
 
70
- import { getSteps, getStepState, RESET_INTERVAL } from './SwapDetails.helpers';
62
+ import { RequestIdRow } from './RequestIdRow';
63
+ import { SwapDateRow } from './SwapDateRow';
64
+ import { getSteps, getStepState } from './SwapDetails.helpers';
71
65
  import {
72
66
  Container,
73
67
  ErrorMessages,
74
68
  MessageText,
75
69
  outputStyles,
76
- RequestIdContainer,
77
- requestIdStyles,
78
- rowStyles,
79
70
  StepsList,
80
- StyledLink,
81
71
  titleStepsStyles,
82
72
  } from './SwapDetails.styles';
83
73
 
84
74
  export function SwapDetails(props: SwapDetailsProps) {
85
- const { swap, requestId, onDelete, onCancel: onCancelProps } = props;
75
+ const { swap, requestId, onDelete, onCancel } = props;
86
76
  const { canSwitchNetworkTo, connect, getWalletInfo } = useWallets();
87
77
  const blockchains = useAppStore().blockchains();
88
78
  const swappers = useAppStore().swappers();
89
79
  const { findToken } = useAppStore();
90
80
  const retry = useQuoteStore.use.retry();
91
- const isActiveTab = useUiStore.use.isActiveTab();
92
81
  const navigate = useNavigate();
93
- const [isCopied, handleCopy] = useCopyToClipboard(RESET_INTERVAL);
94
82
  const containerRef = useRef<HTMLDivElement | null>(null);
83
+ const [isModalOpen, setIsModalOpen] = useState(false);
95
84
  const [modalState, setModalState] = useState<ModalState>(null);
96
85
  const [showCompletedModal, setShowCompletedModal] = useState<
97
86
  'success' | 'failed' | null
98
87
  >(null);
99
-
100
- const onCancel = () => {
101
- onCancelProps();
102
- setModalState(null);
103
- };
88
+ const showSwitchNetworkRef = useRef(false);
104
89
 
105
90
  const getNotifications = useNotificationStore.use.getNotifications();
106
91
  const removeNotification = useNotificationStore.use.removeNotification();
@@ -108,6 +93,15 @@ export function SwapDetails(props: SwapDetailsProps) {
108
93
  const currentStep = getCurrentStep(swap);
109
94
  const currentStepNetworkStatus = currentStep?.networkStatus;
110
95
 
96
+ const handleChangeModalState = (state: ModalState) => {
97
+ setIsModalOpen(true);
98
+ setModalState(state);
99
+ };
100
+
101
+ const handleCloseModal = () => {
102
+ setIsModalOpen(false);
103
+ };
104
+
111
105
  useEffect(() => {
112
106
  const existNotification = notifications.find(
113
107
  (n) => n.requestId === swap.requestId
@@ -116,6 +110,7 @@ export function SwapDetails(props: SwapDetailsProps) {
116
110
  if (swap.status === 'success' || swap.status === 'failed') {
117
111
  setShowCompletedModal(swap.status);
118
112
  removeNotification(swap.requestId);
113
+ handleCloseModal();
119
114
  } else if (showCompletedModal) {
120
115
  setShowCompletedModal(null);
121
116
  }
@@ -124,16 +119,24 @@ export function SwapDetails(props: SwapDetailsProps) {
124
119
 
125
120
  useEffect(() => {
126
121
  if (showSwitchNetwork) {
127
- setModalState(PendingSwapNetworkStatus.WaitingForNetworkChange);
122
+ handleChangeModalState(PendingSwapNetworkStatus.WaitingForNetworkChange);
128
123
  } else if (
129
124
  currentStepNetworkStatus ===
130
- PendingSwapNetworkStatus.WaitingForConnectingWallet ||
125
+ PendingSwapNetworkStatus.WaitingForConnectingWallet
126
+ ) {
127
+ handleChangeModalState(
128
+ PendingSwapNetworkStatus.WaitingForConnectingWallet
129
+ );
130
+ } else if (
131
131
  currentStepNetworkStatus === PendingSwapNetworkStatus.NetworkChanged
132
132
  ) {
133
- setModalState(currentStepNetworkStatus);
134
- } else {
135
- setModalState(null);
133
+ handleChangeModalState(PendingSwapNetworkStatus.NetworkChanged);
136
134
  }
135
+
136
+ if (!showSwitchNetwork && showSwitchNetworkRef.current) {
137
+ handleCloseModal();
138
+ }
139
+ showSwitchNetworkRef.current = showSwitchNetwork;
137
140
  }, [currentStepNetworkStatus]);
138
141
 
139
142
  const lastConvertedTokenInFailedSwap =
@@ -177,7 +180,7 @@ export function SwapDetails(props: SwapDetailsProps) {
177
180
  swap,
178
181
  switchNetwork,
179
182
  showNetworkModal: currentStepNetworkStatus,
180
- setNetworkModal: setModalState,
183
+ setNetworkModal: handleChangeModalState,
181
184
  message: stepMessage,
182
185
  blockchains: blockchains,
183
186
  swappers,
@@ -277,7 +280,9 @@ export function SwapDetails(props: SwapDetailsProps) {
277
280
  header={{
278
281
  title: i18n.t('Swap Details'),
279
282
  onCancel:
280
- swap.status === 'running' ? () => setModalState('cancel') : undefined,
283
+ swap.status === 'running'
284
+ ? () => handleChangeModalState('cancel')
285
+ : undefined,
281
286
  suffix: swap.status !== 'running' && (
282
287
  <SuffixContainer>
283
288
  <Button
@@ -285,7 +290,7 @@ export function SwapDetails(props: SwapDetailsProps) {
285
290
  variant="ghost"
286
291
  type="error"
287
292
  size="xsmall"
288
- onClick={() => setModalState('delete')}>
293
+ onClick={() => handleChangeModalState('delete')}>
289
294
  <Typography size="medium" variant="label" color="error">
290
295
  {i18n.t('Delete')}
291
296
  </Typography>
@@ -314,58 +319,9 @@ export function SwapDetails(props: SwapDetailsProps) {
314
319
  </Button>
315
320
  )
316
321
  }>
317
- <Container compact ref={containerRef} id="widget-swap-details-container">
318
- <RequestIdContainer className={rowStyles()}>
319
- <Typography variant="label" size="large" color="neutral700">
320
- {`${i18n.t('Request ID')}`}
321
- </Typography>
322
- <div className={requestIdStyles()}>
323
- <Typography variant="label" size="small" color="neutral700">
324
- {requestId}
325
- </Typography>
326
- <Tooltip
327
- container={getContainer()}
328
- content={
329
- isCopied
330
- ? i18n.t('Copied To Clipboard')
331
- : i18n.t('Copy Request ID')
332
- }
333
- open={isCopied || undefined}
334
- side="bottom"
335
- alignOffset={-16}
336
- align="end">
337
- <IconButton
338
- id="widget-swap-details-done-copy-icon-btn"
339
- variant="ghost"
340
- onClick={handleCopy.bind(null, requestId || '')}>
341
- {isCopied ? (
342
- <DoneIcon size={16} color="secondary" />
343
- ) : (
344
- <CopyIcon size={16} color="gray" />
345
- )}
346
- </IconButton>
347
- </Tooltip>
348
-
349
- <StyledLink
350
- target="_blank"
351
- href={`${SCANNER_BASE_URL}/swap/${requestId}`}>
352
- <Tooltip
353
- container={getContainer()}
354
- content={i18n.t('View on Rango Explorer')}
355
- side="bottom">
356
- <RangoExplorerIcon size={20} />
357
- </Tooltip>
358
- </StyledLink>
359
- </div>
360
- </RequestIdContainer>
361
- <div className={rowStyles()}>
362
- <Typography variant="label" size="large" color="neutral700">
363
- {swap.finishTime ? i18n.t('Finished at') : i18n.t('Created at')}
364
- </Typography>
365
- <Typography variant="label" size="small" color="neutral700">
366
- {swapDate}
367
- </Typography>
368
- </div>
322
+ <Container compact ref={containerRef}>
323
+ <RequestIdRow requestId={requestId} />
324
+ <SwapDateRow date={swapDate} isFinished={!!swap.finishTime} />
369
325
 
370
326
  <div className={outputStyles()}>
371
327
  <QuoteCost
@@ -460,13 +416,13 @@ export function SwapDetails(props: SwapDetailsProps) {
460
416
  </Container>
461
417
 
462
418
  <SwapDetailsModal
419
+ isOpen={isModalOpen}
463
420
  state={modalState}
464
- onClose={() => setModalState(null)}
421
+ onClose={handleCloseModal}
465
422
  onCancel={onCancel}
466
423
  onDelete={onDelete}
467
424
  message={stepMessage.detailedMessage.content}
468
425
  swap={swap}
469
- walletButtonDisabled={!isActiveTab}
470
426
  />
471
427
  <SwapDetailsCompleteModal
472
428
  open={!!showCompletedModal}
@@ -6,6 +6,13 @@ export interface SwapDetailsProps {
6
6
  onDelete: () => void;
7
7
  onCancel: () => void;
8
8
  }
9
+ export interface RequestIdProps {
10
+ requestId: string;
11
+ }
12
+ export interface SwapDateRowProps {
13
+ date: string;
14
+ isFinished: boolean;
15
+ }
9
16
  export interface SwapDetailsPlaceholderPropTypes {
10
17
  requestId: string;
11
18
  showSkeleton: boolean;