@cometh/connect-react-hooks 0.0.9 → 0.0.10
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/index.cjs +41 -32
- package/dist/index.d.cts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +10 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
@@ -148,6 +148,13 @@ var useAccount = () => {
|
|
148
148
|
throw new Error("useAccount must be used within a ConnectProvider");
|
149
149
|
}
|
150
150
|
const { smartAccountClient, smartAccountAddress } = context;
|
151
|
+
const { chain, chainId } = _react.useMemo.call(void 0,
|
152
|
+
() => ({
|
153
|
+
chain: _optionalChain([smartAccountClient, 'optionalAccess', _2 => _2.chain]),
|
154
|
+
chainId: _optionalChain([smartAccountClient, 'optionalAccess', _3 => _3.chain, 'optionalAccess', _4 => _4.id])
|
155
|
+
}),
|
156
|
+
[smartAccountClient]
|
157
|
+
);
|
151
158
|
const isConnected = _react.useMemo.call(void 0,
|
152
159
|
() => !!smartAccountClient && !!smartAccountAddress,
|
153
160
|
[smartAccountClient, smartAccountAddress]
|
@@ -160,7 +167,9 @@ var useAccount = () => {
|
|
160
167
|
smartAccountClient,
|
161
168
|
isConnected,
|
162
169
|
isDisconnected: !isConnected,
|
163
|
-
status
|
170
|
+
status,
|
171
|
+
chain,
|
172
|
+
chainId
|
164
173
|
};
|
165
174
|
};
|
166
175
|
|
@@ -358,7 +367,7 @@ var FocusManager = (_a = class extends Subscribable {
|
|
358
367
|
if (typeof __privateGet(this, _focused) === "boolean") {
|
359
368
|
return __privateGet(this, _focused);
|
360
369
|
}
|
361
|
-
return _optionalChain([globalThis, 'access',
|
370
|
+
return _optionalChain([globalThis, 'access', _5 => _5.document, 'optionalAccess', _6 => _6.visibilityState]) !== "hidden";
|
362
371
|
}
|
363
372
|
}, _focused = new WeakMap(), _cleanup = new WeakMap(), _setup = new WeakMap(), _a);
|
364
373
|
var focusManager = new FocusManager();
|
@@ -648,7 +657,7 @@ var QueryObserver = (_a3 = class extends Subscribable {
|
|
648
657
|
enumerable: true,
|
649
658
|
get: () => {
|
650
659
|
this.trackProp(key);
|
651
|
-
_optionalChain([onPropTracked, 'optionalCall',
|
660
|
+
_optionalChain([onPropTracked, 'optionalCall', _7 => _7(key)]);
|
652
661
|
return result[key];
|
653
662
|
}
|
654
663
|
});
|
@@ -709,13 +718,13 @@ var QueryObserver = (_a3 = class extends Subscribable {
|
|
709
718
|
}
|
710
719
|
let { error, errorUpdatedAt, status } = newState;
|
711
720
|
if (options.select && newState.data !== void 0) {
|
712
|
-
if (prevResult && newState.data === _optionalChain([prevResultState, 'optionalAccess',
|
721
|
+
if (prevResult && newState.data === _optionalChain([prevResultState, 'optionalAccess', _8 => _8.data]) && options.select === __privateGet(this, _selectFn)) {
|
713
722
|
data = __privateGet(this, _selectResult);
|
714
723
|
} else {
|
715
724
|
try {
|
716
725
|
__privateSet(this, _selectFn, options.select);
|
717
726
|
data = options.select(newState.data);
|
718
|
-
data = replaceData(_optionalChain([prevResult, 'optionalAccess',
|
727
|
+
data = replaceData(_optionalChain([prevResult, 'optionalAccess', _9 => _9.data]), data, options);
|
719
728
|
__privateSet(this, _selectResult, data);
|
720
729
|
__privateSet(this, _selectError, null);
|
721
730
|
} catch (selectError) {
|
@@ -727,11 +736,11 @@ var QueryObserver = (_a3 = class extends Subscribable {
|
|
727
736
|
}
|
728
737
|
if (options.placeholderData !== void 0 && data === void 0 && status === "pending") {
|
729
738
|
let placeholderData;
|
730
|
-
if (_optionalChain([prevResult, 'optionalAccess',
|
739
|
+
if (_optionalChain([prevResult, 'optionalAccess', _10 => _10.isPlaceholderData]) && options.placeholderData === _optionalChain([prevResultOptions, 'optionalAccess', _11 => _11.placeholderData])) {
|
731
740
|
placeholderData = prevResult.data;
|
732
741
|
} else {
|
733
742
|
placeholderData = typeof options.placeholderData === "function" ? options.placeholderData(
|
734
|
-
_optionalChain([__privateGet, 'call',
|
743
|
+
_optionalChain([__privateGet, 'call', _12 => _12(this, _lastQueryWithDefinedData), 'optionalAccess', _13 => _13.state, 'access', _14 => _14.data]),
|
735
744
|
__privateGet(this, _lastQueryWithDefinedData)
|
736
745
|
) : options.placeholderData;
|
737
746
|
if (options.select && placeholderData !== void 0) {
|
@@ -746,7 +755,7 @@ var QueryObserver = (_a3 = class extends Subscribable {
|
|
746
755
|
if (placeholderData !== void 0) {
|
747
756
|
status = "success";
|
748
757
|
data = replaceData(
|
749
|
-
_optionalChain([prevResult, 'optionalAccess',
|
758
|
+
_optionalChain([prevResult, 'optionalAccess', _15 => _15.data]),
|
750
759
|
placeholderData,
|
751
760
|
options
|
752
761
|
);
|
@@ -826,7 +835,7 @@ var QueryObserver = (_a3 = class extends Subscribable {
|
|
826
835
|
return changed && includedProps.has(typedKey);
|
827
836
|
});
|
828
837
|
};
|
829
|
-
if (_optionalChain([notifyOptions, 'optionalAccess',
|
838
|
+
if (_optionalChain([notifyOptions, 'optionalAccess', _16 => _16.listeners]) !== false && shouldNotifyListeners()) {
|
830
839
|
defaultNotifyOptions.listeners = true;
|
831
840
|
}
|
832
841
|
__privateMethod(this, _QueryObserver_instances, notify_fn).call(this, { ...defaultNotifyOptions, ...notifyOptions });
|
@@ -843,7 +852,7 @@ var QueryObserver = (_a3 = class extends Subscribable {
|
|
843
852
|
this.options,
|
844
853
|
fetchOptions
|
845
854
|
);
|
846
|
-
if (!_optionalChain([fetchOptions, 'optionalAccess',
|
855
|
+
if (!_optionalChain([fetchOptions, 'optionalAccess', _17 => _17.throwOnError])) {
|
847
856
|
promise = promise.catch(noop);
|
848
857
|
}
|
849
858
|
return promise;
|
@@ -898,7 +907,7 @@ var QueryObserver = (_a3 = class extends Subscribable {
|
|
898
907
|
__privateSet(this, _currentQuery, query);
|
899
908
|
__privateSet(this, _currentQueryInitialState, query.state);
|
900
909
|
if (this.hasListeners()) {
|
901
|
-
_optionalChain([prevQuery, 'optionalAccess',
|
910
|
+
_optionalChain([prevQuery, 'optionalAccess', _18 => _18.removeObserver, 'call', _19 => _19(this)]);
|
902
911
|
query.addObserver(this);
|
903
912
|
}
|
904
913
|
}, notify_fn = function(notifyOptions) {
|
@@ -969,15 +978,15 @@ var MutationObserver = (_a4 = class extends Subscribable {
|
|
969
978
|
observer: this
|
970
979
|
});
|
971
980
|
}
|
972
|
-
if (_optionalChain([prevOptions, 'optionalAccess',
|
981
|
+
if (_optionalChain([prevOptions, 'optionalAccess', _20 => _20.mutationKey]) && this.options.mutationKey && hashKey(prevOptions.mutationKey) !== hashKey(this.options.mutationKey)) {
|
973
982
|
this.reset();
|
974
|
-
} else if (_optionalChain([__privateGet, 'call',
|
983
|
+
} else if (_optionalChain([__privateGet, 'call', _21 => _21(this, _currentMutation), 'optionalAccess', _22 => _22.state, 'access', _23 => _23.status]) === "pending") {
|
975
984
|
__privateGet(this, _currentMutation).setOptions(this.options);
|
976
985
|
}
|
977
986
|
}
|
978
987
|
onUnsubscribe() {
|
979
988
|
if (!this.hasListeners()) {
|
980
|
-
_optionalChain([__privateGet, 'call',
|
989
|
+
_optionalChain([__privateGet, 'call', _24 => _24(this, _currentMutation), 'optionalAccess', _25 => _25.removeObserver, 'call', _26 => _26(this)]);
|
981
990
|
}
|
982
991
|
}
|
983
992
|
onMutationUpdate(action) {
|
@@ -988,20 +997,20 @@ var MutationObserver = (_a4 = class extends Subscribable {
|
|
988
997
|
return __privateGet(this, _currentResult2);
|
989
998
|
}
|
990
999
|
reset() {
|
991
|
-
_optionalChain([__privateGet, 'call',
|
1000
|
+
_optionalChain([__privateGet, 'call', _27 => _27(this, _currentMutation), 'optionalAccess', _28 => _28.removeObserver, 'call', _29 => _29(this)]);
|
992
1001
|
__privateSet(this, _currentMutation, void 0);
|
993
1002
|
__privateMethod(this, _MutationObserver_instances, updateResult_fn).call(this);
|
994
1003
|
__privateMethod(this, _MutationObserver_instances, notify_fn2).call(this);
|
995
1004
|
}
|
996
1005
|
mutate(variables, options) {
|
997
1006
|
__privateSet(this, _mutateOptions, options);
|
998
|
-
_optionalChain([__privateGet, 'call',
|
1007
|
+
_optionalChain([__privateGet, 'call', _30 => _30(this, _currentMutation), 'optionalAccess', _31 => _31.removeObserver, 'call', _32 => _32(this)]);
|
999
1008
|
__privateSet(this, _currentMutation, __privateGet(this, _client2).getMutationCache().build(__privateGet(this, _client2), this.options));
|
1000
1009
|
__privateGet(this, _currentMutation).addObserver(this);
|
1001
1010
|
return __privateGet(this, _currentMutation).execute(variables);
|
1002
1011
|
}
|
1003
1012
|
}, _client2 = new WeakMap(), _currentResult2 = new WeakMap(), _currentMutation = new WeakMap(), _mutateOptions = new WeakMap(), _MutationObserver_instances = new WeakSet(), updateResult_fn = function() {
|
1004
|
-
const state = _nullishCoalesce(_optionalChain([__privateGet, 'call',
|
1013
|
+
const state = _nullishCoalesce(_optionalChain([__privateGet, 'call', _33 => _33(this, _currentMutation), 'optionalAccess', _34 => _34.state]), () => ( getDefaultState()));
|
1005
1014
|
__privateSet(this, _currentResult2, {
|
1006
1015
|
...state,
|
1007
1016
|
isPending: state.status === "pending",
|
@@ -1016,12 +1025,12 @@ var MutationObserver = (_a4 = class extends Subscribable {
|
|
1016
1025
|
if (__privateGet(this, _mutateOptions) && this.hasListeners()) {
|
1017
1026
|
const variables = __privateGet(this, _currentResult2).variables;
|
1018
1027
|
const context = __privateGet(this, _currentResult2).context;
|
1019
|
-
if (_optionalChain([action, 'optionalAccess',
|
1020
|
-
_optionalChain([__privateGet, 'call',
|
1021
|
-
_optionalChain([__privateGet, 'call',
|
1022
|
-
} else if (_optionalChain([action, 'optionalAccess',
|
1023
|
-
_optionalChain([__privateGet, 'call',
|
1024
|
-
_optionalChain([__privateGet, 'call',
|
1028
|
+
if (_optionalChain([action, 'optionalAccess', _35 => _35.type]) === "success") {
|
1029
|
+
_optionalChain([__privateGet, 'call', _36 => _36(this, _mutateOptions), 'access', _37 => _37.onSuccess, 'optionalCall', _38 => _38(action.data, variables, context)]);
|
1030
|
+
_optionalChain([__privateGet, 'call', _39 => _39(this, _mutateOptions), 'access', _40 => _40.onSettled, 'optionalCall', _41 => _41(action.data, null, variables, context)]);
|
1031
|
+
} else if (_optionalChain([action, 'optionalAccess', _42 => _42.type]) === "error") {
|
1032
|
+
_optionalChain([__privateGet, 'call', _43 => _43(this, _mutateOptions), 'access', _44 => _44.onError, 'optionalCall', _45 => _45(action.error, variables, context)]);
|
1033
|
+
_optionalChain([__privateGet, 'call', _46 => _46(this, _mutateOptions), 'access', _47 => _47.onSettled, 'optionalCall', _48 => _48(
|
1025
1034
|
void 0,
|
1026
1035
|
action.error,
|
1027
1036
|
variables,
|
@@ -1121,7 +1130,7 @@ var ensureStaleTime = (defaultedOptions) => {
|
|
1121
1130
|
}
|
1122
1131
|
}
|
1123
1132
|
};
|
1124
|
-
var shouldSuspend = (defaultedOptions, result) => _optionalChain([defaultedOptions, 'optionalAccess',
|
1133
|
+
var shouldSuspend = (defaultedOptions, result) => _optionalChain([defaultedOptions, 'optionalAccess', _49 => _49.suspense]) && result.isPending;
|
1125
1134
|
var fetchOptimistic = (defaultedOptions, observer, errorResetBoundary) => observer.fetchOptimistic(defaultedOptions).catch(() => {
|
1126
1135
|
errorResetBoundary.clearReset();
|
1127
1136
|
});
|
@@ -1140,7 +1149,7 @@ function useBaseQuery(options, Observer, queryClient) {
|
|
1140
1149
|
const isRestoring = useIsRestoring();
|
1141
1150
|
const errorResetBoundary = useQueryErrorResetBoundary();
|
1142
1151
|
const defaultedOptions = client.defaultQueryOptions(options);
|
1143
|
-
_optionalChain([client, 'access',
|
1152
|
+
_optionalChain([client, 'access', _50 => _50.getDefaultOptions, 'call', _51 => _51(), 'access', _52 => _52.queries, 'optionalAccess', _53 => _53._experimental_beforeQuery, 'optionalCall', _54 => _54(
|
1144
1153
|
defaultedOptions
|
1145
1154
|
)]);
|
1146
1155
|
defaultedOptions._optimisticResults = isRestoring ? "isRestoring" : "optimistic";
|
@@ -1181,7 +1190,7 @@ function useBaseQuery(options, Observer, queryClient) {
|
|
1181
1190
|
throw result.error;
|
1182
1191
|
}
|
1183
1192
|
;
|
1184
|
-
_optionalChain([client, 'access',
|
1193
|
+
_optionalChain([client, 'access', _55 => _55.getDefaultOptions, 'call', _56 => _56(), 'access', _57 => _57.queries, 'optionalAccess', _58 => _58._experimental_afterQuery, 'optionalCall', _59 => _59(
|
1185
1194
|
defaultedOptions,
|
1186
1195
|
result
|
1187
1196
|
)]);
|
@@ -1385,7 +1394,7 @@ var useConnect = () => {
|
|
1385
1394
|
setIsPending(true);
|
1386
1395
|
setError(null);
|
1387
1396
|
updateSmartAccountClient(params).then(() => {
|
1388
|
-
_optionalChain([queryClient, 'optionalAccess',
|
1397
|
+
_optionalChain([queryClient, 'optionalAccess', _60 => _60.invalidateQueries, 'call', _61 => _61({
|
1389
1398
|
queryKey: ["connect"]
|
1390
1399
|
})]);
|
1391
1400
|
}).catch((e) => {
|
@@ -1403,7 +1412,7 @@ var useConnect = () => {
|
|
1403
1412
|
setError(null);
|
1404
1413
|
try {
|
1405
1414
|
await updateSmartAccountClient(params);
|
1406
|
-
_optionalChain([queryClient, 'optionalAccess',
|
1415
|
+
_optionalChain([queryClient, 'optionalAccess', _62 => _62.invalidateQueries, 'call', _63 => _63({ queryKey: ["connect"] })]);
|
1407
1416
|
} catch (e) {
|
1408
1417
|
const err = e instanceof Error ? e : new Error("An error occurred");
|
1409
1418
|
setError(err);
|
@@ -1436,7 +1445,7 @@ var useDisconnect = () => {
|
|
1436
1445
|
setIsPending(true);
|
1437
1446
|
setError(null);
|
1438
1447
|
disconnectSmartAccount().then(() => {
|
1439
|
-
_optionalChain([queryClient, 'optionalAccess',
|
1448
|
+
_optionalChain([queryClient, 'optionalAccess', _64 => _64.invalidateQueries, 'call', _65 => _65({
|
1440
1449
|
queryKey: ["connect"]
|
1441
1450
|
})]);
|
1442
1451
|
}).catch((e) => {
|
@@ -1451,7 +1460,7 @@ var useDisconnect = () => {
|
|
1451
1460
|
setError(null);
|
1452
1461
|
try {
|
1453
1462
|
await disconnectSmartAccount();
|
1454
|
-
_optionalChain([queryClient, 'optionalAccess',
|
1463
|
+
_optionalChain([queryClient, 'optionalAccess', _66 => _66.invalidateQueries, 'call', _67 => _67({ queryKey: ["connect"] })]);
|
1455
1464
|
} catch (e) {
|
1456
1465
|
const err = e instanceof Error ? e : new Error("An error occurred during disconnection");
|
1457
1466
|
setError(err);
|
@@ -1888,7 +1897,7 @@ var useCreateNewSigner = (apiKey, baseUrl) => {
|
|
1888
1897
|
setIsPending(true);
|
1889
1898
|
setError(null);
|
1890
1899
|
_connectsdk4337.createNewSigner.call(void 0, { apiKey, baseUrl, params }).then((signer) => {
|
1891
|
-
_optionalChain([queryClient, 'optionalAccess',
|
1900
|
+
_optionalChain([queryClient, 'optionalAccess', _68 => _68.invalidateQueries, 'call', _69 => _69({ queryKey: ["signer"] })]);
|
1892
1901
|
return signer;
|
1893
1902
|
}).catch((e) => {
|
1894
1903
|
const err = e instanceof Error ? e : new Error("An error occurred");
|
@@ -1909,7 +1918,7 @@ var useCreateNewSigner = (apiKey, baseUrl) => {
|
|
1909
1918
|
baseUrl,
|
1910
1919
|
params
|
1911
1920
|
});
|
1912
|
-
_optionalChain([queryClient, 'optionalAccess',
|
1921
|
+
_optionalChain([queryClient, 'optionalAccess', _70 => _70.invalidateQueries, 'call', _71 => _71({ queryKey: ["signer"] })]);
|
1913
1922
|
return signer;
|
1914
1923
|
} catch (e) {
|
1915
1924
|
const err = e instanceof Error ? e : new Error("An error occurred");
|
package/dist/index.d.cts
CHANGED
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
@@ -148,6 +148,13 @@ var useAccount = () => {
|
|
148
148
|
throw new Error("useAccount must be used within a ConnectProvider");
|
149
149
|
}
|
150
150
|
const { smartAccountClient, smartAccountAddress } = context;
|
151
|
+
const { chain, chainId } = useMemo2(
|
152
|
+
() => ({
|
153
|
+
chain: smartAccountClient?.chain,
|
154
|
+
chainId: smartAccountClient?.chain?.id
|
155
|
+
}),
|
156
|
+
[smartAccountClient]
|
157
|
+
);
|
151
158
|
const isConnected = useMemo2(
|
152
159
|
() => !!smartAccountClient && !!smartAccountAddress,
|
153
160
|
[smartAccountClient, smartAccountAddress]
|
@@ -160,7 +167,9 @@ var useAccount = () => {
|
|
160
167
|
smartAccountClient,
|
161
168
|
isConnected,
|
162
169
|
isDisconnected: !isConnected,
|
163
|
-
status
|
170
|
+
status,
|
171
|
+
chain,
|
172
|
+
chainId
|
164
173
|
};
|
165
174
|
};
|
166
175
|
|
package/package.json
CHANGED
@@ -7,7 +7,7 @@
|
|
7
7
|
"url": "https://twitter.com/slovaye"
|
8
8
|
}
|
9
9
|
],
|
10
|
-
"version": "0.0.
|
10
|
+
"version": "0.0.10",
|
11
11
|
"description": "React hooks Connect 4337",
|
12
12
|
"repository": "https://github.com/cometh-hq/connect-sdk-4337.git",
|
13
13
|
"keywords": [
|
@@ -58,7 +58,7 @@
|
|
58
58
|
"typescript": "^5"
|
59
59
|
},
|
60
60
|
"dependencies": {
|
61
|
-
"@cometh/connect-sdk-4337": "^0.1.
|
61
|
+
"@cometh/connect-sdk-4337": "^0.1.11",
|
62
62
|
"permissionless": "0.1.31"
|
63
63
|
}
|
64
64
|
}
|