@weblock-wallet/sdk 0.1.46 → 0.1.47
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 +51 -17
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +51 -17
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -105785,8 +105785,51 @@ var AssetService = class extends EventEmitter {
|
|
|
105785
105785
|
this.networkService = networkService;
|
|
105786
105786
|
this.userClient = userClient;
|
|
105787
105787
|
this.orgHost = orgHost;
|
|
105788
|
+
this.chainIdCache = /* @__PURE__ */ new Map();
|
|
105788
105789
|
this.erc20Interface = new Interface2(ERC20_ABI2);
|
|
105789
105790
|
}
|
|
105791
|
+
/**
|
|
105792
|
+
* Resolve a user-facing networkId (blockchainId) into an EVM chainId for /v1/rpcs.
|
|
105793
|
+
*
|
|
105794
|
+
* Notes
|
|
105795
|
+
* - Many SDK APIs use `networkId` to mean the registered blockchain id (UUID).
|
|
105796
|
+
* - The wallet-rpc endpoint (/v1/rpcs) expects `chainId`.
|
|
105797
|
+
* - Some older call-sites may pass chainId as a string; we support both.
|
|
105798
|
+
*/
|
|
105799
|
+
async resolveChainId(networkId) {
|
|
105800
|
+
const trimmed = (networkId ?? "").trim();
|
|
105801
|
+
const cached = this.chainIdCache.get(trimmed);
|
|
105802
|
+
if (cached) return cached;
|
|
105803
|
+
const numeric = Number(trimmed);
|
|
105804
|
+
if (!Number.isNaN(numeric) && Number.isFinite(numeric) && numeric > 0) {
|
|
105805
|
+
this.chainIdCache.set(trimmed, numeric);
|
|
105806
|
+
return numeric;
|
|
105807
|
+
}
|
|
105808
|
+
try {
|
|
105809
|
+
const current = await this.networkService.getCurrentNetwork();
|
|
105810
|
+
if (current && current.id === trimmed) {
|
|
105811
|
+
this.chainIdCache.set(trimmed, current.chainId);
|
|
105812
|
+
return current.chainId;
|
|
105813
|
+
}
|
|
105814
|
+
if (current && String(current.chainId) === trimmed) {
|
|
105815
|
+
this.chainIdCache.set(trimmed, current.chainId);
|
|
105816
|
+
return current.chainId;
|
|
105817
|
+
}
|
|
105818
|
+
} catch {
|
|
105819
|
+
}
|
|
105820
|
+
const networks = await this.networkService.getRegisteredNetworks();
|
|
105821
|
+
const found = networks.find((n5) => n5.id === trimmed);
|
|
105822
|
+
if (found) {
|
|
105823
|
+
this.chainIdCache.set(trimmed, found.chainId);
|
|
105824
|
+
return found.chainId;
|
|
105825
|
+
}
|
|
105826
|
+
const foundByChainId = networks.find((n5) => String(n5.chainId) === trimmed);
|
|
105827
|
+
if (foundByChainId) {
|
|
105828
|
+
this.chainIdCache.set(trimmed, foundByChainId.chainId);
|
|
105829
|
+
return foundByChainId.chainId;
|
|
105830
|
+
}
|
|
105831
|
+
throw new SDKError("Invalid network", "INVALID_NETWORK" /* INVALID_NETWORK */);
|
|
105832
|
+
}
|
|
105790
105833
|
async getTokenInfo(params) {
|
|
105791
105834
|
try {
|
|
105792
105835
|
const [name2, symbol, decimals] = await Promise.all([
|
|
@@ -105982,11 +106025,12 @@ var AssetService = class extends EventEmitter {
|
|
|
105982
106025
|
}
|
|
105983
106026
|
async getTokenBalance(params) {
|
|
105984
106027
|
try {
|
|
106028
|
+
const chainId = await this.resolveChainId(params.networkId);
|
|
105985
106029
|
const data = this.erc20Interface.encodeFunctionData("balanceOf", [
|
|
105986
106030
|
params.walletAddress
|
|
105987
106031
|
]);
|
|
105988
106032
|
const response = await this.rpcClient.sendRpc({
|
|
105989
|
-
chainId
|
|
106033
|
+
chainId,
|
|
105990
106034
|
method: "eth_call" /* ETH_CALL */,
|
|
105991
106035
|
params: [
|
|
105992
106036
|
{
|
|
@@ -106007,12 +106051,13 @@ var AssetService = class extends EventEmitter {
|
|
|
106007
106051
|
}
|
|
106008
106052
|
async approveToken(params) {
|
|
106009
106053
|
try {
|
|
106054
|
+
const chainId = await this.resolveChainId(params.networkId);
|
|
106010
106055
|
const data = this.erc20Interface.encodeFunctionData("approve", [
|
|
106011
106056
|
params.spender,
|
|
106012
106057
|
params.amount
|
|
106013
106058
|
]);
|
|
106014
106059
|
const response = await this.rpcClient.sendRpc({
|
|
106015
|
-
chainId
|
|
106060
|
+
chainId,
|
|
106016
106061
|
method: "eth_sendRawTransaction" /* ETH_SEND_RAW_TRANSACTION */,
|
|
106017
106062
|
params: [
|
|
106018
106063
|
{
|
|
@@ -106032,12 +106077,13 @@ var AssetService = class extends EventEmitter {
|
|
|
106032
106077
|
}
|
|
106033
106078
|
async getAllowance(params) {
|
|
106034
106079
|
try {
|
|
106080
|
+
const chainId = await this.resolveChainId(params.networkId);
|
|
106035
106081
|
const data = this.erc20Interface.encodeFunctionData("allowance", [
|
|
106036
106082
|
params.owner,
|
|
106037
106083
|
params.spender
|
|
106038
106084
|
]);
|
|
106039
106085
|
const response = await this.rpcClient.sendRpc({
|
|
106040
|
-
chainId
|
|
106086
|
+
chainId,
|
|
106041
106087
|
method: "eth_call" /* ETH_CALL */,
|
|
106042
106088
|
params: [
|
|
106043
106089
|
{
|
|
@@ -106057,9 +106103,10 @@ var AssetService = class extends EventEmitter {
|
|
|
106057
106103
|
}
|
|
106058
106104
|
}
|
|
106059
106105
|
async callTokenMethod(tokenAddress, networkId, method) {
|
|
106106
|
+
const chainId = await this.resolveChainId(networkId);
|
|
106060
106107
|
const data = this.erc20Interface.encodeFunctionData(method, []);
|
|
106061
106108
|
const response = await this.rpcClient.sendRpc({
|
|
106062
|
-
chainId
|
|
106109
|
+
chainId,
|
|
106063
106110
|
method: "eth_call" /* ETH_CALL */,
|
|
106064
106111
|
params: [
|
|
106065
106112
|
{
|
|
@@ -106087,19 +106134,6 @@ var AssetService = class extends EventEmitter {
|
|
|
106087
106134
|
const key = `${this.orgHost}:nft:${params.networkId}:${params.address}`;
|
|
106088
106135
|
await LocalForage.save(key, params);
|
|
106089
106136
|
}
|
|
106090
|
-
// async checkSecurityTokenCompliance(params: {
|
|
106091
|
-
// networkId: string
|
|
106092
|
-
// tokenAddress: string
|
|
106093
|
-
// from: string
|
|
106094
|
-
// to: string
|
|
106095
|
-
// amount: string
|
|
106096
|
-
// }): Promise<{
|
|
106097
|
-
// canTransfer: boolean
|
|
106098
|
-
// reasons?: string[]
|
|
106099
|
-
// }> {
|
|
106100
|
-
// // TODO: Implement security token compliance check
|
|
106101
|
-
// return { canTransfer: true }
|
|
106102
|
-
// }
|
|
106103
106137
|
};
|
|
106104
106138
|
|
|
106105
106139
|
// src/core/internal.ts
|