btc-wallet 0.2.0 → 0.2.1
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.
- 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
@@ -9,6 +9,7 @@ interface BTCWalletParams {
|
|
9
9
|
iconUrl?: string;
|
10
10
|
deprecated?: boolean;
|
11
11
|
autoConnect?: boolean;
|
12
|
+
isDev?: boolean;
|
12
13
|
}
|
13
14
|
export declare function setupBTCWallet({ iconUrl, deprecated, autoConnect, }?: BTCWalletParams | undefined): WalletModuleFactory<InjectedWallet>;
|
14
15
|
declare const _default: {
|
package/esm/index.js
CHANGED
@@ -5,6 +5,7 @@ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
5
5
|
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
6
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
7
7
|
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
8
|
+
var __pow = Math.pow;
|
8
9
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
9
10
|
var __spreadValues = (a, b) => {
|
10
11
|
for (var prop in b || (b = {}))
|
@@ -2450,6 +2451,11 @@ function removeWalletButton() {
|
|
2450
2451
|
// src/utils/setupBTCWallet.ts
|
2451
2452
|
var { transfer, functionCall } = actionCreators;
|
2452
2453
|
var config = {
|
2454
|
+
dev: {
|
2455
|
+
base_url: "https://api.dev.satoshibridge.top/v1",
|
2456
|
+
token: "nbtc1-nsp.dev",
|
2457
|
+
contractId: "dev1-nsp.dev"
|
2458
|
+
},
|
2453
2459
|
testnet: {
|
2454
2460
|
base_url: "https://api.testnet.satoshibridge.top/v1",
|
2455
2461
|
token: "nbtc2-nsp.testnet",
|
@@ -2518,6 +2524,7 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
2518
2524
|
signAndSendTransaction,
|
2519
2525
|
signAndSendTransactions
|
2520
2526
|
};
|
2527
|
+
const currentConfig = "isDev" in metadata && metadata.isDev ? config.dev : config[options.network.networkId];
|
2521
2528
|
initWalletButton(options.network.networkId, wallet);
|
2522
2529
|
if (!inter) {
|
2523
2530
|
inter = setInterval(() => __async(void 0, null, function* () {
|
@@ -2553,7 +2560,7 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
2553
2560
|
return __async(this, arguments, function* ({ method, args = {} }) {
|
2554
2561
|
const res = yield provider.query({
|
2555
2562
|
request_type: "call_function",
|
2556
|
-
account_id:
|
2563
|
+
account_id: currentConfig.contractId,
|
2557
2564
|
method_name: method,
|
2558
2565
|
args_base64: Buffer.from(JSON.stringify(args)).toString("base64"),
|
2559
2566
|
finality: "optimistic"
|
@@ -2656,7 +2663,7 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
2656
2663
|
nonce: BigInt(rawAccessKey.nonce || 0)
|
2657
2664
|
});
|
2658
2665
|
const publicKeyFormat = PublicKey.from(publicKey);
|
2659
|
-
const nearNonceApi = yield getNearNonceFromApi(
|
2666
|
+
const nearNonceApi = yield getNearNonceFromApi(currentConfig.base_url, accountId);
|
2660
2667
|
const newTransactions = params.transactions.map((transaction, index) => {
|
2661
2668
|
let nearNonceNumber = accessKey.nonce + BigInt(1);
|
2662
2669
|
if (nearNonceApi) {
|
@@ -2695,19 +2702,24 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
2695
2702
|
method: "get_account",
|
2696
2703
|
args: { account_id: accountId }
|
2697
2704
|
});
|
2698
|
-
const nonceApi = yield getNonceFromApi(
|
2705
|
+
const nonceApi = yield getNonceFromApi(currentConfig.base_url, accountId);
|
2699
2706
|
const nonce = Number(nonceApi == null ? void 0 : nonceApi.result_data) > Number(accountInfo.nonce) ? String(nonceApi == null ? void 0 : nonceApi.result_data) : String(accountInfo.nonce);
|
2700
2707
|
const intention = {
|
2701
2708
|
chain_id: "397",
|
2702
2709
|
csna: accountId,
|
2703
2710
|
near_transactions: newTransactions.map((t) => t.txHex),
|
2704
|
-
|
2711
|
+
nonce,
|
2712
|
+
gas_token: currentConfig.token,
|
2705
2713
|
gas_limit: "3000",
|
2706
|
-
|
2714
|
+
use_near_pay_gas: false
|
2707
2715
|
};
|
2716
|
+
const availableBalance = parseFloat(accountInfo.available_balance) / __pow(10, 24);
|
2717
|
+
if (availableBalance > 0.2) {
|
2718
|
+
intention.use_near_pay_gas = true;
|
2719
|
+
}
|
2708
2720
|
const strIntention = JSON.stringify(intention);
|
2709
2721
|
const signature = yield btcContext.signMessage(strIntention);
|
2710
|
-
const result = yield uploadBTCTx(
|
2722
|
+
const result = yield uploadBTCTx(currentConfig.base_url, {
|
2711
2723
|
sig: signature,
|
2712
2724
|
btcPubKey: state.getBtcPublicKey(),
|
2713
2725
|
data: toHex(strIntention)
|
@@ -2741,24 +2753,24 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
2741
2753
|
}
|
2742
2754
|
return wallet;
|
2743
2755
|
});
|
2744
|
-
function getNonceFromApi(
|
2745
|
-
return fetch(`${
|
2756
|
+
function getNonceFromApi(url, accountId) {
|
2757
|
+
return fetch(`${url}/nonce?csna=${accountId}`, {
|
2746
2758
|
method: "GET",
|
2747
2759
|
headers: {
|
2748
2760
|
"Content-Type": "application/json"
|
2749
2761
|
}
|
2750
2762
|
}).then((res) => res.json());
|
2751
2763
|
}
|
2752
|
-
function getNearNonceFromApi(
|
2753
|
-
return fetch(`${
|
2764
|
+
function getNearNonceFromApi(url, accountId) {
|
2765
|
+
return fetch(`${url}/nonceNear?csna=${accountId}`, {
|
2754
2766
|
method: "GET",
|
2755
2767
|
headers: {
|
2756
2768
|
"Content-Type": "application/json"
|
2757
2769
|
}
|
2758
2770
|
}).then((res) => res.json());
|
2759
2771
|
}
|
2760
|
-
function uploadBTCTx(
|
2761
|
-
return fetch(`${
|
2772
|
+
function uploadBTCTx(url, data) {
|
2773
|
+
return fetch(`${url}/receiveTransaction`, {
|
2762
2774
|
method: "POST",
|
2763
2775
|
headers: {
|
2764
2776
|
"Content-Type": "application/json"
|
@@ -2842,7 +2854,7 @@ function pollTransactionStatuses(network, hashes) {
|
|
2842
2854
|
|
2843
2855
|
// src/index.ts
|
2844
2856
|
var getVersion = () => {
|
2845
|
-
return "0.2.
|
2857
|
+
return "0.2.1";
|
2846
2858
|
};
|
2847
2859
|
if (typeof window !== "undefined") {
|
2848
2860
|
window.__PARTICLE_BTC_CONNECT_VERSION = getVersion();
|