@coin-voyage/paykit 2.2.0 → 2.2.2

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.
@@ -7,6 +7,7 @@ import { useLastConnector, useUniversalConnect } from "@coin-voyage/crypto/hooks
7
7
  import { isWalletInstalled } from "@coin-voyage/crypto/lib/utils/is-wallet-installed";
8
8
  import { useIsMobile } from "@coin-voyage/shared/hooks";
9
9
  import { detectBrowser } from "@coin-voyage/shared/utils";
10
+ import { useCallback, useMemo } from "react";
10
11
  import useLocales from "../../../hooks/useLocales";
11
12
  import { useWalletConnectUri } from "../../../hooks/useWalletConnectUri";
12
13
  import { useWallets } from "../../../hooks/useWallets";
@@ -14,34 +15,34 @@ import { walletConfigs } from "../../../lib/config/wallet";
14
15
  import { isCoinbaseWalletConnector, isMobileWalletConnector, isWalletConnectConnector } from "../../../utils";
15
16
  import usePayContext from "../../contexts/pay";
16
17
  const ignoreHoist = ["walletConnect", "WalletConnect", "mobileWallet"];
18
+ const browser = detectBrowser();
17
19
  export default function ConnectorList() {
18
- const context = usePayContext();
19
- const { connectorChainType } = context.paymentState;
20
+ const { paymentState, options } = usePayContext();
21
+ const { connectorChainType } = paymentState;
20
22
  const isMobile = useIsMobile();
23
+ const { uri } = useWalletConnectUri();
21
24
  const installedWallets = useWallets();
22
25
  const { lastConnectorId } = useLastConnector();
23
- const mobileWallet = walletConfigs["mobileWallet"];
24
- if (isMobile && connectorChainType && mobileWallet.chainTypes?.includes(connectorChainType)) {
25
- installedWallets.push({
26
- id: "mobileWallet",
27
- ...mobileWallet,
28
- isInstalled: true,
29
- connectors: [],
30
- });
31
- }
32
- const walletsToDisplay = context.options?.hideRecentBadge || (lastConnectorId && ignoreHoist.includes(lastConnectorId))
33
- ? installedWallets
34
- : [
35
- // move last used wallet to top of list
36
- // using .filter and spread to avoid mutating original array order with .sort
37
- ...installedWallets.filter((wallet) => lastConnectorId === wallet.id),
38
- ...installedWallets.filter((wallet) => lastConnectorId !== wallet.id),
39
- ];
40
- return (_jsx(ScrollArea, { children: walletsToDisplay.length > 0 ? (_jsx(ConnectorsContainer, { "$totalResults": walletsToDisplay.length, children: walletsToDisplay.map((wallet) => (_jsx(ConnectorItem, { wallet: wallet, isRecent: wallet.id === lastConnectorId }, wallet.id))) })) : (_jsx(Alert, { error: true, children: "No wallets found." })) }));
26
+ const walletsToDisplay = useMemo(() => {
27
+ let wallets = [...installedWallets];
28
+ const mobileWallet = walletConfigs["mobileWallet"];
29
+ if (isMobile && connectorChainType && mobileWallet.chainTypes?.includes(connectorChainType)) {
30
+ wallets.push({
31
+ id: "mobileWallet",
32
+ ...mobileWallet,
33
+ isInstalled: true,
34
+ connectors: [],
35
+ });
36
+ }
37
+ if (options?.hideRecentBadge || !lastConnectorId || ignoreHoist.includes(lastConnectorId)) {
38
+ return wallets;
39
+ }
40
+ return [...wallets.filter((w) => w.id === lastConnectorId), ...wallets.filter((w) => w.id !== lastConnectorId)];
41
+ }, [installedWallets, isMobile, connectorChainType, lastConnectorId, options]);
42
+ return (_jsx(ScrollArea, { children: walletsToDisplay.length > 0 ? (_jsx(ConnectorsContainer, { "$totalResults": walletsToDisplay.length, children: walletsToDisplay.map((wallet) => (_jsx(ConnectorItem, { wallet: wallet, walletConnectURI: uri, isRecent: wallet.id === lastConnectorId }, wallet.id))) })) : (_jsx(Alert, { error: true, children: "No wallets found." })) }));
41
43
  }
42
- const ConnectorItem = ({ wallet, isRecent }) => {
44
+ const ConnectorItem = ({ wallet, isRecent, walletConnectURI, }) => {
43
45
  const locales = useLocales();
44
- const { uri } = useWalletConnectUri();
45
46
  const isMobile = useIsMobile();
46
47
  const { route, setRoute, options, paymentState } = usePayContext();
47
48
  const { connect } = useUniversalConnect({
@@ -57,16 +58,27 @@ const ConnectorItem = ({ wallet, isRecent }) => {
57
58
  },
58
59
  });
59
60
  const walletConfig = walletConfigs[wallet.id];
60
- let deeplink = !isWalletInstalled(wallet.id) && isMobile && walletConfig
61
- ? walletConfig.getWalletDeeplink?.(uri ?? "", paymentState.connectorChainType)
62
- : undefined;
63
61
  const redirectToMoreWallets = isMobile && (isWalletConnectConnector(wallet.id) || isMobileWalletConnector(wallet.id));
64
- // Safari requires opening popup on user gesture, so we connect immediately here
65
- const shouldConnectImmediately = (detectBrowser() === "safari" || detectBrowser() === "ios") && isCoinbaseWalletConnector(wallet.id);
66
- if (redirectToMoreWallets || shouldConnectImmediately) {
67
- deeplink = undefined; // mobile redirects to more wallets page
68
- }
69
- const handleClick = () => {
62
+ const shouldConnectImmediately = (browser === "safari" || browser === "ios") && isCoinbaseWalletConnector(wallet.id);
63
+ const deeplink = useMemo(() => {
64
+ if (redirectToMoreWallets ||
65
+ shouldConnectImmediately ||
66
+ isWalletInstalled(wallet.id) ||
67
+ !isMobile ||
68
+ !walletConfig) {
69
+ return undefined;
70
+ }
71
+ return walletConfig.getWalletDeeplink?.(walletConnectURI ?? "", paymentState.connectorChainType);
72
+ }, [
73
+ redirectToMoreWallets,
74
+ shouldConnectImmediately,
75
+ wallet.id,
76
+ isMobile,
77
+ walletConfig,
78
+ walletConnectURI,
79
+ paymentState.connectorChainType,
80
+ ]);
81
+ const handleClick = useCallback(() => {
70
82
  if (deeplink)
71
83
  return;
72
84
  if (redirectToMoreWallets) {
@@ -77,10 +89,10 @@ const ConnectorItem = ({ wallet, isRecent }) => {
77
89
  const walletConnector = wallet.connectors.find((w) => w.chainType === paymentState.connectorChainType);
78
90
  if (!walletConnector)
79
91
  return;
80
- connect({ walletConnector: walletConnector });
92
+ connect({ walletConnector });
81
93
  }
82
- setRoute(ROUTES.CONNECT);
83
94
  paymentState.setSelectedWallet(wallet);
84
- };
95
+ setRoute(ROUTES.CONNECT);
96
+ }, [deeplink, redirectToMoreWallets, shouldConnectImmediately, wallet, paymentState, setRoute, connect]);
85
97
  return (_jsxs(ConnectorButton, { type: "button", as: deeplink ? "a" : undefined, href: deeplink, disabled: route !== ROUTES.CONNECTORS, onClick: handleClick, children: [_jsx(ConnectorIcon, { "data-small": wallet.iconShouldShrink, "data-shape": wallet.iconShape, children: wallet.iconConnector ?? wallet.icon }), _jsxs(ConnectorLabel, { children: [isMobile ? (wallet.shortName ?? wallet.name) : wallet.name, !options?.hideRecentBadge && isRecent && _jsx(RecentlyUsedTag, { children: locales.recent })] })] }));
86
98
  };
@@ -51,10 +51,7 @@ export function useWalletConnectUri({ enabled } = { enabled: true }) {
51
51
  };
52
52
  }, [wcConnector, log]);
53
53
  useEffect(() => {
54
- if (!enabled ||
55
- !wcConnector ||
56
- account.isConnected ||
57
- isConnectingRef.current) {
54
+ if (!enabled || !wcConnector || account.isConnected || isConnectingRef.current) {
58
55
  return;
59
56
  }
60
57
  isConnectingRef.current = true;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@coin-voyage/paykit",
3
3
  "description": "Seamless crypto payments. Onboard users from any chain, any coin into your app with one click.",
4
- "version": "2.2.0",
4
+ "version": "2.2.2",
5
5
  "private": false,
6
6
  "sideEffects": false,
7
7
  "author": "Lars <lars@coinvoyage.io>",
@@ -61,12 +61,13 @@
61
61
  "react-use-measure": "^2.1.1",
62
62
  "styled-components": "^5.3.11",
63
63
  "uuid": "13.0.0",
64
- "@coin-voyage/crypto": "2.2.0",
65
- "@coin-voyage/shared": "2.2.0"
64
+ "@coin-voyage/shared": "2.2.0",
65
+ "@coin-voyage/crypto": "2.2.2"
66
66
  },
67
67
  "devDependencies": {
68
68
  "@types/qrcode": "1.5.5",
69
69
  "@types/styled-components": "^5.1.26",
70
+ "pino-pretty": "^13.0.0",
70
71
  "typescript-plugin-styled-components": "^3.0.0"
71
72
  },
72
73
  "peerDependencies": {