btc-wallet 0.1.0 → 0.1.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 +17 -35
- package/dist/index.js.map +3 -3
- package/esm/index.js +17 -35
- package/esm/index.js.map +3 -3
- package/package.json +1 -1
package/dist/index.js
CHANGED
@@ -2359,7 +2359,6 @@ var import_js_sha256 = require("js-sha256");
|
|
2359
2359
|
// src/utils/initWalletButton.ts
|
2360
2360
|
function setupWalletButton(network, wallet, originalWallet) {
|
2361
2361
|
if (document.getElementById("satoshi-wallet-button")) {
|
2362
|
-
sendInitializeData(wallet, originalWallet);
|
2363
2362
|
return;
|
2364
2363
|
}
|
2365
2364
|
const iframe = createIframe({
|
@@ -2416,6 +2415,9 @@ function createIframe({
|
|
2416
2415
|
iframe.id = "satoshi-wallet-iframe";
|
2417
2416
|
iframe.allow = "clipboard-read; clipboard-write";
|
2418
2417
|
iframe.src = iframeUrl;
|
2418
|
+
iframe.onclick = () => {
|
2419
|
+
iframe.focus();
|
2420
|
+
};
|
2419
2421
|
Object.assign(iframe.style, __spreadValues({
|
2420
2422
|
position: "fixed",
|
2421
2423
|
bottom: "90px",
|
@@ -2428,45 +2430,27 @@ function createIframe({
|
|
2428
2430
|
document.body.appendChild(iframe);
|
2429
2431
|
return iframe;
|
2430
2432
|
}
|
2431
|
-
function
|
2433
|
+
function setupButtonClickHandler(button, iframe, wallet, originalWallet) {
|
2432
2434
|
return __async(this, null, function* () {
|
2433
|
-
var _a
|
2434
|
-
yield delay(1e3);
|
2435
|
+
var _a;
|
2435
2436
|
const accountId = (_a = yield wallet == null ? void 0 : wallet.getAccounts()) == null ? void 0 : _a[0].accountId;
|
2436
2437
|
const originalAccountId = originalWallet.account;
|
2437
2438
|
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
|
-
{
|
2442
|
-
action: "initializeData",
|
2443
|
-
success: true,
|
2444
|
-
data: {
|
2445
|
-
accountId,
|
2446
|
-
originalAccountId,
|
2447
|
-
originalPublicKey
|
2448
|
-
}
|
2449
|
-
},
|
2450
|
-
{ targetOrigin: window.location.origin }
|
2451
|
-
);
|
2452
|
-
}
|
2453
|
-
});
|
2454
|
-
}
|
2455
|
-
function setupButtonClickHandler(button, iframe, wallet, originalWallet) {
|
2456
|
-
return __async(this, null, function* () {
|
2457
|
-
iframe.onload = () => sendInitializeData(wallet, originalWallet);
|
2458
2439
|
const iframeSrc = new URL(iframe.src);
|
2459
2440
|
iframeSrc.searchParams.set("origin", window.location.origin);
|
2441
|
+
accountId && iframeSrc.searchParams.set("accountId", accountId);
|
2442
|
+
originalAccountId && iframeSrc.searchParams.set("originalAccountId", originalAccountId);
|
2443
|
+
originalPublicKey && iframeSrc.searchParams.set("originalPublicKey", originalPublicKey);
|
2460
2444
|
iframe.src = iframeSrc.toString();
|
2461
2445
|
window.addEventListener("message", (event) => __async(this, null, function* () {
|
2462
|
-
var
|
2446
|
+
var _a2, _b;
|
2463
2447
|
if (event.origin !== iframeSrc.origin)
|
2464
2448
|
return;
|
2465
2449
|
const { action, requestId, data } = event.data;
|
2466
2450
|
if (action === "signAndSendTransaction") {
|
2467
2451
|
try {
|
2468
2452
|
const result = yield wallet.signAndSendTransaction(data);
|
2469
|
-
(
|
2453
|
+
(_a2 = event.source) == null ? void 0 : _a2.postMessage(
|
2470
2454
|
{
|
2471
2455
|
requestId,
|
2472
2456
|
data,
|
@@ -2572,11 +2556,8 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
2572
2556
|
if (btcContext) {
|
2573
2557
|
clearInterval(inter);
|
2574
2558
|
const context = btcContext.getContext();
|
2575
|
-
const accountId = state.getAccount();
|
2576
|
-
initWalletButton(options.network.networkId, accountId, wallet);
|
2577
2559
|
context.on("updatePublicKey", (btcPublicKey) => __async(void 0, null, function* () {
|
2578
2560
|
const { nearTempAddress } = yield getNearAccountByBtcPublicKey(btcPublicKey);
|
2579
|
-
initWalletButton(options.network.networkId, nearTempAddress, wallet);
|
2580
2561
|
emitter.emit("accountsChanged", {
|
2581
2562
|
accounts: [
|
2582
2563
|
{
|
@@ -2597,6 +2578,7 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
2597
2578
|
}
|
2598
2579
|
}), 500);
|
2599
2580
|
}
|
2581
|
+
initWalletButton(options.network.networkId, state.getAccount(), wallet);
|
2600
2582
|
function viewMethod(_02) {
|
2601
2583
|
return __async(this, arguments, function* ({ method, args = {} }) {
|
2602
2584
|
const res = yield provider.query({
|
@@ -2622,6 +2604,7 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
2622
2604
|
state.saveAccount(nearTempAddress);
|
2623
2605
|
state.savePublicKey(nearTempPublicKey);
|
2624
2606
|
state.saveBtcPublicKey(btcPublicKey);
|
2607
|
+
initWalletButton(options.network.networkId, nearTempAddress, wallet);
|
2625
2608
|
return {
|
2626
2609
|
nearTempAddress,
|
2627
2610
|
nearTempPublicKey
|
@@ -2644,7 +2627,6 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
2644
2627
|
const btcAccount = yield btcContext.login();
|
2645
2628
|
const btcPublicKey = yield btcContext.getPublicKey();
|
2646
2629
|
const { nearTempAddress, nearTempPublicKey } = yield getNearAccountByBtcPublicKey(btcPublicKey);
|
2647
|
-
initWalletButton(options.network.networkId, accountId, wallet);
|
2648
2630
|
return [
|
2649
2631
|
{
|
2650
2632
|
accountId: nearTempAddress,
|
@@ -2829,16 +2811,16 @@ function toHex(originalString) {
|
|
2829
2811
|
}
|
2830
2812
|
function initWalletButton(network, accountId, wallet) {
|
2831
2813
|
return __async(this, null, function* () {
|
2832
|
-
yield delay(
|
2814
|
+
yield delay(1e3);
|
2833
2815
|
const checkAndSetupWalletButton = () => {
|
2834
2816
|
if (accountId && window.btcContext.account) {
|
2835
2817
|
setupWalletButton(network, wallet, window.btcContext);
|
2836
2818
|
} else {
|
2837
2819
|
removeWalletButton();
|
2820
|
+
!window.btcContext.account && setTimeout(() => {
|
2821
|
+
checkAndSetupWalletButton();
|
2822
|
+
}, 5e3);
|
2838
2823
|
}
|
2839
|
-
!window.btcContext.account && setTimeout(() => {
|
2840
|
-
checkAndSetupWalletButton();
|
2841
|
-
}, 1e4);
|
2842
2824
|
};
|
2843
2825
|
checkAndSetupWalletButton();
|
2844
2826
|
});
|
@@ -2888,7 +2870,7 @@ function pollTransactionStatuses(network, hashes) {
|
|
2888
2870
|
|
2889
2871
|
// src/index.ts
|
2890
2872
|
var getVersion = () => {
|
2891
|
-
return "0.1.
|
2873
|
+
return "0.1.2";
|
2892
2874
|
};
|
2893
2875
|
if (typeof window !== "undefined") {
|
2894
2876
|
window.__PARTICLE_BTC_CONNECT_VERSION = getVersion();
|