@coin-voyage/paykit 2.2.1 → 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
|
|
19
|
-
const { connectorChainType } =
|
|
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
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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
|
-
|
|
65
|
-
const
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
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
|
|
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
|
};
|
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.
|
|
4
|
+
"version": "2.2.2",
|
|
5
5
|
"private": false,
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"author": "Lars <lars@coinvoyage.io>",
|
|
@@ -61,8 +61,8 @@
|
|
|
61
61
|
"react-use-measure": "^2.1.1",
|
|
62
62
|
"styled-components": "^5.3.11",
|
|
63
63
|
"uuid": "13.0.0",
|
|
64
|
-
"@coin-voyage/
|
|
65
|
-
"@coin-voyage/
|
|
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",
|