@rango-dev/widget-embedded 0.31.1-next.2 → 0.31.1-next.3
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/components/ConfirmWalletsModal/WalletList.d.ts.map +1 -1
- package/dist/components/StatefulConnectModal/StatefulConnectModal.d.ts +11 -0
- package/dist/components/StatefulConnectModal/StatefulConnectModal.d.ts.map +1 -0
- package/dist/components/StatefulConnectModal/helpers.d.ts +10 -0
- package/dist/components/StatefulConnectModal/helpers.d.ts.map +1 -0
- package/dist/components/StatefulConnectModal/index.d.ts +2 -0
- package/dist/components/StatefulConnectModal/index.d.ts.map +1 -0
- package/dist/components/SwapDetailsModal/SwapDetailsModal.WalletState.d.ts.map +1 -1
- package/dist/components/WalletStatefulConnect/ConnectStatus.d.ts +4 -0
- package/dist/components/WalletStatefulConnect/ConnectStatus.d.ts.map +1 -0
- package/dist/components/{WalletModal/WalletModalContent.styles.d.ts → WalletStatefulConnect/ConnectStatus.styles.d.ts} +1 -1
- package/dist/components/{WalletModal/WalletModalContent.styles.d.ts.map → WalletStatefulConnect/ConnectStatus.styles.d.ts.map} +1 -1
- package/dist/components/WalletStatefulConnect/ConnectStatus.types.d.ts +8 -0
- package/dist/components/WalletStatefulConnect/ConnectStatus.types.d.ts.map +1 -0
- package/dist/components/WalletStatefulConnect/DerivationPath.d.ts +4 -0
- package/dist/components/WalletStatefulConnect/DerivationPath.d.ts.map +1 -0
- package/dist/components/WalletStatefulConnect/DerivationPath.helpers.d.ts +4 -0
- package/dist/components/WalletStatefulConnect/DerivationPath.helpers.d.ts.map +1 -0
- package/dist/components/{WalletDerivationPathModal/WalletDerivationPathModal.styles.d.ts → WalletStatefulConnect/DerivationPath.styles.d.ts} +1 -1
- package/dist/components/WalletStatefulConnect/DerivationPath.styles.d.ts.map +1 -0
- package/dist/components/WalletStatefulConnect/DerivationPath.types.d.ts +6 -0
- package/dist/components/WalletStatefulConnect/DerivationPath.types.d.ts.map +1 -0
- package/dist/components/WalletStatefulConnect/ExperimentalChain.d.ts +8 -0
- package/dist/components/WalletStatefulConnect/ExperimentalChain.d.ts.map +1 -0
- package/dist/components/WalletStatefulConnect/ExperimentalChainStatus.d.ts +4 -0
- package/dist/components/WalletStatefulConnect/ExperimentalChainStatus.d.ts.map +1 -0
- package/dist/components/WalletStatefulConnect/ExperimentalChainStatus.helpers.d.ts +8 -0
- package/dist/components/WalletStatefulConnect/ExperimentalChainStatus.helpers.d.ts.map +1 -0
- package/dist/components/WalletStatefulConnect/ExperimentalChainStatus.types.d.ts +6 -0
- package/dist/components/WalletStatefulConnect/ExperimentalChainStatus.types.d.ts.map +1 -0
- package/dist/components/WalletStatefulConnect/Namespaces.d.ts +4 -0
- package/dist/components/WalletStatefulConnect/Namespaces.d.ts.map +1 -0
- package/dist/components/WalletStatefulConnect/Namespaces.helpers.d.ts +3 -0
- package/dist/components/WalletStatefulConnect/Namespaces.helpers.d.ts.map +1 -0
- package/dist/components/{WalletNamespacesModal/WalletNamespacesModal.styles.d.ts → WalletStatefulConnect/Namespaces.styles.d.ts} +1 -1
- package/dist/components/WalletStatefulConnect/Namespaces.styles.d.ts.map +1 -0
- package/dist/components/WalletStatefulConnect/Namespaces.types.d.ts +7 -0
- package/dist/components/WalletStatefulConnect/Namespaces.types.d.ts.map +1 -0
- package/dist/components/WalletStatefulConnect/index.d.ts +5 -0
- package/dist/components/WalletStatefulConnect/index.d.ts.map +1 -0
- package/dist/hooks/useStatefulConnect/index.d.ts +5 -0
- package/dist/hooks/useStatefulConnect/index.d.ts.map +1 -0
- package/dist/hooks/useStatefulConnect/useStatefulConnect.d.ts +25 -0
- package/dist/hooks/useStatefulConnect/useStatefulConnect.d.ts.map +1 -0
- package/dist/hooks/useStatefulConnect/useStatefulConnect.helpers.d.ts +8 -0
- package/dist/hooks/useStatefulConnect/useStatefulConnect.helpers.d.ts.map +1 -0
- package/dist/hooks/useStatefulConnect/useStatefulConnect.state.d.ts +9 -0
- package/dist/hooks/useStatefulConnect/useStatefulConnect.state.d.ts.map +1 -0
- package/dist/hooks/useStatefulConnect/useStatefulConnect.types.d.ts +43 -0
- package/dist/hooks/useStatefulConnect/useStatefulConnect.types.d.ts.map +1 -0
- package/dist/hooks/useWalletList.d.ts +11 -14
- package/dist/hooks/useWalletList.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +4 -4
- package/dist/pages/WalletsPage.d.ts +0 -2
- package/dist/pages/WalletsPage.d.ts.map +1 -1
- package/dist/widget-embedded.build.json +1 -1
- package/package.json +2 -2
- package/src/components/ConfirmWalletsModal/WalletList.tsx +52 -243
- package/src/components/HeaderButtons/WalletButton.tsx +1 -1
- package/src/components/StatefulConnectModal/StatefulConnectModal.tsx +168 -0
- package/src/components/StatefulConnectModal/helpers.ts +23 -0
- package/src/components/StatefulConnectModal/index.ts +1 -0
- package/src/components/SwapDetailsModal/SwapDetailsModal.WalletState.tsx +23 -113
- package/src/components/{WalletModal/WalletModalContent.tsx → WalletStatefulConnect/ConnectStatus.tsx} +13 -5
- package/src/components/WalletStatefulConnect/ConnectStatus.types.ts +11 -0
- package/src/components/WalletStatefulConnect/DerivationPath.helpers.ts +23 -0
- package/src/components/{WalletDerivationPathModal/WalletDerivationPathModal.tsx → WalletStatefulConnect/DerivationPath.tsx} +18 -36
- package/src/components/WalletStatefulConnect/DerivationPath.types.ts +6 -0
- package/src/components/WalletStatefulConnect/ExperimentalChain.tsx +36 -0
- package/src/components/WalletStatefulConnect/ExperimentalChainStatus.helpers.ts +53 -0
- package/src/components/WalletStatefulConnect/ExperimentalChainStatus.tsx +35 -0
- package/src/components/WalletStatefulConnect/ExperimentalChainStatus.types.ts +5 -0
- package/src/components/WalletStatefulConnect/Namespaces.helpers.ts +9 -0
- package/src/components/{WalletNamespacesModal/WalletNamespacesModal.tsx → WalletStatefulConnect/Namespaces.tsx} +9 -27
- package/src/components/{WalletNamespacesModal/WalletNamespacesModal.types.tsx → WalletStatefulConnect/Namespaces.types.tsx} +2 -5
- package/src/components/WalletStatefulConnect/index.ts +4 -0
- package/src/hooks/useStatefulConnect/index.ts +9 -0
- package/src/hooks/useStatefulConnect/useStatefulConnect.helpers.ts +13 -0
- package/src/hooks/useStatefulConnect/useStatefulConnect.state.ts +45 -0
- package/src/hooks/useStatefulConnect/useStatefulConnect.ts +232 -0
- package/src/hooks/useStatefulConnect/useStatefulConnect.types.ts +56 -0
- package/src/hooks/useWalletList.ts +22 -53
- package/src/pages/WalletsPage.tsx +10 -162
- package/dist/components/WalletDerivationPathModal/WalletDerivationPathModal.d.ts +0 -4
- package/dist/components/WalletDerivationPathModal/WalletDerivationPathModal.d.ts.map +0 -1
- package/dist/components/WalletDerivationPathModal/WalletDerivationPathModal.styles.d.ts.map +0 -1
- package/dist/components/WalletDerivationPathModal/WalletDerivationPathModal.types.d.ts +0 -10
- package/dist/components/WalletDerivationPathModal/WalletDerivationPathModal.types.d.ts.map +0 -1
- package/dist/components/WalletDerivationPathModal/index.d.ts +0 -2
- package/dist/components/WalletDerivationPathModal/index.d.ts.map +0 -1
- package/dist/components/WalletModal/WalletModal.d.ts +0 -4
- package/dist/components/WalletModal/WalletModal.d.ts.map +0 -1
- package/dist/components/WalletModal/WalletModal.types.d.ts +0 -10
- package/dist/components/WalletModal/WalletModal.types.d.ts.map +0 -1
- package/dist/components/WalletModal/WalletModalContent.d.ts +0 -4
- package/dist/components/WalletModal/WalletModalContent.d.ts.map +0 -1
- package/dist/components/WalletModal/index.d.ts +0 -2
- package/dist/components/WalletModal/index.d.ts.map +0 -1
- package/dist/components/WalletNamespacesModal/WalletNamespacesModal.d.ts +0 -4
- package/dist/components/WalletNamespacesModal/WalletNamespacesModal.d.ts.map +0 -1
- package/dist/components/WalletNamespacesModal/WalletNamespacesModal.styles.d.ts.map +0 -1
- package/dist/components/WalletNamespacesModal/WalletNamespacesModal.types.d.ts +0 -10
- package/dist/components/WalletNamespacesModal/WalletNamespacesModal.types.d.ts.map +0 -1
- package/dist/components/WalletNamespacesModal/index.d.ts +0 -2
- package/dist/components/WalletNamespacesModal/index.d.ts.map +0 -1
- package/src/components/WalletDerivationPathModal/WalletDerivationPathModal.types.tsx +0 -10
- package/src/components/WalletDerivationPathModal/index.ts +0 -1
- package/src/components/WalletModal/WalletModal.tsx +0 -25
- package/src/components/WalletModal/WalletModal.types.ts +0 -11
- package/src/components/WalletModal/index.ts +0 -1
- package/src/components/WalletNamespacesModal/index.ts +0 -1
- /package/src/components/{WalletModal/WalletModalContent.styles.ts → WalletStatefulConnect/ConnectStatus.styles.ts} +0 -0
- /package/src/components/{WalletDerivationPathModal/WalletDerivationPathModal.styles.ts → WalletStatefulConnect/DerivationPath.styles.ts} +0 -0
- /package/src/components/{WalletNamespacesModal/WalletNamespacesModal.styles.ts → WalletStatefulConnect/Namespaces.styles.ts} +0 -0
|
@@ -1,33 +1,18 @@
|
|
|
1
1
|
import type { WalletStateContentProps } from './SwapDetailsModal.types';
|
|
2
|
-
import type {
|
|
2
|
+
import type { WalletInfoWithExtra } from '../../types';
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import { warn } from '@rango-dev/logging-core';
|
|
5
5
|
import { MessageBox, Wallet } from '@rango-dev/ui';
|
|
6
6
|
import { useWallets } from '@rango-dev/wallets-react';
|
|
7
7
|
import React, { useState } from 'react';
|
|
8
8
|
|
|
9
|
+
import { useWalletList } from '../../hooks/useWalletList';
|
|
9
10
|
import { getContainer } from '../../utils/common';
|
|
10
11
|
import { mapStatusToWalletState } from '../../utils/wallets';
|
|
11
|
-
import {
|
|
12
|
-
import { WalletNamespacesModal } from '../WalletNamespacesModal';
|
|
12
|
+
import { StatefulConnectModal } from '../StatefulConnectModal';
|
|
13
13
|
|
|
14
14
|
import { WalletContainer } from './SwapDetailsModal.styles';
|
|
15
15
|
|
|
16
|
-
interface NamespacesModalState {
|
|
17
|
-
open: boolean;
|
|
18
|
-
providerType: string;
|
|
19
|
-
providerImage: string;
|
|
20
|
-
availableNamespaces?: Namespace[];
|
|
21
|
-
singleNamespace?: boolean;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
interface DerivationPathModalState {
|
|
25
|
-
open: boolean;
|
|
26
|
-
providerType: string;
|
|
27
|
-
providerImage: string;
|
|
28
|
-
namespace: Namespace;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
16
|
export const WalletStateContent = (props: WalletStateContentProps) => {
|
|
32
17
|
const {
|
|
33
18
|
type,
|
|
@@ -37,11 +22,9 @@ export const WalletStateContent = (props: WalletStateContentProps) => {
|
|
|
37
22
|
showWalletButton,
|
|
38
23
|
walletButtonDisabled,
|
|
39
24
|
} = props;
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
const [derivationPathModalState, setDerivationPathModalState] =
|
|
44
|
-
useState<DerivationPathModalState | null>(null);
|
|
25
|
+
const [selectedWalletToConnect, setSelectedWalletToConnect] =
|
|
26
|
+
useState<WalletInfoWithExtra>();
|
|
27
|
+
const { getWalletInfo, state } = useWallets();
|
|
45
28
|
const walletType = currentStepWallet?.walletType;
|
|
46
29
|
const walletState = walletType
|
|
47
30
|
? mapStatusToWalletState(state(walletType))
|
|
@@ -49,87 +32,24 @@ export const WalletStateContent = (props: WalletStateContentProps) => {
|
|
|
49
32
|
const walletInfo = walletType ? getWalletInfo(walletType) : null;
|
|
50
33
|
const shouldShowWallet =
|
|
51
34
|
showWalletButton && !!walletType && !!walletState && !!walletInfo;
|
|
52
|
-
|
|
53
|
-
const handleCloseNamespaceModal = () => {
|
|
54
|
-
if (namespacesModalState) {
|
|
55
|
-
setNamespacesModalState({
|
|
56
|
-
...namespacesModalState,
|
|
57
|
-
open: false,
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
const handleCloseDerivationPathModal = () => {
|
|
63
|
-
if (derivationPathModalState) {
|
|
64
|
-
setDerivationPathModalState({
|
|
65
|
-
...derivationPathModalState,
|
|
66
|
-
open: false,
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
};
|
|
35
|
+
const { list } = useWalletList();
|
|
70
36
|
|
|
71
37
|
const handleWalletItemClick = () => {
|
|
72
|
-
if (!!walletType
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
providerType: walletType,
|
|
78
|
-
providerImage: walletInfo.img,
|
|
79
|
-
availableNamespaces: walletInfo.namespaces,
|
|
80
|
-
singleNamespace: walletInfo.singleNamespace,
|
|
81
|
-
});
|
|
82
|
-
} else if (walletInfo.needsDerivationPath) {
|
|
83
|
-
setDerivationPathModalState({
|
|
84
|
-
open: true,
|
|
85
|
-
providerType: walletType,
|
|
86
|
-
providerImage: walletInfo.img,
|
|
87
|
-
namespace: walletInfo.namespaces[0],
|
|
88
|
-
});
|
|
89
|
-
} else {
|
|
90
|
-
connect(walletType).catch((error) => debug(error));
|
|
91
|
-
}
|
|
38
|
+
if (!!walletType) {
|
|
39
|
+
const wallet = list.find((wallet) => wallet.type === walletType);
|
|
40
|
+
|
|
41
|
+
if (wallet) {
|
|
42
|
+
setSelectedWalletToConnect(wallet);
|
|
92
43
|
} else {
|
|
93
|
-
|
|
44
|
+
warn(
|
|
45
|
+
new Error(
|
|
46
|
+
`It seems requested wallet to be connected is not available in the list. requested wallet: ${wallet}`
|
|
47
|
+
)
|
|
48
|
+
);
|
|
94
49
|
}
|
|
95
50
|
}
|
|
96
51
|
};
|
|
97
52
|
|
|
98
|
-
const handleConfirmNamespaces = (selectedNamespaces: Namespace[]) => {
|
|
99
|
-
if (
|
|
100
|
-
!!walletInfo?.needsDerivationPath &&
|
|
101
|
-
walletInfo?.singleNamespace &&
|
|
102
|
-
selectedNamespaces[0] &&
|
|
103
|
-
walletType
|
|
104
|
-
) {
|
|
105
|
-
setDerivationPathModalState({
|
|
106
|
-
open: true,
|
|
107
|
-
providerType: walletType,
|
|
108
|
-
providerImage: walletInfo.img,
|
|
109
|
-
namespace: selectedNamespaces[0],
|
|
110
|
-
});
|
|
111
|
-
} else {
|
|
112
|
-
connect(
|
|
113
|
-
namespacesModalState?.providerType as string,
|
|
114
|
-
undefined,
|
|
115
|
-
selectedNamespaces.map((namespace) => ({
|
|
116
|
-
namespace,
|
|
117
|
-
}))
|
|
118
|
-
).catch((error) => debug(error));
|
|
119
|
-
}
|
|
120
|
-
handleCloseNamespaceModal();
|
|
121
|
-
};
|
|
122
|
-
|
|
123
|
-
const handleDerivationPathConfirm = (derivationPath: string) => {
|
|
124
|
-
if (derivationPath && derivationPathModalState?.namespace) {
|
|
125
|
-
connect(derivationPathModalState?.providerType, undefined, [
|
|
126
|
-
{ namespace: derivationPathModalState.namespace, derivationPath },
|
|
127
|
-
]).catch((error) => debug(error));
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
handleCloseDerivationPathModal();
|
|
131
|
-
};
|
|
132
|
-
|
|
133
53
|
return (
|
|
134
54
|
<>
|
|
135
55
|
<MessageBox type={type} title={title} description={message} />
|
|
@@ -148,21 +68,11 @@ export const WalletStateContent = (props: WalletStateContentProps) => {
|
|
|
148
68
|
/>
|
|
149
69
|
</WalletContainer>
|
|
150
70
|
)}
|
|
151
|
-
<
|
|
152
|
-
|
|
153
|
-
onClose={
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
availableNamespaces={namespacesModalState?.availableNamespaces}
|
|
157
|
-
singleNamespace={namespacesModalState?.singleNamespace}
|
|
158
|
-
/>
|
|
159
|
-
<WalletDerivationPathModal
|
|
160
|
-
open={!!derivationPathModalState?.open}
|
|
161
|
-
selectedNamespace={derivationPathModalState?.namespace}
|
|
162
|
-
type={derivationPathModalState?.providerType}
|
|
163
|
-
image={derivationPathModalState?.providerImage}
|
|
164
|
-
onClose={handleCloseDerivationPathModal}
|
|
165
|
-
onConfirm={handleDerivationPathConfirm}
|
|
71
|
+
<StatefulConnectModal
|
|
72
|
+
wallet={selectedWalletToConnect}
|
|
73
|
+
onClose={() => {
|
|
74
|
+
setSelectedWalletToConnect(undefined);
|
|
75
|
+
}}
|
|
166
76
|
/>
|
|
167
77
|
</>
|
|
168
78
|
);
|
|
@@ -1,18 +1,26 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ConnectStatusProps } from './ConnectStatus.types';
|
|
2
2
|
|
|
3
3
|
import { i18n } from '@lingui/core';
|
|
4
4
|
import { Image, MessageBox, WalletState } from '@rango-dev/ui';
|
|
5
|
+
import { useWallets } from '@rango-dev/wallets-react';
|
|
5
6
|
import React from 'react';
|
|
6
7
|
|
|
8
|
+
import { mapStatusToWalletState } from '../../utils/wallets';
|
|
9
|
+
|
|
7
10
|
import {
|
|
8
11
|
LogoContainer,
|
|
9
12
|
Spinner,
|
|
10
13
|
WalletImageContainer,
|
|
11
|
-
} from './
|
|
14
|
+
} from './ConnectStatus.styles';
|
|
15
|
+
|
|
16
|
+
export function ConnectStatus(props: ConnectStatusProps) {
|
|
17
|
+
// See `wallet` notes on its type definition
|
|
18
|
+
const { wallet, error } = props;
|
|
19
|
+
const { type, image } = wallet;
|
|
20
|
+
const { state } = useWallets();
|
|
21
|
+
const walletState = mapStatusToWalletState(state(type));
|
|
12
22
|
|
|
13
|
-
|
|
14
|
-
const { state, image, error } = props;
|
|
15
|
-
if (state === WalletState.CONNECTED) {
|
|
23
|
+
if (walletState === WalletState.CONNECTED) {
|
|
16
24
|
return (
|
|
17
25
|
<MessageBox
|
|
18
26
|
type="success"
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export interface ConnectStatusProps {
|
|
2
|
+
/*
|
|
3
|
+
* We can not use `WalletInfoWithExtra` because the inside state will be stale in some cases.
|
|
4
|
+
* We should directly use `useWallets` to make sure we have a correct state.
|
|
5
|
+
*/
|
|
6
|
+
wallet: {
|
|
7
|
+
type: string;
|
|
8
|
+
image: string;
|
|
9
|
+
};
|
|
10
|
+
error?: string;
|
|
11
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { DerivationPath, Namespace } from '@rango-dev/wallets-shared';
|
|
2
|
+
|
|
3
|
+
import { namespaces } from '@rango-dev/wallets-shared';
|
|
4
|
+
|
|
5
|
+
export const CUSTOM_DERIVATION_PATH: DerivationPath = {
|
|
6
|
+
id: 'custom',
|
|
7
|
+
label: 'Custom',
|
|
8
|
+
generateDerivationPath: (index: string) => index,
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export function getDerivationPaths(
|
|
12
|
+
selectedNamespace?: Namespace
|
|
13
|
+
): DerivationPath[] {
|
|
14
|
+
const selectedNamespaceDerivationPaths = selectedNamespace
|
|
15
|
+
? namespaces[selectedNamespace].derivationPaths
|
|
16
|
+
: null;
|
|
17
|
+
|
|
18
|
+
const derivationPaths: DerivationPath[] = !!selectedNamespaceDerivationPaths
|
|
19
|
+
? [...selectedNamespaceDerivationPaths, CUSTOM_DERIVATION_PATH]
|
|
20
|
+
: [];
|
|
21
|
+
|
|
22
|
+
return derivationPaths;
|
|
23
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { PropTypes } from './
|
|
2
|
-
import type { DerivationPath
|
|
1
|
+
import type { PropTypes } from './DerivationPath.types';
|
|
2
|
+
import type { DerivationPath } from '@rango-dev/wallets-shared';
|
|
3
3
|
|
|
4
4
|
import { i18n } from '@lingui/core';
|
|
5
5
|
import {
|
|
@@ -10,43 +10,30 @@ import {
|
|
|
10
10
|
Select,
|
|
11
11
|
TextField,
|
|
12
12
|
} from '@rango-dev/ui';
|
|
13
|
-
import { namespaces } from '@rango-dev/wallets-shared';
|
|
14
13
|
import React, { useEffect, useState } from 'react';
|
|
15
14
|
|
|
16
|
-
import { WIDGET_UI_ID } from '../../constants';
|
|
17
|
-
import { WatermarkedModal } from '../common/WatermarkedModal';
|
|
18
15
|
import {
|
|
19
16
|
LogoContainer,
|
|
20
17
|
Spinner,
|
|
21
18
|
WalletImageContainer,
|
|
22
|
-
} from '
|
|
23
|
-
|
|
19
|
+
} from './ConnectStatus.styles';
|
|
20
|
+
import {
|
|
21
|
+
CUSTOM_DERIVATION_PATH,
|
|
22
|
+
getDerivationPaths,
|
|
23
|
+
} from './DerivationPath.helpers';
|
|
24
24
|
import {
|
|
25
25
|
derivationPathInputStyles,
|
|
26
26
|
InputLabel,
|
|
27
27
|
InputsContainer,
|
|
28
|
-
} from './
|
|
29
|
-
|
|
30
|
-
const customDerivationPath: DerivationPath = {
|
|
31
|
-
id: 'custom',
|
|
32
|
-
label: 'Custom',
|
|
33
|
-
generateDerivationPath: (index: string) => index,
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
function getDerivationPaths(selectedNamespace?: Namespace) {
|
|
37
|
-
const selectedNamespaceDerivationPaths = selectedNamespace
|
|
38
|
-
? namespaces[selectedNamespace].derivationPaths
|
|
39
|
-
: null;
|
|
40
|
-
|
|
41
|
-
const derivationPaths: DerivationPath[] = !!selectedNamespaceDerivationPaths
|
|
42
|
-
? [...selectedNamespaceDerivationPaths, customDerivationPath]
|
|
43
|
-
: [];
|
|
44
|
-
|
|
45
|
-
return derivationPaths;
|
|
46
|
-
}
|
|
28
|
+
} from './DerivationPath.styles';
|
|
47
29
|
|
|
48
|
-
export function
|
|
49
|
-
const {
|
|
30
|
+
export function DerivationPath(props: PropTypes) {
|
|
31
|
+
const { onConfirm } = props;
|
|
32
|
+
const {
|
|
33
|
+
namespace: selectedNamespace,
|
|
34
|
+
providerImage: image,
|
|
35
|
+
providerType: type,
|
|
36
|
+
} = props.value;
|
|
50
37
|
|
|
51
38
|
const [selectedDerivationPathId, setSelectedDerivationPathId] = useState<
|
|
52
39
|
string | null
|
|
@@ -54,7 +41,7 @@ export function WalletDerivationPathModal(props: PropTypes) {
|
|
|
54
41
|
const [derivationPathIndex, setDerivationPathIndex] = useState('0');
|
|
55
42
|
|
|
56
43
|
const isCustomOptionSelected =
|
|
57
|
-
selectedDerivationPathId ===
|
|
44
|
+
selectedDerivationPathId === CUSTOM_DERIVATION_PATH.id;
|
|
58
45
|
|
|
59
46
|
const derivationPaths = getDerivationPaths(selectedNamespace);
|
|
60
47
|
|
|
@@ -89,12 +76,7 @@ export function WalletDerivationPathModal(props: PropTypes) {
|
|
|
89
76
|
}, [selectedNamespace]);
|
|
90
77
|
|
|
91
78
|
return (
|
|
92
|
-
|
|
93
|
-
open={open}
|
|
94
|
-
onClose={onClose}
|
|
95
|
-
container={
|
|
96
|
-
document.getElementById(WIDGET_UI_ID.SWAP_BOX_ID) || document.body
|
|
97
|
-
}>
|
|
79
|
+
<>
|
|
98
80
|
<Divider size={20} />
|
|
99
81
|
<MessageBox
|
|
100
82
|
type="info"
|
|
@@ -149,6 +131,6 @@ export function WalletDerivationPathModal(props: PropTypes) {
|
|
|
149
131
|
}>
|
|
150
132
|
{i18n.t('Confirm')}
|
|
151
133
|
</Button>
|
|
152
|
-
|
|
134
|
+
</>
|
|
153
135
|
);
|
|
154
136
|
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { i18n } from '@lingui/core';
|
|
2
|
+
import { Button, Divider, MessageBox } from '@rango-dev/ui';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
|
|
5
|
+
interface PropTypes {
|
|
6
|
+
displayName?: string;
|
|
7
|
+
onConfirm: () => void;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function ExperimentalChain(props: PropTypes) {
|
|
11
|
+
const { displayName, onConfirm } = props;
|
|
12
|
+
|
|
13
|
+
return (
|
|
14
|
+
<MessageBox
|
|
15
|
+
title={i18n.t({
|
|
16
|
+
id: 'Add {blockchainDisplayName} Chain',
|
|
17
|
+
values: { blockchainDisplayName: displayName },
|
|
18
|
+
})}
|
|
19
|
+
type="warning"
|
|
20
|
+
description={i18n.t({
|
|
21
|
+
id: 'You should connect a {blockchainDisplayName} supported wallet or choose a different {blockchainDisplayName} address',
|
|
22
|
+
values: { blockchainDisplayName: displayName },
|
|
23
|
+
})}>
|
|
24
|
+
<Divider size={18} />
|
|
25
|
+
<Divider size={32} />
|
|
26
|
+
<Button
|
|
27
|
+
onClick={onConfirm}
|
|
28
|
+
variant="outlined"
|
|
29
|
+
type="primary"
|
|
30
|
+
fullWidth
|
|
31
|
+
size="large">
|
|
32
|
+
{i18n.t('Confirm')}
|
|
33
|
+
</Button>
|
|
34
|
+
</MessageBox>
|
|
35
|
+
);
|
|
36
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { PropTypes } from './ExperimentalChainStatus.types';
|
|
2
|
+
import type { MessageType } from '@rango-dev/ui';
|
|
3
|
+
|
|
4
|
+
import { i18n } from '@lingui/core';
|
|
5
|
+
|
|
6
|
+
export function generateMessageByStatus(
|
|
7
|
+
status: PropTypes['status'],
|
|
8
|
+
blockchainDisplayName: string | undefined
|
|
9
|
+
): {
|
|
10
|
+
type: MessageType;
|
|
11
|
+
title: string;
|
|
12
|
+
description: string;
|
|
13
|
+
} {
|
|
14
|
+
switch (status) {
|
|
15
|
+
case 'in-progress':
|
|
16
|
+
return {
|
|
17
|
+
type: 'loading',
|
|
18
|
+
title: i18n.t({
|
|
19
|
+
id: 'Add {blockchainDisplayName} Chain',
|
|
20
|
+
values: { blockchainDisplayName },
|
|
21
|
+
}),
|
|
22
|
+
description: i18n.t({
|
|
23
|
+
id: 'You should connect a {blockchainDisplayName} supported wallet or choose a different {blockchainDisplayName} address',
|
|
24
|
+
values: { blockchainDisplayName },
|
|
25
|
+
}),
|
|
26
|
+
};
|
|
27
|
+
case 'completed':
|
|
28
|
+
return {
|
|
29
|
+
type: 'success',
|
|
30
|
+
title: i18n.t({
|
|
31
|
+
id: '{blockchainDisplayName} Chain Added',
|
|
32
|
+
values: { blockchainDisplayName },
|
|
33
|
+
}),
|
|
34
|
+
description: i18n.t({
|
|
35
|
+
id: 'You should connect a {blockchainDisplayName} supported wallet or choose a different {blockchainDisplayName} address',
|
|
36
|
+
values: { blockchainDisplayName },
|
|
37
|
+
}),
|
|
38
|
+
};
|
|
39
|
+
case 'rejected':
|
|
40
|
+
return {
|
|
41
|
+
type: 'error',
|
|
42
|
+
title: i18n.t('Request Rejected'),
|
|
43
|
+
description: i18n.t({
|
|
44
|
+
id: "You've rejected adding {blockchainDisplayName} chain to your wallet.",
|
|
45
|
+
values: { blockchainDisplayName },
|
|
46
|
+
}),
|
|
47
|
+
};
|
|
48
|
+
default:
|
|
49
|
+
throw new Error(
|
|
50
|
+
`Showing information about an experimentation chain status needs to be defined first. status: ${status}`
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { PropTypes } from './ExperimentalChainStatus.types';
|
|
2
|
+
|
|
3
|
+
import { Image, MessageBox, Spinner } from '@rango-dev/ui';
|
|
4
|
+
import React from 'react';
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
LogoContainer,
|
|
8
|
+
WalletImageContainer,
|
|
9
|
+
} from '../ConfirmWalletsModal/WalletList.styles';
|
|
10
|
+
|
|
11
|
+
import { generateMessageByStatus } from './ExperimentalChainStatus.helpers';
|
|
12
|
+
|
|
13
|
+
export function ExperimentalChainStatus(props: PropTypes) {
|
|
14
|
+
const { status, displayName, image } = props;
|
|
15
|
+
const data = generateMessageByStatus(status, displayName);
|
|
16
|
+
const hasImage = status == 'in-progress';
|
|
17
|
+
|
|
18
|
+
return (
|
|
19
|
+
<MessageBox
|
|
20
|
+
type={data.type}
|
|
21
|
+
title={data.title}
|
|
22
|
+
description={data.description}
|
|
23
|
+
icon={
|
|
24
|
+
hasImage ? (
|
|
25
|
+
<LogoContainer>
|
|
26
|
+
<WalletImageContainer>
|
|
27
|
+
<Image src={image} size={45} />
|
|
28
|
+
</WalletImageContainer>
|
|
29
|
+
<Spinner />
|
|
30
|
+
</LogoContainer>
|
|
31
|
+
) : undefined
|
|
32
|
+
}
|
|
33
|
+
/>
|
|
34
|
+
);
|
|
35
|
+
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import type { PropTypes } from './
|
|
1
|
+
import type { PropTypes } from './Namespaces.types';
|
|
2
2
|
import type { Namespace } from '@rango-dev/wallets-shared';
|
|
3
|
-
import type { BlockchainMeta } from 'rango-sdk';
|
|
4
3
|
|
|
5
4
|
import { i18n } from '@lingui/core';
|
|
6
5
|
import {
|
|
@@ -16,27 +15,15 @@ import {
|
|
|
16
15
|
import { namespaces } from '@rango-dev/wallets-shared';
|
|
17
16
|
import React, { useMemo, useState } from 'react';
|
|
18
17
|
|
|
19
|
-
import { WIDGET_UI_ID } from '../../constants';
|
|
20
18
|
import { useAppStore } from '../../store/AppStore';
|
|
21
|
-
import { WatermarkedModal } from '../common/WatermarkedModal';
|
|
22
19
|
import { WalletImageContainer } from '../HeaderButtons/HeaderButtons.styles';
|
|
23
|
-
import {
|
|
24
|
-
LogoContainer,
|
|
25
|
-
Spinner,
|
|
26
|
-
} from '../WalletModal/WalletModalContent.styles';
|
|
27
|
-
|
|
28
|
-
import { NamespaceList } from './WalletNamespacesModal.styles';
|
|
29
20
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
) => {
|
|
34
|
-
return blockchains.find((blockchain) => blockchain.name === blockchainName)
|
|
35
|
-
?.logo;
|
|
36
|
-
};
|
|
21
|
+
import { LogoContainer, Spinner } from './ConnectStatus.styles';
|
|
22
|
+
import { getBlockchainLogo } from './Namespaces.helpers';
|
|
23
|
+
import { NamespaceList } from './Namespaces.styles';
|
|
37
24
|
|
|
38
|
-
export function
|
|
39
|
-
const { singleNamespace, availableNamespaces } = props;
|
|
25
|
+
export function Namespaces(props: PropTypes) {
|
|
26
|
+
const { singleNamespace, availableNamespaces, providerImage } = props.value;
|
|
40
27
|
|
|
41
28
|
const [selectedNamespaces, setSelectedNamespaces] = useState<Namespace[]>([]);
|
|
42
29
|
|
|
@@ -76,12 +63,7 @@ export function WalletNamespacesModal(props: PropTypes) {
|
|
|
76
63
|
};
|
|
77
64
|
|
|
78
65
|
return (
|
|
79
|
-
|
|
80
|
-
open={props.open}
|
|
81
|
-
onClose={props.onClose}
|
|
82
|
-
container={
|
|
83
|
-
document.getElementById(WIDGET_UI_ID.SWAP_BOX_ID) || document.body
|
|
84
|
-
}>
|
|
66
|
+
<>
|
|
85
67
|
<Divider size={20} />
|
|
86
68
|
<MessageBox
|
|
87
69
|
type="info"
|
|
@@ -92,7 +74,7 @@ export function WalletNamespacesModal(props: PropTypes) {
|
|
|
92
74
|
icon={
|
|
93
75
|
<LogoContainer>
|
|
94
76
|
<WalletImageContainer>
|
|
95
|
-
<Image src={
|
|
77
|
+
<Image src={providerImage} size={45} />
|
|
96
78
|
</WalletImageContainer>
|
|
97
79
|
<Spinner />
|
|
98
80
|
</LogoContainer>
|
|
@@ -132,6 +114,6 @@ export function WalletNamespacesModal(props: PropTypes) {
|
|
|
132
114
|
onClick={() => props.onConfirm(selectedNamespaces)}>
|
|
133
115
|
{i18n.t('Confirm')}
|
|
134
116
|
</Button>
|
|
135
|
-
|
|
117
|
+
</>
|
|
136
118
|
);
|
|
137
119
|
}
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
+
import type { NeedsNamespacesState } from '../../hooks/useStatefulConnect';
|
|
1
2
|
import type { Namespace } from '@rango-dev/wallets-shared';
|
|
2
3
|
|
|
3
4
|
export interface PropTypes {
|
|
4
|
-
open: boolean;
|
|
5
|
-
image?: string;
|
|
6
|
-
onClose: () => void;
|
|
7
5
|
onConfirm: (namespaces: Namespace[]) => void;
|
|
8
|
-
|
|
9
|
-
singleNamespace?: boolean;
|
|
6
|
+
value: NeedsNamespacesState;
|
|
10
7
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { useStatefulConnect } from './useStatefulConnect';
|
|
2
|
+
export { ResultStatus } from './useStatefulConnect.types';
|
|
3
|
+
export type {
|
|
4
|
+
NeedsNamespacesState,
|
|
5
|
+
NeedsDerivationPathState,
|
|
6
|
+
Result,
|
|
7
|
+
} from './useStatefulConnect.types';
|
|
8
|
+
|
|
9
|
+
export type { State } from './useStatefulConnect.state';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { State } from './useStatefulConnect.state';
|
|
2
|
+
|
|
3
|
+
export function isStateOnDerivationPathStep(
|
|
4
|
+
state: State
|
|
5
|
+
): state is State & { derivationPath: NonNullable<State['derivationPath']> } {
|
|
6
|
+
return !!state.derivationPath;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function isStateOnNamespace(
|
|
10
|
+
state: State
|
|
11
|
+
): state is State & { namespace: NonNullable<State['namespace']> } {
|
|
12
|
+
return !!state.namespace;
|
|
13
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
Actions,
|
|
3
|
+
NeedsDerivationPathState,
|
|
4
|
+
NeedsNamespacesState,
|
|
5
|
+
} from './useStatefulConnect.types';
|
|
6
|
+
|
|
7
|
+
export interface State {
|
|
8
|
+
status: 'init' | 'namespace' | 'derivationPath';
|
|
9
|
+
namespace: NeedsNamespacesState | null;
|
|
10
|
+
derivationPath: NeedsDerivationPathState | null;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export const initState: State = {
|
|
14
|
+
status: 'init',
|
|
15
|
+
namespace: null,
|
|
16
|
+
derivationPath: null,
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export function reducer(state: State, action: Actions): State {
|
|
20
|
+
switch (action.type) {
|
|
21
|
+
case 'needsNamespace':
|
|
22
|
+
return {
|
|
23
|
+
...state,
|
|
24
|
+
status: 'namespace',
|
|
25
|
+
namespace: action.payload,
|
|
26
|
+
derivationPath: null,
|
|
27
|
+
};
|
|
28
|
+
case 'needsDerivationPath':
|
|
29
|
+
return {
|
|
30
|
+
...state,
|
|
31
|
+
status: 'derivationPath',
|
|
32
|
+
derivationPath: action.payload,
|
|
33
|
+
};
|
|
34
|
+
case 'reset':
|
|
35
|
+
return initState;
|
|
36
|
+
case 'resetDerivation':
|
|
37
|
+
return {
|
|
38
|
+
...state,
|
|
39
|
+
derivationPath: null,
|
|
40
|
+
status: 'namespace',
|
|
41
|
+
};
|
|
42
|
+
default:
|
|
43
|
+
throw new Error(`Action hasn't been defined.`);
|
|
44
|
+
}
|
|
45
|
+
}
|