anchor-sdk 0.1.39 → 0.1.41-internal.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.
@@ -70,6 +70,12 @@ export declare class AnchorApiClientV2 {
70
70
  * @returns API 调用结果
71
71
  */
72
72
  private handleApiCall;
73
+ /**
74
+ * 检查响应是否为 token 过期错误
75
+ * @param response API 响应
76
+ * @returns 是否为 token 过期错误
77
+ */
78
+ private isTokenExpiredResponse;
73
79
  /**
74
80
  * 获取徽章验证器
75
81
  * @param platform 平台标识符
@@ -94,14 +94,21 @@ class AnchorApiClientV2 {
94
94
  */
95
95
  async handleApiCall(apiCall) {
96
96
  try {
97
- return await apiCall();
97
+ const result = await apiCall();
98
+ // 检查响应体中的 token 过期信息
99
+ if (this.isTokenExpiredResponse(result)) {
100
+ console.log("Token expired: JWT token is invalid or expired");
101
+ const error = new Error("Token expired: JWT token is invalid or expired");
102
+ if (this.onTokenExpired) {
103
+ this.onTokenExpired(error);
104
+ }
105
+ throw error;
106
+ }
107
+ return result;
98
108
  }
99
109
  catch (error) {
100
- // 检查 token 过期
101
- if (error instanceof Error &&
102
- (error.message.includes("JWT") ||
103
- error.message.includes("401") ||
104
- error.message.includes("unauthorized"))) {
110
+ // 检查 HTTP 401 状态码的 token 过期
111
+ if (error?.status === 401) {
105
112
  if (this.onTokenExpired) {
106
113
  this.onTokenExpired(error);
107
114
  }
@@ -109,6 +116,24 @@ class AnchorApiClientV2 {
109
116
  throw error;
110
117
  }
111
118
  }
119
+ /**
120
+ * 检查响应是否为 token 过期错误
121
+ * @param response API 响应
122
+ * @returns 是否为 token 过期错误
123
+ */
124
+ isTokenExpiredResponse(response) {
125
+ // 检查响应体中的 token 过期标识
126
+ // 优先检查:success 为 false 且 code 为 9101(标准 token 过期错误码)
127
+ if (response?.success === false && response?.code === "9101") {
128
+ return true;
129
+ }
130
+ // 检查 msgKey 是否为特定的 JWT 错误
131
+ if (response?.success === false &&
132
+ response?.msgKey === "params.jwt.check.invalid") {
133
+ return true;
134
+ }
135
+ return false;
136
+ }
112
137
  // ==================== V2 API Methods ====================
113
138
  /**
114
139
  * 获取徽章验证器
@@ -227,13 +227,23 @@ class AnchorERC1155Client {
227
227
  if (!this.walletClient || !this.account) {
228
228
  throw new Error("Wallet client and account are required to send transactions");
229
229
  }
230
+ const { maxFeePerGas, maxPriorityFeePerGas } = await this.publicClient.estimateFeesPerGas();
231
+ const gas = await this.publicClient.estimateGas({
232
+ to: contractAddress,
233
+ data: calldata,
234
+ value: 0n,
235
+ account: this.account,
236
+ });
230
237
  const txHash = await this.walletClient.writeContract({
231
238
  account: this.account,
232
239
  address: contractAddress,
233
240
  abi: AnchorERC1155_1.AnchorERC1155ABI,
234
241
  functionName: "multicall",
235
242
  args: [data],
236
- chain: null,
243
+ chain: this.publicClient.chain,
244
+ maxFeePerGas,
245
+ maxPriorityFeePerGas,
246
+ gas,
237
247
  });
238
248
  return await this.publicClient.waitForTransactionReceipt({ hash: txHash });
239
249
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "anchor-sdk",
3
- "version": "0.1.39",
3
+ "version": "0.1.41-internal.0",
4
4
  "description": "TypeScript SDK for interacting with Anchor ecosystem - badge minting, payment processing, and ERC1155 token management",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",