@rango-dev/widget-embedded 0.51.1-next.1 → 0.51.1-next.10

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 (46) hide show
  1. package/dist/components/ConfirmWalletsModal/WalletList.d.ts.map +1 -1
  2. package/dist/components/HeaderButtons/WalletButton.d.ts.map +1 -1
  3. package/dist/components/Layout/Layout.constants.d.ts +5 -3
  4. package/dist/components/Layout/Layout.constants.d.ts.map +1 -1
  5. package/dist/components/Layout/Layout.d.ts.map +1 -1
  6. package/dist/components/Layout/Layout.styles.d.ts.map +1 -1
  7. package/dist/components/WalletStatefulConnect/ConnectStatus.d.ts.map +1 -1
  8. package/dist/components/WalletStatefulConnect/Detached.d.ts.map +1 -1
  9. package/dist/components/WalletStatefulConnect/Namespaces.d.ts.map +1 -1
  10. package/dist/containers/App/App.styles.d.ts.map +1 -1
  11. package/dist/hooks/useScreenDetect.d.ts.map +1 -1
  12. package/dist/hooks/useWalletList.d.ts.map +1 -1
  13. package/dist/index.js +2 -2
  14. package/dist/index.js.map +4 -4
  15. package/dist/pages/SelectBlockchainPage.d.ts.map +1 -1
  16. package/dist/pages/WalletsPage.d.ts.map +1 -1
  17. package/dist/store/slices/data.d.ts.map +1 -1
  18. package/dist/types/config.d.ts +0 -15
  19. package/dist/types/config.d.ts.map +1 -1
  20. package/dist/utils/common.d.ts +2 -1
  21. package/dist/utils/common.d.ts.map +1 -1
  22. package/dist/utils/wallets.d.ts +6 -13
  23. package/dist/utils/wallets.d.ts.map +1 -1
  24. package/dist/widget-embedded.build.json +1 -1
  25. package/package.json +10 -10
  26. package/src/components/ConfirmWalletsModal/WalletList.tsx +10 -9
  27. package/src/components/HeaderButtons/WalletButton.tsx +4 -2
  28. package/src/components/Layout/Layout.constants.ts +5 -3
  29. package/src/components/Layout/Layout.styles.ts +12 -5
  30. package/src/components/Layout/Layout.tsx +18 -32
  31. package/src/components/SwapDetailsModal/SwapDetailsModal.WalletState.tsx +3 -3
  32. package/src/components/WalletStatefulConnect/ConnectStatus.tsx +6 -3
  33. package/src/components/WalletStatefulConnect/Detached.tsx +16 -4
  34. package/src/components/WalletStatefulConnect/Namespaces.tsx +16 -4
  35. package/src/containers/App/App.styles.ts +1 -0
  36. package/src/hooks/useScreenDetect.ts +7 -1
  37. package/src/hooks/useWalletList.ts +2 -5
  38. package/src/pages/SelectBlockchainPage.tsx +14 -5
  39. package/src/pages/WalletsPage.tsx +1 -20
  40. package/src/store/slices/data.ts +2 -13
  41. package/src/types/config.ts +1 -15
  42. package/src/utils/common.ts +16 -1
  43. package/src/utils/wallets.ts +42 -52
  44. package/dist/hooks/useDeepLink.d.ts +0 -7
  45. package/dist/hooks/useDeepLink.d.ts.map +0 -1
  46. package/src/hooks/useDeepLink.ts +0 -48
@@ -1,5 +1,5 @@
1
1
  import type { WalletInfoWithExtra } from '../types';
2
- import type { Token } from 'rango-sdk';
2
+ import type { BlockchainMeta, Token } from 'rango-sdk';
3
3
 
4
4
  import { BlockchainCategories, WalletState } from '@rango-dev/ui';
5
5
  import { TransactionType } from 'rango-sdk';
@@ -280,3 +280,18 @@ export function memoizedResult(): <R>(fn: () => R, key: number | string) => R {
280
280
  return result;
281
281
  };
282
282
  }
283
+
284
+ export function filterBlockchainsWithAtLeastOneToken(
285
+ blockchains: BlockchainMeta[],
286
+ tokens: Token[]
287
+ ) {
288
+ const blockchainsWithAtLeastOneToken = new Set<string>();
289
+
290
+ tokens.forEach((token) => {
291
+ blockchainsWithAtLeastOneToken.add(token.blockchain);
292
+ });
293
+
294
+ return blockchains.filter((blockchain) =>
295
+ blockchainsWithAtLeastOneToken.has(blockchain.name)
296
+ );
297
+ }
@@ -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,
@@ -112,6 +125,7 @@ export function mapWalletTypesToWalletInfo(
112
125
  };
113
126
  });
114
127
  }
128
+
115
129
  export function walletAndSupportedChainsNames(
116
130
  supportedBlockchains: BlockchainMeta[]
117
131
  ): Network[] | null {
@@ -418,42 +432,22 @@ export function areTokensEqual(
418
432
  }
419
433
 
420
434
  export function sortWalletsBasedOnConnectionState(
421
- wallets: ExtendedModalWalletInfo[],
422
- state: (type: WalletType) => {
423
- namespaces?: Map<Namespace, { connected: boolean }>;
424
- }
435
+ wallets: ExtendedModalWalletInfo[]
425
436
  ): 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)
437
+ return wallets.sort(
438
+ (a, b) =>
439
+ Number(b.state === WalletStatus.CONNECTED) -
440
+ Number(a.state === WalletStatus.CONNECTED) ||
441
+ Number(b.state === WalletStatus.PARTIALLY_CONNECTED) -
442
+ Number(a.state === WalletStatus.PARTIALLY_CONNECTED) ||
443
+ Number(
444
+ b.state === WalletStatus.DISCONNECTED ||
445
+ b.state === WalletStatus.CONNECTING
446
+ ) -
447
+ Number(
448
+ a.state === WalletStatus.DISCONNECTED ||
449
+ a.state === WalletStatus.CONNECTING
450
+ )
457
451
  );
458
452
  }
459
453
 
@@ -536,14 +530,10 @@ export function filterWalletsByCategory(
536
530
  }
537
531
 
538
532
  export function checkIsWalletPartiallyConnected(
539
- wallet: ExtendedModalWalletInfo,
540
- namespacesState?: Map<Namespace, { connected: boolean }>
533
+ wallet: ExtendedWalletInfo,
534
+ walletState: ReturnType<ProviderContext['state']>
541
535
  ) {
542
- if (
543
- !wallet.isHub ||
544
- !wallet.needsNamespace ||
545
- wallet.state !== WalletStatus.CONNECTED
546
- ) {
536
+ if (!wallet.isHub || !wallet.needsNamespace || !walletState.connected) {
547
537
  return false;
548
538
  }
549
539
  const namespaces = wallet.needsNamespace.data;
@@ -555,7 +545,7 @@ export function checkIsWalletPartiallyConnected(
555
545
  return (
556
546
  wallet.needsNamespace.selection === 'multiple' &&
557
547
  supportedNamespaces.some(
558
- (namespace) => !namespacesState?.get(namespace.value)?.connected
548
+ (namespace) => !walletState.namespaces?.get(namespace.value)?.connected
559
549
  )
560
550
  );
561
551
  }
@@ -1,7 +0,0 @@
1
- import type { InstallObjects } from '@rango-dev/wallets-shared';
2
- export declare function useDeepLink(): {
3
- getWalletDeepLink: (walletType: string) => string | undefined;
4
- getWalletLink: (walletType: string) => string | InstallObjects;
5
- checkHasDeepLink: (walletType: string) => boolean;
6
- };
7
- //# sourceMappingURL=useDeepLink.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useDeepLink.d.ts","sourceRoot":"","sources":["../../src/hooks/useDeepLink.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAOhE,wBAAgB,WAAW;oCAKc,MAAM,KAAG,MAAM,GAAG,SAAS;gCAsB/B,MAAM,KAAG,MAAM,GAAG,cAAc;mCAS7B,MAAM,KAAG,OAAO;EAIvD"}
@@ -1,48 +0,0 @@
1
- import type { InstallObjects } from '@rango-dev/wallets-shared';
2
-
3
- import { useWallets } from '@rango-dev/wallets-react';
4
- import { detectMobileScreens } from '@rango-dev/wallets-shared';
5
-
6
- import { useAppStore } from '../store/AppStore';
7
-
8
- export function useDeepLink() {
9
- const { getWalletInfo } = useWallets();
10
- const { config } = useAppStore();
11
- const isMobileScreen = detectMobileScreens();
12
-
13
- function getWalletDeepLink(walletType: string): string | undefined {
14
- const wallet = getWalletInfo(walletType);
15
- const appHost = config.deepLinking?.appHost;
16
- const targetUrl = config.deepLinking?.targetUrl;
17
- if (!appHost || !targetUrl) {
18
- return;
19
- }
20
- return wallet.generateDeepLink?.({
21
- appHost,
22
- targetUrl,
23
- });
24
- }
25
-
26
- /**
27
- * Returns the appropriate wallet link based on the given wallet type.
28
- *
29
- * If a deep link is available and the user is on a mobile screen, the deep link is returned.
30
- * Otherwise, it falls back to returning the wallet's install link.
31
- *
32
- * @param {string} walletType - The type of the wallet (e.g., 'metamask', 'trust-wallet').
33
- * @returns {string | InstallObjects} - A deep link string if available on mobile, or an install link object otherwise.
34
- */
35
- function getWalletLink(walletType: string): string | InstallObjects {
36
- const deepLink = getWalletDeepLink(walletType);
37
- if (deepLink && isMobileScreen) {
38
- return deepLink;
39
- }
40
- const wallet = getWalletInfo(walletType);
41
- return wallet.installLink;
42
- }
43
-
44
- function checkHasDeepLink(walletType: string): boolean {
45
- return !!getWalletDeepLink(walletType) && isMobileScreen;
46
- }
47
- return { getWalletDeepLink, getWalletLink, checkHasDeepLink };
48
- }