btc-wallet 0.2.0 → 0.2.2
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 +35 -17
- package/dist/index.js.map +2 -2
- package/dist/utils/setupBTCWallet.d.ts +1 -0
- package/esm/index.js +35 -17
- 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 = {}))
|
@@ -2357,12 +2358,17 @@ var import_bs58 = __toESM(require("bs58"), 1);
|
|
2357
2358
|
var import_js_sha256 = require("js-sha256");
|
2358
2359
|
|
2359
2360
|
// src/utils/initWalletButton.ts
|
2361
|
+
var walletUrlConfig = {
|
2362
|
+
dev: "https://wallet-dev.satoshibridge.top",
|
2363
|
+
testnet: "https://wallet-test.satoshibridge.top",
|
2364
|
+
mainnet: "https://wallet.satoshibridge.top"
|
2365
|
+
};
|
2360
2366
|
function setupWalletButton(network, wallet, originalWallet) {
|
2361
2367
|
if (document.getElementById("satoshi-wallet-button")) {
|
2362
2368
|
return;
|
2363
2369
|
}
|
2364
2370
|
const iframe = createIframe({
|
2365
|
-
iframeUrl: network
|
2371
|
+
iframeUrl: walletUrlConfig[network],
|
2366
2372
|
iframeStyle: { width: "400px", height: "650px" }
|
2367
2373
|
});
|
2368
2374
|
iframe.addEventListener("mouseenter", () => {
|
@@ -2491,6 +2497,11 @@ function removeWalletButton() {
|
|
2491
2497
|
// src/utils/setupBTCWallet.ts
|
2492
2498
|
var { transfer, functionCall } = import_transactions.actionCreators;
|
2493
2499
|
var config = {
|
2500
|
+
dev: {
|
2501
|
+
base_url: "https://api.dev.satoshibridge.top/v1",
|
2502
|
+
token: "nbtc1-nsp.dev",
|
2503
|
+
contractId: "dev1-nsp.dev"
|
2504
|
+
},
|
2494
2505
|
testnet: {
|
2495
2506
|
base_url: "https://api.testnet.satoshibridge.top/v1",
|
2496
2507
|
token: "nbtc2-nsp.testnet",
|
@@ -2559,7 +2570,9 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
2559
2570
|
signAndSendTransaction,
|
2560
2571
|
signAndSendTransactions
|
2561
2572
|
};
|
2562
|
-
|
2573
|
+
const currentConfig = "isDev" in metadata && metadata.isDev ? config.dev : config[options.network.networkId];
|
2574
|
+
const walletNetwork = "isDev" in metadata && metadata.isDev ? "dev" : options.network.networkId;
|
2575
|
+
initWalletButton(walletNetwork, wallet);
|
2563
2576
|
if (!inter) {
|
2564
2577
|
inter = setInterval(() => __async(void 0, null, function* () {
|
2565
2578
|
const btcContext = window.btcContext;
|
@@ -2569,7 +2582,7 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
2569
2582
|
context.on("updatePublicKey", (btcPublicKey) => __async(void 0, null, function* () {
|
2570
2583
|
const { nearTempAddress } = yield getNearAccountByBtcPublicKey(btcPublicKey);
|
2571
2584
|
removeWalletButton();
|
2572
|
-
initWalletButton(
|
2585
|
+
initWalletButton(walletNetwork, wallet);
|
2573
2586
|
emitter.emit("accountsChanged", {
|
2574
2587
|
accounts: [
|
2575
2588
|
{
|
@@ -2594,7 +2607,7 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
2594
2607
|
return __async(this, arguments, function* ({ method, args = {} }) {
|
2595
2608
|
const res = yield provider.query({
|
2596
2609
|
request_type: "call_function",
|
2597
|
-
account_id:
|
2610
|
+
account_id: currentConfig.contractId,
|
2598
2611
|
method_name: method,
|
2599
2612
|
args_base64: Buffer.from(JSON.stringify(args)).toString("base64"),
|
2600
2613
|
finality: "optimistic"
|
@@ -2626,7 +2639,7 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
2626
2639
|
const accountId = state.getAccount();
|
2627
2640
|
const publicKey = state.getPublicKey();
|
2628
2641
|
const btcContext = window.btcContext;
|
2629
|
-
initWalletButton(
|
2642
|
+
initWalletButton(walletNetwork, wallet);
|
2630
2643
|
if (accountId && publicKey) {
|
2631
2644
|
return [
|
2632
2645
|
{
|
@@ -2697,7 +2710,7 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
2697
2710
|
nonce: BigInt(rawAccessKey.nonce || 0)
|
2698
2711
|
});
|
2699
2712
|
const publicKeyFormat = import_key_pair.PublicKey.from(publicKey);
|
2700
|
-
const nearNonceApi = yield getNearNonceFromApi(
|
2713
|
+
const nearNonceApi = yield getNearNonceFromApi(currentConfig.base_url, accountId);
|
2701
2714
|
const newTransactions = params.transactions.map((transaction, index) => {
|
2702
2715
|
let nearNonceNumber = accessKey.nonce + BigInt(1);
|
2703
2716
|
if (nearNonceApi) {
|
@@ -2736,19 +2749,24 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
2736
2749
|
method: "get_account",
|
2737
2750
|
args: { account_id: accountId }
|
2738
2751
|
});
|
2739
|
-
const nonceApi = yield getNonceFromApi(
|
2752
|
+
const nonceApi = yield getNonceFromApi(currentConfig.base_url, accountId);
|
2740
2753
|
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
2754
|
const intention = {
|
2742
2755
|
chain_id: "397",
|
2743
2756
|
csna: accountId,
|
2744
2757
|
near_transactions: newTransactions.map((t) => t.txHex),
|
2745
|
-
|
2758
|
+
nonce,
|
2759
|
+
gas_token: currentConfig.token,
|
2746
2760
|
gas_limit: "3000",
|
2747
|
-
|
2761
|
+
use_near_pay_gas: false
|
2748
2762
|
};
|
2763
|
+
const availableBalance = parseFloat(accountInfo.available_balance) / __pow(10, 24);
|
2764
|
+
if (availableBalance > 0.2) {
|
2765
|
+
intention.use_near_pay_gas = true;
|
2766
|
+
}
|
2749
2767
|
const strIntention = JSON.stringify(intention);
|
2750
2768
|
const signature = yield btcContext.signMessage(strIntention);
|
2751
|
-
const result = yield uploadBTCTx(
|
2769
|
+
const result = yield uploadBTCTx(currentConfig.base_url, {
|
2752
2770
|
sig: signature,
|
2753
2771
|
btcPubKey: state.getBtcPublicKey(),
|
2754
2772
|
data: toHex(strIntention)
|
@@ -2782,24 +2800,24 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
2782
2800
|
}
|
2783
2801
|
return wallet;
|
2784
2802
|
});
|
2785
|
-
function getNonceFromApi(
|
2786
|
-
return fetch(`${
|
2803
|
+
function getNonceFromApi(url, accountId) {
|
2804
|
+
return fetch(`${url}/nonce?csna=${accountId}`, {
|
2787
2805
|
method: "GET",
|
2788
2806
|
headers: {
|
2789
2807
|
"Content-Type": "application/json"
|
2790
2808
|
}
|
2791
2809
|
}).then((res) => res.json());
|
2792
2810
|
}
|
2793
|
-
function getNearNonceFromApi(
|
2794
|
-
return fetch(`${
|
2811
|
+
function getNearNonceFromApi(url, accountId) {
|
2812
|
+
return fetch(`${url}/nonceNear?csna=${accountId}`, {
|
2795
2813
|
method: "GET",
|
2796
2814
|
headers: {
|
2797
2815
|
"Content-Type": "application/json"
|
2798
2816
|
}
|
2799
2817
|
}).then((res) => res.json());
|
2800
2818
|
}
|
2801
|
-
function uploadBTCTx(
|
2802
|
-
return fetch(`${
|
2819
|
+
function uploadBTCTx(url, data) {
|
2820
|
+
return fetch(`${url}/receiveTransaction`, {
|
2803
2821
|
method: "POST",
|
2804
2822
|
headers: {
|
2805
2823
|
"Content-Type": "application/json"
|
@@ -2883,7 +2901,7 @@ function pollTransactionStatuses(network, hashes) {
|
|
2883
2901
|
|
2884
2902
|
// src/index.ts
|
2885
2903
|
var getVersion = () => {
|
2886
|
-
return "0.2.
|
2904
|
+
return "0.2.2";
|
2887
2905
|
};
|
2888
2906
|
if (typeof window !== "undefined") {
|
2889
2907
|
window.__PARTICLE_BTC_CONNECT_VERSION = getVersion();
|