btc-wallet 0.0.8 → 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 +44 -30
- package/dist/index.js.map +3 -3
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/initWalletButton.d.ts +4 -2
- package/esm/index.js +44 -30
- 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 }
|
@@ -2558,9 +2573,7 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
2558
2573
|
initWalletButton(options.network.networkId, accountId, wallet);
|
2559
2574
|
context.on("updatePublicKey", (btcPublicKey) => __async(void 0, null, function* () {
|
2560
2575
|
const { nearTempAddress } = yield getNearAccountByBtcPublicKey(btcPublicKey);
|
2561
|
-
|
2562
|
-
initWalletButton(options.network.networkId, nearTempAddress, wallet);
|
2563
|
-
}, 1e3);
|
2576
|
+
initWalletButton(options.network.networkId, nearTempAddress, wallet);
|
2564
2577
|
emitter.emit("accountsChanged", {
|
2565
2578
|
accounts: [
|
2566
2579
|
{
|
@@ -2628,6 +2641,7 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
2628
2641
|
const btcAccount = yield btcContext.login();
|
2629
2642
|
const btcPublicKey = yield btcContext.getPublicKey();
|
2630
2643
|
const { nearTempAddress, nearTempPublicKey } = yield getNearAccountByBtcPublicKey(btcPublicKey);
|
2644
|
+
initWalletButton(options.network.networkId, accountId, wallet);
|
2631
2645
|
return [
|
2632
2646
|
{
|
2633
2647
|
accountId: nearTempAddress,
|
@@ -2811,17 +2825,20 @@ function toHex(originalString) {
|
|
2811
2825
|
return hexString;
|
2812
2826
|
}
|
2813
2827
|
function initWalletButton(network, accountId, wallet) {
|
2814
|
-
|
2815
|
-
|
2816
|
-
|
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
|
+
}
|
2817
2836
|
!window.btcContext.account && setTimeout(() => {
|
2818
2837
|
checkAndSetupWalletButton();
|
2819
|
-
},
|
2820
|
-
}
|
2821
|
-
|
2822
|
-
|
2823
|
-
};
|
2824
|
-
checkAndSetupWalletButton();
|
2838
|
+
}, 1e4);
|
2839
|
+
};
|
2840
|
+
checkAndSetupWalletButton();
|
2841
|
+
});
|
2825
2842
|
}
|
2826
2843
|
var rcpUrls = {
|
2827
2844
|
mainnet: [
|
@@ -2836,9 +2853,6 @@ var rcpUrls = {
|
|
2836
2853
|
"https://near-testnet.drpc.org"
|
2837
2854
|
]
|
2838
2855
|
};
|
2839
|
-
function delay(ms) {
|
2840
|
-
return new Promise((resolve) => setTimeout(resolve, ms));
|
2841
|
-
}
|
2842
2856
|
function pollTransactionStatuses(network, hashes) {
|
2843
2857
|
return __async(this, null, function* () {
|
2844
2858
|
const provider = new import_near_api_js.providers.FailoverRpcProvider(
|
@@ -2871,7 +2885,7 @@ function pollTransactionStatuses(network, hashes) {
|
|
2871
2885
|
|
2872
2886
|
// src/index.ts
|
2873
2887
|
var getVersion = () => {
|
2874
|
-
return "0.0.
|
2888
|
+
return "0.0.9";
|
2875
2889
|
};
|
2876
2890
|
if (typeof window !== "undefined") {
|
2877
2891
|
window.__PARTICLE_BTC_CONNECT_VERSION = getVersion();
|