@rango-dev/widget-embedded 0.45.1-next.6 → 0.45.1-next.8

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.45.1-next.6",
3
+ "version": "0.45.1-next.8",
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.9.1-next.0",
28
- "@rango-dev/provider-all": "^0.48.1-next.2",
28
+ "@rango-dev/provider-all": "^0.48.1-next.3",
29
29
  "@rango-dev/queue-manager-core": "^0.30.1-next.0",
30
- "@rango-dev/queue-manager-rango-preset": "^0.47.1-next.3",
30
+ "@rango-dev/queue-manager-rango-preset": "^0.47.1-next.4",
31
31
  "@rango-dev/queue-manager-react": "^0.30.1-next.0",
32
32
  "@rango-dev/signer-solana": "^0.41.1-next.0",
33
- "@rango-dev/ui": "^0.48.1-next.5",
34
- "@rango-dev/wallets-core": "^0.45.1-next.2",
35
- "@rango-dev/wallets-react": "^0.32.1-next.2",
36
- "@rango-dev/wallets-shared": "^0.46.1-next.2",
33
+ "@rango-dev/ui": "^0.48.1-next.6",
34
+ "@rango-dev/wallets-core": "^0.45.1-next.3",
35
+ "@rango-dev/wallets-react": "^0.32.1-next.3",
36
+ "@rango-dev/wallets-shared": "^0.46.1-next.3",
37
37
  "bignumber.js": "^9.1.1",
38
38
  "copy-to-clipboard": "^3.3.3",
39
39
  "dayjs": "^1.11.7",
@@ -54,4 +54,4 @@
54
54
  "publishConfig": {
55
55
  "access": "public"
56
56
  }
57
- }
57
+ }
@@ -55,6 +55,7 @@ export function StatefulConnectModal(props: PropTypes) {
55
55
  handleNamespace,
56
56
  getState,
57
57
  resetState,
58
+ handleDisconnect,
58
59
  } = useStatefulConnect();
59
60
 
60
61
  const handleConfirmNamespaces = (selectedNamespaces: Namespace[]) => {
@@ -194,6 +195,9 @@ export function StatefulConnectModal(props: PropTypes) {
194
195
  {isOnDetached(getState) && (
195
196
  <Detached
196
197
  onConfirm={handleDetachedConfirm}
198
+ onDisconnectWallet={() =>
199
+ void handleDisconnect(getState().namespace.targetWallet)
200
+ }
197
201
  value={getState().namespace}
198
202
  selectedNamespaces={getState().selectedNamespaces}
199
203
  />
@@ -0,0 +1,6 @@
1
+ import { styled } from '@rango-dev/ui';
2
+
3
+ export const NamespacesHeader = styled('div', {
4
+ display: 'flex',
5
+ justifyContent: 'end',
6
+ });
@@ -1,18 +1,23 @@
1
1
  import type { PropTypes } from './Detached.types';
2
2
 
3
3
  import { i18n } from '@lingui/core';
4
- import { Divider, Image, MessageBox } from '@rango-dev/ui';
4
+ import { Button, Divider, Image, MessageBox } from '@rango-dev/ui';
5
+ import { useWallets } from '@rango-dev/wallets-react';
5
6
  import React from 'react';
6
7
 
7
8
  import { NamespaceUnsupportedItem } from '../NamespaceItem/NamespaceUnsupportedItem';
8
9
 
10
+ import { NamespacesHeader } from './Detached.styles';
9
11
  import { NamespaceDetachedItem } from './NamespaceDetachedItem';
10
12
  import { NamespaceList, StyledButton } from './Namespaces.styles';
11
13
 
12
14
  export function Detached(props: PropTypes) {
13
- const { selectedNamespaces, value } = props;
15
+ const { selectedNamespaces, value, onDisconnectWallet } = props;
14
16
  const { targetWallet } = value;
15
17
 
18
+ const { state } = useWallets();
19
+ const walletState = state(targetWallet.type);
20
+
16
21
  return (
17
22
  <>
18
23
  <MessageBox
@@ -25,7 +30,18 @@ export function Detached(props: PropTypes) {
25
30
  )}
26
31
  icon={<Image src={targetWallet.image} size={45} />}
27
32
  />
28
- <Divider size={20} />
33
+ <Divider size={30} />
34
+ <NamespacesHeader>
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>
29
45
  <NamespaceList id="widget-detached-namespace-list" as={'ul'}>
30
46
  {targetWallet.needsNamespace?.data.map((namespace, index, array) => (
31
47
  <React.Fragment key={namespace.id}>
@@ -4,5 +4,6 @@ import type { Namespace } from '@rango-dev/wallets-core/namespaces/common';
4
4
  export interface PropTypes {
5
5
  value: NeedsNamespacesState;
6
6
  onConfirm: () => void;
7
+ onDisconnectWallet: () => void;
7
8
  selectedNamespaces: Namespace[] | null;
8
9
  }
@@ -93,7 +93,7 @@ export const NamespaceDetachedItem = function NamespaceDetachedItem(
93
93
  id="widget-name-space-connect-btn"
94
94
  variant="ghost"
95
95
  type={namespaceState.connected ? 'error' : 'primary'}
96
- size="small"
96
+ size="xsmall"
97
97
  onClick={async () => handleButtonClick(namespaceState)}>
98
98
  {getButtonText()}
99
99
  </Button>
@@ -2,7 +2,7 @@ import { Button, styled } from '@rango-dev/ui';
2
2
 
3
3
  export const NamespaceList = styled('ul', {
4
4
  padding: 0,
5
- paddingTop: '$10',
5
+ paddingTop: '$16',
6
6
  paddingBottom: '$20',
7
7
  margin: 0,
8
8
  });
@@ -7,6 +7,7 @@ import { WalletState } from '@rango-dev/ui';
7
7
  import { useWallets } from '@rango-dev/wallets-react';
8
8
  import { useReducer } from 'react';
9
9
 
10
+ import { isOnDetached } from '../../components/StatefulConnectModal';
10
11
  import { type ExtendedModalWalletInfo } from '../../utils/wallets';
11
12
 
12
13
  import {
@@ -26,7 +27,7 @@ interface UseStatefulConnect {
26
27
  selectedNamespaces: Namespace[]
27
28
  ) => Promise<Result>;
28
29
  handleDerivationPath: (path: string) => Promise<Result>;
29
- handleDisconnect: (type: WalletType) => Promise<Result>;
30
+ handleDisconnect: (wallet: WalletInfoWithExtra) => Promise<Result>;
30
31
  getState(): State;
31
32
  resetState(section?: 'derivation'): void;
32
33
  }
@@ -163,7 +164,7 @@ export function useStatefulConnect(): UseStatefulConnect {
163
164
  }
164
165
 
165
166
  if (options?.disconnectIfConnected) {
166
- await handleDisconnect(wallet.type);
167
+ await handleDisconnect(wallet);
167
168
  return { status: ResultStatus.Disconnected };
168
169
  }
169
170
 
@@ -258,10 +259,25 @@ export function useStatefulConnect(): UseStatefulConnect {
258
259
  return await runConnect(type, namespaces);
259
260
  };
260
261
 
261
- const handleDisconnect = async (type: WalletType): Promise<Result> => {
262
- const wallet = state(type);
263
- if (wallet.connected || wallet.connecting) {
264
- await disconnect(type);
262
+ const getState = () => connectState;
263
+
264
+ const handleDisconnect = async (
265
+ wallet: ExtendedModalWalletInfo
266
+ ): Promise<Result> => {
267
+ const walletState = state(wallet.type);
268
+ if (walletState.connected || walletState.connecting) {
269
+ await disconnect(wallet.type);
270
+
271
+ if (isOnDetached(getState)) {
272
+ dispatch({
273
+ type: 'needsNamespace',
274
+ payload: {
275
+ targetWallet: wallet,
276
+ },
277
+ });
278
+ return { status: ResultStatus.Namespace };
279
+ }
280
+
265
281
  return { status: ResultStatus.Disconnected };
266
282
  }
267
283
 
@@ -273,7 +289,7 @@ export function useStatefulConnect(): UseStatefulConnect {
273
289
  handleDisconnect,
274
290
  handleNamespace,
275
291
  handleDerivationPath,
276
- getState: () => connectState,
292
+ getState,
277
293
  resetState: (section?: 'derivation') => {
278
294
  if (section === 'derivation') {
279
295
  dispatch({
@@ -78,7 +78,7 @@ export function useWalletList(params?: Params): API {
78
78
  wallets?.filter((wallet) => wallet.state === WalletState.CONNECTING) ||
79
79
  [];
80
80
  for (const wallet of connectingWallets) {
81
- void handleDisconnect(wallet.type);
81
+ void handleDisconnect(wallet);
82
82
  }
83
83
  }, [hashWalletsState(wallets)]);
84
84