@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 +50 -35
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +50 -35
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -104971,19 +104971,21 @@ var UserClient = class {
|
|
|
104971
104971
|
* - { coin: CoinResponse }
|
|
104972
104972
|
* - { data: CoinResponse }
|
|
104973
104973
|
*/
|
|
104974
|
+
// UserClient 클래스 내부의 registerToken()을 아래로 교체
|
|
104974
104975
|
async registerToken(req) {
|
|
104975
|
-
const blockchainId = req.blockchainId;
|
|
104976
|
-
const contractAddress =
|
|
104976
|
+
const blockchainId = req.blockchainId ?? req.networkId;
|
|
104977
|
+
const contractAddress = String(
|
|
104978
|
+
req.contractAddress ?? req.tokenAddress ?? req.address ?? ""
|
|
104979
|
+
).trim().toLowerCase();
|
|
104977
104980
|
const name2 = req.name;
|
|
104978
104981
|
const symbol = req.symbol;
|
|
104979
104982
|
const decimals = req.decimals;
|
|
104980
104983
|
const candidates = [
|
|
104981
|
-
// 1)
|
|
104984
|
+
// 1) 주소만 받는 케이스
|
|
104982
104985
|
{ blockchainId, contractAddress },
|
|
104983
|
-
// 2) 필드명이 tokenAddress / address로 바뀐 경우
|
|
104984
104986
|
{ blockchainId, tokenAddress: contractAddress },
|
|
104985
104987
|
{ blockchainId, address: contractAddress },
|
|
104986
|
-
//
|
|
104988
|
+
// 2) 메타까지 받는 케이스
|
|
104987
104989
|
...name2 && symbol && typeof decimals === "number" ? [
|
|
104988
104990
|
{ blockchainId, contractAddress, name: name2, symbol, decimals },
|
|
104989
104991
|
{
|
|
@@ -104995,45 +104997,32 @@ var UserClient = class {
|
|
|
104995
104997
|
},
|
|
104996
104998
|
{ blockchainId, address: contractAddress, name: name2, symbol, decimals }
|
|
104997
104999
|
] : [],
|
|
104998
|
-
//
|
|
104999
|
-
|
|
105000
|
-
|
|
105001
|
-
networkId: blockchainId,
|
|
105002
|
-
contractAddress,
|
|
105003
|
-
name: name2,
|
|
105004
|
-
symbol,
|
|
105005
|
-
decimals
|
|
105006
|
-
},
|
|
105007
|
-
{
|
|
105008
|
-
networkId: blockchainId,
|
|
105009
|
-
tokenAddress: contractAddress,
|
|
105010
|
-
name: name2,
|
|
105011
|
-
symbol,
|
|
105012
|
-
decimals
|
|
105013
|
-
}
|
|
105014
|
-
] : [{ networkId: blockchainId, contractAddress }]
|
|
105000
|
+
// 3) 파라미터명이 networkId로 바뀐 케이스
|
|
105001
|
+
{ networkId: blockchainId, contractAddress },
|
|
105002
|
+
...name2 && symbol && typeof decimals === "number" ? [{ networkId: blockchainId, contractAddress, name: name2, symbol, decimals }] : []
|
|
105015
105003
|
];
|
|
105016
105004
|
let lastError = null;
|
|
105017
105005
|
for (const body of candidates) {
|
|
105018
105006
|
try {
|
|
105019
105007
|
const res = await this.client.post(
|
|
105020
|
-
|
|
105021
|
-
body
|
|
105008
|
+
"/v1/users/register-token",
|
|
105009
|
+
body,
|
|
105010
|
+
{
|
|
105011
|
+
needsAccessToken: true
|
|
105012
|
+
}
|
|
105022
105013
|
);
|
|
105023
|
-
const coin =
|
|
105024
|
-
if (
|
|
105025
|
-
|
|
105014
|
+
const coin = res?.coin ?? res?.data ?? res;
|
|
105015
|
+
if (coin?.contractAddress) {
|
|
105016
|
+
return {
|
|
105017
|
+
...coin,
|
|
105018
|
+
contractAddress: String(coin.contractAddress).trim().toLowerCase(),
|
|
105019
|
+
decimals: typeof coin.decimals === "number" ? coin.decimals : Number(coin.decimals)
|
|
105020
|
+
};
|
|
105026
105021
|
}
|
|
105027
|
-
return {
|
|
105028
|
-
...coin,
|
|
105029
|
-
contractAddress: this.normalizeAddress(coin.contractAddress),
|
|
105030
|
-
decimals: Number(coin.decimals)
|
|
105031
|
-
};
|
|
105032
105022
|
} catch (e7) {
|
|
105033
105023
|
lastError = e7;
|
|
105034
|
-
const status =
|
|
105035
|
-
if (status === 400 || status === 422) continue;
|
|
105036
|
-
if (status === 409) continue;
|
|
105024
|
+
const status = e7?.status ?? e7?.response?.status ?? e7?.cause?.status ?? e7?.cause?.response?.status;
|
|
105025
|
+
if (status === 400 || status === 409 || status === 422) continue;
|
|
105037
105026
|
throw e7;
|
|
105038
105027
|
}
|
|
105039
105028
|
}
|
|
@@ -105057,6 +105046,32 @@ var UserClient = class {
|
|
|
105057
105046
|
{ needsAccessToken: true }
|
|
105058
105047
|
);
|
|
105059
105048
|
}
|
|
105049
|
+
// UserClient 클래스 내부에 추가
|
|
105050
|
+
async postAuthed(path, body) {
|
|
105051
|
+
const httpAny = this.client;
|
|
105052
|
+
const headers = (typeof httpAny.getAuthHeaders === "function" ? await httpAny.getAuthHeaders() : typeof httpAny.getHeaders === "function" ? await httpAny.getHeaders() : void 0) ?? void 0;
|
|
105053
|
+
const attempts = [];
|
|
105054
|
+
if (typeof httpAny.post === "function") {
|
|
105055
|
+
attempts.push(() => httpAny.post(path, body, headers));
|
|
105056
|
+
attempts.push(() => httpAny.post(path, body, { headers }));
|
|
105057
|
+
attempts.push(() => httpAny.post(path, body));
|
|
105058
|
+
}
|
|
105059
|
+
if (typeof httpAny.request === "function") {
|
|
105060
|
+
attempts.push(
|
|
105061
|
+
() => httpAny.request({ method: "POST", path, body, headers })
|
|
105062
|
+
);
|
|
105063
|
+
attempts.push(() => httpAny.request("POST", path, body, headers));
|
|
105064
|
+
}
|
|
105065
|
+
let lastError = null;
|
|
105066
|
+
for (const fn of attempts) {
|
|
105067
|
+
try {
|
|
105068
|
+
return await fn();
|
|
105069
|
+
} catch (e7) {
|
|
105070
|
+
lastError = e7;
|
|
105071
|
+
}
|
|
105072
|
+
}
|
|
105073
|
+
throw lastError ?? new Error(`POST ${path} failed`);
|
|
105074
|
+
}
|
|
105060
105075
|
};
|
|
105061
105076
|
|
|
105062
105077
|
// src/clients/api/wallets.ts
|