@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.js CHANGED
@@ -104954,10 +104954,88 @@ var UserClient = class {
104954
104954
  needsAccessToken: true
104955
104955
  });
104956
104956
  }
104957
- async registerToken(request) {
104958
- return this.client.post(`${this.baseUrl}/register-token`, request, {
104959
- needsAccessToken: true
104960
- });
104957
+ // async registerToken(request: TokenRequest): Promise<TokenResponse> {
104958
+ // return this.client.post(`${this.baseUrl}/register-token`, request, {
104959
+ // needsAccessToken: true,
104960
+ // })
104961
+ // }
104962
+ /**
104963
+ * POST /v1/users/register-token
104964
+ *
104965
+ * 백엔드가 아래 중 어떤 스펙이든 동작하도록:
104966
+ * - 최소 요청형: { blockchainId, contractAddress }
104967
+ * - 풀 요청형: { blockchainId, contractAddress, name, symbol, decimals }
104968
+ *
104969
+ * 또한 응답이 아래 중 어떤 형태든 파싱:
104970
+ * - CoinResponse
104971
+ * - { coin: CoinResponse }
104972
+ * - { data: CoinResponse }
104973
+ */
104974
+ // UserClient 클래스 내부의 registerToken()을 아래로 교체
104975
+ async registerToken(req) {
104976
+ const blockchainId = req.blockchainId ?? req.networkId;
104977
+ const contractAddress = String(
104978
+ req.contractAddress ?? req.tokenAddress ?? req.address ?? ""
104979
+ ).trim().toLowerCase();
104980
+ const name2 = req.name;
104981
+ const symbol = req.symbol;
104982
+ const decimals = req.decimals;
104983
+ const candidates = [
104984
+ // 1) 주소만 받는 케이스
104985
+ { blockchainId, contractAddress },
104986
+ { blockchainId, tokenAddress: contractAddress },
104987
+ { blockchainId, address: contractAddress },
104988
+ // 2) 메타까지 받는 케이스
104989
+ ...name2 && symbol && typeof decimals === "number" ? [
104990
+ { blockchainId, contractAddress, name: name2, symbol, decimals },
104991
+ {
104992
+ blockchainId,
104993
+ tokenAddress: contractAddress,
104994
+ name: name2,
104995
+ symbol,
104996
+ decimals
104997
+ },
104998
+ { blockchainId, address: contractAddress, name: name2, symbol, decimals }
104999
+ ] : [],
105000
+ // 3) 파라미터명이 networkId로 바뀐 케이스
105001
+ { networkId: blockchainId, contractAddress },
105002
+ ...name2 && symbol && typeof decimals === "number" ? [{ networkId: blockchainId, contractAddress, name: name2, symbol, decimals }] : []
105003
+ ];
105004
+ let lastError = null;
105005
+ for (const body of candidates) {
105006
+ try {
105007
+ const res = await this.postAuthed(
105008
+ "/v1/users/register-token",
105009
+ body
105010
+ );
105011
+ const coin = res?.coin ?? res?.data ?? res;
105012
+ if (coin?.contractAddress) {
105013
+ return {
105014
+ ...coin,
105015
+ contractAddress: String(coin.contractAddress).trim().toLowerCase(),
105016
+ decimals: typeof coin.decimals === "number" ? coin.decimals : Number(coin.decimals)
105017
+ };
105018
+ }
105019
+ } catch (e7) {
105020
+ lastError = e7;
105021
+ const status = e7?.status ?? e7?.response?.status ?? e7?.cause?.status ?? e7?.cause?.response?.status;
105022
+ if (status === 400 || status === 409 || status === 422) continue;
105023
+ throw e7;
105024
+ }
105025
+ }
105026
+ throw lastError ?? new Error("registerToken failed");
105027
+ }
105028
+ unwrapCoin(res) {
105029
+ if (!res) return null;
105030
+ if (res.coin) return res.coin;
105031
+ if (res.data) return res.data;
105032
+ return res;
105033
+ }
105034
+ normalizeAddress(address) {
105035
+ return (address ?? "").trim().toLowerCase();
105036
+ }
105037
+ extractStatus(e7) {
105038
+ return e7?.status ?? e7?.response?.status ?? e7?.cause?.status ?? e7?.cause?.response?.status;
104961
105039
  }
104962
105040
  async getRegisteredCoins(blockchainId) {
104963
105041
  return this.client.get(
@@ -104965,6 +105043,32 @@ var UserClient = class {
104965
105043
  { needsAccessToken: true }
104966
105044
  );
104967
105045
  }
105046
+ // UserClient 클래스 내부에 추가
105047
+ async postAuthed(path, body) {
105048
+ const httpAny = this.client;
105049
+ const headers = (typeof httpAny.getAuthHeaders === "function" ? await httpAny.getAuthHeaders() : typeof httpAny.getHeaders === "function" ? await httpAny.getHeaders() : void 0) ?? void 0;
105050
+ const attempts = [];
105051
+ if (typeof httpAny.post === "function") {
105052
+ attempts.push(() => httpAny.post(path, body, headers));
105053
+ attempts.push(() => httpAny.post(path, body, { headers }));
105054
+ attempts.push(() => httpAny.post(path, body));
105055
+ }
105056
+ if (typeof httpAny.request === "function") {
105057
+ attempts.push(
105058
+ () => httpAny.request({ method: "POST", path, body, headers })
105059
+ );
105060
+ attempts.push(() => httpAny.request("POST", path, body, headers));
105061
+ }
105062
+ let lastError = null;
105063
+ for (const fn of attempts) {
105064
+ try {
105065
+ return await fn();
105066
+ } catch (e7) {
105067
+ lastError = e7;
105068
+ }
105069
+ }
105070
+ throw lastError ?? new Error(`POST ${path} failed`);
105071
+ }
104968
105072
  };
104969
105073
 
104970
105074
  // src/clients/api/wallets.ts