@rango-dev/widget-embedded 0.45.1-next.0 → 0.45.1-next.10
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/components/CustomDestination/CustomDestination.styles.d.ts +1 -0
- package/dist/components/CustomDestination/CustomDestination.styles.d.ts.map +1 -1
- package/dist/components/NamespaceItem/NamespaceItem.d.ts +4 -0
- package/dist/components/NamespaceItem/NamespaceItem.d.ts.map +1 -0
- package/dist/components/{WalletStatefulConnect/Namespaces.helpers.d.ts → NamespaceItem/NamespaceItem.helpers.d.ts} +1 -1
- package/dist/components/NamespaceItem/NamespaceItem.helpers.d.ts.map +1 -0
- package/dist/components/NamespaceItem/NamespaceItem.styles.d.ts +1450 -0
- package/dist/components/NamespaceItem/NamespaceItem.styles.d.ts.map +1 -0
- package/dist/components/NamespaceItem/NamespaceItem.types.d.ts +13 -0
- package/dist/components/NamespaceItem/NamespaceItem.types.d.ts.map +1 -0
- package/dist/components/{WalletStatefulConnect → NamespaceItem}/NamespaceUnsupportedItem.d.ts +1 -1
- package/dist/components/NamespaceItem/NamespaceUnsupportedItem.d.ts.map +1 -0
- package/dist/components/NamespaceItem/SupportedChainsList.d.ts.map +1 -0
- package/dist/components/NamespaceItem/SupportedChainsList.styles.d.ts.map +1 -0
- package/dist/components/NamespaceItem/SupportedChainsList.types.d.ts.map +1 -0
- package/dist/components/NamespaceItem/index.d.ts +2 -0
- package/dist/components/NamespaceItem/index.d.ts.map +1 -0
- package/dist/components/Slippage/Slippage.d.ts.map +1 -1
- package/dist/components/Slippage/Slippage.styles.d.ts +0 -162
- package/dist/components/Slippage/Slippage.styles.d.ts.map +1 -1
- package/dist/components/StatefulConnectModal/StatefulConnectModal.d.ts.map +1 -1
- package/dist/components/SwapDetails/RequestIdRow.d.ts +4 -0
- package/dist/components/SwapDetails/RequestIdRow.d.ts.map +1 -0
- package/dist/components/SwapDetails/SwapDateRow.d.ts +4 -0
- package/dist/components/SwapDetails/SwapDateRow.d.ts.map +1 -0
- package/dist/components/SwapDetails/SwapDetails.d.ts.map +1 -1
- package/dist/components/SwapDetails/SwapDetails.types.d.ts +7 -0
- package/dist/components/SwapDetails/SwapDetails.types.d.ts.map +1 -1
- package/dist/components/SwapDetailsModal/SwapDetailsModal.ConnectWallet.d.ts +4 -0
- package/dist/components/SwapDetailsModal/SwapDetailsModal.ConnectWallet.d.ts.map +1 -0
- package/dist/components/SwapDetailsModal/SwapDetailsModal.InstallWallet.d.ts +4 -0
- package/dist/components/SwapDetailsModal/SwapDetailsModal.InstallWallet.d.ts.map +1 -0
- package/dist/components/SwapDetailsModal/SwapDetailsModal.NetworkState.d.ts +4 -0
- package/dist/components/SwapDetailsModal/SwapDetailsModal.NetworkState.d.ts.map +1 -0
- package/dist/components/SwapDetailsModal/SwapDetailsModal.WalletState.d.ts +1 -1
- package/dist/components/SwapDetailsModal/SwapDetailsModal.WalletState.d.ts.map +1 -1
- package/dist/components/SwapDetailsModal/SwapDetailsModal.d.ts.map +1 -1
- package/dist/components/SwapDetailsModal/SwapDetailsModal.styles.d.ts +320 -0
- package/dist/components/SwapDetailsModal/SwapDetailsModal.styles.d.ts.map +1 -1
- package/dist/components/SwapDetailsModal/SwapDetailsModal.types.d.ts +29 -10
- package/dist/components/SwapDetailsModal/SwapDetailsModal.types.d.ts.map +1 -1
- package/dist/components/WalletStatefulConnect/Detached.d.ts.map +1 -1
- package/dist/components/WalletStatefulConnect/Detached.styles.d.ts +161 -0
- package/dist/components/WalletStatefulConnect/Detached.styles.d.ts.map +1 -0
- package/dist/components/WalletStatefulConnect/Detached.types.d.ts +1 -0
- package/dist/components/WalletStatefulConnect/Detached.types.d.ts.map +1 -1
- package/dist/components/WalletStatefulConnect/NamespaceDetachedItem.d.ts.map +1 -1
- package/dist/components/WalletStatefulConnect/NamespaceListItem.d.ts.map +1 -1
- package/dist/components/WalletStatefulConnect/Namespaces.styles.d.ts +281 -1730
- package/dist/components/WalletStatefulConnect/Namespaces.styles.d.ts.map +1 -1
- package/dist/components/WalletStatefulConnect/Namespaces.types.d.ts +0 -3
- package/dist/components/WalletStatefulConnect/Namespaces.types.d.ts.map +1 -1
- package/dist/hooks/useConfirmSwap/useConfirmSwap.d.ts.map +1 -1
- package/dist/hooks/useConfirmSwap/useConfirmSwap.helpers.d.ts +1 -1
- package/dist/hooks/useConfirmSwap/useConfirmSwap.helpers.d.ts.map +1 -1
- package/dist/hooks/useStatefulConnect/useStatefulConnect.d.ts +1 -2
- package/dist/hooks/useStatefulConnect/useStatefulConnect.d.ts.map +1 -1
- package/dist/hooks/useSwapInput.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +4 -4
- package/dist/store/slices/wallets.d.ts +2 -2
- package/dist/store/slices/wallets.d.ts.map +1 -1
- package/dist/types/quote.d.ts +1 -1
- package/dist/types/quote.d.ts.map +1 -1
- package/dist/types/wallets.d.ts +1 -0
- package/dist/types/wallets.d.ts.map +1 -1
- package/dist/utils/swap.d.ts +1 -0
- package/dist/utils/swap.d.ts.map +1 -1
- package/dist/widget-embedded.build.json +1 -1
- package/package.json +7 -7
- package/src/components/{WalletStatefulConnect/Namespaces.helpers.ts → NamespaceItem/NamespaceItem.helpers.ts} +1 -1
- package/src/components/NamespaceItem/NamespaceItem.styles.ts +93 -0
- package/src/components/NamespaceItem/NamespaceItem.tsx +117 -0
- package/src/components/NamespaceItem/NamespaceItem.types.ts +14 -0
- package/src/components/{WalletStatefulConnect → NamespaceItem}/NamespaceUnsupportedItem.tsx +3 -3
- package/src/components/NamespaceItem/index.ts +1 -0
- package/src/components/Quote/Quote.tsx +4 -4
- package/src/components/Slippage/Slippage.styles.ts +0 -23
- package/src/components/Slippage/Slippage.tsx +24 -26
- package/src/components/StatefulConnectModal/StatefulConnectModal.tsx +4 -0
- package/src/components/SwapDetails/RequestIdRow.tsx +73 -0
- package/src/components/SwapDetails/SwapDateRow.tsx +21 -0
- package/src/components/SwapDetails/SwapDetails.tsx +39 -83
- package/src/components/SwapDetails/SwapDetails.types.ts +7 -0
- package/src/components/SwapDetailsModal/SwapDetailsModal.ConnectWallet.tsx +177 -0
- package/src/components/SwapDetailsModal/SwapDetailsModal.InstallWallet.tsx +52 -0
- package/src/components/SwapDetailsModal/SwapDetailsModal.NetworkState.tsx +17 -0
- package/src/components/SwapDetailsModal/SwapDetailsModal.WalletState.tsx +22 -62
- package/src/components/SwapDetailsModal/SwapDetailsModal.styles.ts +20 -1
- package/src/components/SwapDetailsModal/SwapDetailsModal.tsx +24 -35
- package/src/components/SwapDetailsModal/SwapDetailsModal.types.ts +31 -10
- package/src/components/WalletStatefulConnect/Detached.styles.ts +6 -0
- package/src/components/WalletStatefulConnect/Detached.tsx +21 -4
- package/src/components/WalletStatefulConnect/Detached.types.ts +1 -0
- package/src/components/WalletStatefulConnect/NamespaceDetachedItem.tsx +20 -106
- package/src/components/WalletStatefulConnect/NamespaceListItem.tsx +9 -34
- package/src/components/WalletStatefulConnect/Namespaces.styles.ts +2 -94
- package/src/components/WalletStatefulConnect/Namespaces.tsx +1 -1
- package/src/components/WalletStatefulConnect/Namespaces.types.tsx +0 -4
- package/src/containers/Wallets/useUpdates.ts +1 -1
- package/src/hooks/useConfirmSwap/useConfirmSwap.helpers.ts +10 -23
- package/src/hooks/useConfirmSwap/useConfirmSwap.ts +19 -4
- package/src/hooks/useStatefulConnect/useStatefulConnect.ts +23 -7
- package/src/hooks/useSwapInput.ts +13 -4
- package/src/hooks/useWalletList.ts +1 -1
- package/src/store/slices/wallets.ts +11 -5
- package/src/types/quote.ts +1 -1
- package/src/types/wallets.ts +1 -0
- package/src/utils/swap.ts +10 -5
- package/dist/components/SwapDetailsModal/SwapDetailsModal.helpers.d.ts +0 -4
- package/dist/components/SwapDetailsModal/SwapDetailsModal.helpers.d.ts.map +0 -1
- package/dist/components/WalletStatefulConnect/NamespaceUnsupportedItem.d.ts.map +0 -1
- package/dist/components/WalletStatefulConnect/Namespaces.helpers.d.ts.map +0 -1
- package/dist/components/WalletStatefulConnect/SupportedChainsList.d.ts.map +0 -1
- package/dist/components/WalletStatefulConnect/SupportedChainsList.styles.d.ts.map +0 -1
- package/dist/components/WalletStatefulConnect/SupportedChainsList.types.d.ts.map +0 -1
- package/src/components/SwapDetailsModal/SwapDetailsModal.helpers.tsx +0 -26
- /package/dist/components/{WalletStatefulConnect → NamespaceItem}/SupportedChainsList.d.ts +0 -0
- /package/dist/components/{WalletStatefulConnect → NamespaceItem}/SupportedChainsList.styles.d.ts +0 -0
- /package/dist/components/{WalletStatefulConnect → NamespaceItem}/SupportedChainsList.types.d.ts +0 -0
- /package/src/components/{WalletStatefulConnect → NamespaceItem}/SupportedChainsList.styles.ts +0 -0
- /package/src/components/{WalletStatefulConnect → NamespaceItem}/SupportedChainsList.tsx +0 -0
- /package/src/components/{WalletStatefulConnect → NamespaceItem}/SupportedChainsList.types.ts +0 -0
|
@@ -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 {
|
|
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
|
|
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
|
-
|
|
122
|
+
handleChangeModalState(PendingSwapNetworkStatus.WaitingForNetworkChange);
|
|
128
123
|
} else if (
|
|
129
124
|
currentStepNetworkStatus ===
|
|
130
|
-
|
|
125
|
+
PendingSwapNetworkStatus.WaitingForConnectingWallet
|
|
126
|
+
) {
|
|
127
|
+
handleChangeModalState(
|
|
128
|
+
PendingSwapNetworkStatus.WaitingForConnectingWallet
|
|
129
|
+
);
|
|
130
|
+
} else if (
|
|
131
131
|
currentStepNetworkStatus === PendingSwapNetworkStatus.NetworkChanged
|
|
132
132
|
) {
|
|
133
|
-
|
|
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:
|
|
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'
|
|
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={() =>
|
|
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}
|
|
318
|
-
<
|
|
319
|
-
|
|
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={
|
|
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;
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import type { ConnectWalletContentProps } from './SwapDetailsModal.types';
|
|
2
|
+
|
|
3
|
+
import { i18n } from '@lingui/core';
|
|
4
|
+
import {
|
|
5
|
+
Alert,
|
|
6
|
+
Button,
|
|
7
|
+
Checkbox,
|
|
8
|
+
Divider,
|
|
9
|
+
Image,
|
|
10
|
+
MessageBox,
|
|
11
|
+
Spinner,
|
|
12
|
+
WarningIcon,
|
|
13
|
+
} from '@rango-dev/ui';
|
|
14
|
+
import { useWallets } from '@rango-dev/wallets-react';
|
|
15
|
+
import React, { useState } from 'react';
|
|
16
|
+
|
|
17
|
+
import { useWalletList } from '../../hooks/useWalletList';
|
|
18
|
+
import { useUiStore } from '../../store/ui';
|
|
19
|
+
import { getConciseAddress } from '../../utils/wallets';
|
|
20
|
+
import { NamespaceItem } from '../NamespaceItem';
|
|
21
|
+
|
|
22
|
+
import {
|
|
23
|
+
WalletIcon,
|
|
24
|
+
WalletIconBadgeContainer,
|
|
25
|
+
} from './SwapDetailsModal.styles';
|
|
26
|
+
|
|
27
|
+
export const ConnectWalletContent = (props: ConnectWalletContentProps) => {
|
|
28
|
+
const { wallet: currentStepWallet, namespace, onClose } = props;
|
|
29
|
+
|
|
30
|
+
const [error, setError] = useState<Error | null>(null);
|
|
31
|
+
const { list } = useWalletList();
|
|
32
|
+
const isActiveTab = useUiStore.use.isActiveTab();
|
|
33
|
+
const { state, connect } = useWallets();
|
|
34
|
+
|
|
35
|
+
const wallet = list.find(
|
|
36
|
+
(wallet) => wallet.type === currentStepWallet.walletType
|
|
37
|
+
);
|
|
38
|
+
const namespaceData = wallet?.needsNamespace?.data.find(
|
|
39
|
+
(namespaceData) => namespaceData.value === namespace?.namespace
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
if (!wallet) {
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const walletState = state(currentStepWallet.walletType);
|
|
47
|
+
const namespaceState =
|
|
48
|
+
wallet.isHub && namespace?.namespace
|
|
49
|
+
? walletState.namespaces?.get(namespace.namespace)
|
|
50
|
+
: null;
|
|
51
|
+
|
|
52
|
+
const connecting = walletState.connecting || namespaceState?.connecting;
|
|
53
|
+
const connected = wallet.isHub
|
|
54
|
+
? namespaceState?.connected
|
|
55
|
+
: walletState.connected;
|
|
56
|
+
|
|
57
|
+
const getButtonTitle = () => {
|
|
58
|
+
if (connected) {
|
|
59
|
+
return i18n.t('Done');
|
|
60
|
+
}
|
|
61
|
+
if (error) {
|
|
62
|
+
return i18n.t('Try again');
|
|
63
|
+
}
|
|
64
|
+
return i18n.t('Connect');
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
const getNamespaceSuffix = () => {
|
|
68
|
+
if (connecting) {
|
|
69
|
+
return <Spinner color="info" />;
|
|
70
|
+
} else if (error || connected) {
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
return <Checkbox checked disabled />;
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
const handleConnect = async () => {
|
|
77
|
+
try {
|
|
78
|
+
setError(null);
|
|
79
|
+
await connect(
|
|
80
|
+
wallet.type,
|
|
81
|
+
namespace?.namespace
|
|
82
|
+
? [
|
|
83
|
+
{
|
|
84
|
+
namespace: namespace?.namespace,
|
|
85
|
+
network: undefined,
|
|
86
|
+
derivationPath: currentStepWallet.derivationPath,
|
|
87
|
+
},
|
|
88
|
+
]
|
|
89
|
+
: undefined
|
|
90
|
+
);
|
|
91
|
+
} catch (error) {
|
|
92
|
+
setError(error as Error);
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
const handleClickButton = async () => {
|
|
97
|
+
if (connected) {
|
|
98
|
+
onClose();
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
void handleConnect();
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
const getAddress = () => {
|
|
106
|
+
if (!connected) {
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
109
|
+
const firstAccountArray = wallet?.isHub
|
|
110
|
+
? namespaceState?.accounts?.[0]?.split(':')
|
|
111
|
+
: walletState?.accounts?.[0]?.split(':');
|
|
112
|
+
const address = firstAccountArray?.[firstAccountArray?.length - 1];
|
|
113
|
+
|
|
114
|
+
if (!address) {
|
|
115
|
+
return null;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
return getConciseAddress(address);
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
return (
|
|
122
|
+
<>
|
|
123
|
+
<MessageBox
|
|
124
|
+
type="warning"
|
|
125
|
+
title={i18n.t('Connect {wallet}', { wallet: wallet.title })}
|
|
126
|
+
description={i18n.t(
|
|
127
|
+
'The connection of your wallet or some networks has been disconnected. Connect to continue the swap'
|
|
128
|
+
)}
|
|
129
|
+
icon={
|
|
130
|
+
<WalletIcon>
|
|
131
|
+
<Image src={wallet.image} size={45} />
|
|
132
|
+
<WalletIconBadgeContainer>
|
|
133
|
+
<WarningIcon color="warning" size={10} />
|
|
134
|
+
</WalletIconBadgeContainer>
|
|
135
|
+
</WalletIcon>
|
|
136
|
+
}
|
|
137
|
+
/>
|
|
138
|
+
{connected && !namespaceData && (
|
|
139
|
+
<>
|
|
140
|
+
<Divider size={10} />
|
|
141
|
+
<Alert
|
|
142
|
+
type="success"
|
|
143
|
+
variant="alarm"
|
|
144
|
+
title={i18n.t('Wallet connected successfully.')}
|
|
145
|
+
/>
|
|
146
|
+
</>
|
|
147
|
+
)}
|
|
148
|
+
{error && !namespaceData && (
|
|
149
|
+
<>
|
|
150
|
+
<Divider size={10} />
|
|
151
|
+
<Alert type="error" title={error?.message} variant="alarm" />
|
|
152
|
+
</>
|
|
153
|
+
)}
|
|
154
|
+
{namespaceData && (
|
|
155
|
+
<>
|
|
156
|
+
<Divider size={30} />
|
|
157
|
+
<NamespaceItem
|
|
158
|
+
namespace={namespaceData}
|
|
159
|
+
suffix={getNamespaceSuffix()}
|
|
160
|
+
error={error?.message}
|
|
161
|
+
connected={connected}
|
|
162
|
+
address={getAddress()}
|
|
163
|
+
/>
|
|
164
|
+
</>
|
|
165
|
+
)}
|
|
166
|
+
<Divider size="40" />
|
|
167
|
+
<Button
|
|
168
|
+
loading={connecting}
|
|
169
|
+
type="primary"
|
|
170
|
+
id="widget-connect-wallet-btn"
|
|
171
|
+
onClick={handleClickButton}
|
|
172
|
+
disabled={!isActiveTab}>
|
|
173
|
+
{getButtonTitle()}
|
|
174
|
+
</Button>
|
|
175
|
+
</>
|
|
176
|
+
);
|
|
177
|
+
};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { InstallWalletContentProps } from './SwapDetailsModal.types';
|
|
2
|
+
|
|
3
|
+
import { i18n } from '@lingui/core';
|
|
4
|
+
import { Button, Divider, Image, MessageBox, WarningIcon } from '@rango-dev/ui';
|
|
5
|
+
import { useWallets } from '@rango-dev/wallets-react';
|
|
6
|
+
import { detectInstallLink } from '@rango-dev/wallets-shared';
|
|
7
|
+
import React from 'react';
|
|
8
|
+
|
|
9
|
+
import {
|
|
10
|
+
WalletIcon,
|
|
11
|
+
WalletIconBadgeContainer,
|
|
12
|
+
} from './SwapDetailsModal.styles';
|
|
13
|
+
|
|
14
|
+
export const InstallWalletContent = (props: InstallWalletContentProps) => {
|
|
15
|
+
const { walletType } = props;
|
|
16
|
+
|
|
17
|
+
const { getWalletInfo } = useWallets();
|
|
18
|
+
|
|
19
|
+
const walletInfo = walletType ? getWalletInfo(walletType) : null;
|
|
20
|
+
|
|
21
|
+
if (!walletInfo) {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const handleButtonClick = () =>
|
|
26
|
+
window.open(detectInstallLink(walletInfo.installLink), '_blank');
|
|
27
|
+
|
|
28
|
+
return (
|
|
29
|
+
<>
|
|
30
|
+
<MessageBox
|
|
31
|
+
type="warning"
|
|
32
|
+
title={i18n.t('Install {wallet}', { wallet: walletInfo.name })}
|
|
33
|
+
description="Your wallet is not installed. Please install it to continue the swap. "
|
|
34
|
+
icon={
|
|
35
|
+
<WalletIcon>
|
|
36
|
+
<Image src={walletInfo.img} size={45} />
|
|
37
|
+
<WalletIconBadgeContainer>
|
|
38
|
+
<WarningIcon color="warning" size={10} />
|
|
39
|
+
</WalletIconBadgeContainer>
|
|
40
|
+
</WalletIcon>
|
|
41
|
+
}
|
|
42
|
+
/>
|
|
43
|
+
<Divider size="40" />
|
|
44
|
+
<Button
|
|
45
|
+
type="primary"
|
|
46
|
+
id="widget-install-wallet-btn"
|
|
47
|
+
onClick={handleButtonClick}>
|
|
48
|
+
{i18n.t('Install')}
|
|
49
|
+
</Button>
|
|
50
|
+
</>
|
|
51
|
+
);
|
|
52
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { NetworkStateContentProps } from './SwapDetailsModal.types';
|
|
2
|
+
|
|
3
|
+
import { i18n } from '@lingui/core';
|
|
4
|
+
import { MessageBox } from '@rango-dev/ui';
|
|
5
|
+
import React from 'react';
|
|
6
|
+
|
|
7
|
+
export const NetworkStateContent = (props: NetworkStateContentProps) => {
|
|
8
|
+
const { status, message } = props;
|
|
9
|
+
|
|
10
|
+
const type = status === 'waitingForNetworkChange' ? 'loading' : 'success';
|
|
11
|
+
const title =
|
|
12
|
+
status === 'waitingForNetworkChange'
|
|
13
|
+
? i18n.t('Change Network')
|
|
14
|
+
: i18n.t('Network Changed');
|
|
15
|
+
|
|
16
|
+
return <MessageBox type={type} title={title} description={message} />;
|
|
17
|
+
};
|
|
@@ -1,89 +1,49 @@
|
|
|
1
1
|
import type { WalletStateContentProps } from './SwapDetailsModal.types';
|
|
2
|
-
import type { WalletInfoWithExtra } from '../../types';
|
|
3
2
|
|
|
4
|
-
import { warn } from '@rango-dev/logging-core';
|
|
5
3
|
import {
|
|
4
|
+
getCurrentNamespaceOfOrNull,
|
|
6
5
|
getCurrentStep,
|
|
7
6
|
getRelatedWalletOrNull,
|
|
8
7
|
} from '@rango-dev/queue-manager-rango-preset';
|
|
9
|
-
import {
|
|
8
|
+
import { WalletState } from '@rango-dev/ui';
|
|
10
9
|
import { useWallets } from '@rango-dev/wallets-react';
|
|
11
|
-
import React
|
|
10
|
+
import React from 'react';
|
|
12
11
|
|
|
13
|
-
import { useWalletList } from '../../hooks/useWalletList';
|
|
14
|
-
import { getContainer } from '../../utils/common';
|
|
15
12
|
import { mapStatusToWalletState } from '../../utils/wallets';
|
|
16
|
-
import { StatefulConnectModal } from '../StatefulConnectModal';
|
|
17
13
|
|
|
18
|
-
import {
|
|
14
|
+
import { ConnectWalletContent } from './SwapDetailsModal.ConnectWallet';
|
|
15
|
+
import { InstallWalletContent } from './SwapDetailsModal.InstallWallet';
|
|
19
16
|
|
|
20
17
|
export const WalletStateContent = (props: WalletStateContentProps) => {
|
|
21
|
-
const {
|
|
22
|
-
|
|
23
|
-
const [selectedWalletToConnect, setSelectedWalletToConnect] =
|
|
24
|
-
useState<WalletInfoWithExtra>();
|
|
25
|
-
const { getWalletInfo, state } = useWallets();
|
|
18
|
+
const { swap, onClose } = props;
|
|
19
|
+
const { state } = useWallets();
|
|
26
20
|
|
|
27
21
|
const currentStep = getCurrentStep(swap);
|
|
28
22
|
const currentStepWallet = currentStep
|
|
29
23
|
? getRelatedWalletOrNull(swap, currentStep)
|
|
30
24
|
: null;
|
|
31
|
-
|
|
25
|
+
|
|
32
26
|
const walletType = currentStepWallet?.walletType;
|
|
33
27
|
const walletState = walletType
|
|
34
28
|
? mapStatusToWalletState(state(walletType))
|
|
35
29
|
: null;
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
const { list } = useWalletList();
|
|
30
|
+
const currentNamespace = currentStep
|
|
31
|
+
? getCurrentNamespaceOfOrNull(swap, currentStep)
|
|
32
|
+
: null;
|
|
40
33
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
34
|
+
if (!walletType) {
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
44
37
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
warn(
|
|
49
|
-
new Error(
|
|
50
|
-
`It seems requested wallet to be connected is not available in the list. requested wallet: ${wallet}`
|
|
51
|
-
)
|
|
52
|
-
);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
};
|
|
38
|
+
if (walletState === WalletState.NOT_INSTALLED) {
|
|
39
|
+
return <InstallWalletContent walletType={walletType} />;
|
|
40
|
+
}
|
|
56
41
|
|
|
57
42
|
return (
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
{
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
container={getContainer()}
|
|
64
|
-
title={walletInfo.name}
|
|
65
|
-
image={walletInfo.img}
|
|
66
|
-
type={walletType}
|
|
67
|
-
state={walletState}
|
|
68
|
-
link={walletInfo.installLink}
|
|
69
|
-
disabled={walletButtonDisabled}
|
|
70
|
-
// TODO we need to show an error modal when user reject the connection
|
|
71
|
-
onClick={handleWalletItemClick}
|
|
72
|
-
/>
|
|
73
|
-
</WalletContainer>
|
|
74
|
-
)}
|
|
75
|
-
<StatefulConnectModal
|
|
76
|
-
id="widget-swap-details-modal"
|
|
77
|
-
wallet={selectedWalletToConnect}
|
|
78
|
-
onClose={() => {
|
|
79
|
-
setSelectedWalletToConnect(undefined);
|
|
80
|
-
}}
|
|
81
|
-
options={{
|
|
82
|
-
defaultSelectedChains: currentStepFromBlockchain
|
|
83
|
-
? [currentStepFromBlockchain]
|
|
84
|
-
: undefined,
|
|
85
|
-
}}
|
|
86
|
-
/>
|
|
87
|
-
</>
|
|
43
|
+
<ConnectWalletContent
|
|
44
|
+
wallet={currentStepWallet}
|
|
45
|
+
namespace={currentNamespace}
|
|
46
|
+
onClose={onClose}
|
|
47
|
+
/>
|
|
88
48
|
);
|
|
89
49
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { styled } from '@rango-dev/ui';
|
|
1
|
+
import { darkTheme, styled } from '@rango-dev/ui';
|
|
2
2
|
|
|
3
3
|
export const WalletContainer = styled('div', {
|
|
4
4
|
display: 'flex',
|
|
@@ -16,3 +16,22 @@ export const TooltipErrorContent = styled('div', {
|
|
|
16
16
|
export const ProfileBanner = styled('img', {
|
|
17
17
|
width: '100%',
|
|
18
18
|
});
|
|
19
|
+
|
|
20
|
+
export const WalletIcon = styled('div', {
|
|
21
|
+
position: 'relative',
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
export const WalletIconBadgeContainer = styled('span', {
|
|
25
|
+
position: 'absolute',
|
|
26
|
+
top: 0,
|
|
27
|
+
right: 0,
|
|
28
|
+
borderRadius: '50%',
|
|
29
|
+
width: '14px',
|
|
30
|
+
height: '14px',
|
|
31
|
+
display: 'flex',
|
|
32
|
+
padding: '$2',
|
|
33
|
+
backgroundColor: '$warning300',
|
|
34
|
+
[`.${darkTheme} &`]: {
|
|
35
|
+
$$color: '$warning600',
|
|
36
|
+
},
|
|
37
|
+
});
|