btc-wallet 0.5.77-beta → 0.5.78-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.
@@ -21,6 +21,14 @@ interface ReceiveDepositMsgParams {
21
21
  }
22
22
  export declare function preReceiveDepositMsg({ env, btcPublicKey, depositType, postActions, extraMsg, }: Omit<ReceiveDepositMsgParams, 'txHash'>): Promise<any>;
23
23
  export declare function receiveDepositMsg({ env, btcPublicKey, txHash, depositType, postActions, extraMsg, }: ReceiveDepositMsgParams): Promise<any>;
24
+ export declare function getBridgeTransactions({ env, fromChainId, fromAddress, page, pageSize, }: {
25
+ env: ENV;
26
+ /** 0:ALL 1: BTC, 2: NEAR */
27
+ fromChainId?: number;
28
+ fromAddress?: string;
29
+ page?: number;
30
+ pageSize?: number;
31
+ }): Promise<any[]>;
24
32
  export declare function checkBridgeTransactionStatus({ txHash, fromChain, env, }: {
25
33
  txHash: string;
26
34
  fromChain?: 'BTC' | 'NEAR';
package/esm/index.js CHANGED
@@ -1141,6 +1141,35 @@ var GateConnector = class extends InjectedConnector {
1141
1141
  downloadUrl: "https://www.gate.io/en/web3"
1142
1142
  };
1143
1143
  }
1144
+ sendBitcoin(toAddress, satoshis, options) {
1145
+ return __async(this, null, function* () {
1146
+ const addresses = yield this.getAccounts();
1147
+ if (addresses.length === 0) {
1148
+ throw new Error(`${this.metadata.name} not connected!`);
1149
+ }
1150
+ const result = yield window.gatewallet.bitcoin.sendBitcoin({
1151
+ fromAddress: addresses[0],
1152
+ toAddress,
1153
+ satoshis,
1154
+ options
1155
+ });
1156
+ console.log("\u{1F680} ~ GateConnector ~ sendBitcoin ~ result:", result);
1157
+ return result.txhash;
1158
+ });
1159
+ }
1160
+ signMessage(signStr, type) {
1161
+ return __async(this, null, function* () {
1162
+ const addresses = yield this.getAccounts();
1163
+ if (addresses.length === 0) {
1164
+ throw new Error(`${this.metadata.name} not connected!`);
1165
+ }
1166
+ return window.gatewallet.bitcoin.signMessage({
1167
+ fromAddress: addresses[0],
1168
+ text: signStr,
1169
+ type
1170
+ });
1171
+ });
1172
+ }
1144
1173
  };
1145
1174
 
1146
1175
  // src/context/index.tsx
@@ -3321,6 +3350,26 @@ function receiveDepositMsg(_0) {
3321
3350
  return result_data;
3322
3351
  });
3323
3352
  }
3353
+ function getBridgeTransactions(_0) {
3354
+ return __async(this, arguments, function* ({
3355
+ env,
3356
+ fromChainId = 0,
3357
+ fromAddress,
3358
+ page = 1,
3359
+ pageSize = 10
3360
+ }) {
3361
+ try {
3362
+ const config = getWalletConfig(env);
3363
+ const { result_data = [] } = yield request(
3364
+ `${config.base_url}/v1/history?fromChainId=${fromChainId}&fromAddress=${fromAddress}&page=${page}&pageSize=${pageSize}`
3365
+ );
3366
+ return result_data;
3367
+ } catch (error) {
3368
+ console.error("getBridgeTransactions error:", error);
3369
+ return [];
3370
+ }
3371
+ });
3372
+ }
3324
3373
  function checkBridgeTransactionStatus(_0) {
3325
3374
  return __async(this, arguments, function* ({
3326
3375
  txHash,
@@ -3719,13 +3768,13 @@ import coinselect from "coinselect";
3719
3768
  import * as ecc from "@bitcoinerlab/secp256k1";
3720
3769
  bitcoin.initEccLib(ecc);
3721
3770
  var NEAR_STORAGE_DEPOSIT_AMOUNT = "1250000000000000000000";
3722
- var NBTC_STORAGE_DEPOSIT_AMOUNT = "800";
3723
- var NEW_ACCOUNT_MIN_DEPOSIT_AMOUNT = "1000";
3771
+ var NBTC_STORAGE_DEPOSIT_AMOUNT = 800;
3772
+ var NEW_ACCOUNT_MIN_DEPOSIT_AMOUNT = 1e3;
3724
3773
  function getBtcProvider() {
3725
- if (typeof window === "undefined" || !window.btcContext) {
3774
+ if (typeof window === "undefined" || !(window.btcContext || (parent == null ? void 0 : parent.btcContext))) {
3726
3775
  throw new Error("BTC Provider is not initialized.");
3727
3776
  }
3728
- return window.btcContext;
3777
+ return window.btcContext || parent.btcContext;
3729
3778
  }
3730
3779
  function getNetwork() {
3731
3780
  return __async(this, null, function* () {
@@ -3757,8 +3806,16 @@ function checkGasTokenDebt(csna, env, autoDeposit) {
3757
3806
  return __async(this, null, function* () {
3758
3807
  var _a, _b, _c;
3759
3808
  const accountInfo = yield getAccountInfo({ csna, env });
3809
+ const { account } = getBtcProvider();
3810
+ const bridgeTransactions = yield getBridgeTransactions({
3811
+ env,
3812
+ fromAddress: account,
3813
+ page: 1,
3814
+ pageSize: 1
3815
+ });
3816
+ const isNewAccount = !(accountInfo == null ? void 0 : accountInfo.nonce) && bridgeTransactions.length === 0;
3760
3817
  const debtAmount = new Big2(((_a = accountInfo == null ? void 0 : accountInfo.debt_info) == null ? void 0 : _a.near_gas_debt_amount) || 0).plus(((_b = accountInfo == null ? void 0 : accountInfo.debt_info) == null ? void 0 : _b.protocol_fee_debt_amount) || 0).toString();
3761
- const relayerFeeAmount = !(accountInfo == null ? void 0 : accountInfo.nonce) ? NBTC_STORAGE_DEPOSIT_AMOUNT : ((_c = accountInfo == null ? void 0 : accountInfo.relayer_fee) == null ? void 0 : _c.amount) || 0;
3818
+ const relayerFeeAmount = isNewAccount ? NBTC_STORAGE_DEPOSIT_AMOUNT : ((_c = accountInfo == null ? void 0 : accountInfo.relayer_fee) == null ? void 0 : _c.amount) || 0;
3762
3819
  const hasDebtArrears = new Big2(debtAmount).gt(0);
3763
3820
  const hasRelayerFeeArrears = new Big2(relayerFeeAmount).gt(0);
3764
3821
  if (!hasDebtArrears && !hasRelayerFeeArrears)
@@ -5269,7 +5326,7 @@ function getGroup(state) {
5269
5326
 
5270
5327
  // src/index.ts
5271
5328
  var getVersion = () => {
5272
- return "0.5.77-beta";
5329
+ return "0.5.78-beta";
5273
5330
  };
5274
5331
  if (typeof window !== "undefined") {
5275
5332
  window.__BTC_WALLET_VERSION = getVersion();