@rango-dev/widget-embedded 0.1.10-next.98 → 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 (34) 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/WalletsPage.d.ts.map +1 -1
  11. package/dist/store/bestRoute.d.ts.map +1 -1
  12. package/dist/utils/swap.d.ts +2 -1
  13. package/dist/utils/swap.d.ts.map +1 -1
  14. package/dist/widget-embedded.cjs.development.js +335 -92
  15. package/dist/widget-embedded.cjs.development.js.map +1 -1
  16. package/dist/widget-embedded.cjs.production.min.js +335 -92
  17. package/dist/widget-embedded.cjs.production.min.js.map +1 -1
  18. package/dist/widget-embedded.esm.js +334 -92
  19. package/dist/widget-embedded.esm.js.map +1 -1
  20. package/package.json +1 -1
  21. package/src/components/ChangeSlippageButton.tsx +4 -8
  22. package/src/components/HeaderButtons.tsx +2 -2
  23. package/src/components/RoutesOverview.tsx +60 -0
  24. package/src/components/TokenInfo.tsx +125 -77
  25. package/src/components/TokenPreview.tsx +175 -0
  26. package/src/components/warnings/HighSlippageWarning.tsx +4 -7
  27. package/src/globalStyles.ts +1 -1
  28. package/src/hooks/useTheme.ts +9 -9
  29. package/src/languages/en.json +9 -8
  30. package/src/pages/ConfirmWalletsPage.tsx +53 -6
  31. package/src/pages/Home.tsx +33 -35
  32. package/src/pages/WalletsPage.tsx +2 -5
  33. package/src/store/bestRoute.ts +4 -5
  34. package/src/utils/swap.ts +12 -1
@@ -11,18 +11,27 @@ import {
11
11
  getSelectableWallets,
12
12
  isExperimentalChain,
13
13
  } from '../utils/wallets';
14
- import { requiredWallets } from '../utils/swap';
15
- import { decimalNumber } from '../utils/numbers';
14
+ import {
15
+ calcOutputUsdValue,
16
+ getTotalFeeInUsd,
17
+ requiredWallets,
18
+ } from '../utils/swap';
19
+ import { decimalNumber, numberToString } from '../utils/numbers';
16
20
  import { useMetaStore } from '../store/meta';
17
21
  import { Network, WalletType } from '@rango-dev/wallets-shared';
18
22
  import { useNavigateBack } from '../hooks/useNavigateBack';
23
+ import { TokenPreview } from '../components/TokenPreview';
24
+ // @ts-ignore // TODO: fix error in tsc build
25
+ import { t } from 'i18next';
26
+ import { Spacer } from '@rango-dev/ui';
27
+ import RoutesOverview from '../components/RoutesOverview';
19
28
 
20
29
  export function ConfirmWalletsPage() {
21
30
  const navigate = useNavigate();
22
31
  const { navigateBackFrom } = useNavigateBack();
23
32
  const bestRoute = useBestRouteStore.use.bestRoute();
24
33
 
25
- const { blockchains } = useMetaStore.use.meta();
34
+ const { blockchains, tokens } = useMetaStore.use.meta();
26
35
  const accounts = useWalletsStore.use.accounts();
27
36
  const selectedWallets = useWalletsStore.use.selectedWallets();
28
37
  const initSelectedWallets = useWalletsStore.use.initSelectedWallets();
@@ -56,14 +65,13 @@ export function ConfirmWalletsPage() {
56
65
  );
57
66
  };
58
67
 
68
+ const totalFeeInUsd = getTotalFeeInUsd(bestRoute, tokens);
69
+
59
70
  return (
60
71
  <ConfirmWallets
61
72
  requiredWallets={getRequiredChains(bestRoute)}
62
73
  selectableWallets={selectableWallets}
63
74
  onBack={navigateBackFrom.bind(null, navigationRoutes.confirmWallets)}
64
- swap={bestRoute}
65
- fromAmount={fromAmount}
66
- toAmount={toAmount}
67
75
  onConfirm={() =>
68
76
  navigate(navigationRoutes.confirmSwap, { replace: true })
69
77
  }
@@ -75,6 +83,45 @@ export function ConfirmWalletsPage() {
75
83
  ? isExperimentalChain(blockchains, wallet)
76
84
  : false
77
85
  }
86
+ previewInputs={
87
+ <>
88
+ <TokenPreview
89
+ chain={{
90
+ displayName: firstStep?.from.blockchain || '',
91
+ logo: firstStep?.from.blockchainLogo || '',
92
+ }}
93
+ token={{
94
+ symbol: firstStep?.from.symbol || '',
95
+ image: firstStep?.from.logo || '',
96
+ }}
97
+ usdValue={calcOutputUsdValue(fromAmount, firstStep?.from.usdPrice)}
98
+ amount={fromAmount}
99
+ label={t('From')}
100
+ loadingStatus={'success'}
101
+ />
102
+ <Spacer size={12} direction="vertical" />
103
+ <TokenPreview
104
+ chain={{
105
+ displayName: lastStep?.to.blockchain || '',
106
+ logo: lastStep?.to.blockchainLogo || '',
107
+ }}
108
+ token={{
109
+ symbol: lastStep?.to.symbol || '',
110
+ image: lastStep?.to.logo || '',
111
+ }}
112
+ usdValue={calcOutputUsdValue(toAmount, lastStep?.to.usdPrice)}
113
+ amount={toAmount}
114
+ label={t('To')}
115
+ loadingStatus={'success'}
116
+ />
117
+ </>
118
+ }
119
+ previewRoutes={
120
+ <RoutesOverview
121
+ routes={bestRoute}
122
+ totalFee={numberToString(totalFeeInUsd, 0, 2)}
123
+ />
124
+ }
78
125
  />
79
126
  );
80
127
  }
@@ -33,20 +33,23 @@ import {
33
33
  secondsToString,
34
34
  totalArrivalTime,
35
35
  } from '../utils/numbers';
36
+ import BigNumber from 'bignumber.js';
36
37
 
37
38
  const Container = styled('div', {
38
39
  display: 'flex',
39
40
  flexDirection: 'column',
40
- justifyContent: 'center',
41
- alignItems: 'center',
42
41
  });
43
42
 
44
- const SwitchButtonContainer = styled('div', {
45
- display: 'flex',
46
- justifyContent: 'center',
47
- alignItems: 'center',
43
+ const FromContainer = styled('div', {
48
44
  position: 'relative',
49
- top: '11px',
45
+ paddingBottom: '$12',
46
+ });
47
+
48
+ const SwitchButtonContainer = styled('div', {
49
+ position: 'absolute',
50
+ bottom: '-12px',
51
+ left: '50%',
52
+ transform: 'translate(-50%, 10%)',
50
53
  });
51
54
 
52
55
  const BestRouteContainer = styled('div', {
@@ -66,7 +69,6 @@ interface PropTypes {
66
69
  export function Home(props: PropTypes) {
67
70
  const { title = 'SWAP', titleSize = 18, titleWeight = 600 } = props;
68
71
 
69
- const waningMessage = '';
70
72
  const isRouterInContext = useInRouterContext();
71
73
  const navigate = useNavigate();
72
74
  const [count, setCount] = useState(0);
@@ -123,6 +125,7 @@ export function Home(props: PropTypes) {
123
125
  outputUsdValue
124
126
  );
125
127
 
128
+ const inputIsZero = inputAmount === '0';
126
129
  const swapButtonState = getSwapButtonState(
127
130
  loadingMetaStatus,
128
131
  accounts,
@@ -131,14 +134,14 @@ export function Home(props: PropTypes) {
131
134
  hasLimitError(bestRoute),
132
135
  highValueLoss,
133
136
  priceImpactCanNotBeComputed,
134
- needsToWarnEthOnPath
137
+ needsToWarnEthOnPath,
138
+ inputIsZero
135
139
  );
136
140
 
137
141
  const totalFeeInUsd = getTotalFeeInUsd(bestRoute, tokens);
138
142
 
139
143
  const highFee = hasHighFee(totalFeeInUsd);
140
144
 
141
-
142
145
  return (
143
146
  <Container>
144
147
  <Header
@@ -147,24 +150,28 @@ export function Home(props: PropTypes) {
147
150
  titleWeight={titleWeight}
148
151
  onClickRefresh={fetchBestRoute}
149
152
  />
150
- <TokenInfo
151
- type="From"
152
- chain={fromChain}
153
- token={fromToken}
154
- onAmountChange={setInputAmount}
155
- inputAmount={inputAmount}
156
- />
157
- <SwitchButtonContainer>
158
- <Button variant="ghost" onClick={swithFromAndTo}>
159
- <VerticalSwapIcon size={36} />
160
- {isRouterInContext && <SwithFromAndTo count={count} />}
161
- </Button>
162
- </SwitchButtonContainer>
153
+ <FromContainer>
154
+ <TokenInfo
155
+ type="From"
156
+ chain={fromChain}
157
+ token={fromToken}
158
+ onAmountChange={setInputAmount}
159
+ inputAmount={inputAmount}
160
+ />
161
+ <SwitchButtonContainer>
162
+ <Button variant="ghost" onClick={swithFromAndTo}>
163
+ <VerticalSwapIcon size={24} />
164
+ {isRouterInContext && <SwithFromAndTo count={count} />}
165
+ </Button>
166
+ </SwitchButtonContainer>
167
+ </FromContainer>
163
168
  <TokenInfo
164
169
  type="To"
165
170
  chain={toChain}
166
171
  token={toToken}
167
- outputAmount={outputAmount}
172
+ outputAmount={
173
+ outputAmount ? new BigNumber(outputAmount) : new BigNumber(0)
174
+ }
168
175
  outputUsdValue={outputUsdValue}
169
176
  />
170
177
  {showBestRoute && (
@@ -179,13 +186,9 @@ export function Home(props: PropTypes) {
179
186
  />
180
187
  </BestRouteContainer>
181
188
  )}
182
- {(errorMessage || waningMessage || hasLimitError(bestRoute)) && (
189
+ {(errorMessage || hasLimitError(bestRoute)) && (
183
190
  <Alerts>
184
- {errorMessage && (
185
- <Alert type="error">
186
- {<Typography variant="body2">{errorMessage}</Typography>}
187
- </Alert>
188
- )}
191
+ {errorMessage && <Alert type="error">{errorMessage}</Alert>}
189
192
  {hasLimitError(bestRoute) && (
190
193
  <Alert type="error" title={`${swap?.swapperId} Limit`}>
191
194
  <>
@@ -200,11 +203,6 @@ export function Home(props: PropTypes) {
200
203
  </>
201
204
  </Alert>
202
205
  )}
203
- {waningMessage && (
204
- <Alert type="warning">
205
- <Typography variant="body2">{waningMessage}</Typography>
206
- </Alert>
207
- )}
208
206
  </Alerts>
209
207
  )}
210
208
  <Footer>
@@ -3,7 +3,6 @@ import {
3
3
  SecondaryPage,
4
4
  styled,
5
5
  Wallet,
6
- Typography,
7
6
  WalletState,
8
7
  } from '@rango-dev/ui';
9
8
  import React, { useEffect, useState } from 'react';
@@ -27,7 +26,7 @@ const ListContainer = styled('div', {
27
26
  gridTemplateColumns: ' repeat(2, minmax(0, 1fr))',
28
27
  height: '450px',
29
28
  alignContent: 'baseline',
30
- padding: '0 0.5rem',
29
+ padding: '0.5rem',
31
30
  });
32
31
 
33
32
  const AlertContainer = styled('div', {
@@ -85,9 +84,7 @@ export function WalletsPage({ supportedWallets, multiWallets }: PropTypes) {
85
84
  <>
86
85
  {walletErrorMessage && (
87
86
  <AlertContainer>
88
- <Alert type="error">
89
- <Typography variant="body2">{walletErrorMessage}</Typography>
90
- </Alert>
87
+ <Alert type="error">{walletErrorMessage}</Alert>
91
88
  </AlertContainer>
92
89
  )}
93
90
  <ListContainer>
@@ -11,7 +11,7 @@ import createSelectors from './selectors';
11
11
  import { subscribeWithSelector } from 'zustand/middleware';
12
12
  import { httpService } from '../services/httpService';
13
13
  import { useSettingsStore } from './settings';
14
- import { createBestRouteRequestBody } from '../utils/swap';
14
+ import { calcOutputUsdValue, createBestRouteRequestBody } from '../utils/swap';
15
15
  import { useMetaStore } from './meta';
16
16
  import { getDefaultToken, getSortedTokens } from '../utils/wallets';
17
17
  import { useWalletsStore } from './wallets';
@@ -69,10 +69,9 @@ export const useBestRouteStore = createSelectors(
69
69
  outputAmount = !!bestRoute.result?.outputAmount
70
70
  ? new BigNumber(bestRoute.result?.outputAmount)
71
71
  : null;
72
- outputUsdValue = new BigNumber(outputAmount || ZERO).multipliedBy(
73
- getBestRouteToTokenUsdPrice(bestRoute) ||
74
- state.toToken?.usdPrice ||
75
- 0
72
+ outputUsdValue = calcOutputUsdValue(
73
+ bestRoute.result?.outputAmount,
74
+ getBestRouteToTokenUsdPrice(bestRoute) || state.toToken?.usdPrice
76
75
  );
77
76
  }
78
77
  return {
package/src/utils/swap.ts CHANGED
@@ -128,12 +128,14 @@ export function getSwapButtonState(
128
128
  hasLimitError: boolean,
129
129
  highValueLoss: boolean,
130
130
  priceImpactCanNotBeComputed: boolean,
131
- needsToWarnEthOnPath: boolean
131
+ needsToWarnEthOnPath: boolean,
132
+ inputIsZero: boolean
132
133
  ): SwapButtonState {
133
134
  if (loadingMetaStatus !== 'success')
134
135
  return { title: 'Connect Wallet', disabled: true };
135
136
  if (accounts.length == 0) return { title: 'Connect Wallet', disabled: false };
136
137
  if (loading) return { title: 'Finding Best Route...', disabled: true };
138
+ else if (inputIsZero) return { title: 'Enter an amount', disabled: true };
137
139
  else if (!bestRoute) return { title: 'Swap', disabled: true };
138
140
  else if (hasLimitError) return { title: 'Limit Error', disabled: true };
139
141
  else if (highValueLoss)
@@ -539,3 +541,12 @@ export function getBalanceWarnings(
539
541
  return warningMessage;
540
542
  });
541
543
  }
544
+
545
+ export function calcOutputUsdValue(
546
+ outputAmount?: string,
547
+ tokenPrice?: number | null
548
+ ) {
549
+ const amount = !!outputAmount ? new BigNumber(outputAmount) : ZERO;
550
+
551
+ return amount.multipliedBy(tokenPrice || 0);
552
+ }