@getpara/cosmos-wallet-connectors 1.4.4 → 1.5.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
@@ -1,4 +1,55 @@
1
1
  "use client";
2
+ var __defProp = Object.defineProperty;
3
+ var __defProps = Object.defineProperties;
4
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
5
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
8
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
9
+ var __spreadValues = (a, b) => {
10
+ for (var prop in b || (b = {}))
11
+ if (__hasOwnProp.call(b, prop))
12
+ __defNormalProp(a, prop, b[prop]);
13
+ if (__getOwnPropSymbols)
14
+ for (var prop of __getOwnPropSymbols(b)) {
15
+ if (__propIsEnum.call(b, prop))
16
+ __defNormalProp(a, prop, b[prop]);
17
+ }
18
+ return a;
19
+ };
20
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
21
+ var __objRest = (source, exclude) => {
22
+ var target = {};
23
+ for (var prop in source)
24
+ if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
25
+ target[prop] = source[prop];
26
+ if (source != null && __getOwnPropSymbols)
27
+ for (var prop of __getOwnPropSymbols(source)) {
28
+ if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
29
+ target[prop] = source[prop];
30
+ }
31
+ return target;
32
+ };
33
+ var __async = (__this, __arguments, generator) => {
34
+ return new Promise((resolve, reject) => {
35
+ var fulfilled = (value) => {
36
+ try {
37
+ step(generator.next(value));
38
+ } catch (e) {
39
+ reject(e);
40
+ }
41
+ };
42
+ var rejected = (value) => {
43
+ try {
44
+ step(generator.throw(value));
45
+ } catch (e) {
46
+ reject(e);
47
+ }
48
+ };
49
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
50
+ step((generator = generator.apply(__this, __arguments)).next());
51
+ });
52
+ };
2
53
 
3
54
  // src/providers/CosmosExternalWalletContext.tsx
4
55
  import { createContext as createContext2, useEffect as useEffect2, useMemo as useMemo2 } from "react";
@@ -10,33 +61,42 @@ import { GrazProvider, WalletType, connect } from "@getpara/graz";
10
61
  import { jsx } from "react/jsx-runtime";
11
62
  var ParaCosmosContext = createContext({ wallets: [], chains: [], onSwitchChain: () => {
12
63
  } });
13
- function ParaCosmosProvider({
14
- children,
15
- wallets,
16
- chains,
17
- selectedChainId,
18
- multiChain,
19
- shouldUseSuggestChainAndConnect,
20
- onSwitchChain,
21
- ...grazOpts
22
- }) {
64
+ function ParaCosmosProvider(_a) {
65
+ var _b = _a, {
66
+ children,
67
+ wallets,
68
+ chains,
69
+ selectedChainId,
70
+ multiChain,
71
+ shouldUseSuggestChainAndConnect,
72
+ onSwitchChain
73
+ } = _b, grazOpts = __objRest(_b, [
74
+ "children",
75
+ "wallets",
76
+ "chains",
77
+ "selectedChainId",
78
+ "multiChain",
79
+ "shouldUseSuggestChainAndConnect",
80
+ "onSwitchChain"
81
+ ]);
82
+ var _a2;
23
83
  const updateExternalWalletProviderState = useExternalWalletProviderStore((state) => state.updateState);
24
84
  const CosmosProvider = useExternalWalletProviderStore((state) => state.CosmosProvider);
25
85
  const cosmosContext = useExternalWalletProviderStore((state) => state.cosmosContext);
26
- const para = grazOpts.para ?? useClient();
27
- const connectParaCosmosWallet = useCallback(async () => {
86
+ const para = (_a2 = grazOpts.para) != null ? _a2 : useClient();
87
+ const connectParaCosmosWallet = useCallback(() => __async(this, null, function* () {
28
88
  if (!para) {
29
89
  return { error: "No para instance available" };
30
90
  }
31
91
  try {
32
92
  const chainId = multiChain ? chains.map((c) => c.chainId) : selectedChainId;
33
- const result = await connect({ walletType: WalletType.PARA, chainId });
93
+ const result = yield connect({ walletType: WalletType.PARA, chainId });
34
94
  return { result };
35
95
  } catch (err) {
36
96
  const error = err instanceof Error ? err.message : "Unknown error";
37
97
  return { error };
38
98
  }
39
- }, [para, connect]);
99
+ }), [para, connect]);
40
100
  useEffect(() => {
41
101
  if (!cosmosContext || !CosmosProvider) {
42
102
  updateExternalWalletProviderState({
@@ -69,7 +129,7 @@ function ParaCosmosProvider({
69
129
  if (!cosmosContext || !CosmosProvider) {
70
130
  return null;
71
131
  }
72
- return /* @__PURE__ */ jsx(GrazProvider, { grazOptions: { chains, autoReconnect: true, ...grazOpts, para }, children: /* @__PURE__ */ jsx(ParaCosmosContext.Provider, { value, children }) });
132
+ return /* @__PURE__ */ jsx(GrazProvider, { grazOptions: __spreadProps(__spreadValues({ chains, autoReconnect: true }, grazOpts), { para }), children: /* @__PURE__ */ jsx(ParaCosmosContext.Provider, { value, children }) });
73
133
  }
74
134
  var useParaCosmos = () => useContext(ParaCosmosContext);
75
135
 
@@ -95,7 +155,7 @@ var useExternalWalletStore = create(
95
155
  (set) => ({
96
156
  isConnecting: false,
97
157
  updateState: (state) => {
98
- set({ ...state });
158
+ set(__spreadValues({}, state));
99
159
  }
100
160
  }),
101
161
  {
@@ -115,6 +175,7 @@ var defaultCosmosExternalWallet = {
115
175
  };
116
176
  var CosmosExternalWalletContext = createContext2(defaultCosmosExternalWallet);
117
177
  function CosmosExternalWalletProvider({ children, para, onSwitchWallet }) {
178
+ var _a, _b;
118
179
  const {
119
180
  selectedChainId,
120
181
  wallets: incompleteWallets,
@@ -138,45 +199,45 @@ function CosmosExternalWalletProvider({ children, para, onSwitchWallet }) {
138
199
  const { walletType } = useActiveWalletType();
139
200
  const isLocalConnecting = useExternalWalletStore((state) => state.isConnecting);
140
201
  const updateExternalWalletState = useExternalWalletStore((state) => state.updateState);
141
- const bufferAddress = multiChain ? account?.[selectedChainId]?.address.toString() : account?.address.toString();
142
- const address = multiChain ? account?.[selectedChainId]?.bech32Address : account?.bech32Address;
143
- const reset = async () => {
144
- await disconnectAsync();
145
- await para.logout();
146
- };
147
- const switchChain = async (chainId) => {
202
+ const bufferAddress = multiChain ? (_a = account == null ? void 0 : account[selectedChainId]) == null ? void 0 : _a.address.toString() : account == null ? void 0 : account.address.toString();
203
+ const address = multiChain ? (_b = account == null ? void 0 : account[selectedChainId]) == null ? void 0 : _b.bech32Address : account == null ? void 0 : account.bech32Address;
204
+ const reset = () => __async(this, null, function* () {
205
+ yield disconnectAsync();
206
+ yield para.logout();
207
+ });
208
+ const switchChain = (chainId) => __async(this, null, function* () {
148
209
  let error;
149
210
  const hasActiveChain = activeChainIds.includes(chainId);
150
211
  if (!hasActiveChain) {
151
212
  updateExternalWalletState({ isConnecting: true });
152
213
  let changeResp;
153
- changeResp = await connect2(walletType, chainId);
214
+ changeResp = yield connect2(walletType, chainId);
154
215
  onSwitchWallet(changeResp);
155
216
  updateExternalWalletState({ isConnecting: false });
156
217
  if (changeResp.error) {
157
- error = [changeResp?.error];
218
+ error = [changeResp == null ? void 0 : changeResp.error];
158
219
  }
159
220
  }
160
221
  if (!error) {
161
222
  onSwitchChain(chainId);
162
223
  }
163
224
  return { error };
164
- };
165
- const login = async (bufferAddress2, address2, providerName) => {
225
+ });
226
+ const login = (bufferAddress2, address2, providerName) => __async(this, null, function* () {
166
227
  try {
167
- await para.externalWalletLogin({
228
+ yield para.externalWalletLogin({
168
229
  address: bufferAddress2,
169
230
  type: WalletType2.COSMOS,
170
231
  provider: providerName,
171
232
  addressBech32: address2
172
233
  });
173
234
  } catch (err) {
174
- await reset();
235
+ yield reset();
175
236
  throw "Error logging you in. Please try again.";
176
237
  }
177
- };
238
+ });
178
239
  useEffect2(() => {
179
- const storedExternalWallet = para.externalWallets[bufferAddress ?? ""];
240
+ const storedExternalWallet = para.externalWallets[bufferAddress != null ? bufferAddress : ""];
180
241
  if (!isConnecting && !isReconnecting && !isLocalConnecting && address && storedExternalWallet && storedExternalWallet.address !== address && walletType !== GrazWalletType.PARA) {
181
242
  para.setExternalWallet({
182
243
  address: bufferAddress,
@@ -187,17 +248,17 @@ function CosmosExternalWalletProvider({ children, para, onSwitchWallet }) {
187
248
  }
188
249
  }, [isConnecting, isReconnecting, address]);
189
250
  useEffect2(() => {
190
- const storedExternalWallet = para.externalWallets[bufferAddress ?? ""];
251
+ const storedExternalWallet = para.externalWallets[bufferAddress != null ? bufferAddress : ""];
191
252
  if (!isConnecting && !isReconnecting && !isLocalConnecting && !!bufferAddress && !storedExternalWallet && walletType !== GrazWalletType.PARA) {
192
253
  reset();
193
254
  }
194
255
  }, [isConnecting, isReconnecting]);
195
- const connect2 = async (walletType2, chainId) => {
256
+ const connect2 = (walletType2, chainId) => __async(this, null, function* () {
196
257
  updateExternalWalletState({ isConnecting: true });
197
258
  if (!chainId) {
198
- await disconnectAsync();
259
+ yield disconnectAsync();
199
260
  }
200
- const _chainId = chainId ?? (multiChain ? chains.map((c) => c.chainId) : selectedChainId);
261
+ const _chainId = chainId != null ? chainId : multiChain ? chains.map((c) => c.chainId) : selectedChainId;
201
262
  if (!_chainId) {
202
263
  console.error("Chain id not provided.");
203
264
  return;
@@ -222,13 +283,13 @@ function CosmosExternalWalletProvider({ children, para, onSwitchWallet }) {
222
283
  return;
223
284
  }
224
285
  }
225
- const connectedWallet = await (shouldUseSuggestChainAndConnect ? suggestAndConnectAsync({ walletType: walletType2, chainInfo }) : connectAsync({ walletType: walletType2, chainId: _chainId }));
286
+ const connectedWallet = yield shouldUseSuggestChainAndConnect ? suggestAndConnectAsync({ walletType: walletType2, chainInfo }) : connectAsync({ walletType: walletType2, chainId: _chainId });
226
287
  const firstChain = typeof _chainId === "string" ? _chainId : _chainId[0];
227
288
  address2 = connectedWallet.accounts[firstChain].bech32Address;
228
289
  bufferAddress2 = connectedWallet.accounts[firstChain].address.toString();
229
290
  if (connectedWallet.accounts[firstChain]) {
230
291
  try {
231
- await login(bufferAddress2, address2, getProviderName(walletType2));
292
+ yield login(bufferAddress2, address2, getProviderName(walletType2));
232
293
  } catch (err) {
233
294
  bufferAddress2 = void 0;
234
295
  address2 = void 0;
@@ -246,17 +307,20 @@ function CosmosExternalWalletProvider({ children, para, onSwitchWallet }) {
246
307
  }
247
308
  updateExternalWalletState({ isConnecting: false });
248
309
  return { address: address2, bufferAddress: bufferAddress2, error };
310
+ });
311
+ const getProviderName = (walletType2) => {
312
+ var _a2;
313
+ return (_a2 = incompleteWallets.find((w) => w.grazType === walletType2 || w.grazMobileType === walletType2)) == null ? void 0 : _a2.name;
249
314
  };
250
- const getProviderName = (walletType2) => incompleteWallets.find((w) => w.grazType === walletType2 || w.grazMobileType === walletType2)?.name;
251
315
  const wallets = incompleteWallets.map((wallet) => {
252
- return {
316
+ return __spreadProps(__spreadValues({
253
317
  connect: () => connect2(wallet.grazType),
254
318
  connectMobile: () => connect2(wallet.grazMobileType),
255
319
  getQrUri: () => "",
256
- type: WalletType2.COSMOS,
257
- ...wallet,
320
+ type: WalletType2.COSMOS
321
+ }, wallet), {
258
322
  installed: checkWallet(wallet.grazType)
259
- };
323
+ });
260
324
  }).filter((w) => !!w);
261
325
  const formattedChains = chains.map((c) => {
262
326
  return {
package/dist/index.js.br CHANGED
Binary file
package/dist/index.js.gz CHANGED
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@getpara/cosmos-wallet-connectors",
3
- "version": "1.4.4",
3
+ "version": "1.5.1",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -9,7 +9,7 @@
9
9
  "./connectors": "./dist/wallets/connectors/index.js"
10
10
  },
11
11
  "dependencies": {
12
- "@getpara/react-sdk": "1.4.4",
12
+ "@getpara/react-sdk": "1.5.1",
13
13
  "zustand": "^4.5.2",
14
14
  "zustand-sync-tabs": "^0.2.2"
15
15
  },
@@ -39,5 +39,5 @@
39
39
  "dist",
40
40
  "package.json"
41
41
  ],
42
- "gitHead": "9a4086c4b352fff2143d3b931d288c5ebaf127fb"
42
+ "gitHead": "f77e0f5e162a1672219b01dbf7c06a3baadd2f35"
43
43
  }