@rango-dev/widget-embedded 0.5.1-next.2 → 0.5.1-next.21
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/dist/QueueManager.d.ts.map +1 -1
- package/dist/Wallets.d.ts +14 -0
- package/dist/Wallets.d.ts.map +1 -0
- package/dist/Widget.d.ts +3 -3
- package/dist/Widget.d.ts.map +1 -1
- package/dist/components/AppRouter.d.ts.map +1 -1
- package/dist/components/BottomLogo.d.ts.map +1 -1
- package/dist/components/ChangeSlippageButton.d.ts.map +1 -1
- package/dist/components/ConfirmSwapWarnings.d.ts +2 -2
- package/dist/components/ConfirmSwapWarnings.d.ts.map +1 -1
- package/dist/components/HeaderButtons.d.ts.map +1 -1
- package/dist/components/Layout.d.ts.map +1 -1
- package/dist/components/SwapDetailsPlaceholder.d.ts.map +1 -1
- package/dist/components/TokenInfo.d.ts.map +1 -1
- package/dist/components/TokenPreview.d.ts.map +1 -1
- package/dist/components/WidgetEvents.d.ts +2 -0
- package/dist/components/WidgetEvents.d.ts.map +1 -0
- package/dist/components/warnings/HighSlippageWarning.d.ts.map +1 -1
- package/dist/components/warnings/MinRequiredSlippage.d.ts.map +1 -1
- package/dist/hooks/useConfirmSwap.d.ts +1 -1
- package/dist/hooks/useConfirmSwap.d.ts.map +1 -1
- package/dist/hooks/useWalletProviders.d.ts +6 -0
- package/dist/hooks/useWalletProviders.d.ts.map +1 -0
- package/dist/index.d.ts +5 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +4 -4
- package/dist/pages/Home.d.ts.map +1 -1
- package/dist/pages/WalletsPage.d.ts +2 -2
- package/dist/pages/WalletsPage.d.ts.map +1 -1
- package/dist/store/wallets.d.ts +2 -2
- package/dist/store/wallets.d.ts.map +1 -1
- package/dist/types/config.d.ts +8 -2
- package/dist/types/config.d.ts.map +1 -1
- package/dist/types/swap.d.ts +1 -1
- package/dist/types/swap.d.ts.map +1 -1
- package/dist/utils/providers.d.ts +11 -0
- package/dist/utils/providers.d.ts.map +1 -0
- package/dist/utils/routing.d.ts +1 -1
- package/dist/utils/routing.d.ts.map +1 -1
- package/dist/utils/swap.d.ts.map +1 -1
- package/dist/utils/wallets.d.ts.map +1 -1
- package/package.json +10 -13
- package/src/QueueManager.tsx +0 -25
- package/src/Wallets.tsx +105 -0
- package/src/Widget.tsx +41 -84
- package/src/components/AppRouter.tsx +0 -2
- package/src/components/BottomLogo.tsx +2 -4
- package/src/components/ChangeSlippageButton.tsx +3 -3
- package/src/components/ConfirmSwapWarnings.tsx +10 -13
- package/src/components/HeaderButtons.tsx +7 -9
- package/src/components/Layout.tsx +10 -11
- package/src/components/SwapDetailsPlaceholder.tsx +10 -2
- package/src/components/TokenInfo.tsx +26 -23
- package/src/components/TokenPreview.tsx +11 -12
- package/src/components/WidgetEvents.tsx +45 -0
- package/src/components/warnings/BalanceErrors.tsx +3 -3
- package/src/components/warnings/HighSlippageWarning.tsx +9 -2
- package/src/components/warnings/MinRequiredSlippage.tsx +11 -4
- package/src/hooks/useConfirmSwap.ts +6 -3
- package/src/hooks/useWalletProviders.ts +20 -0
- package/src/index.ts +57 -1
- package/src/pages/ConfirmSwapPage.tsx +5 -5
- package/src/pages/Home.tsx +4 -5
- package/src/pages/WalletsPage.tsx +10 -7
- package/src/store/wallets.ts +42 -17
- package/src/types/config.ts +8 -2
- package/src/types/swap.ts +1 -1
- package/src/utils/providers.ts +53 -0
- package/src/utils/routing.ts +1 -1
- package/src/utils/swap.ts +26 -13
- package/src/utils/wallets.ts +31 -11
- package/dist/hooks/useSelectLanguage.d.ts +0 -5
- package/dist/hooks/useSelectLanguage.d.ts.map +0 -1
- package/dist/i18n.d.ts +0 -3
- package/dist/i18n.d.ts.map +0 -1
- package/dist/mockData/pendingSwap.d.ts +0 -2
- package/dist/mockData/pendingSwap.d.ts.map +0 -1
- package/src/hooks/useSelectLanguage.ts +0 -15
- package/src/i18n.js +0 -30
- package/src/mockData/pendingSwap.ts +0 -607
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
} from '@rango-dev/ui';
|
|
10
10
|
import { useNavigate } from 'react-router-dom';
|
|
11
11
|
import { navigationRoutes } from '../constants/navigationRoutes';
|
|
12
|
+
import { i18n } from '@lingui/core';
|
|
12
13
|
|
|
13
14
|
const ButtonsContainer = styled('div', {
|
|
14
15
|
display: 'flex',
|
|
@@ -24,28 +25,25 @@ export function HeaderButtons(props: PropTypes) {
|
|
|
24
25
|
|
|
25
26
|
return (
|
|
26
27
|
<ButtonsContainer>
|
|
27
|
-
<Tooltip content=
|
|
28
|
+
<Tooltip content={i18n.t('Refresh')}>
|
|
28
29
|
<Button
|
|
29
30
|
variant="ghost"
|
|
30
31
|
onClick={onClickRefresh}
|
|
31
|
-
disabled={!onClickRefresh}
|
|
32
|
-
>
|
|
32
|
+
disabled={!onClickRefresh}>
|
|
33
33
|
<RetryIcon size={24} disabled={!onClickRefresh} />
|
|
34
34
|
</Button>
|
|
35
35
|
</Tooltip>
|
|
36
|
-
<Tooltip content=
|
|
36
|
+
<Tooltip content={i18n.t('Transactions History')}>
|
|
37
37
|
<Button
|
|
38
38
|
variant="ghost"
|
|
39
|
-
onClick={() => navigate(navigationRoutes.swaps)}
|
|
40
|
-
>
|
|
39
|
+
onClick={() => navigate(navigationRoutes.swaps)}>
|
|
41
40
|
<HistoryIcon size={24} />
|
|
42
41
|
</Button>
|
|
43
42
|
</Tooltip>
|
|
44
|
-
<Tooltip content=
|
|
43
|
+
<Tooltip content={i18n.t('Settings')}>
|
|
45
44
|
<Button
|
|
46
45
|
variant="ghost"
|
|
47
|
-
onClick={() => navigate(navigationRoutes.settings)}
|
|
48
|
-
>
|
|
46
|
+
onClick={() => navigate(navigationRoutes.settings)}>
|
|
49
47
|
<SettingsIcon size={24} />
|
|
50
48
|
</Button>
|
|
51
49
|
</Tooltip>
|
|
@@ -20,7 +20,7 @@ import {
|
|
|
20
20
|
} from '../utils/wallets';
|
|
21
21
|
import { removeDuplicateFrom } from '../utils/common';
|
|
22
22
|
import { WidgetConfig } from '../types';
|
|
23
|
-
import {
|
|
23
|
+
import { i18n } from '@lingui/core';
|
|
24
24
|
import { useBestRouteStore } from '../store/bestRoute';
|
|
25
25
|
import { useMetaStore } from '../store/meta';
|
|
26
26
|
import { useSettingsStore } from '../store/settings';
|
|
@@ -57,7 +57,7 @@ export function Layout({ config }: LayoutProps) {
|
|
|
57
57
|
const { getWalletInfo } = useWallets();
|
|
58
58
|
const connectedWalletsImages = removeDuplicateFrom(
|
|
59
59
|
getSelectableWallets(connectedWallets, selectedWallets, getWalletInfo).map(
|
|
60
|
-
w => w.image
|
|
60
|
+
(w) => w.image
|
|
61
61
|
)
|
|
62
62
|
);
|
|
63
63
|
const { blockchains, tokens } = useMetaStore.use.meta();
|
|
@@ -69,17 +69,17 @@ export function Layout({ config }: LayoutProps) {
|
|
|
69
69
|
const setAffiliateRef = useSettingsStore.use.setAffiliateRef();
|
|
70
70
|
|
|
71
71
|
const totalBalance = calculateWalletUsdValue(connectedWallets);
|
|
72
|
-
const connectWalletsButtonDisabled =
|
|
72
|
+
const connectWalletsButtonDisabled =
|
|
73
|
+
useUiStore.use.connectWalletsButtonDisabled();
|
|
73
74
|
const loadingMetaStatus = useMetaStore.use.loadingStatus();
|
|
74
75
|
const fetchingBalance = useWalletsStore(fetchingBalanceSelector);
|
|
75
76
|
|
|
76
|
-
const { t } = useTranslation();
|
|
77
77
|
useEffect(() => {
|
|
78
78
|
if (loadingMetaStatus === 'success') {
|
|
79
79
|
const chain = blockchains.find(
|
|
80
|
-
chain => chain.name === config?.to?.blockchain
|
|
80
|
+
(chain) => chain.name === config?.to?.blockchain
|
|
81
81
|
);
|
|
82
|
-
const token = tokens.find(t =>
|
|
82
|
+
const token = tokens.find((t) =>
|
|
83
83
|
tokensAreEqual(t, config?.to?.token || null)
|
|
84
84
|
);
|
|
85
85
|
setToChain(chain || null);
|
|
@@ -94,9 +94,9 @@ export function Layout({ config }: LayoutProps) {
|
|
|
94
94
|
useEffect(() => {
|
|
95
95
|
if (loadingMetaStatus === 'success') {
|
|
96
96
|
const chain = blockchains.find(
|
|
97
|
-
chain => chain.name === config?.from?.blockchain
|
|
97
|
+
(chain) => chain.name === config?.from?.blockchain
|
|
98
98
|
);
|
|
99
|
-
const token = tokens.find(t =>
|
|
99
|
+
const token = tokens.find((t) =>
|
|
100
100
|
tokensAreEqual(t, config?.from?.token || null)
|
|
101
101
|
);
|
|
102
102
|
|
|
@@ -132,12 +132,11 @@ export function Layout({ config }: LayoutProps) {
|
|
|
132
132
|
))}
|
|
133
133
|
</WalletImages>
|
|
134
134
|
) : null
|
|
135
|
-
}
|
|
136
|
-
>
|
|
135
|
+
}>
|
|
137
136
|
<div className="balance">
|
|
138
137
|
<Typography variant="body2">
|
|
139
138
|
{!connectedWallets?.length
|
|
140
|
-
? t('Connect Wallet')
|
|
139
|
+
? i18n.t('Connect Wallet')
|
|
141
140
|
: `$${totalBalance || 0}`}
|
|
142
141
|
</Typography>
|
|
143
142
|
{fetchingBalance && <Spinner />}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { SecondaryPage, Spinner, Alert, styled } from '@rango-dev/ui';
|
|
3
|
+
import { i18n } from '@lingui/core';
|
|
3
4
|
|
|
4
5
|
const PlaceholderContainer = styled('div', { height: '450px' });
|
|
5
6
|
|
|
@@ -21,7 +22,10 @@ export function SwapDetailsPlaceholder(props: PropTypes) {
|
|
|
21
22
|
const { requestId, loading, onBack } = props;
|
|
22
23
|
|
|
23
24
|
return (
|
|
24
|
-
<SecondaryPage
|
|
25
|
+
<SecondaryPage
|
|
26
|
+
title={i18n.t('Swap Details')}
|
|
27
|
+
textField={false}
|
|
28
|
+
onBack={onBack}>
|
|
25
29
|
<PlaceholderContainer>
|
|
26
30
|
{loading ? (
|
|
27
31
|
<LoaderContainer>
|
|
@@ -30,7 +34,11 @@ export function SwapDetailsPlaceholder(props: PropTypes) {
|
|
|
30
34
|
) : (
|
|
31
35
|
<Alert
|
|
32
36
|
type="secondary"
|
|
33
|
-
title={
|
|
37
|
+
title={i18n.t(
|
|
38
|
+
'swapNotFound',
|
|
39
|
+
{ requestId },
|
|
40
|
+
{ message: 'Swap with request ID = ${requestId} not found.' }
|
|
41
|
+
)}
|
|
34
42
|
/>
|
|
35
43
|
)}
|
|
36
44
|
</PlaceholderContainer>
|
|
@@ -17,7 +17,8 @@ import { numberToString } from '../utils/numbers';
|
|
|
17
17
|
import BigNumber from 'bignumber.js';
|
|
18
18
|
import { getBalanceFromWallet } from '../utils/wallets';
|
|
19
19
|
import { useWalletsStore } from '../store/wallets';
|
|
20
|
-
import {
|
|
20
|
+
import { Trans } from '@lingui/react';
|
|
21
|
+
import { i18n } from '@lingui/core';
|
|
21
22
|
import { PercentageChange } from './PercentageChange';
|
|
22
23
|
|
|
23
24
|
type PropTypes = (
|
|
@@ -136,7 +137,6 @@ export function TokenInfo(props: PropTypes) {
|
|
|
136
137
|
const connectedWallets = useWalletsStore.use.connectedWallets();
|
|
137
138
|
const fetchingBestRoute = useBestRouteStore.use.loading();
|
|
138
139
|
const navigate = useNavigate();
|
|
139
|
-
const { t } = useTranslation();
|
|
140
140
|
|
|
141
141
|
const tokenBalance =
|
|
142
142
|
!!fromChain && !!fromToken
|
|
@@ -175,8 +175,7 @@ export function TokenInfo(props: PropTypes) {
|
|
|
175
175
|
display: 'flex',
|
|
176
176
|
justifyContent: 'center',
|
|
177
177
|
alignItems: 'center',
|
|
178
|
-
}}
|
|
179
|
-
>
|
|
178
|
+
}}>
|
|
180
179
|
{loadingStatus === 'failed' && <InfoCircleIcon color="error" size={24} />}
|
|
181
180
|
<AngleDownIcon />
|
|
182
181
|
</div>
|
|
@@ -187,7 +186,11 @@ export function TokenInfo(props: PropTypes) {
|
|
|
187
186
|
<Container type={props.type === 'From' ? 'filled' : 'outlined'}>
|
|
188
187
|
<div className="head">
|
|
189
188
|
<Typography variant="body2" color="neutral800">
|
|
190
|
-
{
|
|
189
|
+
{type === 'From' ? (
|
|
190
|
+
<Trans id="swap from" message="From" />
|
|
191
|
+
) : (
|
|
192
|
+
<Trans id="swap to" message="To" />
|
|
193
|
+
)}
|
|
191
194
|
</Typography>
|
|
192
195
|
{props.type === 'From' ? (
|
|
193
196
|
<Options>
|
|
@@ -196,14 +199,13 @@ export function TokenInfo(props: PropTypes) {
|
|
|
196
199
|
onClick={() => {
|
|
197
200
|
if (tokenBalance !== '0')
|
|
198
201
|
setInputAmount(tokenBalanceReal.split(',').join(''));
|
|
199
|
-
}}
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
)}: ${tokenBalance} ${fromToken?.symbol || ''}`}</Typography>
|
|
202
|
+
}}>
|
|
203
|
+
<Typography variant="body3" color="neutral600">
|
|
204
|
+
{i18n.t('Balance')}: {tokenBalance} {fromToken?.symbol || ''}
|
|
205
|
+
</Typography>
|
|
204
206
|
<Divider size={4} />
|
|
205
207
|
<Button type="primary" variant="ghost" size="compact">
|
|
206
|
-
|
|
208
|
+
<Trans id="maximum amount of asset" message="Max" />
|
|
207
209
|
</Button>
|
|
208
210
|
</div>
|
|
209
211
|
</Options>
|
|
@@ -216,8 +218,9 @@ export function TokenInfo(props: PropTypes) {
|
|
|
216
218
|
<div>
|
|
217
219
|
<Typography
|
|
218
220
|
variant="caption"
|
|
219
|
-
color="neutral600"
|
|
220
|
-
|
|
221
|
+
color="neutral600">{`$${numberToString(
|
|
222
|
+
props.outputUsdValue
|
|
223
|
+
)}`}</Typography>
|
|
221
224
|
</div>
|
|
222
225
|
</div>
|
|
223
226
|
)}
|
|
@@ -240,11 +243,10 @@ export function TokenInfo(props: PropTypes) {
|
|
|
240
243
|
}
|
|
241
244
|
suffix={ItemSuffix}
|
|
242
245
|
align="start"
|
|
243
|
-
size="large"
|
|
244
|
-
>
|
|
246
|
+
size="large">
|
|
245
247
|
{loadingStatus === 'success' && chain
|
|
246
248
|
? chain.displayName
|
|
247
|
-
: t('Chain')}
|
|
249
|
+
: i18n.t('Chain')}
|
|
248
250
|
</Button>
|
|
249
251
|
<Divider size={12} direction="horizontal" />
|
|
250
252
|
<Button
|
|
@@ -268,9 +270,10 @@ export function TokenInfo(props: PropTypes) {
|
|
|
268
270
|
}
|
|
269
271
|
suffix={ItemSuffix}
|
|
270
272
|
size="large"
|
|
271
|
-
align="start"
|
|
272
|
-
|
|
273
|
-
|
|
273
|
+
align="start">
|
|
274
|
+
{loadingStatus === 'success' && token
|
|
275
|
+
? token.symbol
|
|
276
|
+
: i18n.t('Token')}
|
|
274
277
|
</Button>
|
|
275
278
|
<Divider size={12} direction="horizontal" />
|
|
276
279
|
<div className="amount">
|
|
@@ -290,12 +293,12 @@ export function TokenInfo(props: PropTypes) {
|
|
|
290
293
|
position: 'absolute',
|
|
291
294
|
right: '4px',
|
|
292
295
|
bottom: '2px',
|
|
293
|
-
}}
|
|
294
|
-
>
|
|
296
|
+
}}>
|
|
295
297
|
<Typography
|
|
296
298
|
variant="caption"
|
|
297
|
-
color="neutral800"
|
|
298
|
-
|
|
299
|
+
color="neutral800">{`$${numberToString(
|
|
300
|
+
inputUsdValue
|
|
301
|
+
)}`}</Typography>
|
|
299
302
|
</span>
|
|
300
303
|
}
|
|
301
304
|
value={props.inputAmount || ''}
|
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
Image,
|
|
9
9
|
} from '@rango-dev/ui';
|
|
10
10
|
import { LoadingStatus } from '../store/meta';
|
|
11
|
-
import {
|
|
11
|
+
import { i18n } from '@lingui/core';
|
|
12
12
|
import BigNumber from 'bignumber.js';
|
|
13
13
|
import { numberToString } from '../utils/numbers';
|
|
14
14
|
|
|
@@ -105,7 +105,6 @@ interface PropTypes {
|
|
|
105
105
|
|
|
106
106
|
export function TokenPreview(props: PropTypes) {
|
|
107
107
|
const { chain, token, loadingStatus, percentageChange } = props;
|
|
108
|
-
const { t } = useTranslation();
|
|
109
108
|
|
|
110
109
|
const ItemSuffix = (
|
|
111
110
|
<div
|
|
@@ -113,8 +112,7 @@ export function TokenPreview(props: PropTypes) {
|
|
|
113
112
|
display: 'flex',
|
|
114
113
|
justifyContent: 'center',
|
|
115
114
|
alignItems: 'center',
|
|
116
|
-
}}
|
|
117
|
-
>
|
|
115
|
+
}}>
|
|
118
116
|
{loadingStatus === 'failed' && <InfoCircleIcon color="error" size={24} />}
|
|
119
117
|
</div>
|
|
120
118
|
);
|
|
@@ -132,8 +130,9 @@ export function TokenPreview(props: PropTypes) {
|
|
|
132
130
|
<Typography
|
|
133
131
|
variant="caption"
|
|
134
132
|
color="neutral600"
|
|
135
|
-
className="usd-value"
|
|
136
|
-
|
|
133
|
+
className="usd-value">{`$${numberToString(
|
|
134
|
+
props.usdValue
|
|
135
|
+
)}`}</Typography>
|
|
137
136
|
)}
|
|
138
137
|
</div>
|
|
139
138
|
</div>
|
|
@@ -151,11 +150,10 @@ export function TokenPreview(props: PropTypes) {
|
|
|
151
150
|
}
|
|
152
151
|
suffix={ItemSuffix}
|
|
153
152
|
align="start"
|
|
154
|
-
size="large"
|
|
155
|
-
>
|
|
153
|
+
size="large">
|
|
156
154
|
{loadingStatus === 'success' && chain
|
|
157
155
|
? chain.displayName
|
|
158
|
-
: t('Chain')}
|
|
156
|
+
: i18n.t('Chain')}
|
|
159
157
|
</Button>
|
|
160
158
|
<Divider size={12} direction="horizontal" />
|
|
161
159
|
<Button
|
|
@@ -171,9 +169,10 @@ export function TokenPreview(props: PropTypes) {
|
|
|
171
169
|
}
|
|
172
170
|
suffix={ItemSuffix}
|
|
173
171
|
size="large"
|
|
174
|
-
align="start"
|
|
175
|
-
|
|
176
|
-
|
|
172
|
+
align="start">
|
|
173
|
+
{loadingStatus === 'success' && token
|
|
174
|
+
? token.symbol
|
|
175
|
+
: i18n.t('Token')}
|
|
177
176
|
</Button>
|
|
178
177
|
<Divider size={12} direction="horizontal" />
|
|
179
178
|
<div className="amount">
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { useEffect } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
useEvents,
|
|
4
|
+
MainEvents,
|
|
5
|
+
StepEventType,
|
|
6
|
+
StepExecutionEventStatus,
|
|
7
|
+
isApprovalTX,
|
|
8
|
+
} from '@rango-dev/queue-manager-rango-preset';
|
|
9
|
+
import { useWalletsStore } from '../store/wallets';
|
|
10
|
+
|
|
11
|
+
export function WidgetEvents() {
|
|
12
|
+
const connectedWallets = useWalletsStore.use.connectedWallets();
|
|
13
|
+
const getWalletsDetails = useWalletsStore.use.getWalletsDetails();
|
|
14
|
+
|
|
15
|
+
const widgetEvents = useEvents();
|
|
16
|
+
|
|
17
|
+
useEffect(() => {
|
|
18
|
+
widgetEvents.on(MainEvents.StepEvent, (widgetEvent) => {
|
|
19
|
+
const { event, step } = widgetEvent;
|
|
20
|
+
const shouldRefetchBalance =
|
|
21
|
+
(event.type === StepEventType.TX_EXECUTION &&
|
|
22
|
+
event.status === StepExecutionEventStatus.TX_SENT &&
|
|
23
|
+
!isApprovalTX(step)) ||
|
|
24
|
+
event.type === StepEventType.SUCCEEDED;
|
|
25
|
+
|
|
26
|
+
if (shouldRefetchBalance) {
|
|
27
|
+
const fromAccount = connectedWallets.find(
|
|
28
|
+
(account) => account.chain === step?.fromBlockchain
|
|
29
|
+
);
|
|
30
|
+
const toAccount =
|
|
31
|
+
step?.fromBlockchain !== step?.toBlockchain &&
|
|
32
|
+
connectedWallets.find(
|
|
33
|
+
(wallet) => wallet.chain === step?.toBlockchain
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
fromAccount && getWalletsDetails([fromAccount]);
|
|
37
|
+
toAccount && getWalletsDetails([toAccount]);
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
return () => widgetEvents.all.clear();
|
|
42
|
+
}, [widgetEvents, connectedWallets.length]);
|
|
43
|
+
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Divider, styled, Typography } from '@rango-dev/ui';
|
|
2
2
|
import React from 'react';
|
|
3
|
-
|
|
3
|
+
import { i18n } from '@lingui/core';
|
|
4
4
|
interface PropTypes {
|
|
5
5
|
messages: string[];
|
|
6
6
|
}
|
|
@@ -32,7 +32,7 @@ export function BalanceErrors({ messages }: PropTypes) {
|
|
|
32
32
|
return (
|
|
33
33
|
<>
|
|
34
34
|
<Typography className="title" variant="title" color={'error'}>
|
|
35
|
-
Insufficent Balance:
|
|
35
|
+
{i18n.t('Insufficent Balance:')}
|
|
36
36
|
</Typography>
|
|
37
37
|
<Divider size={8} />
|
|
38
38
|
<List showListStyle={showListStyle}>
|
|
@@ -44,4 +44,4 @@ export function BalanceErrors({ messages }: PropTypes) {
|
|
|
44
44
|
</List>
|
|
45
45
|
</>
|
|
46
46
|
);
|
|
47
|
-
}
|
|
47
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Alert } from '@rango-dev/ui';
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import { ChangeSlippageButton } from '../ChangeSlippageButton';
|
|
4
|
+
import { i18n } from '@lingui/core';
|
|
4
5
|
|
|
5
6
|
interface PropTypes {
|
|
6
7
|
selectedSlippage: number;
|
|
@@ -11,8 +12,14 @@ export function HighSlippageWarning(props: PropTypes) {
|
|
|
11
12
|
|
|
12
13
|
return (
|
|
13
14
|
<Alert type="warning" footer={<ChangeSlippageButton />}>
|
|
14
|
-
|
|
15
|
-
|
|
15
|
+
{i18n.t(
|
|
16
|
+
'highSlippage',
|
|
17
|
+
{ selectedSlippage },
|
|
18
|
+
{
|
|
19
|
+
message:
|
|
20
|
+
' Caution, your slippage is high (={selectedSlippage}). Your trade may be front run.',
|
|
21
|
+
}
|
|
22
|
+
)}
|
|
16
23
|
</Alert>
|
|
17
24
|
);
|
|
18
25
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Divider, Typography, styled } from '@rango-dev/ui';
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import { ChangeSlippageButton } from '../ChangeSlippageButton';
|
|
4
|
+
import { i18n } from '@lingui/core';
|
|
4
5
|
|
|
5
6
|
interface PropTypes {
|
|
6
7
|
minRequiredSlippage: string | null;
|
|
@@ -13,10 +14,16 @@ const StyledMessage = styled(Typography, {
|
|
|
13
14
|
export function MinRequiredSlippage({ minRequiredSlippage }: PropTypes) {
|
|
14
15
|
return (
|
|
15
16
|
<StyledMessage variant="body2">
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
{i18n.t(
|
|
18
|
+
'increaseSlippage',
|
|
19
|
+
{ minRequiredSlippage },
|
|
20
|
+
{
|
|
21
|
+
message:
|
|
22
|
+
'We recommend you to increase slippage to at least {minRequiredSlippage} for this route.',
|
|
23
|
+
}
|
|
24
|
+
)}
|
|
25
|
+
|
|
26
|
+
<Divider size={8} />
|
|
20
27
|
<ChangeSlippageButton />
|
|
21
28
|
</StyledMessage>
|
|
22
29
|
);
|
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
ConfirmSwapWarnings,
|
|
11
11
|
PendingSwapSettings,
|
|
12
12
|
} from '../types';
|
|
13
|
-
|
|
13
|
+
|
|
14
14
|
import {
|
|
15
15
|
createBestRouteRequestBody,
|
|
16
16
|
getBalanceWarnings,
|
|
@@ -33,7 +33,10 @@ import {
|
|
|
33
33
|
} from '../utils/routing';
|
|
34
34
|
import { numberToString } from '../utils/numbers';
|
|
35
35
|
import { BestRouteResponse } from 'rango-sdk';
|
|
36
|
-
import {
|
|
36
|
+
import {
|
|
37
|
+
calculatePendingSwap,
|
|
38
|
+
PendingSwap,
|
|
39
|
+
} from '@rango-dev/queue-manager-rango-preset';
|
|
37
40
|
|
|
38
41
|
type ConfirmSwap = {
|
|
39
42
|
loading: boolean;
|
|
@@ -63,7 +66,7 @@ export function useConfirmSwap(): ConfirmSwap {
|
|
|
63
66
|
const userSlippage = customSlippage || slippage;
|
|
64
67
|
const proceedAnywayRef = useRef(false);
|
|
65
68
|
const confiremedRouteRef = useRef<BestRouteResponse | null>(null);
|
|
66
|
-
|
|
69
|
+
const abortControllerRef = useRef<AbortController | null>(null);
|
|
67
70
|
|
|
68
71
|
const [loading, setLoading] = useState(false);
|
|
69
72
|
const [errors, setErrors] = useState<ConfirmSwapError[]>([]);
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { ProviderInterface } from '@rango-dev/wallets-core';
|
|
2
|
+
import { useEffect } from 'react';
|
|
3
|
+
import { useWalletsStore } from '../store/wallets';
|
|
4
|
+
import { WidgetConfig } from '../types';
|
|
5
|
+
import { matchAndGenerateProviders } from '../utils/providers';
|
|
6
|
+
|
|
7
|
+
export function useWalletProviders(providers: WidgetConfig['wallets']) {
|
|
8
|
+
const clearConnectedWallet = useWalletsStore.use.clearConnectedWallet();
|
|
9
|
+
let generateProviders: ProviderInterface[] =
|
|
10
|
+
matchAndGenerateProviders(undefined);
|
|
11
|
+
|
|
12
|
+
useEffect(() => {
|
|
13
|
+
clearConnectedWallet();
|
|
14
|
+
generateProviders = matchAndGenerateProviders(providers);
|
|
15
|
+
}, [providers]);
|
|
16
|
+
|
|
17
|
+
return {
|
|
18
|
+
providers: generateProviders,
|
|
19
|
+
};
|
|
20
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -6,13 +6,69 @@ import {
|
|
|
6
6
|
} from './types';
|
|
7
7
|
import { WidgetProps, Widget } from './Widget';
|
|
8
8
|
import { WalletType } from '@rango-dev/wallets-shared';
|
|
9
|
+
import { WidgetWallets } from './Wallets';
|
|
10
|
+
import {
|
|
11
|
+
useWallets,
|
|
12
|
+
ProviderInterface,
|
|
13
|
+
EventHandler as HandleWalletsUpdate,
|
|
14
|
+
} from '@rango-dev/wallets-core';
|
|
15
|
+
import {
|
|
16
|
+
useEvents as useWidgetEvents,
|
|
17
|
+
MainEvents,
|
|
18
|
+
RouteEvent,
|
|
19
|
+
StepEvent,
|
|
20
|
+
Route,
|
|
21
|
+
Step,
|
|
22
|
+
RouteStartedEvent,
|
|
23
|
+
RouteSucceededEvent,
|
|
24
|
+
RouteFailedEvent,
|
|
25
|
+
RouteEventType,
|
|
26
|
+
StepStartedEvent,
|
|
27
|
+
StepSucceededEvent,
|
|
28
|
+
StepFailedEvent,
|
|
29
|
+
StepTxExecutionUpdatedEvent,
|
|
30
|
+
StepTxExecutionBlockedEvent,
|
|
31
|
+
StepCheckStatusEvent,
|
|
32
|
+
StepApprovalTxSucceededEvent,
|
|
33
|
+
StepOutputRevealedEvent,
|
|
34
|
+
StepEventType,
|
|
35
|
+
StepExecutionEventStatus,
|
|
36
|
+
StepExecutionBlockedEventStatus,
|
|
37
|
+
} from '@rango-dev/queue-manager-rango-preset';
|
|
9
38
|
|
|
10
39
|
export type {
|
|
11
40
|
WidgetConfig,
|
|
12
41
|
WalletType,
|
|
13
42
|
WidgetTheme,
|
|
14
43
|
WidgetColors,
|
|
44
|
+
ProviderInterface,
|
|
15
45
|
BlockchainAndTokenConfig,
|
|
16
46
|
WidgetProps,
|
|
47
|
+
RouteEvent,
|
|
48
|
+
StepEvent,
|
|
49
|
+
Route,
|
|
50
|
+
Step,
|
|
51
|
+
RouteStartedEvent,
|
|
52
|
+
RouteSucceededEvent,
|
|
53
|
+
RouteFailedEvent,
|
|
54
|
+
StepStartedEvent,
|
|
55
|
+
StepSucceededEvent,
|
|
56
|
+
StepFailedEvent,
|
|
57
|
+
StepTxExecutionUpdatedEvent,
|
|
58
|
+
StepTxExecutionBlockedEvent,
|
|
59
|
+
StepCheckStatusEvent,
|
|
60
|
+
StepApprovalTxSucceededEvent,
|
|
61
|
+
StepOutputRevealedEvent,
|
|
62
|
+
HandleWalletsUpdate,
|
|
63
|
+
};
|
|
64
|
+
export {
|
|
65
|
+
Widget,
|
|
66
|
+
WidgetWallets,
|
|
67
|
+
useWallets,
|
|
68
|
+
useWidgetEvents,
|
|
69
|
+
MainEvents,
|
|
70
|
+
RouteEventType,
|
|
71
|
+
StepEventType,
|
|
72
|
+
StepExecutionEventStatus,
|
|
73
|
+
StepExecutionBlockedEventStatus,
|
|
17
74
|
};
|
|
18
|
-
export { Widget };
|
|
@@ -3,6 +3,7 @@ import { useNavigate } from 'react-router-dom';
|
|
|
3
3
|
import { useBestRouteStore } from '../store/bestRoute';
|
|
4
4
|
import { useWalletsStore } from '../store/wallets';
|
|
5
5
|
import { useWallets } from '@rango-dev/wallets-core';
|
|
6
|
+
import { i18n } from '@lingui/core';
|
|
6
7
|
import { navigationRoutes } from '../constants/navigationRoutes';
|
|
7
8
|
import {
|
|
8
9
|
getKeplrCompatibleConnectedWallets,
|
|
@@ -20,7 +21,6 @@ import { useMetaStore } from '../store/meta';
|
|
|
20
21
|
import { WalletType } from '@rango-dev/wallets-shared';
|
|
21
22
|
import { useNavigateBack } from '../hooks/useNavigateBack';
|
|
22
23
|
import { TokenPreview } from '../components/TokenPreview';
|
|
23
|
-
import { t } from 'i18next';
|
|
24
24
|
import { Divider, ConfirmSwap, LoadingFailedAlert } from '@rango-dev/ui';
|
|
25
25
|
import RoutesOverview from '../components/RoutesOverview';
|
|
26
26
|
import { useManager } from '@rango-dev/queue-manager-react';
|
|
@@ -179,7 +179,7 @@ export function ConfirmSwapPage({
|
|
|
179
179
|
}}
|
|
180
180
|
usdValue={inputUsdValue}
|
|
181
181
|
amount={fromAmount}
|
|
182
|
-
label={t('From')}
|
|
182
|
+
label={i18n.t('From')}
|
|
183
183
|
loadingStatus={
|
|
184
184
|
loadingMetaStatus !== 'success'
|
|
185
185
|
? loadingMetaStatus
|
|
@@ -198,7 +198,7 @@ export function ConfirmSwapPage({
|
|
|
198
198
|
}}
|
|
199
199
|
usdValue={outputUsdValue}
|
|
200
200
|
amount={toAmount}
|
|
201
|
-
label={t('To')}
|
|
201
|
+
label={i18n.t('To')}
|
|
202
202
|
loadingStatus={
|
|
203
203
|
loadingMetaStatus !== 'success'
|
|
204
204
|
? loadingMetaStatus
|
|
@@ -239,8 +239,8 @@ export function ConfirmSwapPage({
|
|
|
239
239
|
}
|
|
240
240
|
confirmButtonTitle={
|
|
241
241
|
warnings.length > 0 || errors.length > 0
|
|
242
|
-
? 'Proceed anyway!'
|
|
243
|
-
: 'Confirm swap!'
|
|
242
|
+
? `${i18n.t('Proceed anyway!')}`
|
|
243
|
+
: `${i18n.t('Confirm swap!')}`
|
|
244
244
|
}
|
|
245
245
|
/>
|
|
246
246
|
);
|
package/src/pages/Home.tsx
CHANGED
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
Header,
|
|
9
9
|
} from '@rango-dev/ui';
|
|
10
10
|
import React, { useEffect, useState } from 'react';
|
|
11
|
+
import { i18n } from '@lingui/core';
|
|
11
12
|
import { useInRouterContext, useNavigate } from 'react-router-dom';
|
|
12
13
|
import { TokenInfo } from '../components/TokenInfo';
|
|
13
14
|
import { fetchBestRoute, useBestRouteStore } from '../store/bestRoute';
|
|
@@ -136,7 +137,7 @@ export function Home() {
|
|
|
136
137
|
return (
|
|
137
138
|
<Container>
|
|
138
139
|
<Header
|
|
139
|
-
title=
|
|
140
|
+
title={i18n.t('SWAP')}
|
|
140
141
|
suffix={
|
|
141
142
|
<HeaderButtons
|
|
142
143
|
onClickRefresh={
|
|
@@ -159,8 +160,7 @@ export function Home() {
|
|
|
159
160
|
onClick={() => {
|
|
160
161
|
switchFromAndTo();
|
|
161
162
|
setCount((prev) => prev + 1);
|
|
162
|
-
}}
|
|
163
|
-
>
|
|
163
|
+
}}>
|
|
164
164
|
<VerticalSwapIcon size={32} />
|
|
165
165
|
{isRouterInContext && <SwithFromAndTo count={count} />}
|
|
166
166
|
</Button>
|
|
@@ -216,8 +216,7 @@ export function Home() {
|
|
|
216
216
|
else {
|
|
217
217
|
navigate(navigationRoutes.confirmSwap, { replace: true });
|
|
218
218
|
}
|
|
219
|
-
}}
|
|
220
|
-
>
|
|
219
|
+
}}>
|
|
221
220
|
{swapButtonState.title}
|
|
222
221
|
</Button>
|
|
223
222
|
<BottomLogo />
|