@rango-dev/widget-embedded 0.30.1 → 0.31.1-next.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.
- package/CHANGELOG.md +35 -0
- package/dist/components/ConfirmWalletsModal/ConfirmWallets.styles.d.ts +1 -653
- package/dist/components/ConfirmWalletsModal/ConfirmWallets.styles.d.ts.map +1 -1
- package/dist/components/ConfirmWalletsModal/ConfirmWalletsModal.d.ts.map +1 -1
- package/dist/components/ConfirmWalletsModal/WalletList.d.ts.map +1 -1
- package/dist/components/CustomDestination/CustomDestination.d.ts +4 -0
- package/dist/components/CustomDestination/CustomDestination.d.ts.map +1 -0
- package/dist/components/CustomDestination/CustomDestination.styles.d.ts +495 -0
- package/dist/components/CustomDestination/CustomDestination.styles.d.ts.map +1 -0
- package/dist/components/CustomDestination/CustomDestination.types.d.ts +7 -0
- package/dist/components/CustomDestination/CustomDestination.types.d.ts.map +1 -0
- package/dist/components/FilterSelector/FilterSelector.d.ts +4 -0
- package/dist/components/FilterSelector/FilterSelector.d.ts.map +1 -0
- package/dist/components/FilterSelector/FilterSelector.style.d.ts +962 -0
- package/dist/components/FilterSelector/FilterSelector.style.d.ts.map +1 -0
- package/dist/components/FilterSelector/FilterSelector.type.d.ts +14 -0
- package/dist/components/FilterSelector/FilterSelector.type.d.ts.map +1 -0
- package/dist/components/FilterSelector/FilterSelectorContent.d.ts +4 -0
- package/dist/components/FilterSelector/FilterSelectorContent.d.ts.map +1 -0
- package/dist/components/FilterSelector/index.d.ts +2 -0
- package/dist/components/FilterSelector/index.d.ts.map +1 -0
- package/dist/components/Quote/Quote.styles.d.ts +3 -3
- package/dist/components/RefreshModal/RefreshModal.styles.d.ts +3 -3
- package/dist/components/SearchInput/SearchInput.d.ts.map +1 -1
- package/dist/components/SwapDetails/SwapDetails.d.ts.map +1 -1
- package/dist/components/SwapDetails/SwapDetails.styles.d.ts.map +1 -1
- package/dist/components/SwapDetailsModal/SwapDetailsModal.WalletState.d.ts.map +1 -1
- package/dist/components/TokenList/TokenList.d.ts.map +1 -1
- package/dist/containers/Inputs/Inputs.d.ts.map +1 -1
- package/dist/containers/Wallets/Wallets.d.ts.map +1 -1
- package/dist/containers/WidgetInfo/WidgetInfo.d.ts.map +1 -1
- package/dist/containers/WidgetInfo/WidgetInfo.types.d.ts +5 -1
- package/dist/containers/WidgetInfo/WidgetInfo.types.d.ts.map +1 -1
- package/dist/hooks/useObserveBalanceChanges/index.d.ts +2 -0
- package/dist/hooks/useObserveBalanceChanges/index.d.ts.map +1 -0
- package/dist/hooks/useObserveBalanceChanges/useObserveBalanceChanges.d.ts +4 -0
- package/dist/hooks/useObserveBalanceChanges/useObserveBalanceChanges.d.ts.map +1 -0
- package/dist/hooks/usePrepareBlockchainList/usePrepareBlockchainList.helpers.d.ts +2 -2
- package/dist/hooks/useTheme.d.ts.map +1 -1
- package/dist/hooks/useUpdateQuoteInputs/index.d.ts +2 -0
- package/dist/hooks/useUpdateQuoteInputs/index.d.ts.map +1 -0
- package/dist/hooks/useUpdateQuoteInputs/useUpdateQuoteInputs.d.ts +3 -0
- package/dist/hooks/useUpdateQuoteInputs/useUpdateQuoteInputs.d.ts.map +1 -0
- package/dist/index.d.ts +4 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +4 -4
- package/dist/pages/HistoryPage.d.ts.map +1 -1
- package/dist/pages/Home.d.ts.map +1 -1
- package/dist/pages/WalletsPage.d.ts.map +1 -1
- package/dist/services/cacheService.d.ts +21 -0
- package/dist/services/cacheService.d.ts.map +1 -0
- package/dist/store/notification.d.ts.map +1 -1
- package/dist/store/slices/config.d.ts +2 -1
- package/dist/store/slices/config.d.ts.map +1 -1
- package/dist/store/slices/data.d.ts +2 -1
- package/dist/store/slices/data.d.ts.map +1 -1
- package/dist/store/utils/data.d.ts +20 -0
- package/dist/store/utils/data.d.ts.map +1 -0
- package/dist/store/utils/data.test.d.ts +2 -0
- package/dist/store/utils/data.test.d.ts.map +1 -0
- package/dist/store/utils/index.d.ts +2 -0
- package/dist/store/utils/index.d.ts.map +1 -0
- package/dist/test-utils/fixtures.d.ts +1 -0
- package/dist/test-utils/fixtures.d.ts.map +1 -1
- package/dist/types/config.d.ts +5 -0
- package/dist/types/config.d.ts.map +1 -1
- package/dist/types/event.d.ts +21 -15
- package/dist/types/event.d.ts.map +1 -1
- package/dist/types/notification.d.ts +1 -0
- package/dist/types/notification.d.ts.map +1 -1
- package/dist/types/quote.d.ts +9 -1
- package/dist/types/quote.d.ts.map +1 -1
- package/dist/types/wallets.d.ts +1 -1
- package/dist/types/wallets.d.ts.map +1 -1
- package/dist/utils/events.d.ts +8 -0
- package/dist/utils/events.d.ts.map +1 -0
- package/dist/utils/settings.d.ts +1 -1
- package/dist/utils/swap.d.ts +1 -1
- package/dist/utils/swap.d.ts.map +1 -1
- package/dist/widget-embedded.build.json +1 -1
- package/package.json +10 -10
- package/src/components/ConfirmWalletsModal/ConfirmWallets.styles.ts +1 -49
- package/src/components/ConfirmWalletsModal/ConfirmWalletsModal.tsx +61 -179
- package/src/components/ConfirmWalletsModal/WalletList.tsx +16 -4
- package/src/components/CustomDestination/CustomDestination.styles.ts +45 -0
- package/src/components/CustomDestination/CustomDestination.tsx +148 -0
- package/src/components/CustomDestination/CustomDestination.types.ts +7 -0
- package/src/components/FilterSelector/FilterSelector.style.ts +95 -0
- package/src/components/FilterSelector/FilterSelector.tsx +42 -0
- package/src/components/FilterSelector/FilterSelector.type.ts +15 -0
- package/src/components/FilterSelector/FilterSelectorContent.tsx +60 -0
- package/src/components/FilterSelector/index.ts +1 -0
- package/src/components/SearchInput/SearchInput.tsx +2 -0
- package/src/components/SwapDetails/SwapDetails.styles.ts +10 -0
- package/src/components/SwapDetails/SwapDetails.tsx +25 -13
- package/src/components/SwapDetailsModal/SwapDetailsModal.WalletState.tsx +28 -13
- package/src/components/TokenList/TokenList.tsx +8 -2
- package/src/containers/Inputs/Inputs.tsx +1 -0
- package/src/containers/Wallets/Wallets.tsx +7 -2
- package/src/containers/WidgetInfo/WidgetInfo.tsx +26 -0
- package/src/containers/WidgetInfo/WidgetInfo.types.ts +5 -1
- package/src/hooks/useObserveBalanceChanges/index.ts +1 -0
- package/src/hooks/useObserveBalanceChanges/useObserveBalanceChanges.ts +68 -0
- package/src/hooks/useTheme.ts +11 -5
- package/src/hooks/useUpdateQuoteInputs/index.ts +1 -0
- package/src/hooks/useUpdateQuoteInputs/useUpdateQuoteInputs.ts +50 -0
- package/src/index.ts +4 -0
- package/src/pages/HistoryPage.tsx +180 -26
- package/src/pages/Home.tsx +6 -3
- package/src/pages/WalletsPage.tsx +29 -13
- package/src/services/cacheService.ts +35 -0
- package/src/store/notification.ts +13 -1
- package/src/store/quote.ts +1 -1
- package/src/store/slices/config.ts +39 -1
- package/src/store/slices/data.test.ts +84 -0
- package/src/store/slices/data.ts +44 -24
- package/src/store/utils/data.test.ts +175 -0
- package/src/store/utils/data.ts +117 -0
- package/src/store/utils/index.ts +1 -0
- package/src/test-utils/fixtures.ts +14 -7
- package/src/types/config.ts +3 -1
- package/src/types/event.ts +32 -16
- package/src/types/notification.ts +1 -0
- package/src/types/quote.ts +11 -0
- package/src/types/wallets.ts +1 -1
- package/src/utils/events.ts +27 -0
- package/src/utils/swap.ts +4 -4
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { css, darkTheme, IconButton, styled } from '@rango-dev/ui';
|
|
2
|
+
|
|
3
|
+
export const IconContainer = styled('div', {
|
|
4
|
+
position: 'relative',
|
|
5
|
+
'&::before': {
|
|
6
|
+
position: 'absolute',
|
|
7
|
+
right: '1px',
|
|
8
|
+
top: '-1px',
|
|
9
|
+
width: '$8',
|
|
10
|
+
height: '$8',
|
|
11
|
+
borderRadius: '100%',
|
|
12
|
+
backgroundColor: '$neutral300',
|
|
13
|
+
[`.${darkTheme} &`]: {
|
|
14
|
+
backgroundColor: '$neutral400',
|
|
15
|
+
},
|
|
16
|
+
padding: '$2',
|
|
17
|
+
},
|
|
18
|
+
variants: {
|
|
19
|
+
isSelect: {
|
|
20
|
+
true: {
|
|
21
|
+
'&::before': {
|
|
22
|
+
content: '',
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
export const FilterButton = styled(IconButton, {
|
|
30
|
+
width: '$36',
|
|
31
|
+
height: '$36',
|
|
32
|
+
position: 'relative',
|
|
33
|
+
padding: '0',
|
|
34
|
+
overflow: 'unset',
|
|
35
|
+
backgroundColor: '$neutral300',
|
|
36
|
+
[`.${darkTheme} &`]: {
|
|
37
|
+
backgroundColor: '$neutral400',
|
|
38
|
+
},
|
|
39
|
+
'&:hover': {
|
|
40
|
+
backgroundColor: '$secondary100',
|
|
41
|
+
[`.${darkTheme} &`]: {
|
|
42
|
+
backgroundColor: '$neutral',
|
|
43
|
+
},
|
|
44
|
+
[`& ${IconContainer}::before`]: {
|
|
45
|
+
backgroundColor: '$secondary100',
|
|
46
|
+
[`.${darkTheme} &`]: {
|
|
47
|
+
backgroundColor: '$neutral',
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
variants: {
|
|
52
|
+
isSelect: {
|
|
53
|
+
true: {
|
|
54
|
+
border: '1px solid $secondary',
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
export const Badge = styled('div', {
|
|
61
|
+
position: 'absolute',
|
|
62
|
+
width: '$6',
|
|
63
|
+
height: '$6',
|
|
64
|
+
display: 'flex',
|
|
65
|
+
justifyContent: 'center',
|
|
66
|
+
alignItems: 'center',
|
|
67
|
+
borderRadius: '3px',
|
|
68
|
+
top: '$0',
|
|
69
|
+
right: '1px',
|
|
70
|
+
backgroundColor: '$secondary500',
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
export const FilterContainer = styled('div', {
|
|
74
|
+
padding: '$15',
|
|
75
|
+
borderRadius: '$sm',
|
|
76
|
+
width: '248px',
|
|
77
|
+
backgroundColor: '$background',
|
|
78
|
+
zIndex: 10,
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
export const centeredFlexContainer = css({
|
|
82
|
+
display: 'flex',
|
|
83
|
+
justifyContent: 'space-between',
|
|
84
|
+
alignItems: 'center',
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
export const FilterList = styled('ul', {
|
|
88
|
+
margin: 0,
|
|
89
|
+
listStyle: 'none',
|
|
90
|
+
height: '100%',
|
|
91
|
+
padding: 0,
|
|
92
|
+
'.item-start-container': {
|
|
93
|
+
paddingRight: '0 !important',
|
|
94
|
+
},
|
|
95
|
+
});
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { FilterSelectorPropTypes } from './FilterSelector.type';
|
|
2
|
+
|
|
3
|
+
import { FilterIcon, Popover } from '@rango-dev/ui';
|
|
4
|
+
import React from 'react';
|
|
5
|
+
|
|
6
|
+
import { getContainer } from '../../utils/common';
|
|
7
|
+
|
|
8
|
+
import { Badge, FilterButton, IconContainer } from './FilterSelector.style';
|
|
9
|
+
import { FilterSelectorContent } from './FilterSelectorContent';
|
|
10
|
+
|
|
11
|
+
export function FilterSelector(props: FilterSelectorPropTypes) {
|
|
12
|
+
const { onClickItem, onOpenChange, filterBy, list, open } = props;
|
|
13
|
+
return (
|
|
14
|
+
<div>
|
|
15
|
+
<Popover
|
|
16
|
+
open={open}
|
|
17
|
+
align="end"
|
|
18
|
+
onOpenChange={onOpenChange}
|
|
19
|
+
container={getContainer()}
|
|
20
|
+
content={
|
|
21
|
+
<FilterSelectorContent
|
|
22
|
+
list={list}
|
|
23
|
+
filterBy={filterBy}
|
|
24
|
+
onClickItem={(id) => {
|
|
25
|
+
onClickItem(id);
|
|
26
|
+
onOpenChange(false);
|
|
27
|
+
}}
|
|
28
|
+
/>
|
|
29
|
+
}>
|
|
30
|
+
<FilterButton
|
|
31
|
+
variant="default"
|
|
32
|
+
isSelect={!!filterBy}
|
|
33
|
+
onClick={() => onOpenChange(!props.open)}>
|
|
34
|
+
<IconContainer isSelect={!!filterBy}>
|
|
35
|
+
<FilterIcon size={16} color="black" />
|
|
36
|
+
{!!filterBy && <Badge />}
|
|
37
|
+
</IconContainer>
|
|
38
|
+
</FilterButton>
|
|
39
|
+
</Popover>
|
|
40
|
+
</div>
|
|
41
|
+
);
|
|
42
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export type PropTypes = {
|
|
2
|
+
filterBy: string;
|
|
3
|
+
onClickItem: (id: string) => void;
|
|
4
|
+
list: Array<FilterItem>;
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
export type FilterItem = {
|
|
8
|
+
id: string;
|
|
9
|
+
title: string;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export type FilterSelectorPropTypes = PropTypes & {
|
|
13
|
+
open: boolean;
|
|
14
|
+
onOpenChange: (open: boolean) => void;
|
|
15
|
+
};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { PropTypes } from './FilterSelector.type';
|
|
2
|
+
|
|
3
|
+
import { i18n } from '@lingui/core';
|
|
4
|
+
import {
|
|
5
|
+
Button,
|
|
6
|
+
Divider,
|
|
7
|
+
ListItemButton,
|
|
8
|
+
Radio,
|
|
9
|
+
RadioRoot,
|
|
10
|
+
Typography,
|
|
11
|
+
} from '@rango-dev/ui';
|
|
12
|
+
import React from 'react';
|
|
13
|
+
|
|
14
|
+
import {
|
|
15
|
+
centeredFlexContainer,
|
|
16
|
+
FilterContainer,
|
|
17
|
+
FilterList,
|
|
18
|
+
} from './FilterSelector.style';
|
|
19
|
+
|
|
20
|
+
export function FilterSelectorContent(props: PropTypes) {
|
|
21
|
+
const { filterBy: value, onClickItem } = props;
|
|
22
|
+
return (
|
|
23
|
+
<FilterContainer>
|
|
24
|
+
<div className={centeredFlexContainer()}>
|
|
25
|
+
<Typography size="small" variant="body">
|
|
26
|
+
{i18n.t('Status')}
|
|
27
|
+
</Typography>
|
|
28
|
+
<Button variant="ghost" size="xxsmall" onClick={() => onClickItem('')}>
|
|
29
|
+
{i18n.t('Reset')}
|
|
30
|
+
</Button>
|
|
31
|
+
</div>
|
|
32
|
+
<Divider size={10} />
|
|
33
|
+
<RadioRoot value={value}>
|
|
34
|
+
<FilterList>
|
|
35
|
+
{props.list.map((item, index) => {
|
|
36
|
+
return (
|
|
37
|
+
<ListItemButton
|
|
38
|
+
key={item.id}
|
|
39
|
+
style={{ height: '40px', width: '100%' }}
|
|
40
|
+
selected={false}
|
|
41
|
+
hasDivider={props.list.length - 1 != index}
|
|
42
|
+
id={item.id}
|
|
43
|
+
title={
|
|
44
|
+
<>
|
|
45
|
+
<Divider direction="horizontal" size={4} />
|
|
46
|
+
<Typography size="medium" variant="body">
|
|
47
|
+
{item.title}
|
|
48
|
+
</Typography>
|
|
49
|
+
</>
|
|
50
|
+
}
|
|
51
|
+
start={<Radio value={item.id} />}
|
|
52
|
+
onClick={onClickItem}
|
|
53
|
+
/>
|
|
54
|
+
);
|
|
55
|
+
})}
|
|
56
|
+
</FilterList>
|
|
57
|
+
</RadioRoot>
|
|
58
|
+
</FilterContainer>
|
|
59
|
+
);
|
|
60
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { FilterSelector } from './FilterSelector';
|
|
@@ -13,6 +13,7 @@ export function SearchInput(props: PropTypes) {
|
|
|
13
13
|
size,
|
|
14
14
|
onChange,
|
|
15
15
|
value,
|
|
16
|
+
style,
|
|
16
17
|
setValue,
|
|
17
18
|
...inputAttributes
|
|
18
19
|
} = props;
|
|
@@ -41,6 +42,7 @@ export function SearchInput(props: PropTypes) {
|
|
|
41
42
|
padding: 10,
|
|
42
43
|
borderRadius: 25,
|
|
43
44
|
alignItems: 'center',
|
|
45
|
+
...style,
|
|
44
46
|
}}
|
|
45
47
|
size={size}
|
|
46
48
|
value={value}
|
|
@@ -11,6 +11,16 @@ export const Container = styled('div', {
|
|
|
11
11
|
|
|
12
12
|
export const HeaderDetails = styled('div', {
|
|
13
13
|
width: '100%',
|
|
14
|
+
'& ._icon-button': {
|
|
15
|
+
'&:hover': {
|
|
16
|
+
'& svg': {
|
|
17
|
+
color: '$secondary550',
|
|
18
|
+
[`.${darkTheme} &`]: {
|
|
19
|
+
color: '$secondary500',
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
},
|
|
14
24
|
});
|
|
15
25
|
|
|
16
26
|
export const StepsList = styled(ScrollableArea, {
|
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
Button,
|
|
12
12
|
CopyIcon,
|
|
13
13
|
Divider,
|
|
14
|
+
DoneIcon,
|
|
14
15
|
IconButton,
|
|
15
16
|
QuoteCost,
|
|
16
17
|
RangoExplorerIcon,
|
|
@@ -88,7 +89,7 @@ export function SwapDetails(props: SwapDetailsProps) {
|
|
|
88
89
|
const retry = useQuoteStore.use.retry();
|
|
89
90
|
const isActiveTab = useUiStore.use.isActiveTab();
|
|
90
91
|
const navigate = useNavigate();
|
|
91
|
-
const [
|
|
92
|
+
const [isCopied, handleCopy] = useCopyToClipboard(RESET_INTERVAL);
|
|
92
93
|
const listRef = useRef<HTMLDivElement | null>(null);
|
|
93
94
|
const [modalState, setModalState] = useState<ModalState>(null);
|
|
94
95
|
const [showCompletedModal, setShowCompletedModal] = useState<
|
|
@@ -187,13 +188,7 @@ export function SwapDetails(props: SwapDetailsProps) {
|
|
|
187
188
|
)?.diagnosisUrl;
|
|
188
189
|
|
|
189
190
|
const outputUsdValue = numberToString(
|
|
190
|
-
parseFloat(
|
|
191
|
-
numberToString(
|
|
192
|
-
outputAmount,
|
|
193
|
-
TOKEN_AMOUNT_MIN_DECIMALS,
|
|
194
|
-
TOKEN_AMOUNT_MAX_DECIMALS
|
|
195
|
-
)
|
|
196
|
-
) * (lastStep.toUsdPrice || 0),
|
|
191
|
+
parseFloat(outputAmount || '0') * (lastStep.toUsdPrice || 0),
|
|
197
192
|
USD_VALUE_MIN_DECIMALS,
|
|
198
193
|
USD_VALUE_MAX_DECIMALS
|
|
199
194
|
);
|
|
@@ -318,11 +313,28 @@ export function SwapDetails(props: SwapDetailsProps) {
|
|
|
318
313
|
<Typography variant="label" size="small" color="neutral700">
|
|
319
314
|
{requestId}
|
|
320
315
|
</Typography>
|
|
321
|
-
<
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
316
|
+
<Tooltip
|
|
317
|
+
container={getContainer()}
|
|
318
|
+
content={
|
|
319
|
+
isCopied
|
|
320
|
+
? i18n.t('Copied To Clipboard')
|
|
321
|
+
: i18n.t('Copy Request ID')
|
|
322
|
+
}
|
|
323
|
+
open={isCopied || undefined}
|
|
324
|
+
side="bottom"
|
|
325
|
+
alignOffset={-16}
|
|
326
|
+
align="end">
|
|
327
|
+
<IconButton
|
|
328
|
+
variant="ghost"
|
|
329
|
+
onClick={handleCopy.bind(null, requestId || '')}>
|
|
330
|
+
{isCopied ? (
|
|
331
|
+
<DoneIcon size={16} color="secondary" />
|
|
332
|
+
) : (
|
|
333
|
+
<CopyIcon size={16} color="gray" />
|
|
334
|
+
)}
|
|
335
|
+
</IconButton>
|
|
336
|
+
</Tooltip>
|
|
337
|
+
|
|
326
338
|
<StyledLink
|
|
327
339
|
target="_blank"
|
|
328
340
|
href={`${SCANNER_BASE_URL}/swap/${requestId}`}>
|
|
@@ -68,6 +68,33 @@ export const WalletStateContent = (props: WalletStateContentProps) => {
|
|
|
68
68
|
}
|
|
69
69
|
};
|
|
70
70
|
|
|
71
|
+
const handleWalletItemClick = () => {
|
|
72
|
+
if (!!walletType && !!walletInfo) {
|
|
73
|
+
if (!!walletInfo.namespaces?.length) {
|
|
74
|
+
if (walletInfo.namespaces.length > 1) {
|
|
75
|
+
setNamespacesModalState({
|
|
76
|
+
open: true,
|
|
77
|
+
providerType: walletType,
|
|
78
|
+
providerImage: walletInfo.img,
|
|
79
|
+
availableNamespaces: walletInfo.namespaces,
|
|
80
|
+
singleNamespace: walletInfo.singleNamespace,
|
|
81
|
+
});
|
|
82
|
+
} else if (walletInfo.needsDerivationPath) {
|
|
83
|
+
setDerivationPathModalState({
|
|
84
|
+
open: true,
|
|
85
|
+
providerType: walletType,
|
|
86
|
+
providerImage: walletInfo.img,
|
|
87
|
+
namespace: walletInfo.namespaces[0],
|
|
88
|
+
});
|
|
89
|
+
} else {
|
|
90
|
+
connect(walletType).catch((error) => debug(error));
|
|
91
|
+
}
|
|
92
|
+
} else {
|
|
93
|
+
connect(walletType).catch((error) => debug(error));
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
|
|
71
98
|
const handleConfirmNamespaces = (selectedNamespaces: Namespace[]) => {
|
|
72
99
|
if (
|
|
73
100
|
!!walletInfo?.needsDerivationPath &&
|
|
@@ -117,19 +144,7 @@ export const WalletStateContent = (props: WalletStateContentProps) => {
|
|
|
117
144
|
link={walletInfo.installLink}
|
|
118
145
|
disabled={walletButtonDisabled}
|
|
119
146
|
// TODO we need to show an error modal when user reject the connection
|
|
120
|
-
onClick={
|
|
121
|
-
if (walletInfo.namespaces) {
|
|
122
|
-
setNamespacesModalState({
|
|
123
|
-
open: true,
|
|
124
|
-
providerType: walletType,
|
|
125
|
-
providerImage: walletInfo.img,
|
|
126
|
-
availableNamespaces: walletInfo.namespaces,
|
|
127
|
-
singleNamespace: walletInfo.singleNamespace,
|
|
128
|
-
});
|
|
129
|
-
} else {
|
|
130
|
-
connect(walletType).catch((error) => debug(error));
|
|
131
|
-
}
|
|
132
|
-
}}
|
|
147
|
+
onClick={handleWalletItemClick}
|
|
133
148
|
/>
|
|
134
149
|
</WalletContainer>
|
|
135
150
|
)}
|
|
@@ -17,6 +17,7 @@ import {
|
|
|
17
17
|
} from '@rango-dev/ui';
|
|
18
18
|
import React, { useEffect, useState } from 'react';
|
|
19
19
|
|
|
20
|
+
import { useObserveBalanceChanges } from '../../hooks/useObserveBalanceChanges';
|
|
20
21
|
import { useAppStore } from '../../store/AppStore';
|
|
21
22
|
import { useWalletsStore } from '../../store/wallets';
|
|
22
23
|
import { createTintsAndShades } from '../../utils/colors';
|
|
@@ -99,6 +100,11 @@ export function TokenList(props: PropTypes) {
|
|
|
99
100
|
const [hasNextPage, setHasNextPage] = useState<boolean>(true);
|
|
100
101
|
const { getBalanceFor, loading: loadingWallet } = useWalletsStore();
|
|
101
102
|
const { isTokenPinned } = useAppStore();
|
|
103
|
+
/**
|
|
104
|
+
* We can create the key by hashing the list of tokens,
|
|
105
|
+
* but if the list is large, the memory usage and cost of comparisons may be high.
|
|
106
|
+
*/
|
|
107
|
+
const { balanceKey } = useObserveBalanceChanges(selectedBlockchain);
|
|
102
108
|
|
|
103
109
|
const loadNextPage = () => {
|
|
104
110
|
setTokens(list.slice(0, tokens.length + PAGE_SIZE));
|
|
@@ -110,7 +116,7 @@ export function TokenList(props: PropTypes) {
|
|
|
110
116
|
|
|
111
117
|
useEffect(() => {
|
|
112
118
|
setTokens(list.slice(0, PAGE_SIZE));
|
|
113
|
-
}, [list.length, selectedBlockchain]);
|
|
119
|
+
}, [list.length, selectedBlockchain, balanceKey]);
|
|
114
120
|
|
|
115
121
|
const renderList = () => {
|
|
116
122
|
if (!tokens.length && !!searchedFor) {
|
|
@@ -244,7 +250,7 @@ export function TokenList(props: PropTypes) {
|
|
|
244
250
|
);
|
|
245
251
|
}}
|
|
246
252
|
totalCount={tokens.length}
|
|
247
|
-
key={`${selectedBlockchain}-${searchedFor}`}
|
|
253
|
+
key={`${selectedBlockchain}-${searchedFor}-${balanceKey}`}
|
|
248
254
|
/>
|
|
249
255
|
);
|
|
250
256
|
};
|
|
@@ -31,7 +31,12 @@ export const WidgetContext = createContext<WidgetContextInterface>({
|
|
|
31
31
|
});
|
|
32
32
|
|
|
33
33
|
function Main(props: PropsWithChildren<PropTypes>) {
|
|
34
|
-
const {
|
|
34
|
+
const {
|
|
35
|
+
updateConfig,
|
|
36
|
+
updateSettings,
|
|
37
|
+
fetch: fetchMeta,
|
|
38
|
+
fetchStatus,
|
|
39
|
+
} = useAppStore();
|
|
35
40
|
const blockchains = useAppStore().blockchains();
|
|
36
41
|
const { findToken } = useAppStore();
|
|
37
42
|
const config = useAppStore().config;
|
|
@@ -61,7 +66,7 @@ function Main(props: PropsWithChildren<PropTypes>) {
|
|
|
61
66
|
dappConfig: props.config,
|
|
62
67
|
};
|
|
63
68
|
}
|
|
64
|
-
}, [props.config]);
|
|
69
|
+
}, [props.config, fetchStatus]);
|
|
65
70
|
|
|
66
71
|
const evmBasedChainNames = blockchains
|
|
67
72
|
.filter(isEvmBlockchain)
|
|
@@ -4,6 +4,7 @@ import { useManager } from '@rango-dev/queue-manager-react';
|
|
|
4
4
|
import React, { createContext, useContext } from 'react';
|
|
5
5
|
|
|
6
6
|
import { useLanguage } from '../../hooks/useLanguage';
|
|
7
|
+
import { useUpdateQuoteInputs } from '../../hooks/useUpdateQuoteInputs/useUpdateQuoteInputs';
|
|
7
8
|
import { useAppStore } from '../../store/AppStore';
|
|
8
9
|
import { useNotificationStore } from '../../store/notification';
|
|
9
10
|
import { useQuoteStore } from '../../store/quote';
|
|
@@ -35,6 +36,9 @@ export function WidgetInfo(props: React.PropsWithChildren) {
|
|
|
35
36
|
const resetLanguage = useLanguage().resetLanguage;
|
|
36
37
|
const notifications = useNotificationStore().getNotifications();
|
|
37
38
|
const clearNotifications = useNotificationStore().clearNotifications;
|
|
39
|
+
const updateQuoteInputs = useUpdateQuoteInputs();
|
|
40
|
+
const { fromBlockchain, toBlockchain, fromToken, toToken, inputAmount } =
|
|
41
|
+
useQuoteStore();
|
|
38
42
|
|
|
39
43
|
// eslint-disable-next-line react/jsx-no-constructed-context-values
|
|
40
44
|
const value: WidgetInfoContextInterface = {
|
|
@@ -59,6 +63,28 @@ export function WidgetInfo(props: React.PropsWithChildren) {
|
|
|
59
63
|
list: notifications,
|
|
60
64
|
clearAll: clearNotifications,
|
|
61
65
|
},
|
|
66
|
+
quote: {
|
|
67
|
+
quoteInputs: {
|
|
68
|
+
fromBlockchain: fromBlockchain?.name ?? null,
|
|
69
|
+
fromToken: fromToken
|
|
70
|
+
? {
|
|
71
|
+
symbol: fromToken.symbol,
|
|
72
|
+
blockchain: fromToken.blockchain,
|
|
73
|
+
address: fromToken.address,
|
|
74
|
+
}
|
|
75
|
+
: null,
|
|
76
|
+
toBlockchain: toBlockchain?.name ?? null,
|
|
77
|
+
toToken: toToken
|
|
78
|
+
? {
|
|
79
|
+
symbol: toToken.symbol,
|
|
80
|
+
blockchain: toToken.blockchain,
|
|
81
|
+
address: toToken.address,
|
|
82
|
+
}
|
|
83
|
+
: null,
|
|
84
|
+
requestAmount: inputAmount,
|
|
85
|
+
},
|
|
86
|
+
updateQuoteInputs,
|
|
87
|
+
},
|
|
62
88
|
};
|
|
63
89
|
|
|
64
90
|
return (
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { WidgetHistory } from './WidgetInfo.helpers';
|
|
2
2
|
import type { FetchStatus, FindToken } from '../../store/slices/data';
|
|
3
3
|
import type { ConnectedWallet } from '../../store/wallets';
|
|
4
|
-
import type { Wallet } from '../../types';
|
|
4
|
+
import type { QuoteInputs, UpdateQuoteInputs, Wallet } from '../../types';
|
|
5
5
|
import type { Notification } from '../../types/notification';
|
|
6
6
|
import type { BlockchainMeta, SwapperMeta, Token } from 'rango-sdk';
|
|
7
7
|
|
|
@@ -27,4 +27,8 @@ export interface WidgetInfoContextInterface {
|
|
|
27
27
|
list: Notification[];
|
|
28
28
|
clearAll: () => void;
|
|
29
29
|
};
|
|
30
|
+
quote: {
|
|
31
|
+
quoteInputs: QuoteInputs;
|
|
32
|
+
updateQuoteInputs: UpdateQuoteInputs;
|
|
33
|
+
};
|
|
30
34
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useObserveBalanceChanges } from './useObserveBalanceChanges';
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type { WalletEventData } from '../../types';
|
|
2
|
+
|
|
3
|
+
import { useWallets } from '@rango-dev/wallets-react';
|
|
4
|
+
import { useEffect, useRef, useState } from 'react';
|
|
5
|
+
|
|
6
|
+
import { widgetEventEmitter } from '../../services/eventEmitter';
|
|
7
|
+
import { useWalletsStore } from '../../store/wallets';
|
|
8
|
+
import { WalletEventTypes, WidgetEvents } from '../../types';
|
|
9
|
+
|
|
10
|
+
// A hook to listen for and detect changes in balances on a specific blockchain.
|
|
11
|
+
export function useObserveBalanceChanges(selectedBlockchain?: string) {
|
|
12
|
+
const { connectedWallets } = useWalletsStore();
|
|
13
|
+
const { getWalletInfo } = useWallets();
|
|
14
|
+
const prevFetchingBalanceWallets = useRef<string[]>([]);
|
|
15
|
+
// The "balanceKey" will be updated and incremented after each change in the balance for a blockchain.
|
|
16
|
+
const [balanceKey, setBalanceKey] = useState(0);
|
|
17
|
+
|
|
18
|
+
useEffect(() => {
|
|
19
|
+
const handleWalletEvent = (event: WalletEventData) => {
|
|
20
|
+
if (event.type === WalletEventTypes.DISCONNECT) {
|
|
21
|
+
const walletInfo = getWalletInfo(event.payload.walletType);
|
|
22
|
+
const blockchainSupported = walletInfo.supportedChains.some(
|
|
23
|
+
(chain) => chain.name === selectedBlockchain
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
if (blockchainSupported) {
|
|
27
|
+
setBalanceKey((prev) => prev + 1);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
widgetEventEmitter.on(WidgetEvents.WalletEvent, handleWalletEvent);
|
|
33
|
+
|
|
34
|
+
if (!selectedBlockchain) {
|
|
35
|
+
return setBalanceKey((prev) => prev + 1);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const supportedWallets = connectedWallets.filter(
|
|
39
|
+
(wallet) => wallet.chain === selectedBlockchain
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
supportedWallets.forEach((wallet) => {
|
|
43
|
+
const { walletType } = wallet;
|
|
44
|
+
const walletIsAlreadyFetching =
|
|
45
|
+
prevFetchingBalanceWallets.current.includes(walletType);
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Watching for changes in "wallet.balances.length" is not accurate.
|
|
49
|
+
* Additionally, checking the equality of previous and current balances for a specific blockchain is resource-intensive, so we avoid these methods.
|
|
50
|
+
*/
|
|
51
|
+
if (wallet.loading && !walletIsAlreadyFetching) {
|
|
52
|
+
prevFetchingBalanceWallets.current =
|
|
53
|
+
prevFetchingBalanceWallets.current.concat(walletType);
|
|
54
|
+
} else if (!wallet.loading && walletIsAlreadyFetching) {
|
|
55
|
+
prevFetchingBalanceWallets.current =
|
|
56
|
+
prevFetchingBalanceWallets.current.filter(
|
|
57
|
+
(prevWallet) => prevWallet !== walletType
|
|
58
|
+
);
|
|
59
|
+
setBalanceKey((prev) => prev + 1);
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
return () =>
|
|
64
|
+
widgetEventEmitter.off(WidgetEvents.WalletEvent, handleWalletEvent);
|
|
65
|
+
}, [connectedWallets, selectedBlockchain, getWalletInfo]);
|
|
66
|
+
|
|
67
|
+
return { balanceKey };
|
|
68
|
+
}
|
package/src/hooks/useTheme.ts
CHANGED
|
@@ -15,6 +15,13 @@ import {
|
|
|
15
15
|
} from '../utils/configs';
|
|
16
16
|
import { customizedThemeTokens } from '../utils/ui';
|
|
17
17
|
|
|
18
|
+
function doesWindowPreferDarkColorScheme() {
|
|
19
|
+
return (
|
|
20
|
+
window.matchMedia &&
|
|
21
|
+
window.matchMedia('(prefers-color-scheme: dark)').matches
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
|
|
18
25
|
export function useTheme(props: WidgetTheme) {
|
|
19
26
|
const {
|
|
20
27
|
colors,
|
|
@@ -23,7 +30,9 @@ export function useTheme(props: WidgetTheme) {
|
|
|
23
30
|
secondaryBorderRadius = DEFAULT_SECONDARY_RADIUS,
|
|
24
31
|
} = props;
|
|
25
32
|
|
|
26
|
-
const [OSTheme, setOSTheme] = useState(
|
|
33
|
+
const [OSTheme, setOSTheme] = useState(
|
|
34
|
+
doesWindowPreferDarkColorScheme() ? 'dark' : 'light'
|
|
35
|
+
);
|
|
27
36
|
|
|
28
37
|
const { theme } = useAppStore();
|
|
29
38
|
|
|
@@ -64,10 +73,7 @@ export function useTheme(props: WidgetTheme) {
|
|
|
64
73
|
}
|
|
65
74
|
};
|
|
66
75
|
|
|
67
|
-
if (
|
|
68
|
-
window.matchMedia &&
|
|
69
|
-
window.matchMedia('(prefers-color-scheme: dark)').matches
|
|
70
|
-
) {
|
|
76
|
+
if (doesWindowPreferDarkColorScheme()) {
|
|
71
77
|
setOSTheme('dark');
|
|
72
78
|
}
|
|
73
79
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useUpdateQuoteInputs } from './useUpdateQuoteInputs';
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { UpdateQuoteInputs } from '../../types';
|
|
2
|
+
|
|
3
|
+
import { useAppStore } from '../../store/AppStore';
|
|
4
|
+
import { useQuoteStore } from '../../store/quote';
|
|
5
|
+
|
|
6
|
+
// This hook provides a function to update quote inputs using fewer and simpler parameters.
|
|
7
|
+
export function useUpdateQuoteInputs() {
|
|
8
|
+
const { findToken } = useAppStore();
|
|
9
|
+
const blockchains = useAppStore().blockchains();
|
|
10
|
+
const tokens = useAppStore().tokens();
|
|
11
|
+
const {
|
|
12
|
+
setFromBlockchain,
|
|
13
|
+
setFromToken,
|
|
14
|
+
setToBlockchain,
|
|
15
|
+
setToToken,
|
|
16
|
+
setInputAmount,
|
|
17
|
+
} = useQuoteStore();
|
|
18
|
+
|
|
19
|
+
const updateQuoteInputs: UpdateQuoteInputs = (params) => {
|
|
20
|
+
const { fromBlockchain, fromToken, toBlockchain, toToken, requestAmount } =
|
|
21
|
+
params;
|
|
22
|
+
const meta = { blockchains, tokens };
|
|
23
|
+
|
|
24
|
+
if (fromBlockchain !== undefined) {
|
|
25
|
+
const blockchainMeta =
|
|
26
|
+
blockchains.find((blockchain) => blockchain.name === fromBlockchain) ??
|
|
27
|
+
null;
|
|
28
|
+
setFromBlockchain(blockchainMeta);
|
|
29
|
+
}
|
|
30
|
+
if (fromToken !== undefined) {
|
|
31
|
+
const token = fromToken ? findToken(fromToken) ?? null : null;
|
|
32
|
+
setFromToken({ meta, token });
|
|
33
|
+
}
|
|
34
|
+
if (toBlockchain !== undefined) {
|
|
35
|
+
const blockchainMeta =
|
|
36
|
+
blockchains.find((blockchain) => blockchain.name === toBlockchain) ??
|
|
37
|
+
null;
|
|
38
|
+
setToBlockchain(blockchainMeta);
|
|
39
|
+
}
|
|
40
|
+
if (toToken !== undefined) {
|
|
41
|
+
const token = toToken ? findToken(toToken) ?? null : null;
|
|
42
|
+
setToToken({ meta, token });
|
|
43
|
+
}
|
|
44
|
+
if (requestAmount !== undefined) {
|
|
45
|
+
setInputAmount(requestAmount);
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
return updateQuoteInputs;
|
|
50
|
+
}
|