@rango-dev/widget-embedded 0.41.2-next.2 → 0.41.2-next.3

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.41.2-next.2",
3
+ "version": "0.41.2-next.3",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "source": "./src/index.ts",
@@ -54,4 +54,4 @@
54
54
  "publishConfig": {
55
55
  "access": "public"
56
56
  }
57
- }
57
+ }
@@ -85,45 +85,34 @@ export function useStatefulConnect(): UseStatefulConnect {
85
85
  const isDisconnected = wallet.state === WalletState.DISCONNECTED;
86
86
 
87
87
  if (isDisconnected) {
88
- // Legacy and hub have different structure to check wether we need to show namespace or not.
89
-
90
- // Hub
91
- const isHub = !!wallet.isHub;
92
- if (isHub) {
93
- const detachedInstances = wallet.properties?.find(
94
- (item) => item.name === 'detached'
95
- );
96
- const needsNamespace =
97
- detachedInstances && wallet.state !== 'connected';
98
-
99
- if (needsNamespace) {
100
- dispatch({
101
- type: 'needsNamespace',
102
- payload: {
103
- targetWallet: wallet,
104
- defaultSelectedChains: options?.defaultSelectedChains,
105
- },
106
- });
107
- return { status: ResultStatus.Namespace };
108
- }
109
- }
110
-
111
88
  /*
112
- * Legacy
113
- *
114
- * For legacy there are 3 states:
115
- * 1. a wallet doesn't have any namespace defined, we call the connect.
116
- * 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.
117
- * 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.
89
+ * Currently, handling connect should be covered for 3 different types of target wallet:
90
+ * 1. Target wallet does not contain any namespaces, in this situation we should just try to connect to the related provider.
91
+ * 2. Target wallet contains more than one namespace, in this situation we should display namespaces modal to allow the user to choose from available namespaces.
92
+ * 3. Target wallet contains only one namespace, in this situation we should check if that namespace needs derivation path and based on that, try to connect to the related provider or display derivation path modal.
118
93
  */
119
- if (!wallet.needsNamespace) {
94
+
95
+ // Legacy and hub have different structure to handle each situation.
96
+ const isHub = !!wallet.isHub;
97
+ const detachedInstances = wallet.properties?.find(
98
+ (item) => item.name === 'detached'
99
+ )?.value;
100
+
101
+ // 1. Target wallet does not contain any namespaces
102
+ if (
103
+ (isHub && !detachedInstances?.length) ||
104
+ (!isHub && !wallet.needsNamespace)
105
+ ) {
120
106
  return await runConnect(wallet.type, undefined, options);
121
107
  }
122
108
 
123
- const needsNamespace = wallet.needsNamespace.data.length > 1;
124
- const needsDerivationPath = wallet.needsDerivationPath;
125
-
126
- if (needsNamespace) {
109
+ // 2. Target wallet contains more than one namespace
110
+ if (
111
+ (isHub && detachedInstances?.length && detachedInstances.length > 1) ||
112
+ (!isHub &&
113
+ wallet.needsNamespace?.data.length &&
114
+ wallet.needsNamespace.data.length > 1)
115
+ ) {
127
116
  dispatch({
128
117
  type: 'needsNamespace',
129
118
  payload: {
@@ -132,27 +121,34 @@ export function useStatefulConnect(): UseStatefulConnect {
132
121
  },
133
122
  });
134
123
  return { status: ResultStatus.Namespace };
135
- } else if (needsDerivationPath) {
136
- const namespace = wallet.needsNamespace.data[0];
124
+ }
137
125
 
138
- dispatch({
139
- type: 'needsDerivationPath',
140
- payload: {
141
- providerType: wallet.type,
142
- providerImage: wallet.image,
126
+ // 3. Target wallet contains only one namespace
127
+ if (
128
+ (isHub && detachedInstances?.length === 1) ||
129
+ (!isHub && wallet.needsNamespace?.data.length === 1)
130
+ ) {
131
+ if (wallet.needsNamespace && wallet.needsDerivationPath) {
132
+ const namespace = wallet.needsNamespace.data[0];
133
+
134
+ dispatch({
135
+ type: 'needsDerivationPath',
136
+ payload: {
137
+ providerType: wallet.type,
138
+ providerImage: wallet.image,
139
+ namespace: namespace.value,
140
+ },
141
+ });
142
+ return { status: ResultStatus.DerivationPath };
143
+ }
144
+ return await runConnect(
145
+ wallet.type,
146
+ wallet.needsNamespace?.data.map((namespace) => ({
143
147
  namespace: namespace.value,
144
- },
145
- });
146
- return { status: ResultStatus.DerivationPath };
148
+ })),
149
+ options
150
+ );
147
151
  }
148
-
149
- return await runConnect(
150
- wallet.type,
151
- wallet.needsNamespace?.data.map((namespace) => ({
152
- namespace: namespace.value,
153
- })),
154
- options
155
- );
156
152
  }
157
153
 
158
154
  if (options?.disconnectIfConnected) {