btc-wallet 0.1.9 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
package/dist/index.js CHANGED
@@ -10,6 +10,7 @@ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
10
10
  var __getProtoOf = Object.getPrototypeOf;
11
11
  var __hasOwnProp = Object.prototype.hasOwnProperty;
12
12
  var __propIsEnum = Object.prototype.propertyIsEnumerable;
13
+ var __pow = Math.pow;
13
14
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
14
15
  var __spreadValues = (a, b) => {
15
16
  for (var prop in b || (b = {}))
@@ -2491,6 +2492,11 @@ function removeWalletButton() {
2491
2492
  // src/utils/setupBTCWallet.ts
2492
2493
  var { transfer, functionCall } = import_transactions.actionCreators;
2493
2494
  var config = {
2495
+ dev: {
2496
+ base_url: "https://api.dev.satoshibridge.top/v1",
2497
+ token: "nbtc1-nsp.dev",
2498
+ contractId: "dev1-nsp.dev"
2499
+ },
2494
2500
  testnet: {
2495
2501
  base_url: "https://api.testnet.satoshibridge.top/v1",
2496
2502
  token: "nbtc2-nsp.testnet",
@@ -2559,6 +2565,7 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
2559
2565
  signAndSendTransaction,
2560
2566
  signAndSendTransactions
2561
2567
  };
2568
+ const currentConfig = "isDev" in metadata && metadata.isDev ? config.dev : config[options.network.networkId];
2562
2569
  initWalletButton(options.network.networkId, wallet);
2563
2570
  if (!inter) {
2564
2571
  inter = setInterval(() => __async(void 0, null, function* () {
@@ -2568,6 +2575,7 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
2568
2575
  const context = btcContext.getContext();
2569
2576
  context.on("updatePublicKey", (btcPublicKey) => __async(void 0, null, function* () {
2570
2577
  const { nearTempAddress } = yield getNearAccountByBtcPublicKey(btcPublicKey);
2578
+ removeWalletButton();
2571
2579
  initWalletButton(options.network.networkId, wallet);
2572
2580
  emitter.emit("accountsChanged", {
2573
2581
  accounts: [
@@ -2593,7 +2601,7 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
2593
2601
  return __async(this, arguments, function* ({ method, args = {} }) {
2594
2602
  const res = yield provider.query({
2595
2603
  request_type: "call_function",
2596
- account_id: config[options.network.networkId].contractId,
2604
+ account_id: currentConfig.contractId,
2597
2605
  method_name: method,
2598
2606
  args_base64: Buffer.from(JSON.stringify(args)).toString("base64"),
2599
2607
  finality: "optimistic"
@@ -2696,7 +2704,7 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
2696
2704
  nonce: BigInt(rawAccessKey.nonce || 0)
2697
2705
  });
2698
2706
  const publicKeyFormat = import_key_pair.PublicKey.from(publicKey);
2699
- const nearNonceApi = yield getNearNonceFromApi(options.network.networkId, accountId);
2707
+ const nearNonceApi = yield getNearNonceFromApi(currentConfig.base_url, accountId);
2700
2708
  const newTransactions = params.transactions.map((transaction, index) => {
2701
2709
  let nearNonceNumber = accessKey.nonce + BigInt(1);
2702
2710
  if (nearNonceApi) {
@@ -2735,19 +2743,24 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
2735
2743
  method: "get_account",
2736
2744
  args: { account_id: accountId }
2737
2745
  });
2738
- const nonceApi = yield getNonceFromApi(options.network.networkId, accountId);
2746
+ const nonceApi = yield getNonceFromApi(currentConfig.base_url, accountId);
2739
2747
  const nonce = Number(nonceApi == null ? void 0 : nonceApi.result_data) > Number(accountInfo.nonce) ? String(nonceApi == null ? void 0 : nonceApi.result_data) : String(accountInfo.nonce);
2740
2748
  const intention = {
2741
2749
  chain_id: "397",
2742
2750
  csna: accountId,
2743
2751
  near_transactions: newTransactions.map((t) => t.txHex),
2744
- gas_token: config[options.network.networkId].token,
2752
+ nonce,
2753
+ gas_token: currentConfig.token,
2745
2754
  gas_limit: "3000",
2746
- nonce
2755
+ use_near_pay_gas: false
2747
2756
  };
2757
+ const availableBalance = parseFloat(accountInfo.available_balance) / __pow(10, 24);
2758
+ if (availableBalance > 0.2) {
2759
+ intention.use_near_pay_gas = true;
2760
+ }
2748
2761
  const strIntention = JSON.stringify(intention);
2749
2762
  const signature = yield btcContext.signMessage(strIntention);
2750
- const result = yield uploadBTCTx(options.network.networkId, {
2763
+ const result = yield uploadBTCTx(currentConfig.base_url, {
2751
2764
  sig: signature,
2752
2765
  btcPubKey: state.getBtcPublicKey(),
2753
2766
  data: toHex(strIntention)
@@ -2781,24 +2794,24 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
2781
2794
  }
2782
2795
  return wallet;
2783
2796
  });
2784
- function getNonceFromApi(network, accountId) {
2785
- return fetch(`${config[network].base_url}/nonce?csna=${accountId}`, {
2797
+ function getNonceFromApi(url, accountId) {
2798
+ return fetch(`${url}/nonce?csna=${accountId}`, {
2786
2799
  method: "GET",
2787
2800
  headers: {
2788
2801
  "Content-Type": "application/json"
2789
2802
  }
2790
2803
  }).then((res) => res.json());
2791
2804
  }
2792
- function getNearNonceFromApi(network, accountId) {
2793
- return fetch(`${config[network].base_url}/nonceNear?csna=${accountId}`, {
2805
+ function getNearNonceFromApi(url, accountId) {
2806
+ return fetch(`${url}/nonceNear?csna=${accountId}`, {
2794
2807
  method: "GET",
2795
2808
  headers: {
2796
2809
  "Content-Type": "application/json"
2797
2810
  }
2798
2811
  }).then((res) => res.json());
2799
2812
  }
2800
- function uploadBTCTx(network, data) {
2801
- return fetch(`${config[network].base_url}/receiveTransaction`, {
2813
+ function uploadBTCTx(url, data) {
2814
+ return fetch(`${url}/receiveTransaction`, {
2802
2815
  method: "POST",
2803
2816
  headers: {
2804
2817
  "Content-Type": "application/json"
@@ -2882,7 +2895,7 @@ function pollTransactionStatuses(network, hashes) {
2882
2895
 
2883
2896
  // src/index.ts
2884
2897
  var getVersion = () => {
2885
- return "0.1.9";
2898
+ return "0.2.1";
2886
2899
  };
2887
2900
  if (typeof window !== "undefined") {
2888
2901
  window.__PARTICLE_BTC_CONNECT_VERSION = getVersion();