anchor-sdk 0.1.42-beta.1 → 0.1.42-beta.2

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.
Files changed (36) hide show
  1. package/dist/AnchorApiClientV2.d.ts +8 -4
  2. package/dist/AnchorApiClientV2.js +316 -0
  3. package/dist/AnchorERC1155Client.d.ts +0 -1
  4. package/dist/AnchorERC1155Client.js +301 -0
  5. package/dist/AnchorPayClient.d.ts +0 -1
  6. package/dist/AnchorPayClient.js +908 -0
  7. package/dist/abi/AnchorERC1155.d.ts +0 -1
  8. package/dist/abi/AnchorERC1155.js +1122 -0
  9. package/dist/abi/AnchorPay.json +578 -0
  10. package/dist/constants.d.ts +1 -2
  11. package/dist/constants.js +367 -0
  12. package/dist/generated/Api.d.ts +692 -606
  13. package/dist/generated/Api.js +794 -0
  14. package/dist/index.d.ts +7 -7
  15. package/dist/index.js +1379 -3
  16. package/dist/react/AnchorReactSDK.d.ts +59 -0
  17. package/dist/react/AnchorReactSDK.js +192 -0
  18. package/dist/react/index.d.ts +1 -0
  19. package/dist/react/index.js +8 -0
  20. package/dist/typechain/AnchorERC1155.d.ts +2 -3
  21. package/dist/typechain/AnchorERC1155.js +2 -0
  22. package/dist/typechain/AnchorPay.d.ts +2 -3
  23. package/dist/typechain/AnchorPay.js +2 -0
  24. package/dist/typechain/common.d.ts +1 -2
  25. package/dist/typechain/common.js +2 -0
  26. package/dist/typechain/factories/AnchorERC1155__factory.d.ts +0 -1
  27. package/dist/typechain/factories/AnchorERC1155__factory.js +1766 -0
  28. package/dist/typechain/factories/AnchorPay__factory.d.ts +0 -1
  29. package/dist/typechain/factories/AnchorPay__factory.js +469 -0
  30. package/dist/typechain/factories/index.d.ts +0 -1
  31. package/dist/typechain/factories/index.js +10 -0
  32. package/dist/typechain/index.d.ts +0 -1
  33. package/dist/typechain/index.js +41 -0
  34. package/dist/types.d.ts +0 -1
  35. package/dist/types.js +2 -0
  36. package/package.json +1 -1
@@ -0,0 +1,59 @@
1
+ import type { AnchorSDKConfig, PaymentOptions, SignedMintRequest } from "../types";
2
+ import React, { ReactNode } from "react";
3
+ import { TransactionReceipt, WalletClient } from "viem";
4
+ import { AnchorSDK } from "../index";
5
+ interface AnchorReactContextType {
6
+ sdk: AnchorSDK | null;
7
+ loading: boolean;
8
+ error: Error | null;
9
+ initialized: boolean;
10
+ setWalletClient: (walletClient: WalletClient) => void;
11
+ buyBadgeWithETH: (customerAddress: string, contractAddress: string, tokenId: string | number | bigint, quantity: string | number | bigint, receiptAddress: string, options?: PaymentOptions) => Promise<TransactionReceipt | {
12
+ to: string;
13
+ data: string;
14
+ value: bigint;
15
+ }>;
16
+ buyBadgeWithERC20: (customerAddress: string, contractAddress: string, tokenId: string | number | bigint, quantity: string | number | bigint, currency: string, receiptAddress: string, options?: PaymentOptions) => Promise<TransactionReceipt | {
17
+ to: string;
18
+ data: string;
19
+ value: bigint;
20
+ }>;
21
+ buyBadgeWithETHWithSignedRequest: (signedRequest: SignedMintRequest, receiptAddress: string, options?: PaymentOptions) => Promise<TransactionReceipt | {
22
+ to: string;
23
+ data: string;
24
+ value: bigint;
25
+ }>;
26
+ buyBadgeWithERC20WithSignedRequest: (signedRequest: SignedMintRequest, receiptAddress: string, options?: PaymentOptions) => Promise<TransactionReceipt | {
27
+ to: string;
28
+ data: string;
29
+ value: bigint;
30
+ }>;
31
+ }
32
+ interface AnchorReactProviderProps {
33
+ children: ReactNode;
34
+ config: AnchorSDKConfig;
35
+ }
36
+ /**
37
+ * Anchor React Provider Component
38
+ * Used to provide Anchor SDK instance in React applications
39
+ */
40
+ export declare function AnchorReactProvider({ children, config, }: AnchorReactProviderProps): React.JSX.Element;
41
+ /**
42
+ * Custom Hook for using Anchor SDK
43
+ * @returns Anchor React context
44
+ */
45
+ export declare const useAnchorSDK: () => AnchorReactContextType;
46
+ /**
47
+ * Custom Hook for using Anchor badges
48
+ * @returns Badge related functions
49
+ */
50
+ export declare const useAnchorBadge: () => {
51
+ loading: boolean;
52
+ error: Error | null;
53
+ initialized: boolean;
54
+ getClaimableBadges: () => Promise<import("../index").WebResultBadgeAssetsResponse>;
55
+ getClaimedBadges: () => Promise<import("../index").WebResultBadgeAssetsResponse>;
56
+ getNftSeries: () => Promise<import("../index").WebResultBadgeSeriesResponse>;
57
+ getNftSeriesById: (series: string) => Promise<import("../index").WebResultBadgeSeriesDetailResponse>;
58
+ };
59
+ export {};
@@ -0,0 +1,192 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.useAnchorBadge = exports.useAnchorSDK = void 0;
37
+ exports.AnchorReactProvider = AnchorReactProvider;
38
+ const react_1 = __importStar(require("react"));
39
+ const index_1 = require("../index");
40
+ // Create React context
41
+ const AnchorReactContext = (0, react_1.createContext)(undefined);
42
+ /**
43
+ * Anchor React Provider Component
44
+ * Used to provide Anchor SDK instance in React applications
45
+ */
46
+ function AnchorReactProvider({ children, config, }) {
47
+ const [sdk, setSdk] = (0, react_1.useState)(null);
48
+ const [loading, setLoading] = (0, react_1.useState)(true);
49
+ const [error, setError] = (0, react_1.useState)(null);
50
+ const [initialized, setInitialized] = (0, react_1.useState)(false);
51
+ (0, react_1.useEffect)(() => {
52
+ try {
53
+ const anchorSdk = new index_1.AnchorSDK(config);
54
+ setSdk(anchorSdk);
55
+ setInitialized(true);
56
+ setError(null);
57
+ }
58
+ catch (err) {
59
+ setError(err instanceof Error ? err : new Error("初始化 Anchor SDK 失败"));
60
+ }
61
+ finally {
62
+ setLoading(false);
63
+ }
64
+ }, [
65
+ config.publicClient,
66
+ config.walletClient,
67
+ config.network.id,
68
+ config.apiBaseUrl,
69
+ config.authToken,
70
+ config.projectId,
71
+ config.env,
72
+ config.anchorERC1155Address,
73
+ config.anchorPayAddress,
74
+ ]);
75
+ // 使用 ETH 购买徽章
76
+ const buyBadgeWithETH = async (customerAddress, contractAddress, tokenId, quantity = 1, receiptAddress, options) => {
77
+ if (!sdk) {
78
+ throw new Error("Anchor SDK not initialized");
79
+ }
80
+ return await sdk.buyBadgeWithETH(customerAddress, contractAddress, tokenId, quantity, receiptAddress, options);
81
+ };
82
+ // 使用 ERC20 购买徽章
83
+ const buyBadgeWithERC20 = async (customerAddress, contractAddress, tokenId, quantity = 1, currency, receiptAddress, options) => {
84
+ if (!sdk) {
85
+ throw new Error("Anchor SDK not initialized");
86
+ }
87
+ return await sdk.buyBadgeWithERC20(customerAddress, contractAddress, tokenId, quantity, currency, receiptAddress, options);
88
+ };
89
+ // 使用 ETH 和签名请求购买徽章
90
+ const buyBadgeWithETHWithSignedRequest = async (signedRequest, receiptAddress, options) => {
91
+ if (!sdk) {
92
+ throw new Error("Anchor SDK not initialized");
93
+ }
94
+ return await sdk.buyBadgeWithETHWithSignedRequest(signedRequest, receiptAddress, options);
95
+ };
96
+ // 使用 ERC20 和签名请求购买徽章
97
+ const buyBadgeWithERC20WithSignedRequest = async (signedRequest, receiptAddress, options) => {
98
+ if (!sdk) {
99
+ throw new Error("Anchor SDK not initialized");
100
+ }
101
+ return await sdk.buyBadgeWithERC20WithSignedRequest(signedRequest, receiptAddress, options);
102
+ };
103
+ // 设置钱包客户端
104
+ const setWalletClient = (walletClient) => {
105
+ if (!sdk) {
106
+ throw new Error("Anchor SDK not initialized");
107
+ }
108
+ sdk.setWalletClient(walletClient);
109
+ // 更新 SDK 实例后重新设置状态,确保组件重新渲染
110
+ setSdk(sdk);
111
+ };
112
+ const value = {
113
+ sdk,
114
+ loading,
115
+ error,
116
+ initialized,
117
+ setWalletClient,
118
+ buyBadgeWithETH,
119
+ buyBadgeWithERC20,
120
+ buyBadgeWithETHWithSignedRequest,
121
+ buyBadgeWithERC20WithSignedRequest,
122
+ };
123
+ return (react_1.default.createElement(AnchorReactContext.Provider, { value: value }, children));
124
+ }
125
+ /**
126
+ * Custom Hook for using Anchor SDK
127
+ * @returns Anchor React context
128
+ */
129
+ const useAnchorSDK = () => {
130
+ const context = (0, react_1.useContext)(AnchorReactContext);
131
+ if (context === undefined) {
132
+ throw new Error("useAnchorSDK must be used inside AnchorReactProvider");
133
+ }
134
+ return context;
135
+ };
136
+ exports.useAnchorSDK = useAnchorSDK;
137
+ /**
138
+ * Custom Hook for using Anchor badges
139
+ * @returns Badge related functions
140
+ */
141
+ const useAnchorBadge = () => {
142
+ const { sdk, loading, error, initialized } = (0, exports.useAnchorSDK)();
143
+ // Get badges that user can claim
144
+ const getClaimableBadges = async () => {
145
+ if (!sdk?.anchorApi) {
146
+ throw new Error("Anchor API client not initialized");
147
+ }
148
+ return await sdk.anchorApi.getUserBadgeAssets({
149
+ includeClaimable: true,
150
+ strategy: "BADGE_ALL",
151
+ });
152
+ };
153
+ // Get badges that user has claimed
154
+ const getClaimedBadges = async () => {
155
+ if (!sdk?.anchorApi) {
156
+ throw new Error("Anchor API client not initialized");
157
+ }
158
+ return await sdk.anchorApi.getUserBadgeAssets({
159
+ includeClaimable: false,
160
+ strategy: "BADGE_ALL",
161
+ });
162
+ };
163
+ // Get NFT series
164
+ const getNftSeries = async () => {
165
+ if (!sdk?.anchorApi) {
166
+ throw new Error("Anchor API client not initialized");
167
+ }
168
+ return await sdk.anchorApi.getBadgeSeries({
169
+ includeBadges: true,
170
+ limit: 100,
171
+ });
172
+ };
173
+ // Get NFT series details
174
+ const getNftSeriesById = async (series) => {
175
+ if (!sdk?.anchorApi) {
176
+ throw new Error("Anchor API client not initialized");
177
+ }
178
+ return await sdk.anchorApi.getBadgeSeriesDetail(series, {
179
+ status: "active",
180
+ });
181
+ };
182
+ return {
183
+ loading,
184
+ error,
185
+ initialized,
186
+ getClaimableBadges,
187
+ getClaimedBadges,
188
+ getNftSeries,
189
+ getNftSeriesById,
190
+ };
191
+ };
192
+ exports.useAnchorBadge = useAnchorBadge;
@@ -0,0 +1 @@
1
+ export { AnchorReactProvider, useAnchorSDK, useAnchorBadge } from './AnchorReactSDK';
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useAnchorBadge = exports.useAnchorSDK = exports.AnchorReactProvider = void 0;
4
+ // Export React SDK core
5
+ var AnchorReactSDK_1 = require("./AnchorReactSDK");
6
+ Object.defineProperty(exports, "AnchorReactProvider", { enumerable: true, get: function () { return AnchorReactSDK_1.AnchorReactProvider; } });
7
+ Object.defineProperty(exports, "useAnchorSDK", { enumerable: true, get: function () { return AnchorReactSDK_1.useAnchorSDK; } });
8
+ Object.defineProperty(exports, "useAnchorBadge", { enumerable: true, get: function () { return AnchorReactSDK_1.useAnchorBadge; } });
@@ -1,5 +1,5 @@
1
- import type { AddressLike, BaseContract, BigNumberish, BytesLike, ContractMethod, ContractRunner, EventFragment, FunctionFragment, Interface, Listener, Result } from "ethers";
2
- import type { TypedContractEvent, TypedContractMethod, TypedDeferredTopicFilter, TypedEventLog, TypedListener, TypedLogDescription } from "./common";
1
+ import type { BaseContract, BigNumberish, BytesLike, FunctionFragment, Result, Interface, EventFragment, AddressLike, ContractRunner, ContractMethod, Listener } from "ethers";
2
+ import type { TypedContractEvent, TypedDeferredTopicFilter, TypedEventLog, TypedLogDescription, TypedListener, TypedContractMethod } from "./common";
3
3
  export declare namespace AnchorDataTypes {
4
4
  type MintRequestStruct = {
5
5
  to: AddressLike;
@@ -997,4 +997,3 @@ export interface AnchorERC1155 extends BaseContract {
997
997
  Upgraded: TypedContractEvent<UpgradedEvent.InputTuple, UpgradedEvent.OutputTuple, UpgradedEvent.OutputObject>;
998
998
  };
999
999
  }
1000
- //# sourceMappingURL=AnchorERC1155.d.ts.map
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,5 +1,5 @@
1
- import type { AddressLike, BaseContract, BigNumberish, BytesLike, ContractMethod, ContractRunner, EventFragment, FunctionFragment, Interface, Listener, Result } from "ethers";
2
- import type { TypedContractEvent, TypedContractMethod, TypedDeferredTopicFilter, TypedEventLog, TypedListener, TypedLogDescription } from "./common";
1
+ import type { BaseContract, BigNumberish, BytesLike, FunctionFragment, Result, Interface, EventFragment, AddressLike, ContractRunner, ContractMethod, Listener } from "ethers";
2
+ import type { TypedContractEvent, TypedDeferredTopicFilter, TypedEventLog, TypedLogDescription, TypedListener, TypedContractMethod } from "./common";
3
3
  export interface AnchorPayInterface extends Interface {
4
4
  getFunction(nameOrSignature: "UPGRADE_INTERFACE_VERSION" | "acceptOwnership" | "getInterfaceImplementer" | "initialize" | "owner" | "pause" | "pendingOwner" | "proxiableUUID" | "renounceOwnership" | "send" | "setInterfaceImplementer" | "transferOwnership" | "unpause" | "upgradeToAndCall"): FunctionFragment;
5
5
  getEvent(nameOrSignatureOrTopic: "Initialized" | "InterfaceImplementerSet" | "OwnershipTransferStarted" | "OwnershipTransferred" | "Paid" | "Upgraded"): EventFragment;
@@ -240,4 +240,3 @@ export interface AnchorPay extends BaseContract {
240
240
  Upgraded: TypedContractEvent<UpgradedEvent.InputTuple, UpgradedEvent.OutputTuple, UpgradedEvent.OutputObject>;
241
241
  };
242
242
  }
243
- //# sourceMappingURL=AnchorPay.d.ts.map
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,4 +1,4 @@
1
- import type { ContractTransaction, ContractTransactionResponse, DeferredTopicFilter, EventFragment, EventLog, FunctionFragment, LogDescription, TransactionRequest, Typed } from "ethers";
1
+ import type { FunctionFragment, Typed, EventFragment, ContractTransaction, ContractTransactionResponse, DeferredTopicFilter, EventLog, TransactionRequest, LogDescription } from "ethers";
2
2
  export interface TypedDeferredTopicFilter<_TCEvent extends TypedContractEvent> extends DeferredTopicFilter {
3
3
  }
4
4
  export interface TypedContractEvent<InputTuple extends Array<any> = any, OutputTuple extends Array<any> = any, OutputObject = any> {
@@ -48,4 +48,3 @@ export interface TypedContractMethod<A extends Array<any> = Array<any>, R = any,
48
48
  staticCallResult(...args: ContractMethodArgs<A, "view">): Promise<R>;
49
49
  }
50
50
  export {};
51
- //# sourceMappingURL=common.d.ts.map
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1363,4 +1363,3 @@ export declare class AnchorERC1155__factory {
1363
1363
  static createInterface(): AnchorERC1155Interface;
1364
1364
  static connect(address: string, runner?: ContractRunner | null): AnchorERC1155;
1365
1365
  }
1366
- //# sourceMappingURL=AnchorERC1155__factory.d.ts.map