@rango-dev/widget-embedded 0.50.0 → 0.50.1-next.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +15 -0
- package/dist/components/StatefulConnectModal/StatefulConnectModal.d.ts.map +1 -1
- package/dist/components/WalletStatefulConnect/Detached.d.ts.map +1 -1
- package/dist/components/WalletStatefulConnect/Detached.types.d.ts +5 -1
- package/dist/components/WalletStatefulConnect/Detached.types.d.ts.map +1 -1
- package/dist/components/WalletStatefulConnect/NamespaceDetachedItem.d.ts +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.map +1 -1
- package/dist/components/WalletStatefulConnect/Namespaces.types.d.ts +8 -2
- package/dist/components/WalletStatefulConnect/Namespaces.types.d.ts.map +1 -1
- package/dist/hooks/useStatefulConnect/useStatefulConnect.d.ts +2 -1
- package/dist/hooks/useStatefulConnect/useStatefulConnect.d.ts.map +1 -1
- package/dist/hooks/useStatefulConnect/useStatefulConnect.state.d.ts +4 -1
- package/dist/hooks/useStatefulConnect/useStatefulConnect.state.d.ts.map +1 -1
- package/dist/hooks/useStatefulConnect/useStatefulConnect.types.d.ts +5 -1
- package/dist/hooks/useStatefulConnect/useStatefulConnect.types.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +3 -3
- package/dist/utils/wallets.d.ts.map +1 -1
- package/dist/widget-embedded.build.json +1 -1
- package/package.json +7 -7
- package/src/components/StatefulConnectModal/StatefulConnectModal.tsx +9 -1
- package/src/components/WalletStatefulConnect/Detached.tsx +126 -27
- package/src/components/WalletStatefulConnect/Detached.types.ts +4 -1
- package/src/components/WalletStatefulConnect/NamespaceDetachedItem.tsx +37 -41
- package/src/components/WalletStatefulConnect/Namespaces.styles.ts +0 -1
- package/src/components/WalletStatefulConnect/Namespaces.tsx +2 -0
- package/src/components/WalletStatefulConnect/Namespaces.types.tsx +8 -2
- package/src/hooks/useStatefulConnect/useStatefulConnect.state.ts +3 -1
- package/src/hooks/useStatefulConnect/useStatefulConnect.ts +22 -3
- package/src/hooks/useStatefulConnect/useStatefulConnect.types.ts +4 -1
- package/src/pages/WalletsPage.tsx +7 -7
- package/src/utils/wallets.ts +6 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rango-dev/widget-embedded",
|
|
3
|
-
"version": "0.50.0",
|
|
3
|
+
"version": "0.50.1-next.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"source": "./src/index.ts",
|
|
@@ -25,15 +25,15 @@
|
|
|
25
25
|
"@lingui/core": "4.2.1",
|
|
26
26
|
"@lingui/react": "4.2.1",
|
|
27
27
|
"@rango-dev/logging-core": "^0.11.0",
|
|
28
|
-
"@rango-dev/provider-all": "^0.52.0",
|
|
28
|
+
"@rango-dev/provider-all": "^0.52.1-next.0",
|
|
29
29
|
"@rango-dev/queue-manager-core": "^0.32.0",
|
|
30
|
-
"@rango-dev/queue-manager-rango-preset": "^0.52.0",
|
|
30
|
+
"@rango-dev/queue-manager-rango-preset": "^0.52.1-next.0",
|
|
31
31
|
"@rango-dev/queue-manager-react": "^0.32.0",
|
|
32
32
|
"@rango-dev/signer-solana": "^0.44.0",
|
|
33
|
-
"@rango-dev/ui": "^0.53.0",
|
|
34
|
-
"@rango-dev/wallets-core": "^0.49.0",
|
|
35
|
-
"@rango-dev/wallets-react": "^0.36.0",
|
|
36
|
-
"@rango-dev/wallets-shared": "^0.50.0",
|
|
33
|
+
"@rango-dev/ui": "^0.53.1-next.0",
|
|
34
|
+
"@rango-dev/wallets-core": "^0.49.1-next.0",
|
|
35
|
+
"@rango-dev/wallets-react": "^0.36.1-next.0",
|
|
36
|
+
"@rango-dev/wallets-shared": "^0.50.1-next.0",
|
|
37
37
|
"bignumber.js": "^9.1.1",
|
|
38
38
|
"copy-to-clipboard": "^3.3.3",
|
|
39
39
|
"dayjs": "^1.11.7",
|
|
@@ -75,7 +75,7 @@ export function StatefulConnectModal(props: PropTypes) {
|
|
|
75
75
|
);
|
|
76
76
|
}
|
|
77
77
|
|
|
78
|
-
handleDerivationPath(derivationPath)
|
|
78
|
+
handleDerivationPath(props.wallet!, derivationPath)
|
|
79
79
|
.then(afterConnected)
|
|
80
80
|
.catch(catchErrorOnHandle);
|
|
81
81
|
};
|
|
@@ -114,6 +114,13 @@ export function StatefulConnectModal(props: PropTypes) {
|
|
|
114
114
|
}
|
|
115
115
|
};
|
|
116
116
|
|
|
117
|
+
const handleNavigateToDerivationPath = (selectedNamespace: Namespace) => {
|
|
118
|
+
if (!props.wallet?.needsDerivationPath) {
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
void handleNamespace(props.wallet, [selectedNamespace]);
|
|
122
|
+
};
|
|
123
|
+
|
|
117
124
|
useEffect(() => {
|
|
118
125
|
if (props.wallet) {
|
|
119
126
|
resetModalState();
|
|
@@ -200,6 +207,7 @@ export function StatefulConnectModal(props: PropTypes) {
|
|
|
200
207
|
}
|
|
201
208
|
value={getState().namespace}
|
|
202
209
|
selectedNamespaces={getState().selectedNamespaces}
|
|
210
|
+
navigateToDerivationPath={handleNavigateToDerivationPath}
|
|
203
211
|
/>
|
|
204
212
|
)}
|
|
205
213
|
</WatermarkedModal>
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import type { PropTypes } from './Detached.types';
|
|
2
|
+
import type { LegacyNamespaceMeta } from '@rango-dev/wallets-core/legacy';
|
|
3
|
+
import type { Namespace } from '@rango-dev/wallets-core/namespaces/common';
|
|
2
4
|
|
|
3
5
|
import { i18n } from '@lingui/core';
|
|
4
|
-
import { Button, Divider, Image, MessageBox } from '@rango-dev/ui';
|
|
6
|
+
import { Alert, Button, Divider, Image, MessageBox } from '@rango-dev/ui';
|
|
5
7
|
import { useWallets } from '@rango-dev/wallets-react';
|
|
6
8
|
import React from 'react';
|
|
7
9
|
|
|
@@ -12,11 +14,127 @@ import { NamespaceDetachedItem } from './NamespaceDetachedItem';
|
|
|
12
14
|
import { NamespaceList, StyledButton } from './Namespaces.styles';
|
|
13
15
|
|
|
14
16
|
export function Detached(props: PropTypes) {
|
|
15
|
-
const {
|
|
17
|
+
const {
|
|
18
|
+
value,
|
|
19
|
+
selectedNamespaces,
|
|
20
|
+
onConfirm,
|
|
21
|
+
onDisconnectWallet,
|
|
22
|
+
navigateToDerivationPath,
|
|
23
|
+
} = props;
|
|
16
24
|
const { targetWallet } = value;
|
|
17
25
|
|
|
18
|
-
const { state } = useWallets();
|
|
19
|
-
const
|
|
26
|
+
const { connect, disconnect, state } = useWallets();
|
|
27
|
+
const walletType = targetWallet.type;
|
|
28
|
+
const walletState = state(walletType);
|
|
29
|
+
const namespacesProperty = targetWallet.properties?.find(
|
|
30
|
+
(property) => property.name === 'namespaces'
|
|
31
|
+
);
|
|
32
|
+
const derivationPathProperty = targetWallet.properties?.find(
|
|
33
|
+
(property) => property.name === 'derivationPath'
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
const singleSelection = namespacesProperty?.value.selection === 'single';
|
|
37
|
+
|
|
38
|
+
const handleConnectNamespace = async (
|
|
39
|
+
namespace: Namespace,
|
|
40
|
+
options?: {
|
|
41
|
+
derivationPath?: string;
|
|
42
|
+
shouldAskForDerivationPath?: boolean;
|
|
43
|
+
}
|
|
44
|
+
) => {
|
|
45
|
+
if (singleSelection) {
|
|
46
|
+
// For single-selection wallets, disconnect all namespaces before connecting a new namespace
|
|
47
|
+
await disconnect(walletType);
|
|
48
|
+
}
|
|
49
|
+
if (derivationPathProperty && options?.shouldAskForDerivationPath) {
|
|
50
|
+
navigateToDerivationPath(namespace);
|
|
51
|
+
} else {
|
|
52
|
+
await connect(walletType, [
|
|
53
|
+
{
|
|
54
|
+
namespace: namespace,
|
|
55
|
+
network: '',
|
|
56
|
+
derivationPath: options?.derivationPath ?? undefined,
|
|
57
|
+
},
|
|
58
|
+
]);
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
const handleDisconnectNamespace = async (namespace: Namespace) => {
|
|
63
|
+
await disconnect(walletType, [namespace]);
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
const renderNamespaceListHeader = () => {
|
|
67
|
+
if (!!singleSelection) {
|
|
68
|
+
return (
|
|
69
|
+
<>
|
|
70
|
+
<Divider size={20} />
|
|
71
|
+
<Alert
|
|
72
|
+
id="widget-wallet-stateful-connect-alert"
|
|
73
|
+
variant="alarm"
|
|
74
|
+
type="info"
|
|
75
|
+
title={i18n.t(
|
|
76
|
+
'This wallet can only connect to one chain at a time.'
|
|
77
|
+
)}
|
|
78
|
+
/>
|
|
79
|
+
<Divider size={30} />
|
|
80
|
+
</>
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
return (
|
|
84
|
+
<>
|
|
85
|
+
<Divider size={30} />
|
|
86
|
+
<NamespacesHeader>
|
|
87
|
+
<Button
|
|
88
|
+
id="widget-detached-disconnect-wallet-btn"
|
|
89
|
+
variant="ghost"
|
|
90
|
+
type="error"
|
|
91
|
+
size="xsmall"
|
|
92
|
+
disabled={walletState.connecting || !walletState.connected}
|
|
93
|
+
onClick={onDisconnectWallet}>
|
|
94
|
+
{i18n.t('Disconnect wallet')}
|
|
95
|
+
</Button>
|
|
96
|
+
</NamespacesHeader>
|
|
97
|
+
<Divider size={16} />
|
|
98
|
+
</>
|
|
99
|
+
);
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
const renderNamespaceItem = (namespace: LegacyNamespaceMeta) => {
|
|
103
|
+
if (namespace.unsupported) {
|
|
104
|
+
return <NamespaceUnsupportedItem namespace={namespace} />;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const selectedNamespace = selectedNamespaces?.find(
|
|
108
|
+
(selectedNamespaceItem) =>
|
|
109
|
+
selectedNamespaceItem.namespace === namespace.value
|
|
110
|
+
);
|
|
111
|
+
|
|
112
|
+
const namespaceState = walletState.namespaces?.get(namespace.value);
|
|
113
|
+
|
|
114
|
+
if (!namespaceState) {
|
|
115
|
+
throw new Error(`State for ${namespace.value} was not found!`);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const disabled = singleSelection && walletState.connecting; // If wallet is configured as single selection, button should be disabled while a namespace is already in connecting state
|
|
119
|
+
|
|
120
|
+
return (
|
|
121
|
+
<NamespaceDetachedItem
|
|
122
|
+
namespace={namespace}
|
|
123
|
+
initialConnect={!!selectedNamespace}
|
|
124
|
+
disabled={disabled}
|
|
125
|
+
state={namespaceState}
|
|
126
|
+
handleConnect={async (options) =>
|
|
127
|
+
handleConnectNamespace(namespace.value, {
|
|
128
|
+
derivationPath: selectedNamespace?.derivationPath,
|
|
129
|
+
shouldAskForDerivationPath: options?.shouldAskForDerivationPath,
|
|
130
|
+
})
|
|
131
|
+
}
|
|
132
|
+
handleDisconnect={async () =>
|
|
133
|
+
handleDisconnectNamespace(namespace.value)
|
|
134
|
+
}
|
|
135
|
+
/>
|
|
136
|
+
);
|
|
137
|
+
};
|
|
20
138
|
|
|
21
139
|
return (
|
|
22
140
|
<>
|
|
@@ -30,30 +148,11 @@ export function Detached(props: PropTypes) {
|
|
|
30
148
|
)}
|
|
31
149
|
icon={<Image src={targetWallet.image} size={45} />}
|
|
32
150
|
/>
|
|
33
|
-
|
|
34
|
-
<
|
|
35
|
-
<Button
|
|
36
|
-
id="widget-detached-disconnect-wallet-btn"
|
|
37
|
-
variant="ghost"
|
|
38
|
-
type="error"
|
|
39
|
-
size="xsmall"
|
|
40
|
-
disabled={walletState.connecting || !walletState.connected}
|
|
41
|
-
onClick={onDisconnectWallet}>
|
|
42
|
-
{i18n.t('Disconnect wallet')}
|
|
43
|
-
</Button>
|
|
44
|
-
</NamespacesHeader>
|
|
45
|
-
<NamespaceList id="widget-detached-namespace-list" as={'ul'}>
|
|
151
|
+
{renderNamespaceListHeader()}
|
|
152
|
+
<NamespaceList id="widget-detached-namespace-list">
|
|
46
153
|
{targetWallet.needsNamespace?.data.map((namespace, index, array) => (
|
|
47
154
|
<React.Fragment key={namespace.id}>
|
|
48
|
-
{namespace
|
|
49
|
-
<NamespaceUnsupportedItem namespace={namespace} />
|
|
50
|
-
) : (
|
|
51
|
-
<NamespaceDetachedItem
|
|
52
|
-
walletType={targetWallet.type}
|
|
53
|
-
namespace={namespace}
|
|
54
|
-
initialConnect={selectedNamespaces?.includes(namespace.value)}
|
|
55
|
-
/>
|
|
56
|
-
)}
|
|
155
|
+
{renderNamespaceItem(namespace)}
|
|
57
156
|
{index !== array.length - 1 && <Divider size={10} />}
|
|
58
157
|
</React.Fragment>
|
|
59
158
|
))}
|
|
@@ -62,7 +161,7 @@ export function Detached(props: PropTypes) {
|
|
|
62
161
|
<StyledButton
|
|
63
162
|
id="widget-name-space-confirm-btn"
|
|
64
163
|
type="primary"
|
|
65
|
-
onClick={
|
|
164
|
+
onClick={onConfirm}>
|
|
66
165
|
{i18n.t('Done')}
|
|
67
166
|
</StyledButton>
|
|
68
167
|
</>
|
|
@@ -5,5 +5,8 @@ export interface PropTypes {
|
|
|
5
5
|
value: NeedsNamespacesState;
|
|
6
6
|
onConfirm: () => void;
|
|
7
7
|
onDisconnectWallet: () => void;
|
|
8
|
-
selectedNamespaces:
|
|
8
|
+
selectedNamespaces:
|
|
9
|
+
| { namespace: Namespace; derivationPath?: string }[]
|
|
10
|
+
| null;
|
|
11
|
+
navigateToDerivationPath: (selectedNamespace: Namespace) => void;
|
|
9
12
|
}
|
|
@@ -1,26 +1,23 @@
|
|
|
1
1
|
import type { NamespaceDetachedItemPropTypes } from './Namespaces.types';
|
|
2
|
-
import type { NamespaceData } from '@rango-dev/wallets-core/dist/hub/store/namespaces';
|
|
3
|
-
import type { Namespace } from '@rango-dev/wallets-core/namespaces/common';
|
|
4
2
|
|
|
5
3
|
import { i18n } from '@lingui/core';
|
|
6
4
|
import { Button, Spinner } from '@rango-dev/ui';
|
|
7
|
-
import { useWallets } from '@rango-dev/wallets-react';
|
|
8
5
|
import React, { useLayoutEffect, useRef, useState } from 'react';
|
|
9
6
|
|
|
10
7
|
import { getConciseAddress } from '../../utils/wallets';
|
|
11
8
|
import { NamespaceItem } from '../NamespaceItem';
|
|
12
9
|
|
|
13
|
-
export
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
10
|
+
export function NamespaceDetachedItem(props: NamespaceDetachedItemPropTypes) {
|
|
11
|
+
const {
|
|
12
|
+
namespace,
|
|
13
|
+
initialConnect,
|
|
14
|
+
disabled,
|
|
15
|
+
state,
|
|
16
|
+
handleConnect,
|
|
17
|
+
handleDisconnect,
|
|
18
|
+
} = props;
|
|
21
19
|
|
|
22
|
-
const
|
|
23
|
-
const firstAccountArray = namespaceState.accounts?.[0]?.split(':');
|
|
20
|
+
const [error, setError] = useState<Error | null>(null);
|
|
24
21
|
|
|
25
22
|
/*
|
|
26
23
|
* Ref to track ongoing connection attempts.
|
|
@@ -31,22 +28,16 @@ export const NamespaceDetachedItem = function NamespaceDetachedItem(
|
|
|
31
28
|
|
|
32
29
|
useLayoutEffect(() => {
|
|
33
30
|
if (initialConnect && !processingConnectAttempt.current) {
|
|
34
|
-
void handleConnectNamespace(
|
|
31
|
+
void handleConnectNamespace(); // If we attempt to connect the namespace as the initial connect, we should not ask for derivation path
|
|
35
32
|
}
|
|
36
33
|
}, []);
|
|
37
34
|
|
|
38
|
-
const handleConnectNamespace = async (
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
) => {
|
|
35
|
+
const handleConnectNamespace = async (options?: {
|
|
36
|
+
shouldAskForDerivationPath?: boolean;
|
|
37
|
+
}) => {
|
|
42
38
|
try {
|
|
43
39
|
processingConnectAttempt.current = true;
|
|
44
|
-
await
|
|
45
|
-
{
|
|
46
|
-
namespace: namespace,
|
|
47
|
-
network: '',
|
|
48
|
-
},
|
|
49
|
-
]);
|
|
40
|
+
await handleConnect(options);
|
|
50
41
|
} catch (error) {
|
|
51
42
|
setError(error as Error);
|
|
52
43
|
} finally {
|
|
@@ -54,17 +45,27 @@ export const NamespaceDetachedItem = function NamespaceDetachedItem(
|
|
|
54
45
|
}
|
|
55
46
|
};
|
|
56
47
|
|
|
57
|
-
const handleButtonClick = async (
|
|
48
|
+
const handleButtonClick = async () => {
|
|
58
49
|
setError(null);
|
|
59
|
-
if (
|
|
60
|
-
await
|
|
50
|
+
if (state.connected) {
|
|
51
|
+
await handleDisconnect();
|
|
61
52
|
} else {
|
|
62
|
-
void handleConnectNamespace(
|
|
53
|
+
void handleConnectNamespace({ shouldAskForDerivationPath: true }); // If we attempt to connect the namespace in result of button click, we should ask for derivation path
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const getConnectedAddress = () => {
|
|
58
|
+
const firstAccountArray = state.accounts?.[0]?.split(':');
|
|
59
|
+
const address = firstAccountArray?.[firstAccountArray.length - 1]; // Considering that account = [namespace, chain, address], we only need to get the address
|
|
60
|
+
if (!state.connected || !address) {
|
|
61
|
+
return null;
|
|
63
62
|
}
|
|
63
|
+
|
|
64
|
+
return getConciseAddress(address);
|
|
64
65
|
};
|
|
65
66
|
|
|
66
67
|
const getButtonText = () => {
|
|
67
|
-
if (
|
|
68
|
+
if (state.connected) {
|
|
68
69
|
return i18n.t('Disconnect');
|
|
69
70
|
}
|
|
70
71
|
if (!!error) {
|
|
@@ -76,29 +77,24 @@ export const NamespaceDetachedItem = function NamespaceDetachedItem(
|
|
|
76
77
|
return (
|
|
77
78
|
<NamespaceItem
|
|
78
79
|
namespace={namespace}
|
|
79
|
-
connected={
|
|
80
|
+
connected={state.connected}
|
|
80
81
|
error={error?.message}
|
|
81
|
-
address={
|
|
82
|
-
namespaceState.connected
|
|
83
|
-
? getConciseAddress(
|
|
84
|
-
firstAccountArray?.[firstAccountArray?.length - 1]
|
|
85
|
-
)
|
|
86
|
-
: ''
|
|
87
|
-
}
|
|
82
|
+
address={getConnectedAddress()}
|
|
88
83
|
suffix={
|
|
89
|
-
|
|
84
|
+
state.connecting ? (
|
|
90
85
|
<Spinner color="info" />
|
|
91
86
|
) : (
|
|
92
87
|
<Button
|
|
93
88
|
id="widget-name-space-connect-btn"
|
|
94
89
|
variant="ghost"
|
|
95
|
-
type={
|
|
90
|
+
type={state.connected ? 'error' : 'primary'}
|
|
96
91
|
size="xsmall"
|
|
97
|
-
onClick={async () => handleButtonClick(
|
|
92
|
+
onClick={async () => handleButtonClick()}
|
|
93
|
+
disabled={disabled}>
|
|
98
94
|
{getButtonText()}
|
|
99
95
|
</Button>
|
|
100
96
|
)
|
|
101
97
|
}
|
|
102
98
|
/>
|
|
103
99
|
);
|
|
104
|
-
}
|
|
100
|
+
}
|
|
@@ -124,6 +124,7 @@ export function Namespaces(props: PropTypes) {
|
|
|
124
124
|
'This wallet can only connect to one chain at a time. '
|
|
125
125
|
)}
|
|
126
126
|
/>
|
|
127
|
+
<Divider size={30} />
|
|
127
128
|
</>
|
|
128
129
|
) : (
|
|
129
130
|
<>
|
|
@@ -139,6 +140,7 @@ export function Namespaces(props: PropTypes) {
|
|
|
139
140
|
? i18n.t('Deselect all')
|
|
140
141
|
: i18n.t('Select all')}
|
|
141
142
|
</Button>
|
|
143
|
+
<Divider size={10} />
|
|
142
144
|
</>
|
|
143
145
|
)}
|
|
144
146
|
<NamespaceList>
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { NeedsNamespacesState } from '../../hooks/useStatefulConnect';
|
|
2
2
|
import type { LegacyNamespaceMeta } from '@rango-dev/wallets-core/legacy';
|
|
3
3
|
import type { Namespace } from '@rango-dev/wallets-core/namespaces/common';
|
|
4
|
+
import type { NamespaceData } from '@rango-dev/wallets-core/store';
|
|
4
5
|
|
|
5
6
|
export interface PropTypes {
|
|
6
7
|
onConfirm: (namespaces: Namespace[]) => void;
|
|
@@ -27,7 +28,12 @@ export type NamespaceItemPropTypes =
|
|
|
27
28
|
| CheckboxNamespaceItemPropTypes;
|
|
28
29
|
|
|
29
30
|
export type NamespaceDetachedItemPropTypes = {
|
|
30
|
-
walletType: string;
|
|
31
|
-
initialConnect?: boolean;
|
|
32
31
|
namespace: LegacyNamespaceMeta;
|
|
32
|
+
state: NamespaceData;
|
|
33
|
+
initialConnect?: boolean;
|
|
34
|
+
disabled?: boolean;
|
|
35
|
+
handleConnect: (options?: {
|
|
36
|
+
shouldAskForDerivationPath?: boolean;
|
|
37
|
+
}) => Promise<void>;
|
|
38
|
+
handleDisconnect: () => Promise<void>;
|
|
33
39
|
};
|
|
@@ -9,7 +9,9 @@ export interface State {
|
|
|
9
9
|
status: 'init' | 'namespace' | 'derivationPath' | 'detached';
|
|
10
10
|
namespace: NeedsNamespacesState | null;
|
|
11
11
|
derivationPath: NeedsDerivationPathState | null;
|
|
12
|
-
selectedNamespaces:
|
|
12
|
+
selectedNamespaces:
|
|
13
|
+
| { namespace: Namespace; derivationPath?: string }[]
|
|
14
|
+
| null;
|
|
13
15
|
}
|
|
14
16
|
|
|
15
17
|
export const initState: State = {
|
|
@@ -26,8 +26,11 @@ interface UseStatefulConnect {
|
|
|
26
26
|
wallet: WalletInfoWithExtra,
|
|
27
27
|
selectedNamespaces: Namespace[]
|
|
28
28
|
) => Promise<Result>;
|
|
29
|
-
handleDerivationPath: (path: string) => Promise<Result>;
|
|
30
29
|
handleDisconnect: (wallet: WalletInfoWithExtra) => Promise<Result>;
|
|
30
|
+
handleDerivationPath: (
|
|
31
|
+
wallet: ExtendedModalWalletInfo,
|
|
32
|
+
path: string
|
|
33
|
+
) => Promise<Result>;
|
|
31
34
|
getState(): State;
|
|
32
35
|
resetState(section?: 'derivation'): void;
|
|
33
36
|
}
|
|
@@ -231,14 +234,14 @@ export function useStatefulConnect(): UseStatefulConnect {
|
|
|
231
234
|
type: 'detached',
|
|
232
235
|
payload: {
|
|
233
236
|
targetWallet: wallet,
|
|
234
|
-
selectedNamespaces:
|
|
235
|
-
namespaces?.map((namespace) => namespace.namespace) || null,
|
|
237
|
+
selectedNamespaces: namespaces ?? null,
|
|
236
238
|
},
|
|
237
239
|
});
|
|
238
240
|
return { status: ResultStatus.Detached };
|
|
239
241
|
};
|
|
240
242
|
|
|
241
243
|
const handleDerivationPath = async (
|
|
244
|
+
wallet: ExtendedModalWalletInfo,
|
|
242
245
|
derivationPath: string
|
|
243
246
|
): Promise<Result> => {
|
|
244
247
|
if (!derivationPath) {
|
|
@@ -256,6 +259,22 @@ export function useStatefulConnect(): UseStatefulConnect {
|
|
|
256
259
|
const selectedNamespace = connectState.derivationPath.namespace;
|
|
257
260
|
const namespaces = [{ namespace: selectedNamespace, derivationPath }];
|
|
258
261
|
|
|
262
|
+
const isHub = !!wallet.isHub;
|
|
263
|
+
const needsNamespace = isHub
|
|
264
|
+
? wallet.properties?.find((item) => item.name === 'namespaces')?.value
|
|
265
|
+
: wallet.needsNamespace;
|
|
266
|
+
if (!!needsNamespace?.data && needsNamespace.data.length > 1) {
|
|
267
|
+
dispatch({
|
|
268
|
+
type: 'detached',
|
|
269
|
+
payload: {
|
|
270
|
+
targetWallet: wallet,
|
|
271
|
+
selectedNamespaces: namespaces ?? null,
|
|
272
|
+
derivationPath,
|
|
273
|
+
},
|
|
274
|
+
});
|
|
275
|
+
return { status: ResultStatus.Detached };
|
|
276
|
+
}
|
|
277
|
+
|
|
259
278
|
return await runConnect(type, namespaces);
|
|
260
279
|
};
|
|
261
280
|
|
|
@@ -14,7 +14,10 @@ export interface NeedsNamespacesState {
|
|
|
14
14
|
|
|
15
15
|
export interface DetachedPayload {
|
|
16
16
|
targetWallet: ExtendedModalWalletInfo;
|
|
17
|
-
selectedNamespaces:
|
|
17
|
+
selectedNamespaces:
|
|
18
|
+
| { namespace: Namespace; derivationPath?: string }[]
|
|
19
|
+
| null;
|
|
20
|
+
derivationPath?: string;
|
|
18
21
|
}
|
|
19
22
|
|
|
20
23
|
export interface NeedsDerivationPathState {
|
|
@@ -89,23 +89,23 @@ export function WalletsPage() {
|
|
|
89
89
|
</Typography>
|
|
90
90
|
<ListContainer>
|
|
91
91
|
{filteredWallets.map((wallet, index) => {
|
|
92
|
-
const
|
|
93
|
-
const namespacesState = walletState.namespaces;
|
|
92
|
+
const namespacesState = state(wallet.type).namespaces;
|
|
94
93
|
const key = `wallet-${index}-${wallet.type}`;
|
|
95
94
|
const isWalletPartiallyConnected = checkIsWalletPartiallyConnected(
|
|
96
95
|
wallet,
|
|
97
96
|
namespacesState
|
|
98
97
|
);
|
|
99
98
|
|
|
99
|
+
let walletState = wallet.state;
|
|
100
|
+
if (isWalletPartiallyConnected) {
|
|
101
|
+
// If the wallet is connected to only a subset of namespaces, and the user has the option to connect to additional ones, we label the wallet as `Partially Connected`
|
|
102
|
+
walletState = WalletState.PARTIALLY_CONNECTED;
|
|
103
|
+
}
|
|
100
104
|
return (
|
|
101
105
|
<Wallet
|
|
102
106
|
key={key}
|
|
103
107
|
{...wallet}
|
|
104
|
-
state={
|
|
105
|
-
isWalletPartiallyConnected
|
|
106
|
-
? WalletState.PARTIALLY_CONNECTED
|
|
107
|
-
: wallet.state
|
|
108
|
-
}
|
|
108
|
+
state={walletState}
|
|
109
109
|
hasDeepLink={checkHasDeepLink(wallet.type)}
|
|
110
110
|
link={getWalletLink(wallet.type)}
|
|
111
111
|
container={getContainer()}
|
package/src/utils/wallets.ts
CHANGED
|
@@ -551,7 +551,11 @@ export function checkIsWalletPartiallyConnected(
|
|
|
551
551
|
(namespace) => !namespace.unsupported
|
|
552
552
|
);
|
|
553
553
|
|
|
554
|
-
|
|
555
|
-
|
|
554
|
+
// If the wallet is connected to only a subset of namespaces, and the user has the option to connect to additional ones, we label the wallet as `Partially Connected`
|
|
555
|
+
return (
|
|
556
|
+
wallet.needsNamespace.selection === 'multiple' &&
|
|
557
|
+
supportedNamespaces.some(
|
|
558
|
+
(namespace) => !namespacesState?.get(namespace.value)?.connected
|
|
559
|
+
)
|
|
556
560
|
);
|
|
557
561
|
}
|