@rango-dev/widget-embedded 0.32.2-next.0 → 0.32.2-next.2
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/StatefulConnectModal/StatefulConnectModal.d.ts.map +1 -1
- package/dist/components/StatefulConnectModal/index.d.ts +1 -0
- package/dist/components/StatefulConnectModal/index.d.ts.map +1 -1
- package/dist/components/WalletStatefulConnect/DerivationPath.d.ts.map +1 -1
- package/dist/hooks/useStatefulConnect/useStatefulConnect.state.d.ts.map +1 -1
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +4 -4
- package/dist/widget-embedded.build.json +1 -1
- package/package.json +2 -2
- package/src/components/StatefulConnectModal/StatefulConnectModal.tsx +10 -2
- package/src/components/StatefulConnectModal/index.ts +1 -0
- package/src/components/WalletStatefulConnect/DerivationPath.tsx +17 -1
- package/src/hooks/useStatefulConnect/useStatefulConnect.state.ts +8 -5
- package/src/hooks/useStatefulConnect/useStatefulConnect.ts +1 -1
- package/src/index.ts +12 -0
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@ import type { WalletInfoWithExtra } from '../../types';
|
|
|
3
3
|
import type { Namespace } from '@rango-dev/wallets-shared';
|
|
4
4
|
|
|
5
5
|
import { Divider } from '@rango-dev/ui';
|
|
6
|
-
import React, { useEffect, useState } from 'react';
|
|
6
|
+
import React, { useEffect, useRef, useState } from 'react';
|
|
7
7
|
|
|
8
8
|
import {
|
|
9
9
|
ResultStatus,
|
|
@@ -31,6 +31,7 @@ interface PropTypes {
|
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
export function StatefulConnectModal(props: PropTypes) {
|
|
34
|
+
const successModalTimerId = useRef<ReturnType<typeof setTimeout>>();
|
|
34
35
|
const [isConnecting, setIsConnecting] = useState(false);
|
|
35
36
|
const [error, setError] = useState<string>();
|
|
36
37
|
const catchErrorOnHandle = (error: Error) => {
|
|
@@ -70,6 +71,10 @@ export function StatefulConnectModal(props: PropTypes) {
|
|
|
70
71
|
setError(undefined);
|
|
71
72
|
resetState();
|
|
72
73
|
setIsConnecting(false);
|
|
74
|
+
|
|
75
|
+
if (successModalTimerId.current) {
|
|
76
|
+
clearTimeout(successModalTimerId.current);
|
|
77
|
+
}
|
|
73
78
|
};
|
|
74
79
|
|
|
75
80
|
useEffect(() => {
|
|
@@ -108,7 +113,10 @@ export function StatefulConnectModal(props: PropTypes) {
|
|
|
108
113
|
}
|
|
109
114
|
|
|
110
115
|
if (resultIsConnected && !isImmediatelyConnected) {
|
|
111
|
-
setTimeout(
|
|
116
|
+
successModalTimerId.current = setTimeout(
|
|
117
|
+
handleClosingModal,
|
|
118
|
+
KEEP_SUCCESS_MODAL_FOR
|
|
119
|
+
);
|
|
112
120
|
} else if (resultIsDisconnected) {
|
|
113
121
|
handleClosingModal();
|
|
114
122
|
}
|
|
@@ -27,6 +27,8 @@ import {
|
|
|
27
27
|
InputsContainer,
|
|
28
28
|
} from './DerivationPath.styles';
|
|
29
29
|
|
|
30
|
+
const DEFAULT_DERIVATION_PATH_INDEX = '0';
|
|
31
|
+
|
|
30
32
|
export function DerivationPath(props: PropTypes) {
|
|
31
33
|
const { onConfirm } = props;
|
|
32
34
|
const {
|
|
@@ -38,7 +40,9 @@ export function DerivationPath(props: PropTypes) {
|
|
|
38
40
|
const [selectedDerivationPathId, setSelectedDerivationPathId] = useState<
|
|
39
41
|
string | null
|
|
40
42
|
>(null);
|
|
41
|
-
const [derivationPathIndex, setDerivationPathIndex] = useState(
|
|
43
|
+
const [derivationPathIndex, setDerivationPathIndex] = useState(
|
|
44
|
+
DEFAULT_DERIVATION_PATH_INDEX
|
|
45
|
+
);
|
|
42
46
|
|
|
43
47
|
const isCustomOptionSelected =
|
|
44
48
|
selectedDerivationPathId === CUSTOM_DERIVATION_PATH.id;
|
|
@@ -51,6 +55,18 @@ export function DerivationPath(props: PropTypes) {
|
|
|
51
55
|
);
|
|
52
56
|
|
|
53
57
|
if (selectedDerivationPath) {
|
|
58
|
+
/*
|
|
59
|
+
* Custom mode accepts string, but other modes only accepts number,
|
|
60
|
+
* Here we are checking if user is on custom mode and trying to switch to another mode
|
|
61
|
+
* if it's an string we will keep it, if not we will reset the value to default
|
|
62
|
+
*/
|
|
63
|
+
if (
|
|
64
|
+
selectedDerivationPathId === CUSTOM_DERIVATION_PATH.id &&
|
|
65
|
+
Number.isNaN(Number(derivationPathIndex))
|
|
66
|
+
) {
|
|
67
|
+
setDerivationPathIndex(DEFAULT_DERIVATION_PATH_INDEX);
|
|
68
|
+
}
|
|
69
|
+
|
|
54
70
|
setSelectedDerivationPathId(selectedDerivationPath.id);
|
|
55
71
|
}
|
|
56
72
|
};
|
|
@@ -34,11 +34,14 @@ export function reducer(state: State, action: Actions): State {
|
|
|
34
34
|
case 'reset':
|
|
35
35
|
return initState;
|
|
36
36
|
case 'resetDerivation':
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
37
|
+
if (state.namespace) {
|
|
38
|
+
return {
|
|
39
|
+
...state,
|
|
40
|
+
derivationPath: null,
|
|
41
|
+
status: 'namespace',
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
return initState;
|
|
42
45
|
default:
|
|
43
46
|
throw new Error(`Action hasn't been defined.`);
|
|
44
47
|
}
|
|
@@ -203,7 +203,7 @@ export function useStatefulConnect(): UseStatefulConnect {
|
|
|
203
203
|
|
|
204
204
|
const handleDisconnect = async (type: WalletType): Promise<Result> => {
|
|
205
205
|
const wallet = state(type);
|
|
206
|
-
if (wallet.connected) {
|
|
206
|
+
if (wallet.connected || wallet.connecting) {
|
|
207
207
|
await disconnect(type);
|
|
208
208
|
return { status: ResultStatus.Disconnected };
|
|
209
209
|
}
|
package/src/index.ts
CHANGED
|
@@ -57,6 +57,11 @@ import { useWallets, Events as WalletEvents } from '@rango-dev/wallets-react';
|
|
|
57
57
|
import { Networks, WalletTypes } from '@rango-dev/wallets-shared';
|
|
58
58
|
import { PendingSwapNetworkStatus } from 'rango-types';
|
|
59
59
|
|
|
60
|
+
import {
|
|
61
|
+
isOnDerivationPath,
|
|
62
|
+
isOnNamespace,
|
|
63
|
+
} from './components/StatefulConnectModal';
|
|
64
|
+
import { DerivationPath, Namespaces } from './components/WalletStatefulConnect';
|
|
60
65
|
import { WIDGET_UI_ID as UI_ID } from './constants';
|
|
61
66
|
import { SUPPORTED_FONTS } from './constants/fonts';
|
|
62
67
|
import { WidgetWallets } from './containers/Wallets';
|
|
@@ -76,6 +81,13 @@ import {
|
|
|
76
81
|
} from './types';
|
|
77
82
|
import { customizedThemeTokens } from './utils/ui';
|
|
78
83
|
|
|
84
|
+
export const StatefulConnect = {
|
|
85
|
+
DerivationPath,
|
|
86
|
+
Namespaces,
|
|
87
|
+
isOnDerivationPath,
|
|
88
|
+
isOnNamespace,
|
|
89
|
+
};
|
|
90
|
+
|
|
79
91
|
export type {
|
|
80
92
|
WidgetConfig,
|
|
81
93
|
WalletType,
|