@rango-dev/ui 0.1.11-next.2 → 0.1.11-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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rango-dev/ui",
3
- "version": "0.1.11-next.2",
3
+ "version": "0.1.11-next.4",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
@@ -7,6 +7,7 @@ import { Skeleton } from '../Skeleton';
7
7
  import { Spinner } from '../Spinner';
8
8
  import { BestRouteResponse } from 'rango-sdk';
9
9
  import { Tooltip } from '../Tooltip';
10
+ import { Image } from '../common';
10
11
 
11
12
  const Container = styled('div', {
12
13
  borderRadius: '$5',
@@ -48,10 +49,6 @@ const HR = styled('hr', {
48
49
  margin: '$8 0',
49
50
  });
50
51
 
51
- const SwapperLogo = styled('img', {
52
- width: '$16',
53
- height: '$16',
54
- });
55
52
  const RelativeContainer = styled('div', {
56
53
  position: 'relative',
57
54
  });
@@ -208,7 +205,7 @@ export function BestRoute(props: PropsWithChildren<PropTypes>) {
208
205
  )}
209
206
  <SwapperContainer>
210
207
  <Line />
211
- <SwapperLogo src={swap.swapperLogo} alt={swap.swapperId} />
208
+ <Image src={swap.swapperLogo} alt={swap.swapperId} size={20} />
212
209
  <Line />
213
210
  </SwapperContainer>
214
211
 
@@ -2,7 +2,7 @@ import React, { useState } from 'react';
2
2
  import { styled } from '../../theme';
3
3
  import { BlockchainMeta } from 'rango-sdk';
4
4
  import { Button } from '../Button/Button';
5
- import { FilledCircle } from '../common';
5
+ import { FilledCircle, Image } from '../common';
6
6
  import { Typography } from '../Typography';
7
7
 
8
8
  export interface PropTypes {
@@ -22,10 +22,8 @@ const ListContainer = styled('div', {
22
22
  height: '100%',
23
23
  });
24
24
 
25
- const Image = styled('img', {
26
- width: '1.5rem',
27
- maxHeight: '1.5rem',
28
- marginRight: '$4',
25
+ const ImageContainer = styled('div', {
26
+ paddingRight: '$4',
29
27
  });
30
28
 
31
29
  export function BlockchainsList(props: PropTypes) {
@@ -55,7 +53,11 @@ export function BlockchainsList(props: PropTypes) {
55
53
  type={isSelect(blockchain.name) ? 'primary' : undefined}
56
54
  variant="outlined"
57
55
  size="large"
58
- prefix={<Image src={blockchain.logo} />}
56
+ prefix={
57
+ <ImageContainer>
58
+ <Image size={24} src={blockchain.logo} />
59
+ </ImageContainer>
60
+ }
59
61
  suffix={isSelect(blockchain.name) ? <FilledCircle /> : undefined}
60
62
  align="start"
61
63
  onClick={changeSelectedBlockchain.bind(null, blockchain)}
@@ -31,6 +31,11 @@ export const SvgWithStrokeColor = styled('svg', {
31
31
  stroke: '$$color',
32
32
  },
33
33
  },
34
+ disabled: {
35
+ true: {
36
+ stroke: '$neutrals400',
37
+ },
38
+ },
34
39
  },
35
40
  });
36
41
 
@@ -65,5 +70,10 @@ export const SvgWithFillColor = styled('svg', {
65
70
  fill: '$$color',
66
71
  },
67
72
  },
73
+ disabled: {
74
+ true: {
75
+ stroke: '$neutrals400',
76
+ },
77
+ },
68
78
  },
69
79
  });
@@ -3,6 +3,7 @@ import * as React from 'react';
3
3
  export interface IconProps extends React.SVGAttributes<SVGElement> {
4
4
  size?: 12 | 16 | 18 | 20 | 24 | 28 | 32 | 36 | 40;
5
5
  color?: 'primary' | 'error' | 'warning' | 'success' | 'black' | 'white';
6
+ disabled?: boolean;
6
7
  }
7
8
 
8
9
  export type Icon =
@@ -9,6 +9,7 @@ import { Typography } from '../Typography';
9
9
  import { Spinner } from '../Spinner';
10
10
  import { LoadingFailedAlert } from '../Alert/LoadingFailedAlert';
11
11
  import { NotFoundAlert } from '../Alert/NotFoundAlert';
12
+ import { Image } from '../common';
12
13
 
13
14
  const groupLiquiditySources = (
14
15
  liquiditySources: LiquiditySource[]
@@ -44,10 +45,8 @@ const LiquiditySourceType = styled('div', {
44
45
  paddingBottom: '$8',
45
46
  });
46
47
 
47
- const LiquidityImage = styled('img', {
48
- width: '$20',
49
- maxHeight: '$20',
50
- marginRight: '$16',
48
+ const LiquidityImageContainer = styled('div', {
49
+ paddingRight: '$16',
51
50
  });
52
51
 
53
52
  const LoaderContainer = styled('div', {
@@ -185,7 +184,11 @@ const LiquiditySourceItem = ({
185
184
  size="large"
186
185
  align="start"
187
186
  variant="outlined"
188
- prefix={<LiquidityImage src={liquiditySource.logo} />}
187
+ prefix={
188
+ <LiquidityImageContainer>
189
+ <Image src={liquiditySource.logo} size={20} />
190
+ </LiquidityImageContainer>
191
+ }
189
192
  suffix={<Switch checked={selected} />}
190
193
  style={{ marginBottom: '12px' }}
191
194
  onClick={onChange.bind(null, liquiditySource)}
@@ -3,6 +3,7 @@ import { styled } from '../../theme';
3
3
  import { SelectableWallet } from '../../types';
4
4
  import { Typography } from '../Typography';
5
5
  import { getConciseAddress } from '../../helper';
6
+ import { Image } from '../common';
6
7
 
7
8
  const Row = styled('div', {
8
9
  display: 'flex',
@@ -102,7 +103,7 @@ export function SelectableWalletList({
102
103
  onClick={onClick.bind(null, w)}
103
104
  key={index}
104
105
  >
105
- <img src={w.image} alt={w.walletType} width={24} height={24} />
106
+ <Image src={w.image} alt={w.walletType} size={24} />
106
107
  <Typography variant="body2">{w.name}</Typography>
107
108
  <Typography variant="caption">
108
109
  {getConciseAddress(w.address)}
@@ -1,6 +1,7 @@
1
1
  import React, { PropsWithChildren } from 'react';
2
2
  import { styled } from '../../theme';
3
3
  import { Typography } from '../Typography';
4
+ import { Image } from '../common';
4
5
 
5
6
  const StepLogoContainer = styled('div', {
6
7
  position: 'relative',
@@ -15,11 +16,6 @@ const StepLogoContainer = styled('div', {
15
16
  },
16
17
  },
17
18
  });
18
- const Logo = styled('img', {
19
- width: '$28',
20
- height: '$28',
21
- borderRadius: '50%',
22
- });
23
19
 
24
20
  const ChainLogo = styled('div', {
25
21
  position: 'absolute',
@@ -27,15 +23,12 @@ const ChainLogo = styled('div', {
27
23
  bottom: -4,
28
24
  width: '$16',
29
25
  height: '$16',
30
- padding: '$2',
31
26
  borderRadius: '50%',
27
+ display: 'flex',
28
+ justifyContent: 'center',
29
+ alignItems: 'center',
32
30
  backgroundColor: '$background',
33
31
  border: '1px solid $neutrals400',
34
-
35
- img: {
36
- width: '100%',
37
- display: 'block',
38
- },
39
32
  });
40
33
  const StepContainer = styled('div', {
41
34
  display: 'flex',
@@ -91,9 +84,9 @@ export function StepDetail({
91
84
  return (
92
85
  <StepContainer direction={direction}>
93
86
  <StepLogoContainer direction={direction}>
94
- <Logo src={logo} alt={symbol} />
87
+ <Image src={logo} alt={symbol} size={28} />
95
88
  <ChainLogo>
96
- <img src={chainLogo} alt={blockchain} />
89
+ <Image src={chainLogo} alt={blockchain} size={12} />
97
90
  </ChainLogo>
98
91
  </StepLogoContainer>
99
92
  <Detail pl={direction === 'horizontal'}>
@@ -6,6 +6,7 @@ import { ArrowRightIcon } from '../Icon';
6
6
  import { Spacer } from '../Spacer';
7
7
  import { Spinner } from '../Spinner';
8
8
  import { Token } from './Token';
9
+ import { limitDecimalPlaces } from '../../helper';
9
10
 
10
11
  const Container = styled('div', {
11
12
  position: 'relative',
@@ -75,7 +76,7 @@ export function SwapDetail({
75
76
  logo: firstStep.fromBlockchainLogo || '',
76
77
  name: firstStep.fromBlockchain,
77
78
  },
78
- amount: swap.inputAmount,
79
+ amount: limitDecimalPlaces(swap.inputAmount),
79
80
  }}
80
81
  />
81
82
  <Spacer size={12} />
@@ -92,10 +93,11 @@ export function SwapDetail({
92
93
  logo: lastStep.toBlockchainLogo,
93
94
  name: lastStep.toBlockchain,
94
95
  },
95
- amount:
96
+ amount: limitDecimalPlaces(
96
97
  lastStep.outputAmount ||
97
- lastStep.expectedOutputAmountHumanReadable ||
98
- '',
98
+ lastStep.expectedOutputAmountHumanReadable ||
99
+ ''
100
+ ),
99
101
  }}
100
102
  />
101
103
  </div>
@@ -1,10 +1,12 @@
1
1
  import React from 'react';
2
2
  import { styled } from '../../theme';
3
3
  import { Spacer } from '../Spacer';
4
+ import { Image } from '../common';
4
5
 
5
6
  const TokenContainer = styled('div', {
6
7
  display: 'flex',
7
8
  alignItems: 'center',
9
+ width: '160px',
8
10
 
9
11
  '& .amount': {
10
12
  fontWeight: 'bold',
@@ -13,13 +15,6 @@ const TokenContainer = styled('div', {
13
15
 
14
16
  const TokenImage = styled('div', {
15
17
  position: 'relative',
16
- width: '$24',
17
- height: '$24',
18
-
19
- img: {
20
- width: '100%',
21
- display: 'block',
22
- },
23
18
 
24
19
  '.overlay': {
25
20
  position: 'absolute',
@@ -29,6 +24,9 @@ const TokenImage = styled('div', {
29
24
  height: '$16',
30
25
  padding: '$2',
31
26
  borderRadius: '50%',
27
+ display: 'flex',
28
+ justifyContent: 'center',
29
+ alignItems: 'center',
32
30
  backgroundColor: '$background',
33
31
  border: '1px solid $neutrals400',
34
32
  },
@@ -51,11 +49,12 @@ export function Token(props: PropTypes) {
51
49
  return (
52
50
  <TokenContainer>
53
51
  <TokenImage>
54
- <img src={props.data.token.logo} alt="" />
52
+ <Image src={props.data.token.logo} alt="" size={24} />
55
53
  <div className="overlay">
56
- <img
54
+ <Image
57
55
  src={props.data.blockchain.logo}
58
56
  alt={props.data.blockchain.name}
57
+ size={12}
59
58
  />
60
59
  </div>
61
60
  </TokenImage>
@@ -4,11 +4,10 @@ import { styled } from '../../theme';
4
4
  import { Button } from '../Button';
5
5
  import { Typography } from '../Typography';
6
6
  import { TokenWithAmount } from './TokenList';
7
+ import { Image } from '../common';
7
8
 
8
- const TokenImage = styled('img', {
9
- width: '$32',
10
- maxHeight: '$32',
11
- marginRight: '$16',
9
+ const TokenImageContainer = styled('div', {
10
+ paddingRight: '$16',
12
11
  });
13
12
 
14
13
  const TokenNameContainer = styled('div', {
@@ -49,7 +48,11 @@ export function TokenItem(props: PropTypes) {
49
48
  align="start"
50
49
  onClick={onClick.bind(null, token)}
51
50
  type={selected ? 'primary' : undefined}
52
- prefix={<TokenImage src={token.image} />}
51
+ prefix={
52
+ <TokenImageContainer>
53
+ <Image src={token.image} size={32} />
54
+ </TokenImageContainer>
55
+ }
53
56
  suffix={
54
57
  token.balance?.amount && (
55
58
  <TokenAmountContainer>
@@ -6,11 +6,10 @@ import { WalletInfo, WalletState } from '../../types/wallet';
6
6
  import { Button } from '../Button/Button';
7
7
  import { Typography } from '../Typography';
8
8
  import { State } from './State';
9
+ import { Image } from '../common';
9
10
 
10
- const WalletImage = styled('img', {
11
- width: '$24',
12
- height: '$24',
13
- marginRight: '$12',
11
+ const WalletImageContainer = styled('div', {
12
+ paddingRight: '$12',
14
13
  });
15
14
  const Text = styled('div', {
16
15
  display: 'flex',
@@ -51,7 +50,11 @@ export function Wallet(props: PropTypes) {
51
50
  align="start"
52
51
  variant="outlined"
53
52
  size="large"
54
- prefix={<WalletImage src={image} />}
53
+ prefix={
54
+ <WalletImageContainer>
55
+ <Image src={image} size={24} />
56
+ </WalletImageContainer>
57
+ }
55
58
  suffix={<State walletState={state} installLink={installLink} />}
56
59
  >
57
60
  <Text>
@@ -0,0 +1,27 @@
1
+ import React from 'react';
2
+ import { styled } from '../../theme';
3
+
4
+ const ImageContainer = styled('div', {
5
+ display: 'flex',
6
+ justifyContent: 'center',
7
+ alignItems: 'center',
8
+ '.image': {
9
+ width: '100%',
10
+ height: '100%',
11
+ objectFit: 'contain',
12
+ },
13
+ });
14
+
15
+ type PropTypes = {
16
+ size: number;
17
+ } & React.ImgHTMLAttributes<HTMLImageElement>;
18
+
19
+ export function Image(props: PropTypes) {
20
+ const { size, ...otherProps } = props;
21
+
22
+ return (
23
+ <ImageContainer css={{ width: size + 'px', height: size + 'px' }}>
24
+ <img className="image" {...otherProps} />
25
+ </ImageContainer>
26
+ );
27
+ }
@@ -1 +1,2 @@
1
1
  export { FilledCircle } from './FilledCircle';
2
+ export { Image } from './Image';
@@ -91,7 +91,7 @@ export function History({
91
91
  <SecondaryPage
92
92
  onBack={onBack}
93
93
  textField={true}
94
- textFieldPlaceholder="Search By Blockchain Or Token Or Request ID"
94
+ textFieldPlaceholder="Search by Blockchain/Token/Request Id"
95
95
  title="Swaps"
96
96
  >
97
97
  {(searchedFor) => {
@@ -12,6 +12,7 @@ import {
12
12
  Drawer,
13
13
  Spinner,
14
14
  Divider,
15
+ Image,
15
16
  } from '../../components';
16
17
  import { styled } from '../../theme';
17
18
  import { PendingSwap } from '../History/types';
@@ -43,11 +44,6 @@ export const Fee = styled('div', {
43
44
  alignItems: 'center',
44
45
  });
45
46
 
46
- export const SwapperLogo = styled('img', {
47
- width: '$16',
48
- height: '$16',
49
- });
50
-
51
47
  export const RelativeContainer = styled('div', {
52
48
  position: 'relative',
53
49
  });
@@ -299,12 +295,11 @@ export function SwapHistory(props: PropTypes) {
299
295
  )}
300
296
  <Line />
301
297
  <SwapperContainer>
302
- <SwapperLogo
303
- src={
304
- // @ts-ignore
305
- step.swapperLogo || ''
306
- }
298
+ <Image
299
+ // @ts-ignore
300
+ src={step.swapperLogo}
307
301
  alt={step.swapperId}
302
+ size={16}
308
303
  />
309
304
  <div>
310
305
  <Typography ml={4} variant="caption">
@@ -1,11 +1,12 @@
1
- export const containsText = (text: string, searchText: string) =>
2
- text.toLowerCase().indexOf(searchText.toLowerCase()) > -1;
1
+ export function containsText(text: string, searchText: string): boolean {
2
+ return text.toLowerCase().indexOf(searchText.toLowerCase()) > -1;
3
+ }
3
4
 
4
- export const getConciseAddress = (
5
+ export function getConciseAddress(
5
6
  address: string | null,
6
7
  maxChars = 8,
7
8
  ellipsisLength = 3
8
- ): string | null => {
9
+ ): string | null {
9
10
  if (!address) return null;
10
11
  if (address.length < 2 * maxChars + ellipsisLength) return address;
11
12
  const start = Math.ceil((address.length - maxChars) / 2);
@@ -13,4 +14,18 @@ export const getConciseAddress = (
13
14
  return `${address.substr(start, maxChars)}${'.'.repeat(
14
15
  ellipsisLength
15
16
  )}${address.substr(end)}`;
16
- };
17
+ }
18
+
19
+ export function limitDecimalPlaces(
20
+ numberString: string,
21
+ maxDecimalPlaces = 4
22
+ ): string {
23
+ const number = parseFloat(numberString);
24
+ if (isNaN(number))
25
+ return numberString; // Return the original string if it's not a valid number
26
+ else {
27
+ const multiplier = Math.pow(10, maxDecimalPlaces);
28
+ const roundedNumber = Math.round(number * multiplier) / multiplier;
29
+ return roundedNumber.toString();
30
+ }
31
+ }