btc-wallet 0.0.7 → 0.0.9
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 +47 -34
- package/dist/index.js.map +3 -3
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/initWalletButton.d.ts +5 -3
- package/esm/index.js +47 -34
- package/esm/index.js.map +3 -3
- package/package.json +1 -1
package/dist/index.js
CHANGED
@@ -1127,6 +1127,7 @@ var checkBTCVersion = (accountContracts, accountContractKey, version) => {
|
|
1127
1127
|
}
|
1128
1128
|
return accountContracts[accountContractKey].some((item) => item.version === version);
|
1129
1129
|
};
|
1130
|
+
var delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
1130
1131
|
|
1131
1132
|
// src/utils/ethereumUtils.ts
|
1132
1133
|
var import_util2 = require("@ethereumjs/util");
|
@@ -2357,8 +2358,10 @@ var import_js_sha256 = require("js-sha256");
|
|
2357
2358
|
|
2358
2359
|
// src/utils/initWalletButton.ts
|
2359
2360
|
function setupWalletButton(network, wallet, originalWallet) {
|
2360
|
-
if (document.getElementById("satoshi-wallet-button"))
|
2361
|
+
if (document.getElementById("satoshi-wallet-button")) {
|
2362
|
+
sendInitializeData(wallet, originalWallet);
|
2361
2363
|
return;
|
2364
|
+
}
|
2362
2365
|
const iframe = createIframe({
|
2363
2366
|
iframeUrl: network === "testnet" ? "https://wallet-dev.satoshibridge.top" : "https://wallet.satoshibridge.top",
|
2364
2367
|
iframeStyle: { width: "400px", height: "650px" }
|
@@ -2425,33 +2428,45 @@ function createIframe({
|
|
2425
2428
|
document.body.appendChild(iframe);
|
2426
2429
|
return iframe;
|
2427
2430
|
}
|
2428
|
-
function
|
2431
|
+
function sendInitializeData(wallet, originalWallet) {
|
2429
2432
|
return __async(this, null, function* () {
|
2430
|
-
var _a;
|
2433
|
+
var _a, _b;
|
2434
|
+
yield delay(1e3);
|
2431
2435
|
const accountId = (_a = yield wallet == null ? void 0 : wallet.getAccounts()) == null ? void 0 : _a[0].accountId;
|
2432
2436
|
const originalAccountId = originalWallet.account;
|
2433
2437
|
const originalPublicKey = yield originalWallet.getPublicKey();
|
2438
|
+
const iframe = document.getElementById("satoshi-wallet-iframe");
|
2439
|
+
if ((iframe == null ? void 0 : iframe.contentWindow) && ((_b = iframe.contentDocument) == null ? void 0 : _b.readyState) === "complete") {
|
2440
|
+
iframe.contentWindow.postMessage({
|
2441
|
+
action: "initializeData",
|
2442
|
+
success: true,
|
2443
|
+
data: {
|
2444
|
+
accountId,
|
2445
|
+
originalAccountId,
|
2446
|
+
originalPublicKey
|
2447
|
+
}
|
2448
|
+
});
|
2449
|
+
}
|
2450
|
+
});
|
2451
|
+
}
|
2452
|
+
function setupButtonClickHandler(button, iframe, wallet, originalWallet) {
|
2453
|
+
return __async(this, null, function* () {
|
2454
|
+
iframe.onload = () => sendInitializeData(wallet, originalWallet);
|
2434
2455
|
const iframeSrc = new URL(iframe.src);
|
2435
2456
|
iframeSrc.searchParams.set("origin", window.location.origin);
|
2436
|
-
if (accountId)
|
2437
|
-
iframeSrc.searchParams.set("accountId", accountId);
|
2438
|
-
if (originalAccountId)
|
2439
|
-
iframeSrc.searchParams.set("originalAccountId", originalAccountId);
|
2440
|
-
if (originalPublicKey)
|
2441
|
-
iframeSrc.searchParams.set("originalPublicKey", originalPublicKey);
|
2442
2457
|
iframe.src = iframeSrc.toString();
|
2443
2458
|
window.addEventListener("message", (event) => __async(this, null, function* () {
|
2444
|
-
var
|
2459
|
+
var _a, _b;
|
2445
2460
|
if (event.origin !== iframeSrc.origin)
|
2446
2461
|
return;
|
2447
|
-
const { action, requestId,
|
2462
|
+
const { action, requestId, data } = event.data;
|
2448
2463
|
if (action === "signAndSendTransaction") {
|
2449
2464
|
try {
|
2450
|
-
const result = yield wallet.signAndSendTransaction(
|
2451
|
-
(
|
2465
|
+
const result = yield wallet.signAndSendTransaction(data);
|
2466
|
+
(_a = event.source) == null ? void 0 : _a.postMessage(
|
2452
2467
|
{
|
2453
2468
|
requestId,
|
2454
|
-
|
2469
|
+
data,
|
2455
2470
|
success: true
|
2456
2471
|
},
|
2457
2472
|
{ targetOrigin: event.origin }
|
@@ -2557,11 +2572,8 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
2557
2572
|
const accountId = state.getAccount();
|
2558
2573
|
initWalletButton(options.network.networkId, accountId, wallet);
|
2559
2574
|
context.on("updatePublicKey", (btcPublicKey) => __async(void 0, null, function* () {
|
2560
|
-
const { nearTempAddress
|
2561
|
-
|
2562
|
-
setTimeout(() => {
|
2563
|
-
initWalletButton(options.network.networkId, nearTempAddress, wallet);
|
2564
|
-
}, 1e3);
|
2575
|
+
const { nearTempAddress } = yield getNearAccountByBtcPublicKey(btcPublicKey);
|
2576
|
+
initWalletButton(options.network.networkId, nearTempAddress, wallet);
|
2565
2577
|
emitter.emit("accountsChanged", {
|
2566
2578
|
accounts: [
|
2567
2579
|
{
|
@@ -2576,7 +2588,7 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
2576
2588
|
});
|
2577
2589
|
}));
|
2578
2590
|
if ("autoConnect" in metadata && metadata.autoConnect && localStorage.getItem("near-wallet-selector:selectedWalletId") === '"btc-wallet"') {
|
2579
|
-
btcContext.autoConnect();
|
2591
|
+
yield btcContext.autoConnect();
|
2580
2592
|
}
|
2581
2593
|
clearInterval(inter);
|
2582
2594
|
}
|
@@ -2629,6 +2641,7 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
2629
2641
|
const btcAccount = yield btcContext.login();
|
2630
2642
|
const btcPublicKey = yield btcContext.getPublicKey();
|
2631
2643
|
const { nearTempAddress, nearTempPublicKey } = yield getNearAccountByBtcPublicKey(btcPublicKey);
|
2644
|
+
initWalletButton(options.network.networkId, accountId, wallet);
|
2632
2645
|
return [
|
2633
2646
|
{
|
2634
2647
|
accountId: nearTempAddress,
|
@@ -2812,17 +2825,20 @@ function toHex(originalString) {
|
|
2812
2825
|
return hexString;
|
2813
2826
|
}
|
2814
2827
|
function initWalletButton(network, accountId, wallet) {
|
2815
|
-
|
2816
|
-
|
2817
|
-
|
2818
|
-
|
2819
|
-
|
2820
|
-
|
2828
|
+
return __async(this, null, function* () {
|
2829
|
+
yield delay(2e3);
|
2830
|
+
const checkAndSetupWalletButton = () => {
|
2831
|
+
if (accountId && window.btcContext.account) {
|
2832
|
+
setupWalletButton(network, wallet, window.btcContext);
|
2833
|
+
} else {
|
2834
|
+
removeWalletButton();
|
2835
|
+
}
|
2836
|
+
!window.btcContext.account && setTimeout(() => {
|
2821
2837
|
checkAndSetupWalletButton();
|
2822
|
-
},
|
2823
|
-
}
|
2824
|
-
|
2825
|
-
|
2838
|
+
}, 1e4);
|
2839
|
+
};
|
2840
|
+
checkAndSetupWalletButton();
|
2841
|
+
});
|
2826
2842
|
}
|
2827
2843
|
var rcpUrls = {
|
2828
2844
|
mainnet: [
|
@@ -2837,9 +2853,6 @@ var rcpUrls = {
|
|
2837
2853
|
"https://near-testnet.drpc.org"
|
2838
2854
|
]
|
2839
2855
|
};
|
2840
|
-
function delay(ms) {
|
2841
|
-
return new Promise((resolve) => setTimeout(resolve, ms));
|
2842
|
-
}
|
2843
2856
|
function pollTransactionStatuses(network, hashes) {
|
2844
2857
|
return __async(this, null, function* () {
|
2845
2858
|
const provider = new import_near_api_js.providers.FailoverRpcProvider(
|
@@ -2872,7 +2885,7 @@ function pollTransactionStatuses(network, hashes) {
|
|
2872
2885
|
|
2873
2886
|
// src/index.ts
|
2874
2887
|
var getVersion = () => {
|
2875
|
-
return "0.0.
|
2888
|
+
return "0.0.9";
|
2876
2889
|
};
|
2877
2890
|
if (typeof window !== "undefined") {
|
2878
2891
|
window.__PARTICLE_BTC_CONNECT_VERSION = getVersion();
|