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.
@@ -3,4 +3,8 @@ import { InjectedConnector } from './injected';
3
3
  export declare class GateConnector extends InjectedConnector {
4
4
  readonly metadata: WalletMetadata;
5
5
  constructor();
6
+ sendBitcoin(toAddress: string, satoshis: number, options?: {
7
+ feeRate: number;
8
+ }): Promise<string>;
9
+ signMessage(signStr: string, type?: 'ecdsa' | 'bip322-simple'): Promise<string>;
6
10
  }
@@ -40,7 +40,7 @@ export declare function getDepositAmount(amount: string, option?: {
40
40
  receiveAmount: number;
41
41
  protocolFee: number;
42
42
  repayAmount: string | number;
43
- newAccountMinDepositAmount: string | number;
43
+ newAccountMinDepositAmount: number;
44
44
  minDepositAmount: number;
45
45
  }>;
46
46
  export declare function getCsnaAccountId(env: ENV): Promise<string>;
package/dist/index.js CHANGED
@@ -1213,6 +1213,35 @@ var GateConnector = class extends InjectedConnector {
1213
1213
  downloadUrl: "https://www.gate.io/en/web3"
1214
1214
  };
1215
1215
  }
1216
+ sendBitcoin(toAddress, satoshis, options) {
1217
+ return __async(this, null, function* () {
1218
+ const addresses = yield this.getAccounts();
1219
+ if (addresses.length === 0) {
1220
+ throw new Error(`${this.metadata.name} not connected!`);
1221
+ }
1222
+ const result = yield window.gatewallet.bitcoin.sendBitcoin({
1223
+ fromAddress: addresses[0],
1224
+ toAddress,
1225
+ satoshis,
1226
+ options
1227
+ });
1228
+ console.log("\u{1F680} ~ GateConnector ~ sendBitcoin ~ result:", result);
1229
+ return result.txhash;
1230
+ });
1231
+ }
1232
+ signMessage(signStr, type) {
1233
+ return __async(this, null, function* () {
1234
+ const addresses = yield this.getAccounts();
1235
+ if (addresses.length === 0) {
1236
+ throw new Error(`${this.metadata.name} not connected!`);
1237
+ }
1238
+ return window.gatewallet.bitcoin.signMessage({
1239
+ fromAddress: addresses[0],
1240
+ text: signStr,
1241
+ type
1242
+ });
1243
+ });
1244
+ }
1216
1245
  };
1217
1246
 
1218
1247
  // src/context/index.tsx
@@ -3393,6 +3422,26 @@ function receiveDepositMsg(_0) {
3393
3422
  return result_data;
3394
3423
  });
3395
3424
  }
3425
+ function getBridgeTransactions(_0) {
3426
+ return __async(this, arguments, function* ({
3427
+ env,
3428
+ fromChainId = 0,
3429
+ fromAddress,
3430
+ page = 1,
3431
+ pageSize = 10
3432
+ }) {
3433
+ try {
3434
+ const config = getWalletConfig(env);
3435
+ const { result_data = [] } = yield request(
3436
+ `${config.base_url}/v1/history?fromChainId=${fromChainId}&fromAddress=${fromAddress}&page=${page}&pageSize=${pageSize}`
3437
+ );
3438
+ return result_data;
3439
+ } catch (error) {
3440
+ console.error("getBridgeTransactions error:", error);
3441
+ return [];
3442
+ }
3443
+ });
3444
+ }
3396
3445
  function checkBridgeTransactionStatus(_0) {
3397
3446
  return __async(this, arguments, function* ({
3398
3447
  txHash,
@@ -3791,13 +3840,13 @@ var import_coinselect = __toESM(require("coinselect"), 1);
3791
3840
  var ecc = __toESM(require("@bitcoinerlab/secp256k1"), 1);
3792
3841
  bitcoin.initEccLib(ecc);
3793
3842
  var NEAR_STORAGE_DEPOSIT_AMOUNT = "1250000000000000000000";
3794
- var NBTC_STORAGE_DEPOSIT_AMOUNT = "800";
3795
- var NEW_ACCOUNT_MIN_DEPOSIT_AMOUNT = "1000";
3843
+ var NBTC_STORAGE_DEPOSIT_AMOUNT = 800;
3844
+ var NEW_ACCOUNT_MIN_DEPOSIT_AMOUNT = 1e3;
3796
3845
  function getBtcProvider() {
3797
- if (typeof window === "undefined" || !window.btcContext) {
3846
+ if (typeof window === "undefined" || !(window.btcContext || (parent == null ? void 0 : parent.btcContext))) {
3798
3847
  throw new Error("BTC Provider is not initialized.");
3799
3848
  }
3800
- return window.btcContext;
3849
+ return window.btcContext || parent.btcContext;
3801
3850
  }
3802
3851
  function getNetwork() {
3803
3852
  return __async(this, null, function* () {
@@ -3829,8 +3878,16 @@ function checkGasTokenDebt(csna, env, autoDeposit) {
3829
3878
  return __async(this, null, function* () {
3830
3879
  var _a, _b, _c;
3831
3880
  const accountInfo = yield getAccountInfo({ csna, env });
3881
+ const { account } = getBtcProvider();
3882
+ const bridgeTransactions = yield getBridgeTransactions({
3883
+ env,
3884
+ fromAddress: account,
3885
+ page: 1,
3886
+ pageSize: 1
3887
+ });
3888
+ const isNewAccount = !(accountInfo == null ? void 0 : accountInfo.nonce) && bridgeTransactions.length === 0;
3832
3889
  const debtAmount = new import_big2.default(((_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();
3833
- 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;
3890
+ const relayerFeeAmount = isNewAccount ? NBTC_STORAGE_DEPOSIT_AMOUNT : ((_c = accountInfo == null ? void 0 : accountInfo.relayer_fee) == null ? void 0 : _c.amount) || 0;
3834
3891
  const hasDebtArrears = new import_big2.default(debtAmount).gt(0);
3835
3892
  const hasRelayerFeeArrears = new import_big2.default(relayerFeeAmount).gt(0);
3836
3893
  if (!hasDebtArrears && !hasRelayerFeeArrears)
@@ -5339,7 +5396,7 @@ function getGroup(state) {
5339
5396
 
5340
5397
  // src/index.ts
5341
5398
  var getVersion = () => {
5342
- return "0.5.77-beta";
5399
+ return "0.5.78-beta";
5343
5400
  };
5344
5401
  if (typeof window !== "undefined") {
5345
5402
  window.__BTC_WALLET_VERSION = getVersion();