btc-wallet 0.5.23-beta → 0.5.25-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 +7 -2
- package/dist/context/index.d.ts +1 -0
- package/dist/core/btcWalletSelectorContext.d.ts +1 -0
- package/dist/core/setupModal.d.ts +5 -0
- package/dist/hooks/useConnectModal.d.ts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +150 -19
- package/dist/index.js.map +4 -4
- package/dist/utils/Dialog.d.ts +5 -0
- package/dist/utils/satoshi.d.ts +1 -1
- package/esm/index.js +152 -19
- package/esm/index.js.map +4 -4
- package/package.json +3 -2
package/dist/utils/Dialog.d.ts
CHANGED
@@ -13,5 +13,10 @@ export declare class Dialog {
|
|
13
13
|
message: string;
|
14
14
|
}): Promise<boolean>;
|
15
15
|
static alert(options: DialogOptions): Promise<void>;
|
16
|
+
static openModal<T>({ title, titleStyle, content, }: {
|
17
|
+
title: string;
|
18
|
+
titleStyle?: string;
|
19
|
+
content: (resolve: (value: T) => void, close: () => void) => HTMLElement;
|
20
|
+
}): Promise<T>;
|
16
21
|
}
|
17
22
|
export {};
|
package/dist/utils/satoshi.d.ts
CHANGED
@@ -37,7 +37,7 @@ export interface AccountInfo {
|
|
37
37
|
export declare function getAccountInfo({ csna, env }: {
|
38
38
|
csna: string;
|
39
39
|
env: ENV;
|
40
|
-
}): Promise<AccountInfo
|
40
|
+
}): Promise<AccountInfo>;
|
41
41
|
export declare function getBridgeConfig({ env }: {
|
42
42
|
env: ENV;
|
43
43
|
}): Promise<{
|
package/esm/index.js
CHANGED
@@ -245,6 +245,44 @@ var Dialog = class {
|
|
245
245
|
});
|
246
246
|
});
|
247
247
|
}
|
248
|
+
static openModal({
|
249
|
+
title,
|
250
|
+
titleStyle,
|
251
|
+
content
|
252
|
+
}) {
|
253
|
+
return new Promise((resolve) => {
|
254
|
+
const modalContainer = document.createElement("div");
|
255
|
+
modalContainer.innerHTML = this.template;
|
256
|
+
document.body.appendChild(modalContainer);
|
257
|
+
const btns = modalContainer.querySelector(".dialog-buttons");
|
258
|
+
btns.style.display = "none";
|
259
|
+
this.injectStyles();
|
260
|
+
const titleEl = modalContainer.querySelector(".dialog-title");
|
261
|
+
if (title) {
|
262
|
+
titleEl.textContent = title;
|
263
|
+
if (titleStyle) {
|
264
|
+
titleEl.style.cssText = titleStyle;
|
265
|
+
}
|
266
|
+
} else {
|
267
|
+
titleEl.style.display = "none";
|
268
|
+
}
|
269
|
+
const cleanup = () => {
|
270
|
+
document.body.removeChild(modalContainer);
|
271
|
+
};
|
272
|
+
const close = () => {
|
273
|
+
cleanup();
|
274
|
+
resolve(null);
|
275
|
+
};
|
276
|
+
const messageEl = modalContainer.querySelector(".dialog-message");
|
277
|
+
messageEl.appendChild(content(resolve, close));
|
278
|
+
const overlay = modalContainer.querySelector(".dialog-overlay");
|
279
|
+
overlay.addEventListener("click", (e) => {
|
280
|
+
if (e.target === overlay) {
|
281
|
+
close();
|
282
|
+
}
|
283
|
+
});
|
284
|
+
});
|
285
|
+
}
|
248
286
|
};
|
249
287
|
Dialog.template = `
|
250
288
|
<div class="dialog-overlay">
|
@@ -275,7 +313,7 @@ Dialog.style = `
|
|
275
313
|
backdrop-filter: blur(4px);
|
276
314
|
}
|
277
315
|
.dialog-container {
|
278
|
-
background: #
|
316
|
+
background: #131313;
|
279
317
|
border-radius: 12px;
|
280
318
|
padding: 24px;
|
281
319
|
width: 350px;
|
@@ -362,6 +400,30 @@ Dialog.style = `
|
|
362
400
|
opacity: 1;
|
363
401
|
}
|
364
402
|
}
|
403
|
+
.option-list {
|
404
|
+
display: flex;
|
405
|
+
flex-direction: column;
|
406
|
+
gap: 12px;
|
407
|
+
}
|
408
|
+
.option-item {
|
409
|
+
display: flex;
|
410
|
+
align-items: center;
|
411
|
+
gap: 12px;
|
412
|
+
color: #fff;
|
413
|
+
border: 1px solid transparent;
|
414
|
+
background-color: hsla(0, 0%, 100%, .05);
|
415
|
+
border-radius: 8px;
|
416
|
+
padding: 8px 16px;
|
417
|
+
transition: all 0.15s ease;
|
418
|
+
cursor: pointer;
|
419
|
+
font-size: 14px;
|
420
|
+
font-weight: bold;
|
421
|
+
&:hover {
|
422
|
+
border-color: #ff7a00;
|
423
|
+
color: #ff7a00;
|
424
|
+
background-color: hsla(0, 0%, 100%, .08);
|
425
|
+
}
|
426
|
+
}
|
365
427
|
`;
|
366
428
|
|
367
429
|
// src/connector/universalLink.ts
|
@@ -1080,8 +1142,8 @@ var useBTCProvider = () => {
|
|
1080
1142
|
|
1081
1143
|
// src/hooks/useConnectModal.ts
|
1082
1144
|
var useConnectModal = () => {
|
1083
|
-
const { openConnectModal, disconnect, requestDirectAccount } = useConnectProvider();
|
1084
|
-
return { openConnectModal, disconnect, requestDirectAccount };
|
1145
|
+
const { openConnectModal, disconnect, requestDirectAccount, connectModalOpen } = useConnectProvider();
|
1146
|
+
return { openConnectModal, disconnect, requestDirectAccount, connectModalOpen };
|
1085
1147
|
};
|
1086
1148
|
|
1087
1149
|
// src/hooks/useConnector.ts
|
@@ -1455,9 +1517,9 @@ import { createPortal } from "react-dom";
|
|
1455
1517
|
import { RemoveScroll } from "react-remove-scroll";
|
1456
1518
|
|
1457
1519
|
// esbuild-scss-modules-plugin:./modal.module.scss
|
1458
|
-
var digest3 = "
|
1459
|
-
var classes3 = { "container": "
|
1460
|
-
var css3 = `.
|
1520
|
+
var digest3 = "9c9a003376c4060e772fdba1e4b20a9af75a33b996c44ae9cea877de3ceb1b80";
|
1521
|
+
var classes3 = { "container": "_container_1s3ca_1", "modal": "_modal_1s3ca_18" };
|
1522
|
+
var css3 = `._container_1s3ca_1{align-items:center;backdrop-filter:blur(12px);background:rgba(0,0,0,.502);bottom:0;color:#fff;display:flex;height:100%;justify-content:center;left:0;overflow:hidden;position:fixed;right:0;top:0;width:100%;z-index:100000}._container_1s3ca_1 ._modal_1s3ca_18{align-items:center;background-color:#131313;border-radius:16px;display:flex;flex-direction:column;font-size:14px;height:auto;margin:16px;max-height:80%;max-width:100%;overflow:auto;padding:24px;position:relative;width:380px}`;
|
1461
1523
|
(function() {
|
1462
1524
|
if (typeof document !== "undefined" && !document.getElementById(digest3)) {
|
1463
1525
|
var ele = document.createElement("style");
|
@@ -1500,9 +1562,9 @@ var Modal = ({ open, onClose, children, isDismissable = true, contentStyle, cont
|
|
1500
1562
|
var modal_default = Modal;
|
1501
1563
|
|
1502
1564
|
// esbuild-scss-modules-plugin:./connect.module.scss
|
1503
|
-
var digest4 = "
|
1504
|
-
var classes4 = { "connectModal": "
|
1505
|
-
var css4 = `.
|
1565
|
+
var digest4 = "9f37532ca7be1b0e97d8b75261330d17b9316635d48e9ec58b471baefd1f674c";
|
1566
|
+
var classes4 = { "connectModal": "_connectModal_1tdkv_1", "title": "_title_1tdkv_4", "closeBtn": "_closeBtn_1tdkv_9", "backBtn": "_backBtn_1tdkv_15", "walletItem": "_walletItem_1tdkv_21", "walletIcon": "_walletIcon_1tdkv_41", "walletName": "_walletName_1tdkv_46", "connecting": "_connecting_1tdkv_50", "connectingIconContainer": "_connectingIconContainer_1tdkv_58", "retryContainer": "_retryContainer_1tdkv_61", "retryIcon": "_retryIcon_1tdkv_70", "connectingIcon": "_connectingIcon_1tdkv_58", "connection": "_connection_1tdkv_79", "acceptRequest": "_acceptRequest_1tdkv_83", "btnDownload": "_btnDownload_1tdkv_90" };
|
1567
|
+
var css4 = `._connectModal_1tdkv_1{gap:12px}._connectModal_1tdkv_1 ._title_1tdkv_4{font-size:18px;font-weight:700;margin-bottom:16px}._connectModal_1tdkv_1 ._closeBtn_1tdkv_9{cursor:pointer;position:absolute;right:16px;top:16px}._connectModal_1tdkv_1 ._backBtn_1tdkv_15{cursor:pointer;left:16px;position:absolute;top:16px}._connectModal_1tdkv_1 ._walletItem_1tdkv_21{background-color:hsla(0,0%,100%,.05);border:1px solid transparent;border-radius:8px;box-sizing:border-box;color:#fff;cursor:pointer;display:flex;font-size:14px;font-weight:700;gap:12px;padding:8px 16px;transition:all .15s ease;width:100%}._connectModal_1tdkv_1 ._walletItem_1tdkv_21:hover{background:hsla(0,0%,100%,.08);border-color:#ff7a00;color:#ff7a00}._connectModal_1tdkv_1 ._walletItem_1tdkv_21 ._walletIcon_1tdkv_41{border-radius:8px;height:32px;width:32px}._connectModal_1tdkv_1 ._walletItem_1tdkv_21 ._walletName_1tdkv_46{flex-grow:1;line-height:32px}._connectModal_1tdkv_1 ._connecting_1tdkv_50{align-items:center;display:flex;flex-direction:column;height:204px;justify-content:center;width:100%}._connectModal_1tdkv_1 ._connecting_1tdkv_50 ._connectingIconContainer_1tdkv_58{position:relative}._connectModal_1tdkv_1 ._connecting_1tdkv_50 ._connectingIconContainer_1tdkv_58 ._retryContainer_1tdkv_61{background:#4b5563;border-radius:50%;bottom:-12px;cursor:pointer;padding:4px;position:absolute;right:-12px}._connectModal_1tdkv_1 ._connecting_1tdkv_50 ._connectingIconContainer_1tdkv_58 ._retryContainer_1tdkv_61 ._retryIcon_1tdkv_70{height:24px;width:24px}._connectModal_1tdkv_1 ._connecting_1tdkv_50 ._connectingIcon_1tdkv_58{border-radius:4px;height:60px;width:60px}._connectModal_1tdkv_1 ._connecting_1tdkv_50 ._connection_1tdkv_79{font-size:18px;margin-top:20px}._connectModal_1tdkv_1 ._connecting_1tdkv_50 ._acceptRequest_1tdkv_83{color:hsla(0,0%,100%,.4);font-size:14px;margin-top:6px;text-align:center;white-space:pre-wrap}._connectModal_1tdkv_1 ._connecting_1tdkv_50 ._btnDownload_1tdkv_90{margin-top:20px}`;
|
1506
1568
|
(function() {
|
1507
1569
|
if (typeof document !== "undefined" && !document.getElementById(digest4)) {
|
1508
1570
|
var ele = document.createElement("style");
|
@@ -2557,6 +2619,7 @@ var ConnectProvider = ({
|
|
2557
2619
|
setConnectorId,
|
2558
2620
|
connector,
|
2559
2621
|
connectors,
|
2622
|
+
connectModalOpen,
|
2560
2623
|
openConnectModal,
|
2561
2624
|
closeConnectModal,
|
2562
2625
|
accounts,
|
@@ -2642,6 +2705,7 @@ function ComfirmBox({ onClose, status = 1, fromChain = {
|
|
2642
2705
|
}
|
2643
2706
|
|
2644
2707
|
// src/core/btcWalletSelectorContext.tsx
|
2708
|
+
import "ref-modal-ui/styles.css";
|
2645
2709
|
import { jsx as jsx12, jsxs as jsxs9 } from "react/jsx-runtime";
|
2646
2710
|
var WalletSelectorContext = React.createContext(null);
|
2647
2711
|
function BtcWalletSelectorContextProvider({
|
@@ -2719,7 +2783,7 @@ function InitBtcWalletSelectorContext() {
|
|
2719
2783
|
return null;
|
2720
2784
|
}
|
2721
2785
|
function useBtcWalletSelector() {
|
2722
|
-
const { openConnectModal, disconnect, requestDirectAccount } = useConnectModal();
|
2786
|
+
const { openConnectModal, disconnect, requestDirectAccount, connectModalOpen } = useConnectModal();
|
2723
2787
|
const {
|
2724
2788
|
accounts,
|
2725
2789
|
sendBitcoin: sendBitcoin2,
|
@@ -2734,7 +2798,6 @@ function useBtcWalletSelector() {
|
|
2734
2798
|
const signMessageFn = useRef(null);
|
2735
2799
|
const connectorRef = useRef(null);
|
2736
2800
|
const context = useContext2(WalletSelectorContext);
|
2737
|
-
const isLoggingIn = useRef(false);
|
2738
2801
|
useEffect6(() => {
|
2739
2802
|
if (provider) {
|
2740
2803
|
getPublicKey().then((res) => {
|
@@ -2768,12 +2831,13 @@ function useBtcWalletSelector() {
|
|
2768
2831
|
return {
|
2769
2832
|
login: () => __async(this, null, function* () {
|
2770
2833
|
const account = accounts == null ? void 0 : accounts[0];
|
2834
|
+
console.log("account", account);
|
2835
|
+
console.log("connecting", connectModalOpen);
|
2771
2836
|
if (!account) {
|
2772
|
-
if (
|
2837
|
+
if (connectModalOpen) {
|
2773
2838
|
return null;
|
2774
2839
|
}
|
2775
2840
|
try {
|
2776
|
-
isLoggingIn.current = true;
|
2777
2841
|
openConnectModal == null ? void 0 : openConnectModal();
|
2778
2842
|
const account1 = yield retryOperation(
|
2779
2843
|
() => window.btcContext.account,
|
@@ -2787,8 +2851,9 @@ function useBtcWalletSelector() {
|
|
2787
2851
|
throw new Error("Failed to get account");
|
2788
2852
|
}
|
2789
2853
|
return account1;
|
2790
|
-
}
|
2791
|
-
|
2854
|
+
} catch (error) {
|
2855
|
+
console.error("btcLoginError", error);
|
2856
|
+
context.emit("btcLoginError");
|
2792
2857
|
}
|
2793
2858
|
}
|
2794
2859
|
return account;
|
@@ -3289,7 +3354,8 @@ function getAccountInfo(_0) {
|
|
3289
3354
|
},
|
3290
3355
|
{ network: config.network }
|
3291
3356
|
).catch((error) => {
|
3292
|
-
|
3357
|
+
console.log(`get_account error, please try again later`, error);
|
3358
|
+
throw error;
|
3293
3359
|
});
|
3294
3360
|
return accountInfo;
|
3295
3361
|
});
|
@@ -3649,7 +3715,7 @@ function calculateWithdraw(_0) {
|
|
3649
3715
|
return {
|
3650
3716
|
withdrawFee: 0,
|
3651
3717
|
isError: true,
|
3652
|
-
errorMsg:
|
3718
|
+
errorMsg: `Mini withdraw amount is ${Number(brgConfig.min_withdraw_amount) + Number(gasLimit)} sats`
|
3653
3719
|
};
|
3654
3720
|
}
|
3655
3721
|
}
|
@@ -4270,7 +4336,6 @@ function createFloatingButtonWithIframe({
|
|
4270
4336
|
zIndex: "100000",
|
4271
4337
|
width: "60px",
|
4272
4338
|
height: "60px",
|
4273
|
-
borderRadius: "50%",
|
4274
4339
|
cursor: "grab",
|
4275
4340
|
transition: "transform 0.15s ease",
|
4276
4341
|
userSelect: "none"
|
@@ -4776,9 +4841,76 @@ function setupBTCWallet({
|
|
4776
4841
|
return btcWallet;
|
4777
4842
|
}
|
4778
4843
|
|
4844
|
+
// src/core/setupModal.ts
|
4845
|
+
import {
|
4846
|
+
setupModal as _setupModal
|
4847
|
+
} from "ref-modal-ui";
|
4848
|
+
function setupWalletSelectorModal(selector, options) {
|
4849
|
+
if (!selector)
|
4850
|
+
throw new Error("selector is required");
|
4851
|
+
const state = selector.store.getState();
|
4852
|
+
const group = getGroup(state);
|
4853
|
+
const modal = _setupModal(selector, options);
|
4854
|
+
const originalShow = modal.show.bind(modal);
|
4855
|
+
modal.show = () => __async(this, null, function* () {
|
4856
|
+
const chain = group.length > 1 ? yield openChainModal() : group[0];
|
4857
|
+
if (chain === "btc") {
|
4858
|
+
const module = state.modules.find((module2) => module2.id === "btc-wallet");
|
4859
|
+
if (module) {
|
4860
|
+
const wallet = yield module.wallet();
|
4861
|
+
yield wallet.signIn(options);
|
4862
|
+
}
|
4863
|
+
} else if (chain === "near") {
|
4864
|
+
originalShow();
|
4865
|
+
}
|
4866
|
+
});
|
4867
|
+
return modal;
|
4868
|
+
}
|
4869
|
+
function openChainModal() {
|
4870
|
+
return __async(this, null, function* () {
|
4871
|
+
const chains5 = ["btc", "near"];
|
4872
|
+
const content = (resolve, close) => {
|
4873
|
+
const buttons = `
|
4874
|
+
<div class="option-list">${chains5.map(
|
4875
|
+
(chain) => `<button class="chain-button option-item" data-chain="${chain}">
|
4876
|
+
<img src="https://assets.deltatrade.ai/assets/chain/${chain}.svg" alt="${chain}" style="width:32px; height: 32px;" />
|
4877
|
+
${chain.toUpperCase()}
|
4878
|
+
</button>`
|
4879
|
+
).join("")}
|
4880
|
+
</div>
|
4881
|
+
`;
|
4882
|
+
const div = document.createElement("div");
|
4883
|
+
div.innerHTML = buttons;
|
4884
|
+
const buttonsEl = div.querySelectorAll(".chain-button");
|
4885
|
+
buttonsEl.forEach((button) => {
|
4886
|
+
button.addEventListener("click", () => {
|
4887
|
+
resolve(button.dataset.chain);
|
4888
|
+
close();
|
4889
|
+
});
|
4890
|
+
});
|
4891
|
+
return div;
|
4892
|
+
};
|
4893
|
+
return yield Dialog.openModal({
|
4894
|
+
title: "Choose Chain",
|
4895
|
+
titleStyle: "font-size: 18px; font-weight: 600; color: #fff; text-align: center;padding-bottom: 10px;",
|
4896
|
+
content
|
4897
|
+
});
|
4898
|
+
});
|
4899
|
+
}
|
4900
|
+
function getGroup(state) {
|
4901
|
+
const hasBtcWallet = state.modules.some((module) => module.id === "btc-wallet");
|
4902
|
+
const hasNearWallet = state.modules.some((module) => module.id !== "btc-wallet");
|
4903
|
+
const group = [];
|
4904
|
+
if (hasBtcWallet)
|
4905
|
+
group.push("btc");
|
4906
|
+
if (hasNearWallet)
|
4907
|
+
group.push("near");
|
4908
|
+
return group;
|
4909
|
+
}
|
4910
|
+
|
4779
4911
|
// src/index.ts
|
4780
4912
|
var getVersion = () => {
|
4781
|
-
return "0.5.
|
4913
|
+
return "0.5.25-beta";
|
4782
4914
|
};
|
4783
4915
|
if (typeof window !== "undefined") {
|
4784
4916
|
window.__BTC_WALLET_VERSION = getVersion();
|
@@ -4816,6 +4948,7 @@ export {
|
|
4816
4948
|
nearRpcUrls,
|
4817
4949
|
sendBitcoin,
|
4818
4950
|
setupBTCWallet,
|
4951
|
+
setupWalletSelectorModal,
|
4819
4952
|
useAccountContract,
|
4820
4953
|
useAccounts,
|
4821
4954
|
useBTCProvider,
|