@rango-dev/widget-embedded 0.29.1-next.20 → 0.29.1-next.21

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 (50) hide show
  1. package/dist/components/ConfirmWalletsModal/ConfirmWallets.styles.d.ts +6 -0
  2. package/dist/components/ConfirmWalletsModal/ConfirmWallets.styles.d.ts.map +1 -1
  3. package/dist/components/ConfirmWalletsModal/WalletList.d.ts.map +1 -1
  4. package/dist/components/SearchInput/SearchInput.types.d.ts +2 -0
  5. package/dist/components/SearchInput/SearchInput.types.d.ts.map +1 -1
  6. package/dist/components/SwapDetailsModal/SwapDetailsModal.WalletState.d.ts.map +1 -1
  7. package/dist/components/WalletDerivationPathModal/WalletDerivationPathModal.d.ts +4 -0
  8. package/dist/components/WalletDerivationPathModal/WalletDerivationPathModal.d.ts.map +1 -0
  9. package/dist/components/WalletDerivationPathModal/WalletDerivationPathModal.styles.d.ts +325 -0
  10. package/dist/components/WalletDerivationPathModal/WalletDerivationPathModal.styles.d.ts.map +1 -0
  11. package/dist/components/WalletDerivationPathModal/WalletDerivationPathModal.types.d.ts +10 -0
  12. package/dist/components/WalletDerivationPathModal/WalletDerivationPathModal.types.d.ts.map +1 -0
  13. package/dist/components/WalletDerivationPathModal/index.d.ts +2 -0
  14. package/dist/components/WalletDerivationPathModal/index.d.ts.map +1 -0
  15. package/dist/components/WalletNamespacesModal/WalletNamespacesModal.d.ts.map +1 -1
  16. package/dist/components/WalletNamespacesModal/WalletNamespacesModal.types.d.ts +1 -1
  17. package/dist/components/WalletNamespacesModal/WalletNamespacesModal.types.d.ts.map +1 -1
  18. package/dist/constants/namespaces.d.ts +8 -0
  19. package/dist/constants/namespaces.d.ts.map +1 -0
  20. package/dist/hooks/useWalletList.d.ts +3 -3
  21. package/dist/hooks/useWalletList.d.ts.map +1 -1
  22. package/dist/index.d.ts +2 -2
  23. package/dist/index.d.ts.map +1 -1
  24. package/dist/index.js +2 -2
  25. package/dist/index.js.map +4 -4
  26. package/dist/pages/WalletsPage.d.ts.map +1 -1
  27. package/dist/types/wallets.d.ts +2 -1
  28. package/dist/types/wallets.d.ts.map +1 -1
  29. package/dist/utils/common.d.ts +2 -2
  30. package/dist/utils/common.d.ts.map +1 -1
  31. package/dist/utils/wallets.d.ts +4 -4
  32. package/dist/utils/wallets.d.ts.map +1 -1
  33. package/dist/widget-embedded.build.json +1 -1
  34. package/package.json +6 -6
  35. package/src/components/ConfirmWalletsModal/WalletList.tsx +81 -14
  36. package/src/components/SearchInput/SearchInput.types.ts +2 -0
  37. package/src/components/SwapDetailsModal/SwapDetailsModal.WalletState.tsx +77 -11
  38. package/src/components/WalletDerivationPathModal/WalletDerivationPathModal.styles.ts +17 -0
  39. package/src/components/WalletDerivationPathModal/WalletDerivationPathModal.tsx +154 -0
  40. package/src/components/WalletDerivationPathModal/WalletDerivationPathModal.types.tsx +10 -0
  41. package/src/components/WalletDerivationPathModal/index.ts +1 -0
  42. package/src/components/WalletNamespacesModal/WalletNamespacesModal.tsx +9 -6
  43. package/src/components/WalletNamespacesModal/WalletNamespacesModal.types.tsx +1 -1
  44. package/src/constants/namespaces.ts +62 -0
  45. package/src/hooks/useWalletList.ts +5 -2
  46. package/src/index.ts +2 -2
  47. package/src/pages/WalletsPage.tsx +85 -19
  48. package/src/types/wallets.ts +2 -1
  49. package/src/utils/common.ts +2 -2
  50. package/src/utils/wallets.ts +7 -5
package/src/index.ts CHANGED
@@ -5,7 +5,7 @@ import type {
5
5
  QuoteEventData,
6
6
  Tokens,
7
7
  WalletEventData,
8
- WalletInfoWithNamespaces,
8
+ WalletInfoWithExtra,
9
9
  WidgetColors,
10
10
  WidgetColorsKeys,
11
11
  WidgetConfig,
@@ -108,7 +108,7 @@ export type {
108
108
  WidgetVariant,
109
109
  WalletEventData,
110
110
  QuoteEventData,
111
- WalletInfoWithNamespaces,
111
+ WalletInfoWithExtra,
112
112
  };
113
113
  export {
114
114
  Widget,
@@ -1,4 +1,4 @@
1
- import type { WalletInfoWithNamespaces } from '../types';
1
+ import type { WalletInfoWithExtra } from '../types';
2
2
  import type { Namespace, WalletType } from '@rango-dev/wallets-shared';
3
3
 
4
4
  import { i18n } from '@lingui/core';
@@ -14,6 +14,7 @@ import {
14
14
  import React, { useState } from 'react';
15
15
 
16
16
  import { Layout, PageContainer } from '../components/Layout';
17
+ import { WalletDerivationPathModal } from '../components/WalletDerivationPathModal';
17
18
  import { WalletModal } from '../components/WalletModal';
18
19
  import { WalletNamespacesModal } from '../components/WalletNamespacesModal';
19
20
  import { useWalletList } from '../hooks/useWalletList';
@@ -26,12 +27,20 @@ import {
26
27
  } from '../utils/wallets';
27
28
 
28
29
  interface NamespacesModalState {
30
+ open: boolean;
29
31
  providerType: string;
30
32
  providerImage: string;
31
33
  availableNamespaces?: Namespace[];
32
34
  singleNamespace?: boolean;
33
35
  }
34
36
 
37
+ interface DerivationPathModalState {
38
+ open: boolean;
39
+ providerType: string;
40
+ providerImage: string;
41
+ namespace: Namespace;
42
+ }
43
+
35
44
  const ListContainer = styled('div', {
36
45
  display: 'flex',
37
46
  justifyContent: 'center',
@@ -57,6 +66,8 @@ export function WalletsPage() {
57
66
  const [openModal, setOpenModal] = useState(false);
58
67
  const [namespacesModalState, setNamespacesModalState] =
59
68
  useState<NamespacesModalState | null>(null);
69
+ const [derivationPathModalState, setDerivationPathModalState] =
70
+ useState<DerivationPathModalState | null>(null);
60
71
  const [selectedWalletType, setSelectedWalletType] = useState<WalletType>('');
61
72
  let modalTimerId: ReturnType<typeof setTimeout> | null = null;
62
73
  const isActiveTab = useUiStore.use.isActiveTab();
@@ -84,6 +95,24 @@ export function WalletsPage() {
84
95
  setOpenModal(false);
85
96
  };
86
97
 
98
+ const handleCloseNamespaceModal = () => {
99
+ if (namespacesModalState) {
100
+ setNamespacesModalState({
101
+ ...namespacesModalState,
102
+ open: false,
103
+ });
104
+ }
105
+ };
106
+
107
+ const handleCloseDerivationPathModal = () => {
108
+ if (derivationPathModalState) {
109
+ setDerivationPathModalState({
110
+ ...derivationPathModalState,
111
+ open: false,
112
+ });
113
+ }
114
+ };
115
+
87
116
  const selectedWallet = list.find(
88
117
  (wallet) => wallet.type === selectedWalletType
89
118
  );
@@ -97,15 +126,14 @@ export function WalletsPage() {
97
126
 
98
127
  const filteredWallets = filterWalletsByCategory(list, blockchainCategory);
99
128
 
100
- const handleWalletClick = (
101
- type: string,
102
- wallet: WalletInfoWithNamespaces
103
- ) => {
129
+ const handleWalletItemClick = (type: string, wallet: WalletInfoWithExtra) => {
130
+ if (isSingleWalletActive(list, config.multiWallets)) {
131
+ return;
132
+ }
133
+
104
134
  if (!!wallet.namespaces && wallet.state === WalletState.DISCONNECTED) {
105
- if (isSingleWalletActive(list, config.multiWallets)) {
106
- return;
107
- }
108
135
  setNamespacesModalState({
136
+ open: true,
109
137
  providerType: type,
110
138
  providerImage: wallet.image,
111
139
  availableNamespaces: wallet.namespaces,
@@ -116,6 +144,42 @@ export function WalletsPage() {
116
144
  }
117
145
  };
118
146
 
147
+ const handleConfirmNamespaces = (selectedNamespaces: Namespace[]) => {
148
+ const wallet = filteredWallets.find(
149
+ (wallet) => wallet.type === namespacesModalState?.providerType
150
+ );
151
+ if (
152
+ wallet?.singleNamespace && // Currently we support derivation path only for single namespace wallets
153
+ wallet?.needsDerivationPath &&
154
+ selectedNamespaces[0]
155
+ ) {
156
+ setDerivationPathModalState({
157
+ open: true,
158
+ providerType: wallet.type,
159
+ providerImage: wallet.image,
160
+ namespace: selectedNamespaces[0],
161
+ });
162
+ } else {
163
+ void handleClick(
164
+ namespacesModalState?.providerType as string,
165
+ selectedNamespaces.map((namespace) => ({
166
+ namespace,
167
+ }))
168
+ );
169
+ }
170
+ handleCloseNamespaceModal();
171
+ };
172
+
173
+ const handleDerivationPathConfirm = (derivationPath: string) => {
174
+ if (derivationPath && derivationPathModalState?.namespace) {
175
+ void handleClick(derivationPathModalState.providerType, [
176
+ { namespace: derivationPathModalState.namespace, derivationPath },
177
+ ]);
178
+ }
179
+
180
+ handleCloseDerivationPathModal();
181
+ };
182
+
119
183
  return (
120
184
  <Layout
121
185
  header={{
@@ -144,7 +208,7 @@ export function WalletsPage() {
144
208
  key={key}
145
209
  {...wallet}
146
210
  container={getContainer()}
147
- onClick={(type) => handleWalletClick(type, wallet)}
211
+ onClick={(type) => handleWalletItemClick(type, wallet)}
148
212
  isLoading={fetchMetaStatus === 'loading'}
149
213
  disabled={!isActiveTab}
150
214
  />
@@ -158,19 +222,21 @@ export function WalletsPage() {
158
222
  error={error}
159
223
  />
160
224
  <WalletNamespacesModal
161
- open={!!namespacesModalState}
162
- onClose={() => setNamespacesModalState(null)}
163
- onConfirm={(namespaces) => {
164
- void handleClick(
165
- namespacesModalState?.providerType as string,
166
- namespaces
167
- );
168
- setNamespacesModalState(null);
169
- }}
225
+ open={!!namespacesModalState?.open}
226
+ onClose={handleCloseNamespaceModal}
227
+ onConfirm={handleConfirmNamespaces}
170
228
  image={namespacesModalState?.providerImage}
171
- namespaces={namespacesModalState?.availableNamespaces}
229
+ availableNamespaces={namespacesModalState?.availableNamespaces}
172
230
  singleNamespace={namespacesModalState?.singleNamespace}
173
231
  />
232
+ <WalletDerivationPathModal
233
+ open={!!derivationPathModalState?.open}
234
+ selectedNamespace={derivationPathModalState?.namespace}
235
+ type={derivationPathModalState?.providerType}
236
+ image={derivationPathModalState?.providerImage}
237
+ onClose={handleCloseDerivationPathModal}
238
+ onConfirm={handleDerivationPathConfirm}
239
+ />
174
240
  </ListContainer>
175
241
  </Container>
176
242
  </Layout>
@@ -24,7 +24,8 @@ export type TokensBalance = {
24
24
  [key: TokenHash]: Balance;
25
25
  };
26
26
 
27
- export type WalletInfoWithNamespaces = WalletInfo & {
27
+ export type WalletInfoWithExtra = WalletInfo & {
28
28
  namespaces?: Namespace[];
29
29
  singleNamespace?: boolean;
30
+ needsDerivationPath?: boolean;
30
31
  };
@@ -1,4 +1,4 @@
1
- import type { WalletInfoWithNamespaces } from '../types';
1
+ import type { WalletInfoWithExtra } from '../types';
2
2
  import type { Token } from 'rango-sdk';
3
3
 
4
4
  import { BlockchainCategories, WalletState } from '@rango-dev/ui';
@@ -250,7 +250,7 @@ export const getFontUrlByName = (fontName: string) => {
250
250
  };
251
251
 
252
252
  export function isSingleWalletActive(
253
- wallets: WalletInfoWithNamespaces[],
253
+ wallets: WalletInfoWithExtra[],
254
254
  multiWallets?: boolean
255
255
  ) {
256
256
  const atLeastOneWalletIsConnected = !!wallets.find(
@@ -5,7 +5,7 @@ import type {
5
5
  SelectedQuote,
6
6
  TokensBalance,
7
7
  Wallet,
8
- WalletInfoWithNamespaces,
8
+ WalletInfoWithExtra,
9
9
  } from '../types';
10
10
  import type { WalletInfo as ModalWalletInfo } from '@rango-dev/ui';
11
11
  import type {
@@ -68,7 +68,7 @@ export function mapWalletTypesToWalletInfo(
68
68
  getWalletInfo: (type: WalletType) => WalletInfo,
69
69
  list: WalletType[],
70
70
  chain?: string
71
- ): WalletInfoWithNamespaces[] {
71
+ ): WalletInfoWithExtra[] {
72
72
  return list
73
73
  .filter((wallet) => !EXCLUDED_WALLETS.includes(wallet as WalletTypes))
74
74
  .filter((wallet) => {
@@ -96,6 +96,7 @@ export function mapWalletTypesToWalletInfo(
96
96
  namespaces,
97
97
  singleNamespace,
98
98
  supportedChains,
99
+ needsDerivationPath,
99
100
  } = getWalletInfo(type);
100
101
  const blockchainTypes = removeDuplicateFrom(
101
102
  supportedChains.map((item) => item.type)
@@ -112,6 +113,7 @@ export function mapWalletTypesToWalletInfo(
112
113
  namespaces,
113
114
  singleNamespace,
114
115
  blockchainTypes,
116
+ needsDerivationPath,
115
117
  };
116
118
  });
117
119
  }
@@ -434,8 +436,8 @@ export function areTokensEqual(
434
436
  }
435
437
 
436
438
  export function sortWalletsBasedOnConnectionState(
437
- wallets: WalletInfoWithNamespaces[]
438
- ): WalletInfoWithNamespaces[] {
439
+ wallets: WalletInfoWithExtra[]
440
+ ): WalletInfoWithExtra[] {
439
441
  return wallets.sort(
440
442
  (a, b) =>
441
443
  Number(b.state === WalletStatus.CONNECTED) -
@@ -549,7 +551,7 @@ export function filterBlockchainsByWalletTypes(
549
551
  }
550
552
 
551
553
  export function filterWalletsByCategory(
552
- wallets: WalletInfoWithNamespaces[],
554
+ wallets: WalletInfoWithExtra[],
553
555
  category: string
554
556
  ) {
555
557
  if (category === BlockchainCategories.ALL) {