@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.
- package/CHANGELOG.md +4 -0
- package/dist/Wallets.d.ts +1 -1
- package/dist/Wallets.d.ts.map +1 -1
- package/dist/components/Layout.d.ts.map +1 -1
- package/dist/components/PercentageChange.d.ts +9 -0
- package/dist/components/PercentageChange.d.ts.map +1 -0
- package/dist/components/RoutesOverview.d.ts +120 -0
- package/dist/components/RoutesOverview.d.ts.map +1 -0
- package/dist/components/SwapDetailsPlaceholder.d.ts +120 -0
- package/dist/components/SwapDetailsPlaceholder.d.ts.map +1 -0
- package/dist/components/SwitchFromAndTo.d.ts +3 -2
- package/dist/components/SwitchFromAndTo.d.ts.map +1 -1
- package/dist/components/TokenInfo.d.ts +18 -0
- package/dist/components/TokenInfo.d.ts.map +1 -0
- package/dist/components/TokenPreview.d.ts +21 -0
- package/dist/components/TokenPreview.d.ts.map +1 -0
- package/dist/hooks/useWalletProviders.d.ts +1 -1
- package/dist/hooks/useWalletProviders.d.ts.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +4 -4
- package/dist/pages/ConfirmSwapPage.d.ts.map +1 -1
- package/dist/pages/Home.d.ts.map +1 -1
- package/dist/pages/SwapDetailsPage.d.ts.map +1 -1
- package/dist/types/config.d.ts +1 -1
- package/dist/types/config.d.ts.map +1 -1
- package/dist/utils/numbers.d.ts.map +1 -1
- package/dist/utils/providers.d.ts +1 -1
- package/dist/utils/providers.d.ts.map +1 -1
- package/package.json +8 -8
- package/src/QueueManager.tsx +1 -1
- package/src/Wallets.tsx +2 -2
- package/src/components/AppRouter.tsx +1 -1
- package/src/components/Layout.tsx +66 -13
- package/src/components/PercentageChange.tsx +33 -0
- package/src/components/RoutesOverview.tsx +57 -0
- package/src/components/SwapDetailsPlaceholder.tsx +47 -0
- package/src/components/SwitchFromAndTo.tsx +4 -34
- package/src/components/TokenInfo.tsx +329 -0
- package/src/components/TokenPreview.tsx +187 -0
- package/src/hooks/useWalletProviders.ts +1 -1
- package/src/index.ts +1 -1
- package/src/languages/en.json +14 -0
- package/src/languages/tr.json +11 -0
- package/src/pages/ConfirmSwapPage.tsx +10 -21
- package/src/pages/Home.tsx +144 -101
- package/src/pages/SwapDetailsPage.tsx +3 -6
- package/src/pages/WalletsPage.tsx +1 -1
- package/src/types/config.ts +1 -1
- package/src/utils/numbers.ts +0 -2
- package/src/utils/providers.ts +1 -1
- package/src/utils/wallets.ts +1 -1
package/src/pages/Home.tsx
CHANGED
|
@@ -1,8 +1,20 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
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 {
|
|
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
|
-
|
|
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
|
-
<
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
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
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
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-
|
|
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-
|
|
16
|
+
import { useWallets } from '@rango-dev/wallets-core';
|
|
17
17
|
|
|
18
18
|
import { useUiStore } from '../store/ui';
|
|
19
19
|
import { useNavigateBack } from '../hooks/useNavigateBack';
|
package/src/types/config.ts
CHANGED
|
@@ -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-
|
|
3
|
+
import { ProviderInterface } from '@rango-dev/wallets-core';
|
|
4
4
|
import { Language } from '@rango-dev/ui';
|
|
5
5
|
|
|
6
6
|
/**
|
package/src/utils/numbers.ts
CHANGED
|
@@ -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
|
};
|
package/src/utils/providers.ts
CHANGED
package/src/utils/wallets.ts
CHANGED
|
@@ -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-
|
|
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';
|