@weblock-wallet/sdk 0.1.49 → 0.1.50

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,29 @@ 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
- const res = await this.client.post(
105061
- `${this.baseUrl}/register-token`,
105048
+ const res = await this.postAuthed(
105049
+ "/v1/users/register-token",
105062
105050
  body
105063
105051
  );
105064
- const coin = this.unwrapCoin(res);
105065
- if (!coin?.contractAddress) {
105066
- continue;
105052
+ const coin = res?.coin ?? res?.data ?? res;
105053
+ if (coin?.contractAddress) {
105054
+ return {
105055
+ ...coin,
105056
+ contractAddress: String(coin.contractAddress).trim().toLowerCase(),
105057
+ decimals: typeof coin.decimals === "number" ? coin.decimals : Number(coin.decimals)
105058
+ };
105067
105059
  }
105068
- return {
105069
- ...coin,
105070
- contractAddress: this.normalizeAddress(coin.contractAddress),
105071
- decimals: Number(coin.decimals)
105072
- };
105073
105060
  } catch (e7) {
105074
105061
  lastError = e7;
105075
- const status = this.extractStatus(e7);
105076
- if (status === 400 || status === 422) continue;
105077
- if (status === 409) continue;
105062
+ const status = e7?.status ?? e7?.response?.status ?? e7?.cause?.status ?? e7?.cause?.response?.status;
105063
+ if (status === 400 || status === 409 || status === 422) continue;
105078
105064
  throw e7;
105079
105065
  }
105080
105066
  }
@@ -105098,6 +105084,32 @@ var UserClient = class {
105098
105084
  { needsAccessToken: true }
105099
105085
  );
105100
105086
  }
105087
+ // UserClient 클래스 내부에 추가
105088
+ async postAuthed(path, body) {
105089
+ const httpAny = this.client;
105090
+ const headers = (typeof httpAny.getAuthHeaders === "function" ? await httpAny.getAuthHeaders() : typeof httpAny.getHeaders === "function" ? await httpAny.getHeaders() : void 0) ?? void 0;
105091
+ const attempts = [];
105092
+ if (typeof httpAny.post === "function") {
105093
+ attempts.push(() => httpAny.post(path, body, headers));
105094
+ attempts.push(() => httpAny.post(path, body, { headers }));
105095
+ attempts.push(() => httpAny.post(path, body));
105096
+ }
105097
+ if (typeof httpAny.request === "function") {
105098
+ attempts.push(
105099
+ () => httpAny.request({ method: "POST", path, body, headers })
105100
+ );
105101
+ attempts.push(() => httpAny.request("POST", path, body, headers));
105102
+ }
105103
+ let lastError = null;
105104
+ for (const fn of attempts) {
105105
+ try {
105106
+ return await fn();
105107
+ } catch (e7) {
105108
+ lastError = e7;
105109
+ }
105110
+ }
105111
+ throw lastError ?? new Error(`POST ${path} failed`);
105112
+ }
105101
105113
  };
105102
105114
 
105103
105115
  // src/clients/api/wallets.ts