btc-wallet 0.4.5-beta → 0.4.7-beta
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/core/btcUtils.d.ts +1 -0
- package/dist/index.js +213 -61
- package/dist/index.js.map +2 -2
- package/esm/index.js +213 -61
- package/esm/index.js.map +2 -2
- package/package.json +1 -1
package/dist/core/btcUtils.d.ts
CHANGED
@@ -50,6 +50,7 @@ export declare function getDepositAmount(amount: string, option?: {
|
|
50
50
|
totalDepositAmount: number;
|
51
51
|
protocolFee: number;
|
52
52
|
repayAmount: string | number;
|
53
|
+
newAccountMinDepositAmount: string | number;
|
53
54
|
}>;
|
54
55
|
export declare function getCsnaAccountId(env: ENV): Promise<string>;
|
55
56
|
interface ExecuteBTCDepositAndActionParams<T extends boolean = true> {
|
package/dist/index.js
CHANGED
@@ -2675,35 +2675,107 @@ function createFloatingButtonWithIframe({
|
|
2675
2675
|
}) {
|
2676
2676
|
const button = document.createElement("img");
|
2677
2677
|
button.id = "satoshi-wallet-button";
|
2678
|
-
|
2678
|
+
const isIframeVisible = localStorage.getItem("btc-wallet-iframe-visible") === "true";
|
2679
|
+
button.src = isIframeVisible ? closeImageUrl : openImageUrl;
|
2680
|
+
iframe.style.display = isIframeVisible ? "block" : "none";
|
2681
|
+
const windowWidth = window.innerWidth;
|
2682
|
+
const windowHeight = window.innerHeight;
|
2683
|
+
const savedPosition = JSON.parse(
|
2684
|
+
localStorage.getItem("btc-wallet-button-position") || '{"right": "20px", "bottom": "20px"}'
|
2685
|
+
);
|
2686
|
+
const right = Math.min(Math.max(20, parseInt(savedPosition.right)), windowWidth - 80);
|
2687
|
+
const bottom = Math.min(Math.max(20, parseInt(savedPosition.bottom)), windowHeight - 80);
|
2679
2688
|
Object.assign(button.style, {
|
2680
2689
|
position: "fixed",
|
2681
|
-
bottom:
|
2682
|
-
right:
|
2690
|
+
bottom: `${bottom}px`,
|
2691
|
+
right: `${right}px`,
|
2683
2692
|
zIndex: "100000",
|
2684
2693
|
width: "60px",
|
2685
2694
|
height: "60px",
|
2686
2695
|
borderRadius: "50%",
|
2687
|
-
cursor: "
|
2688
|
-
transition: "transform 0.15s ease"
|
2696
|
+
cursor: "grab",
|
2697
|
+
transition: "transform 0.15s ease",
|
2698
|
+
userSelect: "none"
|
2689
2699
|
});
|
2690
2700
|
document.body.appendChild(button);
|
2691
|
-
|
2692
|
-
|
2693
|
-
|
2694
|
-
|
2701
|
+
let isDragging = false;
|
2702
|
+
let startX = 0;
|
2703
|
+
let startY = 0;
|
2704
|
+
let initialRight = 0;
|
2705
|
+
let initialBottom = 0;
|
2706
|
+
let dragStartTime = 0;
|
2707
|
+
button.addEventListener("mousedown", (e) => {
|
2708
|
+
isDragging = true;
|
2709
|
+
startX = e.clientX;
|
2710
|
+
startY = e.clientY;
|
2711
|
+
initialRight = parseInt(button.style.right);
|
2712
|
+
initialBottom = parseInt(button.style.bottom);
|
2713
|
+
dragStartTime = Date.now();
|
2714
|
+
button.style.cursor = "grabbing";
|
2715
|
+
button.style.transition = "none";
|
2716
|
+
e.preventDefault();
|
2717
|
+
});
|
2718
|
+
document.addEventListener("mousemove", (e) => {
|
2719
|
+
if (!isDragging)
|
2720
|
+
return;
|
2721
|
+
const deltaX = startX - e.clientX;
|
2722
|
+
const deltaY = startY - e.clientY;
|
2723
|
+
let newRight = initialRight + deltaX;
|
2724
|
+
let newBottom = initialBottom + deltaY;
|
2725
|
+
newRight = Math.min(Math.max(20, newRight), windowWidth - 80);
|
2726
|
+
newBottom = Math.min(Math.max(20, newBottom), windowHeight - 80);
|
2727
|
+
const snapThreshold = 20;
|
2728
|
+
const buttonLeft = windowWidth - newRight - 60;
|
2729
|
+
if (buttonLeft < snapThreshold) {
|
2730
|
+
newRight = windowWidth - 80;
|
2731
|
+
} else if (buttonLeft > windowWidth - snapThreshold - 60) {
|
2732
|
+
newRight = 20;
|
2733
|
+
}
|
2734
|
+
if (newBottom < snapThreshold) {
|
2735
|
+
newBottom = 20;
|
2736
|
+
} else if (newBottom > windowHeight - snapThreshold - 60) {
|
2737
|
+
newBottom = windowHeight - 80;
|
2738
|
+
}
|
2739
|
+
button.style.right = `${newRight}px`;
|
2740
|
+
button.style.bottom = `${newBottom}px`;
|
2741
|
+
updateIframePosition(iframe, newRight, newBottom, windowWidth, windowHeight);
|
2742
|
+
});
|
2743
|
+
document.addEventListener("mouseup", () => {
|
2744
|
+
if (!isDragging)
|
2745
|
+
return;
|
2746
|
+
const dragEndTime = Date.now();
|
2747
|
+
const isDragEvent = dragEndTime - dragStartTime > 200;
|
2748
|
+
isDragging = false;
|
2749
|
+
button.style.cursor = "grab";
|
2750
|
+
button.style.transition = "transform 0.15s ease";
|
2751
|
+
localStorage.setItem(
|
2752
|
+
"btc-wallet-button-position",
|
2753
|
+
JSON.stringify({
|
2754
|
+
right: button.style.right,
|
2755
|
+
bottom: button.style.bottom
|
2756
|
+
})
|
2757
|
+
);
|
2758
|
+
if (!isDragEvent) {
|
2759
|
+
handleButtonClick();
|
2760
|
+
}
|
2761
|
+
});
|
2762
|
+
const handleButtonClick = () => {
|
2695
2763
|
const isCurrentlyVisible = iframe.style.display === "block";
|
2696
2764
|
button.style.transform = "scale(0.8)";
|
2697
2765
|
setTimeout(() => {
|
2698
2766
|
button.style.transform = "scale(1)";
|
2699
2767
|
}, 150);
|
2700
|
-
|
2701
|
-
|
2702
|
-
|
2768
|
+
const newVisibleState = !isCurrentlyVisible;
|
2769
|
+
iframe.style.display = newVisibleState ? "block" : "none";
|
2770
|
+
button.src = newVisibleState ? closeImageUrl : openImageUrl;
|
2771
|
+
localStorage.setItem("btc-wallet-iframe-visible", String(newVisibleState));
|
2703
2772
|
setTimeout(() => {
|
2704
|
-
|
2773
|
+
if (newVisibleState) {
|
2774
|
+
iframe.focus();
|
2775
|
+
}
|
2705
2776
|
}, 0);
|
2706
2777
|
};
|
2778
|
+
button.onclick = null;
|
2707
2779
|
return button;
|
2708
2780
|
}
|
2709
2781
|
function createIframe({
|
@@ -2714,6 +2786,7 @@ function createIframe({
|
|
2714
2786
|
iframe.id = "satoshi-wallet-iframe";
|
2715
2787
|
iframe.allow = "clipboard-read; clipboard-write";
|
2716
2788
|
iframe.src = iframeUrl;
|
2789
|
+
const isVisible = localStorage.getItem("btc-wallet-iframe-visible") === "true";
|
2717
2790
|
Object.assign(iframe.style, __spreadValues({
|
2718
2791
|
position: "fixed",
|
2719
2792
|
bottom: "90px",
|
@@ -2721,7 +2794,7 @@ function createIframe({
|
|
2721
2794
|
zIndex: "100000",
|
2722
2795
|
boxShadow: "0 0 10px rgba(0, 0, 0, 0.1)",
|
2723
2796
|
borderRadius: "10px",
|
2724
|
-
display: "block",
|
2797
|
+
display: isVisible ? "block" : "none",
|
2725
2798
|
border: "none"
|
2726
2799
|
}, iframeStyle));
|
2727
2800
|
document.body.appendChild(iframe);
|
@@ -2779,6 +2852,20 @@ function removeWalletButton() {
|
|
2779
2852
|
const iframe = document.getElementById("satoshi-wallet-iframe");
|
2780
2853
|
iframe == null ? void 0 : iframe.remove();
|
2781
2854
|
}
|
2855
|
+
function updateIframePosition(iframe, buttonRight, buttonBottom, windowWidth, windowHeight) {
|
2856
|
+
const iframeWidth = parseInt(iframe.style.width);
|
2857
|
+
const iframeHeight = parseInt(iframe.style.height);
|
2858
|
+
let iframeRight = buttonRight;
|
2859
|
+
let iframeBottom = buttonBottom + 70;
|
2860
|
+
if (iframeRight + iframeWidth > windowWidth - 20) {
|
2861
|
+
iframeRight = Math.max(20, windowWidth - iframeWidth - 20);
|
2862
|
+
}
|
2863
|
+
if (iframeBottom + iframeHeight > windowHeight - 20) {
|
2864
|
+
iframeBottom = Math.max(20, buttonBottom - iframeHeight - 10);
|
2865
|
+
}
|
2866
|
+
iframe.style.right = `${iframeRight}px`;
|
2867
|
+
iframe.style.bottom = `${iframeBottom}px`;
|
2868
|
+
}
|
2782
2869
|
|
2783
2870
|
// src/utils/nearUtils.ts
|
2784
2871
|
var import_near_api_js = require("near-api-js");
|
@@ -3247,6 +3334,7 @@ var import_coinselect = __toESM(require("coinselect"), 1);
|
|
3247
3334
|
var NEAR_STORAGE_DEPOSIT_AMOUNT = "1250000000000000000000";
|
3248
3335
|
var NBTC_STORAGE_DEPOSIT_AMOUNT = "3000";
|
3249
3336
|
var GAS_LIMIT = "50000000000000";
|
3337
|
+
var NEW_ACCOUNT_MIN_DEPOSIT_AMOUNT = "1000";
|
3250
3338
|
function getBtcProvider() {
|
3251
3339
|
if (typeof window === "undefined" || !window.btcContext) {
|
3252
3340
|
throw new Error("BTC Provider is not initialized.");
|
@@ -3416,12 +3504,14 @@ function getDepositAmount(amount, option) {
|
|
3416
3504
|
} = yield nearCall(config.bridgeContractId, "get_config", {});
|
3417
3505
|
const depositAmount = Math.max(Number(min_deposit_amount), Number(amount));
|
3418
3506
|
const protocolFee = Math.max(Number(fee_min), Number(depositAmount) * fee_rate);
|
3419
|
-
const
|
3507
|
+
const newAccountMinDepositAmount = !(accountInfo == null ? void 0 : accountInfo.nonce) ? NEW_ACCOUNT_MIN_DEPOSIT_AMOUNT : 0;
|
3508
|
+
const totalDepositAmount = new import_big.default(depositAmount).plus(protocolFee).plus(repayAmount).plus(newAccountMinDepositAmount).round(0, import_big.default.roundDown).toNumber();
|
3420
3509
|
return {
|
3421
3510
|
depositAmount,
|
3422
3511
|
totalDepositAmount,
|
3423
3512
|
protocolFee,
|
3424
|
-
repayAmount
|
3513
|
+
repayAmount,
|
3514
|
+
newAccountMinDepositAmount
|
3425
3515
|
};
|
3426
3516
|
});
|
3427
3517
|
}
|
@@ -3548,6 +3638,14 @@ function checkSatoshiWhitelist(btcAccountId, env = "mainnet") {
|
|
3548
3638
|
return __async(this, null, function* () {
|
3549
3639
|
if (env !== "private_mainnet")
|
3550
3640
|
return;
|
3641
|
+
const hasShownNotice = localStorage.getItem("btc-wallet-private-mainnet-notice");
|
3642
|
+
if (!hasShownNotice) {
|
3643
|
+
Dialog.alert({
|
3644
|
+
title: "Notice",
|
3645
|
+
message: "You are currently using Satoshi Private Mainnet. This is a private version for testing. Please try a small amount of assets in Ramp"
|
3646
|
+
});
|
3647
|
+
localStorage.setItem("btc-wallet-private-mainnet-notice", "true");
|
3648
|
+
}
|
3551
3649
|
if (!btcAccountId)
|
3552
3650
|
return;
|
3553
3651
|
const config = yield getConfig(env);
|
@@ -3577,13 +3675,12 @@ function getWithdrawTransaction(_0) {
|
|
3577
3675
|
const btcAddress = yield provider.account;
|
3578
3676
|
const config = yield getConfig(env);
|
3579
3677
|
const brgConfig = yield nearCall(config.bridgeContractId, "get_config", {});
|
3580
|
-
const _amount = Number(new import_big.default(amount).mul(__pow(10, 8)).toFixed(0));
|
3581
3678
|
if (brgConfig.min_withdraw_amount) {
|
3582
|
-
if (
|
3679
|
+
if (Number(amount) < Number(brgConfig.min_withdraw_amount)) {
|
3583
3680
|
throw new Error("Mini withdraw amount is " + brgConfig.min_withdraw_amount);
|
3584
3681
|
}
|
3585
3682
|
}
|
3586
|
-
const feePercent = Number(brgConfig.withdraw_bridge_fee.fee_rate) *
|
3683
|
+
const feePercent = Number(brgConfig.withdraw_bridge_fee.fee_rate) * Number(amount);
|
3587
3684
|
const withdrawFee = feePercent > Number(brgConfig.withdraw_bridge_fee.fee_min) ? feePercent : Number(brgConfig.withdraw_bridge_fee.fee_min);
|
3588
3685
|
const allUTXO = yield nearCall(config.bridgeContractId, "get_utxos_paged", {});
|
3589
3686
|
if (!allUTXO || Object.keys(allUTXO).length === 0) {
|
@@ -3601,7 +3698,7 @@ function getWithdrawTransaction(_0) {
|
|
3601
3698
|
const _feeRate = feeRate || (yield getBtcGasPrice());
|
3602
3699
|
const { inputs, outputs, fee } = (0, import_coinselect.default)(
|
3603
3700
|
utxos,
|
3604
|
-
[{ address: btcAddress, value:
|
3701
|
+
[{ address: btcAddress, value: Number(amount) }],
|
3605
3702
|
Math.ceil(_feeRate)
|
3606
3703
|
);
|
3607
3704
|
if (!outputs || !inputs) {
|
@@ -3616,7 +3713,7 @@ function getWithdrawTransaction(_0) {
|
|
3616
3713
|
let userOutput, noUserOutput;
|
3617
3714
|
for (let i = 0; i < outputs.length; i++) {
|
3618
3715
|
const output = outputs[i];
|
3619
|
-
if (output.value.toString() ===
|
3716
|
+
if (output.value.toString() === amount.toString()) {
|
3620
3717
|
userOutput = output;
|
3621
3718
|
} else {
|
3622
3719
|
noUserOutput = output;
|
@@ -3695,7 +3792,7 @@ function getWithdrawTransaction(_0) {
|
|
3695
3792
|
methodName: "ft_transfer_call",
|
3696
3793
|
args: {
|
3697
3794
|
receiver_id: config.bridgeContractId,
|
3698
|
-
amount:
|
3795
|
+
amount: amount.toString(),
|
3699
3796
|
msg: JSON.stringify(msg)
|
3700
3797
|
},
|
3701
3798
|
gas: "300000000000000",
|
@@ -3713,24 +3810,41 @@ function uint8ArrayToHex(uint8Array) {
|
|
3713
3810
|
|
3714
3811
|
// src/core/setupBTCWallet.ts
|
3715
3812
|
var { transfer, functionCall } = import_transactions.actionCreators;
|
3813
|
+
var STORAGE_KEYS = {
|
3814
|
+
ACCOUNT: "btc-wallet-account",
|
3815
|
+
PUBLIC_KEY: "btc-wallet-publickey",
|
3816
|
+
BTC_PUBLIC_KEY: "btc-wallet-btc-publickey"
|
3817
|
+
};
|
3716
3818
|
var state = {
|
3717
3819
|
saveAccount(account) {
|
3718
|
-
|
3820
|
+
if (!account) {
|
3821
|
+
this.removeAccount();
|
3822
|
+
return;
|
3823
|
+
}
|
3824
|
+
window.localStorage.setItem(STORAGE_KEYS.ACCOUNT, account);
|
3719
3825
|
},
|
3720
3826
|
removeAccount() {
|
3721
|
-
window.localStorage.removeItem(
|
3827
|
+
window.localStorage.removeItem(STORAGE_KEYS.ACCOUNT);
|
3722
3828
|
},
|
3723
3829
|
savePublicKey(publicKey) {
|
3724
|
-
|
3830
|
+
if (!publicKey) {
|
3831
|
+
this.removePublicKey();
|
3832
|
+
return;
|
3833
|
+
}
|
3834
|
+
window.localStorage.setItem(STORAGE_KEYS.PUBLIC_KEY, publicKey);
|
3725
3835
|
},
|
3726
3836
|
removePublicKey() {
|
3727
|
-
window.localStorage.removeItem(
|
3837
|
+
window.localStorage.removeItem(STORAGE_KEYS.PUBLIC_KEY);
|
3728
3838
|
},
|
3729
3839
|
saveBtcPublicKey(publicKey) {
|
3730
|
-
|
3840
|
+
if (!publicKey) {
|
3841
|
+
this.removeBtcPublicKey();
|
3842
|
+
return;
|
3843
|
+
}
|
3844
|
+
window.localStorage.setItem(STORAGE_KEYS.BTC_PUBLIC_KEY, publicKey);
|
3731
3845
|
},
|
3732
3846
|
removeBtcPublicKey() {
|
3733
|
-
window.localStorage.removeItem(
|
3847
|
+
window.localStorage.removeItem(STORAGE_KEYS.BTC_PUBLIC_KEY);
|
3734
3848
|
},
|
3735
3849
|
clear() {
|
3736
3850
|
this.removeAccount();
|
@@ -3738,17 +3852,39 @@ var state = {
|
|
3738
3852
|
this.removeBtcPublicKey();
|
3739
3853
|
},
|
3740
3854
|
save(account, publicKey) {
|
3855
|
+
if (!account || !publicKey) {
|
3856
|
+
this.clear();
|
3857
|
+
return;
|
3858
|
+
}
|
3741
3859
|
this.saveAccount(account);
|
3742
3860
|
this.savePublicKey(publicKey);
|
3743
3861
|
},
|
3744
3862
|
getAccount() {
|
3745
|
-
return window.localStorage.getItem(
|
3863
|
+
return window.localStorage.getItem(STORAGE_KEYS.ACCOUNT);
|
3746
3864
|
},
|
3747
3865
|
getPublicKey() {
|
3748
|
-
return window.localStorage.getItem(
|
3866
|
+
return window.localStorage.getItem(STORAGE_KEYS.PUBLIC_KEY);
|
3749
3867
|
},
|
3750
3868
|
getBtcPublicKey() {
|
3751
|
-
return window.localStorage.getItem(
|
3869
|
+
return window.localStorage.getItem(STORAGE_KEYS.BTC_PUBLIC_KEY);
|
3870
|
+
},
|
3871
|
+
isValid() {
|
3872
|
+
const account = this.getAccount();
|
3873
|
+
const publicKey = this.getPublicKey();
|
3874
|
+
const btcPublicKey = this.getBtcPublicKey();
|
3875
|
+
const allEmpty = !account && !publicKey && !btcPublicKey;
|
3876
|
+
const allExist = account && publicKey && btcPublicKey;
|
3877
|
+
return allEmpty || allExist;
|
3878
|
+
},
|
3879
|
+
syncSave(account, publicKey, btcPublicKey) {
|
3880
|
+
if (!account || !publicKey || !btcPublicKey) {
|
3881
|
+
this.clear();
|
3882
|
+
return;
|
3883
|
+
}
|
3884
|
+
this.clear();
|
3885
|
+
this.savePublicKey(publicKey);
|
3886
|
+
this.saveBtcPublicKey(btcPublicKey);
|
3887
|
+
this.saveAccount(account);
|
3752
3888
|
}
|
3753
3889
|
};
|
3754
3890
|
var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
@@ -3775,16 +3911,33 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
3775
3911
|
const currentConfig = walletConfig[env];
|
3776
3912
|
const walletNetwork = ["mainnet", "private_mainnet"].includes(env) ? "mainnet" : "testnet";
|
3777
3913
|
yield initBtcContext();
|
3914
|
+
function validateWalletState() {
|
3915
|
+
const accountId = state.getAccount();
|
3916
|
+
const publicKey = state.getPublicKey();
|
3917
|
+
const btcPublicKey = state.getBtcPublicKey();
|
3918
|
+
if (!accountId && publicKey || accountId && !publicKey || !publicKey && btcPublicKey) {
|
3919
|
+
state.clear();
|
3920
|
+
return false;
|
3921
|
+
}
|
3922
|
+
return true;
|
3923
|
+
}
|
3778
3924
|
function setupBtcContextListeners() {
|
3779
3925
|
return __async(this, null, function* () {
|
3780
3926
|
const handleConnectionUpdate = () => __async(this, null, function* () {
|
3781
3927
|
yield checkBtcNetwork(walletNetwork);
|
3782
|
-
|
3928
|
+
if (!state.isValid()) {
|
3929
|
+
state.clear();
|
3930
|
+
}
|
3931
|
+
validateWalletState();
|
3783
3932
|
const btcContext = window.btcContext;
|
3784
|
-
if (
|
3785
|
-
yield
|
3786
|
-
|
3787
|
-
|
3933
|
+
if (btcContext.account) {
|
3934
|
+
const btcPublicKey = yield btcContext.getPublicKey();
|
3935
|
+
if (btcPublicKey) {
|
3936
|
+
const { nearAddress, nearPublicKey } = yield getNearAccountByBtcPublicKey(btcPublicKey);
|
3937
|
+
yield checkSatoshiWhitelist(btcContext.account, env);
|
3938
|
+
removeWalletButton();
|
3939
|
+
setupWalletButton(env, wallet, btcContext);
|
3940
|
+
}
|
3788
3941
|
} else {
|
3789
3942
|
removeWalletButton();
|
3790
3943
|
setTimeout(() => {
|
@@ -3795,19 +3948,31 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
3795
3948
|
const context = window.btcContext.getContext();
|
3796
3949
|
context.on("updatePublicKey", (btcPublicKey) => __async(this, null, function* () {
|
3797
3950
|
console.log("updatePublicKey");
|
3798
|
-
|
3799
|
-
|
3800
|
-
|
3801
|
-
|
3802
|
-
|
3951
|
+
state.clear();
|
3952
|
+
try {
|
3953
|
+
const { nearAddress, nearPublicKey } = yield getNearAccountByBtcPublicKey(btcPublicKey);
|
3954
|
+
if (!nearAddress || !nearPublicKey) {
|
3955
|
+
throw new Error("Failed to get near account info");
|
3956
|
+
}
|
3957
|
+
emitter.emit("accountsChanged", {
|
3958
|
+
accounts: [{ accountId: nearAddress }]
|
3959
|
+
});
|
3960
|
+
yield handleConnectionUpdate();
|
3961
|
+
} catch (error) {
|
3962
|
+
console.error("Error updating public key:", error);
|
3963
|
+
state.clear();
|
3964
|
+
emitter.emit("accountsChanged", { accounts: [] });
|
3965
|
+
}
|
3803
3966
|
}));
|
3804
3967
|
context.on("btcLoginError", () => __async(this, null, function* () {
|
3805
3968
|
console.log("btcLoginError");
|
3969
|
+
state.clear();
|
3806
3970
|
emitter.emit("accountsChanged", { accounts: [] });
|
3807
3971
|
yield handleConnectionUpdate();
|
3808
3972
|
}));
|
3809
3973
|
context.on("btcLogOut", () => __async(this, null, function* () {
|
3810
3974
|
console.log("btcLogOut");
|
3975
|
+
state.clear();
|
3811
3976
|
emitter.emit("accountsChanged", { accounts: [] });
|
3812
3977
|
yield handleConnectionUpdate();
|
3813
3978
|
}));
|
@@ -3851,9 +4016,7 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
3851
4016
|
"get_chain_signature_near_account_public_key",
|
3852
4017
|
{ btc_public_key: btcPublicKey }
|
3853
4018
|
);
|
3854
|
-
state.
|
3855
|
-
state.savePublicKey(nearPublicKey);
|
3856
|
-
state.saveBtcPublicKey(btcPublicKey);
|
4019
|
+
state.syncSave(csna, nearPublicKey, btcPublicKey);
|
3857
4020
|
return {
|
3858
4021
|
nearAddress: csna,
|
3859
4022
|
nearPublicKey
|
@@ -3863,10 +4026,8 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
3863
4026
|
function signIn(_02) {
|
3864
4027
|
return __async(this, arguments, function* ({ contractId, methodNames }) {
|
3865
4028
|
const btcContext = window.btcContext;
|
3866
|
-
|
3867
|
-
|
3868
|
-
console.log("isLogin:", accountId && publicKey);
|
3869
|
-
if (!accountId || !publicKey) {
|
4029
|
+
state.clear();
|
4030
|
+
if (!state.getAccount() || !state.getPublicKey()) {
|
3870
4031
|
yield btcContext.login();
|
3871
4032
|
}
|
3872
4033
|
const btcPublicKey = yield btcContext.getPublicKey();
|
@@ -3932,6 +4093,9 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
3932
4093
|
}
|
3933
4094
|
function signAndSendTransactions(params) {
|
3934
4095
|
return __async(this, null, function* () {
|
4096
|
+
if (!validateWalletState()) {
|
4097
|
+
throw new Error("Wallet state is invalid, please reconnect your wallet.");
|
4098
|
+
}
|
3935
4099
|
const btcContext = window.btcContext;
|
3936
4100
|
const accountId = state.getAccount();
|
3937
4101
|
const accountInfo = yield getAccountInfo(accountId, currentConfig.accountContractId);
|
@@ -4138,18 +4302,6 @@ function setupBTCWallet({
|
|
4138
4302
|
env = "mainnet"
|
4139
4303
|
} = {}) {
|
4140
4304
|
console.log("\u26A1\uFE0F BTC Wallet Version:", getVersion(), "env:", env);
|
4141
|
-
if (env === "private_mainnet" && typeof window !== "undefined") {
|
4142
|
-
setTimeout(() => {
|
4143
|
-
const hasShownNotice = localStorage.getItem("satoshi_private_mainnet_notice");
|
4144
|
-
if (!hasShownNotice) {
|
4145
|
-
Dialog.alert({
|
4146
|
-
title: "Notice",
|
4147
|
-
message: "You are currently using Satoshi Private Mainnet. This is a private version for testing. Please try a small amount of assets in Ramp"
|
4148
|
-
});
|
4149
|
-
localStorage.setItem("satoshi_private_mainnet_notice", "true");
|
4150
|
-
}
|
4151
|
-
}, 1e3);
|
4152
|
-
}
|
4153
4305
|
const btcWallet = () => __async(this, null, function* () {
|
4154
4306
|
return {
|
4155
4307
|
id: "btc-wallet",
|
@@ -4173,7 +4325,7 @@ function setupBTCWallet({
|
|
4173
4325
|
|
4174
4326
|
// src/index.ts
|
4175
4327
|
var getVersion = () => {
|
4176
|
-
return "0.4.
|
4328
|
+
return "0.4.7-beta";
|
4177
4329
|
};
|
4178
4330
|
if (typeof window !== "undefined") {
|
4179
4331
|
window.__BTC_WALLET_VERSION = getVersion();
|