@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/src/utils/swap.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-magic-numbers */
|
|
2
|
-
import type { FeesGroup, NameOfFees } from '../constants/quote';
|
|
3
1
|
import type { FetchStatus, FindToken } from '../store/slices/data';
|
|
4
2
|
import type { ConnectedWallet } from '../store/slices/wallets';
|
|
5
3
|
import type {
|
|
@@ -34,6 +32,14 @@ import { PendingSwapNetworkStatus } from 'rango-types';
|
|
|
34
32
|
import { errorMessages } from '../constants/errors';
|
|
35
33
|
import { swapButtonTitles } from '../constants/messages';
|
|
36
34
|
import { ZERO } from '../constants/numbers';
|
|
35
|
+
import {
|
|
36
|
+
type FeesGroup,
|
|
37
|
+
HIGH_FEE_THRESHOLD_USD,
|
|
38
|
+
HIGH_VALUE_LOSS_CRITERIA,
|
|
39
|
+
type NameOfFees,
|
|
40
|
+
OUTPUT_CHANGE_WARNING_CRITERIA,
|
|
41
|
+
PERCENT_MULTIPLIER,
|
|
42
|
+
} from '../constants/quote';
|
|
37
43
|
import {
|
|
38
44
|
BALANCE_MAX_DECIMALS,
|
|
39
45
|
BALANCE_MIN_DECIMALS,
|
|
@@ -43,7 +49,7 @@ import {
|
|
|
43
49
|
|
|
44
50
|
import { getBlockchainShortNameFor, isValidTokenAddress } from './meta';
|
|
45
51
|
import { numberToString } from './numbers';
|
|
46
|
-
import {
|
|
52
|
+
import { getRequiredBalanceOfWallet } from './quote';
|
|
47
53
|
import { getQuoteWallets } from './wallets';
|
|
48
54
|
|
|
49
55
|
export function getOutputRatio(
|
|
@@ -61,7 +67,7 @@ export function getOutputRatio(
|
|
|
61
67
|
return outputUsdValue
|
|
62
68
|
.div(inputUsdValue)
|
|
63
69
|
.minus(1)
|
|
64
|
-
.multipliedBy(
|
|
70
|
+
.multipliedBy(PERCENT_MULTIPLIER)
|
|
65
71
|
.toNumber();
|
|
66
72
|
}
|
|
67
73
|
|
|
@@ -69,12 +75,16 @@ export function hasHighValueLoss(
|
|
|
69
75
|
inputUsdValue: BigNumber | null,
|
|
70
76
|
priceImpact: number
|
|
71
77
|
): boolean {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
+
if (!inputUsdValue) {
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const formattedPriceImpact = parseInt(priceImpact.toFixed(2) || '0');
|
|
83
|
+
|
|
84
|
+
return HIGH_VALUE_LOSS_CRITERIA.some(
|
|
85
|
+
({ threshold, minInput }) =>
|
|
86
|
+
formattedPriceImpact <= threshold &&
|
|
87
|
+
inputUsdValue.gte(new BigNumber(minInput))
|
|
78
88
|
);
|
|
79
89
|
}
|
|
80
90
|
|
|
@@ -328,7 +338,7 @@ export function hasHighFee(totalFeeInUsd: BigNumber | null) {
|
|
|
328
338
|
if (!totalFeeInUsd) {
|
|
329
339
|
return false;
|
|
330
340
|
}
|
|
331
|
-
return !totalFeeInUsd.lt(new BigNumber(
|
|
341
|
+
return !totalFeeInUsd.lt(new BigNumber(HIGH_FEE_THRESHOLD_USD));
|
|
332
342
|
}
|
|
333
343
|
|
|
334
344
|
export function hasSlippageError(
|
|
@@ -480,8 +490,7 @@ export function createQuoteRequestBody(params: {
|
|
|
480
490
|
addresses: [wallet.address],
|
|
481
491
|
});
|
|
482
492
|
});
|
|
483
|
-
|
|
484
|
-
// @ts-ignore
|
|
493
|
+
|
|
485
494
|
const requestBody: BestRouteRequest = {
|
|
486
495
|
amount: inputAmount.toString(),
|
|
487
496
|
affiliateRef: affiliateRef ?? undefined,
|
|
@@ -535,33 +544,52 @@ export function getWalletsForNewSwap(selectedWallets: Wallet[]) {
|
|
|
535
544
|
return wallets;
|
|
536
545
|
}
|
|
537
546
|
|
|
538
|
-
export function
|
|
539
|
-
|
|
547
|
+
export function getUsdInputFrom(quote: SelectedQuote): BigNumber | undefined {
|
|
548
|
+
const inputAmount = quote.requestAmount;
|
|
549
|
+
const inputTokenUsdPrice = quote.swaps[0].from.usdPrice;
|
|
550
|
+
if (!inputAmount || !inputTokenUsdPrice) {
|
|
551
|
+
return;
|
|
552
|
+
}
|
|
553
|
+
return new BigNumber(inputAmount).multipliedBy(inputTokenUsdPrice);
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
export function getUsdOutputFrom(quote: SelectedQuote): BigNumber | undefined {
|
|
557
|
+
const outputAmount = quote?.outputAmount || null;
|
|
558
|
+
const outputTokenUsdPrice = quote.swaps[quote.swaps.length - 1].to.usdPrice;
|
|
559
|
+
if (!outputAmount || !outputTokenUsdPrice) {
|
|
560
|
+
return;
|
|
561
|
+
}
|
|
562
|
+
return new BigNumber(outputAmount).multipliedBy(outputTokenUsdPrice);
|
|
540
563
|
}
|
|
541
564
|
|
|
542
565
|
export function getPercentageChange(input: string, output: string) {
|
|
543
566
|
return new BigNumber(output)
|
|
544
567
|
.div(new BigNumber(input))
|
|
545
568
|
.minus(1)
|
|
546
|
-
.multipliedBy(
|
|
569
|
+
.multipliedBy(PERCENT_MULTIPLIER)
|
|
547
570
|
.toNumber();
|
|
548
571
|
}
|
|
549
572
|
|
|
550
|
-
export function
|
|
551
|
-
|
|
552
|
-
|
|
573
|
+
export function isOutputAmountChangedExcessively(
|
|
574
|
+
previousQuote: SelectedQuote,
|
|
575
|
+
currentQuote: SelectedQuote
|
|
553
576
|
) {
|
|
554
|
-
const
|
|
555
|
-
const
|
|
556
|
-
|
|
577
|
+
const usdInput = getUsdInputFrom(previousQuote);
|
|
578
|
+
const previousUsdOutput = getUsdOutputFrom(previousQuote);
|
|
579
|
+
const currentUsdOutput = getUsdOutputFrom(currentQuote);
|
|
580
|
+
if (!usdInput || !previousUsdOutput || !currentUsdOutput) {
|
|
557
581
|
return false;
|
|
558
582
|
}
|
|
559
|
-
const percentageChange = getPriceImpact(oldOutputAmount, newOutputAmount);
|
|
560
|
-
if (!percentageChange) {
|
|
561
|
-
return true;
|
|
562
|
-
}
|
|
563
583
|
|
|
564
|
-
|
|
584
|
+
const percentageChange = getPercentageChange(
|
|
585
|
+
previousUsdOutput.toString(),
|
|
586
|
+
currentUsdOutput.toString()
|
|
587
|
+
);
|
|
588
|
+
|
|
589
|
+
return OUTPUT_CHANGE_WARNING_CRITERIA.some(
|
|
590
|
+
({ threshold, minInput }) =>
|
|
591
|
+
percentageChange <= threshold && usdInput.isGreaterThanOrEqualTo(minInput)
|
|
592
|
+
);
|
|
565
593
|
}
|
|
566
594
|
|
|
567
595
|
export function generateBalanceWarnings(
|
|
@@ -623,15 +651,6 @@ export function generateBalanceWarnings(
|
|
|
623
651
|
});
|
|
624
652
|
}
|
|
625
653
|
|
|
626
|
-
export function calcOutputUsdValue(
|
|
627
|
-
outputAmount?: string,
|
|
628
|
-
tokenPrice?: number | null
|
|
629
|
-
) {
|
|
630
|
-
const amount = !!outputAmount ? new BigNumber(outputAmount) : ZERO;
|
|
631
|
-
|
|
632
|
-
return amount.multipliedBy(tokenPrice || 0);
|
|
633
|
-
}
|
|
634
|
-
|
|
635
654
|
export function isNetworkStatusInWarningState(
|
|
636
655
|
pendingSwapStep: PendingSwapStep | null
|
|
637
656
|
): boolean {
|
package/src/utils/wallets.ts
CHANGED
|
@@ -87,8 +87,7 @@ export function mapWalletTypesToWalletInfo(
|
|
|
87
87
|
img: image,
|
|
88
88
|
installLink,
|
|
89
89
|
showOnMobile,
|
|
90
|
-
|
|
91
|
-
singleNamespace,
|
|
90
|
+
needsNamespace,
|
|
92
91
|
supportedChains,
|
|
93
92
|
needsDerivationPath,
|
|
94
93
|
properties,
|
|
@@ -106,8 +105,7 @@ export function mapWalletTypesToWalletInfo(
|
|
|
106
105
|
state,
|
|
107
106
|
type,
|
|
108
107
|
showOnMobile,
|
|
109
|
-
|
|
110
|
-
singleNamespace,
|
|
108
|
+
needsNamespace,
|
|
111
109
|
blockchainTypes,
|
|
112
110
|
needsDerivationPath,
|
|
113
111
|
properties,
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"warnings.d.ts","sourceRoot":"","sources":["../../src/constants/warnings.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAMnD,wBAAgB,4BAA4B,CAAC,OAAO,EAAE,kBAAkB,UAmBvE"}
|
package/dist/utils/hub.d.ts
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import type { CommonNamespaceKeys } from '@rango-dev/wallets-core';
|
|
2
|
-
import type { Namespace } from '@rango-dev/wallets-core/namespaces/common';
|
|
3
|
-
export declare function convertCommonNamespacesKeysToLegacyNamespace(namespaces: CommonNamespaceKeys[]): Namespace[];
|
|
4
|
-
//# sourceMappingURL=hub.d.ts.map
|
package/dist/utils/hub.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"hub.d.ts","sourceRoot":"","sources":["../../src/utils/hub.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AACnE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,2CAA2C,CAAC;AAE3E,wBAAgB,4CAA4C,CAC1D,UAAU,EAAE,mBAAmB,EAAE,GAChC,SAAS,EAAE,CAeb"}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import type { QuoteUpdateWarning } from '../types';
|
|
2
|
-
|
|
3
|
-
import { i18n } from '@lingui/core';
|
|
4
|
-
|
|
5
|
-
import { QuoteUpdateType } from '../types';
|
|
6
|
-
|
|
7
|
-
export function getQuoteUpdateWarningMessage(warning: QuoteUpdateWarning) {
|
|
8
|
-
switch (warning.type) {
|
|
9
|
-
case QuoteUpdateType.QUOTE_UPDATED:
|
|
10
|
-
return i18n.t('Route has been updated.');
|
|
11
|
-
case QuoteUpdateType.QUOTE_AND_OUTPUT_AMOUNT_UPDATED:
|
|
12
|
-
return i18n.t(
|
|
13
|
-
'Output amount changed to {newOutputAmount} ({percentageChange}% change).',
|
|
14
|
-
{
|
|
15
|
-
newOutputAmount: warning.newOutputAmount,
|
|
16
|
-
percentageChange: warning.percentageChange,
|
|
17
|
-
}
|
|
18
|
-
);
|
|
19
|
-
case QuoteUpdateType.QUOTE_SWAPPERS_UPDATED:
|
|
20
|
-
return i18n.t('Route swappers has been updated.');
|
|
21
|
-
case QuoteUpdateType.QUOTE_COINS_UPDATED:
|
|
22
|
-
return i18n.t('Route internal coins has been updated.');
|
|
23
|
-
default:
|
|
24
|
-
return '';
|
|
25
|
-
}
|
|
26
|
-
}
|
package/src/utils/hub.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import type { CommonNamespaceKeys } from '@rango-dev/wallets-core';
|
|
2
|
-
import type { Namespace } from '@rango-dev/wallets-core/namespaces/common';
|
|
3
|
-
|
|
4
|
-
export function convertCommonNamespacesKeysToLegacyNamespace(
|
|
5
|
-
namespaces: CommonNamespaceKeys[]
|
|
6
|
-
): Namespace[] {
|
|
7
|
-
return namespaces.map((namespace) => {
|
|
8
|
-
switch (namespace) {
|
|
9
|
-
case 'evm':
|
|
10
|
-
return 'EVM';
|
|
11
|
-
case 'solana':
|
|
12
|
-
return 'Solana';
|
|
13
|
-
case 'cosmos':
|
|
14
|
-
return 'Cosmos';
|
|
15
|
-
default:
|
|
16
|
-
throw new Error(
|
|
17
|
-
'Can not convert this common namespace key to a proper legacy key.'
|
|
18
|
-
);
|
|
19
|
-
}
|
|
20
|
-
});
|
|
21
|
-
}
|