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 +26 -13
- package/dist/index.js.map +2 -2
- package/dist/utils/setupBTCWallet.d.ts +1 -0
- package/esm/index.js +26 -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* () {
|
@@ -2527,6 +2534,7 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
2527
2534
|
const context = btcContext.getContext();
|
2528
2535
|
context.on("updatePublicKey", (btcPublicKey) => __async(void 0, null, function* () {
|
2529
2536
|
const { nearTempAddress } = yield getNearAccountByBtcPublicKey(btcPublicKey);
|
2537
|
+
removeWalletButton();
|
2530
2538
|
initWalletButton(options.network.networkId, wallet);
|
2531
2539
|
emitter.emit("accountsChanged", {
|
2532
2540
|
accounts: [
|
@@ -2552,7 +2560,7 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
2552
2560
|
return __async(this, arguments, function* ({ method, args = {} }) {
|
2553
2561
|
const res = yield provider.query({
|
2554
2562
|
request_type: "call_function",
|
2555
|
-
account_id:
|
2563
|
+
account_id: currentConfig.contractId,
|
2556
2564
|
method_name: method,
|
2557
2565
|
args_base64: Buffer.from(JSON.stringify(args)).toString("base64"),
|
2558
2566
|
finality: "optimistic"
|
@@ -2655,7 +2663,7 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
2655
2663
|
nonce: BigInt(rawAccessKey.nonce || 0)
|
2656
2664
|
});
|
2657
2665
|
const publicKeyFormat = PublicKey.from(publicKey);
|
2658
|
-
const nearNonceApi = yield getNearNonceFromApi(
|
2666
|
+
const nearNonceApi = yield getNearNonceFromApi(currentConfig.base_url, accountId);
|
2659
2667
|
const newTransactions = params.transactions.map((transaction, index) => {
|
2660
2668
|
let nearNonceNumber = accessKey.nonce + BigInt(1);
|
2661
2669
|
if (nearNonceApi) {
|
@@ -2694,19 +2702,24 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
2694
2702
|
method: "get_account",
|
2695
2703
|
args: { account_id: accountId }
|
2696
2704
|
});
|
2697
|
-
const nonceApi = yield getNonceFromApi(
|
2705
|
+
const nonceApi = yield getNonceFromApi(currentConfig.base_url, accountId);
|
2698
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);
|
2699
2707
|
const intention = {
|
2700
2708
|
chain_id: "397",
|
2701
2709
|
csna: accountId,
|
2702
2710
|
near_transactions: newTransactions.map((t) => t.txHex),
|
2703
|
-
|
2711
|
+
nonce,
|
2712
|
+
gas_token: currentConfig.token,
|
2704
2713
|
gas_limit: "3000",
|
2705
|
-
|
2714
|
+
use_near_pay_gas: false
|
2706
2715
|
};
|
2716
|
+
const availableBalance = parseFloat(accountInfo.available_balance) / __pow(10, 24);
|
2717
|
+
if (availableBalance > 0.2) {
|
2718
|
+
intention.use_near_pay_gas = true;
|
2719
|
+
}
|
2707
2720
|
const strIntention = JSON.stringify(intention);
|
2708
2721
|
const signature = yield btcContext.signMessage(strIntention);
|
2709
|
-
const result = yield uploadBTCTx(
|
2722
|
+
const result = yield uploadBTCTx(currentConfig.base_url, {
|
2710
2723
|
sig: signature,
|
2711
2724
|
btcPubKey: state.getBtcPublicKey(),
|
2712
2725
|
data: toHex(strIntention)
|
@@ -2740,24 +2753,24 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
2740
2753
|
}
|
2741
2754
|
return wallet;
|
2742
2755
|
});
|
2743
|
-
function getNonceFromApi(
|
2744
|
-
return fetch(`${
|
2756
|
+
function getNonceFromApi(url, accountId) {
|
2757
|
+
return fetch(`${url}/nonce?csna=${accountId}`, {
|
2745
2758
|
method: "GET",
|
2746
2759
|
headers: {
|
2747
2760
|
"Content-Type": "application/json"
|
2748
2761
|
}
|
2749
2762
|
}).then((res) => res.json());
|
2750
2763
|
}
|
2751
|
-
function getNearNonceFromApi(
|
2752
|
-
return fetch(`${
|
2764
|
+
function getNearNonceFromApi(url, accountId) {
|
2765
|
+
return fetch(`${url}/nonceNear?csna=${accountId}`, {
|
2753
2766
|
method: "GET",
|
2754
2767
|
headers: {
|
2755
2768
|
"Content-Type": "application/json"
|
2756
2769
|
}
|
2757
2770
|
}).then((res) => res.json());
|
2758
2771
|
}
|
2759
|
-
function uploadBTCTx(
|
2760
|
-
return fetch(`${
|
2772
|
+
function uploadBTCTx(url, data) {
|
2773
|
+
return fetch(`${url}/receiveTransaction`, {
|
2761
2774
|
method: "POST",
|
2762
2775
|
headers: {
|
2763
2776
|
"Content-Type": "application/json"
|
@@ -2841,7 +2854,7 @@ function pollTransactionStatuses(network, hashes) {
|
|
2841
2854
|
|
2842
2855
|
// src/index.ts
|
2843
2856
|
var getVersion = () => {
|
2844
|
-
return "0.1
|
2857
|
+
return "0.2.1";
|
2845
2858
|
};
|
2846
2859
|
if (typeof window !== "undefined") {
|
2847
2860
|
window.__PARTICLE_BTC_CONNECT_VERSION = getVersion();
|