btc-wallet 0.5.77-beta → 0.5.79-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.
@@ -18,9 +18,18 @@ interface ReceiveDepositMsgParams {
18
18
  depositType?: number;
19
19
  postActions?: string;
20
20
  extraMsg?: string;
21
+ userDepositAddress?: string;
21
22
  }
22
- export declare function preReceiveDepositMsg({ env, btcPublicKey, depositType, postActions, extraMsg, }: Omit<ReceiveDepositMsgParams, 'txHash'>): Promise<any>;
23
+ export declare function preReceiveDepositMsg({ env, btcPublicKey, depositType, postActions, extraMsg, userDepositAddress, }: Omit<ReceiveDepositMsgParams, 'txHash'>): Promise<any>;
23
24
  export declare function receiveDepositMsg({ env, btcPublicKey, txHash, depositType, postActions, extraMsg, }: ReceiveDepositMsgParams): Promise<any>;
25
+ export declare function getBridgeTransactions({ env, fromChainId, fromAddress, page, pageSize, }: {
26
+ env: ENV;
27
+ /** 0:ALL 1: BTC, 2: NEAR */
28
+ fromChainId?: number;
29
+ fromAddress?: string;
30
+ page?: number;
31
+ pageSize?: number;
32
+ }): Promise<any[]>;
24
33
  export declare function checkBridgeTransactionStatus({ txHash, fromChain, env, }: {
25
34
  txHash: string;
26
35
  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
@@ -3280,14 +3309,15 @@ function preReceiveDepositMsg(_0) {
3280
3309
  btcPublicKey,
3281
3310
  depositType = 1,
3282
3311
  postActions,
3283
- extraMsg
3312
+ extraMsg,
3313
+ userDepositAddress
3284
3314
  }) {
3285
3315
  const config = getWalletConfig(env);
3286
3316
  const { result_code, result_message, result_data } = yield request(
3287
3317
  `${config.base_url}/v1/preReceiveDepositMsg`,
3288
3318
  {
3289
3319
  method: "POST",
3290
- body: { btcPublicKey, depositType, postActions, extraMsg }
3320
+ body: { btcPublicKey, depositType, postActions, extraMsg, userDepositAddress }
3291
3321
  }
3292
3322
  );
3293
3323
  console.log("preReceiveDepositMsg resp:", { result_code, result_message, result_data });
@@ -3321,6 +3351,26 @@ function receiveDepositMsg(_0) {
3321
3351
  return result_data;
3322
3352
  });
3323
3353
  }
3354
+ function getBridgeTransactions(_0) {
3355
+ return __async(this, arguments, function* ({
3356
+ env,
3357
+ fromChainId = 0,
3358
+ fromAddress,
3359
+ page = 1,
3360
+ pageSize = 10
3361
+ }) {
3362
+ try {
3363
+ const config = getWalletConfig(env);
3364
+ const { result_data = [] } = yield request(
3365
+ `${config.base_url}/v1/history?fromChainId=${fromChainId}&fromAddress=${fromAddress}&page=${page}&pageSize=${pageSize}`
3366
+ );
3367
+ return result_data;
3368
+ } catch (error) {
3369
+ console.error("getBridgeTransactions error:", error);
3370
+ return [];
3371
+ }
3372
+ });
3373
+ }
3324
3374
  function checkBridgeTransactionStatus(_0) {
3325
3375
  return __async(this, arguments, function* ({
3326
3376
  txHash,
@@ -3719,13 +3769,13 @@ import coinselect from "coinselect";
3719
3769
  import * as ecc from "@bitcoinerlab/secp256k1";
3720
3770
  bitcoin.initEccLib(ecc);
3721
3771
  var NEAR_STORAGE_DEPOSIT_AMOUNT = "1250000000000000000000";
3722
- var NBTC_STORAGE_DEPOSIT_AMOUNT = "800";
3723
- var NEW_ACCOUNT_MIN_DEPOSIT_AMOUNT = "1000";
3772
+ var NBTC_STORAGE_DEPOSIT_AMOUNT = 800;
3773
+ var NEW_ACCOUNT_MIN_DEPOSIT_AMOUNT = 1e3;
3724
3774
  function getBtcProvider() {
3725
- if (typeof window === "undefined" || !window.btcContext) {
3775
+ if (typeof window === "undefined" || !(window.btcContext || (parent == null ? void 0 : parent.btcContext))) {
3726
3776
  throw new Error("BTC Provider is not initialized.");
3727
3777
  }
3728
- return window.btcContext;
3778
+ return window.btcContext || parent.btcContext;
3729
3779
  }
3730
3780
  function getNetwork() {
3731
3781
  return __async(this, null, function* () {
@@ -3757,8 +3807,16 @@ function checkGasTokenDebt(csna, env, autoDeposit) {
3757
3807
  return __async(this, null, function* () {
3758
3808
  var _a, _b, _c;
3759
3809
  const accountInfo = yield getAccountInfo({ csna, env });
3810
+ const { account } = getBtcProvider();
3811
+ const bridgeTransactions = yield getBridgeTransactions({
3812
+ env,
3813
+ fromAddress: account,
3814
+ page: 1,
3815
+ pageSize: 1
3816
+ });
3817
+ const isNewAccount = !(accountInfo == null ? void 0 : accountInfo.nonce) && bridgeTransactions.length === 0;
3760
3818
  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;
3819
+ const relayerFeeAmount = isNewAccount ? NBTC_STORAGE_DEPOSIT_AMOUNT : ((_c = accountInfo == null ? void 0 : accountInfo.relayer_fee) == null ? void 0 : _c.amount) || 0;
3762
3820
  const hasDebtArrears = new Big2(debtAmount).gt(0);
3763
3821
  const hasRelayerFeeArrears = new Big2(relayerFeeAmount).gt(0);
3764
3822
  if (!hasDebtArrears && !hasRelayerFeeArrears)
@@ -4034,7 +4092,8 @@ function executeBTCDepositAndAction(_0) {
4034
4092
  btcPublicKey,
4035
4093
  depositType: postActionsStr || depositMsg.extra_msg ? 1 : 0,
4036
4094
  postActions: postActionsStr,
4037
- extraMsg: depositMsg.extra_msg
4095
+ extraMsg: depositMsg.extra_msg,
4096
+ userDepositAddress
4038
4097
  });
4039
4098
  const txHash = yield sendBitcoin(userDepositAddress, depositAmount, _feeRate);
4040
4099
  yield receiveDepositMsg({
@@ -5269,7 +5328,7 @@ function getGroup(state) {
5269
5328
 
5270
5329
  // src/index.ts
5271
5330
  var getVersion = () => {
5272
- return "0.5.77-beta";
5331
+ return "0.5.79-beta";
5273
5332
  };
5274
5333
  if (typeof window !== "undefined") {
5275
5334
  window.__BTC_WALLET_VERSION = getVersion();