@b3dotfun/sdk 0.0.47-test.4 → 0.0.47-test.5

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.
@@ -39,6 +39,7 @@ function useAuthentication(partnerId) {
39
39
  const wagmiConfig = (0, useWagmiConfig_1.useWagmiConfig)(partnerId);
40
40
  const { connect } = (0, wagmi_1.useConnect)();
41
41
  const activeWagmiAccount = (0, wagmi_1.useAccount)();
42
+ const { switchAccount } = (0, wagmi_1.useSwitchAccount)();
42
43
  debug("@@activeWagmiAccount", activeWagmiAccount);
43
44
  const wallet = (0, wallets_1.ecosystemWallet)(constants_1.ecosystemWalletId, {
44
45
  partnerId: partnerId,
@@ -54,9 +55,18 @@ function useAuthentication(partnerId) {
54
55
  // or, since ecosystem wallets is separate, connect those via in-app-wallet from wagmi
55
56
  connectors.forEach(async (connector) => {
56
57
  const twWallet = wallets.find(wallet => wallet.id === connector.id || connector.id === "in-app-wallet");
57
- if (twWallet &&
58
- // If it's not an in-app wallet or it is the ecosystem wallet, connect
59
- (connector.id !== "in-app-wallet" || (connector.id === "in-app-wallet" && twWallet.id === constants_1.ecosystemWalletId))) {
58
+ // If no TW wallet, do not prompt the user to connect
59
+ if (!twWallet) {
60
+ return;
61
+ }
62
+ // Metamask will prompt to connect, we can just switch accounts here.
63
+ if (connector.id === "io.metamask") {
64
+ return switchAccount({ connector });
65
+ }
66
+ if (
67
+ // If it's not an in-app wallet or it is the ecosystem wallet, connect
68
+ connector.id !== "in-app-wallet" ||
69
+ (connector.id === "in-app-wallet" && twWallet.id === constants_1.ecosystemWalletId)) {
60
70
  try {
61
71
  const options = {
62
72
  wallet: twWallet, // the connected wallet
@@ -9,7 +9,7 @@ import { useCallback, useEffect, useRef } from "react";
9
9
  import { useActiveWallet, useAutoConnect, useConnectedWallets, useDisconnect, useSetActiveWallet, } from "thirdweb/react";
10
10
  import { ecosystemWallet } from "thirdweb/wallets";
11
11
  import { preAuthenticate } from "thirdweb/wallets/in-app";
12
- import { useAccount, useConnect } from "wagmi";
12
+ import { useAccount, useConnect, useSwitchAccount } from "wagmi";
13
13
  import { useUserQuery } from "./useUserQuery.js";
14
14
  import { useWagmiConfig } from "./useWagmiConfig.js";
15
15
  const debug = debugB3React("useAuthentication");
@@ -33,6 +33,7 @@ export function useAuthentication(partnerId) {
33
33
  const wagmiConfig = useWagmiConfig(partnerId);
34
34
  const { connect } = useConnect();
35
35
  const activeWagmiAccount = useAccount();
36
+ const { switchAccount } = useSwitchAccount();
36
37
  debug("@@activeWagmiAccount", activeWagmiAccount);
37
38
  const wallet = ecosystemWallet(ecosystemWalletId, {
38
39
  partnerId: partnerId,
@@ -48,9 +49,18 @@ export function useAuthentication(partnerId) {
48
49
  // or, since ecosystem wallets is separate, connect those via in-app-wallet from wagmi
49
50
  connectors.forEach(async (connector) => {
50
51
  const twWallet = wallets.find(wallet => wallet.id === connector.id || connector.id === "in-app-wallet");
51
- if (twWallet &&
52
- // If it's not an in-app wallet or it is the ecosystem wallet, connect
53
- (connector.id !== "in-app-wallet" || (connector.id === "in-app-wallet" && twWallet.id === ecosystemWalletId))) {
52
+ // If no TW wallet, do not prompt the user to connect
53
+ if (!twWallet) {
54
+ return;
55
+ }
56
+ // Metamask will prompt to connect, we can just switch accounts here.
57
+ if (connector.id === "io.metamask") {
58
+ return switchAccount({ connector });
59
+ }
60
+ if (
61
+ // If it's not an in-app wallet or it is the ecosystem wallet, connect
62
+ connector.id !== "in-app-wallet" ||
63
+ (connector.id === "in-app-wallet" && twWallet.id === ecosystemWalletId)) {
54
64
  try {
55
65
  const options = {
56
66
  wallet: twWallet, // the connected wallet
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@b3dotfun/sdk",
3
- "version": "0.0.47-test.4",
3
+ "version": "0.0.47-test.5",
4
4
  "source": "src/index.ts",
5
5
  "main": "./dist/cjs/index.js",
6
6
  "react-native": "./dist/cjs/index.native.js",
@@ -16,7 +16,7 @@ import {
16
16
  } from "thirdweb/react";
17
17
  import { ecosystemWallet, Wallet } from "thirdweb/wallets";
18
18
  import { preAuthenticate } from "thirdweb/wallets/in-app";
19
- import { useAccount, useConnect } from "wagmi";
19
+ import { useAccount, useConnect, useSwitchAccount } from "wagmi";
20
20
  import { useUserQuery } from "./useUserQuery";
21
21
  import { useWagmiConfig } from "./useWagmiConfig";
22
22
 
@@ -42,6 +42,7 @@ export function useAuthentication(partnerId: string) {
42
42
  const wagmiConfig = useWagmiConfig(partnerId);
43
43
  const { connect } = useConnect();
44
44
  const activeWagmiAccount = useAccount();
45
+ const { switchAccount } = useSwitchAccount();
45
46
  debug("@@activeWagmiAccount", activeWagmiAccount);
46
47
 
47
48
  const wallet = ecosystemWallet(ecosystemWalletId, {
@@ -60,10 +61,21 @@ export function useAuthentication(partnerId: string) {
60
61
  // or, since ecosystem wallets is separate, connect those via in-app-wallet from wagmi
61
62
  connectors.forEach(async connector => {
62
63
  const twWallet = wallets.find(wallet => wallet.id === connector.id || connector.id === "in-app-wallet");
64
+
65
+ // If no TW wallet, do not prompt the user to connect
66
+ if (!twWallet) {
67
+ return;
68
+ }
69
+
70
+ // Metamask will prompt to connect, we can just switch accounts here.
71
+ if (connector.id === "io.metamask") {
72
+ return switchAccount({ connector });
73
+ }
74
+
63
75
  if (
64
- twWallet &&
65
76
  // If it's not an in-app wallet or it is the ecosystem wallet, connect
66
- (connector.id !== "in-app-wallet" || (connector.id === "in-app-wallet" && twWallet.id === ecosystemWalletId))
77
+ connector.id !== "in-app-wallet" ||
78
+ (connector.id === "in-app-wallet" && twWallet.id === ecosystemWalletId)
67
79
  ) {
68
80
  try {
69
81
  const options = {