btc-wallet 0.2.0 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- 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
@@ -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 = {}))
|
@@ -2316,12 +2317,17 @@ import bs58 from "bs58";
|
|
2316
2317
|
import { sha256 } from "js-sha256";
|
2317
2318
|
|
2318
2319
|
// src/utils/initWalletButton.ts
|
2320
|
+
var walletUrlConfig = {
|
2321
|
+
dev: "https://wallet-dev.satoshibridge.top",
|
2322
|
+
testnet: "https://wallet-test.satoshibridge.top",
|
2323
|
+
mainnet: "https://wallet.satoshibridge.top"
|
2324
|
+
};
|
2319
2325
|
function setupWalletButton(network, wallet, originalWallet) {
|
2320
2326
|
if (document.getElementById("satoshi-wallet-button")) {
|
2321
2327
|
return;
|
2322
2328
|
}
|
2323
2329
|
const iframe = createIframe({
|
2324
|
-
iframeUrl: network
|
2330
|
+
iframeUrl: walletUrlConfig[network],
|
2325
2331
|
iframeStyle: { width: "400px", height: "650px" }
|
2326
2332
|
});
|
2327
2333
|
iframe.addEventListener("mouseenter", () => {
|
@@ -2450,6 +2456,11 @@ function removeWalletButton() {
|
|
2450
2456
|
// src/utils/setupBTCWallet.ts
|
2451
2457
|
var { transfer, functionCall } = actionCreators;
|
2452
2458
|
var config = {
|
2459
|
+
dev: {
|
2460
|
+
base_url: "https://api.dev.satoshibridge.top/v1",
|
2461
|
+
token: "nbtc1-nsp.dev",
|
2462
|
+
contractId: "dev1-nsp.dev"
|
2463
|
+
},
|
2453
2464
|
testnet: {
|
2454
2465
|
base_url: "https://api.testnet.satoshibridge.top/v1",
|
2455
2466
|
token: "nbtc2-nsp.testnet",
|
@@ -2518,7 +2529,9 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
2518
2529
|
signAndSendTransaction,
|
2519
2530
|
signAndSendTransactions
|
2520
2531
|
};
|
2521
|
-
|
2532
|
+
const currentConfig = "isDev" in metadata && metadata.isDev ? config.dev : config[options.network.networkId];
|
2533
|
+
const walletNetwork = "isDev" in metadata && metadata.isDev ? "dev" : options.network.networkId;
|
2534
|
+
initWalletButton(walletNetwork, wallet);
|
2522
2535
|
if (!inter) {
|
2523
2536
|
inter = setInterval(() => __async(void 0, null, function* () {
|
2524
2537
|
const btcContext = window.btcContext;
|
@@ -2528,7 +2541,7 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
2528
2541
|
context.on("updatePublicKey", (btcPublicKey) => __async(void 0, null, function* () {
|
2529
2542
|
const { nearTempAddress } = yield getNearAccountByBtcPublicKey(btcPublicKey);
|
2530
2543
|
removeWalletButton();
|
2531
|
-
initWalletButton(
|
2544
|
+
initWalletButton(walletNetwork, wallet);
|
2532
2545
|
emitter.emit("accountsChanged", {
|
2533
2546
|
accounts: [
|
2534
2547
|
{
|
@@ -2553,7 +2566,7 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
2553
2566
|
return __async(this, arguments, function* ({ method, args = {} }) {
|
2554
2567
|
const res = yield provider.query({
|
2555
2568
|
request_type: "call_function",
|
2556
|
-
account_id:
|
2569
|
+
account_id: currentConfig.contractId,
|
2557
2570
|
method_name: method,
|
2558
2571
|
args_base64: Buffer.from(JSON.stringify(args)).toString("base64"),
|
2559
2572
|
finality: "optimistic"
|
@@ -2585,7 +2598,7 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
2585
2598
|
const accountId = state.getAccount();
|
2586
2599
|
const publicKey = state.getPublicKey();
|
2587
2600
|
const btcContext = window.btcContext;
|
2588
|
-
initWalletButton(
|
2601
|
+
initWalletButton(walletNetwork, wallet);
|
2589
2602
|
if (accountId && publicKey) {
|
2590
2603
|
return [
|
2591
2604
|
{
|
@@ -2656,7 +2669,7 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
2656
2669
|
nonce: BigInt(rawAccessKey.nonce || 0)
|
2657
2670
|
});
|
2658
2671
|
const publicKeyFormat = PublicKey.from(publicKey);
|
2659
|
-
const nearNonceApi = yield getNearNonceFromApi(
|
2672
|
+
const nearNonceApi = yield getNearNonceFromApi(currentConfig.base_url, accountId);
|
2660
2673
|
const newTransactions = params.transactions.map((transaction, index) => {
|
2661
2674
|
let nearNonceNumber = accessKey.nonce + BigInt(1);
|
2662
2675
|
if (nearNonceApi) {
|
@@ -2695,19 +2708,24 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
2695
2708
|
method: "get_account",
|
2696
2709
|
args: { account_id: accountId }
|
2697
2710
|
});
|
2698
|
-
const nonceApi = yield getNonceFromApi(
|
2711
|
+
const nonceApi = yield getNonceFromApi(currentConfig.base_url, accountId);
|
2699
2712
|
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
2713
|
const intention = {
|
2701
2714
|
chain_id: "397",
|
2702
2715
|
csna: accountId,
|
2703
2716
|
near_transactions: newTransactions.map((t) => t.txHex),
|
2704
|
-
|
2717
|
+
nonce,
|
2718
|
+
gas_token: currentConfig.token,
|
2705
2719
|
gas_limit: "3000",
|
2706
|
-
|
2720
|
+
use_near_pay_gas: false
|
2707
2721
|
};
|
2722
|
+
const availableBalance = parseFloat(accountInfo.available_balance) / __pow(10, 24);
|
2723
|
+
if (availableBalance > 0.2) {
|
2724
|
+
intention.use_near_pay_gas = true;
|
2725
|
+
}
|
2708
2726
|
const strIntention = JSON.stringify(intention);
|
2709
2727
|
const signature = yield btcContext.signMessage(strIntention);
|
2710
|
-
const result = yield uploadBTCTx(
|
2728
|
+
const result = yield uploadBTCTx(currentConfig.base_url, {
|
2711
2729
|
sig: signature,
|
2712
2730
|
btcPubKey: state.getBtcPublicKey(),
|
2713
2731
|
data: toHex(strIntention)
|
@@ -2741,24 +2759,24 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
2741
2759
|
}
|
2742
2760
|
return wallet;
|
2743
2761
|
});
|
2744
|
-
function getNonceFromApi(
|
2745
|
-
return fetch(`${
|
2762
|
+
function getNonceFromApi(url, accountId) {
|
2763
|
+
return fetch(`${url}/nonce?csna=${accountId}`, {
|
2746
2764
|
method: "GET",
|
2747
2765
|
headers: {
|
2748
2766
|
"Content-Type": "application/json"
|
2749
2767
|
}
|
2750
2768
|
}).then((res) => res.json());
|
2751
2769
|
}
|
2752
|
-
function getNearNonceFromApi(
|
2753
|
-
return fetch(`${
|
2770
|
+
function getNearNonceFromApi(url, accountId) {
|
2771
|
+
return fetch(`${url}/nonceNear?csna=${accountId}`, {
|
2754
2772
|
method: "GET",
|
2755
2773
|
headers: {
|
2756
2774
|
"Content-Type": "application/json"
|
2757
2775
|
}
|
2758
2776
|
}).then((res) => res.json());
|
2759
2777
|
}
|
2760
|
-
function uploadBTCTx(
|
2761
|
-
return fetch(`${
|
2778
|
+
function uploadBTCTx(url, data) {
|
2779
|
+
return fetch(`${url}/receiveTransaction`, {
|
2762
2780
|
method: "POST",
|
2763
2781
|
headers: {
|
2764
2782
|
"Content-Type": "application/json"
|
@@ -2842,7 +2860,7 @@ function pollTransactionStatuses(network, hashes) {
|
|
2842
2860
|
|
2843
2861
|
// src/index.ts
|
2844
2862
|
var getVersion = () => {
|
2845
|
-
return "0.2.
|
2863
|
+
return "0.2.2";
|
2846
2864
|
};
|
2847
2865
|
if (typeof window !== "undefined") {
|
2848
2866
|
window.__PARTICLE_BTC_CONNECT_VERSION = getVersion();
|