@rango-dev/widget-embedded 0.37.0 → 0.37.1-next.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/QueueManager.d.ts.map +1 -1
- package/dist/components/ConfirmWalletsModal/ConfirmWalletsModal.d.ts.map +1 -1
- package/dist/components/ConfirmWalletsModal/WalletList.d.ts.map +1 -1
- package/dist/components/Layout/Layout.d.ts.map +1 -1
- package/dist/components/Quote/Quote.d.ts.map +1 -1
- package/dist/components/Quote/Quote.styles.d.ts +1 -1
- package/dist/components/Quote/Quote.types.d.ts +2 -0
- package/dist/components/Quote/Quote.types.d.ts.map +1 -1
- package/dist/components/Quote/QuoteCostDetails.d.ts.map +1 -1
- package/dist/components/Quote/QuoteCostDetails.styles.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/RefreshModal/RefreshModal.styles.d.ts +1 -1
- package/dist/components/SwapDetails/SwapDetails.d.ts.map +1 -1
- package/dist/components/SwapDetailsAlerts/SwapDetailsAlerts.types.d.ts +1 -1
- package/dist/components/SwapDetailsAlerts/SwapDetailsAlerts.types.d.ts.map +1 -1
- package/dist/components/SwapDetailsModal/SwapDetailsCompleteModal.d.ts.map +1 -1
- package/dist/components/TokenList/TokenList.d.ts.map +1 -1
- package/dist/components/WalletStatefulConnect/DerivationPath.helpers.d.ts +2 -1
- package/dist/components/WalletStatefulConnect/DerivationPath.helpers.d.ts.map +1 -1
- package/dist/components/WalletStatefulConnect/Namespaces.d.ts.map +1 -1
- package/dist/components/WalletStatefulConnect/Namespaces.types.d.ts +1 -1
- package/dist/components/WalletStatefulConnect/Namespaces.types.d.ts.map +1 -1
- package/dist/constants/quote.d.ts +10 -0
- package/dist/constants/quote.d.ts.map +1 -1
- package/dist/containers/ExpandedQuotes/ExpandedQuotes.styles.d.ts.map +1 -1
- package/dist/containers/Inputs/Inputs.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/containers/WidgetInfo/WidgetInfo.d.ts.map +1 -1
- package/dist/containers/WidgetInfo/WidgetInfo.helpers.d.ts +1 -1
- package/dist/containers/WidgetInfo/WidgetInfo.types.d.ts +2 -2
- package/dist/containers/WidgetInfo/WidgetInfo.types.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/useFetchApiConfig.d.ts.map +1 -1
- package/dist/hooks/useFetchCustomToken.d.ts.map +1 -1
- package/dist/hooks/useStatefulConnect/useStatefulConnect.d.ts +2 -1
- package/dist/hooks/useStatefulConnect/useStatefulConnect.d.ts.map +1 -1
- package/dist/hooks/useStatefulConnect/useStatefulConnect.types.d.ts +3 -5
- package/dist/hooks/useStatefulConnect/useStatefulConnect.types.d.ts.map +1 -1
- package/dist/hooks/useSubscribeToWidgetEvents/useSubscribeToWidgetEvents.d.ts.map +1 -1
- package/dist/hooks/useSwapInput.d.ts.map +1 -1
- package/dist/hooks/useWalletList.d.ts.map +1 -1
- package/dist/hooks/useWalletProviders/useWalletProviders.d.ts +2 -3
- package/dist/hooks/useWalletProviders/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 +2 -2
- 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/SelectSwapItemsPage.d.ts.map +1 -1
- package/dist/store/app.d.ts +2 -4
- package/dist/store/app.d.ts.map +1 -1
- package/dist/store/quote.d.ts.map +1 -1
- package/dist/store/slices/config.d.ts +4 -0
- package/dist/store/slices/config.d.ts.map +1 -1
- package/dist/store/slices/data.d.ts.map +1 -1
- package/dist/store/slices/types.d.ts +6 -0
- package/dist/store/slices/types.d.ts.map +1 -0
- package/dist/store/slices/wallets.d.ts +60 -0
- package/dist/store/slices/wallets.d.ts.map +1 -0
- package/dist/store/ui.d.ts +4 -0
- package/dist/store/ui.d.ts.map +1 -1
- package/dist/store/utils/wallets.d.ts +17 -0
- package/dist/store/utils/wallets.d.ts.map +1 -0
- package/dist/types/config.d.ts +6 -3
- package/dist/types/config.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 +3 -7
- package/dist/types/wallets.d.ts.map +1 -1
- package/dist/utils/providers.d.ts +8 -9
- 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/settings.d.ts +1 -0
- package/dist/utils/settings.d.ts.map +1 -1
- package/dist/utils/swap.d.ts +5 -5
- package/dist/utils/swap.d.ts.map +1 -1
- package/dist/utils/wallets.d.ts +12 -14
- package/dist/utils/wallets.d.ts.map +1 -1
- package/dist/widget-embedded.build.json +1 -1
- package/package.json +8 -8
- package/src/QueueManager.tsx +17 -11
- package/src/components/ConfirmWalletsModal/ConfirmWalletsModal.tsx +5 -24
- package/src/components/ConfirmWalletsModal/WalletList.tsx +10 -7
- package/src/components/Layout/Layout.tsx +1 -3
- package/src/components/Quote/Quote.tsx +22 -3
- package/src/components/Quote/Quote.types.ts +2 -0
- package/src/components/Quote/QuoteCostDetails.styles.ts +0 -1
- package/src/components/Quote/QuoteCostDetails.tsx +23 -4
- package/src/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.helpers.ts +42 -22
- package/src/components/Quotes/Quotes.tsx +2 -3
- package/src/components/StatefulConnectModal/StatefulConnectModal.tsx +1 -1
- package/src/components/SwapDetails/SwapDetails.tsx +14 -6
- package/src/components/SwapDetailsAlerts/SwapDetailsAlerts.types.ts +1 -1
- package/src/components/SwapDetailsModal/SwapDetailsCompleteModal.tsx +26 -13
- package/src/components/TokenList/TokenList.tsx +4 -27
- package/src/components/WalletStatefulConnect/DerivationPath.helpers.ts +2 -1
- package/src/components/WalletStatefulConnect/Namespaces.tsx +31 -38
- package/src/components/WalletStatefulConnect/Namespaces.types.tsx +1 -1
- package/src/constants/quote.ts +25 -0
- package/src/containers/ExpandedQuotes/ExpandedQuotes.styles.ts +1 -0
- package/src/containers/ExpandedQuotes/ExpandedQuotes.tsx +1 -1
- package/src/containers/Inputs/Inputs.tsx +20 -7
- package/src/containers/QuoteInfo/QuoteInfo.tsx +3 -9
- package/src/containers/Wallets/Wallets.tsx +82 -16
- package/src/containers/WidgetInfo/WidgetInfo.helpers.ts +2 -2
- package/src/containers/WidgetInfo/WidgetInfo.tsx +10 -8
- package/src/containers/WidgetInfo/WidgetInfo.types.ts +2 -2
- package/src/hooks/useConfirmSwap/useConfirmSwap.helpers.ts +29 -66
- package/src/hooks/useConfirmSwap/useConfirmSwap.ts +10 -15
- package/src/hooks/useFetchApiConfig.ts +5 -1
- package/src/hooks/useFetchCustomToken.ts +5 -0
- package/src/hooks/useStatefulConnect/useStatefulConnect.ts +50 -17
- package/src/hooks/useStatefulConnect/useStatefulConnect.types.ts +3 -5
- package/src/hooks/useSubscribeToWidgetEvents/useSubscribeToWidgetEvents.ts +7 -6
- package/src/hooks/useSwapInput.ts +3 -11
- package/src/hooks/useWalletList.ts +6 -8
- package/src/hooks/useWalletProviders/useWalletProviders.ts +8 -12
- package/src/index.ts +1 -1
- package/src/pages/ConfirmSwapPage.tsx +7 -15
- package/src/pages/Home.tsx +5 -3
- package/src/pages/SelectSwapItemsPage.tsx +1 -2
- package/src/store/app.ts +4 -4
- package/src/store/quote.ts +3 -13
- package/src/store/slices/config.ts +76 -0
- package/src/store/slices/data.test.ts +23 -1
- package/src/store/slices/data.ts +3 -2
- package/src/store/slices/types.ts +9 -0
- package/src/store/slices/wallets.ts +488 -0
- package/src/store/ui.ts +6 -0
- package/src/store/utils/wallets.ts +108 -0
- package/src/types/config.ts +7 -3
- package/src/types/quote.ts +10 -24
- package/src/types/wallets.ts +3 -7
- package/src/utils/providers.ts +88 -36
- package/src/utils/quote.ts +57 -45
- package/src/utils/settings.ts +4 -0
- package/src/utils/swap.ts +56 -37
- package/src/utils/wallets.ts +76 -141
- package/dist/constants/warnings.d.ts +0 -3
- package/dist/constants/warnings.d.ts.map +0 -1
- package/dist/hooks/useObserveBalanceChanges/index.d.ts +0 -2
- package/dist/hooks/useObserveBalanceChanges/index.d.ts.map +0 -1
- package/dist/hooks/useObserveBalanceChanges/useObserveBalanceChanges.d.ts +0 -4
- package/dist/hooks/useObserveBalanceChanges/useObserveBalanceChanges.d.ts.map +0 -1
- package/dist/store/wallets.d.ts +0 -66
- package/dist/store/wallets.d.ts.map +0 -1
- package/src/constants/warnings.ts +0 -26
- package/src/hooks/useObserveBalanceChanges/index.ts +0 -1
- package/src/hooks/useObserveBalanceChanges/useObserveBalanceChanges.ts +0 -68
- package/src/store/wallets.ts +0 -268
package/src/utils/swap.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
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
|
-
import type { ConnectedWallet } from '../store/wallets';
|
|
2
|
+
import type { ConnectedWallet } from '../store/slices/wallets';
|
|
5
3
|
import type {
|
|
6
4
|
ConvertedToken,
|
|
7
5
|
QuoteError,
|
|
@@ -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
|
@@ -1,26 +1,18 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { ConnectedWallet, TokenBalance } from '../store/wallets';
|
|
1
|
+
import type { BalanceState, ConnectedWallet } from '../store/slices/wallets';
|
|
3
2
|
import type {
|
|
4
3
|
Balance,
|
|
5
4
|
SelectedQuote,
|
|
6
|
-
TokensBalance,
|
|
7
5
|
Wallet,
|
|
8
6
|
WalletInfoWithExtra,
|
|
9
7
|
} from '../types';
|
|
10
|
-
import type {
|
|
8
|
+
import type { ExtendedWalletInfo } from '@rango-dev/wallets-react';
|
|
11
9
|
import type {
|
|
12
10
|
Network,
|
|
13
|
-
WalletInfo,
|
|
14
11
|
WalletState,
|
|
15
12
|
WalletType,
|
|
16
13
|
WalletTypes,
|
|
17
14
|
} from '@rango-dev/wallets-shared';
|
|
18
|
-
import type {
|
|
19
|
-
BlockchainMeta,
|
|
20
|
-
Token,
|
|
21
|
-
TransactionType,
|
|
22
|
-
WalletDetail,
|
|
23
|
-
} from 'rango-sdk';
|
|
15
|
+
import type { BlockchainMeta, Token, TransactionType } from 'rango-sdk';
|
|
24
16
|
|
|
25
17
|
import {
|
|
26
18
|
BlockchainCategories,
|
|
@@ -47,9 +39,11 @@ import {
|
|
|
47
39
|
import { EXCLUDED_WALLETS } from '../constants/wallets';
|
|
48
40
|
|
|
49
41
|
import { isBlockchainTypeInCategory, removeDuplicateFrom } from './common';
|
|
50
|
-
import { createTokenHash } from './meta';
|
|
51
42
|
import { numberToString } from './numbers';
|
|
52
43
|
|
|
44
|
+
export type ExtendedModalWalletInfo = WalletInfoWithExtra &
|
|
45
|
+
Pick<ExtendedWalletInfo, 'properties' | 'isHub'>;
|
|
46
|
+
|
|
53
47
|
export function mapStatusToWalletState(state: WalletState): WalletStatus {
|
|
54
48
|
switch (true) {
|
|
55
49
|
case state.connected:
|
|
@@ -65,10 +59,10 @@ export function mapStatusToWalletState(state: WalletState): WalletStatus {
|
|
|
65
59
|
|
|
66
60
|
export function mapWalletTypesToWalletInfo(
|
|
67
61
|
getState: (type: WalletType) => WalletState,
|
|
68
|
-
getWalletInfo: (type: WalletType) =>
|
|
62
|
+
getWalletInfo: (type: WalletType) => ExtendedWalletInfo,
|
|
69
63
|
list: WalletType[],
|
|
70
64
|
chain?: string
|
|
71
|
-
):
|
|
65
|
+
): ExtendedModalWalletInfo[] {
|
|
72
66
|
return list
|
|
73
67
|
.filter((wallet) => !EXCLUDED_WALLETS.includes(wallet as WalletTypes))
|
|
74
68
|
.filter((wallet) => {
|
|
@@ -93,10 +87,11 @@ export function mapWalletTypesToWalletInfo(
|
|
|
93
87
|
img: image,
|
|
94
88
|
installLink,
|
|
95
89
|
showOnMobile,
|
|
96
|
-
|
|
97
|
-
singleNamespace,
|
|
90
|
+
needsNamespace,
|
|
98
91
|
supportedChains,
|
|
99
92
|
needsDerivationPath,
|
|
93
|
+
properties,
|
|
94
|
+
isHub,
|
|
100
95
|
} = getWalletInfo(type);
|
|
101
96
|
const blockchainTypes = removeDuplicateFrom(
|
|
102
97
|
supportedChains.map((item) => item.type)
|
|
@@ -110,10 +105,11 @@ export function mapWalletTypesToWalletInfo(
|
|
|
110
105
|
state,
|
|
111
106
|
type,
|
|
112
107
|
showOnMobile,
|
|
113
|
-
|
|
114
|
-
singleNamespace,
|
|
108
|
+
needsNamespace,
|
|
115
109
|
blockchainTypes,
|
|
116
110
|
needsDerivationPath,
|
|
111
|
+
properties,
|
|
112
|
+
isHub,
|
|
117
113
|
};
|
|
118
114
|
});
|
|
119
115
|
}
|
|
@@ -265,8 +261,6 @@ export function getQuoteWallets(params: {
|
|
|
265
261
|
return Array.from(wallets);
|
|
266
262
|
}
|
|
267
263
|
|
|
268
|
-
type Blockchain = { name: string; accounts: ConnectedWallet[] };
|
|
269
|
-
|
|
270
264
|
export function isAccountAndWalletMatched(
|
|
271
265
|
account: Wallet,
|
|
272
266
|
connectedWallet: ConnectedWallet
|
|
@@ -278,74 +272,18 @@ export function isAccountAndWalletMatched(
|
|
|
278
272
|
);
|
|
279
273
|
}
|
|
280
274
|
|
|
281
|
-
export function makeBalanceFor(
|
|
282
|
-
retrievedBalance: WalletDetail,
|
|
283
|
-
findToken: FindToken
|
|
284
|
-
): TokenBalance[] {
|
|
285
|
-
const { blockChain: chain, balances = [] } = retrievedBalance;
|
|
286
|
-
return (
|
|
287
|
-
balances?.map((tokenBalance) => ({
|
|
288
|
-
chain,
|
|
289
|
-
symbol: tokenBalance.asset.symbol,
|
|
290
|
-
ticker: tokenBalance.asset.symbol,
|
|
291
|
-
address: tokenBalance.asset.address || null,
|
|
292
|
-
rawAmount: tokenBalance.amount.amount,
|
|
293
|
-
decimal: tokenBalance.amount.decimals,
|
|
294
|
-
amount: new BigNumber(tokenBalance.amount.amount)
|
|
295
|
-
.shiftedBy(-tokenBalance.amount.decimals)
|
|
296
|
-
.toFixed(),
|
|
297
|
-
logo: '',
|
|
298
|
-
usdPrice: findToken(tokenBalance.asset)?.usdPrice || null,
|
|
299
|
-
})) || []
|
|
300
|
-
);
|
|
301
|
-
}
|
|
302
|
-
|
|
303
275
|
export function resetConnectedWalletState(
|
|
304
276
|
connectedWallet: ConnectedWallet
|
|
305
277
|
): ConnectedWallet {
|
|
306
278
|
return { ...connectedWallet, loading: false, error: true };
|
|
307
279
|
}
|
|
308
280
|
|
|
309
|
-
export const calculateWalletUsdValue = (
|
|
310
|
-
const
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
return acc.findIndex(
|
|
314
|
-
(i) => i.address === current.address && i.chain === current.chain
|
|
315
|
-
// eslint-disable-next-line @typescript-eslint/no-magic-numbers
|
|
316
|
-
) === -1
|
|
317
|
-
? [...acc, current]
|
|
318
|
-
: acc;
|
|
319
|
-
},
|
|
320
|
-
[]
|
|
321
|
-
);
|
|
281
|
+
export const calculateWalletUsdValue = (balances: BalanceState) => {
|
|
282
|
+
const total = Object.values(balances).reduce((prev, balance) => {
|
|
283
|
+
return balance.usdValue ? prev.plus(balance.usdValue) : prev;
|
|
284
|
+
}, new BigNumber(ZERO));
|
|
322
285
|
|
|
323
|
-
|
|
324
|
-
const modifiedWalletBlockchain: Blockchain = {
|
|
325
|
-
name: chain.chain,
|
|
326
|
-
accounts: [],
|
|
327
|
-
};
|
|
328
|
-
if (!uniqueAccountAddresses.has(chain.address)) {
|
|
329
|
-
uniqueAccountAddresses.add(chain.address);
|
|
330
|
-
}
|
|
331
|
-
uniqueAccountAddresses.forEach((accountAddress) => {
|
|
332
|
-
if (chain.address === accountAddress) {
|
|
333
|
-
modifiedWalletBlockchain.accounts.push(chain);
|
|
334
|
-
}
|
|
335
|
-
});
|
|
336
|
-
return modifiedWalletBlockchain;
|
|
337
|
-
});
|
|
338
|
-
const total = numberToString(
|
|
339
|
-
modifiedWalletBlockchains
|
|
340
|
-
?.flatMap((b) => b.accounts)
|
|
341
|
-
?.flatMap((a) => a?.balances)
|
|
342
|
-
?.map((b) =>
|
|
343
|
-
new BigNumber(b?.amount || ZERO).multipliedBy(b?.usdPrice || 0)
|
|
344
|
-
)
|
|
345
|
-
?.reduce((a, b) => a.plus(b), ZERO) || ZERO
|
|
346
|
-
).toString();
|
|
347
|
-
|
|
348
|
-
return numberWithThousandSeparator(total);
|
|
286
|
+
return numberWithThousandSeparator(total.toString());
|
|
349
287
|
};
|
|
350
288
|
|
|
351
289
|
function numberWithThousandSeparator(number: string | number): string {
|
|
@@ -384,19 +322,31 @@ export const getKeplrCompatibleConnectedWallets = (
|
|
|
384
322
|
};
|
|
385
323
|
|
|
386
324
|
export function formatBalance(balance: Balance | null): Balance | null {
|
|
325
|
+
if (!balance) {
|
|
326
|
+
return null;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
const amount = new BigNumber(balance.amount)
|
|
330
|
+
.shiftedBy(-balance.decimals)
|
|
331
|
+
.toFixed();
|
|
332
|
+
const usdValue = balance.usdValue
|
|
333
|
+
? new BigNumber(balance.usdValue).shiftedBy(-balance.decimals).toFixed()
|
|
334
|
+
: null;
|
|
335
|
+
const formattedAmount = numberToString(
|
|
336
|
+
amount,
|
|
337
|
+
BALANCE_MIN_DECIMALS,
|
|
338
|
+
BALANCE_MAX_DECIMALS
|
|
339
|
+
);
|
|
340
|
+
// null is using for detecing uknown prices
|
|
341
|
+
const formattedUsdValue = usdValue
|
|
342
|
+
? numberToString(usdValue, USD_VALUE_MIN_DECIMALS, USD_VALUE_MAX_DECIMALS)
|
|
343
|
+
: null;
|
|
344
|
+
|
|
387
345
|
const formattedBalance: Balance | null = balance
|
|
388
346
|
? {
|
|
389
347
|
...balance,
|
|
390
|
-
amount:
|
|
391
|
-
|
|
392
|
-
BALANCE_MIN_DECIMALS,
|
|
393
|
-
BALANCE_MAX_DECIMALS
|
|
394
|
-
),
|
|
395
|
-
usdValue: numberToString(
|
|
396
|
-
balance.usdValue,
|
|
397
|
-
USD_VALUE_MIN_DECIMALS,
|
|
398
|
-
USD_VALUE_MAX_DECIMALS
|
|
399
|
-
),
|
|
348
|
+
amount: formattedAmount,
|
|
349
|
+
usdValue: formattedUsdValue,
|
|
400
350
|
}
|
|
401
351
|
: null;
|
|
402
352
|
|
|
@@ -408,17 +358,39 @@ export function compareTokenBalance(
|
|
|
408
358
|
token2Balance: Balance | null
|
|
409
359
|
): number {
|
|
410
360
|
if (token1Balance?.usdValue || token2Balance?.usdValue) {
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
361
|
+
const token1UsdValue =
|
|
362
|
+
!!token1Balance && !!token1Balance.usdValue
|
|
363
|
+
? new BigNumber(token1Balance.usdValue).shiftedBy(
|
|
364
|
+
-token1Balance.decimals
|
|
365
|
+
)
|
|
366
|
+
: ZERO;
|
|
367
|
+
const token2UsdValue =
|
|
368
|
+
!!token2Balance && !!token2Balance.usdValue
|
|
369
|
+
? new BigNumber(token2Balance.usdValue).shiftedBy(
|
|
370
|
+
-token2Balance.decimals
|
|
371
|
+
)
|
|
372
|
+
: ZERO;
|
|
373
|
+
|
|
374
|
+
if (token1UsdValue.isEqualTo(token2UsdValue)) {
|
|
375
|
+
return 0;
|
|
376
|
+
}
|
|
377
|
+
return token1UsdValue.isGreaterThan(token2UsdValue) ? -1 : 1;
|
|
415
378
|
}
|
|
416
379
|
|
|
417
380
|
if (token1Balance?.amount || token2Balance?.amount) {
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
381
|
+
const token1Amount =
|
|
382
|
+
!!token1Balance && !!token1Balance.amount
|
|
383
|
+
? new BigNumber(token1Balance.amount).shiftedBy(-token1Balance.decimals)
|
|
384
|
+
: ZERO;
|
|
385
|
+
const token2Amount =
|
|
386
|
+
!!token2Balance && !!token2Balance.amount
|
|
387
|
+
? new BigNumber(token2Balance.amount).shiftedBy(-token2Balance.decimals)
|
|
388
|
+
: ZERO;
|
|
389
|
+
|
|
390
|
+
if (token1Amount.isEqualTo(token2Amount)) {
|
|
391
|
+
return 0;
|
|
392
|
+
}
|
|
393
|
+
return token1Amount.isGreaterThan(token2Amount) ? -1 : 1;
|
|
422
394
|
}
|
|
423
395
|
|
|
424
396
|
return 0;
|
|
@@ -436,8 +408,8 @@ export function areTokensEqual(
|
|
|
436
408
|
}
|
|
437
409
|
|
|
438
410
|
export function sortWalletsBasedOnConnectionState(
|
|
439
|
-
wallets:
|
|
440
|
-
):
|
|
411
|
+
wallets: ExtendedModalWalletInfo[]
|
|
412
|
+
): ExtendedModalWalletInfo[] {
|
|
441
413
|
return wallets.sort(
|
|
442
414
|
(a, b) =>
|
|
443
415
|
Number(b.state === WalletStatus.CONNECTED) -
|
|
@@ -484,43 +456,6 @@ export function getAddress({
|
|
|
484
456
|
)?.address;
|
|
485
457
|
}
|
|
486
458
|
|
|
487
|
-
export function makeTokensBalance(connectedWallets: ConnectedWallet[]) {
|
|
488
|
-
return connectedWallets
|
|
489
|
-
.flatMap((wallet) => wallet.balances)
|
|
490
|
-
.reduce((balances: TokensBalance, balance) => {
|
|
491
|
-
const currentBalance = {
|
|
492
|
-
amount: balance?.amount ?? '',
|
|
493
|
-
decimals: balance?.decimal ?? 0,
|
|
494
|
-
usdValue: balance?.usdPrice
|
|
495
|
-
? new BigNumber(balance?.usdPrice ?? ZERO)
|
|
496
|
-
.multipliedBy(balance?.amount)
|
|
497
|
-
.toString()
|
|
498
|
-
: '',
|
|
499
|
-
};
|
|
500
|
-
|
|
501
|
-
const tokenHash = balance
|
|
502
|
-
? createTokenHash({
|
|
503
|
-
symbol: balance.symbol,
|
|
504
|
-
blockchain: balance.chain,
|
|
505
|
-
address: balance.address,
|
|
506
|
-
})
|
|
507
|
-
: null;
|
|
508
|
-
|
|
509
|
-
const prevBalance = tokenHash ? balances[tokenHash] : null;
|
|
510
|
-
|
|
511
|
-
const shouldUpdateBalance =
|
|
512
|
-
tokenHash &&
|
|
513
|
-
(!prevBalance ||
|
|
514
|
-
(prevBalance && prevBalance.amount < currentBalance.amount));
|
|
515
|
-
|
|
516
|
-
if (shouldUpdateBalance) {
|
|
517
|
-
balances[tokenHash] = currentBalance;
|
|
518
|
-
}
|
|
519
|
-
|
|
520
|
-
return balances;
|
|
521
|
-
}, {});
|
|
522
|
-
}
|
|
523
|
-
|
|
524
459
|
export const isFetchingBalance = (
|
|
525
460
|
connectedWallets: ConnectedWallet[],
|
|
526
461
|
blockchain: string
|
|
@@ -529,12 +464,12 @@ export const isFetchingBalance = (
|
|
|
529
464
|
(wallet) => wallet.chain === blockchain && wallet.loading
|
|
530
465
|
);
|
|
531
466
|
|
|
532
|
-
export function hashWalletsState(walletsInfo:
|
|
467
|
+
export function hashWalletsState(walletsInfo: WalletInfoWithExtra[]) {
|
|
533
468
|
return walletsInfo.map((w) => w.state).join('-');
|
|
534
469
|
}
|
|
535
470
|
|
|
536
471
|
export function filterBlockchainsByWalletTypes(
|
|
537
|
-
wallets:
|
|
472
|
+
wallets: WalletInfoWithExtra[],
|
|
538
473
|
blockchains: BlockchainMeta[]
|
|
539
474
|
) {
|
|
540
475
|
const uniqueBlockchainTypes = new Set<TransactionType>();
|
|
@@ -551,7 +486,7 @@ export function filterBlockchainsByWalletTypes(
|
|
|
551
486
|
}
|
|
552
487
|
|
|
553
488
|
export function filterWalletsByCategory(
|
|
554
|
-
wallets:
|
|
489
|
+
wallets: ExtendedModalWalletInfo[],
|
|
555
490
|
category: string
|
|
556
491
|
) {
|
|
557
492
|
if (category === BlockchainCategories.ALL) {
|
|
@@ -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"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/useObserveBalanceChanges/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useObserveBalanceChanges.d.ts","sourceRoot":"","sources":["../../../src/hooks/useObserveBalanceChanges/useObserveBalanceChanges.ts"],"names":[],"mappings":"AAUA,wBAAgB,wBAAwB,CAAC,kBAAkB,CAAC,EAAE,MAAM;;EAyDnE"}
|
package/dist/store/wallets.d.ts
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import type { FindToken } from './slices/data';
|
|
2
|
-
import type { Balance, TokensBalance, Wallet } from '../types';
|
|
3
|
-
import type { WalletType } from '@rango-dev/wallets-shared';
|
|
4
|
-
import type { Token } from 'rango-sdk';
|
|
5
|
-
export type TokenBalance = {
|
|
6
|
-
chain: string;
|
|
7
|
-
symbol: string;
|
|
8
|
-
ticker: string;
|
|
9
|
-
address: string | null;
|
|
10
|
-
rawAmount: string;
|
|
11
|
-
decimal: number | null;
|
|
12
|
-
amount: string;
|
|
13
|
-
logo: string | null;
|
|
14
|
-
usdPrice: number | null;
|
|
15
|
-
};
|
|
16
|
-
export interface ConnectedWallet extends Wallet {
|
|
17
|
-
balances: TokenBalance[] | null;
|
|
18
|
-
explorerUrl: string | null;
|
|
19
|
-
selected: boolean;
|
|
20
|
-
loading: boolean;
|
|
21
|
-
error: boolean;
|
|
22
|
-
}
|
|
23
|
-
interface WalletsStore {
|
|
24
|
-
connectedWallets: ConnectedWallet[];
|
|
25
|
-
balances: TokensBalance;
|
|
26
|
-
loading: boolean;
|
|
27
|
-
connectWallet: (accounts: Wallet[], findToken: FindToken) => void;
|
|
28
|
-
disconnectWallet: (walletType: WalletType) => void;
|
|
29
|
-
selectWallets: (wallets: {
|
|
30
|
-
walletType: string;
|
|
31
|
-
chain: string;
|
|
32
|
-
}[]) => void;
|
|
33
|
-
clearConnectedWallet: () => void;
|
|
34
|
-
getWalletsDetails: (accounts: Wallet[], findToken: FindToken, shouldRetry?: boolean) => void;
|
|
35
|
-
getBalanceFor: (token: Token) => Balance | null;
|
|
36
|
-
}
|
|
37
|
-
export declare const useWalletsStore: {
|
|
38
|
-
(): WalletsStore;
|
|
39
|
-
<U>(selector: (state: WalletsStore) => U): U;
|
|
40
|
-
<U_1>(selector: (state: WalletsStore) => U_1, equalityFn: (a: U_1, b: U_1) => boolean): U_1;
|
|
41
|
-
} & Omit<import("zustand").StoreApi<WalletsStore>, "subscribe"> & {
|
|
42
|
-
subscribe: {
|
|
43
|
-
(listener: (selectedState: WalletsStore, previousSelectedState: WalletsStore) => void): () => void;
|
|
44
|
-
<U_2>(selector: (state: WalletsStore) => U_2, listener: (selectedState: U_2, previousSelectedState: U_2) => void, options?: {
|
|
45
|
-
equalityFn?: ((a: U_2, b: U_2) => boolean) | undefined;
|
|
46
|
-
fireImmediately?: boolean | undefined;
|
|
47
|
-
} | undefined): () => void;
|
|
48
|
-
};
|
|
49
|
-
} & {
|
|
50
|
-
use: {
|
|
51
|
-
connectedWallets: () => ConnectedWallet[];
|
|
52
|
-
balances: () => TokensBalance;
|
|
53
|
-
loading: () => boolean;
|
|
54
|
-
connectWallet: () => (accounts: Wallet[], findToken: FindToken) => void;
|
|
55
|
-
disconnectWallet: () => (walletType: WalletType) => void;
|
|
56
|
-
selectWallets: () => (wallets: {
|
|
57
|
-
walletType: string;
|
|
58
|
-
chain: string;
|
|
59
|
-
}[]) => void;
|
|
60
|
-
clearConnectedWallet: () => () => void;
|
|
61
|
-
getWalletsDetails: () => (accounts: Wallet[], findToken: FindToken, shouldRetry?: boolean) => void;
|
|
62
|
-
getBalanceFor: () => (token: Token) => Balance | null;
|
|
63
|
-
};
|
|
64
|
-
};
|
|
65
|
-
export {};
|
|
66
|
-
//# sourceMappingURL=wallets.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"wallets.d.ts","sourceRoot":"","sources":["../../src/store/wallets.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,KAAK,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAC/D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AAkBvC,MAAM,MAAM,YAAY,GAAG;IACzB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;CACzB,CAAC;AAEF,MAAM,WAAW,eAAgB,SAAQ,MAAM;IAC7C,QAAQ,EAAE,YAAY,EAAE,GAAG,IAAI,CAAC;IAChC,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,QAAQ,EAAE,OAAO,CAAC;IAClB,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,EAAE,OAAO,CAAC;CAChB;AACD,UAAU,YAAY;IACpB,gBAAgB,EAAE,eAAe,EAAE,CAAC;IACpC,QAAQ,EAAE,aAAa,CAAC;IACxB,OAAO,EAAE,OAAO,CAAC;IACjB,aAAa,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,EAAE,SAAS,EAAE,SAAS,KAAK,IAAI,CAAC;IAClE,gBAAgB,EAAE,CAAC,UAAU,EAAE,UAAU,KAAK,IAAI,CAAC;IACnD,aAAa,EAAE,CAAC,OAAO,EAAE;QAAE,UAAU,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,EAAE,KAAK,IAAI,CAAC;IAC1E,oBAAoB,EAAE,MAAM,IAAI,CAAC;IACjC,iBAAiB,EAAE,CACjB,QAAQ,EAAE,MAAM,EAAE,EAClB,SAAS,EAAE,SAAS,EACpB,WAAW,CAAC,EAAE,OAAO,KAClB,IAAI,CAAC;IACV,aAAa,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,OAAO,GAAG,IAAI,CAAC;CACjD;AAED,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;;;wCAZA,MAAM,EAAE,aAAa,SAAS,KAAK,IAAI;6CAClC,UAAU,KAAK,IAAI;uCACzB;YAAE,UAAU,EAAE,MAAM,CAAC;YAAC,KAAK,EAAE,MAAM,CAAA;SAAE,EAAE,KAAK,IAAI;0CAC7C,IAAI;4CAEpB,MAAM,EAAE,aACP,SAAS,gBACN,OAAO,KAClB,IAAI;qCACc,KAAK,KAAK,OAAO,GAAG,IAAI;;CAsNhD,CAAC"}
|
|
@@ -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
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { useObserveBalanceChanges } from './useObserveBalanceChanges';
|