btc-wallet 0.5.34-beta → 0.5.36-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/README.md +1 -0
- package/dist/core/btcUtils.d.ts +3 -1
- package/dist/core/btcWalletSelectorContext.d.ts +3 -3
- package/dist/index.js +68 -83
- package/dist/index.js.map +3 -3
- package/esm/index.js +68 -83
- package/esm/index.js.map +3 -3
- package/package.json +1 -1
package/esm/index.js
CHANGED
@@ -2620,6 +2620,10 @@ function ComfirmBox({ onClose, status = 1, fromChain = {
|
|
2620
2620
|
|
2621
2621
|
// src/core/btcWalletSelectorContext.tsx
|
2622
2622
|
import { jsx as jsx12, jsxs as jsxs9 } from "react/jsx-runtime";
|
2623
|
+
var eventCache = {
|
2624
|
+
lastProcessedAccount: "",
|
2625
|
+
lastProcessedTime: 0
|
2626
|
+
};
|
2623
2627
|
var WalletSelectorContext = React.createContext(null);
|
2624
2628
|
function BtcWalletSelectorContextProvider({
|
2625
2629
|
children
|
@@ -2707,76 +2711,63 @@ function useBtcWalletSelector() {
|
|
2707
2711
|
getNetwork: getNetwork2,
|
2708
2712
|
switchNetwork
|
2709
2713
|
} = useBTCProvider();
|
2710
|
-
const publicKey = useRef(null);
|
2711
|
-
const signMessageFn = useRef(null);
|
2712
2714
|
const connectorRef = useRef(null);
|
2713
2715
|
const context = useContext2(WalletSelectorContext);
|
2714
2716
|
useEffect6(() => {
|
2715
|
-
|
2717
|
+
const handleAccountsChanged = (account) => {
|
2718
|
+
if (!(account == null ? void 0 : account.length))
|
2719
|
+
return;
|
2720
|
+
const accountKey = JSON.stringify(account);
|
2721
|
+
const now = Date.now();
|
2722
|
+
if (accountKey === eventCache.lastProcessedAccount && now - eventCache.lastProcessedTime < 3e3) {
|
2723
|
+
return;
|
2724
|
+
}
|
2725
|
+
eventCache.lastProcessedAccount = accountKey;
|
2726
|
+
eventCache.lastProcessedTime = now;
|
2716
2727
|
getPublicKey().then((res) => {
|
2717
|
-
|
2728
|
+
context.emit("updatePublicKey", res);
|
2718
2729
|
});
|
2719
|
-
}
|
2720
|
-
}, [getPublicKey, provider]);
|
2721
|
-
useEffect6(() => {
|
2722
|
-
signMessageFn.current = signMessage;
|
2723
|
-
}, [signMessage]);
|
2724
|
-
useEffect6(() => {
|
2725
|
-
const fn = (account) => {
|
2726
|
-
console.log("accountsChanged account", account);
|
2727
|
-
if (account == null ? void 0 : account.length) {
|
2728
|
-
getPublicKey().then((res) => {
|
2729
|
-
publicKey.current = res;
|
2730
|
-
context.emit("updatePublicKey", res);
|
2731
|
-
});
|
2732
|
-
}
|
2733
2730
|
};
|
2734
|
-
|
2735
|
-
connector.on("accountsChanged", fn);
|
2736
|
-
}
|
2731
|
+
connector == null ? void 0 : connector.on("accountsChanged", handleAccountsChanged);
|
2737
2732
|
connectorRef.current = connector;
|
2738
2733
|
return () => {
|
2739
|
-
|
2740
|
-
connector.removeListener("accountsChanged", fn);
|
2741
|
-
}
|
2734
|
+
connector == null ? void 0 : connector.removeListener("accountsChanged", handleAccountsChanged);
|
2742
2735
|
};
|
2743
2736
|
}, [connector, context, getPublicKey]);
|
2744
2737
|
const hook = useMemo6(() => {
|
2738
|
+
const connectWallet = (useModal = false) => __async(this, null, function* () {
|
2739
|
+
if (connectModalOpen)
|
2740
|
+
return null;
|
2741
|
+
const account = accounts == null ? void 0 : accounts[0];
|
2742
|
+
if (account)
|
2743
|
+
return account;
|
2744
|
+
try {
|
2745
|
+
if (useModal) {
|
2746
|
+
openConnectModal == null ? void 0 : openConnectModal();
|
2747
|
+
} else {
|
2748
|
+
yield requestDirectAccount(connectorRef.current);
|
2749
|
+
}
|
2750
|
+
const account2 = yield retryOperation(
|
2751
|
+
() => window.btcContext.account,
|
2752
|
+
(res) => !!res,
|
2753
|
+
{
|
2754
|
+
maxRetries: 100,
|
2755
|
+
delayMs: 1e3
|
2756
|
+
}
|
2757
|
+
);
|
2758
|
+
return account2 || null;
|
2759
|
+
} catch (error) {
|
2760
|
+
console.error("btcLoginError", error);
|
2761
|
+
context.emit("btcLoginError");
|
2762
|
+
return null;
|
2763
|
+
}
|
2764
|
+
});
|
2745
2765
|
return {
|
2746
2766
|
login: () => __async(this, null, function* () {
|
2747
|
-
|
2748
|
-
console.log("account", account);
|
2749
|
-
console.log("connecting", connectModalOpen);
|
2750
|
-
if (!account) {
|
2751
|
-
if (connectModalOpen) {
|
2752
|
-
return null;
|
2753
|
-
}
|
2754
|
-
try {
|
2755
|
-
openConnectModal == null ? void 0 : openConnectModal();
|
2756
|
-
const account1 = yield retryOperation(
|
2757
|
-
() => window.btcContext.account,
|
2758
|
-
(res) => !!res,
|
2759
|
-
{
|
2760
|
-
maxRetries: 100,
|
2761
|
-
delayMs: 1e3
|
2762
|
-
}
|
2763
|
-
);
|
2764
|
-
if (!account1) {
|
2765
|
-
throw new Error("Failed to get account");
|
2766
|
-
}
|
2767
|
-
return account1;
|
2768
|
-
} catch (error) {
|
2769
|
-
console.error("btcLoginError", error);
|
2770
|
-
context.emit("btcLoginError");
|
2771
|
-
}
|
2772
|
-
}
|
2773
|
-
return account;
|
2767
|
+
return connectWallet(true);
|
2774
2768
|
}),
|
2775
2769
|
autoConnect: () => __async(this, null, function* () {
|
2776
|
-
return
|
2777
|
-
console.error("btcLoginError", e);
|
2778
|
-
context.emit("btcLoginError");
|
2779
|
-
});
|
2770
|
+
return connectWallet(false);
|
2780
2771
|
}),
|
2781
2772
|
logout: () => {
|
2782
2773
|
const accountId = accounts == null ? void 0 : accounts[0];
|
@@ -2787,29 +2778,25 @@ function useBtcWalletSelector() {
|
|
2787
2778
|
},
|
2788
2779
|
account: accounts == null ? void 0 : accounts[0],
|
2789
2780
|
getPublicKey: () => __async(this, null, function* () {
|
2790
|
-
const
|
2791
|
-
if (
|
2792
|
-
return
|
2793
|
-
|
2794
|
-
|
2795
|
-
|
2796
|
-
|
2797
|
-
|
2798
|
-
|
2799
|
-
console.error("btcLoginError", error);
|
2800
|
-
context.emit("btcLoginError");
|
2801
|
-
return;
|
2802
|
-
}
|
2781
|
+
const publicKey = yield getPublicKey().catch(() => null);
|
2782
|
+
if (publicKey)
|
2783
|
+
return publicKey;
|
2784
|
+
yield connectWallet(false);
|
2785
|
+
return getPublicKey();
|
2786
|
+
}),
|
2787
|
+
signMessage: (msg) => __async(this, null, function* () {
|
2788
|
+
yield connectWallet(false);
|
2789
|
+
return signMessage(msg);
|
2803
2790
|
}),
|
2804
|
-
signMessage: (msg) => {
|
2805
|
-
return signMessageFn.current(msg);
|
2806
|
-
},
|
2807
2791
|
getContext: () => {
|
2808
2792
|
return context;
|
2809
2793
|
},
|
2810
2794
|
getNetwork: getNetwork2,
|
2811
2795
|
switchNetwork,
|
2812
|
-
sendBitcoin:
|
2796
|
+
sendBitcoin: (toAddress, satoshis, options) => __async(this, null, function* () {
|
2797
|
+
yield connectWallet(false);
|
2798
|
+
return sendBitcoin2(toAddress, satoshis, options);
|
2799
|
+
})
|
2813
2800
|
};
|
2814
2801
|
}, [
|
2815
2802
|
accounts,
|
@@ -2821,7 +2808,8 @@ function useBtcWalletSelector() {
|
|
2821
2808
|
context,
|
2822
2809
|
requestDirectAccount,
|
2823
2810
|
disconnect,
|
2824
|
-
getPublicKey
|
2811
|
+
getPublicKey,
|
2812
|
+
signMessage
|
2825
2813
|
]);
|
2826
2814
|
return hook;
|
2827
2815
|
}
|
@@ -3984,7 +3972,8 @@ function executeBTCDepositAndAction(_0) {
|
|
3984
3972
|
pollResult = true,
|
3985
3973
|
registerDeposit,
|
3986
3974
|
env = "mainnet",
|
3987
|
-
newAccountMinDepositAmount
|
3975
|
+
newAccountMinDepositAmount,
|
3976
|
+
registerContractId
|
3988
3977
|
}) {
|
3989
3978
|
var _a;
|
3990
3979
|
try {
|
@@ -4022,17 +4011,14 @@ function executeBTCDepositAndAction(_0) {
|
|
4022
4011
|
}));
|
4023
4012
|
}
|
4024
4013
|
const storageDepositMsg = {};
|
4025
|
-
const
|
4026
|
-
|
4027
|
-
|
4028
|
-
);
|
4029
|
-
console.log("executeBTCDepositAndAction registerContractId", registerContractId);
|
4030
|
-
const registerRes = yield nearCall(registerContractId, "storage_balance_of", {
|
4014
|
+
const _registerContractId = registerContractId || ((action == null ? void 0 : action.receiver_id) || config.btcToken).replace(config.accountContractId, config.btcToken);
|
4015
|
+
console.log("executeBTCDepositAndAction registerContractId", _registerContractId);
|
4016
|
+
const registerRes = yield nearCall(_registerContractId, "storage_balance_of", {
|
4031
4017
|
account_id: csna
|
4032
4018
|
});
|
4033
4019
|
if (!(registerRes == null ? void 0 : registerRes.available)) {
|
4034
4020
|
storageDepositMsg.storage_deposit_msg = {
|
4035
|
-
contract_id:
|
4021
|
+
contract_id: _registerContractId,
|
4036
4022
|
deposit: registerDeposit || NEAR_STORAGE_DEPOSIT_AMOUNT,
|
4037
4023
|
registration_only: true
|
4038
4024
|
};
|
@@ -4538,7 +4524,6 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
4538
4524
|
console.log("setupBtcContextListeners clear");
|
4539
4525
|
}
|
4540
4526
|
const valid = validateWalletState();
|
4541
|
-
console.log("setupBtcContextListeners wallet state valid:", valid);
|
4542
4527
|
if (!valid) {
|
4543
4528
|
return;
|
4544
4529
|
}
|
@@ -4860,7 +4845,7 @@ function getGroup(state) {
|
|
4860
4845
|
|
4861
4846
|
// src/index.ts
|
4862
4847
|
var getVersion = () => {
|
4863
|
-
return "0.5.
|
4848
|
+
return "0.5.36-beta";
|
4864
4849
|
};
|
4865
4850
|
if (typeof window !== "undefined") {
|
4866
4851
|
window.__BTC_WALLET_VERSION = getVersion();
|