@rango-dev/widget-embedded 0.32.2-next.0 → 0.32.2-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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rango-dev/widget-embedded",
3
- "version": "0.32.2-next.0",
3
+ "version": "0.32.2-next.10",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "source": "./src/index.ts",
@@ -25,19 +25,19 @@
25
25
  "@lingui/core": "4.2.1",
26
26
  "@lingui/react": "4.2.1",
27
27
  "@rango-dev/logging-core": "^0.6.0",
28
- "@rango-dev/provider-all": "^0.36.1-next.5",
28
+ "@rango-dev/provider-all": "^0.36.1-next.9",
29
29
  "@rango-dev/queue-manager-core": "^0.27.0",
30
- "@rango-dev/queue-manager-rango-preset": "^0.36.1-next.1",
30
+ "@rango-dev/queue-manager-rango-preset": "^0.36.1-next.2",
31
31
  "@rango-dev/queue-manager-react": "^0.27.0",
32
32
  "@rango-dev/signer-solana": "^0.31.1-next.1",
33
- "@rango-dev/ui": "^0.38.1-next.0",
33
+ "@rango-dev/ui": "^0.38.1-next.4",
34
34
  "@rango-dev/wallets-core": "^0.37.1-next.1",
35
- "@rango-dev/wallets-react": "^0.22.1-next.1",
36
- "@rango-dev/wallets-shared": "^0.36.1-next.1",
35
+ "@rango-dev/wallets-react": "^0.22.1-next.2",
36
+ "@rango-dev/wallets-shared": "^0.36.1-next.2",
37
37
  "bignumber.js": "^9.1.1",
38
38
  "copy-to-clipboard": "^3.3.3",
39
39
  "dayjs": "^1.11.7",
40
- "ethers": "^5.7.2",
40
+ "ethers": "^6.13.2",
41
41
  "immer": "^9.0.19",
42
42
  "mitt": "^3.0.0",
43
43
  "rango-sdk": "^0.1.49",
@@ -109,17 +109,15 @@ function Layout(props: PropsWithChildren<PropTypes>) {
109
109
  ref={containerRef}>
110
110
  <Header
111
111
  prefix={
112
- <>
113
- {showBackButton && (
114
- <BackButton
115
- onClick={() => {
116
- navigateBack();
117
- // As an example, used in routes page to add a custom logic when navigating back to the home page.
118
- header.onBack && header.onBack();
119
- }}
120
- />
121
- )}
122
- </>
112
+ showBackButton ? (
113
+ <BackButton
114
+ onClick={() => {
115
+ navigateBack();
116
+ // As an example, used in routes page to add a custom logic when navigating back to the home page.
117
+ header.onBack && header.onBack();
118
+ }}
119
+ />
120
+ ) : null
123
121
  }
124
122
  title={header.title}
125
123
  suffix={
@@ -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(handleClosingModal, KEEP_SUCCESS_MODAL_FOR);
116
+ successModalTimerId.current = setTimeout(
117
+ handleClosingModal,
118
+ KEEP_SUCCESS_MODAL_FOR
119
+ );
112
120
  } else if (resultIsDisconnected) {
113
121
  handleClosingModal();
114
122
  }
@@ -1 +1,2 @@
1
1
  export { StatefulConnectModal } from './StatefulConnectModal';
2
+ export { isOnNamespace, isOnDerivationPath } from './helpers';
@@ -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('0');
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
  };
@@ -81,9 +97,12 @@ export function DerivationPath(props: PropTypes) {
81
97
  <MessageBox
82
98
  type="info"
83
99
  title={i18n.t('Select Derivation Path')}
84
- description={i18n.t(
85
- `In order to connect to ${type}, you must first select a Derivation Path`
86
- )}
100
+ description={i18n.t({
101
+ id: 'In order to connect to {type}, you must first select a Derivation Path',
102
+ values: {
103
+ type,
104
+ },
105
+ })}
87
106
  icon={
88
107
  <LogoContainer>
89
108
  <WalletImageContainer>
@@ -51,9 +51,12 @@ export function useFetchCustomToken(): UseFetchCustomToken {
51
51
  case 'not-found':
52
52
  return {
53
53
  title: i18n.t('Token Not Found'),
54
- message: i18n.t(
55
- `Sorry, no token was found on ${blockchain} blockchain with the provided address. please make sure you have entered the right token address.`
56
- ),
54
+ message: i18n.t({
55
+ id: 'Sorry, no token was found on {blockchain} blockchain with the provided address. please make sure you have entered the right token address.',
56
+ values: {
57
+ blockchain,
58
+ },
59
+ }),
57
60
  };
58
61
  }
59
62
  }
@@ -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
- return {
38
- ...state,
39
- derivationPath: null,
40
- status: 'namespace',
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,