@rango-dev/widget-embedded 0.0.0-experimental-1624fbb4-20260708 → 0.0.0-experimental-99f1781b-20260920
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 +2 -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/Detached.types.d.ts +2 -1
- package/dist/components/WalletStatefulConnect/Detached.types.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.constants.d.ts +3 -0
- package/dist/containers/Wallets/Wallets.constants.d.ts.map +1 -0
- 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.helpers.test.d.ts +2 -0
- package/dist/containers/Wallets/Wallets.helpers.test.d.ts.map +1 -0
- package/dist/containers/Wallets/Wallets.types.d.ts +6 -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/useConnectWithLogging/index.d.ts +2 -0
- package/dist/hooks/useConnectWithLogging/index.d.ts.map +1 -0
- package/dist/hooks/useConnectWithLogging/useConnectWithLogging.d.ts +11 -0
- package/dist/hooks/useConnectWithLogging/useConnectWithLogging.d.ts.map +1 -0
- package/dist/hooks/useConnectWithLogging/useConnectWithLogging.test.d.ts +2 -0
- package/dist/hooks/useConnectWithLogging/useConnectWithLogging.test.d.ts.map +1 -0
- 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 +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/libs/connectLogging/connectLogging.constants.d.ts +9 -0
- package/dist/libs/connectLogging/connectLogging.constants.d.ts.map +1 -0
- package/dist/libs/connectLogging/connectLogging.d.ts +12 -0
- package/dist/libs/connectLogging/connectLogging.d.ts.map +1 -0
- package/dist/libs/connectLogging/connectLogging.test.d.ts +2 -0
- package/dist/libs/connectLogging/connectLogging.test.d.ts.map +1 -0
- package/dist/libs/connectLogging/connectLogging.types.d.ts +57 -0
- package/dist/libs/connectLogging/connectLogging.types.d.ts.map +1 -0
- package/dist/libs/connectLogging/index.d.ts +3 -0
- package/dist/libs/connectLogging/index.d.ts.map +1 -0
- package/dist/pages/WalletsPage.d.ts.map +1 -1
- 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/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 -16
- package/src/components/ConfirmWalletsModal/WalletList.tsx +2 -2
- 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 +4 -2
- package/src/components/SwapDetails/SwapDetails.tsx +17 -8
- package/src/components/SwapDetailsModal/SwapDetailsModal.ConnectWallet.tsx +12 -13
- 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 -10
- package/src/components/WalletStatefulConnect/Detached.types.ts +2 -1
- 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.constants.ts +14 -0
- package/src/containers/Wallets/Wallets.helpers.test.ts +67 -0
- package/src/containers/Wallets/Wallets.helpers.ts +9 -9
- package/src/containers/Wallets/Wallets.tsx +20 -3
- package/src/containers/Wallets/Wallets.types.ts +7 -7
- package/src/containers/Wallets/useUpdates.ts +7 -117
- 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/useConnectWithLogging/index.ts +1 -0
- package/src/hooks/useConnectWithLogging/useConnectWithLogging.test.ts +138 -0
- package/src/hooks/useConnectWithLogging/useConnectWithLogging.ts +36 -0
- package/src/hooks/useStatefulConnect/useStatefulConnect.ts +36 -29
- 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/libs/connectLogging/connectLogging.constants.ts +17 -0
- package/src/libs/connectLogging/connectLogging.test.ts +918 -0
- package/src/libs/connectLogging/connectLogging.ts +359 -0
- package/src/libs/connectLogging/connectLogging.types.ts +70 -0
- package/src/libs/connectLogging/index.ts +5 -0
- package/src/pages/WalletsPage.tsx +1 -0
- 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/errors.test.ts +78 -0
- package/src/utils/errors.ts +69 -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
|
@@ -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(
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Events } from '@rango-dev/wallets-react';
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* Events the widget keeps to itself, never passed on to `onUpdateState`.
|
|
5
|
+
*
|
|
6
|
+
* 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.
|
|
7
|
+
* so for backward-compat we need to keep the behavior of WalletEventTypes.DISCONNECT
|
|
8
|
+
*
|
|
9
|
+
* AUTO_CONNECT_FAILED only exists so the widget can log it.
|
|
10
|
+
*/
|
|
11
|
+
export const INTERNAL_EVENTS = [
|
|
12
|
+
Events.PROVIDER_DISCONNECTED,
|
|
13
|
+
Events.AUTO_CONNECT_FAILED,
|
|
14
|
+
] as const;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import type { EventInfo, WalletState } from '@rango-dev/wallets-react';
|
|
2
|
+
|
|
3
|
+
import { AutoConnectionAttemptError, Events } from '@rango-dev/wallets-react';
|
|
4
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
5
|
+
|
|
6
|
+
import { propagateEvents } from './Wallets.helpers';
|
|
7
|
+
|
|
8
|
+
const CORE_STATE: WalletState = {
|
|
9
|
+
connected: false,
|
|
10
|
+
connecting: false,
|
|
11
|
+
reachable: false,
|
|
12
|
+
installed: true,
|
|
13
|
+
accounts: null,
|
|
14
|
+
network: null,
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const INFO: EventInfo = {
|
|
18
|
+
supportedBlockchains: [],
|
|
19
|
+
isContractWallet: false,
|
|
20
|
+
isHub: true,
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
describe('propagating events to the integrator', () => {
|
|
24
|
+
it('passes an event on, unchanged', () => {
|
|
25
|
+
const onUpdateState = vi.fn();
|
|
26
|
+
|
|
27
|
+
propagateEvents(onUpdateState, [
|
|
28
|
+
'metamask',
|
|
29
|
+
Events.CONNECTED,
|
|
30
|
+
true,
|
|
31
|
+
CORE_STATE,
|
|
32
|
+
INFO,
|
|
33
|
+
]);
|
|
34
|
+
|
|
35
|
+
expect(onUpdateState).toHaveBeenCalledWith(
|
|
36
|
+
'metamask',
|
|
37
|
+
Events.CONNECTED,
|
|
38
|
+
true,
|
|
39
|
+
CORE_STATE,
|
|
40
|
+
INFO
|
|
41
|
+
);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it('keeps provider disconnected and auto-connect failed events from the integrator', () => {
|
|
45
|
+
const onUpdateState = vi.fn();
|
|
46
|
+
|
|
47
|
+
propagateEvents(onUpdateState, [
|
|
48
|
+
'metamask',
|
|
49
|
+
Events.PROVIDER_DISCONNECTED,
|
|
50
|
+
undefined,
|
|
51
|
+
CORE_STATE,
|
|
52
|
+
INFO,
|
|
53
|
+
]);
|
|
54
|
+
propagateEvents(onUpdateState, [
|
|
55
|
+
'metamask',
|
|
56
|
+
Events.AUTO_CONNECT_FAILED,
|
|
57
|
+
new AutoConnectionAttemptError({
|
|
58
|
+
errors: [new Error('boom')],
|
|
59
|
+
requestedNamespaces: [{ namespace: 'EVM', network: undefined }],
|
|
60
|
+
}),
|
|
61
|
+
CORE_STATE,
|
|
62
|
+
INFO,
|
|
63
|
+
]);
|
|
64
|
+
|
|
65
|
+
expect(onUpdateState).not.toHaveBeenCalled();
|
|
66
|
+
});
|
|
67
|
+
});
|
|
@@ -1,7 +1,11 @@
|
|
|
1
|
-
import type { OnUpdateState } from './Wallets.types';
|
|
2
|
-
import type {
|
|
1
|
+
import type { InternalEvent, OnUpdateState } from './Wallets.types';
|
|
2
|
+
import type { EventHandler, Events } from '@rango-dev/wallets-react';
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import { INTERNAL_EVENTS } from './Wallets.constants';
|
|
5
|
+
|
|
6
|
+
function isInternalEvent(event: Events): event is InternalEvent {
|
|
7
|
+
return (INTERNAL_EVENTS as readonly Events[]).includes(event);
|
|
8
|
+
}
|
|
5
9
|
|
|
6
10
|
/*
|
|
7
11
|
* propagate updates for Dapps using external wallets
|
|
@@ -10,15 +14,11 @@ import { LegacyEvents } from '@rango-dev/wallets-core/legacy';
|
|
|
10
14
|
*/
|
|
11
15
|
export function propagateEvents(
|
|
12
16
|
cb: OnUpdateState,
|
|
13
|
-
eventParams: Parameters<
|
|
17
|
+
eventParams: Parameters<EventHandler>
|
|
14
18
|
): void {
|
|
15
19
|
const [walletType, event, value, coreState, info] = eventParams;
|
|
16
20
|
|
|
17
|
-
|
|
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
|
-
* so for backward-compat we need to keep the behavior of WalletEventTypes.DISCONNECT
|
|
20
|
-
*/
|
|
21
|
-
if (event === LegacyEvents.PROVIDER_DISCONNECTED) {
|
|
21
|
+
if (isInternalEvent(event)) {
|
|
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}
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { INTERNAL_EVENTS } from './Wallets.constants';
|
|
2
|
+
import type { WidgetConfigWithoutLegacyProviders } from '../../types';
|
|
2
3
|
import type { LastConnectedWallet } from '@rango-dev/queue-manager-rango-preset';
|
|
3
|
-
import type {
|
|
4
|
-
LegacyEventHandler as EventHandler,
|
|
5
|
-
LegacyEvents,
|
|
6
|
-
} from '@rango-dev/wallets-core/legacy';
|
|
4
|
+
import type { EventHandler, Events } from '@rango-dev/wallets-react';
|
|
7
5
|
|
|
8
6
|
export type OnWalletConnectHandler = (wallet: LastConnectedWallet) => void;
|
|
9
7
|
export type OnWalletDisconnectHandler = (walletType: string) => void;
|
|
@@ -22,8 +20,10 @@ export interface WidgetContextInterface {
|
|
|
22
20
|
onDisconnectWallet(handler: OnWalletDisconnectHandler): void;
|
|
23
21
|
}
|
|
24
22
|
|
|
23
|
+
export type InternalEvent = (typeof INTERNAL_EVENTS)[number];
|
|
24
|
+
|
|
25
25
|
type EventHandlerParams = Parameters<EventHandler>;
|
|
26
|
-
type EventParam = Exclude<
|
|
26
|
+
type EventParam = Exclude<Events, InternalEvent>;
|
|
27
27
|
|
|
28
28
|
export type OnUpdateState = (
|
|
29
29
|
type: EventHandlerParams[0],
|
|
@@ -35,5 +35,5 @@ export type OnUpdateState = (
|
|
|
35
35
|
|
|
36
36
|
export interface PropTypes {
|
|
37
37
|
onUpdateState?: OnUpdateState;
|
|
38
|
-
config:
|
|
38
|
+
config: WidgetConfigWithoutLegacyProviders;
|
|
39
39
|
}
|
|
@@ -2,20 +2,14 @@ import type {
|
|
|
2
2
|
OnWalletConnectHandler,
|
|
3
3
|
OnWalletDisconnectHandler,
|
|
4
4
|
} from './Wallets.types';
|
|
5
|
+
import type { Network } from '@rango-dev/internal-blockchains';
|
|
5
6
|
import type { LastConnectedWallet } from '@rango-dev/queue-manager-rango-preset';
|
|
6
|
-
import type {
|
|
7
|
-
LegacyEventHandler as EventHandler,
|
|
8
|
-
LegacyEventHandler,
|
|
9
|
-
} from '@rango-dev/wallets-core/legacy';
|
|
7
|
+
import type { EventHandler } from '@rango-dev/wallets-react';
|
|
10
8
|
|
|
11
|
-
import {
|
|
12
|
-
legacyFormatAddressWithNetwork as formatAddressWithNetwork,
|
|
13
|
-
legacyReadAccountAddress as readAccountAddress,
|
|
14
|
-
} from '@rango-dev/wallets-core/legacy';
|
|
15
9
|
import { Events } from '@rango-dev/wallets-react';
|
|
16
|
-
import { type Network } from '@rango-dev/wallets-shared';
|
|
17
10
|
import { isEvmBlockchain } from 'rango-sdk';
|
|
18
11
|
|
|
12
|
+
import { logAutoConnectFailure } from '../../libs/connectLogging';
|
|
19
13
|
import { useAppStore } from '../../store/AppStore';
|
|
20
14
|
import {
|
|
21
15
|
prepareAccountsForWalletStore,
|
|
@@ -39,8 +33,6 @@ export function useUpdates(params: UseUpdatesParams): UseUpdates {
|
|
|
39
33
|
newWalletConnected,
|
|
40
34
|
disconnectWallet,
|
|
41
35
|
disconnectNamespaces,
|
|
42
|
-
connectedWallets,
|
|
43
|
-
removeBalancesForWallet,
|
|
44
36
|
blockchains,
|
|
45
37
|
} = useAppStore();
|
|
46
38
|
|
|
@@ -50,7 +42,7 @@ export function useUpdates(params: UseUpdatesParams): UseUpdates {
|
|
|
50
42
|
.map((chain) => chain.name);
|
|
51
43
|
|
|
52
44
|
const onAccountsEvent = (
|
|
53
|
-
event: Parameters<
|
|
45
|
+
event: Parameters<EventHandler>,
|
|
54
46
|
params: {
|
|
55
47
|
supportedChainNames: Network[] | null;
|
|
56
48
|
}
|
|
@@ -83,13 +75,7 @@ export function useUpdates(params: UseUpdatesParams): UseUpdates {
|
|
|
83
75
|
}
|
|
84
76
|
};
|
|
85
77
|
|
|
86
|
-
const
|
|
87
|
-
type,
|
|
88
|
-
event,
|
|
89
|
-
value,
|
|
90
|
-
state,
|
|
91
|
-
info
|
|
92
|
-
) => {
|
|
78
|
+
const handler: EventHandler = (type, event, value, state, info) => {
|
|
93
79
|
if (event === Events.ACCOUNTS) {
|
|
94
80
|
const supportedChainNames: Network[] | null =
|
|
95
81
|
walletAndSupportedChainsNames(info.supportedBlockchains);
|
|
@@ -116,97 +102,11 @@ export function useUpdates(params: UseUpdatesParams): UseUpdates {
|
|
|
116
102
|
if (event === Events.NAMESPACE_DISCONNECTED) {
|
|
117
103
|
disconnectNamespaces(type, value);
|
|
118
104
|
}
|
|
119
|
-
};
|
|
120
|
-
|
|
121
|
-
const handleUpdatesForLegacy: EventHandler = (
|
|
122
|
-
type,
|
|
123
|
-
event,
|
|
124
|
-
value,
|
|
125
|
-
state,
|
|
126
|
-
info
|
|
127
|
-
) => {
|
|
128
|
-
if (event === Events.ACCOUNTS) {
|
|
129
|
-
const supportedChainNames: Network[] | null =
|
|
130
|
-
walletAndSupportedChainsNames(info.supportedBlockchains);
|
|
131
|
-
|
|
132
|
-
/*
|
|
133
|
-
* When a wallet is connecting to an evm account, we will consider it as the account exists on other evm-compatible blockchains
|
|
134
|
-
* To get their balances.
|
|
135
|
-
*
|
|
136
|
-
* The logic here is for handling switching account functionality in wallets. when a wallet is switching to another account
|
|
137
|
-
* we need to clean the balances for old accounts.
|
|
138
|
-
*
|
|
139
|
-
* Note: hub will do the cleanup on namespace diconnected event.
|
|
140
|
-
*/
|
|
141
|
-
const evmAccounts: string[] = [];
|
|
142
|
-
const nonEvmAccounts: string[] = [];
|
|
143
|
-
|
|
144
|
-
value?.forEach((account: string) => {
|
|
145
|
-
const { network } = readAccountAddress(account);
|
|
146
|
-
if (evmBasedChainNames.includes(network)) {
|
|
147
|
-
evmAccounts.push(account);
|
|
148
|
-
} else {
|
|
149
|
-
nonEvmAccounts.push(account);
|
|
150
|
-
}
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
const previousAccounts = connectedWallets
|
|
154
|
-
.filter((wallet) => wallet.walletType === type)
|
|
155
|
-
.map((wallet) =>
|
|
156
|
-
formatAddressWithNetwork(wallet.address, wallet.chain)
|
|
157
|
-
);
|
|
158
|
-
|
|
159
|
-
if (previousAccounts.length > 0) {
|
|
160
|
-
if (evmAccounts.length > 0) {
|
|
161
|
-
// We use same logic for removing as we use for adding.
|
|
162
|
-
const data = prepareAccountsForWalletStore(
|
|
163
|
-
type,
|
|
164
|
-
evmAccounts,
|
|
165
|
-
evmBasedChainNames,
|
|
166
|
-
supportedChainNames,
|
|
167
|
-
info.isContractWallet
|
|
168
|
-
);
|
|
169
|
-
|
|
170
|
-
removeBalancesForWallet(type, {
|
|
171
|
-
chains: data.map((account) => account.chain),
|
|
172
|
-
});
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
if (nonEvmAccounts.length > 0) {
|
|
176
|
-
removeBalancesForWallet(type, {
|
|
177
|
-
chains: nonEvmAccounts.map((account) => {
|
|
178
|
-
const { network } = readAccountAddress(account);
|
|
179
|
-
return network;
|
|
180
|
-
}),
|
|
181
|
-
});
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
105
|
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
onAccountsEvent([type, event, value, state, info], {
|
|
188
|
-
supportedChainNames,
|
|
189
|
-
});
|
|
190
|
-
} else {
|
|
191
|
-
disconnectWallet(type);
|
|
192
|
-
if (!!onDisconnectWalletHandler.current) {
|
|
193
|
-
onDisconnectWalletHandler.current(type);
|
|
194
|
-
} else {
|
|
195
|
-
console.warn(
|
|
196
|
-
`onDisconnectWallet handler hasn't been set. Are you sure?`
|
|
197
|
-
);
|
|
198
|
-
}
|
|
199
|
-
}
|
|
106
|
+
if (event === Events.AUTO_CONNECT_FAILED) {
|
|
107
|
+
logAutoConnectFailure(type, value);
|
|
200
108
|
}
|
|
201
|
-
};
|
|
202
109
|
|
|
203
|
-
const handleUpdatesForBoth: EventHandler = (
|
|
204
|
-
type,
|
|
205
|
-
event,
|
|
206
|
-
value,
|
|
207
|
-
state,
|
|
208
|
-
_info
|
|
209
|
-
) => {
|
|
210
110
|
if (event === Events.CONNECTED && value) {
|
|
211
111
|
const walletFromEvent: LastConnectedWallet = {
|
|
212
112
|
walletType: type,
|
|
@@ -234,16 +134,6 @@ export function useUpdates(params: UseUpdatesParams): UseUpdates {
|
|
|
234
134
|
}
|
|
235
135
|
};
|
|
236
136
|
|
|
237
|
-
const handler: EventHandler = (type, event, value, state, info) => {
|
|
238
|
-
if (info.isHub) {
|
|
239
|
-
handleUpdatesForHub(type, event, value, state, info);
|
|
240
|
-
} else {
|
|
241
|
-
handleUpdatesForLegacy(type, event, value, state, info);
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
handleUpdatesForBoth(type, event, value, state, info);
|
|
245
|
-
};
|
|
246
|
-
|
|
247
137
|
return {
|
|
248
138
|
handler,
|
|
249
139
|
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { WalletType } from '@hub3js/core';
|
|
2
|
+
import type { ProviderInterface } from '@rango-dev/wallets-react';
|
|
3
|
+
|
|
4
|
+
import { Provider } from '@hub3js/core';
|
|
5
|
+
|
|
6
|
+
export function isHubWallet(
|
|
7
|
+
wallet: WalletType | ProviderInterface | Provider
|
|
8
|
+
): wallet is WalletType | Provider {
|
|
9
|
+
return typeof wallet === 'string' || wallet instanceof Provider;
|
|
10
|
+
}
|
|
@@ -13,9 +13,18 @@ import { getApiKeyFromEnvOrThrow } from '../../utils/env';
|
|
|
13
13
|
import { WidgetWallets } from '../Wallets';
|
|
14
14
|
import { WidgetInfo } from '../WidgetInfo';
|
|
15
15
|
|
|
16
|
+
import { isHubWallet } from './WidgetProvider.helpers';
|
|
17
|
+
|
|
16
18
|
export function WidgetProvider(props: PropsWithChildren<PropTypes>) {
|
|
17
19
|
const { onUpdateState, config } = props;
|
|
18
20
|
|
|
21
|
+
const wallets = config?.wallets;
|
|
22
|
+
if (wallets && !wallets.every(isHubWallet)) {
|
|
23
|
+
throw new Error(
|
|
24
|
+
"Legacy providers aren't supported anymore. Expected a provider with version '1.0.0'."
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
|
|
19
28
|
const fontFamily = props.config?.theme?.fontFamily;
|
|
20
29
|
|
|
21
30
|
const { fetchApiConfig } = useFetchApiConfig();
|
|
@@ -45,7 +54,9 @@ export function WidgetProvider(props: PropsWithChildren<PropTypes>) {
|
|
|
45
54
|
}, [props.config?.signers?.customSolanaRPC]);
|
|
46
55
|
|
|
47
56
|
return (
|
|
48
|
-
<WidgetWallets
|
|
57
|
+
<WidgetWallets
|
|
58
|
+
config={{ ...config, wallets }}
|
|
59
|
+
onUpdateState={onUpdateState}>
|
|
49
60
|
<QueueManager apiKey={config.apiKey}>
|
|
50
61
|
<WidgetInfo>{props.children}</WidgetInfo>
|
|
51
62
|
</QueueManager>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useConnectWithLogging } from './useConnectWithLogging';
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
ConnectResult,
|
|
3
|
+
NamespaceInputForConnect,
|
|
4
|
+
} from '@rango-dev/wallets-react';
|
|
5
|
+
|
|
6
|
+
import { WalletConnectionError } from '@hub3js/std/utils';
|
|
7
|
+
import { error as logError } from '@rango-dev/logging-core';
|
|
8
|
+
import { WalletConnectionAttemptError } from '@rango-dev/wallets-react';
|
|
9
|
+
import { createElement } from 'react';
|
|
10
|
+
import { renderToStaticMarkup } from 'react-dom/server';
|
|
11
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
12
|
+
|
|
13
|
+
import { useConnectWithLogging } from './useConnectWithLogging';
|
|
14
|
+
|
|
15
|
+
const { connect } = vi.hoisted(() => ({ connect: vi.fn() }));
|
|
16
|
+
|
|
17
|
+
vi.mock('@rango-dev/logging-core', () => ({ error: vi.fn() }));
|
|
18
|
+
vi.mock('@rango-dev/wallets-react', async (importOriginal) => ({
|
|
19
|
+
...(await importOriginal<Record<string, unknown>>()),
|
|
20
|
+
useWallets: () => ({ connect }),
|
|
21
|
+
}));
|
|
22
|
+
|
|
23
|
+
const loggedError = vi.mocked(logError);
|
|
24
|
+
|
|
25
|
+
const THREE_MINUTES = 180_000;
|
|
26
|
+
|
|
27
|
+
const NAMESPACES: NamespaceInputForConnect[] = [
|
|
28
|
+
{ namespace: 'EVM', network: undefined },
|
|
29
|
+
];
|
|
30
|
+
|
|
31
|
+
const CONNECTED: ConnectResult[] = [{ accounts: [], network: null }];
|
|
32
|
+
|
|
33
|
+
type ConnectWithLogging = ReturnType<typeof useConnectWithLogging>;
|
|
34
|
+
|
|
35
|
+
async function pending(): Promise<ConnectResult[]> {
|
|
36
|
+
return new Promise<ConnectResult[]>(() => undefined);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function failedAttempt(): WalletConnectionAttemptError {
|
|
40
|
+
return new WalletConnectionAttemptError({
|
|
41
|
+
errors: [
|
|
42
|
+
new WalletConnectionError({ namespace: 'EVM', cause: new Error('boom') }),
|
|
43
|
+
],
|
|
44
|
+
requestedNamespaces: NAMESPACES,
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function renderConnect(): ConnectWithLogging {
|
|
49
|
+
let rendered: ConnectWithLogging | undefined;
|
|
50
|
+
function Probe() {
|
|
51
|
+
rendered = useConnectWithLogging();
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
renderToStaticMarkup(createElement(Probe));
|
|
56
|
+
|
|
57
|
+
if (!rendered) {
|
|
58
|
+
throw new Error('The hook was not rendered.');
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return rendered;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
beforeEach(() => {
|
|
65
|
+
loggedError.mockReset();
|
|
66
|
+
connect.mockReset();
|
|
67
|
+
connect.mockResolvedValue(CONNECTED);
|
|
68
|
+
vi.useFakeTimers();
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
afterEach(() => {
|
|
72
|
+
vi.useRealTimers();
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
describe('connecting without a trigger', () => {
|
|
76
|
+
it('calls connect with the same wallet type and namespaces and resolves with its result', async () => {
|
|
77
|
+
await expect(renderConnect()('metamask', NAMESPACES)).resolves.toBe(
|
|
78
|
+
CONNECTED
|
|
79
|
+
);
|
|
80
|
+
|
|
81
|
+
expect(connect).toHaveBeenCalledWith('metamask', NAMESPACES);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it('logs nothing when the attempt fails and rethrows its error unchanged', async () => {
|
|
85
|
+
const received = failedAttempt();
|
|
86
|
+
connect.mockRejectedValue(received);
|
|
87
|
+
|
|
88
|
+
await expect(renderConnect()('metamask', NAMESPACES)).rejects.toBe(
|
|
89
|
+
received
|
|
90
|
+
);
|
|
91
|
+
|
|
92
|
+
expect(loggedError).not.toHaveBeenCalled();
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it('logs nothing when the attempt is still pending after three minutes', () => {
|
|
96
|
+
connect.mockReturnValue(pending());
|
|
97
|
+
|
|
98
|
+
void renderConnect()('metamask', NAMESPACES);
|
|
99
|
+
vi.advanceTimersByTime(THREE_MINUTES);
|
|
100
|
+
|
|
101
|
+
expect(loggedError).not.toHaveBeenCalled();
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
describe('connecting with a trigger', () => {
|
|
106
|
+
it('logs the error the attempt failed with, tagged with the trigger, and rethrows it unchanged', async () => {
|
|
107
|
+
const received = failedAttempt();
|
|
108
|
+
connect.mockRejectedValue(received);
|
|
109
|
+
|
|
110
|
+
await expect(
|
|
111
|
+
renderConnect()('metamask', NAMESPACES, {
|
|
112
|
+
trigger: 'swap-details-reconnect',
|
|
113
|
+
})
|
|
114
|
+
).rejects.toBe(received);
|
|
115
|
+
|
|
116
|
+
expect(connect).toHaveBeenCalledWith('metamask', NAMESPACES);
|
|
117
|
+
expect(loggedError).toHaveBeenCalledTimes(1);
|
|
118
|
+
expect(loggedError.mock.calls[0]?.[0]).toBe(received);
|
|
119
|
+
expect(loggedError.mock.calls[0]?.[1]?.tags).toEqual({
|
|
120
|
+
walletType: 'metamask',
|
|
121
|
+
namespaces: 'EVM',
|
|
122
|
+
trigger: 'swap-details-reconnect',
|
|
123
|
+
category: 'wallet',
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
it('logs a timeout when the attempt is still pending after three minutes', () => {
|
|
128
|
+
connect.mockReturnValue(pending());
|
|
129
|
+
|
|
130
|
+
void renderConnect()('metamask', NAMESPACES, { trigger: 'wallets-page' });
|
|
131
|
+
vi.advanceTimersByTime(THREE_MINUTES);
|
|
132
|
+
|
|
133
|
+
expect(loggedError).toHaveBeenCalledTimes(1);
|
|
134
|
+
expect(loggedError.mock.calls[0]?.[1]?.tags).toEqual(
|
|
135
|
+
expect.objectContaining({ trigger: 'wallets-page', category: 'timeout' })
|
|
136
|
+
);
|
|
137
|
+
});
|
|
138
|
+
});
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { WithConnectTrigger } from '../../libs/connectLogging';
|
|
2
|
+
import type { WalletType } from '@hub3js/core';
|
|
3
|
+
import type {
|
|
4
|
+
ConnectResult,
|
|
5
|
+
NamespaceInputForConnect,
|
|
6
|
+
} from '@rango-dev/wallets-react';
|
|
7
|
+
|
|
8
|
+
import { useWallets } from '@rango-dev/wallets-react';
|
|
9
|
+
|
|
10
|
+
import { runConnectWithLogging } from '../../libs/connectLogging';
|
|
11
|
+
|
|
12
|
+
type ConnectWithLogging = (
|
|
13
|
+
walletType: WalletType,
|
|
14
|
+
namespaces?: NamespaceInputForConnect[],
|
|
15
|
+
options?: WithConnectTrigger
|
|
16
|
+
) => Promise<ConnectResult[]>;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* `connect` from `useWallets`, logging the attempts that fail. Without a
|
|
20
|
+
* trigger it's `connect` itself: nothing is logged and no timer runs.
|
|
21
|
+
*/
|
|
22
|
+
export function useConnectWithLogging(): ConnectWithLogging {
|
|
23
|
+
const { connect } = useWallets();
|
|
24
|
+
|
|
25
|
+
return async (walletType, namespaces, options) => {
|
|
26
|
+
const trigger = options?.trigger;
|
|
27
|
+
if (!trigger) {
|
|
28
|
+
return connect(walletType, namespaces);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return runConnectWithLogging(
|
|
32
|
+
{ walletType, trigger, requestedNamespaces: namespaces ?? [] },
|
|
33
|
+
async () => connect(walletType, namespaces)
|
|
34
|
+
);
|
|
35
|
+
};
|
|
36
|
+
}
|