@getpara/cosmos-wallet-connectors 2.0.0-dev.0 → 2.0.0-dev.1

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/dist/index.js CHANGED
@@ -45,7 +45,6 @@ import {
45
45
  checkWallet,
46
46
  WalletType as GrazWalletType,
47
47
  useAccount,
48
- useActiveChainIds,
49
48
  useActiveWalletType,
50
49
  useConnect,
51
50
  useDisconnect,
@@ -94,19 +93,21 @@ function CosmosExternalWalletProvider({
94
93
  multiChain,
95
94
  shouldUseSuggestChainAndConnect,
96
95
  onSwitchChain,
97
- para
96
+ para,
97
+ walletsWithFullAuth,
98
+ connectedWallet
98
99
  }) {
99
100
  var _a, _b;
100
101
  const { suggestAndConnectAsync } = useSuggestChainAndConnect();
101
102
  const {
102
103
  data: account,
103
104
  isConnecting,
104
- isReconnecting
105
+ isReconnecting,
106
+ isConnected
105
107
  } = useAccount({
106
108
  chainId: multiChain ? chains.map((c) => c.chainId) : selectedChainId,
107
109
  multiChain
108
110
  });
109
- const activeChainIds = useActiveChainIds();
110
111
  const { connectAsync } = useConnect();
111
112
  const { disconnectAsync } = useDisconnect();
112
113
  const { walletType } = useActiveWalletType();
@@ -120,30 +121,51 @@ function CosmosExternalWalletProvider({
120
121
  yield para.logout();
121
122
  });
122
123
  const switchChain = (chainId) => __async(this, null, function* () {
124
+ var _a2;
123
125
  let error;
124
- const hasActiveChain = activeChainIds.includes(chainId);
125
- if (!hasActiveChain) {
126
- updateExternalWalletState({ isConnecting: true });
127
- let changeResp;
128
- changeResp = yield connect(walletType, chainId);
129
- onSwitchWallet(changeResp);
130
- updateExternalWalletState({ isConnecting: false });
131
- if (changeResp.error) {
132
- error = [changeResp == null ? void 0 : changeResp.error];
126
+ let changeResp = {};
127
+ try {
128
+ let chainInfo;
129
+ if (shouldUseSuggestChainAndConnect) {
130
+ chainInfo = getChainInfo({ chainId });
131
+ if (!chainInfo) {
132
+ console.error("Chain not found.");
133
+ return;
134
+ }
135
+ }
136
+ const connectedWallet2 = yield shouldUseSuggestChainAndConnect ? suggestAndConnectAsync({ walletType, chainInfo }) : connectAsync({ walletType, chainId });
137
+ changeResp.address = connectedWallet2.accounts[chainId].bech32Address;
138
+ changeResp.bufferAddress = connectedWallet2.accounts[chainId].address.toString();
139
+ } catch (err) {
140
+ if (err.message === "No wallet exists") {
141
+ changeResp.error = err.message;
142
+ } else {
143
+ console.error("Graz connection error:", err);
144
+ changeResp.error = "An unknown error occurred.";
133
145
  }
134
146
  }
135
- if (!error) {
147
+ onSwitchWallet(changeResp);
148
+ if (!changeResp.error) {
136
149
  onSwitchChain(chainId);
150
+ const storedExternalWallet = para.externalWallets[(_a2 = changeResp.bufferAddress) != null ? _a2 : ""];
151
+ para.setExternalWallet({
152
+ address: changeResp.bufferAddress,
153
+ type: WalletType.COSMOS,
154
+ provider: getProviderName(walletType),
155
+ addressBech32: changeResp.address,
156
+ withFullParaAuth: storedExternalWallet.isExternalWithParaAuth
157
+ });
137
158
  }
138
159
  return { error };
139
160
  });
140
- const login = (bufferAddress2, address2, providerName) => __async(this, null, function* () {
161
+ const login = (bufferAddress2, address2, isFullAuthWallet, providerName) => __async(this, null, function* () {
141
162
  try {
142
163
  return yield para.externalWalletLogin({
143
164
  address: bufferAddress2,
144
165
  type: WalletType.COSMOS,
145
166
  provider: providerName,
146
- addressBech32: address2
167
+ addressBech32: address2,
168
+ withFullParaAuth: isFullAuthWallet
147
169
  });
148
170
  } catch (err) {
149
171
  yield reset();
@@ -152,21 +174,27 @@ function CosmosExternalWalletProvider({
152
174
  });
153
175
  useEffect(() => {
154
176
  const storedExternalWallet = para.externalWallets[bufferAddress != null ? bufferAddress : ""];
155
- if (!isConnecting && !isReconnecting && !isLocalConnecting && address && storedExternalWallet && storedExternalWallet.address !== address && walletType !== GrazWalletType.PARA) {
156
- para.setExternalWallet({
157
- address: bufferAddress,
158
- type: WalletType.COSMOS,
159
- provider: getProviderName(walletType),
160
- addressBech32: address
161
- });
162
- }
163
- }, [isConnecting, isReconnecting, address]);
164
- useEffect(() => {
165
- const storedExternalWallet = para.externalWallets[bufferAddress != null ? bufferAddress : ""];
166
- if (!isConnecting && !isReconnecting && !isLocalConnecting && !!bufferAddress && !storedExternalWallet && walletType !== GrazWalletType.PARA) {
177
+ if (isConnected && !isConnecting && !isReconnecting && !isLocalConnecting && !!bufferAddress && !storedExternalWallet && walletType !== GrazWalletType.PARA) {
167
178
  reset();
168
179
  }
169
- }, [isConnecting, isReconnecting]);
180
+ }, [isConnecting, isLocalConnecting, isReconnecting, isConnected]);
181
+ useEffect(() => {
182
+ const connect2 = () => __async(this, null, function* () {
183
+ var _a2;
184
+ if (!isLocalConnecting && !isConnecting && !isReconnecting && connectedWallet && connectedWallet.type === WalletType.COSMOS && (connectedWallet.isExternal ? walletType !== ((_a2 = connectedWallet.name) == null ? void 0 : _a2.toLowerCase()) : walletType !== "para")) {
185
+ const isLoggedIn = yield para.isFullyLoggedIn();
186
+ if (!isLoggedIn) {
187
+ return;
188
+ }
189
+ const chainId = multiChain ? chains.map((c) => c.chainId) : selectedChainId;
190
+ yield connectAsync({
191
+ walletType: connectedWallet.isExternal ? connectedWallet.name.toLowerCase() : GrazWalletType.PARA,
192
+ chainId
193
+ });
194
+ }
195
+ });
196
+ connect2();
197
+ }, [isLocalConnecting, isConnecting, isReconnecting, walletType, connectedWallet]);
170
198
  const signMessage = (message) => __async(this, null, function* () {
171
199
  const wallet = grazGetWallet(walletType);
172
200
  if (!wallet) {
@@ -193,7 +221,10 @@ function CosmosExternalWalletProvider({
193
221
  return signature;
194
222
  });
195
223
  const connect = (walletType2, chainId) => __async(this, null, function* () {
224
+ var _a2;
196
225
  updateExternalWalletState({ isConnecting: true });
226
+ const walletId = (_a2 = getWallet(walletType2)) == null ? void 0 : _a2.id;
227
+ const isFullAuthWallet = walletsWithFullAuth.includes(walletId.toUpperCase());
197
228
  if (!chainId) {
198
229
  yield disconnectAsync();
199
230
  }
@@ -224,13 +255,13 @@ function CosmosExternalWalletProvider({
224
255
  return;
225
256
  }
226
257
  }
227
- const connectedWallet = yield shouldUseSuggestChainAndConnect ? suggestAndConnectAsync({ walletType: walletType2, chainInfo }) : connectAsync({ walletType: walletType2, chainId: _chainId });
228
- const firstChain = typeof _chainId === "string" ? _chainId : _chainId[0];
229
- address2 = connectedWallet.accounts[firstChain].bech32Address;
230
- bufferAddress2 = connectedWallet.accounts[firstChain].address.toString();
231
- if (connectedWallet.accounts[firstChain]) {
258
+ const connectedWallet2 = yield shouldUseSuggestChainAndConnect ? suggestAndConnectAsync({ walletType: walletType2, chainInfo }) : connectAsync({ walletType: walletType2, chainId: _chainId });
259
+ const firstChain = !chainId ? selectedChainId : typeof _chainId === "string" ? _chainId : _chainId[0];
260
+ address2 = connectedWallet2.accounts[firstChain].bech32Address;
261
+ bufferAddress2 = connectedWallet2.accounts[firstChain].address.toString();
262
+ if (connectedWallet2.accounts[firstChain]) {
232
263
  try {
233
- const loginResp = yield login(bufferAddress2, address2, getProviderName(walletType2));
264
+ const loginResp = yield login(bufferAddress2, address2, isFullAuthWallet, getProviderName(walletType2));
234
265
  userExists = loginResp.userExists;
235
266
  isVerified = loginResp.isVerified;
236
267
  verificationMessage.current = loginResp.signatureVerificationMessage;
@@ -252,14 +283,15 @@ function CosmosExternalWalletProvider({
252
283
  updateExternalWalletState({ isConnecting: false });
253
284
  return { address: address2, bufferAddress: bufferAddress2, error, userExists, isVerified };
254
285
  });
286
+ const getWallet = (walletType2) => incompleteWallets.find((w) => w.grazType === walletType2 || w.grazMobileType === walletType2);
255
287
  const getProviderName = (walletType2) => {
256
288
  var _a2;
257
- return (_a2 = incompleteWallets.find((w) => w.grazType === walletType2 || w.grazMobileType === walletType2)) == null ? void 0 : _a2.name;
289
+ return (_a2 = getWallet(walletType2)) == null ? void 0 : _a2.name;
258
290
  };
259
291
  const wallets = incompleteWallets.map((wallet) => {
260
292
  return __spreadProps(__spreadValues({
261
293
  connect: () => connect(wallet.grazType),
262
- connectMobile: () => connect(wallet.grazMobileType),
294
+ connectMobile: () => connect(wallet.grazType),
263
295
  getQrUri: () => "",
264
296
  type: WalletType.COSMOS
265
297
  }, wallet), {
package/dist/index.js.br CHANGED
Binary file
package/dist/index.js.gz CHANGED
Binary file
@@ -1,8 +1,8 @@
1
1
  import { PropsWithChildren } from 'react';
2
2
  import { ParaCosmosProviderConfig } from './ParaCosmosContext.js';
3
3
  import { WalletWithType } from '../types/Wallet.js';
4
- import ParaWeb from '@getpara/web-sdk';
5
- import type { CommonChain, CommonWallet } from '@getpara/react-common';
4
+ import ParaWeb, { Wallet } from '@getpara/web-sdk';
5
+ import type { CommonChain, CommonWallet, TExternalWallet } from '@getpara/react-common';
6
6
  export type CosmosExternalWalletContextType = {
7
7
  wallets: CommonWallet[];
8
8
  chains: CommonChain[];
@@ -33,9 +33,11 @@ export type CosmosExternalWalletProviderConfig = {
33
33
  error?: string;
34
34
  }) => void;
35
35
  para: ParaWeb;
36
+ walletsWithFullAuth: TExternalWallet[];
37
+ connectedWallet?: Omit<Wallet, 'signer'> | null;
36
38
  };
37
39
  export type CosmosExternalWalletProviderConfigFull = {
38
40
  wallets: WalletWithType[];
39
41
  } & Omit<ParaCosmosProviderConfig, 'wallets'> & CosmosExternalWalletProviderConfig;
40
42
  export declare const CosmosExternalWalletContext: import("react").Context<CosmosExternalWalletContextType>;
41
- export declare function CosmosExternalWalletProvider({ children, onSwitchWallet, selectedChainId, wallets: incompleteWallets, chains, multiChain, shouldUseSuggestChainAndConnect, onSwitchChain, para, }: CosmosExternalWalletProviderConfigFull & PropsWithChildren): import("react/jsx-runtime").JSX.Element;
43
+ export declare function CosmosExternalWalletProvider({ children, onSwitchWallet, selectedChainId, wallets: incompleteWallets, chains, multiChain, shouldUseSuggestChainAndConnect, onSwitchChain, para, walletsWithFullAuth, connectedWallet, }: CosmosExternalWalletProviderConfigFull & PropsWithChildren): import("react/jsx-runtime").JSX.Element;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@getpara/cosmos-wallet-connectors",
3
- "version": "2.0.0-dev.0",
3
+ "version": "2.0.0-dev.1",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -19,14 +19,14 @@
19
19
  "@cosmjs/proto-signing": "<=0.31.3",
20
20
  "@cosmjs/stargate": "<=0.31.3",
21
21
  "@cosmjs/tendermint-rpc": "<=0.31.3",
22
- "@getpara/graz": "^0.1.0",
23
- "@getpara/web-sdk": "^2.0.0-dev.0",
22
+ "@getpara/graz": "^1.0.0-dev.1",
23
+ "@getpara/web-sdk": "^2.0.0-dev.1",
24
24
  "@leapwallet/cosmos-social-login-capsule-provider": "^0.0.41",
25
25
  "zustand": "^4.5.2",
26
26
  "zustand-sync-tabs": "^0.2.2"
27
27
  },
28
28
  "devDependencies": {
29
- "@getpara/react-common": "^2.0.0-dev.0",
29
+ "@getpara/react-common": "^2.0.0-dev.1",
30
30
  "@types/react": "^18.0.31",
31
31
  "@types/react-dom": "^18.2.7",
32
32
  "typescript": "^5.4.3"
@@ -39,5 +39,5 @@
39
39
  "dist",
40
40
  "package.json"
41
41
  ],
42
- "gitHead": "f94ef031ef0e1894f5f0800e55f6ca2904641780"
42
+ "gitHead": "426e843bd6084fb2e5f30ab87b02c79fc2f52832"
43
43
  }