@rango-dev/widget-embedded 0.29.1-next.7 → 0.29.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.29.1-next.7",
3
+ "version": "0.29.1-next.8",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "source": "./src/index.ts",
@@ -53,4 +53,4 @@
53
53
  "publishConfig": {
54
54
  "access": "public"
55
55
  }
56
- }
56
+ }
@@ -37,7 +37,7 @@ function Main(props: PropsWithChildren<PropTypes>) {
37
37
  const config = useAppStore().config;
38
38
 
39
39
  const walletOptions: ProvidersOptions = {
40
- walletConnectProjectId: props.config?.walletConnectProjectId,
40
+ walletConnectProjectId: config?.walletConnectProjectId,
41
41
  walletConnectListedDesktopWalletLink:
42
42
  props.config.__UNSTABLE_OR_INTERNAL__
43
43
  ?.walletConnectListedDesktopWalletLink,
@@ -13,6 +13,7 @@ import { useCallback, useEffect, useState } from 'react';
13
13
 
14
14
  import { useAppStore } from '../store/AppStore';
15
15
  import { useWalletsStore } from '../store/wallets';
16
+ import { isSingleWalletActive } from '../utils/common';
16
17
  import { configWalletsToWalletName } from '../utils/providers';
17
18
  import {
18
19
  hashWalletsState,
@@ -82,10 +83,7 @@ export function useWalletList(params: Params) {
82
83
  if (wallet.connected) {
83
84
  await disconnect(type);
84
85
  } else {
85
- const atLeastOneWalletIsConnected = !!wallets.find(
86
- (w) => w.state === WalletState.CONNECTED
87
- );
88
- if (config?.multiWallets === false && atLeastOneWalletIsConnected) {
86
+ if (isSingleWalletActive(wallets, config.multiWallets)) {
89
87
  return;
90
88
  }
91
89
  onBeforeConnect?.(type);
@@ -1,3 +1,4 @@
1
+ import type { WalletInfoWithNamespaces } from '../types';
1
2
  import type { Namespace, WalletType } from '@rango-dev/wallets-shared';
2
3
 
3
4
  import { i18n } from '@lingui/core';
@@ -18,7 +19,7 @@ import { WalletNamespacesModal } from '../components/WalletNamespacesModal';
18
19
  import { useWalletList } from '../hooks/useWalletList';
19
20
  import { useAppStore } from '../store/AppStore';
20
21
  import { useUiStore } from '../store/ui';
21
- import { getContainer } from '../utils/common';
22
+ import { getContainer, isSingleWalletActive } from '../utils/common';
22
23
  import {
23
24
  filterBlockchainsByWalletTypes,
24
25
  filterWalletsByCategory,
@@ -51,6 +52,7 @@ export function WalletsPage() {
51
52
  const { fetchStatus: fetchMetaStatus } = useAppStore();
52
53
  const [blockchainCategory, setBlockchainCategory] = useState<string>('ALL');
53
54
  const blockchains = useAppStore().blockchains();
55
+ const { config } = useAppStore();
54
56
 
55
57
  const [openModal, setOpenModal] = useState(false);
56
58
  const [namespacesModalState, setNamespacesModalState] =
@@ -95,6 +97,25 @@ export function WalletsPage() {
95
97
 
96
98
  const filteredWallets = filterWalletsByCategory(list, blockchainCategory);
97
99
 
100
+ const handleWalletClick = (
101
+ type: string,
102
+ wallet: WalletInfoWithNamespaces
103
+ ) => {
104
+ if (!!wallet.namespaces && wallet.state === WalletState.DISCONNECTED) {
105
+ if (isSingleWalletActive(list, config.multiWallets)) {
106
+ return;
107
+ }
108
+ setNamespacesModalState({
109
+ providerType: type,
110
+ providerImage: wallet.image,
111
+ availableNamespaces: wallet.namespaces,
112
+ singleNamespace: wallet.singleNamespace,
113
+ });
114
+ } else {
115
+ void handleClick(type);
116
+ }
117
+ };
118
+
98
119
  return (
99
120
  <Layout
100
121
  header={{
@@ -123,21 +144,7 @@ export function WalletsPage() {
123
144
  key={key}
124
145
  {...wallet}
125
146
  container={getContainer()}
126
- onClick={(type) => {
127
- if (
128
- !!wallet.namespaces &&
129
- wallet.state === WalletState.DISCONNECTED
130
- ) {
131
- setNamespacesModalState({
132
- providerType: type,
133
- providerImage: wallet.image,
134
- availableNamespaces: wallet.namespaces,
135
- singleNamespace: wallet.singleNamespace,
136
- });
137
- } else {
138
- void handleClick(type);
139
- }
140
- }}
147
+ onClick={(type) => handleWalletClick(type, wallet)}
141
148
  isLoading={fetchMetaStatus === 'loading'}
142
149
  disabled={!isActiveTab}
143
150
  />
@@ -1,6 +1,7 @@
1
+ import type { WalletInfoWithNamespaces } from '../types';
1
2
  import type { Token } from 'rango-sdk';
2
3
 
3
- import { BlockchainCategories } from '@rango-dev/ui';
4
+ import { BlockchainCategories, WalletState } from '@rango-dev/ui';
4
5
  import { TransactionType } from 'rango-sdk';
5
6
 
6
7
  import { WIDGET_UI_ID } from '../constants';
@@ -247,3 +248,13 @@ export const getFontUrlByName = (fontName: string) => {
247
248
  const font = SUPPORTED_FONTS.find((font) => font.value === fontName);
248
249
  return font?.url;
249
250
  };
251
+
252
+ export function isSingleWalletActive(
253
+ wallets: WalletInfoWithNamespaces[],
254
+ multiWallets?: boolean
255
+ ) {
256
+ const atLeastOneWalletIsConnected = !!wallets.find(
257
+ (w) => w.state === WalletState.CONNECTED
258
+ );
259
+ return multiWallets === false && atLeastOneWalletIsConnected;
260
+ }