btc-wallet 0.5.1-beta → 0.5.3-beta

Sign up to get free protection for your applications and to get access to all the features.
package/esm/index.js CHANGED
@@ -2876,7 +2876,7 @@ var walletConfig = {
2876
2876
  token: "nbtc.toalice.near",
2877
2877
  accountContractId: "acc.toalice.near",
2878
2878
  bridgeContractId: "brg.toalice.near",
2879
- walletUrl: "http://localhost:3100",
2879
+ walletUrl: "https://wallet-stg.satoshibridge.top",
2880
2880
  bridgeUrl: "https://old.ramp.satos.network"
2881
2881
  },
2882
2882
  mainnet: {
@@ -2902,231 +2902,8 @@ var btcRpcUrls = {
2902
2902
  testnet: "https://mempool.space/testnet/api"
2903
2903
  };
2904
2904
 
2905
- // src/utils/initWalletButton.ts
2906
- function setupWalletButton(env, wallet, originalWallet) {
2907
- console.log("setupWalletButton");
2908
- if (document.getElementById("satoshi-wallet-button")) {
2909
- return;
2910
- }
2911
- const iframe = createIframe({
2912
- iframeUrl: walletConfig[env].walletUrl,
2913
- iframeStyle: { width: "400px", height: "650px" }
2914
- });
2915
- iframe.addEventListener("mouseenter", () => {
2916
- var _a;
2917
- if (document.activeElement !== iframe) {
2918
- (_a = document.activeElement) == null ? void 0 : _a.setAttribute("tabindex", "null");
2919
- setTimeout(() => {
2920
- iframe.focus();
2921
- }, 0);
2922
- }
2923
- });
2924
- const button = createFloatingButtonWithIframe({
2925
- openImageUrl: "https://assets.deltatrade.ai/wallet-assets/wallet-btn.png",
2926
- closeImageUrl: "https://assets.deltatrade.ai/wallet-assets/wallet-btn-active.png",
2927
- iframe
2928
- });
2929
- setupButtonClickHandler(button, iframe, wallet, originalWallet);
2930
- }
2931
- function createFloatingButtonWithIframe({
2932
- openImageUrl,
2933
- closeImageUrl,
2934
- iframe
2935
- }) {
2936
- const button = document.createElement("img");
2937
- button.id = "satoshi-wallet-button";
2938
- const isIframeVisible = localStorage.getItem("btc-wallet-iframe-visible") === "true";
2939
- button.src = isIframeVisible ? closeImageUrl : openImageUrl;
2940
- iframe.style.display = isIframeVisible ? "block" : "none";
2941
- const windowWidth = window.innerWidth;
2942
- const windowHeight = window.innerHeight;
2943
- const savedPosition = JSON.parse(
2944
- localStorage.getItem("btc-wallet-button-position") || '{"right": "20px", "bottom": "20px"}'
2945
- );
2946
- const right = Math.min(Math.max(20, parseInt(savedPosition.right)), windowWidth - 80);
2947
- const bottom = Math.min(Math.max(20, parseInt(savedPosition.bottom)), windowHeight - 80);
2948
- Object.assign(button.style, {
2949
- position: "fixed",
2950
- bottom: `${bottom}px`,
2951
- right: `${right}px`,
2952
- zIndex: "100000",
2953
- width: "60px",
2954
- height: "60px",
2955
- borderRadius: "50%",
2956
- cursor: "grab",
2957
- transition: "transform 0.15s ease",
2958
- userSelect: "none"
2959
- });
2960
- document.body.appendChild(button);
2961
- updateIframePosition(iframe, right, bottom, windowWidth, windowHeight);
2962
- let isDragging = false;
2963
- let startX = 0;
2964
- let startY = 0;
2965
- let initialRight = 0;
2966
- let initialBottom = 0;
2967
- let dragStartTime = 0;
2968
- button.addEventListener("mousedown", (e) => {
2969
- isDragging = true;
2970
- startX = e.clientX;
2971
- startY = e.clientY;
2972
- initialRight = parseInt(button.style.right);
2973
- initialBottom = parseInt(button.style.bottom);
2974
- dragStartTime = Date.now();
2975
- button.style.cursor = "grabbing";
2976
- button.style.transition = "none";
2977
- e.preventDefault();
2978
- });
2979
- document.addEventListener("mousemove", (e) => {
2980
- if (!isDragging)
2981
- return;
2982
- const deltaX = startX - e.clientX;
2983
- const deltaY = startY - e.clientY;
2984
- let newRight = initialRight + deltaX;
2985
- let newBottom = initialBottom + deltaY;
2986
- newRight = Math.min(Math.max(20, newRight), windowWidth - 80);
2987
- newBottom = Math.min(Math.max(20, newBottom), windowHeight - 80);
2988
- const snapThreshold = 20;
2989
- const buttonLeft = windowWidth - newRight - 60;
2990
- if (buttonLeft < snapThreshold) {
2991
- newRight = windowWidth - 80;
2992
- } else if (buttonLeft > windowWidth - snapThreshold - 60) {
2993
- newRight = 20;
2994
- }
2995
- if (newBottom < snapThreshold) {
2996
- newBottom = 20;
2997
- } else if (newBottom > windowHeight - snapThreshold - 60) {
2998
- newBottom = windowHeight - 80;
2999
- }
3000
- button.style.right = `${newRight}px`;
3001
- button.style.bottom = `${newBottom}px`;
3002
- updateIframePosition(iframe, newRight, newBottom, windowWidth, windowHeight);
3003
- });
3004
- document.addEventListener("mouseup", () => {
3005
- if (!isDragging)
3006
- return;
3007
- const dragEndTime = Date.now();
3008
- const isDragEvent = dragEndTime - dragStartTime > 200;
3009
- isDragging = false;
3010
- button.style.cursor = "grab";
3011
- button.style.transition = "transform 0.15s ease";
3012
- localStorage.setItem(
3013
- "btc-wallet-button-position",
3014
- JSON.stringify({
3015
- right: button.style.right,
3016
- bottom: button.style.bottom
3017
- })
3018
- );
3019
- if (!isDragEvent) {
3020
- handleButtonClick();
3021
- }
3022
- });
3023
- const handleButtonClick = () => {
3024
- const isCurrentlyVisible = iframe.style.display === "block";
3025
- button.style.transform = "scale(0.8)";
3026
- setTimeout(() => {
3027
- button.style.transform = "scale(1)";
3028
- }, 150);
3029
- const newVisibleState = !isCurrentlyVisible;
3030
- iframe.style.display = newVisibleState ? "block" : "none";
3031
- button.src = newVisibleState ? closeImageUrl : openImageUrl;
3032
- localStorage.setItem("btc-wallet-iframe-visible", String(newVisibleState));
3033
- setTimeout(() => {
3034
- if (newVisibleState) {
3035
- iframe.focus();
3036
- }
3037
- }, 0);
3038
- };
3039
- button.onclick = null;
3040
- return button;
3041
- }
3042
- function createIframe({
3043
- iframeUrl,
3044
- iframeStyle = {}
3045
- }) {
3046
- const iframe = document.createElement("iframe");
3047
- iframe.id = "satoshi-wallet-iframe";
3048
- iframe.allow = "clipboard-read; clipboard-write";
3049
- iframe.src = iframeUrl;
3050
- const isVisible = localStorage.getItem("btc-wallet-iframe-visible") === "true";
3051
- Object.assign(iframe.style, __spreadValues({
3052
- position: "fixed",
3053
- bottom: "90px",
3054
- right: "20px",
3055
- zIndex: "100000",
3056
- boxShadow: "0 0 10px rgba(0, 0, 0, 0.1)",
3057
- borderRadius: "10px",
3058
- display: isVisible ? "block" : "none",
3059
- border: "none"
3060
- }, iframeStyle));
3061
- document.body.appendChild(iframe);
3062
- return iframe;
3063
- }
3064
- function setupButtonClickHandler(button, iframe, wallet, originalWallet) {
3065
- return __async(this, null, function* () {
3066
- var _a;
3067
- const accountId = (_a = yield wallet == null ? void 0 : wallet.getAccounts()) == null ? void 0 : _a[0].accountId;
3068
- const originalAccountId = originalWallet.account;
3069
- const originalPublicKey = yield originalWallet.getPublicKey();
3070
- console.log({ accountId, originalAccountId, originalPublicKey });
3071
- const iframeSrc = new URL(iframe.src);
3072
- iframeSrc.searchParams.set("origin", window.location.origin);
3073
- accountId && iframeSrc.searchParams.set("accountId", accountId);
3074
- originalAccountId && iframeSrc.searchParams.set("originalAccountId", originalAccountId);
3075
- originalPublicKey && iframeSrc.searchParams.set("originalPublicKey", originalPublicKey);
3076
- iframe.src = iframeSrc.toString();
3077
- window.addEventListener("message", (event) => __async(this, null, function* () {
3078
- var _a2, _b;
3079
- if (event.origin !== iframeSrc.origin)
3080
- return;
3081
- const { action, requestId, data } = event.data;
3082
- if (action === "signAndSendTransaction") {
3083
- console.log("signAndSendTransaction message", event.data);
3084
- try {
3085
- const result = yield wallet.signAndSendTransaction(data);
3086
- console.log("signAndSendTransaction result", result);
3087
- (_a2 = event.source) == null ? void 0 : _a2.postMessage(
3088
- {
3089
- requestId,
3090
- data,
3091
- success: true
3092
- },
3093
- { targetOrigin: event.origin }
3094
- );
3095
- } catch (error) {
3096
- console.error("signAndSendTransaction error", error);
3097
- (_b = event.source) == null ? void 0 : _b.postMessage(
3098
- {
3099
- requestId,
3100
- error: error.message,
3101
- success: false
3102
- },
3103
- { targetOrigin: event.origin }
3104
- );
3105
- }
3106
- }
3107
- }));
3108
- });
3109
- }
3110
- function removeWalletButton() {
3111
- const button = document.getElementById("satoshi-wallet-button");
3112
- button == null ? void 0 : button.remove();
3113
- const iframe = document.getElementById("satoshi-wallet-iframe");
3114
- iframe == null ? void 0 : iframe.remove();
3115
- }
3116
- function updateIframePosition(iframe, buttonRight, buttonBottom, windowWidth, windowHeight) {
3117
- const iframeWidth = parseInt(iframe.style.width);
3118
- const iframeHeight = parseInt(iframe.style.height);
3119
- let iframeRight = buttonRight;
3120
- let iframeBottom = buttonBottom + 70;
3121
- if (iframeRight + iframeWidth > windowWidth - 20) {
3122
- iframeRight = Math.max(20, windowWidth - iframeWidth - 20);
3123
- }
3124
- if (iframeBottom + iframeHeight > windowHeight - 20) {
3125
- iframeBottom = Math.max(20, buttonBottom - iframeHeight - 10);
3126
- }
3127
- iframe.style.right = `${iframeRight}px`;
3128
- iframe.style.bottom = `${iframeBottom}px`;
3129
- }
2905
+ // src/core/btcUtils.ts
2906
+ import Big from "big.js";
3130
2907
 
3131
2908
  // src/utils/nearUtils.ts
3132
2909
  import { providers } from "near-api-js";
@@ -3190,12 +2967,6 @@ function pollTransactionStatuses(network, hashes) {
3190
2967
  });
3191
2968
  }
3192
2969
 
3193
- // src/core/setupBTCWallet.ts
3194
- import Big2 from "big.js";
3195
-
3196
- // src/core/btcUtils.ts
3197
- import Big from "big.js";
3198
-
3199
2970
  // src/utils/request.ts
3200
2971
  var cache = /* @__PURE__ */ new Map();
3201
2972
  var defaultCacheTimeout = 3e3;
@@ -3398,11 +3169,10 @@ var NBTC_STORAGE_DEPOSIT_AMOUNT = "3000";
3398
3169
  var GAS_LIMIT = "50000000000000";
3399
3170
  var NEW_ACCOUNT_MIN_DEPOSIT_AMOUNT = "1000";
3400
3171
  function getBtcProvider() {
3401
- var _a, _b;
3402
- if (typeof window === "undefined" || !window.btcContext && !((_a = window.top) == null ? void 0 : _a.btcContext)) {
3172
+ if (typeof window === "undefined" || !window.btcContext) {
3403
3173
  throw new Error("BTC Provider is not initialized.");
3404
3174
  }
3405
- return window.btcContext || ((_b = window.top) == null ? void 0 : _b.btcContext);
3175
+ return window.btcContext;
3406
3176
  }
3407
3177
  function getNetwork() {
3408
3178
  return __async(this, null, function* () {
@@ -3465,7 +3235,6 @@ function checkGasTokenDebt(accountInfo, env, autoDeposit) {
3465
3235
  return;
3466
3236
  const config = yield getConfig(env);
3467
3237
  const transferAmount = hasDebtArrears ? debtAmount : relayerFeeAmount;
3468
- console.log("get_account:", accountInfo);
3469
3238
  const action = {
3470
3239
  receiver_id: config.accountContractId,
3471
3240
  amount: transferAmount.toString(),
@@ -3876,7 +3645,239 @@ function uint8ArrayToHex(uint8Array) {
3876
3645
  return Array.from(uint8Array).map((byte) => byte.toString(16).padStart(2, "0")).join("");
3877
3646
  }
3878
3647
 
3648
+ // src/utils/initWalletButton.ts
3649
+ function setupWalletButton(env, wallet, originalWallet) {
3650
+ console.log("setupWalletButton");
3651
+ if (document.getElementById("satoshi-wallet-button")) {
3652
+ return;
3653
+ }
3654
+ const iframe = createIframe({
3655
+ iframeUrl: walletConfig[env].walletUrl,
3656
+ iframeStyle: { width: "400px", height: "650px" }
3657
+ });
3658
+ iframe.addEventListener("mouseenter", () => {
3659
+ var _a;
3660
+ if (document.activeElement !== iframe) {
3661
+ (_a = document.activeElement) == null ? void 0 : _a.setAttribute("tabindex", "null");
3662
+ setTimeout(() => {
3663
+ iframe.focus();
3664
+ }, 0);
3665
+ }
3666
+ });
3667
+ const button = createFloatingButtonWithIframe({
3668
+ openImageUrl: "https://assets.deltatrade.ai/wallet-assets/wallet-btn.png",
3669
+ closeImageUrl: "https://assets.deltatrade.ai/wallet-assets/wallet-btn-active.png",
3670
+ iframe
3671
+ });
3672
+ setupButtonClickHandler(button, iframe, wallet, originalWallet);
3673
+ }
3674
+ function createFloatingButtonWithIframe({
3675
+ openImageUrl,
3676
+ closeImageUrl,
3677
+ iframe
3678
+ }) {
3679
+ const button = document.createElement("img");
3680
+ button.id = "satoshi-wallet-button";
3681
+ const isIframeVisible = localStorage.getItem("btc-wallet-iframe-visible") === "true";
3682
+ button.src = isIframeVisible ? closeImageUrl : openImageUrl;
3683
+ iframe.style.display = isIframeVisible ? "block" : "none";
3684
+ const windowWidth = window.innerWidth;
3685
+ const windowHeight = window.innerHeight;
3686
+ const savedPosition = JSON.parse(
3687
+ localStorage.getItem("btc-wallet-button-position") || '{"right": "20px", "bottom": "20px"}'
3688
+ );
3689
+ const right = Math.min(Math.max(20, parseInt(savedPosition.right)), windowWidth - 80);
3690
+ const bottom = Math.min(Math.max(20, parseInt(savedPosition.bottom)), windowHeight - 80);
3691
+ Object.assign(button.style, {
3692
+ position: "fixed",
3693
+ bottom: `${bottom}px`,
3694
+ right: `${right}px`,
3695
+ zIndex: "100000",
3696
+ width: "60px",
3697
+ height: "60px",
3698
+ borderRadius: "50%",
3699
+ cursor: "grab",
3700
+ transition: "transform 0.15s ease",
3701
+ userSelect: "none"
3702
+ });
3703
+ document.body.appendChild(button);
3704
+ updateIframePosition(iframe, right, bottom, windowWidth, windowHeight);
3705
+ let isDragging = false;
3706
+ let startX = 0;
3707
+ let startY = 0;
3708
+ let initialRight = 0;
3709
+ let initialBottom = 0;
3710
+ let dragStartTime = 0;
3711
+ button.addEventListener("mousedown", (e) => {
3712
+ isDragging = true;
3713
+ startX = e.clientX;
3714
+ startY = e.clientY;
3715
+ initialRight = parseInt(button.style.right);
3716
+ initialBottom = parseInt(button.style.bottom);
3717
+ dragStartTime = Date.now();
3718
+ button.style.cursor = "grabbing";
3719
+ button.style.transition = "none";
3720
+ e.preventDefault();
3721
+ });
3722
+ document.addEventListener("mousemove", (e) => {
3723
+ if (!isDragging)
3724
+ return;
3725
+ const deltaX = startX - e.clientX;
3726
+ const deltaY = startY - e.clientY;
3727
+ let newRight = initialRight + deltaX;
3728
+ let newBottom = initialBottom + deltaY;
3729
+ newRight = Math.min(Math.max(20, newRight), windowWidth - 80);
3730
+ newBottom = Math.min(Math.max(20, newBottom), windowHeight - 80);
3731
+ const snapThreshold = 20;
3732
+ const buttonLeft = windowWidth - newRight - 60;
3733
+ if (buttonLeft < snapThreshold) {
3734
+ newRight = windowWidth - 80;
3735
+ } else if (buttonLeft > windowWidth - snapThreshold - 60) {
3736
+ newRight = 20;
3737
+ }
3738
+ if (newBottom < snapThreshold) {
3739
+ newBottom = 20;
3740
+ } else if (newBottom > windowHeight - snapThreshold - 60) {
3741
+ newBottom = windowHeight - 80;
3742
+ }
3743
+ button.style.right = `${newRight}px`;
3744
+ button.style.bottom = `${newBottom}px`;
3745
+ updateIframePosition(iframe, newRight, newBottom, windowWidth, windowHeight);
3746
+ });
3747
+ document.addEventListener("mouseup", () => {
3748
+ if (!isDragging)
3749
+ return;
3750
+ const dragEndTime = Date.now();
3751
+ const isDragEvent = dragEndTime - dragStartTime > 200;
3752
+ isDragging = false;
3753
+ button.style.cursor = "grab";
3754
+ button.style.transition = "transform 0.15s ease";
3755
+ localStorage.setItem(
3756
+ "btc-wallet-button-position",
3757
+ JSON.stringify({
3758
+ right: button.style.right,
3759
+ bottom: button.style.bottom
3760
+ })
3761
+ );
3762
+ if (!isDragEvent) {
3763
+ handleButtonClick();
3764
+ }
3765
+ });
3766
+ const handleButtonClick = () => {
3767
+ const isCurrentlyVisible = iframe.style.display === "block";
3768
+ button.style.transform = "scale(0.8)";
3769
+ setTimeout(() => {
3770
+ button.style.transform = "scale(1)";
3771
+ }, 150);
3772
+ const newVisibleState = !isCurrentlyVisible;
3773
+ iframe.style.display = newVisibleState ? "block" : "none";
3774
+ button.src = newVisibleState ? closeImageUrl : openImageUrl;
3775
+ localStorage.setItem("btc-wallet-iframe-visible", String(newVisibleState));
3776
+ setTimeout(() => {
3777
+ if (newVisibleState) {
3778
+ iframe.focus();
3779
+ }
3780
+ }, 0);
3781
+ };
3782
+ button.onclick = null;
3783
+ return button;
3784
+ }
3785
+ function createIframe({
3786
+ iframeUrl,
3787
+ iframeStyle = {}
3788
+ }) {
3789
+ const iframe = document.createElement("iframe");
3790
+ iframe.id = "satoshi-wallet-iframe";
3791
+ iframe.allow = "clipboard-read; clipboard-write";
3792
+ iframe.src = iframeUrl;
3793
+ const isVisible = localStorage.getItem("btc-wallet-iframe-visible") === "true";
3794
+ Object.assign(iframe.style, __spreadValues({
3795
+ position: "fixed",
3796
+ bottom: "90px",
3797
+ right: "20px",
3798
+ zIndex: "100000",
3799
+ boxShadow: "0 0 10px rgba(0, 0, 0, 0.1)",
3800
+ borderRadius: "10px",
3801
+ display: isVisible ? "block" : "none",
3802
+ border: "none"
3803
+ }, iframeStyle));
3804
+ document.body.appendChild(iframe);
3805
+ return iframe;
3806
+ }
3807
+ function setupButtonClickHandler(button, iframe, wallet, originalWallet) {
3808
+ return __async(this, null, function* () {
3809
+ var _a;
3810
+ const accountId = (_a = yield wallet == null ? void 0 : wallet.getAccounts()) == null ? void 0 : _a[0].accountId;
3811
+ const originalAccountId = originalWallet.account;
3812
+ const originalPublicKey = yield originalWallet.getPublicKey();
3813
+ console.log({ accountId, originalAccountId, originalPublicKey });
3814
+ const iframeSrc = new URL(iframe.src);
3815
+ iframeSrc.searchParams.set("origin", window.location.origin);
3816
+ accountId && iframeSrc.searchParams.set("accountId", accountId);
3817
+ originalAccountId && iframeSrc.searchParams.set("originalAccountId", originalAccountId);
3818
+ originalPublicKey && iframeSrc.searchParams.set("originalPublicKey", originalPublicKey);
3819
+ iframe.src = iframeSrc.toString();
3820
+ const actions = {
3821
+ signAndSendTransaction: wallet.signAndSendTransaction,
3822
+ executeBTCDepositAndAction
3823
+ };
3824
+ window.addEventListener("message", (event) => __async(this, null, function* () {
3825
+ var _a2, _b;
3826
+ if (event.origin !== iframeSrc.origin)
3827
+ return;
3828
+ const { action, requestId, data } = event.data;
3829
+ try {
3830
+ const actionFn = actions[action];
3831
+ if (!actionFn)
3832
+ return;
3833
+ console.log("handleWalletAction", action, event.data);
3834
+ const result = yield actionFn(data);
3835
+ console.log("handleWalletAction result", action, result);
3836
+ (_a2 = event.source) == null ? void 0 : _a2.postMessage(
3837
+ {
3838
+ requestId,
3839
+ data,
3840
+ success: true
3841
+ },
3842
+ { targetOrigin: event.origin }
3843
+ );
3844
+ } catch (error) {
3845
+ console.error("handleWalletAction error", action, error);
3846
+ (_b = event.source) == null ? void 0 : _b.postMessage(
3847
+ {
3848
+ requestId,
3849
+ error: error.message,
3850
+ success: false
3851
+ },
3852
+ { targetOrigin: event.origin }
3853
+ );
3854
+ }
3855
+ }));
3856
+ });
3857
+ }
3858
+ function removeWalletButton() {
3859
+ const button = document.getElementById("satoshi-wallet-button");
3860
+ button == null ? void 0 : button.remove();
3861
+ const iframe = document.getElementById("satoshi-wallet-iframe");
3862
+ iframe == null ? void 0 : iframe.remove();
3863
+ }
3864
+ function updateIframePosition(iframe, buttonRight, buttonBottom, windowWidth, windowHeight) {
3865
+ const iframeWidth = parseInt(iframe.style.width);
3866
+ const iframeHeight = parseInt(iframe.style.height);
3867
+ let iframeRight = buttonRight;
3868
+ let iframeBottom = buttonBottom + 70;
3869
+ if (iframeRight + iframeWidth > windowWidth - 20) {
3870
+ iframeRight = Math.max(20, windowWidth - iframeWidth - 20);
3871
+ }
3872
+ if (iframeBottom + iframeHeight > windowHeight - 20) {
3873
+ iframeBottom = Math.max(20, buttonBottom - iframeHeight - 10);
3874
+ }
3875
+ iframe.style.right = `${iframeRight}px`;
3876
+ iframe.style.bottom = `${iframeBottom}px`;
3877
+ }
3878
+
3879
3879
  // src/core/setupBTCWallet.ts
3880
+ import Big2 from "big.js";
3880
3881
  var { transfer, functionCall } = actionCreators;
3881
3882
  var STORAGE_KEYS = {
3882
3883
  ACCOUNT: "btc-wallet-account",
@@ -4389,7 +4390,7 @@ function setupBTCWallet({
4389
4390
 
4390
4391
  // src/index.ts
4391
4392
  var getVersion = () => {
4392
- return "0.5.1-beta";
4393
+ return "0.5.3-beta";
4393
4394
  };
4394
4395
  if (typeof window !== "undefined") {
4395
4396
  window.__BTC_WALLET_VERSION = getVersion();
@@ -4416,6 +4417,7 @@ export {
4416
4417
  getAccountInfo,
4417
4418
  getBtcBalance,
4418
4419
  getBtcGasPrice,
4420
+ getConfig,
4419
4421
  getCsnaAccountId,
4420
4422
  getDepositAmount,
4421
4423
  getNBTCBalance,