@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.js
CHANGED
|
@@ -104474,14 +104474,9 @@ var WalletService = class {
|
|
|
104474
104474
|
});
|
|
104475
104475
|
const network = await this.networkService.getCurrentNetwork();
|
|
104476
104476
|
const decimals = network?.decimals || DECIMALS.ETH;
|
|
104477
|
-
const formatted = TokenAmount.format(response.result, decimals);
|
|
104478
104477
|
return {
|
|
104479
104478
|
raw: response.result,
|
|
104480
|
-
|
|
104481
|
-
balanceWei: response.result,
|
|
104482
|
-
result: response.result,
|
|
104483
|
-
formatted,
|
|
104484
|
-
balance: formatted,
|
|
104479
|
+
formatted: TokenAmount.format(response.result, decimals),
|
|
104485
104480
|
decimals,
|
|
104486
104481
|
symbol: network?.symbol || "ETH"
|
|
104487
104482
|
};
|
|
@@ -104624,6 +104619,18 @@ var WalletService = class {
|
|
|
104624
104619
|
if (!from) {
|
|
104625
104620
|
throw new SDKError("Wallet not found", "WALLET_NOT_FOUND" /* WALLET_NOT_FOUND */);
|
|
104626
104621
|
}
|
|
104622
|
+
const toHexQuantity = (v5) => {
|
|
104623
|
+
if (v5 === void 0 || v5 === null) return "0x0";
|
|
104624
|
+
const s5 = String(v5).trim();
|
|
104625
|
+
if (!s5) return "0x0";
|
|
104626
|
+
if (s5.startsWith("0x") || s5.startsWith("0X")) return s5;
|
|
104627
|
+
try {
|
|
104628
|
+
const bi = BigInt(s5);
|
|
104629
|
+
return "0x" + bi.toString(16);
|
|
104630
|
+
} catch {
|
|
104631
|
+
return s5;
|
|
104632
|
+
}
|
|
104633
|
+
};
|
|
104627
104634
|
const [share1, share2] = await Promise.all([
|
|
104628
104635
|
this.walletClient.getWallet().then((wallet2) => wallet2.share1),
|
|
104629
104636
|
LocalForage.get(STORAGE_KEYS.share2(this.orgHost))
|
|
@@ -104638,19 +104645,42 @@ var WalletService = class {
|
|
|
104638
104645
|
const wallet = new Wallet(privateKey);
|
|
104639
104646
|
const nonce = params.nonce ?? await this.getTransactionCount(from, params.chainId);
|
|
104640
104647
|
const gasPrice = params.gasPrice ?? await this.getGasPrice(params.chainId);
|
|
104648
|
+
let gasLimit = params.gasLimit;
|
|
104649
|
+
if (!gasLimit) {
|
|
104650
|
+
try {
|
|
104651
|
+
const est = await this.estimateGas(
|
|
104652
|
+
{
|
|
104653
|
+
from,
|
|
104654
|
+
to: params.to,
|
|
104655
|
+
value: toHexQuantity(params.value),
|
|
104656
|
+
data: params.data || "0x"
|
|
104657
|
+
},
|
|
104658
|
+
params.chainId
|
|
104659
|
+
);
|
|
104660
|
+
const buffered = Math.max(21e3, Math.ceil(est * 1.2));
|
|
104661
|
+
gasLimit = "0x" + buffered.toString(16);
|
|
104662
|
+
} catch (e7) {
|
|
104663
|
+
const data = (params.data || "").toLowerCase();
|
|
104664
|
+
const fallback = data.startsWith("0x095ea7b3") ? 12e4 : data && data !== "0x" ? 8e5 : 21e3;
|
|
104665
|
+
gasLimit = "0x" + fallback.toString(16);
|
|
104666
|
+
}
|
|
104667
|
+
}
|
|
104641
104668
|
const signedTx = await wallet.signTransaction({
|
|
104642
104669
|
to: params.to,
|
|
104643
|
-
value: params.value,
|
|
104670
|
+
value: params.value ?? "0x0",
|
|
104644
104671
|
data: params.data || "0x",
|
|
104645
104672
|
chainId: params.chainId,
|
|
104646
104673
|
nonce,
|
|
104647
104674
|
gasPrice,
|
|
104648
|
-
gasLimit
|
|
104675
|
+
gasLimit
|
|
104649
104676
|
});
|
|
104650
104677
|
return this.sendRawTransaction(signedTx, params.chainId);
|
|
104651
104678
|
} catch (error) {
|
|
104679
|
+
const detail = String(
|
|
104680
|
+
error?.shortMessage ?? error?.reason ?? error?.message ?? ""
|
|
104681
|
+
).trim();
|
|
104652
104682
|
throw new SDKError(
|
|
104653
|
-
"Transaction failed",
|
|
104683
|
+
detail ? `Transaction failed: ${detail}` : "Transaction failed",
|
|
104654
104684
|
"TRANSACTION_FAILED" /* TRANSACTION_FAILED */,
|
|
104655
104685
|
error
|
|
104656
104686
|
);
|
|
@@ -104704,11 +104734,34 @@ var NetworkService = class {
|
|
|
104704
104734
|
async switchNetwork(networkId) {
|
|
104705
104735
|
try {
|
|
104706
104736
|
const networks = await this.getRegisteredNetworks();
|
|
104707
|
-
const
|
|
104737
|
+
const key = String(networkId || "").trim();
|
|
104738
|
+
let network = networks.find((n5) => n5.id === key);
|
|
104739
|
+
if (!network) {
|
|
104740
|
+
const lower = key.toLowerCase();
|
|
104741
|
+
network = networks.find((n5) => (n5.name || "").toLowerCase() === lower);
|
|
104742
|
+
}
|
|
104743
|
+
if (!network && /^\d+$/.test(key)) {
|
|
104744
|
+
const chainId = Number(key);
|
|
104745
|
+
network = networks.find((n5) => n5.chainId === chainId);
|
|
104746
|
+
}
|
|
104747
|
+
if (!network) {
|
|
104748
|
+
const alias = key.toLowerCase();
|
|
104749
|
+
const aliasChainId = {
|
|
104750
|
+
fuji: 43113,
|
|
104751
|
+
avalanchefuji: 43113,
|
|
104752
|
+
"avalanche-fuji": 43113,
|
|
104753
|
+
avaxfuji: 43113,
|
|
104754
|
+
"avax-fuji": 43113
|
|
104755
|
+
};
|
|
104756
|
+
const chainId = aliasChainId[alias];
|
|
104757
|
+
if (chainId) {
|
|
104758
|
+
network = networks.find((n5) => n5.chainId === chainId);
|
|
104759
|
+
}
|
|
104760
|
+
}
|
|
104708
104761
|
if (!network) {
|
|
104709
104762
|
throw new SDKError("Network not found", "INVALID_NETWORK" /* INVALID_NETWORK */);
|
|
104710
104763
|
}
|
|
104711
|
-
await LocalForage.save(`${this.orgHost}:currentNetwork`,
|
|
104764
|
+
await LocalForage.save(`${this.orgHost}:currentNetwork`, network.id);
|
|
104712
104765
|
} catch (error) {
|
|
104713
104766
|
if (error instanceof SDKError) throw error;
|
|
104714
104767
|
throw new SDKError("Failed to switch network", "NETWORK_ERROR" /* NETWORK_ERROR */);
|