@rango-dev/widget-embedded 0.36.1-next.11 → 0.36.1-next.13
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/components/ConfirmWalletsModal/ConfirmWalletsModal.d.ts.map +1 -1
- package/dist/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.helpers.d.ts.map +1 -1
- package/dist/components/Quotes/Quotes.d.ts.map +1 -1
- package/dist/components/WalletStatefulConnect/Namespaces.d.ts.map +1 -1
- package/dist/constants/quote.d.ts +8 -0
- package/dist/constants/quote.d.ts.map +1 -1
- package/dist/containers/QuoteInfo/QuoteInfo.d.ts.map +1 -1
- package/dist/containers/Wallets/Wallets.d.ts.map +1 -1
- package/dist/hooks/useConfirmSwap/useConfirmSwap.d.ts.map +1 -1
- package/dist/hooks/useConfirmSwap/useConfirmSwap.helpers.d.ts +6 -4
- package/dist/hooks/useConfirmSwap/useConfirmSwap.helpers.d.ts.map +1 -1
- package/dist/hooks/useStatefulConnect/useStatefulConnect.d.ts.map +1 -1
- package/dist/hooks/useStatefulConnect/useStatefulConnect.types.d.ts +2 -4
- package/dist/hooks/useStatefulConnect/useStatefulConnect.types.d.ts.map +1 -1
- package/dist/hooks/useSwapInput.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +4 -4
- package/dist/pages/ConfirmSwapPage.d.ts.map +1 -1
- package/dist/store/quote.d.ts.map +1 -1
- package/dist/store/slices/wallets.d.ts +3 -1
- package/dist/store/slices/wallets.d.ts.map +1 -1
- package/dist/types/quote.d.ts +8 -17
- package/dist/types/quote.d.ts.map +1 -1
- package/dist/types/wallets.d.ts +1 -6
- package/dist/types/wallets.d.ts.map +1 -1
- package/dist/utils/providers.d.ts.map +1 -1
- package/dist/utils/quote.d.ts +5 -6
- package/dist/utils/quote.d.ts.map +1 -1
- package/dist/utils/swap.d.ts +4 -4
- package/dist/utils/swap.d.ts.map +1 -1
- package/dist/utils/wallets.d.ts.map +1 -1
- package/dist/widget-embedded.build.json +1 -1
- package/package.json +3 -3
- package/src/components/ConfirmWalletsModal/ConfirmWalletsModal.tsx +2 -19
- package/src/components/ConfirmWalletsModal/WalletList.tsx +1 -1
- package/src/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.helpers.ts +42 -22
- package/src/components/Quotes/Quotes.tsx +2 -3
- package/src/components/WalletStatefulConnect/Namespaces.tsx +30 -37
- package/src/constants/quote.ts +23 -0
- package/src/containers/QuoteInfo/QuoteInfo.tsx +3 -9
- package/src/containers/Wallets/Wallets.tsx +63 -3
- package/src/hooks/useConfirmSwap/useConfirmSwap.helpers.ts +29 -66
- package/src/hooks/useConfirmSwap/useConfirmSwap.ts +10 -15
- package/src/hooks/useStatefulConnect/useStatefulConnect.ts +20 -22
- package/src/hooks/useStatefulConnect/useStatefulConnect.types.ts +2 -4
- package/src/hooks/useSwapInput.ts +2 -9
- package/src/pages/ConfirmSwapPage.tsx +7 -15
- package/src/store/quote.ts +3 -13
- package/src/store/slices/wallets.ts +13 -2
- package/src/types/quote.ts +10 -24
- package/src/types/wallets.ts +1 -6
- package/src/utils/providers.ts +43 -36
- package/src/utils/quote.ts +57 -45
- package/src/utils/swap.ts +55 -36
- package/src/utils/wallets.ts +2 -4
- package/dist/constants/warnings.d.ts +0 -3
- package/dist/constants/warnings.d.ts.map +0 -1
- package/dist/utils/hub.d.ts +0 -4
- package/dist/utils/hub.d.ts.map +0 -1
- package/src/constants/warnings.ts +0 -26
- package/src/utils/hub.ts +0 -21
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rango-dev/widget-embedded",
|
|
3
|
-
"version": "0.36.1-next.
|
|
3
|
+
"version": "0.36.1-next.13",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"source": "./src/index.ts",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"@rango-dev/queue-manager-rango-preset": "^0.40.1-next.5",
|
|
31
31
|
"@rango-dev/queue-manager-react": "^0.27.0",
|
|
32
32
|
"@rango-dev/signer-solana": "^0.35.1-next.0",
|
|
33
|
-
"@rango-dev/ui": "^0.42.1-next.
|
|
33
|
+
"@rango-dev/ui": "^0.42.1-next.10",
|
|
34
34
|
"@rango-dev/wallets-core": "^0.40.1-next.5",
|
|
35
35
|
"@rango-dev/wallets-react": "^0.26.1-next.6",
|
|
36
36
|
"@rango-dev/wallets-shared": "^0.40.1-next.5",
|
|
@@ -54,4 +54,4 @@
|
|
|
54
54
|
"publishConfig": {
|
|
55
55
|
"access": "public"
|
|
56
56
|
}
|
|
57
|
-
}
|
|
57
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { PropTypes } from './ConfirmWalletsModal.types';
|
|
2
2
|
import type { ConnectedWallet } from '../../store/slices/wallets';
|
|
3
|
-
import type {
|
|
3
|
+
import type { Wallet } from '../../types';
|
|
4
4
|
|
|
5
5
|
import { i18n } from '@lingui/core';
|
|
6
6
|
import {
|
|
@@ -17,7 +17,6 @@ import { useNavigate } from 'react-router-dom';
|
|
|
17
17
|
|
|
18
18
|
import { WIDGET_UI_ID } from '../../constants';
|
|
19
19
|
import { getQuoteErrorMessage } from '../../constants/errors';
|
|
20
|
-
import { getQuoteUpdateWarningMessage } from '../../constants/warnings';
|
|
21
20
|
import { useAppStore } from '../../store/AppStore';
|
|
22
21
|
import { useQuoteStore } from '../../store/quote';
|
|
23
22
|
import { getBlockchainShortNameFor } from '../../utils/meta';
|
|
@@ -58,9 +57,6 @@ export function ConfirmWalletsModal(props: PropTypes) {
|
|
|
58
57
|
const [showMoreWalletFor, setShowMoreWalletFor] = useState('');
|
|
59
58
|
const [balanceWarnings, setBalanceWarnings] = useState<string[]>([]);
|
|
60
59
|
const [error, setError] = useState('');
|
|
61
|
-
const [quoteWarning, setQuoteWarning] = useState<
|
|
62
|
-
ConfirmSwapWarnings['quoteUpdate'] | null
|
|
63
|
-
>(null);
|
|
64
60
|
|
|
65
61
|
const [isCustomDestinationOpen, setCustomDestinationOpen] = useState(
|
|
66
62
|
!!customDestination
|
|
@@ -224,7 +220,6 @@ export function ConfirmWalletsModal(props: PropTypes) {
|
|
|
224
220
|
const onConfirmWallets = async () => {
|
|
225
221
|
setBalanceWarnings([]);
|
|
226
222
|
setError('');
|
|
227
|
-
setQuoteWarning(null);
|
|
228
223
|
|
|
229
224
|
const result = await onCheckBalance?.({
|
|
230
225
|
selectedWallets: selectableWallets.filter((wallet) => wallet.selected),
|
|
@@ -234,9 +229,7 @@ export function ConfirmWalletsModal(props: PropTypes) {
|
|
|
234
229
|
if (warnings?.balance?.messages) {
|
|
235
230
|
setBalanceWarnings(warnings.balance.messages);
|
|
236
231
|
}
|
|
237
|
-
|
|
238
|
-
setQuoteWarning(warnings.quoteUpdate);
|
|
239
|
-
}
|
|
232
|
+
|
|
240
233
|
if (result.error) {
|
|
241
234
|
setError(getQuoteErrorMessage(result.error));
|
|
242
235
|
}
|
|
@@ -416,16 +409,6 @@ export function ConfirmWalletsModal(props: PropTypes) {
|
|
|
416
409
|
<Divider size={12} />
|
|
417
410
|
</>
|
|
418
411
|
)}
|
|
419
|
-
{quoteWarning && (
|
|
420
|
-
<>
|
|
421
|
-
<Alert
|
|
422
|
-
variant="alarm"
|
|
423
|
-
type="warning"
|
|
424
|
-
title={getQuoteUpdateWarningMessage(quoteWarning)}
|
|
425
|
-
/>
|
|
426
|
-
<Divider size={12} />
|
|
427
|
-
</>
|
|
428
|
-
)}
|
|
429
412
|
<Wallets>
|
|
430
413
|
{quoteWallets.map((requiredWallet, index) => {
|
|
431
414
|
const blockchain = blockchains.find(
|
|
@@ -149,7 +149,7 @@ export function WalletList(props: PropTypes) {
|
|
|
149
149
|
const isDisconnected = wallet.state === WalletState.DISCONNECTED;
|
|
150
150
|
const isConnectedButDifferentThanTargetNamespace = wallet.isHub
|
|
151
151
|
? !conciseAddress
|
|
152
|
-
: !!wallet.
|
|
152
|
+
: !!wallet.needsNamespace && !conciseAddress;
|
|
153
153
|
|
|
154
154
|
if (isDisconnected) {
|
|
155
155
|
setSelectedWalletToConnect(wallet);
|
|
@@ -44,30 +44,50 @@ export function makeAlerts(
|
|
|
44
44
|
return alertInfo;
|
|
45
45
|
}
|
|
46
46
|
if (warning) {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
47
|
+
switch (warning.type) {
|
|
48
|
+
case QuoteWarningType.HIGH_VALUE_LOSS: {
|
|
49
|
+
const warningLevel = getPriceImpactLevel(warning.priceImpact);
|
|
50
|
+
if (warningLevel === 'high') {
|
|
51
|
+
alertInfo.alertType = 'error';
|
|
52
|
+
}
|
|
53
|
+
alertInfo.action = 'show-info';
|
|
54
|
+
alertInfo.title = errorMessages().highValueLossError.title;
|
|
55
|
+
break;
|
|
51
56
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
57
|
+
case QuoteWarningType.EXCESSIVE_OUTPUT_AMOUNT_CHANGE: {
|
|
58
|
+
alertInfo.title = i18n.t({
|
|
59
|
+
id: 'Output amount changed by {percentageChange}% (${usdValueChange}).',
|
|
60
|
+
values: {
|
|
61
|
+
percentageChange: warning.percentageChange,
|
|
62
|
+
usdValueChange: warning.usdValueChange,
|
|
63
|
+
},
|
|
64
|
+
});
|
|
65
|
+
break;
|
|
66
|
+
}
|
|
67
|
+
case QuoteWarningType.UNKNOWN_PRICE: {
|
|
68
|
+
alertInfo.title = errorMessages().unknownPriceError.title;
|
|
69
|
+
break;
|
|
70
|
+
}
|
|
71
|
+
case QuoteWarningType.INSUFFICIENT_SLIPPAGE: {
|
|
72
|
+
alertInfo.title = i18n.t({
|
|
73
|
+
id: 'We recommend you to increase slippage to at least {minRequiredSlippage} for this route.',
|
|
74
|
+
values: {
|
|
75
|
+
minRequiredSlippage: warning.minRequiredSlippage,
|
|
76
|
+
},
|
|
77
|
+
});
|
|
78
|
+
alertInfo.action = 'change-settings';
|
|
79
|
+
break;
|
|
80
|
+
}
|
|
81
|
+
case QuoteWarningType.HIGH_SLIPPAGE: {
|
|
82
|
+
alertInfo.title = i18n.t('Caution, your slippage is high.');
|
|
83
|
+
alertInfo.action = 'change-settings';
|
|
84
|
+
break;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
default:
|
|
88
|
+
break;
|
|
70
89
|
}
|
|
90
|
+
|
|
71
91
|
return alertInfo;
|
|
72
92
|
}
|
|
73
93
|
return null;
|
|
@@ -12,8 +12,7 @@ import {
|
|
|
12
12
|
Radio,
|
|
13
13
|
RadioRoot,
|
|
14
14
|
} from '@rango-dev/ui';
|
|
15
|
-
import {
|
|
16
|
-
import React, { useMemo, useState } from 'react';
|
|
15
|
+
import React, { useState } from 'react';
|
|
17
16
|
|
|
18
17
|
import { useAppStore } from '../../store/AppStore';
|
|
19
18
|
import { WalletImageContainer } from '../HeaderButtons/HeaderButtons.styles';
|
|
@@ -23,25 +22,14 @@ import { getBlockchainLogo } from './Namespaces.helpers';
|
|
|
23
22
|
import { NamespaceList } from './Namespaces.styles';
|
|
24
23
|
|
|
25
24
|
export function Namespaces(props: PropTypes) {
|
|
26
|
-
const {
|
|
25
|
+
const { targetWallet } = props.value;
|
|
26
|
+
const singleNamespace = targetWallet.needsNamespace?.selection === 'single';
|
|
27
|
+
const providerImage = targetWallet.image;
|
|
27
28
|
|
|
28
29
|
const [selectedNamespaces, setSelectedNamespaces] = useState<Namespace[]>([]);
|
|
29
30
|
|
|
30
31
|
const blockchains = useAppStore().blockchains();
|
|
31
32
|
|
|
32
|
-
const namespacesInfo = useMemo(
|
|
33
|
-
() =>
|
|
34
|
-
availableNamespaces?.map((namespace) => ({
|
|
35
|
-
name: namespace,
|
|
36
|
-
logo: getBlockchainLogo(
|
|
37
|
-
blockchains,
|
|
38
|
-
namespaces[namespace].mainBlockchain
|
|
39
|
-
),
|
|
40
|
-
title: namespaces[namespace].title,
|
|
41
|
-
})),
|
|
42
|
-
[availableNamespaces]
|
|
43
|
-
);
|
|
44
|
-
|
|
45
33
|
const onSelect = (namespace: Namespace) => {
|
|
46
34
|
if (singleNamespace) {
|
|
47
35
|
setSelectedNamespaces([namespace]);
|
|
@@ -83,28 +71,33 @@ export function Namespaces(props: PropTypes) {
|
|
|
83
71
|
<NamespaceList>
|
|
84
72
|
{wrapRadioRoot(
|
|
85
73
|
<>
|
|
86
|
-
{
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
<Checkbox
|
|
100
|
-
checked={selectedNamespaces.includes(
|
|
101
|
-
namespaceInfoItem.name
|
|
102
|
-
)}
|
|
74
|
+
{targetWallet.needsNamespace?.data.map((ns) => {
|
|
75
|
+
return (
|
|
76
|
+
<ListItemButton
|
|
77
|
+
key={ns.id}
|
|
78
|
+
id={ns.id}
|
|
79
|
+
title={ns.label}
|
|
80
|
+
hasDivider
|
|
81
|
+
style={{ height: 60 }}
|
|
82
|
+
onClick={() => onSelect(ns.value)}
|
|
83
|
+
start={
|
|
84
|
+
<Image
|
|
85
|
+
src={getBlockchainLogo(blockchains, ns.id)}
|
|
86
|
+
size={22}
|
|
103
87
|
/>
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
88
|
+
}
|
|
89
|
+
end={
|
|
90
|
+
singleNamespace ? (
|
|
91
|
+
<Radio value={ns.value} />
|
|
92
|
+
) : (
|
|
93
|
+
<Checkbox
|
|
94
|
+
checked={selectedNamespaces.includes(ns.value)}
|
|
95
|
+
/>
|
|
96
|
+
)
|
|
97
|
+
}
|
|
98
|
+
/>
|
|
99
|
+
);
|
|
100
|
+
})}
|
|
108
101
|
</>
|
|
109
102
|
)}
|
|
110
103
|
</NamespaceList>
|
package/src/constants/quote.ts
CHANGED
|
@@ -32,6 +32,29 @@ export const HIGH_PRIORITY_TAGS: TagValue[] = [
|
|
|
32
32
|
'HIGH_IMPACT',
|
|
33
33
|
];
|
|
34
34
|
|
|
35
|
+
export type Criteria = {
|
|
36
|
+
threshold: number;
|
|
37
|
+
minInput: number;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export const PERCENT_MULTIPLIER = 100;
|
|
35
41
|
export const GAS_FEE_MAX = 30;
|
|
36
42
|
export const ROUTE_TIME_MAX = 15;
|
|
37
43
|
export const SECONDS_IN_MINUTE = 60;
|
|
44
|
+
export const HIGH_FEE_THRESHOLD_USD = 30;
|
|
45
|
+
|
|
46
|
+
export const HIGH_VALUE_LOSS_CRITERIA: Criteria[] = [
|
|
47
|
+
{ threshold: -10, minInput: 400 },
|
|
48
|
+
{ threshold: -5, minInput: 1000 },
|
|
49
|
+
];
|
|
50
|
+
|
|
51
|
+
export const OUTPUT_CHANGE_WARNING_CRITERIA: Criteria[] = [
|
|
52
|
+
{
|
|
53
|
+
threshold: -1,
|
|
54
|
+
minInput: 1000,
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
threshold: -2,
|
|
58
|
+
minInput: 500,
|
|
59
|
+
},
|
|
60
|
+
];
|
|
@@ -7,8 +7,7 @@ import { Quote } from '../../components/Quote';
|
|
|
7
7
|
import { QuoteSkeleton } from '../../components/QuoteSkeleton';
|
|
8
8
|
import { useQuoteStore } from '../../store/quote';
|
|
9
9
|
import { QuoteErrorType } from '../../types';
|
|
10
|
-
import {
|
|
11
|
-
import { calcOutputUsdValue } from '../../utils/swap';
|
|
10
|
+
import { getUsdOutputFrom } from '../../utils/swap';
|
|
12
11
|
|
|
13
12
|
import { QuoteContainer } from './QuoteInfo.styles';
|
|
14
13
|
|
|
@@ -28,17 +27,12 @@ export function QuoteInfo(props: PropTypes) {
|
|
|
28
27
|
fullExpandedMode = false,
|
|
29
28
|
container,
|
|
30
29
|
} = props;
|
|
31
|
-
const { inputAmount, inputUsdValue
|
|
30
|
+
const { inputAmount, inputUsdValue } = useQuoteStore();
|
|
32
31
|
|
|
33
32
|
const outputAmount = !!quote?.outputAmount
|
|
34
33
|
? new BigNumber(quote?.outputAmount)
|
|
35
34
|
: null;
|
|
36
|
-
const outputUsdValue =
|
|
37
|
-
? calcOutputUsdValue(
|
|
38
|
-
quote?.outputAmount,
|
|
39
|
-
getQuoteToTokenUsdPrice(quote) || toToken?.usdPrice
|
|
40
|
-
)
|
|
41
|
-
: null;
|
|
35
|
+
const outputUsdValue = quote ? getUsdOutputFrom(quote) : null;
|
|
42
36
|
|
|
43
37
|
const noResult =
|
|
44
38
|
error &&
|
|
@@ -7,6 +7,10 @@ import type { ProvidersOptions } from '../../utils/providers';
|
|
|
7
7
|
import type { LegacyEventHandler as EventHandler } from '@rango-dev/wallets-core/legacy';
|
|
8
8
|
import type { PropsWithChildren } from 'react';
|
|
9
9
|
|
|
10
|
+
import {
|
|
11
|
+
legacyFormatAddressWithNetwork as formatAddressWithNetwork,
|
|
12
|
+
legacyReadAccountAddress as readAccountAddress,
|
|
13
|
+
} from '@rango-dev/wallets-core/legacy';
|
|
10
14
|
import { Events, Provider } from '@rango-dev/wallets-react';
|
|
11
15
|
import { type Network } from '@rango-dev/wallets-shared';
|
|
12
16
|
import { isEvmBlockchain } from 'rango-sdk';
|
|
@@ -36,9 +40,11 @@ function Main(props: PropsWithChildren<PropTypes>) {
|
|
|
36
40
|
updateSettings,
|
|
37
41
|
fetch: fetchMeta,
|
|
38
42
|
fetchStatus,
|
|
43
|
+
removeBalancesForWallet,
|
|
39
44
|
} = useAppStore();
|
|
40
45
|
const blockchains = useAppStore().blockchains();
|
|
41
|
-
const { newWalletConnected, disconnectWallet } =
|
|
46
|
+
const { newWalletConnected, disconnectWallet, connectedWallets } =
|
|
47
|
+
useAppStore();
|
|
42
48
|
const config = useAppStore().config;
|
|
43
49
|
|
|
44
50
|
const walletOptions: ProvidersOptions = {
|
|
@@ -75,9 +81,62 @@ function Main(props: PropsWithChildren<PropTypes>) {
|
|
|
75
81
|
|
|
76
82
|
const onUpdateState: EventHandler = (type, event, value, state, meta) => {
|
|
77
83
|
if (event === Events.ACCOUNTS) {
|
|
84
|
+
const supportedChainNames: Network[] | null =
|
|
85
|
+
walletAndSupportedChainsNames(meta.supportedBlockchains);
|
|
86
|
+
|
|
87
|
+
/*
|
|
88
|
+
* When a wallet is connecting to an evm account, we will consider it as the account exists on other evm-compatible blockchains
|
|
89
|
+
* To get their balances.
|
|
90
|
+
*
|
|
91
|
+
* The logic here is for handling switching account functionality in wallets. when a wallet is switching to another account
|
|
92
|
+
* we need to clean the balances for old accounts.
|
|
93
|
+
*/
|
|
94
|
+
const evmAccounts: string[] = [];
|
|
95
|
+
const nonEvmAccounts: string[] = [];
|
|
96
|
+
|
|
97
|
+
value?.forEach((account: string) => {
|
|
98
|
+
const { network } = readAccountAddress(account);
|
|
99
|
+
if (evmBasedChainNames.includes(network)) {
|
|
100
|
+
evmAccounts.push(account);
|
|
101
|
+
} else {
|
|
102
|
+
nonEvmAccounts.push(account);
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
const previousAccounts = connectedWallets
|
|
107
|
+
.filter((wallet) => wallet.walletType === type)
|
|
108
|
+
.map((wallet) =>
|
|
109
|
+
formatAddressWithNetwork(wallet.address, wallet.chain)
|
|
110
|
+
);
|
|
111
|
+
|
|
112
|
+
if (previousAccounts.length > 0) {
|
|
113
|
+
if (evmAccounts.length > 0) {
|
|
114
|
+
// We use same logic for removing as we use for adding.
|
|
115
|
+
const data = prepareAccountsForWalletStore(
|
|
116
|
+
type,
|
|
117
|
+
evmAccounts,
|
|
118
|
+
evmBasedChainNames,
|
|
119
|
+
supportedChainNames,
|
|
120
|
+
meta.isContractWallet
|
|
121
|
+
);
|
|
122
|
+
|
|
123
|
+
removeBalancesForWallet(type, {
|
|
124
|
+
chains: data.map((account) => account.chain),
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
if (nonEvmAccounts.length > 0) {
|
|
129
|
+
removeBalancesForWallet(type, {
|
|
130
|
+
chains: nonEvmAccounts.map((account) => {
|
|
131
|
+
const { network } = readAccountAddress(account);
|
|
132
|
+
return network;
|
|
133
|
+
}),
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// After cleaning up balances, it's time to add new accounts.
|
|
78
139
|
if (value) {
|
|
79
|
-
const supportedChainNames: Network[] | null =
|
|
80
|
-
walletAndSupportedChainsNames(meta.supportedBlockchains);
|
|
81
140
|
const data = prepareAccountsForWalletStore(
|
|
82
141
|
type,
|
|
83
142
|
value,
|
|
@@ -149,6 +208,7 @@ function Main(props: PropsWithChildren<PropTypes>) {
|
|
|
149
208
|
onUpdateState={onUpdateState}
|
|
150
209
|
autoConnect={!!isActiveTab}
|
|
151
210
|
configs={{
|
|
211
|
+
wallets: config.wallets,
|
|
152
212
|
isExperimentalEnabled: isFeatureEnabled(
|
|
153
213
|
'experimentalWallet',
|
|
154
214
|
config.features
|
|
@@ -7,27 +7,18 @@ import type {
|
|
|
7
7
|
SelectedQuote,
|
|
8
8
|
Wallet,
|
|
9
9
|
} from '../../types';
|
|
10
|
-
import type
|
|
10
|
+
import type BigNumber from 'bignumber.js';
|
|
11
|
+
import type { BlockchainMeta, SwapResult } from 'rango-sdk';
|
|
11
12
|
|
|
12
13
|
import { errorMessages } from '../../constants/errors';
|
|
13
|
-
import { QuoteErrorType
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
generateQuoteWarnings,
|
|
17
|
-
getPriceImpact,
|
|
18
|
-
isNumberOfSwapsChanged,
|
|
19
|
-
isQuoteChanged,
|
|
20
|
-
isQuoteInternalCoinsUpdated,
|
|
21
|
-
isQuoteSwappersUpdated,
|
|
22
|
-
} from '../../utils/quote';
|
|
14
|
+
import { QuoteErrorType } from '../../types';
|
|
15
|
+
import { generateQuoteWarnings } from '../../utils/quote';
|
|
23
16
|
import {
|
|
24
17
|
checkSlippageErrors,
|
|
25
18
|
generateBalanceWarnings,
|
|
26
19
|
getLimitErrorMessage,
|
|
27
20
|
getMinRequiredSlippage,
|
|
28
|
-
getQuoteOutputAmount,
|
|
29
21
|
hasLimitError,
|
|
30
|
-
isOutputAmountChangedALot,
|
|
31
22
|
} from '../../utils/swap';
|
|
32
23
|
|
|
33
24
|
/**
|
|
@@ -82,72 +73,44 @@ export function getQuoteError(swaps: SwapResult[]): QuoteErrorResponse | null {
|
|
|
82
73
|
return null;
|
|
83
74
|
}
|
|
84
75
|
|
|
85
|
-
export function generateWarnings(
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
76
|
+
export function generateWarnings(params: {
|
|
77
|
+
currentQuote: SelectedQuote;
|
|
78
|
+
previousQuote?: SelectedQuote;
|
|
79
|
+
meta: { blockchains: BlockchainMeta[] };
|
|
80
|
+
selectedWallets: Wallet[];
|
|
81
|
+
userSlippage: number;
|
|
82
|
+
inputUsdValue: BigNumber | null;
|
|
83
|
+
findToken: FindToken;
|
|
84
|
+
}): ConfirmSwapWarnings {
|
|
85
|
+
const {
|
|
86
|
+
currentQuote,
|
|
87
|
+
previousQuote,
|
|
88
|
+
meta,
|
|
89
|
+
selectedWallets,
|
|
90
|
+
userSlippage,
|
|
91
|
+
findToken,
|
|
92
|
+
} = params;
|
|
93
|
+
|
|
101
94
|
const output: ConfirmSwapWarnings = {
|
|
102
95
|
quote: null,
|
|
103
|
-
quoteUpdate: null,
|
|
104
96
|
balance: null,
|
|
105
97
|
};
|
|
106
98
|
|
|
107
|
-
const quoteWarning = generateQuoteWarnings(
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
findToken
|
|
111
|
-
userSlippage
|
|
99
|
+
const quoteWarning = generateQuoteWarnings({
|
|
100
|
+
previousQuote,
|
|
101
|
+
currentQuote,
|
|
102
|
+
findToken,
|
|
103
|
+
userSlippage,
|
|
112
104
|
});
|
|
113
105
|
|
|
114
106
|
if (quoteWarning) {
|
|
115
107
|
output.quote = quoteWarning;
|
|
116
108
|
}
|
|
117
109
|
|
|
118
|
-
if (previousQuote && quoteChanged) {
|
|
119
|
-
if (isOutputAmountChangedALot(previousQuote, currentQuote)) {
|
|
120
|
-
output.quoteUpdate = {
|
|
121
|
-
type: QuoteUpdateType.QUOTE_AND_OUTPUT_AMOUNT_UPDATED,
|
|
122
|
-
newOutputAmount: numberToString(getQuoteOutputAmount(currentQuote)),
|
|
123
|
-
percentageChange: numberToString(
|
|
124
|
-
getPriceImpact(
|
|
125
|
-
getQuoteOutputAmount(previousQuote) ?? '',
|
|
126
|
-
getQuoteOutputAmount(currentQuote) ?? ''
|
|
127
|
-
),
|
|
128
|
-
null,
|
|
129
|
-
2
|
|
130
|
-
),
|
|
131
|
-
};
|
|
132
|
-
} else if (isNumberOfSwapsChanged(previousQuote, currentQuote)) {
|
|
133
|
-
output.quoteUpdate = {
|
|
134
|
-
type: QuoteUpdateType.QUOTE_UPDATED,
|
|
135
|
-
};
|
|
136
|
-
} else if (isQuoteSwappersUpdated(previousQuote, currentQuote)) {
|
|
137
|
-
output.quoteUpdate = {
|
|
138
|
-
type: QuoteUpdateType.QUOTE_SWAPPERS_UPDATED,
|
|
139
|
-
};
|
|
140
|
-
} else if (isQuoteInternalCoinsUpdated(previousQuote, currentQuote)) {
|
|
141
|
-
output.quoteUpdate = {
|
|
142
|
-
type: QuoteUpdateType.QUOTE_COINS_UPDATED,
|
|
143
|
-
};
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
|
|
147
110
|
const balanceWarnings = generateBalanceWarnings(
|
|
148
111
|
currentQuote,
|
|
149
|
-
|
|
150
|
-
|
|
112
|
+
selectedWallets,
|
|
113
|
+
meta.blockchains
|
|
151
114
|
);
|
|
152
115
|
|
|
153
116
|
const enoughBalance = balanceWarnings.length === 0;
|
|
@@ -21,10 +21,10 @@ export function useConfirmSwap(): ConfirmSwap {
|
|
|
21
21
|
fromToken,
|
|
22
22
|
toToken,
|
|
23
23
|
inputAmount,
|
|
24
|
+
inputUsdValue,
|
|
24
25
|
setSelectedQuote,
|
|
25
26
|
selectedQuote: initialQuote,
|
|
26
27
|
customDestination: customDestinationFromStore,
|
|
27
|
-
setQuoteWarningsConfirmed,
|
|
28
28
|
resetAlerts,
|
|
29
29
|
} = useQuoteStore();
|
|
30
30
|
|
|
@@ -95,21 +95,16 @@ export function useConfirmSwap(): ConfirmSwap {
|
|
|
95
95
|
disabledSwappersGroups: disabledLiquiditySources,
|
|
96
96
|
};
|
|
97
97
|
|
|
98
|
-
const confirmSwapWarnings = generateWarnings(
|
|
99
|
-
initialQuote ?? undefined,
|
|
98
|
+
const confirmSwapWarnings = generateWarnings({
|
|
99
|
+
previousQuote: initialQuote ?? undefined,
|
|
100
100
|
currentQuote,
|
|
101
|
-
{
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
}
|
|
109
|
-
);
|
|
110
|
-
if (confirmSwapWarnings.quoteUpdate) {
|
|
111
|
-
setQuoteWarningsConfirmed(false);
|
|
112
|
-
}
|
|
101
|
+
meta: { blockchains },
|
|
102
|
+
selectedWallets,
|
|
103
|
+
userSlippage,
|
|
104
|
+
inputUsdValue,
|
|
105
|
+
findToken,
|
|
106
|
+
});
|
|
107
|
+
|
|
113
108
|
resetAlerts();
|
|
114
109
|
|
|
115
110
|
const proceedAnyway = !!confirmSwapWarnings.balance;
|