@rango-dev/widget-embedded 0.36.1-next.10 → 0.36.1-next.12

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.
Files changed (33) hide show
  1. package/dist/QueueManager.d.ts.map +1 -1
  2. package/dist/components/SwapDetails/SwapDetails.d.ts.map +1 -1
  3. package/dist/components/WalletStatefulConnect/Namespaces.d.ts.map +1 -1
  4. package/dist/containers/Wallets/Wallets.d.ts.map +1 -1
  5. package/dist/containers/WidgetInfo/WidgetInfo.helpers.d.ts +1 -1
  6. package/dist/hooks/useStatefulConnect/useStatefulConnect.d.ts.map +1 -1
  7. package/dist/hooks/useStatefulConnect/useStatefulConnect.types.d.ts +2 -4
  8. package/dist/hooks/useStatefulConnect/useStatefulConnect.types.d.ts.map +1 -1
  9. package/dist/index.js +2 -2
  10. package/dist/index.js.map +4 -4
  11. package/dist/store/slices/wallets.d.ts +3 -1
  12. package/dist/store/slices/wallets.d.ts.map +1 -1
  13. package/dist/types/wallets.d.ts +1 -6
  14. package/dist/types/wallets.d.ts.map +1 -1
  15. package/dist/utils/providers.d.ts.map +1 -1
  16. package/dist/utils/wallets.d.ts.map +1 -1
  17. package/dist/widget-embedded.build.json +1 -1
  18. package/package.json +7 -7
  19. package/src/QueueManager.tsx +11 -10
  20. package/src/components/ConfirmWalletsModal/WalletList.tsx +1 -1
  21. package/src/components/SwapDetails/SwapDetails.tsx +10 -7
  22. package/src/components/WalletStatefulConnect/Namespaces.tsx +30 -37
  23. package/src/containers/Wallets/Wallets.tsx +63 -3
  24. package/src/containers/WidgetInfo/WidgetInfo.helpers.ts +2 -2
  25. package/src/hooks/useStatefulConnect/useStatefulConnect.ts +20 -22
  26. package/src/hooks/useStatefulConnect/useStatefulConnect.types.ts +2 -4
  27. package/src/store/slices/wallets.ts +13 -2
  28. package/src/types/wallets.ts +1 -6
  29. package/src/utils/providers.ts +43 -36
  30. package/src/utils/wallets.ts +2 -4
  31. package/dist/utils/hub.d.ts +0 -4
  32. package/dist/utils/hub.d.ts.map +0 -1
  33. package/src/utils/hub.ts +0 -21
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rango-dev/widget-embedded",
3
- "version": "0.36.1-next.10",
3
+ "version": "0.36.1-next.12",
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.6.0",
28
- "@rango-dev/provider-all": "^0.40.1-next.5",
28
+ "@rango-dev/provider-all": "^0.40.1-next.6",
29
29
  "@rango-dev/queue-manager-core": "^0.27.0",
30
- "@rango-dev/queue-manager-rango-preset": "^0.40.1-next.4",
30
+ "@rango-dev/queue-manager-rango-preset": "^0.40.1-next.5",
31
31
  "@rango-dev/queue-manager-react": "^0.27.0",
32
32
  "@rango-dev/signer-solana": "^0.35.1-next.0",
33
- "@rango-dev/ui": "^0.42.1-next.7",
34
- "@rango-dev/wallets-core": "^0.40.1-next.4",
35
- "@rango-dev/wallets-react": "^0.26.1-next.5",
36
- "@rango-dev/wallets-shared": "^0.40.1-next.4",
33
+ "@rango-dev/ui": "^0.42.1-next.10",
34
+ "@rango-dev/wallets-core": "^0.40.1-next.5",
35
+ "@rango-dev/wallets-react": "^0.26.1-next.6",
36
+ "@rango-dev/wallets-shared": "^0.40.1-next.5",
37
37
  "bignumber.js": "^9.1.1",
38
38
  "copy-to-clipboard": "^3.3.3",
39
39
  "dayjs": "^1.11.7",
@@ -1,5 +1,8 @@
1
- import type { SwapQueueContext } from '@rango-dev/queue-manager-rango-preset';
2
- import type { Network, WalletType } from '@rango-dev/wallets-shared';
1
+ import type {
2
+ SwapQueueContext,
3
+ TargetNamespace,
4
+ } from '@rango-dev/queue-manager-rango-preset';
5
+ import type { WalletType } from '@rango-dev/wallets-shared';
3
6
  import type { PropsWithChildren } from 'react';
4
7
 
5
8
  import {
@@ -48,16 +51,14 @@ function QueueManager(props: PropsWithChildren<{ apiKey?: string }>) {
48
51
  })),
49
52
  };
50
53
 
51
- const switchNetwork = async (wallet: WalletType, network: Network) => {
52
- if (!canSwitchNetworkTo(wallet, network)) {
54
+ const switchNetwork = async (
55
+ wallet: WalletType,
56
+ namespace: TargetNamespace
57
+ ) => {
58
+ if (!canSwitchNetworkTo(wallet, namespace.network)) {
53
59
  return undefined;
54
60
  }
55
- const result = await connect(wallet, [
56
- {
57
- namespace: 'DISCOVER_MODE',
58
- network,
59
- },
60
- ]);
61
+ const result = await connect(wallet, [namespace]);
61
62
 
62
63
  return result;
63
64
  };
@@ -149,7 +149,7 @@ export function WalletList(props: PropTypes) {
149
149
  const isDisconnected = wallet.state === WalletState.DISCONNECTED;
150
150
  const isConnectedButDifferentThanTargetNamespace = wallet.isHub
151
151
  ? !conciseAddress
152
- : !!wallet.namespaces && !conciseAddress;
152
+ : !!wallet.needsNamespace && !conciseAddress;
153
153
 
154
154
  if (isDisconnected) {
155
155
  setSelectedWalletToConnect(wallet);
@@ -3,7 +3,7 @@ import type { ModalState } from '../SwapDetailsModal';
3
3
 
4
4
  import { i18n } from '@lingui/core';
5
5
  import {
6
- getCurrentBlockchainOfOrNull,
6
+ getCurrentNamespaceOfOrNull,
7
7
  getCurrentStep,
8
8
  getRelatedWalletOrNull,
9
9
  } from '@rango-dev/queue-manager-rango-preset';
@@ -138,8 +138,8 @@ export function SwapDetails(props: SwapDetailsProps) {
138
138
  const lastConvertedTokenInFailedSwap =
139
139
  getLastConvertedTokenInFailedSwap(swap);
140
140
 
141
- const currentStepBlockchain = currentStep
142
- ? getCurrentBlockchainOfOrNull(swap, currentStep)
141
+ const currentStepNamespace = currentStep
142
+ ? getCurrentNamespaceOfOrNull(swap, currentStep)
143
143
  : null;
144
144
  const currentStepWallet = currentStep
145
145
  ? getRelatedWalletOrNull(swap, currentStep)
@@ -154,16 +154,19 @@ export function SwapDetails(props: SwapDetailsProps) {
154
154
  const showSwitchNetwork =
155
155
  currentStepNetworkStatus ===
156
156
  PendingSwapNetworkStatus.WaitingForNetworkChange &&
157
- !!currentStepBlockchain &&
157
+ !!currentStepNamespace &&
158
158
  !!currentStepWallet?.walletType &&
159
159
  (isMobileWallet(currentStepWallet.walletType) ||
160
- canSwitchNetworkTo(currentStepWallet.walletType, currentStepBlockchain));
160
+ canSwitchNetworkTo(
161
+ currentStepWallet.walletType,
162
+ currentStepNamespace.network
163
+ ));
161
164
 
162
165
  const switchNetwork = showSwitchNetwork
163
166
  ? connect.bind(null, currentStepWallet.walletType, [
164
167
  {
165
- namespace: 'DISCOVER_MODE',
166
- network: currentStepBlockchain,
168
+ namespace: currentStepNamespace.namespace,
169
+ network: currentStepNamespace.network,
167
170
  },
168
171
  ])
169
172
  : undefined;
@@ -12,8 +12,7 @@ import {
12
12
  Radio,
13
13
  RadioRoot,
14
14
  } from '@rango-dev/ui';
15
- import { namespaces } from '@rango-dev/wallets-shared';
16
- import React, { useMemo, useState } from 'react';
15
+ import React, { useState } from 'react';
17
16
 
18
17
  import { useAppStore } from '../../store/AppStore';
19
18
  import { WalletImageContainer } from '../HeaderButtons/HeaderButtons.styles';
@@ -23,25 +22,14 @@ import { getBlockchainLogo } from './Namespaces.helpers';
23
22
  import { NamespaceList } from './Namespaces.styles';
24
23
 
25
24
  export function Namespaces(props: PropTypes) {
26
- const { singleNamespace, availableNamespaces, providerImage } = props.value;
25
+ const { targetWallet } = props.value;
26
+ const singleNamespace = targetWallet.needsNamespace?.selection === 'single';
27
+ const providerImage = targetWallet.image;
27
28
 
28
29
  const [selectedNamespaces, setSelectedNamespaces] = useState<Namespace[]>([]);
29
30
 
30
31
  const blockchains = useAppStore().blockchains();
31
32
 
32
- const namespacesInfo = useMemo(
33
- () =>
34
- availableNamespaces?.map((namespace) => ({
35
- name: namespace,
36
- logo: getBlockchainLogo(
37
- blockchains,
38
- namespaces[namespace].mainBlockchain
39
- ),
40
- title: namespaces[namespace].title,
41
- })),
42
- [availableNamespaces]
43
- );
44
-
45
33
  const onSelect = (namespace: Namespace) => {
46
34
  if (singleNamespace) {
47
35
  setSelectedNamespaces([namespace]);
@@ -83,28 +71,33 @@ export function Namespaces(props: PropTypes) {
83
71
  <NamespaceList>
84
72
  {wrapRadioRoot(
85
73
  <>
86
- {namespacesInfo?.map((namespaceInfoItem) => (
87
- <ListItemButton
88
- key={namespaceInfoItem.name}
89
- id={namespaceInfoItem.name}
90
- title={namespaceInfoItem.title}
91
- hasDivider
92
- style={{ height: 60 }}
93
- onClick={() => onSelect(namespaceInfoItem.name)}
94
- start={<Image src={namespaceInfoItem.logo} size={22} />}
95
- end={
96
- singleNamespace ? (
97
- <Radio value={namespaceInfoItem.name} />
98
- ) : (
99
- <Checkbox
100
- checked={selectedNamespaces.includes(
101
- namespaceInfoItem.name
102
- )}
74
+ {targetWallet.needsNamespace?.data.map((ns) => {
75
+ return (
76
+ <ListItemButton
77
+ key={ns.id}
78
+ id={ns.id}
79
+ title={ns.label}
80
+ hasDivider
81
+ style={{ height: 60 }}
82
+ onClick={() => onSelect(ns.value)}
83
+ start={
84
+ <Image
85
+ src={getBlockchainLogo(blockchains, ns.id)}
86
+ size={22}
103
87
  />
104
- )
105
- }
106
- />
107
- ))}
88
+ }
89
+ end={
90
+ singleNamespace ? (
91
+ <Radio value={ns.value} />
92
+ ) : (
93
+ <Checkbox
94
+ checked={selectedNamespaces.includes(ns.value)}
95
+ />
96
+ )
97
+ }
98
+ />
99
+ );
100
+ })}
108
101
  </>
109
102
  )}
110
103
  </NamespaceList>
@@ -7,6 +7,10 @@ import type { ProvidersOptions } from '../../utils/providers';
7
7
  import type { LegacyEventHandler as EventHandler } from '@rango-dev/wallets-core/legacy';
8
8
  import type { PropsWithChildren } from 'react';
9
9
 
10
+ import {
11
+ legacyFormatAddressWithNetwork as formatAddressWithNetwork,
12
+ legacyReadAccountAddress as readAccountAddress,
13
+ } from '@rango-dev/wallets-core/legacy';
10
14
  import { Events, Provider } from '@rango-dev/wallets-react';
11
15
  import { type Network } from '@rango-dev/wallets-shared';
12
16
  import { isEvmBlockchain } from 'rango-sdk';
@@ -36,9 +40,11 @@ function Main(props: PropsWithChildren<PropTypes>) {
36
40
  updateSettings,
37
41
  fetch: fetchMeta,
38
42
  fetchStatus,
43
+ removeBalancesForWallet,
39
44
  } = useAppStore();
40
45
  const blockchains = useAppStore().blockchains();
41
- const { newWalletConnected, disconnectWallet } = useAppStore();
46
+ const { newWalletConnected, disconnectWallet, connectedWallets } =
47
+ useAppStore();
42
48
  const config = useAppStore().config;
43
49
 
44
50
  const walletOptions: ProvidersOptions = {
@@ -75,9 +81,62 @@ function Main(props: PropsWithChildren<PropTypes>) {
75
81
 
76
82
  const onUpdateState: EventHandler = (type, event, value, state, meta) => {
77
83
  if (event === Events.ACCOUNTS) {
84
+ const supportedChainNames: Network[] | null =
85
+ walletAndSupportedChainsNames(meta.supportedBlockchains);
86
+
87
+ /*
88
+ * When a wallet is connecting to an evm account, we will consider it as the account exists on other evm-compatible blockchains
89
+ * To get their balances.
90
+ *
91
+ * The logic here is for handling switching account functionality in wallets. when a wallet is switching to another account
92
+ * we need to clean the balances for old accounts.
93
+ */
94
+ const evmAccounts: string[] = [];
95
+ const nonEvmAccounts: string[] = [];
96
+
97
+ value?.forEach((account: string) => {
98
+ const { network } = readAccountAddress(account);
99
+ if (evmBasedChainNames.includes(network)) {
100
+ evmAccounts.push(account);
101
+ } else {
102
+ nonEvmAccounts.push(account);
103
+ }
104
+ });
105
+
106
+ const previousAccounts = connectedWallets
107
+ .filter((wallet) => wallet.walletType === type)
108
+ .map((wallet) =>
109
+ formatAddressWithNetwork(wallet.address, wallet.chain)
110
+ );
111
+
112
+ if (previousAccounts.length > 0) {
113
+ if (evmAccounts.length > 0) {
114
+ // We use same logic for removing as we use for adding.
115
+ const data = prepareAccountsForWalletStore(
116
+ type,
117
+ evmAccounts,
118
+ evmBasedChainNames,
119
+ supportedChainNames,
120
+ meta.isContractWallet
121
+ );
122
+
123
+ removeBalancesForWallet(type, {
124
+ chains: data.map((account) => account.chain),
125
+ });
126
+ }
127
+
128
+ if (nonEvmAccounts.length > 0) {
129
+ removeBalancesForWallet(type, {
130
+ chains: nonEvmAccounts.map((account) => {
131
+ const { network } = readAccountAddress(account);
132
+ return network;
133
+ }),
134
+ });
135
+ }
136
+ }
137
+
138
+ // After cleaning up balances, it's time to add new accounts.
78
139
  if (value) {
79
- const supportedChainNames: Network[] | null =
80
- walletAndSupportedChainsNames(meta.supportedBlockchains);
81
140
  const data = prepareAccountsForWalletStore(
82
141
  type,
83
142
  value,
@@ -149,6 +208,7 @@ function Main(props: PropsWithChildren<PropTypes>) {
149
208
  onUpdateState={onUpdateState}
150
209
  autoConnect={!!isActiveTab}
151
210
  configs={{
211
+ wallets: config.wallets,
152
212
  isExperimentalEnabled: isFeatureEnabled(
153
213
  'experimentalWallet',
154
214
  config.features
@@ -5,7 +5,7 @@ import type { PendingSwap } from 'rango-types/lib';
5
5
 
6
6
  import {
7
7
  cancelSwap,
8
- getCurrentBlockchainOfOrNull,
8
+ getCurrentNamespaceOfOrNull,
9
9
  getCurrentStep,
10
10
  getRelatedWalletOrNull,
11
11
  } from '@rango-dev/queue-manager-rango-preset';
@@ -66,7 +66,7 @@ export class WidgetHistory {
66
66
  step: currentStep,
67
67
  wallet: currentStep ? getRelatedWalletOrNull(swap, currentStep) : null,
68
68
  network: currentStep
69
- ? getCurrentBlockchainOfOrNull(swap, currentStep)
69
+ ? getCurrentNamespaceOfOrNull(swap, currentStep)?.network
70
70
  : null,
71
71
  };
72
72
  }
@@ -8,8 +8,6 @@ import { WalletState } from '@rango-dev/ui';
8
8
  import { useWallets } from '@rango-dev/wallets-react';
9
9
  import { useReducer } from 'react';
10
10
 
11
- import { convertCommonNamespacesKeysToLegacyNamespace } from '../../utils/hub';
12
-
13
11
  import {
14
12
  isStateOnDerivationPathStep,
15
13
  isStateOnNamespace,
@@ -99,50 +97,48 @@ export function useStatefulConnect(): UseStatefulConnect {
99
97
  detachedInstances && wallet.state !== 'connected';
100
98
 
101
99
  if (needsNamespace) {
102
- const availableNamespaces =
103
- convertCommonNamespacesKeysToLegacyNamespace(
104
- detachedInstances.value
105
- );
106
-
107
100
  dispatch({
108
101
  type: 'needsNamespace',
109
102
  payload: {
110
- providerType: wallet.type,
111
- providerImage: wallet.image,
112
- availableNamespaces,
113
- singleNamespace: false,
103
+ targetWallet: wallet,
114
104
  },
115
105
  });
116
106
  return { status: ResultStatus.Namespace };
117
107
  }
118
108
  }
119
109
 
120
- // Legacy
121
- if (!wallet.namespaces) {
110
+ /*
111
+ * Legacy
112
+ *
113
+ * For legacy there are 3 states:
114
+ * 1. a wallet doesn't have any namespace defined, we call the connect.
115
+ * 2. a wallet has more than two namespaces, we should show namepsace modal, and in that place user will be checked to needs derivation path or not.
116
+ * 3. a wallet has exactly one namespacesape, in this case we check if that needs derivation or not, if it needs we will do it here by dispatching the action accordingly.
117
+ */
118
+ if (!wallet.needsNamespace) {
122
119
  return await runConnect(wallet.type, undefined, options);
123
120
  }
124
121
 
125
- const needsNamespace = wallet.namespaces.length > 1;
122
+ const needsNamespace = wallet.needsNamespace.data.length > 1;
126
123
  const needsDerivationPath = wallet.needsDerivationPath;
127
124
 
128
125
  if (needsNamespace) {
129
126
  dispatch({
130
127
  type: 'needsNamespace',
131
128
  payload: {
132
- providerType: wallet.type,
133
- providerImage: wallet.image,
134
- availableNamespaces: wallet.namespaces,
135
- singleNamespace: wallet.singleNamespace,
129
+ targetWallet: wallet,
136
130
  },
137
131
  });
138
132
  return { status: ResultStatus.Namespace };
139
133
  } else if (needsDerivationPath) {
134
+ const namespace = wallet.needsNamespace.data[0];
135
+
140
136
  dispatch({
141
137
  type: 'needsDerivationPath',
142
138
  payload: {
143
139
  providerType: wallet.type,
144
140
  providerImage: wallet.image,
145
- namespace: wallet.namespaces[0],
141
+ namespace: namespace.value,
146
142
  },
147
143
  });
148
144
  return { status: ResultStatus.DerivationPath };
@@ -150,7 +146,9 @@ export function useStatefulConnect(): UseStatefulConnect {
150
146
 
151
147
  return await runConnect(
152
148
  wallet.type,
153
- wallet.namespaces.map((namespace) => ({ namespace })),
149
+ wallet.needsNamespace?.data.map((namespace) => ({
150
+ namespace: namespace.value,
151
+ })),
154
152
  options
155
153
  );
156
154
  }
@@ -167,7 +165,7 @@ export function useStatefulConnect(): UseStatefulConnect {
167
165
  wallet: WalletInfoWithExtra,
168
166
  selectedNamespaces: Namespace[]
169
167
  ): Promise<Result> => {
170
- const isSingleNamespace = wallet.singleNamespace;
168
+ const isSingleNamespace = wallet.needsNamespace?.selection === 'single';
171
169
  const needsDerivationPath = wallet.needsDerivationPath;
172
170
  const firstSelectedNamespace = selectedNamespaces[0];
173
171
 
@@ -207,7 +205,7 @@ export function useStatefulConnect(): UseStatefulConnect {
207
205
  );
208
206
  }
209
207
 
210
- const type = connectState.namespace.providerType;
208
+ const type = connectState.namespace.targetWallet.type;
211
209
  const namespaces = selectedNamespaces.map((namespace) => ({
212
210
  namespace,
213
211
  }));
@@ -1,3 +1,4 @@
1
+ import type { ExtendedModalWalletInfo } from '../../utils/wallets';
1
2
  import type { Namespace } from '@rango-dev/wallets-core/namespaces/common';
2
3
 
3
4
  export interface HandleConnectOptions {
@@ -6,10 +7,7 @@ export interface HandleConnectOptions {
6
7
  }
7
8
 
8
9
  export interface NeedsNamespacesState {
9
- providerType: string;
10
- providerImage: string;
11
- availableNamespaces?: Namespace[];
12
- singleNamespace?: boolean;
10
+ targetWallet: ExtendedModalWalletInfo;
13
11
  }
14
12
 
15
13
  export interface NeedsDerivationPathState {
@@ -55,7 +55,12 @@ export interface WalletsSlice {
55
55
  setConnectedWalletAsRefetching: (walletType: string) => void;
56
56
  setConnectedWalletHasError: (walletType: string) => void;
57
57
  setConnectedWalletRetrievedData: (walletType: string) => void;
58
- removeBalancesForWallet: (walletType: string) => void;
58
+ removeBalancesForWallet: (
59
+ walletType: string,
60
+ options?: {
61
+ chains?: string[];
62
+ }
63
+ ) => void;
59
64
  addConnectedWallet: (accounts: Wallet[]) => void;
60
65
  setWalletsAsSelected: (
61
66
  wallets: { walletType: string; chain: string }[]
@@ -254,7 +259,7 @@ export const createWalletsSlice: StateCreator<
254
259
 
255
260
  void get().fetchBalances(accounts);
256
261
  },
257
- removeBalancesForWallet: (walletType) => {
262
+ removeBalancesForWallet: (walletType, options) => {
258
263
  let walletsNeedsToBeRemoved = get().connectedWallets.filter(
259
264
  (connectedWallet) => connectedWallet.walletType === walletType
260
265
  );
@@ -275,6 +280,12 @@ export const createWalletsSlice: StateCreator<
275
280
  }
276
281
  });
277
282
 
283
+ if (!!options?.chains && options.chains.length > 0) {
284
+ walletsNeedsToBeRemoved = walletsNeedsToBeRemoved.filter((wallet) => {
285
+ return options.chains?.includes(wallet.chain);
286
+ });
287
+ }
288
+
278
289
  const nextBalancesState: BalanceState = {};
279
290
  let nextAggregatedBalanceState: AggregatedBalanceState =
280
291
  get()._aggregatedBalances;
@@ -1,5 +1,4 @@
1
1
  import type { WalletInfo } from '@rango-dev/ui';
2
- import type { Namespace } from '@rango-dev/wallets-core/namespaces/common';
3
2
  import type { WalletType } from '@rango-dev/wallets-shared';
4
3
 
5
4
  export interface Wallet {
@@ -25,8 +24,4 @@ export type TokensBalance = {
25
24
  [key: TokenHash]: Balance;
26
25
  };
27
26
 
28
- export type WalletInfoWithExtra = WalletInfo & {
29
- namespaces?: Namespace[];
30
- singleNamespace?: boolean;
31
- needsDerivationPath?: boolean;
32
- };
27
+ export type WalletInfoWithExtra = WalletInfo;
@@ -48,6 +48,10 @@ export function matchAndGenerateProviders(
48
48
  const all = allProviders(envs);
49
49
 
50
50
  if (providers) {
51
+ /*
52
+ * If `wallets` is included in widget config,
53
+ * allProviders should be filtered based on wallets list
54
+ */
51
55
  const selectedProviders: VersionedProviders[] = [];
52
56
 
53
57
  providers.forEach((requestedProvider) => {
@@ -57,29 +61,36 @@ export function matchAndGenerateProviders(
57
61
  * The second way is passing a custom provider which implemented ProviderInterface.
58
62
  */
59
63
  if (typeof requestedProvider === 'string') {
60
- const result: BothProvidersInterface | undefined =
61
- pickVersionWithFallbackToLegacy(all, options).find((provider) => {
62
- if (provider instanceof Provider) {
63
- return provider.id === requestedProvider;
64
- }
65
- return provider.config.type === requestedProvider;
66
- });
64
+ const result = all.find((provider) => {
65
+ /*
66
+ * To find a provider in allProviders,
67
+ * a version of each provider should be picked
68
+ * and validated based on that version scheme.
69
+ * If the corresponding provider to a wallet was found in allProvider,
70
+ * it will be add to selected providers.
71
+ */
72
+ const versionedProvider = pickProviderVersionWithFallbackToLegacy(
73
+ provider,
74
+ options
75
+ );
76
+ if (versionedProvider instanceof Provider) {
77
+ return versionedProvider.id === requestedProvider;
78
+ }
79
+ return versionedProvider.config.type === requestedProvider;
80
+ });
67
81
 
82
+ /*
83
+ * A provider may have multiple versions
84
+ * (e.g., 0.0, also known as legacy, and 1.0, also known as hub).
85
+ * We should ensure that all existing versions of a provider are added to selectedProviders.
86
+ */
68
87
  if (result) {
69
- if (result instanceof Provider) {
70
- selectedProviders.push(
71
- defineVersions().version('1.0.0', result).build()
72
- );
73
- } else {
74
- selectedProviders.push(
75
- defineVersions().version('0.0.0', result).build()
76
- );
77
- }
78
- } else {
79
- console.warn(
80
- `Couldn't find ${requestedProvider} provider. Please make sure you are passing the correct name.`
81
- );
88
+ selectedProviders.push(result);
82
89
  }
90
+ console.warn(
91
+ // A provider name is included in config but was not found in allProviders
92
+ `Couldn't find ${requestedProvider} provider. Please make sure you are passing the correct name.`
93
+ );
83
94
  } else {
84
95
  // It's a custom provider so we directly push it to the list.
85
96
  if (requestedProvider instanceof Provider) {
@@ -100,31 +111,27 @@ export function matchAndGenerateProviders(
100
111
  return all;
101
112
  }
102
113
 
103
- // TODO: this is a duplication with what we do in core.
104
- function pickVersionWithFallbackToLegacy(
105
- providers: VersionedProviders[],
114
+ function pickProviderVersionWithFallbackToLegacy(
115
+ provider: VersionedProviders,
106
116
  options?: ProvidersOptions
107
- ): BothProvidersInterface[] {
117
+ ): BothProvidersInterface {
108
118
  const { experimentalWallet = 'enabled' } = options || {};
119
+ const version = experimentalWallet == 'disabled' ? '0.0.0' : '1.0.0';
109
120
 
110
- return providers.map((provider) => {
111
- const version = experimentalWallet == 'disabled' ? '0.0.0' : '1.0.0';
112
- try {
113
- return pickVersion(provider, version)[1];
114
- } catch {
115
- // Fallback to legacy version, if target version doesn't exists.
116
- return pickVersion(provider, '0.0.0')[1];
117
- }
118
- });
121
+ try {
122
+ return pickVersion(provider, version)[1];
123
+ } catch {
124
+ // Fallback to legacy version, if target version doesn't exists.
125
+ return pickVersion(provider, '0.0.0')[1];
126
+ }
119
127
  }
120
128
 
121
129
  export function configWalletsToWalletName(
122
130
  config: WidgetConfig['wallets'],
123
131
  options?: ProvidersOptions
124
132
  ): string[] {
125
- const providers = pickVersionWithFallbackToLegacy(
126
- matchAndGenerateProviders(config, options),
127
- options
133
+ const providers = matchAndGenerateProviders(config, options).map((provider) =>
134
+ pickProviderVersionWithFallbackToLegacy(provider, options)
128
135
  );
129
136
  const names = providers.map((provider) => {
130
137
  if (provider instanceof Provider) {
@@ -87,8 +87,7 @@ export function mapWalletTypesToWalletInfo(
87
87
  img: image,
88
88
  installLink,
89
89
  showOnMobile,
90
- namespaces,
91
- singleNamespace,
90
+ needsNamespace,
92
91
  supportedChains,
93
92
  needsDerivationPath,
94
93
  properties,
@@ -106,8 +105,7 @@ export function mapWalletTypesToWalletInfo(
106
105
  state,
107
106
  type,
108
107
  showOnMobile,
109
- namespaces,
110
- singleNamespace,
108
+ needsNamespace,
111
109
  blockchainTypes,
112
110
  needsDerivationPath,
113
111
  properties,
@@ -1,4 +0,0 @@
1
- import type { CommonNamespaceKeys } from '@rango-dev/wallets-core';
2
- import type { Namespace } from '@rango-dev/wallets-core/namespaces/common';
3
- export declare function convertCommonNamespacesKeysToLegacyNamespace(namespaces: CommonNamespaceKeys[]): Namespace[];
4
- //# sourceMappingURL=hub.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"hub.d.ts","sourceRoot":"","sources":["../../src/utils/hub.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AACnE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,2CAA2C,CAAC;AAE3E,wBAAgB,4CAA4C,CAC1D,UAAU,EAAE,mBAAmB,EAAE,GAChC,SAAS,EAAE,CAeb"}
package/src/utils/hub.ts DELETED
@@ -1,21 +0,0 @@
1
- import type { CommonNamespaceKeys } from '@rango-dev/wallets-core';
2
- import type { Namespace } from '@rango-dev/wallets-core/namespaces/common';
3
-
4
- export function convertCommonNamespacesKeysToLegacyNamespace(
5
- namespaces: CommonNamespaceKeys[]
6
- ): Namespace[] {
7
- return namespaces.map((namespace) => {
8
- switch (namespace) {
9
- case 'evm':
10
- return 'EVM';
11
- case 'solana':
12
- return 'Solana';
13
- case 'cosmos':
14
- return 'Cosmos';
15
- default:
16
- throw new Error(
17
- 'Can not convert this common namespace key to a proper legacy key.'
18
- );
19
- }
20
- });
21
- }