@satoshai/kit 0.6.0 → 0.7.0
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/README.md +23 -0
- package/dist/index.cjs +109 -19
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +61 -6
- package/dist/index.d.ts +61 -6
- package/dist/index.js +105 -20
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -3,6 +3,61 @@ import { ClarityValue, TupleCV, PostCondition, PostConditionMode } from '@stacks
|
|
|
3
3
|
import { ClarityAbi, ExtractAbiFunctionNames, Pretty, ExtractAbiFunction, ClarityAbiArgToPrimitiveTypeValue } from 'clarity-abitype';
|
|
4
4
|
export { ClarityAbi } from 'clarity-abitype';
|
|
5
5
|
|
|
6
|
+
type BaseErrorType = BaseError & {
|
|
7
|
+
name: 'StacksKitError';
|
|
8
|
+
};
|
|
9
|
+
declare class BaseError extends Error {
|
|
10
|
+
name: string;
|
|
11
|
+
shortMessage: string;
|
|
12
|
+
constructor(shortMessage: string, options?: {
|
|
13
|
+
cause?: Error;
|
|
14
|
+
details?: string;
|
|
15
|
+
});
|
|
16
|
+
walk(fn?: (err: unknown) => boolean): unknown;
|
|
17
|
+
}
|
|
18
|
+
type WalletNotConnectedErrorType = WalletNotConnectedError & {
|
|
19
|
+
name: 'WalletNotConnectedError';
|
|
20
|
+
};
|
|
21
|
+
declare class WalletNotConnectedError extends BaseError {
|
|
22
|
+
name: string;
|
|
23
|
+
constructor();
|
|
24
|
+
}
|
|
25
|
+
type WalletNotFoundErrorType = WalletNotFoundError & {
|
|
26
|
+
name: 'WalletNotFoundError';
|
|
27
|
+
};
|
|
28
|
+
declare class WalletNotFoundError extends BaseError {
|
|
29
|
+
name: string;
|
|
30
|
+
wallet: string;
|
|
31
|
+
constructor({ wallet }: {
|
|
32
|
+
wallet: string;
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
type UnsupportedMethodErrorType = UnsupportedMethodError & {
|
|
36
|
+
name: 'UnsupportedMethodError';
|
|
37
|
+
};
|
|
38
|
+
declare class UnsupportedMethodError extends BaseError {
|
|
39
|
+
name: string;
|
|
40
|
+
method: string;
|
|
41
|
+
wallet: string;
|
|
42
|
+
constructor({ method, wallet }: {
|
|
43
|
+
method: string;
|
|
44
|
+
wallet: string;
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
type WalletRequestErrorType = WalletRequestError & {
|
|
48
|
+
name: 'WalletRequestError';
|
|
49
|
+
};
|
|
50
|
+
declare class WalletRequestError extends BaseError {
|
|
51
|
+
name: string;
|
|
52
|
+
method: string;
|
|
53
|
+
wallet: string;
|
|
54
|
+
constructor({ method, wallet, cause }: {
|
|
55
|
+
method: string;
|
|
56
|
+
wallet: string;
|
|
57
|
+
cause: Error;
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
|
|
6
61
|
declare const SUPPORTED_STACKS_WALLETS: readonly ["xverse", "leather", "asigna", "fordefi", "wallet-connect", "okx"];
|
|
7
62
|
type SupportedStacksWallet = (typeof SUPPORTED_STACKS_WALLETS)[number];
|
|
8
63
|
|
|
@@ -116,7 +171,7 @@ declare const useSignMessage: () => {
|
|
|
116
171
|
signMessageAsync: (variables: SignMessageVariables) => Promise<SignMessageData>;
|
|
117
172
|
reset: () => void;
|
|
118
173
|
data: SignMessageData | undefined;
|
|
119
|
-
error:
|
|
174
|
+
error: BaseError | null;
|
|
120
175
|
isError: boolean;
|
|
121
176
|
isIdle: boolean;
|
|
122
177
|
isPending: boolean;
|
|
@@ -142,7 +197,7 @@ declare const useSignStructuredMessage: () => {
|
|
|
142
197
|
signStructuredMessageAsync: (variables: SignStructuredMessageVariables) => Promise<SignStructuredMessageData>;
|
|
143
198
|
reset: () => void;
|
|
144
199
|
data: SignStructuredMessageData | undefined;
|
|
145
|
-
error:
|
|
200
|
+
error: BaseError | null;
|
|
146
201
|
isError: boolean;
|
|
147
202
|
isIdle: boolean;
|
|
148
203
|
isPending: boolean;
|
|
@@ -168,7 +223,7 @@ declare const useSignTransaction: () => {
|
|
|
168
223
|
signTransactionAsync: (variables: SignTransactionVariables) => Promise<SignTransactionData>;
|
|
169
224
|
reset: () => void;
|
|
170
225
|
data: SignTransactionData | undefined;
|
|
171
|
-
error:
|
|
226
|
+
error: BaseError | null;
|
|
172
227
|
isError: boolean;
|
|
173
228
|
isIdle: boolean;
|
|
174
229
|
isPending: boolean;
|
|
@@ -193,7 +248,7 @@ declare const useTransferSTX: () => {
|
|
|
193
248
|
transferSTXAsync: (variables: TransferSTXVariables) => Promise<string>;
|
|
194
249
|
reset: () => void;
|
|
195
250
|
data: string | undefined;
|
|
196
|
-
error:
|
|
251
|
+
error: BaseError | null;
|
|
197
252
|
isError: boolean;
|
|
198
253
|
isIdle: boolean;
|
|
199
254
|
isPending: boolean;
|
|
@@ -254,7 +309,7 @@ declare const useWriteContract: () => {
|
|
|
254
309
|
writeContractAsync: WriteContractAsyncFn;
|
|
255
310
|
reset: () => void;
|
|
256
311
|
data: string | undefined;
|
|
257
|
-
error:
|
|
312
|
+
error: BaseError | null;
|
|
258
313
|
isError: boolean;
|
|
259
314
|
isIdle: boolean;
|
|
260
315
|
isPending: boolean;
|
|
@@ -295,4 +350,4 @@ declare function createContractConfig<const TAbi extends ClarityAbi>(config: {
|
|
|
295
350
|
contract: string;
|
|
296
351
|
};
|
|
297
352
|
|
|
298
|
-
export { type ConnectOptions, type MutationStatus, type PostConditionConfig, type PublicFunctionArgs, type PublicFunctionName, SUPPORTED_STACKS_WALLETS, type SignMessageData, type SignMessageOptions, type SignMessageVariables, type SignStructuredMessageData, type SignStructuredMessageOptions, type SignStructuredMessageVariables, type SignTransactionData, type SignTransactionOptions, type SignTransactionVariables, type StacksChain, StacksWalletProvider, type StacksWallets, type SupportedStacksWallet, type TraitReference, type TransferSTXOptions, type TransferSTXVariables, type TypedWriteContractVariables, type UntypedWriteContractVariables, type WalletConnectMetadata, type WalletContextValue, type WalletInfo, type WalletState, type WriteContractOptions, type WriteContractVariables, createContractConfig, getLocalStorageWallet, getNetworkFromAddress, getStacksWallets, useAddress, useBnsName, useConnect, useDisconnect, useSignMessage, useSignStructuredMessage, useSignTransaction, useTransferSTX, useWallets, useWriteContract };
|
|
353
|
+
export { BaseError, type BaseErrorType, type ConnectOptions, type MutationStatus, type PostConditionConfig, type PublicFunctionArgs, type PublicFunctionName, SUPPORTED_STACKS_WALLETS, type SignMessageData, type SignMessageOptions, type SignMessageVariables, type SignStructuredMessageData, type SignStructuredMessageOptions, type SignStructuredMessageVariables, type SignTransactionData, type SignTransactionOptions, type SignTransactionVariables, type StacksChain, StacksWalletProvider, type StacksWallets, type SupportedStacksWallet, type TraitReference, type TransferSTXOptions, type TransferSTXVariables, type TypedWriteContractVariables, UnsupportedMethodError, type UnsupportedMethodErrorType, type UntypedWriteContractVariables, type WalletConnectMetadata, type WalletContextValue, type WalletInfo, WalletNotConnectedError, type WalletNotConnectedErrorType, WalletNotFoundError, type WalletNotFoundErrorType, WalletRequestError, type WalletRequestErrorType, type WalletState, type WriteContractOptions, type WriteContractVariables, createContractConfig, getLocalStorageWallet, getNetworkFromAddress, getStacksWallets, useAddress, useBnsName, useConnect, useDisconnect, useSignMessage, useSignStructuredMessage, useSignTransaction, useTransferSTX, useWallets, useWriteContract };
|
package/dist/index.d.ts
CHANGED
|
@@ -3,6 +3,61 @@ import { ClarityValue, TupleCV, PostCondition, PostConditionMode } from '@stacks
|
|
|
3
3
|
import { ClarityAbi, ExtractAbiFunctionNames, Pretty, ExtractAbiFunction, ClarityAbiArgToPrimitiveTypeValue } from 'clarity-abitype';
|
|
4
4
|
export { ClarityAbi } from 'clarity-abitype';
|
|
5
5
|
|
|
6
|
+
type BaseErrorType = BaseError & {
|
|
7
|
+
name: 'StacksKitError';
|
|
8
|
+
};
|
|
9
|
+
declare class BaseError extends Error {
|
|
10
|
+
name: string;
|
|
11
|
+
shortMessage: string;
|
|
12
|
+
constructor(shortMessage: string, options?: {
|
|
13
|
+
cause?: Error;
|
|
14
|
+
details?: string;
|
|
15
|
+
});
|
|
16
|
+
walk(fn?: (err: unknown) => boolean): unknown;
|
|
17
|
+
}
|
|
18
|
+
type WalletNotConnectedErrorType = WalletNotConnectedError & {
|
|
19
|
+
name: 'WalletNotConnectedError';
|
|
20
|
+
};
|
|
21
|
+
declare class WalletNotConnectedError extends BaseError {
|
|
22
|
+
name: string;
|
|
23
|
+
constructor();
|
|
24
|
+
}
|
|
25
|
+
type WalletNotFoundErrorType = WalletNotFoundError & {
|
|
26
|
+
name: 'WalletNotFoundError';
|
|
27
|
+
};
|
|
28
|
+
declare class WalletNotFoundError extends BaseError {
|
|
29
|
+
name: string;
|
|
30
|
+
wallet: string;
|
|
31
|
+
constructor({ wallet }: {
|
|
32
|
+
wallet: string;
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
type UnsupportedMethodErrorType = UnsupportedMethodError & {
|
|
36
|
+
name: 'UnsupportedMethodError';
|
|
37
|
+
};
|
|
38
|
+
declare class UnsupportedMethodError extends BaseError {
|
|
39
|
+
name: string;
|
|
40
|
+
method: string;
|
|
41
|
+
wallet: string;
|
|
42
|
+
constructor({ method, wallet }: {
|
|
43
|
+
method: string;
|
|
44
|
+
wallet: string;
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
type WalletRequestErrorType = WalletRequestError & {
|
|
48
|
+
name: 'WalletRequestError';
|
|
49
|
+
};
|
|
50
|
+
declare class WalletRequestError extends BaseError {
|
|
51
|
+
name: string;
|
|
52
|
+
method: string;
|
|
53
|
+
wallet: string;
|
|
54
|
+
constructor({ method, wallet, cause }: {
|
|
55
|
+
method: string;
|
|
56
|
+
wallet: string;
|
|
57
|
+
cause: Error;
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
|
|
6
61
|
declare const SUPPORTED_STACKS_WALLETS: readonly ["xverse", "leather", "asigna", "fordefi", "wallet-connect", "okx"];
|
|
7
62
|
type SupportedStacksWallet = (typeof SUPPORTED_STACKS_WALLETS)[number];
|
|
8
63
|
|
|
@@ -116,7 +171,7 @@ declare const useSignMessage: () => {
|
|
|
116
171
|
signMessageAsync: (variables: SignMessageVariables) => Promise<SignMessageData>;
|
|
117
172
|
reset: () => void;
|
|
118
173
|
data: SignMessageData | undefined;
|
|
119
|
-
error:
|
|
174
|
+
error: BaseError | null;
|
|
120
175
|
isError: boolean;
|
|
121
176
|
isIdle: boolean;
|
|
122
177
|
isPending: boolean;
|
|
@@ -142,7 +197,7 @@ declare const useSignStructuredMessage: () => {
|
|
|
142
197
|
signStructuredMessageAsync: (variables: SignStructuredMessageVariables) => Promise<SignStructuredMessageData>;
|
|
143
198
|
reset: () => void;
|
|
144
199
|
data: SignStructuredMessageData | undefined;
|
|
145
|
-
error:
|
|
200
|
+
error: BaseError | null;
|
|
146
201
|
isError: boolean;
|
|
147
202
|
isIdle: boolean;
|
|
148
203
|
isPending: boolean;
|
|
@@ -168,7 +223,7 @@ declare const useSignTransaction: () => {
|
|
|
168
223
|
signTransactionAsync: (variables: SignTransactionVariables) => Promise<SignTransactionData>;
|
|
169
224
|
reset: () => void;
|
|
170
225
|
data: SignTransactionData | undefined;
|
|
171
|
-
error:
|
|
226
|
+
error: BaseError | null;
|
|
172
227
|
isError: boolean;
|
|
173
228
|
isIdle: boolean;
|
|
174
229
|
isPending: boolean;
|
|
@@ -193,7 +248,7 @@ declare const useTransferSTX: () => {
|
|
|
193
248
|
transferSTXAsync: (variables: TransferSTXVariables) => Promise<string>;
|
|
194
249
|
reset: () => void;
|
|
195
250
|
data: string | undefined;
|
|
196
|
-
error:
|
|
251
|
+
error: BaseError | null;
|
|
197
252
|
isError: boolean;
|
|
198
253
|
isIdle: boolean;
|
|
199
254
|
isPending: boolean;
|
|
@@ -254,7 +309,7 @@ declare const useWriteContract: () => {
|
|
|
254
309
|
writeContractAsync: WriteContractAsyncFn;
|
|
255
310
|
reset: () => void;
|
|
256
311
|
data: string | undefined;
|
|
257
|
-
error:
|
|
312
|
+
error: BaseError | null;
|
|
258
313
|
isError: boolean;
|
|
259
314
|
isIdle: boolean;
|
|
260
315
|
isPending: boolean;
|
|
@@ -295,4 +350,4 @@ declare function createContractConfig<const TAbi extends ClarityAbi>(config: {
|
|
|
295
350
|
contract: string;
|
|
296
351
|
};
|
|
297
352
|
|
|
298
|
-
export { type ConnectOptions, type MutationStatus, type PostConditionConfig, type PublicFunctionArgs, type PublicFunctionName, SUPPORTED_STACKS_WALLETS, type SignMessageData, type SignMessageOptions, type SignMessageVariables, type SignStructuredMessageData, type SignStructuredMessageOptions, type SignStructuredMessageVariables, type SignTransactionData, type SignTransactionOptions, type SignTransactionVariables, type StacksChain, StacksWalletProvider, type StacksWallets, type SupportedStacksWallet, type TraitReference, type TransferSTXOptions, type TransferSTXVariables, type TypedWriteContractVariables, type UntypedWriteContractVariables, type WalletConnectMetadata, type WalletContextValue, type WalletInfo, type WalletState, type WriteContractOptions, type WriteContractVariables, createContractConfig, getLocalStorageWallet, getNetworkFromAddress, getStacksWallets, useAddress, useBnsName, useConnect, useDisconnect, useSignMessage, useSignStructuredMessage, useSignTransaction, useTransferSTX, useWallets, useWriteContract };
|
|
353
|
+
export { BaseError, type BaseErrorType, type ConnectOptions, type MutationStatus, type PostConditionConfig, type PublicFunctionArgs, type PublicFunctionName, SUPPORTED_STACKS_WALLETS, type SignMessageData, type SignMessageOptions, type SignMessageVariables, type SignStructuredMessageData, type SignStructuredMessageOptions, type SignStructuredMessageVariables, type SignTransactionData, type SignTransactionOptions, type SignTransactionVariables, type StacksChain, StacksWalletProvider, type StacksWallets, type SupportedStacksWallet, type TraitReference, type TransferSTXOptions, type TransferSTXVariables, type TypedWriteContractVariables, UnsupportedMethodError, type UnsupportedMethodErrorType, type UntypedWriteContractVariables, type WalletConnectMetadata, type WalletContextValue, type WalletInfo, WalletNotConnectedError, type WalletNotConnectedErrorType, WalletNotFoundError, type WalletNotFoundErrorType, WalletRequestError, type WalletRequestErrorType, type WalletState, type WriteContractOptions, type WriteContractVariables, createContractConfig, getLocalStorageWallet, getNetworkFromAddress, getStacksWallets, useAddress, useBnsName, useConnect, useDisconnect, useSignMessage, useSignStructuredMessage, useSignTransaction, useTransferSTX, useWallets, useWriteContract };
|
package/dist/index.js
CHANGED
|
@@ -4,6 +4,69 @@ import { jsx } from 'react/jsx-runtime';
|
|
|
4
4
|
import { PostConditionMode, postConditionToHex, cvToHex, noneCV, contractPrincipalCV, standardPrincipalCV, boolCV, intCV, uintCV, bufferCV, stringAsciiCV, stringUtf8CV, someCV, listCV, tupleCV } from '@stacks/transactions';
|
|
5
5
|
import { getPrimaryName } from 'bns-v2-sdk';
|
|
6
6
|
|
|
7
|
+
// src/errors.ts
|
|
8
|
+
var BaseError = class extends Error {
|
|
9
|
+
name = "StacksKitError";
|
|
10
|
+
shortMessage;
|
|
11
|
+
constructor(shortMessage, options) {
|
|
12
|
+
const message = [
|
|
13
|
+
shortMessage,
|
|
14
|
+
options?.details && `Details: ${options.details}`
|
|
15
|
+
].filter(Boolean).join("\n\n");
|
|
16
|
+
super(message, options?.cause ? { cause: options.cause } : void 0);
|
|
17
|
+
this.shortMessage = shortMessage;
|
|
18
|
+
}
|
|
19
|
+
walk(fn) {
|
|
20
|
+
return walk(this, fn);
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
function walk(err, fn) {
|
|
24
|
+
if (fn?.(err)) return err;
|
|
25
|
+
if (err && typeof err === "object" && "cause" in err) {
|
|
26
|
+
return walk(err.cause, fn);
|
|
27
|
+
}
|
|
28
|
+
return err;
|
|
29
|
+
}
|
|
30
|
+
var WalletNotConnectedError = class extends BaseError {
|
|
31
|
+
name = "WalletNotConnectedError";
|
|
32
|
+
constructor() {
|
|
33
|
+
super("Wallet is not connected");
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
var WalletNotFoundError = class extends BaseError {
|
|
37
|
+
name = "WalletNotFoundError";
|
|
38
|
+
wallet;
|
|
39
|
+
constructor({ wallet }) {
|
|
40
|
+
super(`${wallet} wallet not found`, {
|
|
41
|
+
details: "The wallet extension may not be installed."
|
|
42
|
+
});
|
|
43
|
+
this.wallet = wallet;
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
var UnsupportedMethodError = class extends BaseError {
|
|
47
|
+
name = "UnsupportedMethodError";
|
|
48
|
+
method;
|
|
49
|
+
wallet;
|
|
50
|
+
constructor({ method, wallet }) {
|
|
51
|
+
super(`${method} is not supported by ${wallet} wallet`);
|
|
52
|
+
this.method = method;
|
|
53
|
+
this.wallet = wallet;
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
var WalletRequestError = class extends BaseError {
|
|
57
|
+
name = "WalletRequestError";
|
|
58
|
+
method;
|
|
59
|
+
wallet;
|
|
60
|
+
constructor({ method, wallet, cause }) {
|
|
61
|
+
super(`${wallet} wallet request failed`, {
|
|
62
|
+
cause,
|
|
63
|
+
details: cause.message
|
|
64
|
+
});
|
|
65
|
+
this.method = method;
|
|
66
|
+
this.wallet = wallet;
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
|
|
7
70
|
// src/constants/stacks-provider-mapping.ts
|
|
8
71
|
var STACKS_TO_STACKS_CONNECT_PROVIDERS = {
|
|
9
72
|
xverse: "XverseProviders.BitcoinProvider",
|
|
@@ -683,7 +746,7 @@ var useSignMessage = () => {
|
|
|
683
746
|
const signMessageAsync = useCallback(
|
|
684
747
|
async (variables) => {
|
|
685
748
|
if (!isConnected) {
|
|
686
|
-
throw new
|
|
749
|
+
throw new WalletNotConnectedError();
|
|
687
750
|
}
|
|
688
751
|
setStatus("pending");
|
|
689
752
|
setError(null);
|
|
@@ -692,7 +755,7 @@ var useSignMessage = () => {
|
|
|
692
755
|
let result;
|
|
693
756
|
if (provider === "okx") {
|
|
694
757
|
if (!window.okxwallet) {
|
|
695
|
-
throw new
|
|
758
|
+
throw new WalletNotFoundError({ wallet: "OKX" });
|
|
696
759
|
}
|
|
697
760
|
result = await window.okxwallet.stacks.signMessage({
|
|
698
761
|
message: variables.message
|
|
@@ -709,7 +772,11 @@ var useSignMessage = () => {
|
|
|
709
772
|
setStatus("success");
|
|
710
773
|
return result;
|
|
711
774
|
} catch (err) {
|
|
712
|
-
const error2 = err instanceof
|
|
775
|
+
const error2 = err instanceof BaseError ? err : new WalletRequestError({
|
|
776
|
+
method: "stx_signMessage",
|
|
777
|
+
wallet: provider ?? "unknown",
|
|
778
|
+
cause: err instanceof Error ? err : new Error(String(err))
|
|
779
|
+
});
|
|
713
780
|
setError(error2);
|
|
714
781
|
setStatus("error");
|
|
715
782
|
throw error2;
|
|
@@ -760,12 +827,13 @@ var useSignStructuredMessage = () => {
|
|
|
760
827
|
const signStructuredMessageAsync = useCallback(
|
|
761
828
|
async (variables) => {
|
|
762
829
|
if (!isConnected) {
|
|
763
|
-
throw new
|
|
830
|
+
throw new WalletNotConnectedError();
|
|
764
831
|
}
|
|
765
832
|
if (provider === "okx") {
|
|
766
|
-
throw new
|
|
767
|
-
|
|
768
|
-
|
|
833
|
+
throw new UnsupportedMethodError({
|
|
834
|
+
method: "stx_signStructuredMessage",
|
|
835
|
+
wallet: "OKX"
|
|
836
|
+
});
|
|
769
837
|
}
|
|
770
838
|
setStatus("pending");
|
|
771
839
|
setError(null);
|
|
@@ -779,7 +847,11 @@ var useSignStructuredMessage = () => {
|
|
|
779
847
|
setStatus("success");
|
|
780
848
|
return result;
|
|
781
849
|
} catch (err) {
|
|
782
|
-
const error2 = err instanceof
|
|
850
|
+
const error2 = err instanceof BaseError ? err : new WalletRequestError({
|
|
851
|
+
method: "stx_signStructuredMessage",
|
|
852
|
+
wallet: provider ?? "unknown",
|
|
853
|
+
cause: err instanceof Error ? err : new Error(String(err))
|
|
854
|
+
});
|
|
783
855
|
setError(error2);
|
|
784
856
|
setStatus("error");
|
|
785
857
|
throw error2;
|
|
@@ -835,12 +907,13 @@ var useSignTransaction = () => {
|
|
|
835
907
|
const signTransactionAsync = useCallback(
|
|
836
908
|
async (variables) => {
|
|
837
909
|
if (!isConnected) {
|
|
838
|
-
throw new
|
|
910
|
+
throw new WalletNotConnectedError();
|
|
839
911
|
}
|
|
840
912
|
if (provider === "okx") {
|
|
841
|
-
throw new
|
|
842
|
-
|
|
843
|
-
|
|
913
|
+
throw new UnsupportedMethodError({
|
|
914
|
+
method: "stx_signTransaction",
|
|
915
|
+
wallet: "OKX"
|
|
916
|
+
});
|
|
844
917
|
}
|
|
845
918
|
setStatus("pending");
|
|
846
919
|
setError(null);
|
|
@@ -856,7 +929,11 @@ var useSignTransaction = () => {
|
|
|
856
929
|
setStatus("success");
|
|
857
930
|
return result;
|
|
858
931
|
} catch (err) {
|
|
859
|
-
const error2 = err instanceof
|
|
932
|
+
const error2 = err instanceof BaseError ? err : new WalletRequestError({
|
|
933
|
+
method: "stx_signTransaction",
|
|
934
|
+
wallet: provider ?? "unknown",
|
|
935
|
+
cause: err instanceof Error ? err : new Error(String(err))
|
|
936
|
+
});
|
|
860
937
|
setError(error2);
|
|
861
938
|
setStatus("error");
|
|
862
939
|
throw error2;
|
|
@@ -918,7 +995,7 @@ var useTransferSTX = () => {
|
|
|
918
995
|
const transferSTXAsync = useCallback(
|
|
919
996
|
async (variables) => {
|
|
920
997
|
if (!isConnected || !address) {
|
|
921
|
-
throw new
|
|
998
|
+
throw new WalletNotConnectedError();
|
|
922
999
|
}
|
|
923
1000
|
setStatus("pending");
|
|
924
1001
|
setError(null);
|
|
@@ -926,7 +1003,7 @@ var useTransferSTX = () => {
|
|
|
926
1003
|
try {
|
|
927
1004
|
if (provider === "okx") {
|
|
928
1005
|
if (!window.okxwallet) {
|
|
929
|
-
throw new
|
|
1006
|
+
throw new WalletNotFoundError({ wallet: "OKX" });
|
|
930
1007
|
}
|
|
931
1008
|
const response2 = await window.okxwallet.stacks.signTransaction({
|
|
932
1009
|
txType: "token_transfer",
|
|
@@ -961,7 +1038,11 @@ var useTransferSTX = () => {
|
|
|
961
1038
|
setStatus("success");
|
|
962
1039
|
return response.txid;
|
|
963
1040
|
} catch (err) {
|
|
964
|
-
const error2 = err instanceof
|
|
1041
|
+
const error2 = err instanceof BaseError ? err : new WalletRequestError({
|
|
1042
|
+
method: "stx_transferStx",
|
|
1043
|
+
wallet: provider ?? "unknown",
|
|
1044
|
+
cause: err instanceof Error ? err : new Error(String(err))
|
|
1045
|
+
});
|
|
965
1046
|
setError(error2);
|
|
966
1047
|
setStatus("error");
|
|
967
1048
|
throw error2;
|
|
@@ -1149,7 +1230,7 @@ var useWriteContract = () => {
|
|
|
1149
1230
|
const writeContractAsync = useCallback(
|
|
1150
1231
|
async (variables) => {
|
|
1151
1232
|
if (!isConnected || !address) {
|
|
1152
|
-
throw new
|
|
1233
|
+
throw new WalletNotConnectedError();
|
|
1153
1234
|
}
|
|
1154
1235
|
setStatus("pending");
|
|
1155
1236
|
setError(null);
|
|
@@ -1158,7 +1239,7 @@ var useWriteContract = () => {
|
|
|
1158
1239
|
try {
|
|
1159
1240
|
if (provider === "okx") {
|
|
1160
1241
|
if (!window.okxwallet) {
|
|
1161
|
-
throw new
|
|
1242
|
+
throw new WalletNotFoundError({ wallet: "OKX" });
|
|
1162
1243
|
}
|
|
1163
1244
|
const response2 = await window.okxwallet.stacks.signTransaction({
|
|
1164
1245
|
contractAddress: variables.address,
|
|
@@ -1193,7 +1274,11 @@ var useWriteContract = () => {
|
|
|
1193
1274
|
setStatus("success");
|
|
1194
1275
|
return response.txid;
|
|
1195
1276
|
} catch (err) {
|
|
1196
|
-
const error2 = err instanceof
|
|
1277
|
+
const error2 = err instanceof BaseError ? err : new WalletRequestError({
|
|
1278
|
+
method: "stx_callContract",
|
|
1279
|
+
wallet: provider ?? "unknown",
|
|
1280
|
+
cause: err instanceof Error ? err : new Error(String(err))
|
|
1281
|
+
});
|
|
1197
1282
|
setError(error2);
|
|
1198
1283
|
setStatus("error");
|
|
1199
1284
|
throw error2;
|
|
@@ -1278,6 +1363,6 @@ function createContractConfig(config) {
|
|
|
1278
1363
|
return config;
|
|
1279
1364
|
}
|
|
1280
1365
|
|
|
1281
|
-
export { SUPPORTED_STACKS_WALLETS, StacksWalletProvider, createContractConfig, getLocalStorageWallet, getNetworkFromAddress, getStacksWallets, useAddress, useBnsName, useConnect, useDisconnect, useSignMessage, useSignStructuredMessage, useSignTransaction, useTransferSTX, useWallets, useWriteContract };
|
|
1366
|
+
export { BaseError, SUPPORTED_STACKS_WALLETS, StacksWalletProvider, UnsupportedMethodError, WalletNotConnectedError, WalletNotFoundError, WalletRequestError, createContractConfig, getLocalStorageWallet, getNetworkFromAddress, getStacksWallets, useAddress, useBnsName, useConnect, useDisconnect, useSignMessage, useSignStructuredMessage, useSignTransaction, useTransferSTX, useWallets, useWriteContract };
|
|
1282
1367
|
//# sourceMappingURL=index.js.map
|
|
1283
1368
|
//# sourceMappingURL=index.js.map
|