btc-wallet 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/index.js +25 -13
- package/dist/index.js.map +2 -2
- package/dist/utils/setupBTCWallet.d.ts +1 -0
- package/esm/index.js +25 -13
- package/esm/index.js.map +2 -2
- package/package.json +1 -1
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* () {
|
@@ -2594,7 +2601,7 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
2594
2601
|
return __async(this, arguments, function* ({ method, args = {} }) {
|
2595
2602
|
const res = yield provider.query({
|
2596
2603
|
request_type: "call_function",
|
2597
|
-
account_id:
|
2604
|
+
account_id: currentConfig.contractId,
|
2598
2605
|
method_name: method,
|
2599
2606
|
args_base64: Buffer.from(JSON.stringify(args)).toString("base64"),
|
2600
2607
|
finality: "optimistic"
|
@@ -2697,7 +2704,7 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
2697
2704
|
nonce: BigInt(rawAccessKey.nonce || 0)
|
2698
2705
|
});
|
2699
2706
|
const publicKeyFormat = import_key_pair.PublicKey.from(publicKey);
|
2700
|
-
const nearNonceApi = yield getNearNonceFromApi(
|
2707
|
+
const nearNonceApi = yield getNearNonceFromApi(currentConfig.base_url, accountId);
|
2701
2708
|
const newTransactions = params.transactions.map((transaction, index) => {
|
2702
2709
|
let nearNonceNumber = accessKey.nonce + BigInt(1);
|
2703
2710
|
if (nearNonceApi) {
|
@@ -2736,19 +2743,24 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
2736
2743
|
method: "get_account",
|
2737
2744
|
args: { account_id: accountId }
|
2738
2745
|
});
|
2739
|
-
const nonceApi = yield getNonceFromApi(
|
2746
|
+
const nonceApi = yield getNonceFromApi(currentConfig.base_url, accountId);
|
2740
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);
|
2741
2748
|
const intention = {
|
2742
2749
|
chain_id: "397",
|
2743
2750
|
csna: accountId,
|
2744
2751
|
near_transactions: newTransactions.map((t) => t.txHex),
|
2745
|
-
|
2752
|
+
nonce,
|
2753
|
+
gas_token: currentConfig.token,
|
2746
2754
|
gas_limit: "3000",
|
2747
|
-
|
2755
|
+
use_near_pay_gas: false
|
2748
2756
|
};
|
2757
|
+
const availableBalance = parseFloat(accountInfo.available_balance) / __pow(10, 24);
|
2758
|
+
if (availableBalance > 0.2) {
|
2759
|
+
intention.use_near_pay_gas = true;
|
2760
|
+
}
|
2749
2761
|
const strIntention = JSON.stringify(intention);
|
2750
2762
|
const signature = yield btcContext.signMessage(strIntention);
|
2751
|
-
const result = yield uploadBTCTx(
|
2763
|
+
const result = yield uploadBTCTx(currentConfig.base_url, {
|
2752
2764
|
sig: signature,
|
2753
2765
|
btcPubKey: state.getBtcPublicKey(),
|
2754
2766
|
data: toHex(strIntention)
|
@@ -2782,24 +2794,24 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
2782
2794
|
}
|
2783
2795
|
return wallet;
|
2784
2796
|
});
|
2785
|
-
function getNonceFromApi(
|
2786
|
-
return fetch(`${
|
2797
|
+
function getNonceFromApi(url, accountId) {
|
2798
|
+
return fetch(`${url}/nonce?csna=${accountId}`, {
|
2787
2799
|
method: "GET",
|
2788
2800
|
headers: {
|
2789
2801
|
"Content-Type": "application/json"
|
2790
2802
|
}
|
2791
2803
|
}).then((res) => res.json());
|
2792
2804
|
}
|
2793
|
-
function getNearNonceFromApi(
|
2794
|
-
return fetch(`${
|
2805
|
+
function getNearNonceFromApi(url, accountId) {
|
2806
|
+
return fetch(`${url}/nonceNear?csna=${accountId}`, {
|
2795
2807
|
method: "GET",
|
2796
2808
|
headers: {
|
2797
2809
|
"Content-Type": "application/json"
|
2798
2810
|
}
|
2799
2811
|
}).then((res) => res.json());
|
2800
2812
|
}
|
2801
|
-
function uploadBTCTx(
|
2802
|
-
return fetch(`${
|
2813
|
+
function uploadBTCTx(url, data) {
|
2814
|
+
return fetch(`${url}/receiveTransaction`, {
|
2803
2815
|
method: "POST",
|
2804
2816
|
headers: {
|
2805
2817
|
"Content-Type": "application/json"
|
@@ -2883,7 +2895,7 @@ function pollTransactionStatuses(network, hashes) {
|
|
2883
2895
|
|
2884
2896
|
// src/index.ts
|
2885
2897
|
var getVersion = () => {
|
2886
|
-
return "0.2.
|
2898
|
+
return "0.2.1";
|
2887
2899
|
};
|
2888
2900
|
if (typeof window !== "undefined") {
|
2889
2901
|
window.__PARTICLE_BTC_CONNECT_VERSION = getVersion();
|