btc-wallet 0.5.0-beta → 0.5.1-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/README.md CHANGED
@@ -69,6 +69,7 @@ interface ExecuteBTCDepositAndActionParams<T extends boolean = true> {
69
69
  env?: 'mainnet' | 'testnet' | 'private_mainnet' | 'dev'; // optional: defaults to NEAR network environment
70
70
  pollResult?: T; // optional: whether to poll for transaction result
71
71
  registerDeposit?: string; // optional: whether to register deposit,default 0.000125 NEAR
72
+ newAccountMinDepositAmount?: boolean; // default is true, if true, new account minimum deposit BTC amount 1000sat, otherwise 0
72
73
  }
73
74
 
74
75
  // Example 1: dApp one-click BTC deposit
@@ -110,7 +111,8 @@ import { getDepositAmount } from 'btc-wallet';
110
111
  const result = await getDepositAmount(
111
112
  amount: string, // Amount in satoshi units
112
113
  options?: {
113
- env?: 'mainnet' | 'testnet' | 'private_mainnet' | 'dev' // Optional: Defaults to NEAR network environment
114
+ env?: 'mainnet' | 'testnet' | 'private_mainnet' | 'dev', // Optional: Defaults to NEAR network environment
115
+ newAccountMinDepositAmount?: boolean // default is true, if true, new account minimum deposit amount 1000sat, otherwise 0
114
116
  }
115
117
  );
116
118
 
@@ -39,6 +39,8 @@ export declare function estimateDepositAmount(amount: string, option?: {
39
39
  }): Promise<string>;
40
40
  export declare function getDepositAmount(amount: string, option?: {
41
41
  env?: ENV;
42
+ /** default is true, if true, new account minimum deposit amount 1000sat, otherwise 0 */
43
+ newAccountMinDepositAmount?: boolean;
42
44
  }): Promise<{
43
45
  depositAmount: number;
44
46
  totalDepositAmount: number;
@@ -59,12 +61,13 @@ interface ExecuteBTCDepositAndActionParams<T extends boolean = true> {
59
61
  feeRate?: number;
60
62
  env?: ENV;
61
63
  pollResult?: T;
64
+ newAccountMinDepositAmount?: boolean;
62
65
  }
63
66
  /**
64
67
  * @param T - if true, return the poll result, otherwise return the btcTxHash
65
68
  */
66
69
  type ExecuteBTCDepositAndActionReturn<T extends boolean> = T extends true ? FinalExecutionOutcome[] : string;
67
- export declare function executeBTCDepositAndAction<T extends boolean = true>({ action, amount, feeRate, pollResult, registerDeposit, env, }: ExecuteBTCDepositAndActionParams<T>): Promise<ExecuteBTCDepositAndActionReturn<T>>;
70
+ export declare function executeBTCDepositAndAction<T extends boolean = true>({ action, amount, feeRate, pollResult, registerDeposit, env, newAccountMinDepositAmount, }: ExecuteBTCDepositAndActionParams<T>): Promise<ExecuteBTCDepositAndActionReturn<T>>;
68
71
  export declare function checkSatoshiWhitelist(btcAccountId: string, env?: ENV): Promise<void>;
69
72
  interface WithdrawParams {
70
73
  amount: string | number;
package/dist/index.js CHANGED
@@ -2855,6 +2855,7 @@ function useBtcWalletSelector() {
2855
2855
  }),
2856
2856
  autoConnect: () => __async(this, null, function* () {
2857
2857
  requestDirectAccount(connectorRef.current).catch((e) => {
2858
+ console.error("btcLoginError", e);
2858
2859
  context.emit("btcLoginError");
2859
2860
  });
2860
2861
  }),
@@ -2924,7 +2925,7 @@ var walletConfig = {
2924
2925
  token: "nbtc.toalice.near",
2925
2926
  accountContractId: "acc.toalice.near",
2926
2927
  bridgeContractId: "brg.toalice.near",
2927
- walletUrl: "https://wallet-stg.satoshibridge.top",
2928
+ walletUrl: "http://localhost:3100",
2928
2929
  bridgeUrl: "https://old.ramp.satos.network"
2929
2930
  },
2930
2931
  mainnet: {
@@ -3446,10 +3447,11 @@ var NBTC_STORAGE_DEPOSIT_AMOUNT = "3000";
3446
3447
  var GAS_LIMIT = "50000000000000";
3447
3448
  var NEW_ACCOUNT_MIN_DEPOSIT_AMOUNT = "1000";
3448
3449
  function getBtcProvider() {
3449
- if (typeof window === "undefined" || !window.btcContext) {
3450
+ var _a, _b;
3451
+ if (typeof window === "undefined" || !window.btcContext && !((_a = window.top) == null ? void 0 : _a.btcContext)) {
3450
3452
  throw new Error("BTC Provider is not initialized.");
3451
3453
  }
3452
- return window.btcContext;
3454
+ return window.btcContext || ((_b = window.top) == null ? void 0 : _b.btcContext);
3453
3455
  }
3454
3456
  function getNetwork() {
3455
3457
  return __async(this, null, function* () {
@@ -3603,7 +3605,9 @@ function estimateDepositAmount(amount, option) {
3603
3605
  }
3604
3606
  function getDepositAmount(amount, option) {
3605
3607
  return __async(this, null, function* () {
3608
+ var _a;
3606
3609
  const env = (option == null ? void 0 : option.env) || "mainnet";
3610
+ const _newAccountMinDepositAmount = (_a = option == null ? void 0 : option.newAccountMinDepositAmount) != null ? _a : true;
3607
3611
  const config = yield getConfig(env);
3608
3612
  const csna = yield getCsnaAccountId(env);
3609
3613
  const accountInfo = yield getAccountInfo(csna, config.accountContractId);
@@ -3615,7 +3619,7 @@ function getDepositAmount(amount, option) {
3615
3619
  } = yield nearCall(config.bridgeContractId, "get_config", {});
3616
3620
  const depositAmount = Math.max(Number(min_deposit_amount), Number(amount));
3617
3621
  const protocolFee = Math.max(Number(fee_min), Number(depositAmount) * fee_rate);
3618
- const newAccountMinDepositAmount = !(accountInfo == null ? void 0 : accountInfo.nonce) ? NEW_ACCOUNT_MIN_DEPOSIT_AMOUNT : 0;
3622
+ const newAccountMinDepositAmount = !(accountInfo == null ? void 0 : accountInfo.nonce) && _newAccountMinDepositAmount ? NEW_ACCOUNT_MIN_DEPOSIT_AMOUNT : 0;
3619
3623
  const totalDepositAmount = new import_big.default(depositAmount).plus(protocolFee).plus(repayAmount).plus(newAccountMinDepositAmount).round(0, import_big.default.roundDown).toNumber();
3620
3624
  return {
3621
3625
  depositAmount,
@@ -3648,7 +3652,8 @@ function executeBTCDepositAndAction(_0) {
3648
3652
  feeRate,
3649
3653
  pollResult = true,
3650
3654
  registerDeposit,
3651
- env = "mainnet"
3655
+ env = "mainnet",
3656
+ newAccountMinDepositAmount
3652
3657
  }) {
3653
3658
  var _a;
3654
3659
  try {
@@ -3667,7 +3672,8 @@ function executeBTCDepositAndAction(_0) {
3667
3672
  throw new Error("amount must be greater than 0");
3668
3673
  }
3669
3674
  const { totalDepositAmount, protocolFee, repayAmount } = yield getDepositAmount(depositAmount, {
3670
- env
3675
+ env,
3676
+ newAccountMinDepositAmount
3671
3677
  });
3672
3678
  const accountInfo = yield getAccountInfo(csna, config.accountContractId);
3673
3679
  const newActions = [];
@@ -4044,7 +4050,7 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
4044
4050
  if (btcContext.account) {
4045
4051
  const btcPublicKey = yield btcContext.getPublicKey();
4046
4052
  if (btcPublicKey) {
4047
- const { nearAddress, nearPublicKey } = yield getNearAccountByBtcPublicKey(btcPublicKey);
4053
+ yield getNearAccountByBtcPublicKey(btcPublicKey);
4048
4054
  yield checkSatoshiWhitelist(btcContext.account, env);
4049
4055
  removeWalletButton();
4050
4056
  setupWalletButton(env, wallet, btcContext);
@@ -4076,10 +4082,6 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
4076
4082
  }
4077
4083
  }));
4078
4084
  context.on("btcLoginError", () => __async(this, null, function* () {
4079
- console.log("btcLoginError");
4080
- state.clear();
4081
- emitter.emit("accountsChanged", { accounts: [] });
4082
- yield handleConnectionUpdate();
4083
4085
  }));
4084
4086
  context.on("btcLogOut", () => __async(this, null, function* () {
4085
4087
  console.log("btcLogOut");
@@ -4436,7 +4438,7 @@ function setupBTCWallet({
4436
4438
 
4437
4439
  // src/index.ts
4438
4440
  var getVersion = () => {
4439
- return "0.5.0-beta";
4441
+ return "0.5.1-beta";
4440
4442
  };
4441
4443
  if (typeof window !== "undefined") {
4442
4444
  window.__BTC_WALLET_VERSION = getVersion();