btc-wallet 0.5.50-beta → 0.5.52-beta

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
@@ -2390,6 +2390,14 @@ var ConnectProvider = ({
2390
2390
  name: ((_a = Object.keys(options.aaOptions.accountContracts)) == null ? void 0 : _a[0]) || "BTC",
2391
2391
  version: ((_c = options.aaOptions.accountContracts[((_b = Object.keys(options.aaOptions.accountContracts)) == null ? void 0 : _b[0]) || "BTC"]) == null ? void 0 : _c[0].version) || "1.0.0"
2392
2392
  });
2393
+ const initConnectorId = (0, import_react10.useCallback)(() => {
2394
+ const id = localStorage.getItem("current-connector-id");
2395
+ setConnectorId(id || "");
2396
+ }, []);
2397
+ const getConnector = (0, import_react10.useCallback)(() => {
2398
+ const connectorId2 = localStorage.getItem("current-connector-id");
2399
+ return connectors.find((item) => item.metadata.id === connectorId2);
2400
+ }, [connectorId, connectors]);
2393
2401
  const setAccountContract = (0, import_react10.useCallback)(
2394
2402
  (config) => {
2395
2403
  if (!checkBTCVersion(options.aaOptions.accountContracts, config.name, config.version)) {
@@ -2401,11 +2409,8 @@ var ConnectProvider = ({
2401
2409
  [options.aaOptions.accountContracts, _setAccountContract]
2402
2410
  );
2403
2411
  (0, import_react10.useEffect)(() => {
2404
- const id = localStorage.getItem("current-connector-id");
2405
- if (id) {
2406
- setConnectorId(id);
2407
- }
2408
- }, [autoConnect]);
2412
+ initConnectorId();
2413
+ }, [autoConnect, initConnectorId]);
2409
2414
  const evmSupportChainIds = (0, import_react10.useMemo)(() => {
2410
2415
  var _a2;
2411
2416
  let chainIds = (_a2 = options.aaOptions.accountContracts[accountContract.name]) == null ? void 0 : _a2.filter((item) => item.version === accountContract.version).map((item) => item.chainIds).reduce((a, b) => {
@@ -2415,16 +2420,15 @@ var ConnectProvider = ({
2415
2420
  chainIds = Array.from(new Set(chainIds || []));
2416
2421
  return chainIds;
2417
2422
  }, [options.aaOptions.accountContracts, accountContract]);
2418
- const connector = (0, import_react10.useMemo)(() => {
2419
- return connectors.find((item) => item.metadata.id === connectorId);
2420
- }, [connectorId, connectors]);
2423
+ const connector = (0, import_react10.useMemo)(() => getConnector(), [connectorId, connectors]);
2421
2424
  const getPublicKey = (0, import_react10.useCallback)(() => __async(void 0, null, function* () {
2422
- if (!connector) {
2425
+ const connector2 = getConnector();
2426
+ if (!connector2) {
2423
2427
  throw new Error("Wallet not connected!");
2424
2428
  }
2425
- const pubKey = yield connector.getPublicKey();
2429
+ const pubKey = yield connector2.getPublicKey();
2426
2430
  return pubKey;
2427
- }), [connector]);
2431
+ }), [getConnector]);
2428
2432
  const signMessage = (0, import_react10.useCallback)(
2429
2433
  (message) => __async(void 0, null, function* () {
2430
2434
  if (!connector) {
@@ -3725,7 +3729,7 @@ function getNetwork() {
3725
3729
  });
3726
3730
  }
3727
3731
  function formatBtcAmount(amount) {
3728
- return new import_big2.default(amount).div(__pow(10, 8)).toString();
3732
+ return new import_big2.default(amount).div(__pow(10, 8)).toFixed();
3729
3733
  }
3730
3734
  function getBtcRpcUrl() {
3731
3735
  return __async(this, null, function* () {
@@ -4334,6 +4338,18 @@ function calculateWithdraw(_0) {
4334
4338
  errorMsg: "Not enough gas"
4335
4339
  };
4336
4340
  }
4341
+ const belowMinChangeAmount = newOutputs.some(
4342
+ (item) => item.value > 0 && item.value < Number(brgConfig.min_change_amount)
4343
+ );
4344
+ if (belowMinChangeAmount) {
4345
+ const minWithdrawAmount = new import_big2.default(brgConfig.min_withdraw_amount).plus(brgConfig.min_change_amount).plus(gasLimit).plus(withdrawFee).toNumber();
4346
+ return {
4347
+ gasFee: newFee,
4348
+ withdrawFee,
4349
+ isError: true,
4350
+ errorMsg: `Transaction amount too small. Minimum required: ${formatBtcAmount(minWithdrawAmount)} BTC`
4351
+ };
4352
+ }
4337
4353
  const inputSum = newInputs.reduce((sum, cur) => sum + Number(cur.value), 0);
4338
4354
  const outputSum = newOutputs.reduce((sum, cur) => sum + Number(cur.value), 0);
4339
4355
  if (newFee + outputSum !== inputSum) {
@@ -5033,7 +5049,7 @@ function getGroup(state) {
5033
5049
 
5034
5050
  // src/index.ts
5035
5051
  var getVersion = () => {
5036
- return "0.5.50-beta";
5052
+ return "0.5.52-beta";
5037
5053
  };
5038
5054
  if (typeof window !== "undefined") {
5039
5055
  window.__BTC_WALLET_VERSION = getVersion();