@rango-dev/widget-embedded 0.1.10-next.96 → 0.1.10-next.99

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.
Files changed (36) hide show
  1. package/dist/components/ChangeSlippageButton.d.ts.map +1 -1
  2. package/dist/components/RoutesOverview.d.ts +10 -0
  3. package/dist/components/RoutesOverview.d.ts.map +1 -0
  4. package/dist/components/TokenInfo.d.ts.map +1 -1
  5. package/dist/components/TokenPreview.d.ts +20 -0
  6. package/dist/components/TokenPreview.d.ts.map +1 -0
  7. package/dist/components/warnings/HighSlippageWarning.d.ts.map +1 -1
  8. package/dist/pages/ConfirmWalletsPage.d.ts.map +1 -1
  9. package/dist/pages/Home.d.ts.map +1 -1
  10. package/dist/pages/SwapDetailsPage.d.ts.map +1 -1
  11. package/dist/pages/WalletsPage.d.ts.map +1 -1
  12. package/dist/store/bestRoute.d.ts.map +1 -1
  13. package/dist/utils/swap.d.ts +2 -1
  14. package/dist/utils/swap.d.ts.map +1 -1
  15. package/dist/widget-embedded.cjs.development.js +344 -97
  16. package/dist/widget-embedded.cjs.development.js.map +1 -1
  17. package/dist/widget-embedded.cjs.production.min.js +344 -97
  18. package/dist/widget-embedded.cjs.production.min.js.map +1 -1
  19. package/dist/widget-embedded.esm.js +343 -97
  20. package/dist/widget-embedded.esm.js.map +1 -1
  21. package/package.json +1 -1
  22. package/src/components/ChangeSlippageButton.tsx +4 -8
  23. package/src/components/HeaderButtons.tsx +2 -2
  24. package/src/components/RoutesOverview.tsx +60 -0
  25. package/src/components/TokenInfo.tsx +125 -77
  26. package/src/components/TokenPreview.tsx +175 -0
  27. package/src/components/warnings/HighSlippageWarning.tsx +4 -7
  28. package/src/globalStyles.ts +1 -1
  29. package/src/hooks/useTheme.ts +9 -9
  30. package/src/languages/en.json +9 -8
  31. package/src/pages/ConfirmWalletsPage.tsx +53 -6
  32. package/src/pages/Home.tsx +33 -35
  33. package/src/pages/SwapDetailsPage.tsx +12 -7
  34. package/src/pages/WalletsPage.tsx +2 -5
  35. package/src/store/bestRoute.ts +4 -5
  36. package/src/utils/swap.ts +12 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rango-dev/widget-embedded",
3
- "version": "0.1.10-next.96",
3
+ "version": "0.1.10-next.99",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
@@ -1,23 +1,19 @@
1
1
  import React from 'react';
2
- import { Button, styled } from '@rango-dev/ui';
2
+ import { Button } from '@rango-dev/ui';
3
3
  import { useNavigate } from 'react-router-dom';
4
4
  import { navigationRoutes } from '../constants/navigationRoutes';
5
5
 
6
- const StyledButton = styled(Button, {
7
- marginTop: '$8',
8
- });
9
-
10
6
  export function ChangeSlippageButton() {
11
7
  const navigate = useNavigate();
12
8
 
13
9
  return (
14
- <StyledButton
10
+ <Button
15
11
  type="primary"
16
- variant="contained"
12
+ variant="outlined"
17
13
  size="small"
18
14
  onClick={() => navigate(navigationRoutes.settings)}
19
15
  >
20
16
  Change Slippage
21
- </StyledButton>
17
+ </Button>
22
18
  );
23
19
  }
@@ -21,9 +21,9 @@ export function HeaderButtons(props: PropTypes) {
21
21
 
22
22
  return (
23
23
  <ButtonsContainer>
24
- <Tooltip content="Retry">
24
+ <Tooltip content="Refresh">
25
25
  <Button variant="ghost" onClick={onClickRefresh}>
26
- <RetryIcon size={28} />
26
+ <RetryIcon size={24} />
27
27
  </Button>
28
28
  </Tooltip>
29
29
  <Tooltip content="Transactions History">
@@ -0,0 +1,60 @@
1
+ import React from 'react';
2
+ import { styled } from '@rango-dev/ui';
3
+ import { BestRouteResponse } from 'rango-sdk';
4
+ import { ChevronRightIcon } from '@rango-dev/ui';
5
+ import { GasIcon } from '@rango-dev/ui';
6
+ import { Spacer } from '@rango-dev/ui';
7
+
8
+ export const Container = styled('div', {
9
+ display: 'flex',
10
+ alignItems: 'center',
11
+ justifyContent: 'space-between',
12
+ padding: '$8',
13
+ borderRadius: '$5',
14
+ backgroundColor: '$neutrals300',
15
+ color: '$neutrals800',
16
+ fontSize: '$12',
17
+
18
+ '.routes': {
19
+ display: 'flex',
20
+ alignItems: 'center',
21
+ },
22
+ '.fee': {
23
+ display: 'flex',
24
+ alignItems: 'center',
25
+ },
26
+ });
27
+
28
+ interface PropTypes {
29
+ routes: BestRouteResponse | null;
30
+ totalFee?: string;
31
+ }
32
+ function RoutesOverview(props: PropTypes) {
33
+ if (!props.routes) return null;
34
+
35
+ const swaps = props.routes.result?.swaps;
36
+ return (
37
+ <Container>
38
+ <div className="routes">
39
+ {swaps?.map((swap, idx) => {
40
+ const isLast = idx + 1 == swaps.length;
41
+ return (
42
+ <>
43
+ <div className="route">{swap.from.symbol}</div>
44
+ <ChevronRightIcon size={12} />
45
+ {isLast ? <div className="route">{swap.to.symbol}</div> : null}
46
+ </>
47
+ );
48
+ })}
49
+ </div>
50
+ {props.totalFee ? (
51
+ <div className="fee">
52
+ <GasIcon size={12} />
53
+ <Spacer size={4} />${props.totalFee}
54
+ </div>
55
+ ) : null}
56
+ </Container>
57
+ );
58
+ }
59
+
60
+ export default RoutesOverview;
@@ -16,6 +16,7 @@ import BigNumber from 'bignumber.js';
16
16
  import { getBalanceFromWallet } from '../utils/wallets';
17
17
  import { useWalletsStore } from '../store/wallets';
18
18
  import { useTranslation } from 'react-i18next';
19
+ import { Spacer } from '@rango-dev/ui';
19
20
 
20
21
  type PropTypes = (
21
22
  | {
@@ -38,14 +39,46 @@ const Box = styled('div', {
38
39
 
39
40
  const Container = styled('div', {
40
41
  boxSizing: 'border-box',
41
- backgroundColor: '$neutrals300',
42
42
  borderRadius: '$5',
43
- padding: '$8 0',
43
+ padding: '$8 $16 $16 $16',
44
+
45
+ variants: {
46
+ type: {
47
+ filled: {
48
+ backgroundColor: '$neutrals300',
49
+ },
50
+ outlined: {
51
+ border: '1px solid $neutrals300',
52
+ },
53
+ },
54
+ },
55
+
56
+ defaultVariants: {
57
+ type: 'filled',
58
+ },
44
59
 
60
+ '.head': {
61
+ display: 'flex',
62
+ justifyContent: 'space-between',
63
+ alignItems: 'center',
64
+ minHeight: '32px',
65
+ },
45
66
  '.form': {
46
67
  display: 'flex',
47
68
  width: '100%',
48
- padding: '$8 $16',
69
+ padding: '$2 0',
70
+ '.selectors': {
71
+ width: '35%',
72
+
73
+ '._text': {
74
+ whiteSpace: 'nowrap',
75
+ overflow: 'hidden',
76
+ textOverflow: 'ellipsis',
77
+ },
78
+ },
79
+ '.amount': {
80
+ width: '30%',
81
+ },
49
82
  },
50
83
  });
51
84
 
@@ -57,7 +90,11 @@ const StyledImage = styled('img', {
57
90
  const Options = styled('div', {
58
91
  display: 'flex',
59
92
  justifyContent: 'flex-end',
60
- padding: '0 $8',
93
+
94
+ '.balance': {
95
+ display: 'flex',
96
+ alignItems: 'center',
97
+ },
61
98
  });
62
99
 
63
100
  const ImagePlaceholder = styled('span', {
@@ -68,10 +105,9 @@ const ImagePlaceholder = styled('span', {
68
105
  });
69
106
 
70
107
  const OutputContainer = styled('div', {
108
+ windth: '100%',
71
109
  height: '$48',
72
110
  borderRadius: '$5',
73
- flexGrow: 1,
74
- width: '70%',
75
111
  backgroundColor: '$background',
76
112
  border: '1px solid transparent',
77
113
  position: 'relative',
@@ -141,29 +177,39 @@ export function TokenInfo(props: PropTypes) {
141
177
 
142
178
  return (
143
179
  <Box>
144
- <div>
145
- <Typography variant="body2">{t(type)}</Typography>
146
- </div>
147
- <Container>
148
- {props.type === 'From' && (
149
- <Options>
150
- <div
151
- className="balance"
152
- onClick={() => {
153
- if (tokenBalance !== '0')
154
- setInputAmount(tokenBalanceReal.split(',').join(''));
155
- }}
156
- >
157
- <Button variant="ghost" size="small">
158
- <Typography variant="body2">{`${t('Max')}: ${tokenBalance} ${
159
- fromToken?.symbol || ''
160
- }`}</Typography>
161
- </Button>
162
- </div>
163
- </Options>
164
- )}
180
+ <Container type={props.type === 'From' ? 'filled' : 'outlined'}>
181
+ <div className="head">
182
+ <Typography variant="body2" color="neutrals800">
183
+ {t(type)}
184
+ </Typography>
185
+ {props.type === 'From' ? (
186
+ <Options>
187
+ <div
188
+ className="balance"
189
+ onClick={() => {
190
+ if (tokenBalance !== '0')
191
+ setInputAmount(tokenBalanceReal.split(',').join(''));
192
+ }}
193
+ >
194
+ <Typography variant="body3" color="neutrals600">{`${t(
195
+ 'Balance'
196
+ )}: ${tokenBalance} ${fromToken?.symbol || ''}`}</Typography>
197
+ <Spacer size={4} />
198
+ <Button type="primary" variant="ghost" size="compact">
199
+ {t('Max')}
200
+ </Button>
201
+ </div>
202
+ </Options>
203
+ ) : (
204
+ <Typography
205
+ variant="caption"
206
+ color="neutrals600"
207
+ >{`$${numberToString(props.outputUsdValue)}`}</Typography>
208
+ )}
209
+ </div>
165
210
  <div className="form">
166
211
  <Button
212
+ className="selectors"
167
213
  onClick={() => {
168
214
  navigate(`/${props.type.toLowerCase()}-chain`);
169
215
  }}
@@ -180,11 +226,14 @@ export function TokenInfo(props: PropTypes) {
180
226
  suffix={ItemSuffix}
181
227
  align="start"
182
228
  size="large"
183
- style={{ marginRight: '.5rem' }}
184
229
  >
185
- {loadingStatus === 'success' && chain ? chain.displayName : t('Chain')}
230
+ {loadingStatus === 'success' && chain
231
+ ? chain.displayName
232
+ : t('Chain')}
186
233
  </Button>
234
+ <Spacer size={12} />
187
235
  <Button
236
+ className="selectors"
188
237
  onClick={() => {
189
238
  navigate(`/${props.type.toLowerCase()}-token`);
190
239
  }}
@@ -205,57 +254,56 @@ export function TokenInfo(props: PropTypes) {
205
254
  suffix={ItemSuffix}
206
255
  size="large"
207
256
  align="start"
208
- style={{ marginRight: '.5rem' }}
209
257
  >
210
258
  {loadingStatus === 'success' && token ? token.symbol : t('Token')}
211
259
  </Button>
212
- {props.type === 'From' ? (
213
- <TextField
214
- type="number"
215
- size="large"
216
- autoFocus
217
- placeholder="0"
218
- style={{
219
- width: '70%',
220
- position: 'relative',
221
- backgroundColor: '$background !important',
222
- }}
223
- suffix={
224
- <span
225
- style={{ position: 'absolute', right: '4px', bottom: '2px' }}
226
- >
227
- <Typography variant="caption">{`$${numberToString(
228
- inputUsdValue
229
- )}`}</Typography>
230
- </span>
231
- }
232
- value={props.inputAmount || ''}
233
- onChange={
234
- props.type === 'From'
235
- ? (event) => {
236
- props.onAmountChange(event.target.value);
237
- }
238
- : undefined
239
- }
240
- />
241
- ) : (
242
- <OutputContainer>
243
- <Typography variant="body1">
244
- {bestRoute
245
- ? `≈ ${numberToString(props.outputAmount)}`
246
- : inputAmount
247
- ? '?'
248
- : '0'}
249
- </Typography>
250
- <span
251
- style={{ position: 'absolute', right: '4px', bottom: '2px' }}
252
- >
253
- <Typography variant="caption">{`$${numberToString(
254
- props.outputUsdValue
255
- )}`}</Typography>
256
- </span>
257
- </OutputContainer>
258
- )}
260
+ <Spacer size={12} />
261
+ <div className="amount">
262
+ {props.type === 'From' ? (
263
+ <TextField
264
+ type="number"
265
+ size="large"
266
+ autoFocus
267
+ placeholder="0"
268
+ style={{
269
+ position: 'relative',
270
+ backgroundColor: '$background !important',
271
+ }}
272
+ suffix={
273
+ <span
274
+ style={{
275
+ position: 'absolute',
276
+ right: '4px',
277
+ bottom: '2px',
278
+ }}
279
+ >
280
+ <Typography
281
+ variant="caption"
282
+ color="neutrals800"
283
+ >{`$${numberToString(inputUsdValue)}`}</Typography>
284
+ </span>
285
+ }
286
+ value={props.inputAmount || ''}
287
+ onChange={
288
+ props.type === 'From'
289
+ ? (event) => {
290
+ props.onAmountChange(event.target.value);
291
+ }
292
+ : undefined
293
+ }
294
+ />
295
+ ) : (
296
+ <OutputContainer>
297
+ <Typography variant="h4">
298
+ {bestRoute
299
+ ? `≈ ${numberToString(props.outputAmount)}`
300
+ : inputAmount
301
+ ? '?'
302
+ : '0'}
303
+ </Typography>
304
+ </OutputContainer>
305
+ )}
306
+ </div>
259
307
  </div>
260
308
  </Container>
261
309
  </Box>
@@ -0,0 +1,175 @@
1
+ import React from 'react';
2
+ import { Button, InfoCircleIcon, styled, Typography } from '@rango-dev/ui';
3
+ import { LoadingStatus } from '../store/meta';
4
+ import { useTranslation } from 'react-i18next';
5
+ import { Spacer } from '@rango-dev/ui';
6
+ import BigNumber from 'bignumber.js';
7
+ import { numberToString } from '../utils/numbers';
8
+
9
+ const Box = styled('div', {
10
+ display: 'flex',
11
+ flexDirection: 'column',
12
+ width: '100%',
13
+ });
14
+
15
+ const Container = styled('div', {
16
+ boxSizing: 'border-box',
17
+ borderRadius: '$5',
18
+ padding: '$8 $16 $16 $16',
19
+
20
+ variants: {
21
+ type: {
22
+ filled: {
23
+ backgroundColor: '$neutrals300',
24
+ },
25
+ outlined: {
26
+ border: '1px solid $neutrals300',
27
+ },
28
+ },
29
+ },
30
+
31
+ defaultVariants: {
32
+ type: 'filled',
33
+ },
34
+
35
+ '.head': {
36
+ display: 'flex',
37
+ justifyContent: 'space-between',
38
+ alignItems: 'center',
39
+ minHeight: '32px',
40
+ },
41
+ '.form': {
42
+ display: 'flex',
43
+ width: '100%',
44
+ padding: '$2 0',
45
+ '.selectors': {
46
+ width: '35%',
47
+
48
+ '._text': {
49
+ whiteSpace: 'nowrap',
50
+ overflow: 'hidden',
51
+ textOverflow: 'ellipsis',
52
+ },
53
+ },
54
+ '.amount': {
55
+ width: '30%',
56
+ },
57
+ },
58
+ });
59
+
60
+ const StyledImage = styled('img', {
61
+ width: '$24',
62
+ maxHeight: '$24',
63
+ });
64
+
65
+ const ImagePlaceholder = styled('span', {
66
+ width: '24px',
67
+ height: '24px',
68
+ backgroundColor: '$neutrals300',
69
+ borderRadius: '99999px',
70
+ });
71
+
72
+ const OutputContainer = styled('div', {
73
+ windth: '100%',
74
+ height: '$48',
75
+ borderRadius: '$5',
76
+ backgroundColor: '$background',
77
+ border: '1px solid transparent',
78
+ position: 'relative',
79
+ display: 'flex',
80
+ alignItems: 'center',
81
+ paddingLeft: '$8',
82
+ paddingRight: '$8',
83
+ });
84
+
85
+ interface PropTypes {
86
+ label: string;
87
+ amount: string;
88
+ usdValue: BigNumber;
89
+ loadingStatus: LoadingStatus;
90
+ chain: {
91
+ displayName: string;
92
+ logo: string;
93
+ };
94
+ token: {
95
+ symbol: string;
96
+ image: string;
97
+ };
98
+ }
99
+
100
+ export function TokenPreview(props: PropTypes) {
101
+ const { chain, token, loadingStatus } = props;
102
+ const { t } = useTranslation();
103
+
104
+ const ItemSuffix = (
105
+ <div
106
+ style={{
107
+ display: 'flex',
108
+ justifyContent: 'center',
109
+ alignItems: 'center',
110
+ }}
111
+ >
112
+ {loadingStatus === 'failed' && <InfoCircleIcon color="error" size={24} />}
113
+ </div>
114
+ );
115
+
116
+ return (
117
+ <Box>
118
+ <Container type={'outlined'}>
119
+ <div className="head">
120
+ <Typography variant="body2" color="neutrals800">
121
+ {props.label}
122
+ </Typography>
123
+ <Typography variant="caption" color="neutrals600">{`$${numberToString(
124
+ props.usdValue
125
+ )}`}</Typography>
126
+ </div>
127
+ <div className="form">
128
+ <Button
129
+ className="selectors"
130
+ variant="outlined"
131
+ loading={loadingStatus === 'loading'}
132
+ prefix={
133
+ loadingStatus === 'success' && chain ? (
134
+ <StyledImage src={chain.logo} />
135
+ ) : (
136
+ <ImagePlaceholder />
137
+ )
138
+ }
139
+ suffix={ItemSuffix}
140
+ align="start"
141
+ size="large"
142
+ >
143
+ {loadingStatus === 'success' && chain
144
+ ? chain.displayName
145
+ : t('Chain')}
146
+ </Button>
147
+ <Spacer size={12} />
148
+ <Button
149
+ className="selectors"
150
+ variant="outlined"
151
+ loading={loadingStatus === 'loading'}
152
+ prefix={
153
+ loadingStatus === 'success' && token ? (
154
+ <StyledImage src={token.image} />
155
+ ) : (
156
+ <ImagePlaceholder />
157
+ )
158
+ }
159
+ suffix={ItemSuffix}
160
+ size="large"
161
+ align="start"
162
+ >
163
+ {loadingStatus === 'success' && token ? token.symbol : t('Token')}
164
+ </Button>
165
+ <Spacer size={12} />
166
+ <div className="amount">
167
+ <OutputContainer>
168
+ <Typography variant="h4">{props.amount}</Typography>
169
+ </OutputContainer>
170
+ </div>
171
+ </div>
172
+ </Container>
173
+ </Box>
174
+ );
175
+ }
@@ -1,4 +1,4 @@
1
- import { Alert, Typography } from '@rango-dev/ui';
1
+ import { Alert } from '@rango-dev/ui';
2
2
  import React from 'react';
3
3
  import { ChangeSlippageButton } from '../ChangeSlippageButton';
4
4
 
@@ -10,12 +10,9 @@ export function HighSlippageWarning(props: PropTypes) {
10
10
  const { selectedSlippage } = props;
11
11
 
12
12
  return (
13
- <Alert type="warning">
14
- <Typography variant="body2">
15
- Caution, your slippage is high (=
16
- {selectedSlippage}). Your trade may be front run.
17
- <ChangeSlippageButton />
18
- </Typography>
13
+ <Alert type="warning" footer={<ChangeSlippageButton />}>
14
+ Caution, your slippage is high (=
15
+ {selectedSlippage}). Your trade may be front run.
19
16
  </Alert>
20
17
  );
21
18
  }
@@ -20,7 +20,7 @@ export const globalFont = (fontFamily: string) =>
20
20
  "url('https://fonts.googleapis.com/css2?family=Roboto:ital,wght@0,100;0,300;0,400;0,500;0,700;0,900;1,100;1,300;1,400;1,500;1,700;1,900&display=swap')",
21
21
  "url('https://fonts.cdnfonts.com/css/times-new-roman')",
22
22
  ],
23
- [`.font_${fontFamily.replace(/ /g, '')} ._text`]: {
23
+ body: {
24
24
  fontFamily,
25
25
  },
26
26
  })();
@@ -14,16 +14,16 @@ export function useTheme({
14
14
  warning = '#F5A623',
15
15
  success = '#0070F3',
16
16
  fontFamily = 'Robot',
17
- borderRadius = 5,
17
+ borderRadius = 8,
18
18
  }: Colors & { borderRadius?: number; fontFamily?: string }) {
19
19
  const theme = useSettingsStore.use.theme();
20
20
  const fetchMeta = useMetaStore.use.fetchMeta();
21
21
  const colors = {
22
22
  neutrals200: '#FAFAFA',
23
- neutrals300: '#EAEAEA',
24
- neutrals400: '#999999',
25
- neutrals500: '#888888',
26
- neutrals600: '#666666',
23
+ neutrals300: '#f2f2f2',
24
+ neutrals400: '#dedede',
25
+ neutrals500: '#cccccc',
26
+ neutrals600: '#acacac',
27
27
  neutrals700: '#444444',
28
28
  neutrals800: '#333333',
29
29
  neutrals900: '#111111',
@@ -69,10 +69,10 @@ export function useTheme({
69
69
  neutrals200: '#111111',
70
70
  neutrals300: '#333333',
71
71
  neutrals400: '#444444',
72
- neutrals500: '#666666',
73
- neutrals600: '#888888',
74
- neutrals700: '#999999',
75
- neutrals800: '#EAEAEA',
72
+ neutrals500: '#acacac',
73
+ neutrals600: '#cccccc',
74
+ neutrals700: '#dedede',
75
+ neutrals800: '#f2f2f2',
76
76
  neutrals900: '#FAFAFA',
77
77
  foreground: background,
78
78
  background: foreground,
@@ -1,13 +1,14 @@
1
1
  {
2
2
  "swap": "SWAP",
3
- "Connect Wallet":"Connect Wallet",
4
- "Powered By":"Powered By",
5
- "From":"From",
6
- "To":"To",
7
- "Max":"Max",
3
+ "Connect Wallet": "Connect Wallet",
4
+ "Powered By": "Powered By",
5
+ "From": "You sell",
6
+ "To": "You receive",
7
+ "Balance": "Balance",
8
+ "Max": "Max",
8
9
  "Chain": "Chain",
9
10
  "Token": "Token",
10
- "Source" :"Source",
11
- "Destination" :"Destination",
12
- "Select Wallet":"Select Wallet"
11
+ "Source": "Source",
12
+ "Destination": "Destination",
13
+ "Select Wallet": "Connect Your Wallet"
13
14
  }