@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.js CHANGED
@@ -104954,10 +104954,102 @@ 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
+ 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(
@@ -106020,9 +106112,44 @@ var AssetService = class extends EventEmitter {
106020
106112
  checkStatus();
106021
106113
  }
106022
106114
  async addToken(params) {
106115
+ const hasMeta = !!params.name && !!params.symbol && typeof params.decimals === "number";
106116
+ const meta = hasMeta ? {
106117
+ name: params.name,
106118
+ symbol: params.symbol,
106119
+ decimals: params.decimals
106120
+ } : await this.getTokenInfo({
106121
+ networkId: params.networkId,
106122
+ tokenAddress: params.address
106123
+ });
106124
+ try {
106125
+ await this.userClient.registerToken({
106126
+ blockchainId: params.networkId,
106127
+ contractAddress: params.address,
106128
+ name: meta.name,
106129
+ symbol: meta.symbol,
106130
+ decimals: meta.decimals
106131
+ });
106132
+ } catch (error) {
106133
+ throw new SDKError(
106134
+ "Failed to register token",
106135
+ "REQUEST_FAILED" /* REQUEST_FAILED */,
106136
+ error
106137
+ );
106138
+ }
106023
106139
  const key = `${this.orgHost}:token:${params.networkId}:${params.address}`;
106024
106140
  await LocalForage.save(key, params);
106025
106141
  }
106142
+ async getRegisteredCoins(networkId) {
106143
+ try {
106144
+ return await this.userClient.getRegisteredCoins(networkId);
106145
+ } catch (error) {
106146
+ throw new SDKError(
106147
+ "Failed to get registered tokens",
106148
+ "REQUEST_FAILED" /* REQUEST_FAILED */,
106149
+ error
106150
+ );
106151
+ }
106152
+ }
106026
106153
  async getTokenBalance(params) {
106027
106154
  try {
106028
106155
  const chainId = await this.resolveChainId(params.networkId);
@@ -106134,6 +106261,19 @@ var AssetService = class extends EventEmitter {
106134
106261
  const key = `${this.orgHost}:nft:${params.networkId}:${params.address}`;
106135
106262
  await LocalForage.save(key, params);
106136
106263
  }
106264
+ // async checkSecurityTokenCompliance(params: {
106265
+ // networkId: string
106266
+ // tokenAddress: string
106267
+ // from: string
106268
+ // to: string
106269
+ // amount: string
106270
+ // }): Promise<{
106271
+ // canTransfer: boolean
106272
+ // reasons?: string[]
106273
+ // }> {
106274
+ // // TODO: Implement security token compliance check
106275
+ // return { canTransfer: true }
106276
+ // }
106137
106277
  };
106138
106278
 
106139
106279
  // src/core/internal.ts
@@ -106151,7 +106291,6 @@ var InternalCoreImpl = class {
106151
106291
  getAddress: () => this.walletService.getAddress(),
106152
106292
  create: (password) => this.walletService.create(password),
106153
106293
  retrieveWallet: (password) => this.walletService.retrieveWallet(password),
106154
- resetPin: (newPassword) => this.walletService.resetPin(newPassword),
106155
106294
  getBalance: (address, chainId) => this.walletService.getBalance(address, chainId),
106156
106295
  getTokenBalance: (tokenAddress, walletAddress, chainId) => this.walletService.getTokenBalance(tokenAddress, walletAddress, chainId),
106157
106296
  sendTransaction: (params) => this.walletService.sendTransaction(params),
@@ -106173,25 +106312,27 @@ var InternalCoreImpl = class {
106173
106312
  };
106174
106313
  this.asset = {
106175
106314
  transfer: (params) => this.assetService.transfer(params),
106176
- /**
106177
- * 타입 정합성:
106178
- * - InternalCore는 decimals?: number
106179
- * - 기존 AssetService 내부 구현이 decimals를 string으로 받는 경우가 있어,
106180
- * 여기서 안전하게 string으로 변환해서 전달합니다.
106181
- */
106182
- addToken: (params) => this.assetService.addToken({
106183
- ...params,
106184
- decimals: typeof params.decimals === "number" ? String(params.decimals) : void 0
106185
- }),
106315
+ addToken: (params) => this.assetService.addToken(params),
106316
+ // New ERC20 methods
106186
106317
  getTokenBalance: (params) => this.assetService.getTokenBalance(params),
106187
106318
  approveToken: (params) => this.assetService.approveToken(params),
106188
106319
  getAllowance: (params) => this.assetService.getAllowance(params),
106320
+ // getTokenInfo: (params: TokenInfoParams) =>
106321
+ // this.assetService.getTokenInfo(params),
106189
106322
  addNFTCollection: (params) => this.assetService.addNFTCollection(params),
106323
+ // checkSecurityTokenCompliance: (params: {
106324
+ // networkId: string
106325
+ // tokenAddress: string
106326
+ // from: string
106327
+ // to: string
106328
+ // amount: string
106329
+ // }) => this.assetService.checkSecurityTokenCompliance(params),
106190
106330
  on: (event, listener) => this.assetService.on(event, listener),
106191
106331
  off: (event, listener) => this.assetService.off(event, listener),
106192
106332
  getTokenInfo: (params) => this.assetService.getTokenInfo(params),
106193
106333
  registerToken: (params) => this.assetService.registerToken(params),
106194
- getTokenFullInfo: (params) => this.assetService.getTokenFullInfo(params)
106334
+ getTokenFullInfo: (params) => this.assetService.getTokenFullInfo(params),
106335
+ getRegisteredCoins: (networkId) => this.assetService.getRegisteredCoins(networkId)
106195
106336
  };
106196
106337
  const httpClient = new HttpClient(options);
106197
106338
  const firebase = new FirebaseAuth(options);
@@ -106346,6 +106487,34 @@ var WalletModule = class {
106346
106487
  network.chainId
106347
106488
  );
106348
106489
  console.log("\uCD5C\uADFC \uD2B8\uB79C\uC7AD\uC158:", latestTransaction);
106490
+ let tokens = [];
106491
+ try {
106492
+ const registered = await this.core.asset.getRegisteredCoins(network.id);
106493
+ if (registered?.length) {
106494
+ const unique = new Map(
106495
+ registered.map((c5) => [c5.contractAddress.toLowerCase(), c5])
106496
+ );
106497
+ tokens = await Promise.all(
106498
+ Array.from(unique.values()).map(async (coin) => {
106499
+ const full = await this.core.asset.getTokenFullInfo({
106500
+ networkId: network.id,
106501
+ tokenAddress: coin.contractAddress,
106502
+ walletAddress: address
106503
+ });
106504
+ return {
106505
+ ...full,
106506
+ address: coin.contractAddress,
106507
+ name: coin.name ?? full.name,
106508
+ symbol: coin.symbol ?? full.symbol,
106509
+ decimals: typeof coin.decimals === "number" ? coin.decimals : full.decimals
106510
+ };
106511
+ })
106512
+ );
106513
+ }
106514
+ } catch (e7) {
106515
+ console.warn("Registered token load failed:", e7);
106516
+ tokens = [];
106517
+ }
106349
106518
  const walletInfo = {
106350
106519
  address,
106351
106520
  network: {
@@ -106358,40 +106527,7 @@ var WalletModule = class {
106358
106527
  balance: nativeBalance,
106359
106528
  decimals: 18
106360
106529
  },
106361
- tokens: [
106362
- // {
106363
- // symbol: rbtBalance.symbol,
106364
- // name: 'Real-estate Backed Token',
106365
- // address: '0xB10536cC40Cb6E6415f70d3a4C1AF7Fa638AE829',
106366
- // balance: rbtBalance,
106367
- // decimals: rbtBalance.decimals,
106368
- // totalSupply: rbtBalance,
106369
- // },
106370
- // {
106371
- // symbol: usdrBalance.symbol,
106372
- // name: 'USD Real-estate',
106373
- // address: '0x8d335fe5B30e27F2B21F057a4766cf4BB8c30785',
106374
- // balance: usdrBalance,
106375
- // decimals: usdrBalance.decimals,
106376
- // totalSupply: usdrBalance,
106377
- // },
106378
- // {
106379
- // symbol: wftBalance.symbol,
106380
- // name: 'WeBlock Foundation Token',
106381
- // address: '0x6fa62Eda03956ef4E54f3C8597E8c3f3bE40A45B',
106382
- // balance: wftBalance,
106383
- // decimals: wftBalance.decimals,
106384
- // totalSupply: wftBalance,
106385
- // },
106386
- // {
106387
- // symbol: usdtBalance.symbol,
106388
- // name: 'USD Tether',
106389
- // address: '0xfF54B9ebe777f528E64C74bc95c68433B7546038',
106390
- // balance: usdtBalance,
106391
- // decimals: usdtBalance.decimals,
106392
- // totalSupply: usdtBalance,
106393
- // },
106394
- ],
106530
+ tokens,
106395
106531
  nfts: [],
106396
106532
  securities: []
106397
106533
  },