@rango-dev/widget-embedded 0.0.0-experimental-1624fbb4-20260708 → 0.0.0-experimental-a84f27a7-20260921
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 +47 -0
- package/dist/QueueManager.d.ts.map +1 -1
- package/dist/components/ConfirmWalletsModal/ConfirmWallets.styles.d.ts +1 -1
- package/dist/components/ConfirmWalletsModal/ConfirmWallets.styles.d.ts.map +1 -1
- package/dist/components/CustomDestination/CustomDestination.styles.d.ts +4 -4
- package/dist/components/CustomDestination/CustomDestination.styles.d.ts.map +1 -1
- package/dist/components/CustomTokenModal/CustomTokenModal.styles.d.ts +169 -169
- package/dist/components/CustomTokenModal/CustomTokenModal.styles.d.ts.map +1 -1
- package/dist/components/FilterSelector/FilterSelector.style.d.ts +1 -1
- package/dist/components/FilterSelector/FilterSelector.style.d.ts.map +1 -1
- package/dist/components/HeaderButtons/HeaderButtons.styles.d.ts +1 -1
- package/dist/components/HeaderButtons/HeaderButtons.styles.d.ts.map +1 -1
- package/dist/components/NamespaceItem/NamespaceItem.d.ts.map +1 -1
- package/dist/components/NamespaceItem/NamespaceItem.styles.d.ts +1 -1
- package/dist/components/NamespaceItem/NamespaceItem.styles.d.ts.map +1 -1
- package/dist/components/NamespaceItem/NamespaceItem.types.d.ts +3 -3
- package/dist/components/NamespaceItem/NamespaceItem.types.d.ts.map +1 -1
- package/dist/components/Quote/Quote.d.ts.map +1 -1
- package/dist/components/Quote/Quote.styles.d.ts +171 -171
- package/dist/components/Quote/Quote.styles.d.ts.map +1 -1
- package/dist/components/Quote/Quote.types.d.ts +0 -2
- package/dist/components/Quote/Quote.types.d.ts.map +1 -1
- package/dist/components/Quote/QuoteCostDetails.d.ts.map +1 -1
- package/dist/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.styles.d.ts +169 -169
- package/dist/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.styles.d.ts.map +1 -1
- package/dist/components/RefreshModal/RefreshModal.styles.d.ts +168 -168
- package/dist/components/RefreshModal/RefreshModal.styles.d.ts.map +1 -1
- package/dist/components/StatefulConnectModal/StatefulConnectModal.d.ts.map +1 -1
- package/dist/components/SwapDetails/SwapDetails.d.ts.map +1 -1
- package/dist/components/SwapDetails/SwapDetails.styles.d.ts +1 -1
- package/dist/components/SwapDetails/SwapDetails.styles.d.ts.map +1 -1
- package/dist/components/SwapDetailsModal/SwapDetailsModal.ConnectWallet.d.ts.map +1 -1
- package/dist/components/SwapDetailsModal/SwapDetailsModal.InstallWallet.d.ts.map +1 -1
- package/dist/components/SwapDetailsModal/SwapDetailsModal.types.d.ts +3 -3
- package/dist/components/SwapDetailsModal/SwapDetailsModal.types.d.ts.map +1 -1
- package/dist/components/SwapMetrics/SwapMetrics.styles.d.ts +1 -1
- package/dist/components/SwapMetrics/SwapMetrics.styles.d.ts.map +1 -1
- package/dist/components/TokenList/TokenList.styles.d.ts +2 -2
- package/dist/components/TokenList/TokenList.styles.d.ts.map +1 -1
- package/dist/components/WalletStatefulConnect/DerivationPath.d.ts.map +1 -1
- package/dist/components/WalletStatefulConnect/DerivationPath.helpers.d.ts +7 -3
- package/dist/components/WalletStatefulConnect/DerivationPath.helpers.d.ts.map +1 -1
- package/dist/components/WalletStatefulConnect/DerivationPath.helpers.test.d.ts +2 -0
- package/dist/components/WalletStatefulConnect/DerivationPath.helpers.test.d.ts.map +1 -0
- package/dist/components/WalletStatefulConnect/DerivationPath.styles.d.ts +169 -169
- package/dist/components/WalletStatefulConnect/DerivationPath.styles.d.ts.map +1 -1
- package/dist/components/WalletStatefulConnect/Detached.d.ts.map +1 -1
- package/dist/components/WalletStatefulConnect/NamespaceDetachedItem.d.ts.map +1 -1
- package/dist/components/WalletStatefulConnect/Namespaces.d.ts.map +1 -1
- package/dist/components/WalletStatefulConnect/Namespaces.styles.d.ts +168 -168
- package/dist/components/WalletStatefulConnect/Namespaces.styles.d.ts.map +1 -1
- package/dist/components/WalletStatefulConnect/Namespaces.types.d.ts +3 -3
- package/dist/components/WalletStatefulConnect/Namespaces.types.d.ts.map +1 -1
- package/dist/constants/errors.d.ts +1 -0
- package/dist/constants/errors.d.ts.map +1 -1
- package/dist/containers/Wallets/Wallets.d.ts.map +1 -1
- package/dist/containers/Wallets/Wallets.helpers.d.ts +2 -2
- package/dist/containers/Wallets/Wallets.helpers.d.ts.map +1 -1
- package/dist/containers/Wallets/Wallets.types.d.ts +4 -4
- package/dist/containers/Wallets/Wallets.types.d.ts.map +1 -1
- package/dist/containers/Wallets/useUpdates.d.ts +1 -1
- package/dist/containers/Wallets/useUpdates.d.ts.map +1 -1
- package/dist/containers/WidgetProvider/WidgetProvider.d.ts.map +1 -1
- package/dist/containers/WidgetProvider/WidgetProvider.helpers.d.ts +5 -0
- package/dist/containers/WidgetProvider/WidgetProvider.helpers.d.ts.map +1 -0
- package/dist/containers/WidgetProvider/WidgetProvider.types.d.ts +1 -1
- package/dist/containers/WidgetProvider/WidgetProvider.types.d.ts.map +1 -1
- package/dist/hooks/useStatefulConnect/useStatefulConnect.d.ts.map +1 -1
- package/dist/hooks/useStatefulConnect/useStatefulConnect.types.d.ts +5 -4
- package/dist/hooks/useStatefulConnect/useStatefulConnect.types.d.ts.map +1 -1
- package/dist/hooks/useWalletList.d.ts.map +1 -1
- package/dist/hooks/useWalletProviders/useWalletProviders.d.ts +2 -2
- package/dist/hooks/useWalletProviders/useWalletProviders.d.ts.map +1 -1
- package/dist/hooks/useWalletProviders/useWalletProviders.helpers.d.ts +2 -3
- package/dist/hooks/useWalletProviders/useWalletProviders.helpers.d.ts.map +1 -1
- package/dist/index.d.ts +10 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -2
- package/dist/index.js.map +4 -4
- package/dist/store/AppStore.d.ts +2 -2
- package/dist/store/AppStore.d.ts.map +1 -1
- package/dist/store/app.d.ts +2 -2
- package/dist/store/app.d.ts.map +1 -1
- package/dist/store/slices/config.d.ts +5 -5
- package/dist/store/slices/config.d.ts.map +1 -1
- package/dist/test-utils/fixtures.d.ts +2 -2
- package/dist/test-utils/fixtures.d.ts.map +1 -1
- package/dist/types/config.d.ts +25 -4
- package/dist/types/config.d.ts.map +1 -1
- package/dist/types/wallets.d.ts +1 -1
- package/dist/types/wallets.d.ts.map +1 -1
- package/dist/utils/common.d.ts +1 -0
- package/dist/utils/common.d.ts.map +1 -1
- package/dist/utils/connectionReporting.d.ts +24 -0
- package/dist/utils/connectionReporting.d.ts.map +1 -0
- package/dist/utils/connectionReporting.test.d.ts +2 -0
- package/dist/utils/connectionReporting.test.d.ts.map +1 -0
- package/dist/utils/errors.d.ts +14 -0
- package/dist/utils/errors.d.ts.map +1 -0
- package/dist/utils/errors.test.d.ts +2 -0
- package/dist/utils/errors.test.d.ts.map +1 -0
- package/dist/utils/providers.d.ts +3 -6
- package/dist/utils/providers.d.ts.map +1 -1
- package/dist/utils/swap.d.ts +1 -1
- package/dist/utils/swap.d.ts.map +1 -1
- package/dist/utils/wallets.d.ts +2 -1
- package/dist/utils/wallets.d.ts.map +1 -1
- package/package.json +16 -16
- package/src/QueueManager.tsx +17 -8
- package/src/components/NamespaceItem/NamespaceItem.styles.ts +1 -0
- package/src/components/NamespaceItem/NamespaceItem.tsx +5 -1
- package/src/components/NamespaceItem/NamespaceItem.types.ts +3 -3
- package/src/components/Quote/Quote.tsx +0 -2
- package/src/components/Quote/Quote.types.ts +0 -2
- package/src/components/Quote/QuoteCostDetails.tsx +15 -4
- package/src/components/StatefulConnectModal/StatefulConnectModal.tsx +8 -2
- package/src/components/SwapDetails/SwapDetails.tsx +18 -6
- package/src/components/SwapDetailsModal/SwapDetailsModal.ConnectWallet.tsx +23 -23
- package/src/components/SwapDetailsModal/SwapDetailsModal.InstallWallet.tsx +8 -2
- package/src/components/SwapDetailsModal/SwapDetailsModal.types.ts +3 -3
- package/src/components/TokenList/LoadingTokenList.tsx +2 -2
- package/src/components/WalletStatefulConnect/DerivationPath.helpers.test.ts +98 -0
- package/src/components/WalletStatefulConnect/DerivationPath.helpers.ts +14 -10
- package/src/components/WalletStatefulConnect/DerivationPath.tsx +14 -7
- package/src/components/WalletStatefulConnect/Detached.tsx +17 -8
- package/src/components/WalletStatefulConnect/NamespaceDetachedItem.tsx +2 -1
- package/src/components/WalletStatefulConnect/Namespaces.tsx +6 -12
- package/src/components/WalletStatefulConnect/Namespaces.types.tsx +3 -3
- package/src/constants/errors.ts +3 -0
- package/src/containers/Wallets/Wallets.helpers.ts +4 -4
- package/src/containers/Wallets/Wallets.tsx +20 -3
- package/src/containers/Wallets/Wallets.types.ts +4 -7
- package/src/containers/Wallets/useUpdates.ts +4 -119
- package/src/containers/WidgetProvider/WidgetProvider.helpers.ts +10 -0
- package/src/containers/WidgetProvider/WidgetProvider.tsx +12 -1
- package/src/containers/WidgetProvider/WidgetProvider.types.ts +1 -1
- package/src/hooks/useStatefulConnect/useStatefulConnect.ts +30 -31
- package/src/hooks/useStatefulConnect/useStatefulConnect.types.ts +6 -3
- package/src/hooks/useWalletList.ts +10 -7
- package/src/hooks/useWalletProviders/useWalletProviders.helpers.ts +3 -10
- package/src/hooks/useWalletProviders/useWalletProviders.ts +2 -2
- package/src/index.ts +10 -11
- package/src/store/AppStore.tsx +4 -2
- package/src/store/app.ts +7 -2
- package/src/store/slices/config.ts +36 -25
- package/src/store/slices/data.test.ts +2 -2
- package/src/test-utils/fixtures.ts +6 -2
- package/src/types/config.ts +31 -4
- package/src/types/wallets.ts +1 -1
- package/src/utils/common.ts +6 -0
- package/src/utils/connectionReporting.test.ts +379 -0
- package/src/utils/connectionReporting.ts +94 -0
- package/src/utils/errors.test.ts +125 -0
- package/src/utils/errors.ts +88 -0
- package/src/utils/providers.ts +16 -50
- package/src/utils/swap.ts +8 -1
- package/src/utils/wallets.ts +12 -15
- package/dist/widget-embedded.build.json +0 -1
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { QuoteCostDetailsProps } from './Quote.types';
|
|
2
2
|
import type { NameOfFees } from '../../constants/quote';
|
|
3
|
-
import type BigNumber from 'bignumber.js';
|
|
4
3
|
|
|
5
4
|
import { i18n } from '@lingui/core';
|
|
6
5
|
import {
|
|
@@ -12,6 +11,7 @@ import {
|
|
|
12
11
|
QuoteCost,
|
|
13
12
|
Typography,
|
|
14
13
|
} from '@rango-dev/ui';
|
|
14
|
+
import BigNumber from 'bignumber.js';
|
|
15
15
|
import React, { useState } from 'react';
|
|
16
16
|
|
|
17
17
|
import { getFeeLabel } from '../../constants/quote';
|
|
@@ -62,7 +62,6 @@ export function QuoteCostDetails(props: QuoteCostDetailsProps) {
|
|
|
62
62
|
const {
|
|
63
63
|
steps,
|
|
64
64
|
quote,
|
|
65
|
-
fee,
|
|
66
65
|
time,
|
|
67
66
|
feeWarning,
|
|
68
67
|
timeWarning,
|
|
@@ -73,8 +72,20 @@ export function QuoteCostDetails(props: QuoteCostDetailsProps) {
|
|
|
73
72
|
const container = fullExpandedMode ? getExpanded() : getContainer();
|
|
74
73
|
|
|
75
74
|
const feesGroup = getFeesGroup(swaps);
|
|
75
|
+
|
|
76
|
+
/*
|
|
77
|
+
* The "Total Payable Fee" must reflect only the fees the user actually pays
|
|
78
|
+
* (feesGroup.payable). We sum the USD value of every payable fee group and use
|
|
79
|
+
* it for both the collapsed summary and the itemized rows in the modal, so the
|
|
80
|
+
* two never disagree.
|
|
81
|
+
*/
|
|
82
|
+
const totalPayableFee = Object.values(feesGroup.payable).reduce(
|
|
83
|
+
(acc: BigNumber, fees) => acc.plus(getTotalFeesInUsd(fees)),
|
|
84
|
+
new BigNumber(0)
|
|
85
|
+
);
|
|
86
|
+
|
|
76
87
|
const roundedFee = numberToString(
|
|
77
|
-
|
|
88
|
+
totalPayableFee,
|
|
78
89
|
GAS_FEE_MIN_DECIMALS,
|
|
79
90
|
GAS_FEE_MAX_DECIMALS
|
|
80
91
|
);
|
|
@@ -181,7 +192,7 @@ export function QuoteCostDetails(props: QuoteCostDetailsProps) {
|
|
|
181
192
|
<Typography variant="label" size="medium">
|
|
182
193
|
$
|
|
183
194
|
{numberToString(
|
|
184
|
-
|
|
195
|
+
totalPayableFee,
|
|
185
196
|
USD_VALUE_MIN_DECIMALS,
|
|
186
197
|
USD_VALUE_MAX_DECIMALS
|
|
187
198
|
)}
|
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
} from '../../hooks/useStatefulConnect';
|
|
12
12
|
import { useWalletList } from '../../hooks/useWalletList';
|
|
13
13
|
import { getContainer } from '../../utils/common';
|
|
14
|
+
import { tryRefineErrorMessage } from '../../utils/errors';
|
|
14
15
|
import { WatermarkedModal } from '../common/WatermarkedModal';
|
|
15
16
|
import {
|
|
16
17
|
ConnectStatus,
|
|
@@ -44,8 +45,13 @@ export function StatefulConnectModal(props: PropTypes) {
|
|
|
44
45
|
const successModalTimerId = useRef<ReturnType<typeof setTimeout>>();
|
|
45
46
|
const [isConnecting, setIsConnecting] = useState(false);
|
|
46
47
|
const [error, setError] = useState<string>();
|
|
47
|
-
const catchErrorOnHandle = (error
|
|
48
|
-
setError(
|
|
48
|
+
const catchErrorOnHandle = (error?: Error) => {
|
|
49
|
+
setError(
|
|
50
|
+
tryRefineErrorMessage(
|
|
51
|
+
error,
|
|
52
|
+
error?.message || 'An unknown error happened during connecting wallet.'
|
|
53
|
+
)
|
|
54
|
+
);
|
|
49
55
|
};
|
|
50
56
|
const { terminateConnectingWallets } = useWalletList();
|
|
51
57
|
|
|
@@ -36,6 +36,8 @@ import { useNotificationStore } from '../../store/notification';
|
|
|
36
36
|
import { useQuoteStore } from '../../store/quote';
|
|
37
37
|
import { UiEventTypes } from '../../types';
|
|
38
38
|
import { getContainer } from '../../utils/common';
|
|
39
|
+
import { trackConnection } from '../../utils/connectionReporting';
|
|
40
|
+
import { tryRefineError } from '../../utils/errors';
|
|
39
41
|
import { emitUiEvent } from '../../utils/events';
|
|
40
42
|
import {
|
|
41
43
|
numberToString,
|
|
@@ -175,17 +177,27 @@ export function SwapDetails(props: SwapDetailsProps) {
|
|
|
175
177
|
const handleSwitchNetwork = () => {
|
|
176
178
|
if (switchNetworkIsAvailable) {
|
|
177
179
|
handleShowSwitchNetworkLoading();
|
|
178
|
-
|
|
180
|
+
trackConnection(
|
|
181
|
+
connect(currentStepWallet.walletType, [
|
|
182
|
+
{
|
|
183
|
+
namespace: currentStepNamespace.namespace,
|
|
184
|
+
network: currentStepNamespace.network,
|
|
185
|
+
},
|
|
186
|
+
]),
|
|
179
187
|
{
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
188
|
+
trigger: 'swap-details',
|
|
189
|
+
source: 'user',
|
|
190
|
+
walletType: currentStepWallet.walletType,
|
|
191
|
+
namespaces: [currentStepNamespace.namespace],
|
|
192
|
+
}
|
|
193
|
+
)
|
|
184
194
|
.then(() => {
|
|
185
195
|
handleShowSwitchNetworkSucceeded();
|
|
186
196
|
})
|
|
187
197
|
.catch((error: unknown) => {
|
|
188
|
-
handleShowSwitchNetworkFailed(
|
|
198
|
+
handleShowSwitchNetworkFailed(
|
|
199
|
+
tryRefineError(error) ?? (error as Error)
|
|
200
|
+
);
|
|
189
201
|
});
|
|
190
202
|
}
|
|
191
203
|
};
|
|
@@ -16,6 +16,8 @@ import React, { useState } from 'react';
|
|
|
16
16
|
|
|
17
17
|
import { useWalletList } from '../../hooks/useWalletList';
|
|
18
18
|
import { useUiStore } from '../../store/ui';
|
|
19
|
+
import { trackConnection } from '../../utils/connectionReporting';
|
|
20
|
+
import { tryRefineError } from '../../utils/errors';
|
|
19
21
|
import { getConciseAddress } from '../../utils/wallets';
|
|
20
22
|
import { NamespaceItem } from '../NamespaceItem';
|
|
21
23
|
|
|
@@ -44,15 +46,12 @@ export const ConnectWalletContent = (props: ConnectWalletContentProps) => {
|
|
|
44
46
|
}
|
|
45
47
|
|
|
46
48
|
const walletState = state(currentStepWallet.walletType);
|
|
47
|
-
const namespaceState =
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
: null;
|
|
49
|
+
const namespaceState = namespace?.namespace
|
|
50
|
+
? walletState.namespaces?.get(namespace.namespace)
|
|
51
|
+
: null;
|
|
51
52
|
|
|
52
53
|
const connecting = walletState.connecting || namespaceState?.connecting;
|
|
53
|
-
const connected =
|
|
54
|
-
? namespaceState?.connected
|
|
55
|
-
: walletState.connected;
|
|
54
|
+
const connected = namespaceState?.connected;
|
|
56
55
|
|
|
57
56
|
const getButtonTitle = () => {
|
|
58
57
|
if (connected) {
|
|
@@ -76,20 +75,23 @@ export const ConnectWalletContent = (props: ConnectWalletContentProps) => {
|
|
|
76
75
|
const handleConnect = async () => {
|
|
77
76
|
try {
|
|
78
77
|
setError(null);
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
78
|
+
const namespaces = namespace?.namespace
|
|
79
|
+
? [
|
|
80
|
+
{
|
|
81
|
+
namespace: namespace?.namespace,
|
|
82
|
+
network: undefined,
|
|
83
|
+
derivationPath: currentStepWallet.derivationPath,
|
|
84
|
+
},
|
|
85
|
+
]
|
|
86
|
+
: undefined;
|
|
87
|
+
await trackConnection(connect(wallet.type, namespaces), {
|
|
88
|
+
trigger: 'swap-details-modal',
|
|
89
|
+
source: 'user',
|
|
90
|
+
walletType: wallet.type,
|
|
91
|
+
namespaces: namespaces?.map((item) => item.namespace),
|
|
92
|
+
});
|
|
91
93
|
} catch (error) {
|
|
92
|
-
setError(error as Error);
|
|
94
|
+
setError(tryRefineError(error) ?? (error as Error));
|
|
93
95
|
}
|
|
94
96
|
};
|
|
95
97
|
|
|
@@ -106,9 +108,7 @@ export const ConnectWalletContent = (props: ConnectWalletContentProps) => {
|
|
|
106
108
|
if (!connected) {
|
|
107
109
|
return null;
|
|
108
110
|
}
|
|
109
|
-
const firstAccountArray =
|
|
110
|
-
? namespaceState?.accounts?.[0]?.split(':')
|
|
111
|
-
: walletState?.accounts?.[0]?.split(':');
|
|
111
|
+
const firstAccountArray = namespaceState?.accounts?.[0]?.split(':');
|
|
112
112
|
const address = firstAccountArray?.[firstAccountArray?.length - 1];
|
|
113
113
|
|
|
114
114
|
if (!address) {
|
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
import type { InstallWalletContentProps } from './SwapDetailsModal.types';
|
|
2
2
|
|
|
3
3
|
import { i18n } from '@lingui/core';
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
Button,
|
|
6
|
+
detectInstallLink,
|
|
7
|
+
Divider,
|
|
8
|
+
Image,
|
|
9
|
+
MessageBox,
|
|
10
|
+
WarningIcon,
|
|
11
|
+
} from '@rango-dev/ui';
|
|
5
12
|
import { useWallets } from '@rango-dev/wallets-react';
|
|
6
|
-
import { detectInstallLink } from '@rango-dev/wallets-shared';
|
|
7
13
|
import React from 'react';
|
|
8
14
|
|
|
9
15
|
import {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import type { WalletType } from '@hub3js/core';
|
|
1
2
|
import type { TargetNamespace } from '@rango-dev/queue-manager-rango-preset';
|
|
2
|
-
import type { LegacyWalletType } from '@rango-dev/wallets-core/legacy';
|
|
3
3
|
import type { PendingSwap } from 'rango-types';
|
|
4
4
|
|
|
5
5
|
export type ModalState =
|
|
@@ -60,12 +60,12 @@ export interface NetworkStateContentProps {
|
|
|
60
60
|
}
|
|
61
61
|
|
|
62
62
|
export interface InstallWalletContentProps {
|
|
63
|
-
walletType:
|
|
63
|
+
walletType: WalletType;
|
|
64
64
|
}
|
|
65
65
|
|
|
66
66
|
export interface ConnectWalletContentProps {
|
|
67
67
|
wallet: {
|
|
68
|
-
walletType:
|
|
68
|
+
walletType: WalletType;
|
|
69
69
|
address: string;
|
|
70
70
|
derivationPath?: string;
|
|
71
71
|
};
|
|
@@ -8,9 +8,9 @@ import { End, List } from './TokenList.styles';
|
|
|
8
8
|
export function LoadingTokenList(props: LoadingTokenListProps) {
|
|
9
9
|
return (
|
|
10
10
|
<List>
|
|
11
|
-
{Array.from(Array(props.size), (
|
|
11
|
+
{Array.from(Array(props.size), (_, index) => (
|
|
12
12
|
<ListItem
|
|
13
|
-
key={
|
|
13
|
+
key={index}
|
|
14
14
|
hasDivider
|
|
15
15
|
start={<Skeleton variant="circular" width={35} height={35} />}
|
|
16
16
|
end={
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import type { DerivationPathTemplate } from './DerivationPath.helpers';
|
|
2
|
+
|
|
3
|
+
import { describe, expect, it } from 'vitest';
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
CUSTOM_DERIVATION_PATH,
|
|
7
|
+
getDerivationPaths,
|
|
8
|
+
} from './DerivationPath.helpers';
|
|
9
|
+
|
|
10
|
+
const LEDGER: DerivationPathTemplate[] = [
|
|
11
|
+
{
|
|
12
|
+
id: 'metamask',
|
|
13
|
+
label: `Metamask (m/44'/60'/0'/0/index)`,
|
|
14
|
+
namespace: 'EVM',
|
|
15
|
+
generateDerivationPath: (index) => `44'/60'/0'/0/${index}`,
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
id: 'ledgerLive',
|
|
19
|
+
label: `LedgerLive (m/44'/60'/index'/0/0)`,
|
|
20
|
+
namespace: 'EVM',
|
|
21
|
+
generateDerivationPath: (index) => `44'/60'/${index}'/0/0`,
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
id: 'legacy',
|
|
25
|
+
label: `Legacy (m/44'/60'/0'/index)`,
|
|
26
|
+
namespace: 'EVM',
|
|
27
|
+
generateDerivationPath: (index) => `44'/60'/0'/${index}`,
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
id: `(m/44'/501'/index')`,
|
|
31
|
+
label: `(m/44'/501'/index')`,
|
|
32
|
+
namespace: 'Solana',
|
|
33
|
+
generateDerivationPath: (index) => `44'/501'/${index}'`,
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
id: `(m/44'/501'/0'/index)`,
|
|
37
|
+
label: `(m/44'/501'/0'/index)`,
|
|
38
|
+
namespace: 'Solana',
|
|
39
|
+
generateDerivationPath: (index) => `44'/501'/0'/${index}`,
|
|
40
|
+
},
|
|
41
|
+
];
|
|
42
|
+
|
|
43
|
+
const TREZOR_UTXO: DerivationPathTemplate[] = [
|
|
44
|
+
{
|
|
45
|
+
id: 'bitcoin-native-segwit',
|
|
46
|
+
label: `Native SegWit (m/84'/0'/index')`,
|
|
47
|
+
namespace: 'UTXO',
|
|
48
|
+
generateDerivationPath: (index) => `84'/0'/${index}'/0/0`,
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
id: 'bitcoin-taproot',
|
|
52
|
+
label: `Taproot (m/86'/0'/index')`,
|
|
53
|
+
namespace: 'UTXO',
|
|
54
|
+
generateDerivationPath: (index) => `86'/0'/${index}'/0/0`,
|
|
55
|
+
},
|
|
56
|
+
];
|
|
57
|
+
|
|
58
|
+
describe('getDerivationPaths', () => {
|
|
59
|
+
it('returns only the templates of the selected namespace', () => {
|
|
60
|
+
expect(getDerivationPaths(LEDGER, 'EVM').map((path) => path.id)).toEqual([
|
|
61
|
+
'metamask',
|
|
62
|
+
'ledgerLive',
|
|
63
|
+
'legacy',
|
|
64
|
+
CUSTOM_DERIVATION_PATH.id,
|
|
65
|
+
]);
|
|
66
|
+
|
|
67
|
+
expect(getDerivationPaths(LEDGER, 'Solana').map((path) => path.id)).toEqual(
|
|
68
|
+
[
|
|
69
|
+
`(m/44'/501'/index')`,
|
|
70
|
+
`(m/44'/501'/0'/index)`,
|
|
71
|
+
CUSTOM_DERIVATION_PATH.id,
|
|
72
|
+
]
|
|
73
|
+
);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it('appends the custom template so a user can enter a full path', () => {
|
|
77
|
+
const paths = getDerivationPaths(TREZOR_UTXO, 'UTXO');
|
|
78
|
+
|
|
79
|
+
expect(paths.at(-1)).toBe(CUSTOM_DERIVATION_PATH);
|
|
80
|
+
expect(CUSTOM_DERIVATION_PATH.generateDerivationPath(`84'/0'/3'/0/0`)).toBe(
|
|
81
|
+
`84'/0'/3'/0/0`
|
|
82
|
+
);
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it('generates the path the wallet expects for the picked index', () => {
|
|
86
|
+
const evm = getDerivationPaths(LEDGER, 'EVM');
|
|
87
|
+
const utxo = getDerivationPaths(TREZOR_UTXO, 'UTXO');
|
|
88
|
+
|
|
89
|
+
expect(evm[0]?.generateDerivationPath('2')).toBe(`44'/60'/0'/0/2`);
|
|
90
|
+
expect(evm[1]?.generateDerivationPath('2')).toBe(`44'/60'/2'/0/0`);
|
|
91
|
+
expect(utxo[0]?.generateDerivationPath('2')).toBe(`84'/0'/2'/0/0`);
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
it('returns nothing when the provider declares no template for the namespace', () => {
|
|
95
|
+
expect(getDerivationPaths(LEDGER, 'UTXO')).toEqual([]);
|
|
96
|
+
expect(getDerivationPaths([], 'EVM')).toEqual([]);
|
|
97
|
+
});
|
|
98
|
+
});
|
|
@@ -1,24 +1,28 @@
|
|
|
1
|
+
import type { ProviderProperty } from '@hub3js/core/store';
|
|
1
2
|
import type { Namespace } from '@hub3js/namespaces';
|
|
2
|
-
import type { DerivationPath } from '@rango-dev/wallets-shared';
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
export type DerivationPathTemplate = Extract<
|
|
5
|
+
ProviderProperty,
|
|
6
|
+
{ name: 'derivationPath' }
|
|
7
|
+
>['value']['data'][number];
|
|
5
8
|
|
|
6
|
-
export
|
|
9
|
+
export type DerivationPathOption = Omit<DerivationPathTemplate, 'namespace'>;
|
|
10
|
+
|
|
11
|
+
export const CUSTOM_DERIVATION_PATH: DerivationPathOption = {
|
|
7
12
|
id: 'custom',
|
|
8
13
|
label: 'Custom',
|
|
9
14
|
generateDerivationPath: (index: string) => index,
|
|
10
15
|
};
|
|
11
16
|
|
|
12
17
|
export function getDerivationPaths(
|
|
18
|
+
derivationPaths: DerivationPathTemplate[],
|
|
13
19
|
selectedNamespace?: Namespace
|
|
14
|
-
):
|
|
15
|
-
const selectedNamespaceDerivationPaths =
|
|
16
|
-
|
|
17
|
-
|
|
20
|
+
): DerivationPathOption[] {
|
|
21
|
+
const selectedNamespaceDerivationPaths = derivationPaths.filter(
|
|
22
|
+
(derivationPath) => derivationPath.namespace === selectedNamespace
|
|
23
|
+
);
|
|
18
24
|
|
|
19
|
-
|
|
25
|
+
return selectedNamespaceDerivationPaths.length
|
|
20
26
|
? [...selectedNamespaceDerivationPaths, CUSTOM_DERIVATION_PATH]
|
|
21
27
|
: [];
|
|
22
|
-
|
|
23
|
-
return derivationPaths;
|
|
24
28
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { PropTypes } from './DerivationPath.types';
|
|
2
|
-
import type { DerivationPath } from '@rango-dev/wallets-shared';
|
|
3
2
|
|
|
4
3
|
import { i18n } from '@lingui/core';
|
|
5
4
|
import { Divider, Image, MessageBox, Select, TextField } from '@rango-dev/ui';
|
|
6
|
-
import
|
|
5
|
+
import { useWallets } from '@rango-dev/wallets-react';
|
|
6
|
+
import React, { useEffect, useMemo, useState } from 'react';
|
|
7
7
|
|
|
8
8
|
import {
|
|
9
9
|
CUSTOM_DERIVATION_PATH,
|
|
@@ -26,6 +26,8 @@ export function DerivationPath(props: PropTypes) {
|
|
|
26
26
|
providerType: type,
|
|
27
27
|
} = props.value;
|
|
28
28
|
|
|
29
|
+
const { getWalletInfo } = useWallets();
|
|
30
|
+
|
|
29
31
|
const [selectedDerivationPathId, setSelectedDerivationPathId] = useState<
|
|
30
32
|
string | null
|
|
31
33
|
>(null);
|
|
@@ -36,7 +38,14 @@ export function DerivationPath(props: PropTypes) {
|
|
|
36
38
|
const isCustomOptionSelected =
|
|
37
39
|
selectedDerivationPathId === CUSTOM_DERIVATION_PATH.id;
|
|
38
40
|
|
|
39
|
-
const derivationPaths =
|
|
41
|
+
const derivationPaths = useMemo(
|
|
42
|
+
() =>
|
|
43
|
+
getDerivationPaths(
|
|
44
|
+
getWalletInfo(type).needsDerivationPath?.data ?? [],
|
|
45
|
+
selectedNamespace
|
|
46
|
+
),
|
|
47
|
+
[type, selectedNamespace]
|
|
48
|
+
);
|
|
40
49
|
|
|
41
50
|
const handleDerivationPathItemClick = ({ value }: { value: string }) => {
|
|
42
51
|
const selectedDerivationPath = derivationPaths?.find(
|
|
@@ -75,10 +84,8 @@ export function DerivationPath(props: PropTypes) {
|
|
|
75
84
|
};
|
|
76
85
|
|
|
77
86
|
useEffect(() => {
|
|
78
|
-
setSelectedDerivationPathId(
|
|
79
|
-
|
|
80
|
-
);
|
|
81
|
-
}, [selectedNamespace]);
|
|
87
|
+
setSelectedDerivationPathId(derivationPaths[0]?.id || null);
|
|
88
|
+
}, [derivationPaths]);
|
|
82
89
|
|
|
83
90
|
return (
|
|
84
91
|
<>
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { PropTypes } from './Detached.types';
|
|
2
2
|
import type { Namespace } from '@hub3js/namespaces';
|
|
3
|
-
import type {
|
|
3
|
+
import type { NamespaceMeta } from '@rango-dev/wallets-react';
|
|
4
4
|
|
|
5
5
|
import { i18n } from '@lingui/core';
|
|
6
6
|
import {
|
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
import { useWallets } from '@rango-dev/wallets-react';
|
|
15
15
|
import React from 'react';
|
|
16
16
|
|
|
17
|
+
import { trackConnection } from '../../utils/connectionReporting';
|
|
17
18
|
import { NamespaceUnsupportedItem } from '../NamespaceItem/NamespaceUnsupportedItem';
|
|
18
19
|
|
|
19
20
|
import { NamespacesHeader } from './Detached.styles';
|
|
@@ -57,13 +58,21 @@ export function Detached(props: PropTypes) {
|
|
|
57
58
|
if (derivationPathProperty && options?.shouldAskForDerivationPath) {
|
|
58
59
|
navigateToDerivationPath(namespace);
|
|
59
60
|
} else {
|
|
60
|
-
await
|
|
61
|
+
await trackConnection(
|
|
62
|
+
connect(walletType, [
|
|
63
|
+
{
|
|
64
|
+
namespace: namespace,
|
|
65
|
+
network: '',
|
|
66
|
+
derivationPath: options?.derivationPath ?? undefined,
|
|
67
|
+
},
|
|
68
|
+
]),
|
|
61
69
|
{
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
70
|
+
trigger: 'wallet-modal-namespace',
|
|
71
|
+
source: 'user',
|
|
72
|
+
walletType,
|
|
73
|
+
namespaces: [namespace],
|
|
74
|
+
}
|
|
75
|
+
);
|
|
67
76
|
}
|
|
68
77
|
};
|
|
69
78
|
|
|
@@ -119,7 +128,7 @@ export function Detached(props: PropTypes) {
|
|
|
119
128
|
);
|
|
120
129
|
};
|
|
121
130
|
|
|
122
|
-
const renderNamespaceItem = (namespace:
|
|
131
|
+
const renderNamespaceItem = (namespace: NamespaceMeta) => {
|
|
123
132
|
if (namespace.unsupported) {
|
|
124
133
|
return <NamespaceUnsupportedItem namespace={namespace} />;
|
|
125
134
|
}
|
|
@@ -4,6 +4,7 @@ import { i18n } from '@lingui/core';
|
|
|
4
4
|
import { Button, Spinner } from '@rango-dev/ui';
|
|
5
5
|
import React, { useLayoutEffect, useRef, useState } from 'react';
|
|
6
6
|
|
|
7
|
+
import { tryRefineError } from '../../utils/errors';
|
|
7
8
|
import { getConciseAddress } from '../../utils/wallets';
|
|
8
9
|
import { NamespaceItem } from '../NamespaceItem';
|
|
9
10
|
|
|
@@ -39,7 +40,7 @@ export function NamespaceDetachedItem(props: NamespaceDetachedItemPropTypes) {
|
|
|
39
40
|
processingConnectAttempt.current = true;
|
|
40
41
|
await handleConnect(options);
|
|
41
42
|
} catch (error) {
|
|
42
|
-
setError(error as Error);
|
|
43
|
+
setError(tryRefineError(error) ?? (error as Error));
|
|
43
44
|
} finally {
|
|
44
45
|
processingConnectAttempt.current = false;
|
|
45
46
|
}
|
|
@@ -2,6 +2,7 @@ import type { PropTypes } from './Namespaces.types';
|
|
|
2
2
|
import type { Namespace } from '@hub3js/namespaces';
|
|
3
3
|
|
|
4
4
|
import { i18n } from '@lingui/core';
|
|
5
|
+
import { getSupportedChainsFromNamespace } from '@rango-dev/internal-blockchains';
|
|
5
6
|
import {
|
|
6
7
|
Alert,
|
|
7
8
|
Button,
|
|
@@ -24,13 +25,8 @@ export function Namespaces(props: PropTypes) {
|
|
|
24
25
|
const namespacesProperty = targetWallet.properties?.find(
|
|
25
26
|
(property) => property.name === 'namespaces'
|
|
26
27
|
);
|
|
27
|
-
const
|
|
28
|
-
const
|
|
29
|
-
? namespacesProperty?.value.selection === 'single'
|
|
30
|
-
: targetWallet.needsNamespace?.selection === 'single';
|
|
31
|
-
const needsNamespace = isHub
|
|
32
|
-
? namespacesProperty?.value
|
|
33
|
-
: targetWallet.needsNamespace;
|
|
28
|
+
const singleNamespace = namespacesProperty?.value.selection === 'single';
|
|
29
|
+
const needsNamespace = namespacesProperty?.value;
|
|
34
30
|
const providerImage = targetWallet.image;
|
|
35
31
|
|
|
36
32
|
const blockchains = useAppStore().blockchains();
|
|
@@ -83,11 +79,9 @@ export function Namespaces(props: PropTypes) {
|
|
|
83
79
|
if (!!props.value.defaultSelectedChains?.length) {
|
|
84
80
|
const namespacesContainingDefaultSelectedChains =
|
|
85
81
|
supportedNamespaces.filter((namespace) =>
|
|
86
|
-
namespace
|
|
87
|
-
.
|
|
88
|
-
|
|
89
|
-
props.value.defaultSelectedChains?.includes(chain.name)
|
|
90
|
-
)
|
|
82
|
+
getSupportedChainsFromNamespace(namespace, blockchains).some(
|
|
83
|
+
(chain) => props.value.defaultSelectedChains?.includes(chain.name)
|
|
84
|
+
)
|
|
91
85
|
);
|
|
92
86
|
setSelectedNamespaces(
|
|
93
87
|
namespacesContainingDefaultSelectedChains.map(
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { NeedsNamespacesState } from '../../hooks/useStatefulConnect';
|
|
2
2
|
import type { NamespaceData } from '@hub3js/core/store';
|
|
3
3
|
import type { Namespace } from '@hub3js/namespaces';
|
|
4
|
-
import type {
|
|
4
|
+
import type { NamespaceMeta } from '@rango-dev/wallets-react';
|
|
5
5
|
|
|
6
6
|
export interface PropTypes {
|
|
7
7
|
onConfirm: (namespaces: Namespace[]) => void;
|
|
@@ -11,7 +11,7 @@ export interface PropTypes {
|
|
|
11
11
|
interface NamespaceItemSharedPropTypes {
|
|
12
12
|
onClick: () => void;
|
|
13
13
|
type: 'radio' | 'checkbox';
|
|
14
|
-
namespace:
|
|
14
|
+
namespace: NamespaceMeta;
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
interface RadioNamespaceItemPropTypes extends NamespaceItemSharedPropTypes {
|
|
@@ -28,7 +28,7 @@ export type NamespaceItemPropTypes =
|
|
|
28
28
|
| CheckboxNamespaceItemPropTypes;
|
|
29
29
|
|
|
30
30
|
export type NamespaceDetachedItemPropTypes = {
|
|
31
|
-
namespace:
|
|
31
|
+
namespace: NamespaceMeta;
|
|
32
32
|
state: NamespaceData;
|
|
33
33
|
initialConnect?: boolean;
|
|
34
34
|
disabled?: boolean;
|
package/src/constants/errors.ts
CHANGED
|
@@ -7,6 +7,9 @@ import { QuoteErrorType } from '../types';
|
|
|
7
7
|
export const errorMessages = () => {
|
|
8
8
|
return {
|
|
9
9
|
genericServerError: i18n.t('Failed Network, Please retry your swap.'),
|
|
10
|
+
moduleLoadError: i18n.t(
|
|
11
|
+
'A network error occurred while processing your request. Please check your internet connection or refresh the page and try again.'
|
|
12
|
+
),
|
|
10
13
|
liquiditySourcesError: {
|
|
11
14
|
title: i18n.t('Please reset your liquidity sources.'),
|
|
12
15
|
description: i18n.t(
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { OnUpdateState } from './Wallets.types';
|
|
2
|
-
import type {
|
|
2
|
+
import type { EventHandler } from '@rango-dev/wallets-react';
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import { Events } from '@rango-dev/wallets-react';
|
|
5
5
|
|
|
6
6
|
/*
|
|
7
7
|
* propagate updates for Dapps using external wallets
|
|
@@ -10,7 +10,7 @@ import { LegacyEvents } from '@rango-dev/wallets-core/legacy';
|
|
|
10
10
|
*/
|
|
11
11
|
export function propagateEvents(
|
|
12
12
|
cb: OnUpdateState,
|
|
13
|
-
eventParams: Parameters<
|
|
13
|
+
eventParams: Parameters<EventHandler>
|
|
14
14
|
): void {
|
|
15
15
|
const [walletType, event, value, coreState, info] = eventParams;
|
|
16
16
|
|
|
@@ -18,7 +18,7 @@ export function propagateEvents(
|
|
|
18
18
|
* PROVIDER_DISCONNECTED has conflict with WalletEventTypes.DISCONNECT since they are doing samething, the first one is using only for Hub, the second one is what we exposed to the lib users.
|
|
19
19
|
* so for backward-compat we need to keep the behavior of WalletEventTypes.DISCONNECT
|
|
20
20
|
*/
|
|
21
|
-
if (event ===
|
|
21
|
+
if (event === Events.PROVIDER_DISCONNECTED) {
|
|
22
22
|
return;
|
|
23
23
|
}
|
|
24
24
|
|
|
@@ -5,11 +5,11 @@ import type {
|
|
|
5
5
|
WidgetContextInterface,
|
|
6
6
|
} from './Wallets.types';
|
|
7
7
|
import type { ProvidersOptions } from '../../utils/providers';
|
|
8
|
-
import type {
|
|
8
|
+
import type { EventHandler } from '@rango-dev/wallets-react';
|
|
9
9
|
import type { PropsWithChildren } from 'react';
|
|
10
10
|
|
|
11
|
+
import { WalletTypes } from '@rango-dev/provider-all';
|
|
11
12
|
import { Provider } from '@rango-dev/wallets-react';
|
|
12
|
-
import { WalletTypes } from '@rango-dev/wallets-shared';
|
|
13
13
|
import React, { createContext, useEffect, useMemo, useRef } from 'react';
|
|
14
14
|
|
|
15
15
|
import { useWalletProviders } from '../../hooks/useWalletProviders';
|
|
@@ -89,7 +89,7 @@ function Main(props: PropsWithChildren<PropTypes>) {
|
|
|
89
89
|
allBlockChains={blockchains}
|
|
90
90
|
providers={providers}
|
|
91
91
|
onUpdateState={(type, event, value, state, info) => {
|
|
92
|
-
const eventParams: Parameters<
|
|
92
|
+
const eventParams: Parameters<EventHandler> = [
|
|
93
93
|
type,
|
|
94
94
|
event,
|
|
95
95
|
value,
|
|
@@ -109,9 +109,26 @@ function Main(props: PropsWithChildren<PropTypes>) {
|
|
|
109
109
|
[WalletTypes.TON_CONNECT]: {
|
|
110
110
|
provider: { manifestUrl: config.tonConnect?.manifestUrl },
|
|
111
111
|
},
|
|
112
|
+
[WalletTypes.OKX]: {
|
|
113
|
+
provider: {
|
|
114
|
+
tonConnectManifestUrl: config.tonConnect?.manifestUrl,
|
|
115
|
+
},
|
|
116
|
+
},
|
|
112
117
|
[WalletTypes.TREZOR]: {
|
|
113
118
|
provider: { manifest: config.trezorManifest },
|
|
114
119
|
},
|
|
120
|
+
[WalletTypes.WALLET_CONNECT_2]: {
|
|
121
|
+
provider: {
|
|
122
|
+
WC_PROJECT_ID: config.walletConnectProjectId || '',
|
|
123
|
+
DISABLE_MODAL_AND_OPEN_LINK:
|
|
124
|
+
config.__UNSTABLE_OR_INTERNAL__
|
|
125
|
+
?.walletConnectListedDesktopWalletLink,
|
|
126
|
+
meta: blockchains,
|
|
127
|
+
},
|
|
128
|
+
},
|
|
129
|
+
[WalletTypes.LEDGER_WALLET]: {
|
|
130
|
+
provider: config.ledgerWallet,
|
|
131
|
+
},
|
|
115
132
|
},
|
|
116
133
|
}}>
|
|
117
134
|
{props.children}
|