@rango-dev/widget-embedded 0.63.1-next.0 → 0.63.1-next.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/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.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.styles.d.ts +171 -171
- package/dist/components/Quote/Quote.styles.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/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/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/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 +8 -9
- package/src/QueueManager.tsx +10 -7
- package/src/components/NamespaceItem/NamespaceItem.tsx +1 -1
- package/src/components/NamespaceItem/NamespaceItem.types.ts +3 -3
- package/src/components/SwapDetails/SwapDetails.tsx +4 -1
- package/src/components/SwapDetailsModal/SwapDetailsModal.ConnectWallet.tsx +7 -11
- 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 +2 -2
- package/src/components/WalletStatefulConnect/NamespaceDetachedItem.tsx +2 -1
- package/src/components/WalletStatefulConnect/Namespaces.tsx +3 -8
- 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 +6 -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 +28 -26
- 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 +39 -12
- 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
|
@@ -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 {
|
|
@@ -119,7 +119,7 @@ export function Detached(props: PropTypes) {
|
|
|
119
119
|
);
|
|
120
120
|
};
|
|
121
121
|
|
|
122
|
-
const renderNamespaceItem = (namespace:
|
|
122
|
+
const renderNamespaceItem = (namespace: NamespaceMeta) => {
|
|
123
123
|
if (namespace.unsupported) {
|
|
124
124
|
return <NamespaceUnsupportedItem namespace={namespace} />;
|
|
125
125
|
}
|
|
@@ -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,
|
|
@@ -11,7 +12,6 @@ import {
|
|
|
11
12
|
RadioRoot,
|
|
12
13
|
WalletImageContainer,
|
|
13
14
|
} from '@rango-dev/ui';
|
|
14
|
-
import { getSupportedChainsFromNamespace } from '@rango-dev/wallets-shared';
|
|
15
15
|
import React, { useEffect, useMemo, useState } from 'react';
|
|
16
16
|
|
|
17
17
|
import { useAppStore } from '../../store/AppStore';
|
|
@@ -25,13 +25,8 @@ export function Namespaces(props: PropTypes) {
|
|
|
25
25
|
const namespacesProperty = targetWallet.properties?.find(
|
|
26
26
|
(property) => property.name === 'namespaces'
|
|
27
27
|
);
|
|
28
|
-
const
|
|
29
|
-
const
|
|
30
|
-
? namespacesProperty?.value.selection === 'single'
|
|
31
|
-
: targetWallet.needsNamespace?.selection === 'single';
|
|
32
|
-
const needsNamespace = isHub
|
|
33
|
-
? namespacesProperty?.value
|
|
34
|
-
: targetWallet.needsNamespace;
|
|
28
|
+
const singleNamespace = namespacesProperty?.value.selection === 'single';
|
|
29
|
+
const needsNamespace = namespacesProperty?.value;
|
|
35
30
|
const providerImage = targetWallet.image;
|
|
36
31
|
|
|
37
32
|
const blockchains = useAppStore().blockchains();
|
|
@@ -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,
|
|
@@ -126,6 +126,9 @@ function Main(props: PropsWithChildren<PropTypes>) {
|
|
|
126
126
|
meta: blockchains,
|
|
127
127
|
},
|
|
128
128
|
},
|
|
129
|
+
[WalletTypes.LEDGER_WALLET]: {
|
|
130
|
+
provider: config.ledgerWallet,
|
|
131
|
+
},
|
|
129
132
|
},
|
|
130
133
|
}}>
|
|
131
134
|
{props.children}
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { WidgetConfigWithoutLegacyProviders } from '../../types';
|
|
2
2
|
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';
|
|
3
|
+
import type { EventHandler, Events } from '@rango-dev/wallets-react';
|
|
7
4
|
|
|
8
5
|
export type OnWalletConnectHandler = (wallet: LastConnectedWallet) => void;
|
|
9
6
|
export type OnWalletDisconnectHandler = (walletType: string) => void;
|
|
@@ -23,7 +20,7 @@ export interface WidgetContextInterface {
|
|
|
23
20
|
}
|
|
24
21
|
|
|
25
22
|
type EventHandlerParams = Parameters<EventHandler>;
|
|
26
|
-
type EventParam = Exclude<
|
|
23
|
+
type EventParam = Exclude<Events, Events.PROVIDER_DISCONNECTED>;
|
|
27
24
|
|
|
28
25
|
export type OnUpdateState = (
|
|
29
26
|
type: EventHandlerParams[0],
|
|
@@ -35,5 +32,5 @@ export type OnUpdateState = (
|
|
|
35
32
|
|
|
36
33
|
export interface PropTypes {
|
|
37
34
|
onUpdateState?: OnUpdateState;
|
|
38
|
-
config:
|
|
35
|
+
config: WidgetConfigWithoutLegacyProviders;
|
|
39
36
|
}
|
|
@@ -2,18 +2,11 @@ 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
|
|
|
19
12
|
import { useAppStore } from '../../store/AppStore';
|
|
@@ -39,8 +32,6 @@ export function useUpdates(params: UseUpdatesParams): UseUpdates {
|
|
|
39
32
|
newWalletConnected,
|
|
40
33
|
disconnectWallet,
|
|
41
34
|
disconnectNamespaces,
|
|
42
|
-
connectedWallets,
|
|
43
|
-
removeBalancesForWallet,
|
|
44
35
|
blockchains,
|
|
45
36
|
} = useAppStore();
|
|
46
37
|
|
|
@@ -50,7 +41,7 @@ export function useUpdates(params: UseUpdatesParams): UseUpdates {
|
|
|
50
41
|
.map((chain) => chain.name);
|
|
51
42
|
|
|
52
43
|
const onAccountsEvent = (
|
|
53
|
-
event: Parameters<
|
|
44
|
+
event: Parameters<EventHandler>,
|
|
54
45
|
params: {
|
|
55
46
|
supportedChainNames: Network[] | null;
|
|
56
47
|
}
|
|
@@ -83,13 +74,7 @@ export function useUpdates(params: UseUpdatesParams): UseUpdates {
|
|
|
83
74
|
}
|
|
84
75
|
};
|
|
85
76
|
|
|
86
|
-
const
|
|
87
|
-
type,
|
|
88
|
-
event,
|
|
89
|
-
value,
|
|
90
|
-
state,
|
|
91
|
-
info
|
|
92
|
-
) => {
|
|
77
|
+
const handler: EventHandler = (type, event, value, state, info) => {
|
|
93
78
|
if (event === Events.ACCOUNTS) {
|
|
94
79
|
const supportedChainNames: Network[] | null =
|
|
95
80
|
walletAndSupportedChainsNames(info.supportedBlockchains);
|
|
@@ -116,97 +101,7 @@ export function useUpdates(params: UseUpdatesParams): UseUpdates {
|
|
|
116
101
|
if (event === Events.NAMESPACE_DISCONNECTED) {
|
|
117
102
|
disconnectNamespaces(type, value);
|
|
118
103
|
}
|
|
119
|
-
};
|
|
120
104
|
|
|
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
|
-
|
|
185
|
-
// After cleaning up balances, it's time to add new accounts.
|
|
186
|
-
if (value) {
|
|
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
|
-
}
|
|
200
|
-
}
|
|
201
|
-
};
|
|
202
|
-
|
|
203
|
-
const handleUpdatesForBoth: EventHandler = (
|
|
204
|
-
type,
|
|
205
|
-
event,
|
|
206
|
-
value,
|
|
207
|
-
state,
|
|
208
|
-
_info
|
|
209
|
-
) => {
|
|
210
105
|
if (event === Events.CONNECTED && value) {
|
|
211
106
|
const walletFromEvent: LastConnectedWallet = {
|
|
212
107
|
walletType: type,
|
|
@@ -234,16 +129,6 @@ export function useUpdates(params: UseUpdatesParams): UseUpdates {
|
|
|
234
129
|
}
|
|
235
130
|
};
|
|
236
131
|
|
|
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
132
|
return {
|
|
248
133
|
handler,
|
|
249
134
|
};
|
|
@@ -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>
|