@weblock-wallet/sdk 0.1.48 → 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
@@ -104995,10 +104995,88 @@ var UserClient = class {
104995
104995
  needsAccessToken: true
104996
104996
  });
104997
104997
  }
104998
- async registerToken(request) {
104999
- return this.client.post(`${this.baseUrl}/register-token`, request, {
105000
- needsAccessToken: true
105001
- });
104998
+ // async registerToken(request: TokenRequest): Promise<TokenResponse> {
104999
+ // return this.client.post(`${this.baseUrl}/register-token`, request, {
105000
+ // needsAccessToken: true,
105001
+ // })
105002
+ // }
105003
+ /**
105004
+ * POST /v1/users/register-token
105005
+ *
105006
+ * 백엔드가 아래 중 어떤 스펙이든 동작하도록:
105007
+ * - 최소 요청형: { blockchainId, contractAddress }
105008
+ * - 풀 요청형: { blockchainId, contractAddress, name, symbol, decimals }
105009
+ *
105010
+ * 또한 응답이 아래 중 어떤 형태든 파싱:
105011
+ * - CoinResponse
105012
+ * - { coin: CoinResponse }
105013
+ * - { data: CoinResponse }
105014
+ */
105015
+ // UserClient 클래스 내부의 registerToken()을 아래로 교체
105016
+ async registerToken(req) {
105017
+ const blockchainId = req.blockchainId ?? req.networkId;
105018
+ const contractAddress = String(
105019
+ req.contractAddress ?? req.tokenAddress ?? req.address ?? ""
105020
+ ).trim().toLowerCase();
105021
+ const name2 = req.name;
105022
+ const symbol = req.symbol;
105023
+ const decimals = req.decimals;
105024
+ const candidates = [
105025
+ // 1) 주소만 받는 케이스
105026
+ { blockchainId, contractAddress },
105027
+ { blockchainId, tokenAddress: contractAddress },
105028
+ { blockchainId, address: contractAddress },
105029
+ // 2) 메타까지 받는 케이스
105030
+ ...name2 && symbol && typeof decimals === "number" ? [
105031
+ { blockchainId, contractAddress, name: name2, symbol, decimals },
105032
+ {
105033
+ blockchainId,
105034
+ tokenAddress: contractAddress,
105035
+ name: name2,
105036
+ symbol,
105037
+ decimals
105038
+ },
105039
+ { blockchainId, address: contractAddress, name: name2, symbol, decimals }
105040
+ ] : [],
105041
+ // 3) 파라미터명이 networkId로 바뀐 케이스
105042
+ { networkId: blockchainId, contractAddress },
105043
+ ...name2 && symbol && typeof decimals === "number" ? [{ networkId: blockchainId, contractAddress, name: name2, symbol, decimals }] : []
105044
+ ];
105045
+ let lastError = null;
105046
+ for (const body of candidates) {
105047
+ try {
105048
+ const res = await this.postAuthed(
105049
+ "/v1/users/register-token",
105050
+ body
105051
+ );
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
+ };
105059
+ }
105060
+ } catch (e7) {
105061
+ lastError = e7;
105062
+ const status = e7?.status ?? e7?.response?.status ?? e7?.cause?.status ?? e7?.cause?.response?.status;
105063
+ if (status === 400 || status === 409 || status === 422) continue;
105064
+ throw e7;
105065
+ }
105066
+ }
105067
+ throw lastError ?? new Error("registerToken failed");
105068
+ }
105069
+ unwrapCoin(res) {
105070
+ if (!res) return null;
105071
+ if (res.coin) return res.coin;
105072
+ if (res.data) return res.data;
105073
+ return res;
105074
+ }
105075
+ normalizeAddress(address) {
105076
+ return (address ?? "").trim().toLowerCase();
105077
+ }
105078
+ extractStatus(e7) {
105079
+ return e7?.status ?? e7?.response?.status ?? e7?.cause?.status ?? e7?.cause?.response?.status;
105002
105080
  }
105003
105081
  async getRegisteredCoins(blockchainId) {
105004
105082
  return this.client.get(
@@ -105006,6 +105084,32 @@ var UserClient = class {
105006
105084
  { needsAccessToken: true }
105007
105085
  );
105008
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
+ }
105009
105113
  };
105010
105114
 
105011
105115
  // src/clients/api/wallets.ts