@rango-dev/widget-embedded 0.1.11-next.12 → 0.1.11-next.15

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 (34) hide show
  1. package/dist/components/ConfirmSwapErrors.d.ts +1 -1
  2. package/dist/components/ConfirmSwapErrors.d.ts.map +1 -1
  3. package/dist/components/ConfirmSwapWarnings.d.ts +1 -2
  4. package/dist/components/ConfirmSwapWarnings.d.ts.map +1 -1
  5. package/dist/components/warnings/BalanceErrors.d.ts +7 -0
  6. package/dist/components/warnings/BalanceErrors.d.ts.map +1 -0
  7. package/dist/pages/Home.d.ts.map +1 -1
  8. package/dist/store/bestRoute.d.ts.map +1 -1
  9. package/dist/types/routing.d.ts +8 -8
  10. package/dist/types/routing.d.ts.map +1 -1
  11. package/dist/utils/numbers.d.ts +1 -0
  12. package/dist/utils/numbers.d.ts.map +1 -1
  13. package/dist/utils/time.d.ts.map +1 -1
  14. package/dist/widget-embedded.cjs.development.js +53 -62
  15. package/dist/widget-embedded.cjs.development.js.map +1 -1
  16. package/dist/widget-embedded.cjs.production.min.js +53 -62
  17. package/dist/widget-embedded.cjs.production.min.js.map +1 -1
  18. package/dist/widget-embedded.esm.js +53 -62
  19. package/dist/widget-embedded.esm.js.map +1 -1
  20. package/package.json +4 -4
  21. package/src/components/ConfirmSwapErrors.tsx +8 -16
  22. package/src/components/ConfirmSwapWarnings.tsx +5 -15
  23. package/src/components/warnings/BalanceErrors.tsx +45 -0
  24. package/src/hooks/useConfirmSwap.ts +2 -2
  25. package/src/pages/Home.tsx +4 -7
  26. package/src/pages/SwapDetailsPage.tsx +1 -1
  27. package/src/pages/WalletsPage.tsx +1 -1
  28. package/src/store/bestRoute.ts +5 -3
  29. package/src/types/routing.ts +4 -4
  30. package/src/utils/numbers.ts +4 -0
  31. package/src/utils/time.ts +2 -8
  32. package/dist/components/warnings/BalanceWarnings.d.ts +0 -7
  33. package/dist/components/warnings/BalanceWarnings.d.ts.map +0 -1
  34. package/src/components/warnings/BalanceWarnings.tsx +0 -40
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rango-dev/widget-embedded",
3
- "version": "0.1.11-next.12",
3
+ "version": "0.1.11-next.15",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
@@ -11,7 +11,7 @@
11
11
  "browserslist": "> 0.5%, last 2 versions, not dead",
12
12
  "scripts": {
13
13
  "watch-tsc": "tsc --watch --noEmit",
14
- "dev": "parcel public/index.html -p 3001 --cache-dir=.parcel-cache",
14
+ "dev": "parcel public/index.html -p 3001 --no-cache",
15
15
  "dev-tsc": "npm-run-all --parallel watch-tsc dev",
16
16
  "build:app": "parcel build --cache-dir=.parcel-cache",
17
17
  "build": "tsdx build --entry ./src/lib.tsx"
@@ -30,9 +30,9 @@
30
30
  "dependencies": {
31
31
  "@rango-dev/provider-all": "^0.1.11-next.84",
32
32
  "@rango-dev/queue-manager-core": "^0.1.11-next.0",
33
- "@rango-dev/queue-manager-rango-preset": "^0.1.11-next.3",
33
+ "@rango-dev/queue-manager-rango-preset": "^0.1.11-next.5",
34
34
  "@rango-dev/queue-manager-react": "^0.1.10-next.76",
35
- "@rango-dev/ui": "^0.1.11-next.4",
35
+ "@rango-dev/ui": "^0.1.11-next.8",
36
36
  "@rango-dev/wallets-core": "^0.1.11-next.88",
37
37
  "@rango-dev/wallets-shared": "^0.1.11-next.84",
38
38
  "bignumber.js": "^9.1.1",
@@ -1,38 +1,30 @@
1
1
  import React from 'react';
2
- import { Typography } from '@rango-dev/ui';
3
2
  import { ConfirmSwapError, ConfirmSwapErrorTypes } from '../types';
4
3
  import { MinRequiredSlippage } from './warnings/MinRequiredSlippage';
4
+ import { BalanceErrors } from './warnings/BalanceErrors';
5
5
 
6
6
  export function ConfirmSwapErrors(errors: ConfirmSwapError[]) {
7
7
  return errors.flatMap((error) => {
8
8
  switch (error.type) {
9
9
  case ConfirmSwapErrorTypes.NO_ROUTE:
10
- return (
11
- <Typography variant="body2">
12
- No routes found. Please try again later.
13
- </Typography>
14
- );
10
+ return "No routes found. Please try again later."
15
11
  case ConfirmSwapErrorTypes.REQUEST_FAILED:
16
- return (
17
- <Typography variant="body2">{`Failed to confirm swap ${
12
+ return `Failed to confirm swap ${
18
13
  error.status ? `'status': ${error.status})` : ''
19
- }, please try again.`}</Typography>
20
- );
14
+ }, please try again.`
21
15
 
22
16
  case ConfirmSwapErrorTypes.ROUTE_UPDATED_WITH_HIGH_VALUE_LOSS:
23
- return (
24
- <Typography variant="body2">
25
- Route updated and price impact is too high, try again later!
26
- </Typography>
27
- );
17
+ return "Route updated and price impact is too high, try again later!"
28
18
  case ConfirmSwapErrorTypes.INSUFFICIENT_SLIPPAGE:
29
19
  return (
30
20
  <MinRequiredSlippage
31
21
  minRequiredSlippage={error.minRequiredSlippage}
32
22
  />
33
23
  );
24
+ case ConfirmSwapErrorTypes.INSUFFICIENT_BALANCE:
25
+ return <BalanceErrors messages={error.messages} />;
34
26
  default:
35
27
  return [];
36
28
  }
37
29
  });
38
- }
30
+ }
@@ -1,35 +1,25 @@
1
- import React from 'react';
2
- import { Typography } from '@rango-dev/ui';
3
1
  import { ConfirmSwapWarningTypes, ConfirmSwapWarnings } from '../types';
4
- import { BalanceWarnings } from './warnings/BalanceWarnings';
5
2
 
6
3
  export function ConfirmSwapWarnings(warnings: ConfirmSwapWarnings[]) {
7
4
  return warnings.flatMap((warning) => {
8
5
  switch (warning.type) {
9
6
  case ConfirmSwapWarningTypes.ROUTE_UPDATED:
10
- return <Typography variant="body2">Route has been updated.</Typography>;
7
+ return "Route has been updated.";
11
8
  case ConfirmSwapWarningTypes.ROUTE_AND_OUTPUT_AMOUNT_UPDATED:
12
9
  return (
13
- <Typography variant="body2">{`Output amount changed to ${warning.newOutputAmount}
14
- (${warning.percentageChange}% change).`}</Typography>
10
+ `Output amount changed to ${warning.newOutputAmount} (${warning.percentageChange}% change).`
15
11
  );
16
12
 
17
13
  case ConfirmSwapWarningTypes.ROUTE_SWAPPERS_UPDATED:
18
14
  return (
19
- <Typography variant="body2">
20
- Route swappers has been updated.
21
- </Typography>
15
+ "Route swappers has been updated."
22
16
  );
23
17
  case ConfirmSwapWarningTypes.ROUTE_COINS_UPDATED:
24
18
  return (
25
- <Typography variant="body2">
26
- Route internal coins has been updated.
27
- </Typography>
19
+ "Route internal coins has been updated."
28
20
  );
29
- case ConfirmSwapWarningTypes.INSUFFICIENT_BALANCE:
30
- return <BalanceWarnings messages={warning.messages} />;
31
21
  default:
32
22
  return [];
33
23
  }
34
24
  });
35
- }
25
+ }
@@ -0,0 +1,45 @@
1
+ import { Spacer, styled, Typography } from '@rango-dev/ui';
2
+ import React from 'react';
3
+
4
+ interface PropTypes {
5
+ messages: string[];
6
+ }
7
+
8
+ const List = styled('ul', {
9
+ variants: {
10
+ showListStyle: {
11
+ true: { paddingLeft: '$24' },
12
+ },
13
+ },
14
+ });
15
+
16
+ const ListItem = styled('li', {
17
+ variants: {
18
+ showListStyle: {
19
+ true: { listStyleType: 'disc', listStylePosition: 'outside' },
20
+ },
21
+ },
22
+ });
23
+
24
+ const Message = styled(Typography, {
25
+ display: 'block',
26
+ });
27
+
28
+ export function BalanceErrors({ messages }: PropTypes) {
29
+ const showListStyle = messages.length > 1;
30
+ return (
31
+ <>
32
+ <Typography className="title" variant="title" color={'error'}>
33
+ Insufficent Balance:
34
+ </Typography>
35
+ <Spacer size={8} direction="vertical" />
36
+ <List showListStyle={showListStyle}>
37
+ {messages.map((warning) => (
38
+ <ListItem showListStyle={showListStyle}>
39
+ <Message variant="body3">- {warning}</Message>
40
+ </ListItem>
41
+ ))}
42
+ </List>
43
+ </>
44
+ );
45
+ }
@@ -198,8 +198,8 @@ export function useConfirmSwap(): ConfirmSwap {
198
198
  const enoughBalance = balanceWarnings.length === 0;
199
199
 
200
200
  if (!enoughBalance)
201
- confirmSwapState.warnings.push({
202
- type: ConfirmSwapWarningTypes.INSUFFICIENT_BALANCE,
201
+ confirmSwapState.errors.push({
202
+ type: ConfirmSwapErrorTypes.INSUFFICIENT_BALANCE,
203
203
  messages: balanceWarnings,
204
204
  });
205
205
 
@@ -191,14 +191,11 @@ export function Home() {
191
191
  {hasLimitError(bestRoute) && (
192
192
  <Alert type="error" title={`${swap?.swapperId} Limit`}>
193
193
  <>
194
- <Typography variant="body2">{fromAmountRangeError}</Typography>
195
- <br />
196
- <Typography variant="body2">
197
- Yours: {numberToString(swap?.fromAmount || null)}
198
- {swap?.from.symbol}
194
+ <Typography variant="body3">
195
+ {fromAmountRangeError}, Yours: {numberToString(swap?.fromAmount || null)}
196
+ &nbsp;{swap?.from.symbol}
199
197
  </Typography>
200
- <br />
201
- <Typography variant="body2">{recommendation}</Typography>
198
+ <Typography variant="body3">{recommendation}</Typography>
202
199
  </>
203
200
  </Alert>
204
201
  )}
@@ -44,7 +44,7 @@ export function SwapDetailsPage() {
44
44
  useEffect(() => {
45
45
  setTimeout(() => {
46
46
  setLoading(false);
47
- }, 5000);
47
+ }, 5_000);
48
48
  }, []);
49
49
 
50
50
  const pendingSwaps = getPendingSwaps(manager);
@@ -113,7 +113,7 @@ export function WalletsPage({ supportedWallets, multiWallets }: PropTypes) {
113
113
  <>
114
114
  {walletErrorMessage && (
115
115
  <AlertContainer>
116
- <Alert type="error">{walletErrorMessage}</Alert>
116
+ <Alert type="error" title={walletErrorMessage}/>
117
117
  </AlertContainer>
118
118
  )}
119
119
  {loadingMetaStatus === 'loading' && (
@@ -22,6 +22,8 @@ import { useWalletsStore } from './wallets';
22
22
  import { TokenWithBalance } from '../pages/SelectTokenPage';
23
23
  import { PendingSwap } from '@rango-dev/queue-manager-rango-preset/dist/shared';
24
24
  import { debounce } from '../utils/common';
25
+ import { isPositiveNumber } from '../utils/numbers';
26
+
25
27
  const getUsdValue = (token: Token | null, amount: string) =>
26
28
  new BigNumber(amount || ZERO).multipliedBy(token?.usdPrice || 0);
27
29
 
@@ -72,7 +74,7 @@ export const useBestRouteStore = createSelectors(
72
74
  set((state) => {
73
75
  let outputAmount: BigNumber | null = null;
74
76
  let outputUsdValue: BigNumber = ZERO;
75
- if (!state.inputAmount || state.inputAmount === '0') return {};
77
+ if (!isPositiveNumber(state.inputAmount)) return {};
76
78
  if (!!bestRoute) {
77
79
  outputAmount = !!bestRoute.result?.outputAmount
78
80
  ? new BigNumber(bestRoute.result?.outputAmount)
@@ -251,7 +253,7 @@ const bestRoute = (
251
253
  const { fromToken, toToken, inputAmount } = bestRouteStore.getState();
252
254
  const { slippage, customSlippage, disabledLiquiditySources, affiliateRef } =
253
255
  settingsStore.getState();
254
- if (!fromToken || !toToken || !inputAmount || inputAmount === '0') return;
256
+ if (!fromToken || !toToken || !isPositiveNumber(inputAmount)) return;
255
257
  abortController?.abort();
256
258
  abortController = new AbortController();
257
259
  const userSlippage = !!customSlippage ? customSlippage : slippage;
@@ -296,7 +298,7 @@ const bestRoute = (
296
298
  const bestRouteParamsListener = () => {
297
299
  const { fromToken, toToken, inputAmount, inputUsdValue } =
298
300
  useBestRouteStore.getState();
299
- if (!inputAmount || inputAmount === '0' || inputUsdValue.eq(0))
301
+ if (!isPositiveNumber(inputAmount) || inputUsdValue.eq(0))
300
302
  return bestRouteStore.setState({ loading: false });
301
303
 
302
304
  if (tokensAreEqual(fromToken, toToken))
@@ -33,6 +33,7 @@ export enum ConfirmSwapErrorTypes {
33
33
  ROUTE_UPDATED_WITH_HIGH_VALUE_LOSS,
34
34
  REQUEST_FAILED,
35
35
  INSUFFICIENT_SLIPPAGE,
36
+ INSUFFICIENT_BALANCE,
36
37
  }
37
38
 
38
39
  export type ConfirmSwapError =
@@ -44,11 +45,13 @@ export type ConfirmSwapError =
44
45
  type: ConfirmSwapErrorTypes.INSUFFICIENT_SLIPPAGE;
45
46
  minRequiredSlippage: string | null;
46
47
  }
48
+ | { type: ConfirmSwapErrorTypes.INSUFFICIENT_BALANCE; messages: string[] }
47
49
  | {
48
50
  type: Exclude<
49
51
  ConfirmSwapErrorTypes,
50
52
  | ConfirmSwapErrorTypes.REQUEST_FAILED
51
53
  | ConfirmSwapErrorTypes.INSUFFICIENT_SLIPPAGE
54
+ | ConfirmSwapErrorTypes.INSUFFICIENT_BALANCE
52
55
  >;
53
56
  };
54
57
 
@@ -58,12 +61,10 @@ export type ConfirmSwapWarnings =
58
61
  newOutputAmount: string;
59
62
  percentageChange: string;
60
63
  }
61
- | { type: ConfirmSwapWarningTypes.INSUFFICIENT_BALANCE; messages: string[] }
62
64
  | {
63
65
  type: Exclude<
64
66
  ConfirmSwapWarningTypes,
65
- | ConfirmSwapWarningTypes.ROUTE_AND_OUTPUT_AMOUNT_UPDATED
66
- | ConfirmSwapWarningTypes.INSUFFICIENT_BALANCE
67
+ ConfirmSwapWarningTypes.ROUTE_AND_OUTPUT_AMOUNT_UPDATED
67
68
  >;
68
69
  };
69
70
 
@@ -72,5 +73,4 @@ export enum ConfirmSwapWarningTypes {
72
73
  ROUTE_SWAPPERS_UPDATED,
73
74
  ROUTE_COINS_UPDATED,
74
75
  ROUTE_AND_OUTPUT_AMOUNT_UPDATED,
75
- INSUFFICIENT_BALANCE,
76
76
  }
@@ -131,3 +131,7 @@ export const decimalNumber = (number = '0', toFixed: number) =>
131
131
 
132
132
  export const containsText = (text: string, searchText: string) =>
133
133
  text.toLowerCase().indexOf(searchText.toLowerCase()) > -1;
134
+
135
+ export const isPositiveNumber = (text?: string) =>
136
+ !!text && parseFloat(text) > 0;
137
+ 10;
package/src/utils/time.ts CHANGED
@@ -41,12 +41,6 @@ export function timeSince(timeMillis: number): string {
41
41
 
42
42
  export function getSwapDate(pendingSwap: PendingSwap) {
43
43
  return pendingSwap.finishTime
44
- ? `Finished ${timeSince(parseInt(pendingSwap.finishTime))} ago @ ${new Date(
45
- parseInt(pendingSwap.finishTime)
46
- ).toLocaleString()}`
47
- : `Started ${timeSince(
48
- parseInt(pendingSwap.creationTime)
49
- )} ago @ ${new Date(
50
- parseInt(pendingSwap.creationTime)
51
- ).toLocaleString()}`;
44
+ ? `${timeSince(parseInt(pendingSwap.finishTime))} ago`
45
+ : `${timeSince(parseInt(pendingSwap.creationTime))} ago`;
52
46
  }
@@ -1,7 +0,0 @@
1
- /// <reference types="react" />
2
- interface PropTypes {
3
- messages: string[];
4
- }
5
- export declare function BalanceWarnings({ messages }: PropTypes): JSX.Element;
6
- export {};
7
- //# sourceMappingURL=BalanceWarnings.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"BalanceWarnings.d.ts","sourceRoot":"","sources":["../../src/components/warnings/BalanceWarnings.tsx"],"names":[],"mappings":";AAGA,UAAU,SAAS;IACjB,QAAQ,EAAE,MAAM,EAAE,CAAC;CACpB;AAuBD,wBAAgB,eAAe,CAAC,EAAE,QAAQ,EAAE,EAAE,SAAS,eAWtD"}
@@ -1,40 +0,0 @@
1
- import { styled, Typography } from '@rango-dev/ui';
2
- import React from 'react';
3
-
4
- interface PropTypes {
5
- messages: string[];
6
- }
7
-
8
- const List = styled('ul', {
9
- variants: {
10
- showListStyle: {
11
- true: { paddingLeft: '$24' },
12
- },
13
- },
14
- });
15
-
16
- const ListItem = styled('li', {
17
- variants: {
18
- showListStyle: {
19
- true: { listStyleType: 'disc', listStylePosition: 'outside' },
20
- },
21
- },
22
- });
23
-
24
- const Message = styled(Typography, {
25
- display: 'block',
26
- color: '$warning500 !important',
27
- });
28
-
29
- export function BalanceWarnings({ messages }: PropTypes) {
30
- const showListStyle = messages.length > 1;
31
- return (
32
- <List showListStyle={showListStyle}>
33
- {messages.map((warning) => (
34
- <ListItem showListStyle={showListStyle}>
35
- <Message variant="body2">{warning}</Message>
36
- </ListItem>
37
- ))}
38
- </List>
39
- );
40
- }