@rango-dev/ui 0.1.10 → 0.1.11-next.3

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.10",
3
+ "version": "0.1.11-next.3",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
@@ -12,7 +12,6 @@ export interface PropTypes {
12
12
  content: React.ReactNode;
13
13
  action?: React.ReactNode;
14
14
  containerStyle?: CSSProperties;
15
- contentStyle?: CSSProperties;
16
15
  }
17
16
 
18
17
  const BackDrop = styled('div', {
@@ -48,7 +47,6 @@ const ModalHeader = styled('div', {
48
47
  marginBottom: '$16',
49
48
  });
50
49
 
51
- const ContentContainer = styled('div', {});
52
50
 
53
51
  export function Modal(props: PropTypes) {
54
52
  const {
@@ -58,7 +56,6 @@ export function Modal(props: PropTypes) {
58
56
  onClose,
59
57
  containerStyle,
60
58
  action,
61
- contentStyle,
62
59
  } = props;
63
60
 
64
61
  const handleBackDropClick = (event: React.MouseEvent<HTMLDivElement>) => {
@@ -81,9 +78,7 @@ export function Modal(props: PropTypes) {
81
78
  <CloseIcon size={24} onClick={onClose} />
82
79
  </Row>
83
80
  </ModalHeader>
84
- <ContentContainer style={contentStyle}>
85
- {content}
86
- </ContentContainer>
81
+ {content}
87
82
  </ModalContainer>
88
83
  </BackDrop>,
89
84
  document.body
@@ -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',
@@ -72,10 +73,10 @@ export function SwapDetail({
72
73
  },
73
74
  blockchain: {
74
75
  // @ts-ignore
75
- logo: firstStep.fromBlockchainLogo,
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>
@@ -5,6 +5,7 @@ import { Spacer } from '../Spacer';
5
5
  const TokenContainer = styled('div', {
6
6
  display: 'flex',
7
7
  alignItems: 'center',
8
+ width: '160px',
8
9
 
9
10
  '& .amount': {
10
11
  fontWeight: 'bold',
@@ -1,6 +1,6 @@
1
1
  import React, { forwardRef, useEffect, useState } from 'react';
2
2
  import { CommonProps } from 'react-window';
3
- import { Token } from 'rango-sdk';
3
+ import { Asset, Token } from 'rango-sdk';
4
4
  import { VirtualizedList } from '../VirtualizedList/VirtualizedList';
5
5
  import { TokenItem } from './TokenItem';
6
6
 
@@ -18,7 +18,7 @@ export interface PropTypes {
18
18
  searchedText: string;
19
19
  onChange: (token: TokenWithAmount) => void;
20
20
  multiSelect?: boolean;
21
- selectedList?: TokenWithAmount[] | 'all';
21
+ selectedList?: Asset[];
22
22
  }
23
23
 
24
24
  export function TokenList(props: PropTypes) {
@@ -33,7 +33,6 @@ export function TokenList(props: PropTypes) {
33
33
  const isSelected = (token: Token) => {
34
34
  if (multiSelect && selectedList) {
35
35
  return (
36
- selectedList === 'all' ||
37
36
  selectedList
38
37
  .map((item) => item.symbol + item.address)
39
38
  .indexOf(token.symbol + token.address) > -1
@@ -9,27 +9,21 @@ import { LoadingFailedAlert } from '../Alert/LoadingFailedAlert';
9
9
  import { NotFoundAlert } from '../Alert/NotFoundAlert';
10
10
  import { styled } from '../../theme';
11
11
 
12
- const Container = styled('div', {
13
- flex: '1',
14
- });
15
-
16
12
  export const LoaderContainer = styled('div', {
17
13
  display: 'flex',
18
14
  justifyContent: 'center',
19
15
  width: '100%',
20
- position: 'absolute',
21
- top: '50%',
16
+ paddingTop: '5%',
17
+ flex: 1,
22
18
  });
23
19
  export interface PropTypes {
24
20
  list: TokenWithAmount[];
25
21
  type?: 'Source' | 'Destination';
26
22
  selected: TokenWithAmount | null;
27
23
  onChange: (token: TokenWithAmount) => void;
28
- hasHeader?: boolean;
29
- multiSelect?: boolean;
30
24
  onBack?: () => void;
31
- selectedList?: TokenWithAmount[] | 'all';
32
25
  loadingStatus: LoadingStatus;
26
+ hasHeader?: boolean;
33
27
  }
34
28
 
35
29
  const filterTokens = (list: TokenWithAmount[], searchedFor: string) =>
@@ -41,53 +35,35 @@ const filterTokens = (list: TokenWithAmount[], searchedFor: string) =>
41
35
  );
42
36
 
43
37
  export function TokenSelector(props: PropTypes) {
44
- const {
45
- list,
46
- type,
47
- selected,
48
- onChange,
49
- hasHeader,
50
- multiSelect,
51
- selectedList,
52
- onBack,
53
- loadingStatus,
54
- } = props;
38
+ const { list, type, selected, hasHeader, onChange, onBack, loadingStatus } =
39
+ props;
55
40
 
56
41
  return (
57
42
  <SecondaryPage
58
43
  textField={true}
59
- textFieldPlaceholder="Search Blockchain By Name"
60
- title={`Select ${type} Token`}
61
44
  hasHeader={hasHeader}
45
+ title={`Select ${type} Token`}
62
46
  onBack={onBack}
47
+ textFieldPlaceholder="Search Token By Name"
63
48
  >
64
49
  {(searchedFor) => {
65
50
  const filteredTokens = filterTokens(list, searchedFor);
66
- return (
67
- <Container>
68
- {loadingStatus === 'loading' && (
69
- <LoaderContainer>
70
- <Spinner size={24} />
71
- </LoaderContainer>
72
- )}
73
- {loadingStatus === 'failed' && <LoadingFailedAlert />}
74
- {loadingStatus === 'success' && (
75
- <>
76
- {filteredTokens.length ? (
77
- <TokenList
78
- searchedText={searchedFor}
79
- list={filteredTokens}
80
- selected={selected}
81
- selectedList={selectedList}
82
- multiSelect={multiSelect}
83
- onChange={onChange}
84
- />
85
- ) : (
86
- <NotFoundAlert catergory="Token" searchedFor={searchedFor} />
87
- )}
88
- </>
89
- )}
90
- </Container>
51
+
52
+ return loadingStatus === 'loading' ? (
53
+ <LoaderContainer>
54
+ <Spinner size={24} />
55
+ </LoaderContainer>
56
+ ) : loadingStatus === 'failed' ? (
57
+ <LoadingFailedAlert />
58
+ ) : filteredTokens.length ? (
59
+ <TokenList
60
+ searchedText={searchedFor}
61
+ list={filteredTokens}
62
+ selected={selected}
63
+ onChange={onChange}
64
+ />
65
+ ) : (
66
+ <NotFoundAlert catergory="Token" searchedFor={searchedFor} />
91
67
  );
92
68
  }}
93
69
  </SecondaryPage>
@@ -290,7 +290,7 @@ export function SwapHistory(props: PropTypes) {
290
290
  logo={step.fromLogo}
291
291
  symbol={step.fromSymbol}
292
292
  // @ts-ignore
293
- chainLogo={step.fromBlockchainLogo}
293
+ chainLogo={step.fromBlockchainLogo || ''}
294
294
  blockchain={step.fromBlockchain}
295
295
  amount={pendingSwap.inputAmount}
296
296
  />
@@ -300,8 +300,10 @@ export function SwapHistory(props: PropTypes) {
300
300
  <Line />
301
301
  <SwapperContainer>
302
302
  <SwapperLogo
303
- // @ts-ignore
304
- src={step.swapperLogo}
303
+ src={
304
+ // @ts-ignore
305
+ step.swapperLogo || ''
306
+ }
305
307
  alt={step.swapperId}
306
308
  />
307
309
  <div>
@@ -319,6 +321,7 @@ export function SwapHistory(props: PropTypes) {
319
321
  $
320
322
  {
321
323
  // @ts-ignore
324
+
322
325
  step.feeInUsd
323
326
  }{' '}
324
327
  estimated gas fee
@@ -377,7 +380,8 @@ export function SwapHistory(props: PropTypes) {
377
380
  logo={step.toLogo}
378
381
  symbol={step.toSymbol}
379
382
  // @ts-ignore
380
- chainLogo={step.toBlockchainLogo}
383
+
384
+ chainLogo={step.toBlockchainLogo || ''}
381
385
  blockchain={step.toBlockchain}
382
386
  amount={step.outputAmount || ''}
383
387
  />
@@ -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
+ }