@rango-dev/widget-embedded 0.0.0-experimental-d66900c7-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/event.d.ts +1 -1
- package/dist/types/event.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 -8
- 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/store/slices/wallets.ts +1 -1
- package/src/test-utils/fixtures.ts +6 -2
- package/src/types/config.ts +31 -4
- package/src/types/event.ts +1 -1
- 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
|
@@ -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
|
+
}
|
|
@@ -1,14 +1,20 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type {
|
|
2
|
+
HandleConnectOptions,
|
|
3
|
+
NamespaceData,
|
|
4
|
+
Result,
|
|
5
|
+
} from './useStatefulConnect.types';
|
|
6
|
+
import type { WithConnectTrigger } from '../../libs/connectLogging';
|
|
2
7
|
import type { WalletInfoWithExtra } from '../../types';
|
|
3
8
|
import type { Namespace } from '@hub3js/namespaces';
|
|
4
|
-
import type { NamespaceData } from '@rango-dev/wallets-shared';
|
|
5
9
|
|
|
6
10
|
import { WalletState } from '@rango-dev/ui';
|
|
7
11
|
import { useWallets } from '@rango-dev/wallets-react';
|
|
8
12
|
import { useReducer } from 'react';
|
|
9
13
|
|
|
10
14
|
import { isOnDetached } from '../../components/StatefulConnectModal';
|
|
15
|
+
import { tryRefineErrorMessage } from '../../utils/errors';
|
|
11
16
|
import { type ExtendedModalWalletInfo } from '../../utils/wallets';
|
|
17
|
+
import { useConnectWithLogging } from '../useConnectWithLogging';
|
|
12
18
|
|
|
13
19
|
import {
|
|
14
20
|
isStateOnDerivationPathStep,
|
|
@@ -48,8 +54,11 @@ export interface UseStatefulConnect {
|
|
|
48
54
|
* or what derivation path should be used for.
|
|
49
55
|
*
|
|
50
56
|
*/
|
|
51
|
-
export function useStatefulConnect(
|
|
52
|
-
|
|
57
|
+
export function useStatefulConnect({
|
|
58
|
+
trigger,
|
|
59
|
+
}: WithConnectTrigger = {}): UseStatefulConnect {
|
|
60
|
+
const { state, disconnect } = useWallets();
|
|
61
|
+
const connect = useConnectWithLogging();
|
|
53
62
|
|
|
54
63
|
const [connectState, dispatch] = useReducer(reducer, initState);
|
|
55
64
|
|
|
@@ -71,13 +80,16 @@ export function useStatefulConnect(): UseStatefulConnect {
|
|
|
71
80
|
...namespaceInput,
|
|
72
81
|
network: undefined,
|
|
73
82
|
}));
|
|
74
|
-
await connect(wallet.type, legacyNamespacesInput);
|
|
83
|
+
await connect(wallet.type, legacyNamespacesInput, { trigger });
|
|
75
84
|
return { status: ResultStatus.Connected };
|
|
76
85
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
77
86
|
} catch (e: any) {
|
|
78
|
-
const message =
|
|
79
|
-
|
|
80
|
-
|
|
87
|
+
const message = tryRefineErrorMessage(
|
|
88
|
+
e,
|
|
89
|
+
e?.message
|
|
90
|
+
? `Error: ${e.message}`
|
|
91
|
+
: 'An unknown error happened during connecting wallet.'
|
|
92
|
+
);
|
|
81
93
|
|
|
82
94
|
if (options?.disconnectOnError) {
|
|
83
95
|
try {
|
|
@@ -110,16 +122,13 @@ export function useStatefulConnect(): UseStatefulConnect {
|
|
|
110
122
|
* 3. Target wallet contains only one namespace, in this situation we should check if that namespace needs derivation path and based on that, try to connect to the related provider or display derivation path modal.
|
|
111
123
|
*/
|
|
112
124
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
? wallet.properties?.find((item) => item.name === 'namespaces')?.value
|
|
117
|
-
: wallet.needsNamespace;
|
|
125
|
+
const needsNamespace = wallet.properties?.find(
|
|
126
|
+
(item) => item.name === 'namespaces'
|
|
127
|
+
)?.value;
|
|
118
128
|
|
|
119
|
-
const needsDerivationPath =
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
: wallet.needsDerivationPath;
|
|
129
|
+
const needsDerivationPath = wallet.properties?.find(
|
|
130
|
+
(item) => item.name === 'derivationPath'
|
|
131
|
+
)?.value;
|
|
123
132
|
|
|
124
133
|
// Forced namespaces are used to bypass namespace selection flow.
|
|
125
134
|
if (forceConnectToNamespaces) {
|
|
@@ -209,7 +218,7 @@ export function useStatefulConnect(): UseStatefulConnect {
|
|
|
209
218
|
* and forced namespaces are not enabled,
|
|
210
219
|
* we should display detached modal
|
|
211
220
|
*/
|
|
212
|
-
if (
|
|
221
|
+
if (!options?.forceConnectToNamespaces) {
|
|
213
222
|
const needsNamespace = wallet.properties?.find(
|
|
214
223
|
(item) => item.name === 'namespaces'
|
|
215
224
|
)?.value;
|
|
@@ -237,14 +246,13 @@ export function useStatefulConnect(): UseStatefulConnect {
|
|
|
237
246
|
wallet: ExtendedModalWalletInfo,
|
|
238
247
|
selectedNamespaces: Namespace[]
|
|
239
248
|
): Promise<Result> => {
|
|
240
|
-
const
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
: wallet.needsNamespace;
|
|
249
|
+
const needsNamespace = wallet.properties?.find(
|
|
250
|
+
(item) => item.name === 'namespaces'
|
|
251
|
+
)?.value;
|
|
244
252
|
|
|
245
|
-
const needsDerivationPath =
|
|
246
|
-
|
|
247
|
-
|
|
253
|
+
const needsDerivationPath = wallet.properties?.find(
|
|
254
|
+
(item) => item.name === 'derivationPath'
|
|
255
|
+
)?.value;
|
|
248
256
|
|
|
249
257
|
const isSingleNamespace = needsNamespace?.selection === 'single';
|
|
250
258
|
const firstSelectedNamespace = selectedNamespaces[0];
|
|
@@ -320,10 +328,9 @@ export function useStatefulConnect(): UseStatefulConnect {
|
|
|
320
328
|
const selectedNamespace = connectState.derivationPath.namespace;
|
|
321
329
|
const namespaces = [{ namespace: selectedNamespace, derivationPath }];
|
|
322
330
|
|
|
323
|
-
const
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
: wallet.needsNamespace;
|
|
331
|
+
const needsNamespace = wallet.properties?.find(
|
|
332
|
+
(item) => item.name === 'namespaces'
|
|
333
|
+
)?.value;
|
|
327
334
|
|
|
328
335
|
const namespaceIsAvailable =
|
|
329
336
|
!!needsNamespace?.data && needsNamespace.data.length > 1;
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import type { ExtendedModalWalletInfo } from '../../utils/wallets';
|
|
2
2
|
import type { Namespace } from '@hub3js/namespaces';
|
|
3
3
|
|
|
4
|
+
export interface NamespaceData {
|
|
5
|
+
namespace: Namespace;
|
|
6
|
+
derivationPath?: string;
|
|
7
|
+
}
|
|
8
|
+
|
|
4
9
|
export interface HandleConnectOptions {
|
|
5
10
|
// To have a switch between connect and disconnect when user is clicking on a button, this option can be helpful.
|
|
6
11
|
forceConnectToNamespaces?: Namespace[];
|
|
@@ -15,9 +20,7 @@ export interface NeedsNamespacesState {
|
|
|
15
20
|
|
|
16
21
|
export interface DetachedPayload {
|
|
17
22
|
targetWallet: ExtendedModalWalletInfo;
|
|
18
|
-
selectedNamespaces:
|
|
19
|
-
| { namespace: Namespace; derivationPath?: string }[]
|
|
20
|
-
| null;
|
|
23
|
+
selectedNamespaces: NamespaceData[] | null;
|
|
21
24
|
derivationPath?: string;
|
|
22
25
|
}
|
|
23
26
|
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import type { ExtendedModalWalletInfo } from '../utils/wallets';
|
|
2
2
|
import type { WalletInfo } from '@rango-dev/ui';
|
|
3
3
|
|
|
4
|
+
import { WalletTypes } from '@rango-dev/provider-all';
|
|
4
5
|
import { WalletState } from '@rango-dev/ui';
|
|
5
6
|
import { useWallets } from '@rango-dev/wallets-react';
|
|
6
|
-
import { detectMobileScreens, WalletTypes } from '@rango-dev/wallets-shared';
|
|
7
7
|
import { useCallback, useEffect } from 'react';
|
|
8
8
|
|
|
9
9
|
import { useAppStore } from '../store/AppStore';
|
|
10
|
+
import { detectMobileScreens } from '../utils/common';
|
|
10
11
|
import { emitWalletDetected } from '../utils/events';
|
|
11
12
|
import { configWalletsToWalletName } from '../utils/providers';
|
|
12
13
|
import {
|
|
@@ -37,6 +38,12 @@ const NON_INJECTED_WALLET_TYPES = new Set<string>([
|
|
|
37
38
|
WalletTypes.DEFAULT,
|
|
38
39
|
]);
|
|
39
40
|
|
|
41
|
+
const DEFAULT_EVM_WALLETS = new Set<string>([
|
|
42
|
+
WalletTypes.DEFAULT,
|
|
43
|
+
WalletTypes.WALLET_CONNECT_2,
|
|
44
|
+
WalletTypes.LEDGER,
|
|
45
|
+
]);
|
|
46
|
+
|
|
40
47
|
interface Params {
|
|
41
48
|
chain?: string;
|
|
42
49
|
}
|
|
@@ -89,8 +96,7 @@ export function useWalletList(params?: Params): API {
|
|
|
89
96
|
if (isDetected && !detectedWalletsReported.has(wallet.type)) {
|
|
90
97
|
detectedWalletsReported.add(wallet.type);
|
|
91
98
|
emitWalletDetected({
|
|
92
|
-
|
|
93
|
-
walletName: wallet.title,
|
|
99
|
+
walletName: wallet.type,
|
|
94
100
|
});
|
|
95
101
|
}
|
|
96
102
|
});
|
|
@@ -132,11 +138,7 @@ export function useWalletList(params?: Params): API {
|
|
|
132
138
|
const isEvmWalletInstalledExceptDefault = wallets.filter(
|
|
133
139
|
(wallet) =>
|
|
134
140
|
wallet.state != WalletState.NOT_INSTALLED &&
|
|
135
|
-
!
|
|
136
|
-
WalletTypes.DEFAULT,
|
|
137
|
-
WalletTypes.WALLET_CONNECT_2,
|
|
138
|
-
WalletTypes.LEDGER,
|
|
139
|
-
].includes(wallet.type as WalletTypes) &&
|
|
141
|
+
!DEFAULT_EVM_WALLETS.has(wallet.type) &&
|
|
140
142
|
getWalletInfo(wallet.type).supportedChains.filter(
|
|
141
143
|
(blockchain) => blockchain.type == 'EVM'
|
|
142
144
|
).length > 0
|
|
@@ -1,19 +1,12 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Provider } from '@hub3js/core';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export function hashProviders(
|
|
6
|
-
providers: (string | ProviderInterface | Provider)[]
|
|
7
|
-
): string {
|
|
3
|
+
export function hashProviders(providers: (string | Provider)[]): string {
|
|
8
4
|
return providers
|
|
9
5
|
.map((provider) => {
|
|
10
6
|
if (typeof provider === 'string') {
|
|
11
7
|
return provider;
|
|
12
8
|
}
|
|
13
|
-
|
|
14
|
-
return provider.id;
|
|
15
|
-
}
|
|
16
|
-
return provider.config.type;
|
|
9
|
+
return provider.id;
|
|
17
10
|
})
|
|
18
11
|
.join('-');
|
|
19
12
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { WidgetConfigWithoutLegacyProviders } from '../../types';
|
|
2
2
|
import type { ProvidersOptions } from '../../utils/providers';
|
|
3
3
|
|
|
4
4
|
import { useEffect } from 'react';
|
|
@@ -8,7 +8,7 @@ import { useAppStore } from '../../store/AppStore';
|
|
|
8
8
|
import { hashProviders } from './useWalletProviders.helpers';
|
|
9
9
|
|
|
10
10
|
export function useWalletProviders(
|
|
11
|
-
configWallets:
|
|
11
|
+
configWallets: WidgetConfigWithoutLegacyProviders['wallets'],
|
|
12
12
|
options?: ProvidersOptions
|
|
13
13
|
) {
|
|
14
14
|
const { clearConnectedWallet, getAvailableProviders, buildAndSetProviders } =
|
package/src/index.ts
CHANGED
|
@@ -14,6 +14,7 @@ import type {
|
|
|
14
14
|
WidgetTheme,
|
|
15
15
|
WidgetVariant,
|
|
16
16
|
} from './types';
|
|
17
|
+
import type { WalletType } from '@hub3js/core';
|
|
17
18
|
import type {
|
|
18
19
|
PendingSwapWithQueueID,
|
|
19
20
|
Route,
|
|
@@ -36,16 +37,14 @@ import type {
|
|
|
36
37
|
StepTxExecutionUpdatedEvent,
|
|
37
38
|
} from '@rango-dev/queue-manager-rango-preset';
|
|
38
39
|
import type {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
} from '@rango-dev/wallets-core/legacy';
|
|
42
|
-
import type {
|
|
40
|
+
EventHandler as HandleWalletsUpdate,
|
|
41
|
+
ProviderInterface,
|
|
43
42
|
WalletInfo,
|
|
44
43
|
WalletState,
|
|
45
|
-
|
|
46
|
-
} from '@rango-dev/wallets-shared';
|
|
44
|
+
} from '@rango-dev/wallets-react';
|
|
47
45
|
import type { PendingSwap, PendingSwapStep } from 'rango-types';
|
|
48
46
|
|
|
47
|
+
import { Networks, readAccountAddress } from '@rango-dev/internal-blockchains';
|
|
49
48
|
import {
|
|
50
49
|
EventSeverity,
|
|
51
50
|
RouteEventType,
|
|
@@ -53,9 +52,7 @@ import {
|
|
|
53
52
|
StepExecutionBlockedEventStatus,
|
|
54
53
|
StepExecutionEventStatus,
|
|
55
54
|
} from '@rango-dev/queue-manager-rango-preset';
|
|
56
|
-
import { legacyReadAccountAddress as readAccountAddress } from '@rango-dev/wallets-core/legacy';
|
|
57
55
|
import { useWallets, Events as WalletEvents } from '@rango-dev/wallets-react';
|
|
58
|
-
import { Networks, WalletTypes } from '@rango-dev/wallets-shared';
|
|
59
56
|
import { PendingSwapNetworkStatus } from 'rango-types';
|
|
60
57
|
|
|
61
58
|
import {
|
|
@@ -87,7 +84,7 @@ import {
|
|
|
87
84
|
WalletEventTypes,
|
|
88
85
|
WidgetEvents,
|
|
89
86
|
} from './types';
|
|
90
|
-
import {
|
|
87
|
+
import { pickProviderVersion } from './utils/providers';
|
|
91
88
|
import { customizedThemeTokens } from './utils/ui';
|
|
92
89
|
|
|
93
90
|
export const StatefulConnect = {
|
|
@@ -105,6 +102,9 @@ export type {
|
|
|
105
102
|
WidgetTheme,
|
|
106
103
|
WidgetColors,
|
|
107
104
|
WidgetColorsKeys,
|
|
105
|
+
/**
|
|
106
|
+
* @deprecated Pass a hub `Provider` instead. This type will be removed in future versions.
|
|
107
|
+
*/
|
|
108
108
|
ProviderInterface,
|
|
109
109
|
BlockchainAndTokenConfig,
|
|
110
110
|
WidgetProps,
|
|
@@ -183,10 +183,9 @@ export type {
|
|
|
183
183
|
// Internal function and enum exports for Rango
|
|
184
184
|
export {
|
|
185
185
|
readAccountAddress,
|
|
186
|
-
|
|
186
|
+
pickProviderVersion,
|
|
187
187
|
Networks,
|
|
188
188
|
WalletEvents,
|
|
189
|
-
WalletTypes,
|
|
190
189
|
PendingSwapNetworkStatus,
|
|
191
190
|
EventSeverity,
|
|
192
191
|
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/** How long a wallet may leave an attempt unanswered before it's logged. */
|
|
2
|
+
export const CONNECT_TIMEOUT = 180_000;
|
|
3
|
+
|
|
4
|
+
export const CONNECT_TIMEOUT_MESSAGE =
|
|
5
|
+
'Wallet connection still pending after 3 minutes';
|
|
6
|
+
|
|
7
|
+
export const UNREADABLE_FAILURE_MESSAGE = 'Failure could not be described';
|
|
8
|
+
|
|
9
|
+
/** No class is named like this, so it can't be mistaken for a real name. */
|
|
10
|
+
export const UNREADABLE_FAILURE_NAME = '(unreadable)';
|
|
11
|
+
|
|
12
|
+
export const ATTEMPT_ERROR_NAMES: readonly string[] = [
|
|
13
|
+
'WalletConnectionAttemptError',
|
|
14
|
+
'AutoConnectionAttemptError',
|
|
15
|
+
];
|
|
16
|
+
|
|
17
|
+
export const CONNECTION_ERROR_NAME = 'WalletConnectionError';
|