@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.js
CHANGED
|
@@ -104954,10 +104954,102 @@ var UserClient = class {
|
|
|
104954
104954
|
needsAccessToken: true
|
|
104955
104955
|
});
|
|
104956
104956
|
}
|
|
104957
|
-
async registerToken(request) {
|
|
104958
|
-
|
|
104959
|
-
|
|
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
|
+
async registerToken(req) {
|
|
104975
|
+
const blockchainId = req.blockchainId;
|
|
104976
|
+
const contractAddress = this.normalizeAddress(req.contractAddress);
|
|
104977
|
+
const name2 = req.name;
|
|
104978
|
+
const symbol = req.symbol;
|
|
104979
|
+
const decimals = req.decimals;
|
|
104980
|
+
const candidates = [
|
|
104981
|
+
// 1) 최신 스펙으로 바뀌며 "주소만" 받는 경우
|
|
104982
|
+
{ blockchainId, contractAddress },
|
|
104983
|
+
// 2) 필드명이 tokenAddress / address로 바뀐 경우
|
|
104984
|
+
{ blockchainId, tokenAddress: contractAddress },
|
|
104985
|
+
{ blockchainId, address: contractAddress },
|
|
104986
|
+
// 3) 구 스펙(메타 포함) 유지/필요한 경우
|
|
104987
|
+
...name2 && symbol && typeof decimals === "number" ? [
|
|
104988
|
+
{ blockchainId, contractAddress, name: name2, symbol, decimals },
|
|
104989
|
+
{
|
|
104990
|
+
blockchainId,
|
|
104991
|
+
tokenAddress: contractAddress,
|
|
104992
|
+
name: name2,
|
|
104993
|
+
symbol,
|
|
104994
|
+
decimals
|
|
104995
|
+
},
|
|
104996
|
+
{ blockchainId, address: contractAddress, name: name2, symbol, decimals }
|
|
104997
|
+
] : [],
|
|
104998
|
+
// 4) blockchainId가 networkId로 바뀐 경우
|
|
104999
|
+
...name2 && symbol && typeof decimals === "number" ? [
|
|
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 }]
|
|
105015
|
+
];
|
|
105016
|
+
let lastError = null;
|
|
105017
|
+
for (const body of candidates) {
|
|
105018
|
+
try {
|
|
105019
|
+
const res = await this.client.post(
|
|
105020
|
+
`${this.baseUrl}/register-token`,
|
|
105021
|
+
body
|
|
105022
|
+
);
|
|
105023
|
+
const coin = this.unwrapCoin(res);
|
|
105024
|
+
if (!coin?.contractAddress) {
|
|
105025
|
+
continue;
|
|
105026
|
+
}
|
|
105027
|
+
return {
|
|
105028
|
+
...coin,
|
|
105029
|
+
contractAddress: this.normalizeAddress(coin.contractAddress),
|
|
105030
|
+
decimals: Number(coin.decimals)
|
|
105031
|
+
};
|
|
105032
|
+
} catch (e7) {
|
|
105033
|
+
lastError = e7;
|
|
105034
|
+
const status = this.extractStatus(e7);
|
|
105035
|
+
if (status === 400 || status === 422) continue;
|
|
105036
|
+
if (status === 409) continue;
|
|
105037
|
+
throw e7;
|
|
105038
|
+
}
|
|
105039
|
+
}
|
|
105040
|
+
throw lastError ?? new Error("registerToken failed");
|
|
105041
|
+
}
|
|
105042
|
+
unwrapCoin(res) {
|
|
105043
|
+
if (!res) return null;
|
|
105044
|
+
if (res.coin) return res.coin;
|
|
105045
|
+
if (res.data) return res.data;
|
|
105046
|
+
return res;
|
|
105047
|
+
}
|
|
105048
|
+
normalizeAddress(address) {
|
|
105049
|
+
return (address ?? "").trim().toLowerCase();
|
|
105050
|
+
}
|
|
105051
|
+
extractStatus(e7) {
|
|
105052
|
+
return e7?.status ?? e7?.response?.status ?? e7?.cause?.status ?? e7?.cause?.response?.status;
|
|
104961
105053
|
}
|
|
104962
105054
|
async getRegisteredCoins(blockchainId) {
|
|
104963
105055
|
return this.client.get(
|