@rango-dev/ui 0.1.10-next.69 → 0.1.10-next.71
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/BlockchainSelector/BlockchainSelector.d.ts +3 -1
- package/dist/components/BlockchainsList/BlockchainsList.d.ts +3 -1
- package/dist/components/Checkbox/Checkbox.d.ts +1 -1
- package/dist/components/ColorPicker/ColorPicker.d.ts +9 -0
- package/dist/components/ColorPicker/ColorPicker.stories.d.ts +4 -0
- package/dist/components/ColorPicker/index.d.ts +1 -0
- package/dist/components/Modal/Modal.d.ts +1 -0
- package/dist/components/SecondaryPage/SecondaryPage.d.ts +1 -1
- package/dist/components/TextField/TextField.stories.d.ts +1 -1
- package/dist/components/TokenList/TokenList.d.ts +3 -1
- package/dist/components/TokenSelector/TokenSelector.d.ts +4 -2
- package/dist/components/index.d.ts +4 -0
- package/dist/ui.cjs.development.js +142 -31
- package/dist/ui.cjs.development.js.map +1 -1
- package/dist/ui.cjs.production.min.js +1 -1
- package/dist/ui.cjs.production.min.js.map +1 -1
- package/dist/ui.esm.js +139 -32
- package/dist/ui.esm.js.map +1 -1
- package/package.json +5 -3
- package/src/components/BlockchainSelector/BlockchainSelector.tsx +9 -3
- package/src/components/BlockchainsList/BlockchainsList.tsx +16 -6
- package/src/components/Checkbox/Checkbox.tsx +1 -1
- package/src/components/ColorPicker/ColorPicker.stories.tsx +36 -0
- package/src/components/ColorPicker/ColorPicker.tsx +81 -0
- package/src/components/ColorPicker/index.ts +1 -0
- package/src/components/LiquiditySourcesSelector/LiquiditySourcesSelector.tsx +1 -1
- package/src/components/Modal/Modal.tsx +20 -7
- package/src/components/Radio/Radio.tsx +8 -6
- package/src/components/SecondaryPage/SecondaryPage.tsx +1 -2
- package/src/components/Spacer/Spacer.stories.tsx +14 -1
- package/src/components/Spacer/Spacer.tsx +1 -1
- package/src/components/SwapContainer/SwapContainer.tsx +1 -0
- package/src/components/TextField/TextField.tsx +1 -1
- package/src/components/TokenList/TokenList.tsx +21 -9
- package/src/components/TokenSelector/TokenSelector.tsx +16 -3
- package/src/components/index.ts +4 -0
- package/src/helper/index.ts +1 -1
- package/dist/helpers.d.ts +0 -1
- package/src/helpers.ts +0 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rango-dev/ui",
|
|
3
|
-
"version": "0.1.10-next.
|
|
3
|
+
"version": "0.1.10-next.71",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"typings": "dist/index.d.ts",
|
|
@@ -75,9 +75,11 @@
|
|
|
75
75
|
"@radix-ui/react-radio-group": "^1.1.1",
|
|
76
76
|
"@radix-ui/react-switch": "^1.0.1",
|
|
77
77
|
"@radix-ui/react-tooltip": "^1.0.2",
|
|
78
|
-
"@rango-dev/wallets-shared": "^0.1.11-next.
|
|
78
|
+
"@rango-dev/wallets-shared": "^0.1.11-next.71",
|
|
79
79
|
"@stitches/react": "^1.2.8",
|
|
80
|
+
"@types/react-color": "^3.0.6",
|
|
80
81
|
"rango-sdk": "^0.1.11",
|
|
82
|
+
"react-color": "^2.19.3",
|
|
81
83
|
"react-virtualized-auto-sizer": "^1.0.7",
|
|
82
84
|
"react-window": "^1.8.8",
|
|
83
85
|
"react-window-infinite-loader": "^1.0.8"
|
|
@@ -85,5 +87,5 @@
|
|
|
85
87
|
"publishConfig": {
|
|
86
88
|
"access": "public"
|
|
87
89
|
},
|
|
88
|
-
"gitHead": "
|
|
90
|
+
"gitHead": "a06369ceaa20017adb7b949401111552987a53ee"
|
|
89
91
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { containsText } from '../../helpers';
|
|
3
2
|
import { BlockchainMeta } from 'rango-sdk';
|
|
4
3
|
import { BlockchainsList } from '../BlockchainsList';
|
|
5
4
|
import { SecondaryPage } from '../SecondaryPage/SecondaryPage';
|
|
@@ -7,6 +6,7 @@ import { Alert } from '../Alert';
|
|
|
7
6
|
import { Spinner } from '../Spinner';
|
|
8
7
|
import { styled } from '../../theme';
|
|
9
8
|
import { CSSProperties } from '@stitches/react';
|
|
9
|
+
import { containsText } from '../../helper';
|
|
10
10
|
|
|
11
11
|
const ListContainer = styled('div', {
|
|
12
12
|
height: '450px',
|
|
@@ -27,12 +27,14 @@ export type LoadingStatus = 'loading' | 'success' | 'failed';
|
|
|
27
27
|
export interface PropTypes {
|
|
28
28
|
type?: 'Source' | 'Destination';
|
|
29
29
|
list: BlockchainMeta[];
|
|
30
|
-
selected
|
|
30
|
+
selected?: BlockchainMeta | null;
|
|
31
31
|
onChange: (blockchain: BlockchainMeta) => void;
|
|
32
32
|
onBack?: () => void;
|
|
33
33
|
loadingStatus: LoadingStatus;
|
|
34
34
|
hasHeader?: boolean;
|
|
35
35
|
listContainerStyle?: CSSProperties;
|
|
36
|
+
multiSelect?: boolean;
|
|
37
|
+
selectedList?: BlockchainMeta[] | 'all';
|
|
36
38
|
}
|
|
37
39
|
|
|
38
40
|
export function BlockchainSelector(props: PropTypes) {
|
|
@@ -45,14 +47,16 @@ export function BlockchainSelector(props: PropTypes) {
|
|
|
45
47
|
loadingStatus,
|
|
46
48
|
hasHeader,
|
|
47
49
|
listContainerStyle,
|
|
50
|
+
multiSelect,
|
|
51
|
+
selectedList,
|
|
48
52
|
} = props;
|
|
49
53
|
|
|
50
54
|
return (
|
|
51
55
|
<SecondaryPage
|
|
52
56
|
textField={true}
|
|
57
|
+
hasHeader={hasHeader}
|
|
53
58
|
textFieldPlaceholder="Search Blockchain By Name"
|
|
54
59
|
title={`Select ${type} Network`}
|
|
55
|
-
hasHeader={hasHeader}
|
|
56
60
|
onBack={onBack}
|
|
57
61
|
Content={({ searchedFor }) => {
|
|
58
62
|
const filteredBlockchains = filterBlockchains(list, searchedFor);
|
|
@@ -75,6 +79,8 @@ export function BlockchainSelector(props: PropTypes) {
|
|
|
75
79
|
<BlockchainsList
|
|
76
80
|
list={filteredBlockchains}
|
|
77
81
|
selected={selected}
|
|
82
|
+
multiSelect={multiSelect}
|
|
83
|
+
selectedList={selectedList}
|
|
78
84
|
onChange={onChange}
|
|
79
85
|
/>
|
|
80
86
|
) : (
|
|
@@ -7,8 +7,10 @@ import { Typography } from '../Typography';
|
|
|
7
7
|
|
|
8
8
|
export interface PropTypes {
|
|
9
9
|
list: BlockchainMeta[];
|
|
10
|
-
selected
|
|
10
|
+
selected?: BlockchainMeta | null;
|
|
11
11
|
onChange: (blockchain: BlockchainMeta) => void;
|
|
12
|
+
multiSelect?: boolean;
|
|
13
|
+
selectedList?: BlockchainMeta[] | 'all';
|
|
12
14
|
}
|
|
13
15
|
|
|
14
16
|
const ListContainer = styled('div', {
|
|
@@ -27,7 +29,7 @@ const Image = styled('img', {
|
|
|
27
29
|
});
|
|
28
30
|
|
|
29
31
|
export function BlockchainsList(props: PropTypes) {
|
|
30
|
-
const { list, onChange } = props;
|
|
32
|
+
const { list, onChange, multiSelect, selectedList } = props;
|
|
31
33
|
const [selected, setSelected] = useState(props.selected);
|
|
32
34
|
|
|
33
35
|
const changeSelectedBlockchain = (blockchain: BlockchainMeta) => {
|
|
@@ -35,18 +37,26 @@ export function BlockchainsList(props: PropTypes) {
|
|
|
35
37
|
onChange(blockchain);
|
|
36
38
|
};
|
|
37
39
|
|
|
40
|
+
const isSelect = (name: string) => {
|
|
41
|
+
if (multiSelect && selectedList) {
|
|
42
|
+
return (
|
|
43
|
+
selectedList === 'all' ||
|
|
44
|
+
selectedList.findIndex((item) => name === item.name) > -1
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
return name === selected?.name;
|
|
48
|
+
};
|
|
49
|
+
|
|
38
50
|
return (
|
|
39
51
|
<ListContainer>
|
|
40
52
|
{list.map((blockchain, index) => {
|
|
41
53
|
return (
|
|
42
54
|
<Button
|
|
43
|
-
type={blockchain.name
|
|
55
|
+
type={isSelect(blockchain.name) ? 'primary' : undefined}
|
|
44
56
|
variant="outlined"
|
|
45
57
|
size="large"
|
|
46
58
|
prefix={<Image src={blockchain.logo} />}
|
|
47
|
-
suffix={
|
|
48
|
-
blockchain.name === selected?.name ? <FilledCircle /> : undefined
|
|
49
|
-
}
|
|
59
|
+
suffix={isSelect(blockchain.name) ? <FilledCircle /> : undefined}
|
|
50
60
|
align="start"
|
|
51
61
|
onClick={changeSelectedBlockchain.bind(null, blockchain)}
|
|
52
62
|
key={index}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import React, { useState } from 'react';
|
|
2
|
+
import { ComponentMeta } from '@storybook/react';
|
|
3
|
+
import { ColorPicker, PropTypes } from './ColorPicker';
|
|
4
|
+
|
|
5
|
+
export default {
|
|
6
|
+
title: 'Components/ColorPicker',
|
|
7
|
+
component: ColorPicker,
|
|
8
|
+
argTypes: {
|
|
9
|
+
place: {
|
|
10
|
+
name: 'place',
|
|
11
|
+
control: { type: 'select' },
|
|
12
|
+
options: ['top', 'bottom', 'left', 'right'],
|
|
13
|
+
defaultValue: 'top',
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
} as ComponentMeta<typeof ColorPicker>;
|
|
17
|
+
|
|
18
|
+
export const Main = (args: PropTypes) => {
|
|
19
|
+
const [color, setColor] = useState<string>('#5FA425');
|
|
20
|
+
return (
|
|
21
|
+
<div
|
|
22
|
+
style={{
|
|
23
|
+
height: 600,
|
|
24
|
+
display: 'flex',
|
|
25
|
+
justifyContent: 'center',
|
|
26
|
+
alignItems: 'center',
|
|
27
|
+
}}
|
|
28
|
+
>
|
|
29
|
+
<ColorPicker
|
|
30
|
+
{...args}
|
|
31
|
+
color={color}
|
|
32
|
+
onChangeColor={(color) => setColor(color.hex)}
|
|
33
|
+
/>
|
|
34
|
+
</div>
|
|
35
|
+
);
|
|
36
|
+
};
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import React, { useState } from 'react';
|
|
2
|
+
import { ChromePicker, ColorResult } from 'react-color';
|
|
3
|
+
import { styled } from '../../theme';
|
|
4
|
+
import { Button } from '../Button';
|
|
5
|
+
import { Typography } from '../Typography';
|
|
6
|
+
|
|
7
|
+
const Container = styled('div', {
|
|
8
|
+
position: 'relative',
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
const Color = styled('div', {
|
|
12
|
+
border: '1px solid $neutrals300',
|
|
13
|
+
borderRadius: '$5',
|
|
14
|
+
width: '$32',
|
|
15
|
+
height: '$32',
|
|
16
|
+
});
|
|
17
|
+
const Cover = styled('div', {
|
|
18
|
+
position: 'fixed',
|
|
19
|
+
top: '0px',
|
|
20
|
+
right: '0px',
|
|
21
|
+
bottom: '0px',
|
|
22
|
+
left: '0px',
|
|
23
|
+
});
|
|
24
|
+
const Popover = styled('div', {
|
|
25
|
+
position: 'absolute',
|
|
26
|
+
zIndex: '2',
|
|
27
|
+
variants: {
|
|
28
|
+
place: {
|
|
29
|
+
top: {
|
|
30
|
+
top: '-241px',
|
|
31
|
+
},
|
|
32
|
+
bottom: {},
|
|
33
|
+
left: {
|
|
34
|
+
top: '-50%',
|
|
35
|
+
left: '-225px',
|
|
36
|
+
},
|
|
37
|
+
right: {
|
|
38
|
+
top: '-50%',
|
|
39
|
+
right: '-225px',
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
export interface PropTypes {
|
|
45
|
+
color: string;
|
|
46
|
+
place: 'top' | 'bottom' | 'left' | 'right';
|
|
47
|
+
onChangeColor: (
|
|
48
|
+
color: ColorResult,
|
|
49
|
+
event: React.ChangeEvent<HTMLInputElement>
|
|
50
|
+
) => void;
|
|
51
|
+
label?: string;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function ColorPicker({ color, onChangeColor, label, place }: PropTypes) {
|
|
55
|
+
const [displayColorPicker, setDisplayColorPicker] = useState<boolean>(false);
|
|
56
|
+
|
|
57
|
+
return (
|
|
58
|
+
<Container>
|
|
59
|
+
<Typography mb={4} variant="body2">
|
|
60
|
+
{label}
|
|
61
|
+
</Typography>
|
|
62
|
+
<Button
|
|
63
|
+
variant="outlined"
|
|
64
|
+
prefix={<Color style={{ backgroundColor: color }} />}
|
|
65
|
+
fullWidth
|
|
66
|
+
align="start"
|
|
67
|
+
size="large"
|
|
68
|
+
onClick={() => setDisplayColorPicker((prev) => !prev)}
|
|
69
|
+
>
|
|
70
|
+
{color}
|
|
71
|
+
</Button>
|
|
72
|
+
|
|
73
|
+
{displayColorPicker && (
|
|
74
|
+
<Popover place={place}>
|
|
75
|
+
<Cover onClick={() => setDisplayColorPicker(false)} />
|
|
76
|
+
<ChromePicker color={color} onChange={onChangeColor} />
|
|
77
|
+
</Popover>
|
|
78
|
+
)}
|
|
79
|
+
</Container>
|
|
80
|
+
);
|
|
81
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { ColorPicker } from './ColorPicker';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { CSSProperties } from '@stitches/react';
|
|
2
2
|
import React from 'react';
|
|
3
|
-
import { containsText } from '../../
|
|
3
|
+
import { containsText } from '../../helper';
|
|
4
4
|
import { styled } from '../../theme';
|
|
5
5
|
import { LiquiditySource } from '../../types/meta';
|
|
6
6
|
import { Button } from '../Button';
|
|
@@ -10,6 +10,7 @@ export interface PropTypes {
|
|
|
10
10
|
open: boolean;
|
|
11
11
|
onClose: () => void;
|
|
12
12
|
content: React.ReactNode;
|
|
13
|
+
action?: React.ReactNode;
|
|
13
14
|
containerStyle?: CSSProperties;
|
|
14
15
|
contentStyle?: CSSProperties;
|
|
15
16
|
}
|
|
@@ -33,8 +34,12 @@ const ModalContainer = styled('div', {
|
|
|
33
34
|
display: 'flex',
|
|
34
35
|
flexDirection: 'column',
|
|
35
36
|
boxShadow: '$s',
|
|
37
|
+
zIndex: 10,
|
|
38
|
+
});
|
|
39
|
+
const Row = styled('div', {
|
|
40
|
+
display: 'flex',
|
|
41
|
+
alignItems: 'center',
|
|
36
42
|
});
|
|
37
|
-
|
|
38
43
|
const ModalHeader = styled('div', {
|
|
39
44
|
display: 'flex',
|
|
40
45
|
justifyContent: 'space-between',
|
|
@@ -43,17 +48,22 @@ const ModalHeader = styled('div', {
|
|
|
43
48
|
marginBottom: '$16',
|
|
44
49
|
});
|
|
45
50
|
|
|
46
|
-
const ContentContainer = styled('div', {
|
|
47
|
-
overflowY: 'scroll',
|
|
48
|
-
});
|
|
51
|
+
const ContentContainer = styled('div', {});
|
|
49
52
|
|
|
50
53
|
export function Modal(props: PropTypes) {
|
|
51
|
-
const {
|
|
54
|
+
const {
|
|
55
|
+
title,
|
|
56
|
+
content,
|
|
57
|
+
open,
|
|
58
|
+
onClose,
|
|
59
|
+
containerStyle,
|
|
60
|
+
action,
|
|
61
|
+
contentStyle,
|
|
62
|
+
} = props;
|
|
52
63
|
|
|
53
64
|
const handleBackDropClick = (event: React.MouseEvent<HTMLDivElement>) => {
|
|
54
65
|
if (event.target === event.currentTarget) onClose();
|
|
55
66
|
};
|
|
56
|
-
|
|
57
67
|
return (
|
|
58
68
|
<>
|
|
59
69
|
{open &&
|
|
@@ -62,7 +72,10 @@ export function Modal(props: PropTypes) {
|
|
|
62
72
|
<ModalContainer style={containerStyle}>
|
|
63
73
|
<ModalHeader>
|
|
64
74
|
<Typography variant="h4">{title}</Typography>
|
|
65
|
-
<
|
|
75
|
+
<Row>
|
|
76
|
+
{action}
|
|
77
|
+
<CloseIcon size={24} onClick={onClose} />
|
|
78
|
+
</Row>
|
|
66
79
|
</ModalHeader>
|
|
67
80
|
<ContentContainer style={contentStyle}>
|
|
68
81
|
{content}
|
|
@@ -23,9 +23,8 @@ const StyledRoot = styled(RadioGroup.Root, {
|
|
|
23
23
|
const ItemContainer = styled('div', {
|
|
24
24
|
display: 'flex',
|
|
25
25
|
alignItems: 'center',
|
|
26
|
-
marginRight: '$
|
|
26
|
+
marginRight: '$8',
|
|
27
27
|
});
|
|
28
|
-
|
|
29
28
|
const StyledItem = styled(RadioGroup.Item, {
|
|
30
29
|
backgroundColor: '$neutrals300',
|
|
31
30
|
width: '20px',
|
|
@@ -38,6 +37,10 @@ const StyledItem = styled(RadioGroup.Item, {
|
|
|
38
37
|
},
|
|
39
38
|
});
|
|
40
39
|
|
|
40
|
+
const Container = styled('div', {
|
|
41
|
+
display: 'flex',
|
|
42
|
+
});
|
|
43
|
+
|
|
41
44
|
const StyledIndicator = styled(RadioGroup.Indicator, {
|
|
42
45
|
display: 'flex',
|
|
43
46
|
alignItems: 'center',
|
|
@@ -56,7 +59,7 @@ const StyledIndicator = styled(RadioGroup.Indicator, {
|
|
|
56
59
|
});
|
|
57
60
|
|
|
58
61
|
const Label = styled('label', {
|
|
59
|
-
paddingLeft: '$
|
|
62
|
+
paddingLeft: '$8',
|
|
60
63
|
cursor: 'pointer',
|
|
61
64
|
});
|
|
62
65
|
|
|
@@ -66,13 +69,12 @@ export interface PropTypes {
|
|
|
66
69
|
onChange: (value: string) => void;
|
|
67
70
|
direction?: 'vertical' | 'horizontal';
|
|
68
71
|
style?: CSSProperties;
|
|
69
|
-
|
|
70
72
|
}
|
|
71
73
|
|
|
72
74
|
export function Radio(props: PropTypes) {
|
|
73
75
|
const { defaultValue, onChange, direction = 'vertical', style } = props;
|
|
74
76
|
return (
|
|
75
|
-
<
|
|
77
|
+
<Container>
|
|
76
78
|
<StyledRoot
|
|
77
79
|
onValueChange={onChange}
|
|
78
80
|
defaultValue={defaultValue}
|
|
@@ -90,6 +92,6 @@ export function Radio(props: PropTypes) {
|
|
|
90
92
|
</ItemContainer>
|
|
91
93
|
))}
|
|
92
94
|
</StyledRoot>
|
|
93
|
-
</
|
|
95
|
+
</Container>
|
|
94
96
|
);
|
|
95
97
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import React, { useState } from 'react';
|
|
2
|
-
// import { ChevronLeftIcon } from '@radix-ui/react-icons';
|
|
3
2
|
import { styled } from '../../theme';
|
|
4
3
|
import { AngleLeftIcon, SearchIcon } from '../Icon';
|
|
5
4
|
import { TextField } from '../TextField/TextField';
|
|
@@ -16,7 +15,7 @@ export type PropTypes = (
|
|
|
16
15
|
Content: React.ReactNode;
|
|
17
16
|
}
|
|
18
17
|
) & {
|
|
19
|
-
title
|
|
18
|
+
title?: string;
|
|
20
19
|
onBack?: () => void;
|
|
21
20
|
TopButton?: React.ReactNode;
|
|
22
21
|
Footer?: React.ReactNode;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ComponentMeta } from '@storybook/react';
|
|
2
2
|
import React from 'react';
|
|
3
|
+
import { Typography } from '../Typography';
|
|
3
4
|
import { Spacer, PropTypes } from './Spacer';
|
|
4
5
|
|
|
5
6
|
export default {
|
|
@@ -12,7 +13,19 @@ export default {
|
|
|
12
13
|
options: [12, 16, 18, 20],
|
|
13
14
|
defaultValue: 12,
|
|
14
15
|
},
|
|
16
|
+
direction: {
|
|
17
|
+
name: 'direction',
|
|
18
|
+
control: { type: 'select' },
|
|
19
|
+
options: ['vertical', 'horizontal'],
|
|
20
|
+
defaultValue: 'horizontal',
|
|
21
|
+
},
|
|
15
22
|
},
|
|
16
23
|
} as ComponentMeta<typeof Spacer>;
|
|
17
24
|
|
|
18
|
-
export const Main = (props: PropTypes) =>
|
|
25
|
+
export const Main = (props: PropTypes) => (
|
|
26
|
+
<div style={{ display: props.direction === 'horizontal' ? 'flex' : 'block' }}>
|
|
27
|
+
<Typography variant="body1">spacer </Typography>
|
|
28
|
+
<Spacer {...props} />
|
|
29
|
+
<Typography variant="body1">spacer</Typography>
|
|
30
|
+
</div>
|
|
31
|
+
);
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import React, { forwardRef, useEffect, useState } from 'react';
|
|
2
2
|
import { CommonProps } from 'react-window';
|
|
3
|
-
import { containsText } from '../../helpers';
|
|
4
3
|
import { styled } from '../../theme';
|
|
5
4
|
import { Token } from 'rango-sdk';
|
|
6
5
|
import { Button } from '../Button/Button';
|
|
7
6
|
import { Typography } from '../Typography';
|
|
8
7
|
import { VirtualizedList } from '../VirtualizedList/VirtualizedList';
|
|
9
8
|
import { CSSProperties } from '@stitches/react';
|
|
9
|
+
import { containsText } from '../../helper';
|
|
10
10
|
|
|
11
11
|
export interface TokenWithAmount extends Token {
|
|
12
12
|
balance?: {
|
|
@@ -18,9 +18,11 @@ export interface TokenWithAmount extends Token {
|
|
|
18
18
|
const PAGE_SIZE = 20;
|
|
19
19
|
export interface PropTypes {
|
|
20
20
|
list: TokenWithAmount[];
|
|
21
|
-
selected
|
|
21
|
+
selected?: TokenWithAmount | null;
|
|
22
22
|
searchedText: string;
|
|
23
23
|
onChange: (token: TokenWithAmount) => void;
|
|
24
|
+
multiSelect?: boolean;
|
|
25
|
+
selectedList?: TokenWithAmount[] | 'all';
|
|
24
26
|
}
|
|
25
27
|
|
|
26
28
|
const TokenImage = styled('img', {
|
|
@@ -58,7 +60,8 @@ const filterTokens = (
|
|
|
58
60
|
};
|
|
59
61
|
|
|
60
62
|
export function TokenList(props: PropTypes) {
|
|
61
|
-
const { list, searchedText, onChange } = props;
|
|
63
|
+
const { list, searchedText, onChange, multiSelect, selectedList } = props;
|
|
64
|
+
|
|
62
65
|
const [selected, setSelected] = useState(props.selected);
|
|
63
66
|
|
|
64
67
|
const changeSelected = (token: TokenWithAmount) => {
|
|
@@ -66,6 +69,20 @@ export function TokenList(props: PropTypes) {
|
|
|
66
69
|
onChange(token);
|
|
67
70
|
};
|
|
68
71
|
|
|
72
|
+
const isSelect = (token: Token) => {
|
|
73
|
+
if (multiSelect && selectedList) {
|
|
74
|
+
return (
|
|
75
|
+
selectedList === 'all' ||
|
|
76
|
+
selectedList
|
|
77
|
+
.map((item) => item.symbol + item.address)
|
|
78
|
+
.indexOf(token.symbol + token.address) > -1
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
return (
|
|
82
|
+
selected?.symbol === token.symbol && selected?.address === token.address
|
|
83
|
+
);
|
|
84
|
+
};
|
|
85
|
+
|
|
69
86
|
const Token = ({
|
|
70
87
|
filteredTokens,
|
|
71
88
|
index,
|
|
@@ -92,12 +109,7 @@ export function TokenList(props: PropTypes) {
|
|
|
92
109
|
size="large"
|
|
93
110
|
align="start"
|
|
94
111
|
onClick={changeSelected.bind(null, currentToken)}
|
|
95
|
-
type={
|
|
96
|
-
selected?.symbol === currentToken.symbol &&
|
|
97
|
-
selected?.address === currentToken.address
|
|
98
|
-
? 'primary'
|
|
99
|
-
: undefined
|
|
100
|
-
}
|
|
112
|
+
type={isSelect(currentToken) ? 'primary' : undefined}
|
|
101
113
|
prefix={<TokenImage src={currentToken.image} />}
|
|
102
114
|
suffix={
|
|
103
115
|
currentToken.balance?.amount && (
|
|
@@ -6,14 +6,25 @@ import { TokenWithAmount } from '../TokenList/TokenList';
|
|
|
6
6
|
export interface PropTypes {
|
|
7
7
|
list: TokenWithAmount[];
|
|
8
8
|
type?: 'Source' | 'Destination';
|
|
9
|
-
selected
|
|
9
|
+
selected?: TokenWithAmount;
|
|
10
10
|
onChange: (token: TokenWithAmount) => void;
|
|
11
|
-
onBack?: () => void;
|
|
12
11
|
hasHeader?: boolean;
|
|
12
|
+
multiSelect?: boolean;
|
|
13
|
+
onBack?: () => void;
|
|
14
|
+
selectedList?: TokenWithAmount[] | 'all';
|
|
13
15
|
}
|
|
14
16
|
|
|
15
17
|
export function TokenSelector(props: PropTypes) {
|
|
16
|
-
const {
|
|
18
|
+
const {
|
|
19
|
+
list,
|
|
20
|
+
type,
|
|
21
|
+
selected,
|
|
22
|
+
onChange,
|
|
23
|
+
hasHeader,
|
|
24
|
+
multiSelect,
|
|
25
|
+
selectedList,
|
|
26
|
+
onBack,
|
|
27
|
+
} = props;
|
|
17
28
|
|
|
18
29
|
return (
|
|
19
30
|
<SecondaryPage
|
|
@@ -27,6 +38,8 @@ export function TokenSelector(props: PropTypes) {
|
|
|
27
38
|
searchedText={searchedFor}
|
|
28
39
|
list={list}
|
|
29
40
|
selected={selected}
|
|
41
|
+
selectedList={selectedList}
|
|
42
|
+
multiSelect={multiSelect}
|
|
30
43
|
onChange={onChange}
|
|
31
44
|
/>
|
|
32
45
|
)}
|
package/src/components/index.ts
CHANGED
package/src/helper/index.ts
CHANGED
|
@@ -20,4 +20,4 @@ export const decimalNumber = (number = '0', toFixed: number) =>
|
|
|
20
20
|
parseFloat(number).toFixed(toFixed);
|
|
21
21
|
|
|
22
22
|
export const containsText = (text: string, searchText: string) =>
|
|
23
|
-
text.toLowerCase().
|
|
23
|
+
text.toLowerCase().includes(searchText.toLowerCase());
|
package/dist/helpers.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const containsText: (text: string, searchText: string) => boolean;
|
package/src/helpers.ts
DELETED