@weblock-wallet/sdk 0.1.49 → 0.1.51

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/dist/index.cjs CHANGED
@@ -105012,19 +105012,21 @@ var UserClient = class {
105012
105012
  * - { coin: CoinResponse }
105013
105013
  * - { data: CoinResponse }
105014
105014
  */
105015
+ // UserClient 클래스 내부의 registerToken()을 아래로 교체
105015
105016
  async registerToken(req) {
105016
- const blockchainId = req.blockchainId;
105017
- const contractAddress = this.normalizeAddress(req.contractAddress);
105017
+ const blockchainId = req.blockchainId ?? req.networkId;
105018
+ const contractAddress = String(
105019
+ req.contractAddress ?? req.tokenAddress ?? req.address ?? ""
105020
+ ).trim().toLowerCase();
105018
105021
  const name2 = req.name;
105019
105022
  const symbol = req.symbol;
105020
105023
  const decimals = req.decimals;
105021
105024
  const candidates = [
105022
- // 1) 최신 스펙으로 바뀌며 "주소만" 받는 경우
105025
+ // 1) 주소만 받는 케이스
105023
105026
  { blockchainId, contractAddress },
105024
- // 2) 필드명이 tokenAddress / address로 바뀐 경우
105025
105027
  { blockchainId, tokenAddress: contractAddress },
105026
105028
  { blockchainId, address: contractAddress },
105027
- // 3) 스펙(메타 포함) 유지/필요한 경우
105029
+ // 2) 메타까지 받는 케이스
105028
105030
  ...name2 && symbol && typeof decimals === "number" ? [
105029
105031
  { blockchainId, contractAddress, name: name2, symbol, decimals },
105030
105032
  {
@@ -105036,45 +105038,32 @@ var UserClient = class {
105036
105038
  },
105037
105039
  { blockchainId, address: contractAddress, name: name2, symbol, decimals }
105038
105040
  ] : [],
105039
- // 4) blockchainId가 networkId로 바뀐 경우
105040
- ...name2 && symbol && typeof decimals === "number" ? [
105041
- {
105042
- networkId: blockchainId,
105043
- contractAddress,
105044
- name: name2,
105045
- symbol,
105046
- decimals
105047
- },
105048
- {
105049
- networkId: blockchainId,
105050
- tokenAddress: contractAddress,
105051
- name: name2,
105052
- symbol,
105053
- decimals
105054
- }
105055
- ] : [{ networkId: blockchainId, contractAddress }]
105041
+ // 3) 파라미터명이 networkId로 바뀐 케이스
105042
+ { networkId: blockchainId, contractAddress },
105043
+ ...name2 && symbol && typeof decimals === "number" ? [{ networkId: blockchainId, contractAddress, name: name2, symbol, decimals }] : []
105056
105044
  ];
105057
105045
  let lastError = null;
105058
105046
  for (const body of candidates) {
105059
105047
  try {
105060
105048
  const res = await this.client.post(
105061
- `${this.baseUrl}/register-token`,
105062
- body
105049
+ "/v1/users/register-token",
105050
+ body,
105051
+ {
105052
+ needsAccessToken: true
105053
+ }
105063
105054
  );
105064
- const coin = this.unwrapCoin(res);
105065
- if (!coin?.contractAddress) {
105066
- continue;
105055
+ const coin = res?.coin ?? res?.data ?? res;
105056
+ if (coin?.contractAddress) {
105057
+ return {
105058
+ ...coin,
105059
+ contractAddress: String(coin.contractAddress).trim().toLowerCase(),
105060
+ decimals: typeof coin.decimals === "number" ? coin.decimals : Number(coin.decimals)
105061
+ };
105067
105062
  }
105068
- return {
105069
- ...coin,
105070
- contractAddress: this.normalizeAddress(coin.contractAddress),
105071
- decimals: Number(coin.decimals)
105072
- };
105073
105063
  } catch (e7) {
105074
105064
  lastError = e7;
105075
- const status = this.extractStatus(e7);
105076
- if (status === 400 || status === 422) continue;
105077
- if (status === 409) continue;
105065
+ const status = e7?.status ?? e7?.response?.status ?? e7?.cause?.status ?? e7?.cause?.response?.status;
105066
+ if (status === 400 || status === 409 || status === 422) continue;
105078
105067
  throw e7;
105079
105068
  }
105080
105069
  }
@@ -105098,6 +105087,32 @@ var UserClient = class {
105098
105087
  { needsAccessToken: true }
105099
105088
  );
105100
105089
  }
105090
+ // UserClient 클래스 내부에 추가
105091
+ async postAuthed(path, body) {
105092
+ const httpAny = this.client;
105093
+ const headers = (typeof httpAny.getAuthHeaders === "function" ? await httpAny.getAuthHeaders() : typeof httpAny.getHeaders === "function" ? await httpAny.getHeaders() : void 0) ?? void 0;
105094
+ const attempts = [];
105095
+ if (typeof httpAny.post === "function") {
105096
+ attempts.push(() => httpAny.post(path, body, headers));
105097
+ attempts.push(() => httpAny.post(path, body, { headers }));
105098
+ attempts.push(() => httpAny.post(path, body));
105099
+ }
105100
+ if (typeof httpAny.request === "function") {
105101
+ attempts.push(
105102
+ () => httpAny.request({ method: "POST", path, body, headers })
105103
+ );
105104
+ attempts.push(() => httpAny.request("POST", path, body, headers));
105105
+ }
105106
+ let lastError = null;
105107
+ for (const fn of attempts) {
105108
+ try {
105109
+ return await fn();
105110
+ } catch (e7) {
105111
+ lastError = e7;
105112
+ }
105113
+ }
105114
+ throw lastError ?? new Error(`POST ${path} failed`);
105115
+ }
105101
105116
  };
105102
105117
 
105103
105118
  // src/clients/api/wallets.ts