@rango-dev/widget-embedded 0.51.1-next.4 → 0.51.1-next.6

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.51.1-next.4",
3
+ "version": "0.51.1-next.6",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "source": "./src/index.ts",
@@ -30,7 +30,7 @@
30
30
  "@rango-dev/queue-manager-rango-preset": "^0.53.1-next.1",
31
31
  "@rango-dev/queue-manager-react": "^0.32.1-next.0",
32
32
  "@rango-dev/signer-solana": "^0.44.0",
33
- "@rango-dev/ui": "^0.54.1-next.1",
33
+ "@rango-dev/ui": "^0.54.1-next.2",
34
34
  "@rango-dev/wallets-core": "^0.50.1-next.0",
35
35
  "@rango-dev/wallets-react": "^0.37.1-next.1",
36
36
  "@rango-dev/wallets-shared": "^0.51.1-next.0",
@@ -119,7 +119,9 @@ export function WalletList(props: PropTypes) {
119
119
  walletType: wallet.type,
120
120
  chain,
121
121
  });
122
- const isConnected = wallet.state === WalletState.CONNECTED;
122
+ const isConnected =
123
+ wallet.state === WalletState.CONNECTED ||
124
+ wallet.state === WalletState.PARTIALLY_CONNECTED;
123
125
  const conciseAddress = address
124
126
  ? getConciseAddress(address, ACCOUNT_ADDRESS_MAX_CHARACTERS)
125
127
  : '';
@@ -179,12 +181,16 @@ export function WalletList(props: PropTypes) {
179
181
  };
180
182
 
181
183
  const getWalletDescriptionColor = () => {
182
- if (wallet.state === WalletState.CONNECTED) {
184
+ if (
185
+ wallet.state === WalletState.CONNECTED ||
186
+ wallet.state === WalletState.PARTIALLY_CONNECTED
187
+ ) {
183
188
  if (isConnectedButDifferentThanTargetNamespace) {
184
189
  return 'neutral600';
185
190
  }
186
191
  return 'neutral700';
187
192
  }
193
+
188
194
  return info.color;
189
195
  };
190
196
 
@@ -1,7 +1,7 @@
1
1
  import type { PropTypes } from './HeaderButtons.types';
2
2
 
3
3
  import { i18n } from '@lingui/core';
4
- import { Image, Tooltip, WalletIcon } from '@rango-dev/ui';
4
+ import { Image, Tooltip, WalletIcon, WalletState } from '@rango-dev/ui';
5
5
  import React from 'react';
6
6
 
7
7
  import { useWalletList } from '../../hooks/useWalletList';
@@ -16,7 +16,9 @@ import {
16
16
  function WalletButton(props: PropTypes) {
17
17
  const { list } = useWalletList();
18
18
  const connectedWallets = list.filter(
19
- (wallet) => wallet.state === 'connected'
19
+ (wallet) =>
20
+ wallet.state === WalletState.CONNECTED ||
21
+ wallet.state === WalletState.PARTIALLY_CONNECTED
20
22
  );
21
23
  const content = !connectedWallets.length ? (
22
24
  i18n.t('Connect Wallet')
@@ -9,14 +9,14 @@ import { WalletState } from '@rango-dev/ui';
9
9
  import { useWallets } from '@rango-dev/wallets-react';
10
10
  import React from 'react';
11
11
 
12
- import { mapStatusToWalletState } from '../../utils/wallets';
12
+ import { getWalletConnectionStatus } from '../../utils/wallets';
13
13
 
14
14
  import { ConnectWalletContent } from './SwapDetailsModal.ConnectWallet';
15
15
  import { InstallWalletContent } from './SwapDetailsModal.InstallWallet';
16
16
 
17
17
  export const WalletStateContent = (props: WalletStateContentProps) => {
18
18
  const { swap, onClose } = props;
19
- const { state } = useWallets();
19
+ const { state, getWalletInfo } = useWallets();
20
20
 
21
21
  const currentStep = getCurrentStep(swap);
22
22
  const currentStepWallet = currentStep
@@ -25,7 +25,7 @@ export const WalletStateContent = (props: WalletStateContentProps) => {
25
25
 
26
26
  const walletType = currentStepWallet?.walletType;
27
27
  const walletState = walletType
28
- ? mapStatusToWalletState(state(walletType))
28
+ ? getWalletConnectionStatus(getWalletInfo(walletType), state(walletType))
29
29
  : null;
30
30
  const currentNamespace = currentStep
31
31
  ? getCurrentNamespaceOfOrNull(swap, currentStep)
@@ -10,7 +10,7 @@ import {
10
10
  import { useWallets } from '@rango-dev/wallets-react';
11
11
  import React from 'react';
12
12
 
13
- import { mapStatusToWalletState } from '../../utils/wallets';
13
+ import { getWalletConnectionStatus } from '../../utils/wallets';
14
14
 
15
15
  import { LogoContainer, Spinner } from './ConnectStatus.styles';
16
16
 
@@ -18,8 +18,11 @@ export function ConnectStatus(props: ConnectStatusProps) {
18
18
  // See `wallet` notes on its type definition
19
19
  const { wallet, error } = props;
20
20
  const { type, image } = wallet;
21
- const { state } = useWallets();
22
- const walletState = mapStatusToWalletState(state(type));
21
+ const { state, getWalletInfo } = useWallets();
22
+ const walletState = getWalletConnectionStatus(
23
+ getWalletInfo(type),
24
+ state(type)
25
+ );
23
26
 
24
27
  if (walletState === WalletState.CONNECTED) {
25
28
  return (
@@ -67,7 +67,7 @@ export function useWalletList(params?: Params): API {
67
67
  )
68
68
  : wallets;
69
69
 
70
- const sortedWallets = sortWalletsBasedOnConnectionState(wallets, state);
70
+ const sortedWallets = sortWalletsBasedOnConnectionState(wallets);
71
71
 
72
72
  const isExperimentalChainNotAdded = (walletType: string) =>
73
73
  !connectedWallets.find(
@@ -8,9 +8,7 @@ import {
8
8
  styled,
9
9
  Typography,
10
10
  Wallet,
11
- WalletState,
12
11
  } from '@rango-dev/ui';
13
- import { useWallets } from '@rango-dev/wallets-react';
14
12
  import React, { useState } from 'react';
15
13
 
16
14
  import { Layout, PageContainer } from '../components/Layout';
@@ -21,7 +19,6 @@ import { useAppStore } from '../store/AppStore';
21
19
  import { useUiStore } from '../store/ui';
22
20
  import { getContainer, isSingleWalletActive } from '../utils/common';
23
21
  import {
24
- checkIsWalletPartiallyConnected,
25
22
  filterBlockchainsByWalletTypes,
26
23
  filterWalletsByCategory,
27
24
  } from '../utils/wallets';
@@ -45,7 +42,6 @@ export function WalletsPage() {
45
42
  const [blockchainCategory, setBlockchainCategory] = useState<string>('ALL');
46
43
  const blockchains = useAppStore().blockchains();
47
44
  const { config } = useAppStore();
48
- const { state } = useWallets();
49
45
  const { checkHasDeepLink, getWalletLink } = useDeepLink();
50
46
  const [selectedWalletToConnect, setSelectedWalletToConnect] =
51
47
  useState<WalletInfoWithExtra>();
@@ -89,25 +85,14 @@ export function WalletsPage() {
89
85
  </Typography>
90
86
  <ListContainer>
91
87
  {filteredWallets.map((wallet, index) => {
92
- const namespacesState = state(wallet.type).namespaces;
93
88
  const key = `wallet-${index}-${wallet.type}`;
94
- const isWalletPartiallyConnected = checkIsWalletPartiallyConnected(
95
- wallet,
96
- namespacesState
97
- );
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
- }
104
89
  return (
105
90
  <Wallet
106
91
  key={key}
107
92
  {...wallet}
108
- state={walletState}
109
93
  hasDeepLink={checkHasDeepLink(wallet.type)}
110
94
  link={getWalletLink(wallet.type)}
95
+ state={wallet.state}
111
96
  container={getContainer()}
112
97
  onClick={() => handleWalletItemClick(wallet)}
113
98
  isLoading={fetchMetaStatus === 'loading'}
@@ -5,11 +5,12 @@ import type {
5
5
  Wallet,
6
6
  WalletInfoWithExtra,
7
7
  } from '../types';
8
- import type { Namespace } from '@rango-dev/wallets-core/namespaces/common';
9
- import type { ExtendedWalletInfo } from '@rango-dev/wallets-react';
8
+ import type {
9
+ ExtendedWalletInfo,
10
+ ProviderContext,
11
+ } from '@rango-dev/wallets-react';
10
12
  import type {
11
13
  Network,
12
- WalletState,
13
14
  WalletType,
14
15
  WalletTypes,
15
16
  } from '@rango-dev/wallets-shared';
@@ -46,19 +47,27 @@ import { formatThousandsWithCommas } from './sanitizers';
46
47
  export type ExtendedModalWalletInfo = WalletInfoWithExtra &
47
48
  Pick<ExtendedWalletInfo, 'properties' | 'isHub'>;
48
49
 
49
- export function mapStatusToWalletState(state: WalletState): WalletStatus {
50
- if (state.connected) {
50
+ export function getWalletConnectionStatus(
51
+ wallet: ExtendedWalletInfo,
52
+ walletState: ReturnType<ProviderContext['state']>
53
+ ): WalletStatus {
54
+ if (checkIsWalletPartiallyConnected(wallet, walletState)) {
55
+ return WalletStatus.PARTIALLY_CONNECTED;
56
+ }
57
+ if (walletState.connected) {
51
58
  return WalletStatus.CONNECTED;
52
- } else if (state.connecting) {
59
+ }
60
+ if (walletState.connecting) {
53
61
  return WalletStatus.CONNECTING;
54
- } else if (!state.installed) {
62
+ }
63
+ if (!walletState.installed) {
55
64
  return WalletStatus.NOT_INSTALLED;
56
65
  }
57
66
  return WalletStatus.DISCONNECTED;
58
67
  }
59
68
 
60
69
  export function mapWalletTypesToWalletInfo(
61
- getState: (type: WalletType) => WalletState,
70
+ getState: ProviderContext['state'],
62
71
  getWalletInfo: (type: WalletType) => ExtendedWalletInfo,
63
72
  list: WalletType[],
64
73
  chain?: string
@@ -96,7 +105,11 @@ export function mapWalletTypesToWalletInfo(
96
105
  const blockchainTypes = removeDuplicateFrom(
97
106
  supportedChains.map((item) => item.type)
98
107
  );
99
- const state = mapStatusToWalletState(getState(type));
108
+
109
+ const state = getWalletConnectionStatus(
110
+ getWalletInfo(type),
111
+ getState(type)
112
+ );
100
113
  return {
101
114
  title: name,
102
115
  image,
@@ -418,42 +431,22 @@ export function areTokensEqual(
418
431
  }
419
432
 
420
433
  export function sortWalletsBasedOnConnectionState(
421
- wallets: ExtendedModalWalletInfo[],
422
- state: (type: WalletType) => {
423
- namespaces?: Map<Namespace, { connected: boolean }>;
424
- }
434
+ wallets: ExtendedModalWalletInfo[]
425
435
  ): ExtendedModalWalletInfo[] {
426
- return (
427
- wallets
428
- .map((wallet) => ({
429
- // add isPartiallyConnected to wallet items
430
- isPartiallyConnected: checkIsWalletPartiallyConnected(
431
- wallet,
432
- state(wallet.type).namespaces
433
- ),
434
- ...wallet,
435
- }))
436
- .sort(
437
- (a, b) =>
438
- Number(
439
- b.state === WalletStatus.CONNECTED && !b.isPartiallyConnected
440
- ) -
441
- Number(
442
- a.state === WalletStatus.CONNECTED && !a.isPartiallyConnected
443
- ) ||
444
- Number(b.state === WalletStatus.CONNECTED) -
445
- Number(a.state === WalletStatus.CONNECTED) ||
446
- Number(
447
- b.state === WalletStatus.DISCONNECTED ||
448
- b.state === WalletStatus.CONNECTING
449
- ) -
450
- Number(
451
- a.state === WalletStatus.DISCONNECTED ||
452
- a.state === WalletStatus.CONNECTING
453
- )
454
- )
455
- // remove isPartiallyConnected from wallet items
456
- .map(({ isPartiallyConnected, ...wallet }) => wallet)
436
+ return wallets.sort(
437
+ (a, b) =>
438
+ Number(b.state === WalletStatus.CONNECTED) -
439
+ Number(a.state === WalletStatus.CONNECTED) ||
440
+ Number(b.state === WalletStatus.PARTIALLY_CONNECTED) -
441
+ Number(a.state === WalletStatus.PARTIALLY_CONNECTED) ||
442
+ Number(
443
+ b.state === WalletStatus.DISCONNECTED ||
444
+ b.state === WalletStatus.CONNECTING
445
+ ) -
446
+ Number(
447
+ a.state === WalletStatus.DISCONNECTED ||
448
+ a.state === WalletStatus.CONNECTING
449
+ )
457
450
  );
458
451
  }
459
452
 
@@ -536,14 +529,10 @@ export function filterWalletsByCategory(
536
529
  }
537
530
 
538
531
  export function checkIsWalletPartiallyConnected(
539
- wallet: ExtendedModalWalletInfo,
540
- namespacesState?: Map<Namespace, { connected: boolean }>
532
+ wallet: ExtendedWalletInfo,
533
+ walletState: ReturnType<ProviderContext['state']>
541
534
  ) {
542
- if (
543
- !wallet.isHub ||
544
- !wallet.needsNamespace ||
545
- wallet.state !== WalletStatus.CONNECTED
546
- ) {
535
+ if (!wallet.isHub || !wallet.needsNamespace || !walletState.connected) {
547
536
  return false;
548
537
  }
549
538
  const namespaces = wallet.needsNamespace.data;
@@ -555,7 +544,7 @@ export function checkIsWalletPartiallyConnected(
555
544
  return (
556
545
  wallet.needsNamespace.selection === 'multiple' &&
557
546
  supportedNamespaces.some(
558
- (namespace) => !namespacesState?.get(namespace.value)?.connected
547
+ (namespace) => !walletState.namespaces?.get(namespace.value)?.connected
559
548
  )
560
549
  );
561
550
  }