@weblock-wallet/sdk 0.1.56 → 0.1.57
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 +53 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +53 -9
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -104519,14 +104519,9 @@ var WalletService = class {
|
|
|
104519
104519
|
});
|
|
104520
104520
|
const network = await this.networkService.getCurrentNetwork();
|
|
104521
104521
|
const decimals = network?.decimals || DECIMALS.ETH;
|
|
104522
|
-
const formatted = TokenAmount.format(response.result, decimals);
|
|
104523
104522
|
return {
|
|
104524
104523
|
raw: response.result,
|
|
104525
|
-
|
|
104526
|
-
balanceWei: response.result,
|
|
104527
|
-
result: response.result,
|
|
104528
|
-
formatted,
|
|
104529
|
-
balance: formatted,
|
|
104524
|
+
formatted: TokenAmount.format(response.result, decimals),
|
|
104530
104525
|
decimals,
|
|
104531
104526
|
symbol: network?.symbol || "ETH"
|
|
104532
104527
|
};
|
|
@@ -104669,6 +104664,18 @@ var WalletService = class {
|
|
|
104669
104664
|
if (!from) {
|
|
104670
104665
|
throw new SDKError("Wallet not found", "WALLET_NOT_FOUND" /* WALLET_NOT_FOUND */);
|
|
104671
104666
|
}
|
|
104667
|
+
const toHexQuantity = (v5) => {
|
|
104668
|
+
if (v5 === void 0 || v5 === null) return "0x0";
|
|
104669
|
+
const s5 = String(v5).trim();
|
|
104670
|
+
if (!s5) return "0x0";
|
|
104671
|
+
if (s5.startsWith("0x") || s5.startsWith("0X")) return s5;
|
|
104672
|
+
try {
|
|
104673
|
+
const bi = BigInt(s5);
|
|
104674
|
+
return "0x" + bi.toString(16);
|
|
104675
|
+
} catch {
|
|
104676
|
+
return s5;
|
|
104677
|
+
}
|
|
104678
|
+
};
|
|
104672
104679
|
const [share1, share2] = await Promise.all([
|
|
104673
104680
|
this.walletClient.getWallet().then((wallet2) => wallet2.share1),
|
|
104674
104681
|
LocalForage.get(STORAGE_KEYS.share2(this.orgHost))
|
|
@@ -104683,6 +104690,20 @@ var WalletService = class {
|
|
|
104683
104690
|
const wallet = new import_ethers2.Wallet(privateKey);
|
|
104684
104691
|
const nonce = params.nonce ?? await this.getTransactionCount(from, params.chainId);
|
|
104685
104692
|
const gasPrice = params.gasPrice ?? await this.getGasPrice(params.chainId);
|
|
104693
|
+
let gasLimit = params.gasLimit;
|
|
104694
|
+
if (!gasLimit) {
|
|
104695
|
+
const est = await this.estimateGas(
|
|
104696
|
+
{
|
|
104697
|
+
from,
|
|
104698
|
+
to: params.to,
|
|
104699
|
+
value: toHexQuantity(params.value),
|
|
104700
|
+
data: params.data || "0x"
|
|
104701
|
+
},
|
|
104702
|
+
params.chainId
|
|
104703
|
+
);
|
|
104704
|
+
const buffered = Math.max(21e3, Math.ceil(est * 1.2));
|
|
104705
|
+
gasLimit = "0x" + buffered.toString(16);
|
|
104706
|
+
}
|
|
104686
104707
|
const signedTx = await wallet.signTransaction({
|
|
104687
104708
|
to: params.to,
|
|
104688
104709
|
value: params.value,
|
|
@@ -104690,7 +104711,7 @@ var WalletService = class {
|
|
|
104690
104711
|
chainId: params.chainId,
|
|
104691
104712
|
nonce,
|
|
104692
104713
|
gasPrice,
|
|
104693
|
-
gasLimit
|
|
104714
|
+
gasLimit
|
|
104694
104715
|
});
|
|
104695
104716
|
return this.sendRawTransaction(signedTx, params.chainId);
|
|
104696
104717
|
} catch (error) {
|
|
@@ -104749,11 +104770,34 @@ var NetworkService = class {
|
|
|
104749
104770
|
async switchNetwork(networkId) {
|
|
104750
104771
|
try {
|
|
104751
104772
|
const networks = await this.getRegisteredNetworks();
|
|
104752
|
-
const
|
|
104773
|
+
const key = String(networkId || "").trim();
|
|
104774
|
+
let network = networks.find((n5) => n5.id === key);
|
|
104775
|
+
if (!network) {
|
|
104776
|
+
const lower = key.toLowerCase();
|
|
104777
|
+
network = networks.find((n5) => (n5.name || "").toLowerCase() === lower);
|
|
104778
|
+
}
|
|
104779
|
+
if (!network && /^\d+$/.test(key)) {
|
|
104780
|
+
const chainId = Number(key);
|
|
104781
|
+
network = networks.find((n5) => n5.chainId === chainId);
|
|
104782
|
+
}
|
|
104783
|
+
if (!network) {
|
|
104784
|
+
const alias = key.toLowerCase();
|
|
104785
|
+
const aliasChainId = {
|
|
104786
|
+
fuji: 43113,
|
|
104787
|
+
avalanchefuji: 43113,
|
|
104788
|
+
"avalanche-fuji": 43113,
|
|
104789
|
+
avaxfuji: 43113,
|
|
104790
|
+
"avax-fuji": 43113
|
|
104791
|
+
};
|
|
104792
|
+
const chainId = aliasChainId[alias];
|
|
104793
|
+
if (chainId) {
|
|
104794
|
+
network = networks.find((n5) => n5.chainId === chainId);
|
|
104795
|
+
}
|
|
104796
|
+
}
|
|
104753
104797
|
if (!network) {
|
|
104754
104798
|
throw new SDKError("Network not found", "INVALID_NETWORK" /* INVALID_NETWORK */);
|
|
104755
104799
|
}
|
|
104756
|
-
await LocalForage.save(`${this.orgHost}:currentNetwork`,
|
|
104800
|
+
await LocalForage.save(`${this.orgHost}:currentNetwork`, network.id);
|
|
104757
104801
|
} catch (error) {
|
|
104758
104802
|
if (error instanceof SDKError) throw error;
|
|
104759
104803
|
throw new SDKError("Failed to switch network", "NETWORK_ERROR" /* NETWORK_ERROR */);
|