@weblock-wallet/sdk 0.1.56 → 0.1.58
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 +64 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +64 -11
- 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,19 +104690,42 @@ 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
|
+
try {
|
|
104696
|
+
const est = await this.estimateGas(
|
|
104697
|
+
{
|
|
104698
|
+
from,
|
|
104699
|
+
to: params.to,
|
|
104700
|
+
value: toHexQuantity(params.value),
|
|
104701
|
+
data: params.data || "0x"
|
|
104702
|
+
},
|
|
104703
|
+
params.chainId
|
|
104704
|
+
);
|
|
104705
|
+
const buffered = Math.max(21e3, Math.ceil(est * 1.2));
|
|
104706
|
+
gasLimit = "0x" + buffered.toString(16);
|
|
104707
|
+
} catch (e7) {
|
|
104708
|
+
const data = (params.data || "").toLowerCase();
|
|
104709
|
+
const fallback = data.startsWith("0x095ea7b3") ? 12e4 : data && data !== "0x" ? 8e5 : 21e3;
|
|
104710
|
+
gasLimit = "0x" + fallback.toString(16);
|
|
104711
|
+
}
|
|
104712
|
+
}
|
|
104686
104713
|
const signedTx = await wallet.signTransaction({
|
|
104687
104714
|
to: params.to,
|
|
104688
|
-
value: params.value,
|
|
104715
|
+
value: params.value ?? "0x0",
|
|
104689
104716
|
data: params.data || "0x",
|
|
104690
104717
|
chainId: params.chainId,
|
|
104691
104718
|
nonce,
|
|
104692
104719
|
gasPrice,
|
|
104693
|
-
gasLimit
|
|
104720
|
+
gasLimit
|
|
104694
104721
|
});
|
|
104695
104722
|
return this.sendRawTransaction(signedTx, params.chainId);
|
|
104696
104723
|
} catch (error) {
|
|
104724
|
+
const detail = String(
|
|
104725
|
+
error?.shortMessage ?? error?.reason ?? error?.message ?? ""
|
|
104726
|
+
).trim();
|
|
104697
104727
|
throw new SDKError(
|
|
104698
|
-
"Transaction failed",
|
|
104728
|
+
detail ? `Transaction failed: ${detail}` : "Transaction failed",
|
|
104699
104729
|
"TRANSACTION_FAILED" /* TRANSACTION_FAILED */,
|
|
104700
104730
|
error
|
|
104701
104731
|
);
|
|
@@ -104749,11 +104779,34 @@ var NetworkService = class {
|
|
|
104749
104779
|
async switchNetwork(networkId) {
|
|
104750
104780
|
try {
|
|
104751
104781
|
const networks = await this.getRegisteredNetworks();
|
|
104752
|
-
const
|
|
104782
|
+
const key = String(networkId || "").trim();
|
|
104783
|
+
let network = networks.find((n5) => n5.id === key);
|
|
104784
|
+
if (!network) {
|
|
104785
|
+
const lower = key.toLowerCase();
|
|
104786
|
+
network = networks.find((n5) => (n5.name || "").toLowerCase() === lower);
|
|
104787
|
+
}
|
|
104788
|
+
if (!network && /^\d+$/.test(key)) {
|
|
104789
|
+
const chainId = Number(key);
|
|
104790
|
+
network = networks.find((n5) => n5.chainId === chainId);
|
|
104791
|
+
}
|
|
104792
|
+
if (!network) {
|
|
104793
|
+
const alias = key.toLowerCase();
|
|
104794
|
+
const aliasChainId = {
|
|
104795
|
+
fuji: 43113,
|
|
104796
|
+
avalanchefuji: 43113,
|
|
104797
|
+
"avalanche-fuji": 43113,
|
|
104798
|
+
avaxfuji: 43113,
|
|
104799
|
+
"avax-fuji": 43113
|
|
104800
|
+
};
|
|
104801
|
+
const chainId = aliasChainId[alias];
|
|
104802
|
+
if (chainId) {
|
|
104803
|
+
network = networks.find((n5) => n5.chainId === chainId);
|
|
104804
|
+
}
|
|
104805
|
+
}
|
|
104753
104806
|
if (!network) {
|
|
104754
104807
|
throw new SDKError("Network not found", "INVALID_NETWORK" /* INVALID_NETWORK */);
|
|
104755
104808
|
}
|
|
104756
|
-
await LocalForage.save(`${this.orgHost}:currentNetwork`,
|
|
104809
|
+
await LocalForage.save(`${this.orgHost}:currentNetwork`, network.id);
|
|
104757
104810
|
} catch (error) {
|
|
104758
104811
|
if (error instanceof SDKError) throw error;
|
|
104759
104812
|
throw new SDKError("Failed to switch network", "NETWORK_ERROR" /* NETWORK_ERROR */);
|