@rango-dev/widget-embedded 0.49.0 → 0.49.1-next.0

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.49.0",
3
+ "version": "0.49.1-next.0",
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.11.0",
28
- "@rango-dev/provider-all": "^0.51.0",
28
+ "@rango-dev/provider-all": "^0.51.1-next.0",
29
29
  "@rango-dev/queue-manager-core": "^0.32.0",
30
- "@rango-dev/queue-manager-rango-preset": "^0.51.0",
30
+ "@rango-dev/queue-manager-rango-preset": "^0.51.1-next.0",
31
31
  "@rango-dev/queue-manager-react": "^0.32.0",
32
32
  "@rango-dev/signer-solana": "^0.44.0",
33
- "@rango-dev/ui": "^0.52.0",
34
- "@rango-dev/wallets-core": "^0.48.0",
35
- "@rango-dev/wallets-react": "^0.35.0",
36
- "@rango-dev/wallets-shared": "^0.49.0",
33
+ "@rango-dev/ui": "^0.52.1-next.0",
34
+ "@rango-dev/wallets-core": "^0.48.1-next.0",
35
+ "@rango-dev/wallets-react": "^0.35.1-next.0",
36
+ "@rango-dev/wallets-shared": "^0.49.1-next.0",
37
37
  "bignumber.js": "^9.1.1",
38
38
  "copy-to-clipboard": "^3.3.3",
39
39
  "dayjs": "^1.11.7",
@@ -15,6 +15,7 @@ import React, { useEffect, useState } from 'react';
15
15
 
16
16
  import { useWallets } from '../..';
17
17
  import { WIDGET_UI_ID } from '../../constants';
18
+ import { useDeepLink } from '../../hooks/useDeepLink';
18
19
  import { useWalletList } from '../../hooks/useWalletList';
19
20
  import { useAppStore } from '../../store/AppStore';
20
21
  import { useUiStore } from '../../store/ui';
@@ -38,7 +39,7 @@ export function WalletList(props: PropTypes) {
38
39
  const { chain, quoteChains, isSelected, selectWallet, limit, onShowMore } =
39
40
  props;
40
41
  const isActiveTab = useUiStore.use.isActiveTab();
41
-
42
+ const { checkHasDeepLink, getWalletLink } = useDeepLink();
42
43
  const { blockchains, connectedWallets } = useAppStore();
43
44
  const [selectedWalletToConnect, setSelectedWalletToConnect] =
44
45
  useState<ExtendedModalWalletInfo>();
@@ -159,7 +160,9 @@ export function WalletList(props: PropTypes) {
159
160
  }
160
161
  };
161
162
 
162
- const info = makeInfo(wallet.state);
163
+ const info = makeInfo(wallet.state, {
164
+ hasDeepLink: checkHasDeepLink(wallet.type),
165
+ });
163
166
 
164
167
  const getWalletDescription = () => {
165
168
  if (couldAddExperimentalChain) {
@@ -226,6 +229,7 @@ export function WalletList(props: PropTypes) {
226
229
  </WatermarkedModal>
227
230
  )}
228
231
  <SelectableWallet
232
+ hasDeepLink={checkHasDeepLink(wallet.type)}
229
233
  key={wallet.type}
230
234
  id="widget-wallets-list-selectable-wallet-btn"
231
235
  description={getWalletDescription()}
@@ -234,6 +238,7 @@ export function WalletList(props: PropTypes) {
234
238
  selected={isSelected(wallet.type, chain)}
235
239
  disabled={!isActiveTab}
236
240
  {...wallet}
241
+ link={getWalletLink(wallet.type)}
237
242
  />
238
243
  </React.Fragment>
239
244
  );
@@ -0,0 +1,48 @@
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
+ }
@@ -20,6 +20,7 @@ import {
20
20
  sortWalletsBasedOnConnectionState,
21
21
  } from '../utils/wallets';
22
22
 
23
+ import { useDeepLink } from './useDeepLink';
23
24
  import { useStatefulConnect } from './useStatefulConnect/useStatefulConnect';
24
25
 
25
26
  interface Params {
@@ -44,6 +45,7 @@ export function useWalletList(params?: Params): API {
44
45
  const { state, getWalletInfo } = useWallets();
45
46
  const blockchains = useAppStore().blockchains();
46
47
  const { handleDisconnect } = useStatefulConnect();
48
+ const { checkHasDeepLink } = useDeepLink();
47
49
 
48
50
  /** It can be what has been set by widget config or as a fallback we use all the supported wallets by our library */
49
51
  const listAvailableWalletTypes = configWalletsToWalletName(
@@ -60,7 +62,8 @@ export function useWalletList(params?: Params): API {
60
62
  wallets = detectMobileScreens()
61
63
  ? wallets.filter(
62
64
  (wallet) =>
63
- wallet.showOnMobile !== false && state(wallet.type).installed
65
+ wallet.showOnMobile !== false &&
66
+ (state(wallet.type).installed || checkHasDeepLink(wallet.type))
64
67
  )
65
68
  : wallets;
66
69
 
@@ -15,6 +15,7 @@ import React, { useState } from 'react';
15
15
 
16
16
  import { Layout, PageContainer } from '../components/Layout';
17
17
  import { StatefulConnectModal } from '../components/StatefulConnectModal';
18
+ import { useDeepLink } from '../hooks/useDeepLink';
18
19
  import { useWalletList } from '../hooks/useWalletList';
19
20
  import { useAppStore } from '../store/AppStore';
20
21
  import { useUiStore } from '../store/ui';
@@ -45,7 +46,7 @@ export function WalletsPage() {
45
46
  const blockchains = useAppStore().blockchains();
46
47
  const { config } = useAppStore();
47
48
  const { state } = useWallets();
48
-
49
+ const { checkHasDeepLink, getWalletLink } = useDeepLink();
49
50
  const [selectedWalletToConnect, setSelectedWalletToConnect] =
50
51
  useState<WalletInfoWithExtra>();
51
52
  const isActiveTab = useUiStore.use.isActiveTab();
@@ -95,6 +96,7 @@ export function WalletsPage() {
95
96
  wallet,
96
97
  namespacesState
97
98
  );
99
+
98
100
  return (
99
101
  <Wallet
100
102
  key={key}
@@ -104,6 +106,8 @@ export function WalletsPage() {
104
106
  ? WalletState.PARTIALLY_CONNECTED
105
107
  : wallet.state
106
108
  }
109
+ hasDeepLink={checkHasDeepLink(wallet.type)}
110
+ link={getWalletLink(wallet.type)}
107
111
  container={getContainer()}
108
112
  onClick={() => handleWalletItemClick(wallet)}
109
113
  isLoading={fetchMetaStatus === 'loading'}
@@ -175,7 +175,19 @@ export type TrezorManifest = {
175
175
  appUrl: string;
176
176
  email: string;
177
177
  };
178
-
178
+ /**
179
+ * `DeepLinking`
180
+ *
181
+ * @property {string} [targetUrl]
182
+ * - The URL to be opened in the provider's in-app browser.
183
+ *
184
+ * @property {string} [appHost]
185
+ * - The full domain of the app, excluding the protocol (https://), path, and query parameters.
186
+ */
187
+ export type DeepLinking = {
188
+ targetUrl: string;
189
+ appHost: string;
190
+ };
179
191
  /**
180
192
  *
181
193
  * @property {string} manifestUrl - The URL of the TON Connect [manifest]{@link https://github.com/ton-connect/docs/blob/main/requests-responses.md#app-manifest}, containing the Dapp metadata to be displayed in the user’s wallet.
@@ -223,6 +235,7 @@ export type TonConnectConfig = {
223
235
  * @property {WidgetTheme} theme - The `theme` property is a part of the `WidgetConfig` type and is
224
236
  * used to specify the visual theme of the widget. It is of type `WidgetTheme`, which is an interface
225
237
  * that defines the various properties of the theme, such as colors, fonts, and others.
238
+ * @property {DeepLinking} deepLinking - Configures deep linking parameters for providers that support it.
226
239
  * @property {boolean} externalWallets
227
240
  * If `externalWallets` is `true`, you should add `WidgetWallets` to your app.
228
241
  * @property {boolean} excludeLiquiditySources - The `excludeLiquiditySources` property is a boolean value that when you
@@ -265,6 +278,7 @@ export type WidgetConfig = {
265
278
  defaultCustomDestinations?: { [blockchain: string]: string };
266
279
  language?: Language;
267
280
  theme?: WidgetTheme;
281
+ deepLinking?: DeepLinking;
268
282
  externalWallets?: boolean;
269
283
  excludeLiquiditySources?: boolean;
270
284
  features?: Features;
@@ -96,7 +96,6 @@ export function mapWalletTypesToWalletInfo(
96
96
  const blockchainTypes = removeDuplicateFrom(
97
97
  supportedChains.map((item) => item.type)
98
98
  );
99
-
100
99
  const state = mapStatusToWalletState(getState(type));
101
100
  return {
102
101
  title: name,
@@ -113,7 +112,6 @@ export function mapWalletTypesToWalletInfo(
113
112
  };
114
113
  });
115
114
  }
116
-
117
115
  export function walletAndSupportedChainsNames(
118
116
  supportedBlockchains: BlockchainMeta[]
119
117
  ): Network[] | null {