@rango-dev/widget-embedded 0.11.1-next.3 → 0.12.0

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 (53) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/dist/Wallets.d.ts +1 -1
  3. package/dist/Wallets.d.ts.map +1 -1
  4. package/dist/components/Layout.d.ts.map +1 -1
  5. package/dist/components/PercentageChange.d.ts +9 -0
  6. package/dist/components/PercentageChange.d.ts.map +1 -0
  7. package/dist/components/RoutesOverview.d.ts +120 -0
  8. package/dist/components/RoutesOverview.d.ts.map +1 -0
  9. package/dist/components/SwapDetailsPlaceholder.d.ts +120 -0
  10. package/dist/components/SwapDetailsPlaceholder.d.ts.map +1 -0
  11. package/dist/components/SwitchFromAndTo.d.ts +3 -2
  12. package/dist/components/SwitchFromAndTo.d.ts.map +1 -1
  13. package/dist/components/TokenInfo.d.ts +18 -0
  14. package/dist/components/TokenInfo.d.ts.map +1 -0
  15. package/dist/components/TokenPreview.d.ts +21 -0
  16. package/dist/components/TokenPreview.d.ts.map +1 -0
  17. package/dist/hooks/useWalletProviders.d.ts +1 -1
  18. package/dist/hooks/useWalletProviders.d.ts.map +1 -1
  19. package/dist/index.d.ts +1 -1
  20. package/dist/index.d.ts.map +1 -1
  21. package/dist/index.js +1 -1
  22. package/dist/index.js.map +4 -4
  23. package/dist/pages/ConfirmSwapPage.d.ts.map +1 -1
  24. package/dist/pages/Home.d.ts.map +1 -1
  25. package/dist/pages/SwapDetailsPage.d.ts.map +1 -1
  26. package/dist/types/config.d.ts +1 -1
  27. package/dist/types/config.d.ts.map +1 -1
  28. package/dist/utils/numbers.d.ts.map +1 -1
  29. package/dist/utils/providers.d.ts +1 -1
  30. package/dist/utils/providers.d.ts.map +1 -1
  31. package/package.json +8 -8
  32. package/src/QueueManager.tsx +1 -1
  33. package/src/Wallets.tsx +2 -2
  34. package/src/components/AppRouter.tsx +1 -1
  35. package/src/components/Layout.tsx +66 -13
  36. package/src/components/PercentageChange.tsx +33 -0
  37. package/src/components/RoutesOverview.tsx +57 -0
  38. package/src/components/SwapDetailsPlaceholder.tsx +47 -0
  39. package/src/components/SwitchFromAndTo.tsx +4 -34
  40. package/src/components/TokenInfo.tsx +329 -0
  41. package/src/components/TokenPreview.tsx +187 -0
  42. package/src/hooks/useWalletProviders.ts +1 -1
  43. package/src/index.ts +1 -1
  44. package/src/languages/en.json +14 -0
  45. package/src/languages/tr.json +11 -0
  46. package/src/pages/ConfirmSwapPage.tsx +10 -21
  47. package/src/pages/Home.tsx +144 -101
  48. package/src/pages/SwapDetailsPage.tsx +3 -6
  49. package/src/pages/WalletsPage.tsx +1 -1
  50. package/src/types/config.ts +1 -1
  51. package/src/utils/numbers.ts +0 -2
  52. package/src/utils/providers.ts +1 -1
  53. package/src/utils/wallets.ts +1 -1
@@ -1,8 +1,20 @@
1
- import React, { useEffect } from 'react';
2
- import { useNavigate } from 'react-router-dom';
3
- import { HomePanel } from '@rango-dev/ui';
1
+ import {
2
+ Alert,
3
+ BestRoute,
4
+ BottomLogo,
5
+ Button,
6
+ styled,
7
+ Typography,
8
+ VerticalSwapIcon,
9
+ Header,
10
+ HeaderButtons,
11
+ } from '@rango-dev/ui';
12
+ import React, { useEffect, useState } from 'react';
13
+ import { i18n } from '@lingui/core';
14
+ import { useInRouterContext, useNavigate } from 'react-router-dom';
15
+ import { TokenInfo } from '../components/TokenInfo';
4
16
  import { fetchBestRoute, useBestRouteStore } from '../store/bestRoute';
5
- import { SwithFromAndToButton } from '../components/SwitchFromAndTo';
17
+ import { SwithFromAndTo } from '../components/SwitchFromAndTo';
6
18
  import { navigationRoutes } from '../constants/navigationRoutes';
7
19
  import { useMetaStore } from '../store/meta';
8
20
  import { useWalletsStore } from '../store/wallets';
@@ -16,20 +28,54 @@ import {
16
28
  LimitErrorMessage,
17
29
  getTotalFeeInUsd,
18
30
  hasHighFee,
19
- getPercentageChange,
20
31
  } from '../utils/swap';
21
- import { useUiStore } from '../store/ui';
22
32
  import {
23
33
  numberToString,
24
34
  secondsToString,
25
35
  totalArrivalTime,
26
36
  } from '../utils/numbers';
27
- import { getBalanceFromWallet } from '../utils/wallets';
28
- import { getFormatedBestRoute } from '../utils/routing';
29
37
  import BigNumber from 'bignumber.js';
38
+ import { useUiStore } from '../store/ui';
39
+ import { getFormatedBestRoute } from '../utils/routing';
40
+
41
+ const Container = styled('div', {
42
+ display: 'flex',
43
+ flexDirection: 'column',
44
+ });
45
+
46
+ const FromContainer = styled('div', {
47
+ position: 'relative',
48
+ paddingBottom: '$12',
49
+ });
50
+
51
+ const SwitchButtonContainer = styled('div', {
52
+ position: 'absolute',
53
+ bottom: '-12px',
54
+ left: '50%',
55
+ transform: 'translate(-50%, 10%)',
56
+ });
57
+
58
+ const BestRouteContainer = styled('div', {
59
+ width: '100%',
60
+ paddingTop: '$16',
61
+ });
62
+
63
+ const Alerts = styled('div', {
64
+ width: '100%',
65
+ paddingTop: '$16',
66
+ });
67
+
68
+ const Footer = styled('div', {
69
+ display: 'flex',
70
+ flexDirection: 'column',
71
+ width: '100%',
72
+ paddingTop: '$16',
73
+ });
30
74
 
31
75
  export function Home() {
76
+ const isRouterInContext = useInRouterContext();
32
77
  const navigate = useNavigate();
78
+ const [count, setCount] = useState(0);
33
79
  const fromChain = useBestRouteStore.use.fromChain();
34
80
  const fromToken = useBestRouteStore.use.fromToken();
35
81
  const toChain = useBestRouteStore.use.toChain();
@@ -46,6 +92,7 @@ export function Home() {
46
92
  const loadingMetaStatus = useMetaStore.use.loadingStatus();
47
93
  const connectedWallets = useWalletsStore.use.connectedWallets();
48
94
  const setCurrentPage = useUiStore.use.setCurrentPage();
95
+ const switchFromAndTo = useBestRouteStore.use.switchFromAndTo();
49
96
 
50
97
  const errorMessage =
51
98
  loadingMetaStatus === 'failed'
@@ -55,7 +102,7 @@ export function Home() {
55
102
  const needsToWarnEthOnPath = false;
56
103
 
57
104
  const showBestRoute =
58
- !!inputAmount && (!!bestRoute || fetchingBestRoute || !!bestRouteError);
105
+ inputAmount && (!!bestRoute || fetchingBestRoute || bestRouteError);
59
106
 
60
107
  const outToInRatio = getOutputRatio(inputUsdValue, outputUsdValue);
61
108
 
@@ -87,105 +134,101 @@ export function Home() {
87
134
 
88
135
  const highFee = hasHighFee(totalFeeInUsd);
89
136
 
90
- const tokenBalance =
91
- !!fromChain && !!fromToken
92
- ? numberToString(
93
- getBalanceFromWallet(
94
- connectedWallets,
95
- fromChain?.name,
96
- fromToken?.symbol,
97
- fromToken?.address
98
- )?.amount || '0',
99
- 8
100
- )
101
- : '0';
102
-
103
- const tokenBalanceReal =
104
- !!fromChain && !!fromToken
105
- ? numberToString(
106
- getBalanceFromWallet(
107
- connectedWallets,
108
- fromChain?.name,
109
- fromToken?.symbol,
110
- fromToken?.address
111
- )?.amount || '0',
112
- getBalanceFromWallet(
113
- connectedWallets,
114
- fromChain?.name,
115
- fromToken?.symbol,
116
- fromToken?.address
117
- )?.decimal
118
- )
119
- : '0';
120
-
121
137
  useEffect(() => {
122
138
  setCurrentPage(navigationRoutes.home);
123
139
 
124
140
  return setCurrentPage.bind(null, '');
125
141
  }, []);
126
142
 
127
- const percentageChange =
128
- !inputUsdValue || !outputUsdValue || !outputUsdValue.gt(0)
129
- ? null
130
- : getPercentageChange(
131
- inputUsdValue.toNumber(),
132
- outputUsdValue.toNumber()
133
- );
134
-
135
143
  return (
136
- <HomePanel
137
- bestRoute={bestRoute}
138
- bestRouteError={bestRouteError}
139
- fetchBestRoute={fetchBestRoute}
140
- onClickHistory={() => navigate(navigationRoutes.swaps)}
141
- onClickSettings={() => navigate(navigationRoutes.settings)}
142
- setInputAmount={setInputAmount}
143
- fromChain={fromChain}
144
- toChain={toChain}
145
- fromToken={fromToken}
146
- toToken={toToken}
147
- outputAmount={
148
- outputAmount
149
- ? numberToString(new BigNumber(outputAmount))
150
- : numberToString(new BigNumber(0))
151
- }
152
- inputAmount={inputAmount}
153
- loadingStatus={loadingMetaStatus}
154
- showBestRoute={showBestRoute}
155
- fetchingBestRoute={fetchingBestRoute}
156
- outputUsdValue={numberToString(outputUsdValue)}
157
- inputUsdValue={numberToString(inputUsdValue)}
158
- swapButtonTitle={swapButtonState.title}
159
- swapButtonDisabled={swapButtonState.disabled}
160
- swapButtonClick={() => {
161
- if (swapButtonState.title === 'Connect Wallet')
162
- navigate(navigationRoutes.wallets);
163
- else {
164
- navigate(navigationRoutes.confirmSwap, { replace: true });
144
+ <Container>
145
+ <Header
146
+ title={i18n.t('SWAP')}
147
+ suffix={
148
+ <HeaderButtons
149
+ onClickRefresh={
150
+ !!bestRoute || bestRouteError ? fetchBestRoute : undefined
151
+ }
152
+ onClickHistory={() => navigate(navigationRoutes.swaps)}
153
+ onClickSettings={() => navigate(navigationRoutes.settings)}
154
+ />
155
+ }
156
+ />
157
+ <FromContainer>
158
+ <TokenInfo
159
+ type="From"
160
+ chain={fromChain}
161
+ token={fromToken}
162
+ onAmountChange={setInputAmount}
163
+ inputAmount={inputAmount}
164
+ />
165
+ <SwitchButtonContainer>
166
+ <Button
167
+ variant="ghost"
168
+ onClick={() => {
169
+ switchFromAndTo();
170
+ setCount((prev) => prev + 1);
171
+ }}>
172
+ <VerticalSwapIcon size={32} />
173
+ {isRouterInContext && <SwithFromAndTo count={count} />}
174
+ </Button>
175
+ </SwitchButtonContainer>
176
+ </FromContainer>
177
+ <TokenInfo
178
+ type="To"
179
+ chain={toChain}
180
+ token={toToken}
181
+ outputAmount={
182
+ outputAmount ? new BigNumber(outputAmount) : new BigNumber(0)
165
183
  }
166
- }}
167
- onChainClick={(route) => {
168
- navigate(route);
169
- }}
170
- onTokenClick={(route) => {
171
- navigate(route);
172
- }}
173
- highFee={highFee}
174
- errorMessage={errorMessage}
175
- hasLimitError={hasLimitError}
176
- swap={swap}
177
- fromAmountRangeError={fromAmountRangeError}
178
- recommendation={recommendation}
179
- totalFeeInUsd={numberToString(totalFeeInUsd, 0, 2)}
180
- swithFromAndToComponent={<SwithFromAndToButton />}
181
- connectedWallets={connectedWallets}
182
- percentageChange={numberToString(percentageChange, 0, 2)}
183
- showPercentageChange={!!percentageChange?.lt(0)}
184
- tokenBalanceReal={tokenBalanceReal}
185
- tokenBalance={tokenBalance}
186
- totalTime={secondsToString(totalArrivalTime(bestRoute))}
187
- bestRouteData={getFormatedBestRoute(bestRoute)}
188
- swapFromAmount={numberToString(swap?.fromAmount || null)}
189
- />
184
+ outputUsdValue={outputUsdValue}
185
+ />
186
+ {showBestRoute && (
187
+ <BestRouteContainer>
188
+ <BestRoute
189
+ error={bestRouteError}
190
+ loading={fetchingBestRoute}
191
+ data={getFormatedBestRoute(bestRoute)}
192
+ totalFee={numberToString(totalFeeInUsd, 0, 2)}
193
+ feeWarning={highFee}
194
+ totalTime={secondsToString(totalArrivalTime(bestRoute))}
195
+ />
196
+ </BestRouteContainer>
197
+ )}
198
+ {(errorMessage || hasLimitError(bestRoute)) && (
199
+ <Alerts>
200
+ {errorMessage && <Alert type="error">{errorMessage}</Alert>}
201
+ {hasLimitError(bestRoute) && (
202
+ <Alert type="error" title={`${swap?.swapperId} Limit`}>
203
+ <>
204
+ <Typography variant="body2">
205
+ {`${fromAmountRangeError}, Yours: ${numberToString(
206
+ swap?.fromAmount || null
207
+ )} ${swap?.from.symbol}`}
208
+ </Typography>
209
+ <Typography variant="body2">{recommendation}</Typography>
210
+ </>
211
+ </Alert>
212
+ )}
213
+ </Alerts>
214
+ )}
215
+ <Footer>
216
+ <Button
217
+ type="primary"
218
+ align="grow"
219
+ size="large"
220
+ disabled={swapButtonState.disabled}
221
+ onClick={() => {
222
+ if (swapButtonState.title === 'Connect Wallet')
223
+ navigate(navigationRoutes.wallets);
224
+ else {
225
+ navigate(navigationRoutes.confirmSwap, { replace: true });
226
+ }
227
+ }}>
228
+ {swapButtonState.title}
229
+ </Button>
230
+ <BottomLogo />
231
+ </Footer>
232
+ </Container>
190
233
  );
191
234
  }
@@ -3,17 +3,13 @@ import { navigationRoutes } from '../constants/navigationRoutes';
3
3
  import { useManager } from '@rango-dev/queue-manager-react';
4
4
  import { useNavigateBack } from '../hooks/useNavigateBack';
5
5
  import { getPendingSwaps } from '../utils/queue';
6
- import {
7
- SwapHistory,
8
- useCopyToClipboard,
9
- SwapDetailsPlaceholder,
10
- } from '@rango-dev/ui';
6
+ import { SwapHistory, useCopyToClipboard } from '@rango-dev/ui';
11
7
  import { useUiStore } from '../store/ui';
12
8
  import {
13
9
  cancelSwap,
14
10
  PendingSwapNetworkStatus,
15
11
  } from '@rango-dev/queue-manager-rango-preset';
16
- import { useWallets } from '@rango-dev/wallets-react';
12
+ import { useWallets } from '@rango-dev/wallets-core';
17
13
  import {
18
14
  getCurrentBlockchainOfOrNull,
19
15
  getCurrentStep,
@@ -28,6 +24,7 @@ import {
28
24
  isNetworkStatusInWarningState,
29
25
  shouldRetrySwap,
30
26
  } from '../utils/swap';
27
+ import { SwapDetailsPlaceholder } from '../components/SwapDetailsPlaceholder';
31
28
  import { getFormatedPendingSwap } from '../utils/routing';
32
29
 
33
30
  export function SwapDetailsPage() {
@@ -13,7 +13,7 @@ import {
13
13
  WalletTypes,
14
14
  detectMobileScreens,
15
15
  } from '@rango-dev/wallets-shared';
16
- import { useWallets } from '@rango-dev/wallets-react';
16
+ import { useWallets } from '@rango-dev/wallets-core';
17
17
 
18
18
  import { useUiStore } from '../store/ui';
19
19
  import { useNavigateBack } from '../hooks/useNavigateBack';
@@ -1,6 +1,6 @@
1
1
  import { Asset } from 'rango-sdk';
2
2
  import { WalletType } from '@rango-dev/wallets-shared';
3
- import { ProviderInterface } from '@rango-dev/wallets-react';
3
+ import { ProviderInterface } from '@rango-dev/wallets-core';
4
4
  import { Language } from '@rango-dev/ui';
5
5
 
6
6
  /**
@@ -3,7 +3,6 @@ import { BestRouteResponse } from 'rango-sdk';
3
3
 
4
4
  export const percentToString = (p: number, fractions = 0): string =>
5
5
  (p * 100).toFixed(fractions);
6
-
7
6
  export const secondsToString = (s: number): string => {
8
7
  const seconds = (s % 60).toString().padStart(2, '0');
9
8
  const minutes = parseInt((s / 60).toString())
@@ -88,7 +87,6 @@ export const convertBigNumberToHex = (
88
87
 
89
88
  export const uint8ArrayToHex = (buffer: Uint8Array): string => {
90
89
  // buffer is an ArrayBuffer
91
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
92
90
  // @ts-ignore
93
91
  return [...buffer].map((x) => x.toString(16).padStart(2, '0')).join('');
94
92
  };
@@ -1,5 +1,5 @@
1
1
  import { allProviders } from '@rango-dev/provider-all';
2
- import { ProviderInterface } from '@rango-dev/wallets-react';
2
+ import { ProviderInterface } from '@rango-dev/wallets-core';
3
3
  import { WidgetConfig } from '../types';
4
4
 
5
5
  export interface ProvidersOptions {
@@ -23,7 +23,7 @@ import {
23
23
  WalletDetail,
24
24
  } from 'rango-sdk';
25
25
  import { isCosmosBlockchain } from 'rango-types';
26
- import { readAccountAddress } from '@rango-dev/wallets-react';
26
+ import { readAccountAddress } from '@rango-dev/wallets-core';
27
27
  import { ConnectedWallet, TokenBalance } from '../store/wallets';
28
28
  import { numberToString } from './numbers';
29
29
  import BigNumber from 'bignumber.js';