@weblock-wallet/sdk 0.1.48 → 0.1.49
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 +96 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +96 -4
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -104995,10 +104995,102 @@ var UserClient = class {
|
|
|
104995
104995
|
needsAccessToken: true
|
|
104996
104996
|
});
|
|
104997
104997
|
}
|
|
104998
|
-
async registerToken(request) {
|
|
104999
|
-
|
|
105000
|
-
|
|
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
|
+
async registerToken(req) {
|
|
105016
|
+
const blockchainId = req.blockchainId;
|
|
105017
|
+
const contractAddress = this.normalizeAddress(req.contractAddress);
|
|
105018
|
+
const name2 = req.name;
|
|
105019
|
+
const symbol = req.symbol;
|
|
105020
|
+
const decimals = req.decimals;
|
|
105021
|
+
const candidates = [
|
|
105022
|
+
// 1) 최신 스펙으로 바뀌며 "주소만" 받는 경우
|
|
105023
|
+
{ blockchainId, contractAddress },
|
|
105024
|
+
// 2) 필드명이 tokenAddress / address로 바뀐 경우
|
|
105025
|
+
{ blockchainId, tokenAddress: contractAddress },
|
|
105026
|
+
{ blockchainId, address: contractAddress },
|
|
105027
|
+
// 3) 구 스펙(메타 포함) 유지/필요한 경우
|
|
105028
|
+
...name2 && symbol && typeof decimals === "number" ? [
|
|
105029
|
+
{ blockchainId, contractAddress, name: name2, symbol, decimals },
|
|
105030
|
+
{
|
|
105031
|
+
blockchainId,
|
|
105032
|
+
tokenAddress: contractAddress,
|
|
105033
|
+
name: name2,
|
|
105034
|
+
symbol,
|
|
105035
|
+
decimals
|
|
105036
|
+
},
|
|
105037
|
+
{ blockchainId, address: contractAddress, name: name2, symbol, decimals }
|
|
105038
|
+
] : [],
|
|
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 }]
|
|
105056
|
+
];
|
|
105057
|
+
let lastError = null;
|
|
105058
|
+
for (const body of candidates) {
|
|
105059
|
+
try {
|
|
105060
|
+
const res = await this.client.post(
|
|
105061
|
+
`${this.baseUrl}/register-token`,
|
|
105062
|
+
body
|
|
105063
|
+
);
|
|
105064
|
+
const coin = this.unwrapCoin(res);
|
|
105065
|
+
if (!coin?.contractAddress) {
|
|
105066
|
+
continue;
|
|
105067
|
+
}
|
|
105068
|
+
return {
|
|
105069
|
+
...coin,
|
|
105070
|
+
contractAddress: this.normalizeAddress(coin.contractAddress),
|
|
105071
|
+
decimals: Number(coin.decimals)
|
|
105072
|
+
};
|
|
105073
|
+
} catch (e7) {
|
|
105074
|
+
lastError = e7;
|
|
105075
|
+
const status = this.extractStatus(e7);
|
|
105076
|
+
if (status === 400 || status === 422) continue;
|
|
105077
|
+
if (status === 409) continue;
|
|
105078
|
+
throw e7;
|
|
105079
|
+
}
|
|
105080
|
+
}
|
|
105081
|
+
throw lastError ?? new Error("registerToken failed");
|
|
105082
|
+
}
|
|
105083
|
+
unwrapCoin(res) {
|
|
105084
|
+
if (!res) return null;
|
|
105085
|
+
if (res.coin) return res.coin;
|
|
105086
|
+
if (res.data) return res.data;
|
|
105087
|
+
return res;
|
|
105088
|
+
}
|
|
105089
|
+
normalizeAddress(address) {
|
|
105090
|
+
return (address ?? "").trim().toLowerCase();
|
|
105091
|
+
}
|
|
105092
|
+
extractStatus(e7) {
|
|
105093
|
+
return e7?.status ?? e7?.response?.status ?? e7?.cause?.status ?? e7?.cause?.response?.status;
|
|
105002
105094
|
}
|
|
105003
105095
|
async getRegisteredCoins(blockchainId) {
|
|
105004
105096
|
return this.client.get(
|