anchor-sdk 0.1.41-internal.6 → 0.1.42-beta.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.
Files changed (58) hide show
  1. package/dist/AnchorApiClientV2.d.ts +3 -2
  2. package/dist/AnchorApiClientV2.d.ts.map +1 -0
  3. package/dist/AnchorERC1155Client.d.ts +1 -0
  4. package/dist/AnchorERC1155Client.d.ts.map +1 -0
  5. package/dist/AnchorPayClient.d.ts +1 -0
  6. package/dist/AnchorPayClient.d.ts.map +1 -0
  7. package/dist/abi/AnchorERC1155.d.ts +1 -0
  8. package/dist/abi/AnchorERC1155.d.ts.map +1 -0
  9. package/dist/constants.d.ts +2 -1
  10. package/dist/constants.d.ts.map +1 -0
  11. package/dist/generated/Api.d.ts +1 -0
  12. package/dist/generated/Api.d.ts.map +1 -0
  13. package/dist/index.d.ts +7 -7
  14. package/dist/index.d.ts.map +1 -0
  15. package/dist/index.js +3 -1379
  16. package/dist/index.js.map +18 -0
  17. package/dist/typechain/AnchorERC1155.d.ts +3 -2
  18. package/dist/typechain/AnchorERC1155.d.ts.map +1 -0
  19. package/dist/typechain/AnchorPay.d.ts +3 -2
  20. package/dist/typechain/AnchorPay.d.ts.map +1 -0
  21. package/dist/typechain/common.d.ts +2 -1
  22. package/dist/typechain/common.d.ts.map +1 -0
  23. package/dist/typechain/factories/AnchorERC1155__factory.d.ts +1 -0
  24. package/dist/typechain/factories/AnchorERC1155__factory.d.ts.map +1 -0
  25. package/dist/typechain/factories/AnchorPay__factory.d.ts +1 -0
  26. package/dist/typechain/factories/AnchorPay__factory.d.ts.map +1 -0
  27. package/dist/typechain/factories/index.d.ts +1 -0
  28. package/dist/typechain/factories/index.d.ts.map +1 -0
  29. package/dist/typechain/index.d.ts +1 -0
  30. package/dist/typechain/index.d.ts.map +1 -0
  31. package/dist/types.d.ts +1 -0
  32. package/dist/types.d.ts.map +1 -0
  33. package/package.json +83 -85
  34. package/dist/AnchorApiClient.d.ts +0 -203
  35. package/dist/AnchorApiClient.js +0 -279
  36. package/dist/AnchorApiClientV2.js +0 -316
  37. package/dist/AnchorERC1155Client.js +0 -301
  38. package/dist/AnchorPayClient.js +0 -908
  39. package/dist/abi/AnchorERC1155.js +0 -1122
  40. package/dist/abi/AnchorPay.json +0 -578
  41. package/dist/api/AnchorApiHttpClient.d.ts +0 -210
  42. package/dist/api/AnchorApiHttpClient.js +0 -411
  43. package/dist/api/types.d.ts +0 -764
  44. package/dist/api/types.js +0 -2
  45. package/dist/constants.js +0 -367
  46. package/dist/generated/Api.js +0 -763
  47. package/dist/react/AnchorReactSDK.d.ts +0 -59
  48. package/dist/react/AnchorReactSDK.js +0 -192
  49. package/dist/react/index.d.ts +0 -1
  50. package/dist/react/index.js +0 -8
  51. package/dist/typechain/AnchorERC1155.js +0 -2
  52. package/dist/typechain/AnchorPay.js +0 -2
  53. package/dist/typechain/common.js +0 -2
  54. package/dist/typechain/factories/AnchorERC1155__factory.js +0 -1766
  55. package/dist/typechain/factories/AnchorPay__factory.js +0 -469
  56. package/dist/typechain/factories/index.js +0 -10
  57. package/dist/typechain/index.js +0 -41
  58. package/dist/types.js +0 -2
@@ -1,59 +0,0 @@
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 {};
@@ -1,192 +0,0 @@
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;
@@ -1 +0,0 @@
1
- export { AnchorReactProvider, useAnchorSDK, useAnchorBadge } from './AnchorReactSDK';
@@ -1,8 +0,0 @@
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,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });