@weblock-wallet/sdk 0.1.47 → 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 CHANGED
@@ -104995,10 +104995,102 @@ 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
+ 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(
@@ -106061,9 +106153,44 @@ var AssetService = class extends EventEmitter {
106061
106153
  checkStatus();
106062
106154
  }
106063
106155
  async addToken(params) {
106156
+ const hasMeta = !!params.name && !!params.symbol && typeof params.decimals === "number";
106157
+ const meta = hasMeta ? {
106158
+ name: params.name,
106159
+ symbol: params.symbol,
106160
+ decimals: params.decimals
106161
+ } : await this.getTokenInfo({
106162
+ networkId: params.networkId,
106163
+ tokenAddress: params.address
106164
+ });
106165
+ try {
106166
+ await this.userClient.registerToken({
106167
+ blockchainId: params.networkId,
106168
+ contractAddress: params.address,
106169
+ name: meta.name,
106170
+ symbol: meta.symbol,
106171
+ decimals: meta.decimals
106172
+ });
106173
+ } catch (error) {
106174
+ throw new SDKError(
106175
+ "Failed to register token",
106176
+ "REQUEST_FAILED" /* REQUEST_FAILED */,
106177
+ error
106178
+ );
106179
+ }
106064
106180
  const key = `${this.orgHost}:token:${params.networkId}:${params.address}`;
106065
106181
  await LocalForage.save(key, params);
106066
106182
  }
106183
+ async getRegisteredCoins(networkId) {
106184
+ try {
106185
+ return await this.userClient.getRegisteredCoins(networkId);
106186
+ } catch (error) {
106187
+ throw new SDKError(
106188
+ "Failed to get registered tokens",
106189
+ "REQUEST_FAILED" /* REQUEST_FAILED */,
106190
+ error
106191
+ );
106192
+ }
106193
+ }
106067
106194
  async getTokenBalance(params) {
106068
106195
  try {
106069
106196
  const chainId = await this.resolveChainId(params.networkId);
@@ -106175,6 +106302,19 @@ var AssetService = class extends EventEmitter {
106175
106302
  const key = `${this.orgHost}:nft:${params.networkId}:${params.address}`;
106176
106303
  await LocalForage.save(key, params);
106177
106304
  }
106305
+ // async checkSecurityTokenCompliance(params: {
106306
+ // networkId: string
106307
+ // tokenAddress: string
106308
+ // from: string
106309
+ // to: string
106310
+ // amount: string
106311
+ // }): Promise<{
106312
+ // canTransfer: boolean
106313
+ // reasons?: string[]
106314
+ // }> {
106315
+ // // TODO: Implement security token compliance check
106316
+ // return { canTransfer: true }
106317
+ // }
106178
106318
  };
106179
106319
 
106180
106320
  // src/core/internal.ts
@@ -106192,7 +106332,6 @@ var InternalCoreImpl = class {
106192
106332
  getAddress: () => this.walletService.getAddress(),
106193
106333
  create: (password) => this.walletService.create(password),
106194
106334
  retrieveWallet: (password) => this.walletService.retrieveWallet(password),
106195
- resetPin: (newPassword) => this.walletService.resetPin(newPassword),
106196
106335
  getBalance: (address, chainId) => this.walletService.getBalance(address, chainId),
106197
106336
  getTokenBalance: (tokenAddress, walletAddress, chainId) => this.walletService.getTokenBalance(tokenAddress, walletAddress, chainId),
106198
106337
  sendTransaction: (params) => this.walletService.sendTransaction(params),
@@ -106214,25 +106353,27 @@ var InternalCoreImpl = class {
106214
106353
  };
106215
106354
  this.asset = {
106216
106355
  transfer: (params) => this.assetService.transfer(params),
106217
- /**
106218
- * 타입 정합성:
106219
- * - InternalCore는 decimals?: number
106220
- * - 기존 AssetService 내부 구현이 decimals를 string으로 받는 경우가 있어,
106221
- * 여기서 안전하게 string으로 변환해서 전달합니다.
106222
- */
106223
- addToken: (params) => this.assetService.addToken({
106224
- ...params,
106225
- decimals: typeof params.decimals === "number" ? String(params.decimals) : void 0
106226
- }),
106356
+ addToken: (params) => this.assetService.addToken(params),
106357
+ // New ERC20 methods
106227
106358
  getTokenBalance: (params) => this.assetService.getTokenBalance(params),
106228
106359
  approveToken: (params) => this.assetService.approveToken(params),
106229
106360
  getAllowance: (params) => this.assetService.getAllowance(params),
106361
+ // getTokenInfo: (params: TokenInfoParams) =>
106362
+ // this.assetService.getTokenInfo(params),
106230
106363
  addNFTCollection: (params) => this.assetService.addNFTCollection(params),
106364
+ // checkSecurityTokenCompliance: (params: {
106365
+ // networkId: string
106366
+ // tokenAddress: string
106367
+ // from: string
106368
+ // to: string
106369
+ // amount: string
106370
+ // }) => this.assetService.checkSecurityTokenCompliance(params),
106231
106371
  on: (event, listener) => this.assetService.on(event, listener),
106232
106372
  off: (event, listener) => this.assetService.off(event, listener),
106233
106373
  getTokenInfo: (params) => this.assetService.getTokenInfo(params),
106234
106374
  registerToken: (params) => this.assetService.registerToken(params),
106235
- getTokenFullInfo: (params) => this.assetService.getTokenFullInfo(params)
106375
+ getTokenFullInfo: (params) => this.assetService.getTokenFullInfo(params),
106376
+ getRegisteredCoins: (networkId) => this.assetService.getRegisteredCoins(networkId)
106236
106377
  };
106237
106378
  const httpClient = new HttpClient(options);
106238
106379
  const firebase = new FirebaseAuth(options);
@@ -106387,6 +106528,34 @@ var WalletModule = class {
106387
106528
  network.chainId
106388
106529
  );
106389
106530
  console.log("\uCD5C\uADFC \uD2B8\uB79C\uC7AD\uC158:", latestTransaction);
106531
+ let tokens = [];
106532
+ try {
106533
+ const registered = await this.core.asset.getRegisteredCoins(network.id);
106534
+ if (registered?.length) {
106535
+ const unique = new Map(
106536
+ registered.map((c5) => [c5.contractAddress.toLowerCase(), c5])
106537
+ );
106538
+ tokens = await Promise.all(
106539
+ Array.from(unique.values()).map(async (coin) => {
106540
+ const full = await this.core.asset.getTokenFullInfo({
106541
+ networkId: network.id,
106542
+ tokenAddress: coin.contractAddress,
106543
+ walletAddress: address
106544
+ });
106545
+ return {
106546
+ ...full,
106547
+ address: coin.contractAddress,
106548
+ name: coin.name ?? full.name,
106549
+ symbol: coin.symbol ?? full.symbol,
106550
+ decimals: typeof coin.decimals === "number" ? coin.decimals : full.decimals
106551
+ };
106552
+ })
106553
+ );
106554
+ }
106555
+ } catch (e7) {
106556
+ console.warn("Registered token load failed:", e7);
106557
+ tokens = [];
106558
+ }
106390
106559
  const walletInfo = {
106391
106560
  address,
106392
106561
  network: {
@@ -106399,40 +106568,7 @@ var WalletModule = class {
106399
106568
  balance: nativeBalance,
106400
106569
  decimals: 18
106401
106570
  },
106402
- tokens: [
106403
- // {
106404
- // symbol: rbtBalance.symbol,
106405
- // name: 'Real-estate Backed Token',
106406
- // address: '0xB10536cC40Cb6E6415f70d3a4C1AF7Fa638AE829',
106407
- // balance: rbtBalance,
106408
- // decimals: rbtBalance.decimals,
106409
- // totalSupply: rbtBalance,
106410
- // },
106411
- // {
106412
- // symbol: usdrBalance.symbol,
106413
- // name: 'USD Real-estate',
106414
- // address: '0x8d335fe5B30e27F2B21F057a4766cf4BB8c30785',
106415
- // balance: usdrBalance,
106416
- // decimals: usdrBalance.decimals,
106417
- // totalSupply: usdrBalance,
106418
- // },
106419
- // {
106420
- // symbol: wftBalance.symbol,
106421
- // name: 'WeBlock Foundation Token',
106422
- // address: '0x6fa62Eda03956ef4E54f3C8597E8c3f3bE40A45B',
106423
- // balance: wftBalance,
106424
- // decimals: wftBalance.decimals,
106425
- // totalSupply: wftBalance,
106426
- // },
106427
- // {
106428
- // symbol: usdtBalance.symbol,
106429
- // name: 'USD Tether',
106430
- // address: '0xfF54B9ebe777f528E64C74bc95c68433B7546038',
106431
- // balance: usdtBalance,
106432
- // decimals: usdtBalance.decimals,
106433
- // totalSupply: usdtBalance,
106434
- // },
106435
- ],
106571
+ tokens,
106436
106572
  nfts: [],
106437
106573
  securities: []
106438
106574
  },