btc-wallet 0.5.53-beta → 0.5.56-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/index.js CHANGED
@@ -234,6 +234,51 @@ function isMobile() {
234
234
  }
235
235
  return false;
236
236
  }
237
+ function safeJSONParse(str) {
238
+ try {
239
+ return JSON.parse(str);
240
+ } catch (e) {
241
+ console.error("safeJSONParse", e);
242
+ return void 0;
243
+ }
244
+ }
245
+ function safeJSONStringify(obj) {
246
+ try {
247
+ return JSON.stringify(obj);
248
+ } catch (e) {
249
+ console.error("safeJSONStringify", e);
250
+ return void 0;
251
+ }
252
+ }
253
+ function storageStore(namespace, options) {
254
+ if (typeof window === "undefined")
255
+ return;
256
+ const _namespace = namespace || "SATOSHI_WALLET_DEFAULT";
257
+ const storage5 = (options == null ? void 0 : options.storage) || (window == null ? void 0 : window.localStorage);
258
+ const namespaceKey = (key) => {
259
+ return _namespace + ":" + key;
260
+ };
261
+ return {
262
+ set(key, value) {
263
+ const _value = safeJSONStringify(value);
264
+ _value ? storage5.setItem(namespaceKey(key), _value) : storage5.removeItem(namespaceKey(key));
265
+ },
266
+ get(key) {
267
+ const _value = storage5.getItem(namespaceKey(key));
268
+ return _value ? safeJSONParse(_value) : void 0;
269
+ },
270
+ remove(key) {
271
+ storage5.removeItem(namespaceKey(key));
272
+ },
273
+ clearAll: function clearAll() {
274
+ for (const key in storage5) {
275
+ if (key.startsWith(namespace + ":")) {
276
+ storage5.removeItem(key);
277
+ }
278
+ }
279
+ }
280
+ };
281
+ }
237
282
 
238
283
  // src/utils/Dialog.ts
239
284
  var Dialog = class {
@@ -503,7 +548,7 @@ var MobileWalletConnect = class {
503
548
  case "okx":
504
549
  return `okx://wallet/dapp/url?dappUrl=${encodeURIComponent(url)}`;
505
550
  case "bitget":
506
- return `https://bkcode.vip?action=dapp&url=${encodeURIComponent(url)}`;
551
+ return `bitkeep://bkconnect?action=dapp&url=${encodeURIComponent(url)}`;
507
552
  case "xverse":
508
553
  return `xverse://browser?url=${encodeURIComponent(url)}`;
509
554
  default:
@@ -589,9 +634,13 @@ var InjectedConnector = class extends BaseConnector {
589
634
  }
590
635
  requestAccounts() {
591
636
  return __async(this, null, function* () {
592
- if (isMobile() && !this.getProvider()) {
593
- MobileWalletConnect.redirectToWallet(this.metadata.id);
594
- return [];
637
+ if (isMobile()) {
638
+ try {
639
+ this.getProvider();
640
+ } catch (error) {
641
+ yield MobileWalletConnect.redirectToWallet(this.metadata.id);
642
+ return [];
643
+ }
595
644
  }
596
645
  const accounts = yield this.getProviderOrThrow().requestAccounts();
597
646
  console.log("network:", yield this.getNetwork());
@@ -776,6 +825,7 @@ var import_events = __toESM(require("events"), 1);
776
825
  var xverse_default = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAIAAAACACAYAAADDPmHLAAALhUlEQVR4nO2dT2wc1R3Hv7+dFk/kN8u2tdBsLJThUCm0SNhCKn8utcWFG644wCk4p4I4JBZIKb2YnEokIpJbgaomioTKIWJzA6lVHFUy9JRNRapU5TA0sj3igMbOa7uO2H095D2zXu+/2Z0/783OR7IcrzzzXvz9zJs3b968IeQQ13W9Uqk0J4TwABwTQlQAePILbd878YkoFEKERBQC8AF8LYSoW5YVbm5u1lP8b6QCZV2BcXFd1wOwQESPA1gA4MnAY0fKUSeiOhFdb7Va9SAI/CTKSgvjBPA8r9JoNOaI6HkhxFKfozkViKguhKgDuBQEwXqWdRkFYwRwXXcBwMtEtJTUET4usoWolUqlq1tbW7Ws6zMMWgswOzs712w2nyei07qG3gcfwDqAszqfJrQUQB7tq/KcngeUCNqdIrQSIIfBd+JLET7MuiIKLQSYgOA70UaETAWQl3BrExT8AYioJoRYybKPYGVRqOd5Fdu2zwCoZX0ZlzHHAZxmjGFmZuZmGIaNtCuQegsgm/u1CQ++Gz6Ak2l3FFNrATzPqxw5cuR3AH4PwLRLujSoAFh2HKfCOf8srUJTaQHkuf5acdQPjQ9gMY2+QSnpAlzXfZmI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SWTMF6AbszOzs41m80KEc3JvsMxIUSFiCpSjl79Cb/tu09EO/K732q16qaH3Y3/A6eWgM0UqgCVAAAAAElFTkSuQmCC";
777
826
 
778
827
  // src/connector/xverse.ts
828
+ var storage = storageStore("SATOSHI_WALLET_XVERSE");
779
829
  var _network, _event;
780
830
  var XverseConnector = class extends BaseConnector {
781
831
  constructor() {
@@ -801,7 +851,7 @@ var XverseConnector = class extends BaseConnector {
801
851
  walletType
802
852
  }));
803
853
  console.log("\u{1F680} ~ XverseConnector ~ loadAccounts ~ res:", addresses);
804
- localStorage.setItem("btc-connect-xverse-addresses-" + network, JSON.stringify(addresses));
854
+ storage == null ? void 0 : storage.set(`${network}:addresses`, addresses);
805
855
  return addresses;
806
856
  });
807
857
  __privateGet(this, _event).setMaxListeners(100);
@@ -836,9 +886,9 @@ var XverseConnector = class extends BaseConnector {
836
886
  }
837
887
  getAddresses() {
838
888
  return __async(this, null, function* () {
839
- const data = localStorage.getItem("btc-connect-xverse-addresses-" + __privateGet(this, _network));
889
+ const data = storage == null ? void 0 : storage.get(`${__privateGet(this, _network)}:addresses`);
840
890
  if (data) {
841
- return JSON.parse(data);
891
+ return data;
842
892
  }
843
893
  return [];
844
894
  });
@@ -923,8 +973,7 @@ var XverseConnector = class extends BaseConnector {
923
973
  });
924
974
  }
925
975
  disconnect() {
926
- localStorage.removeItem("btc-connect-xverse-addresses-Mainnet");
927
- localStorage.removeItem("btc-connect-xverse-addresses-Testnet");
976
+ storage == null ? void 0 : storage.remove(`${__privateGet(this, _network)}:addresses`);
928
977
  }
929
978
  };
930
979
  _network = new WeakMap();
@@ -937,6 +986,7 @@ var import_events2 = __toESM(require("events"), 1);
937
986
  var magicEden_default = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADYAAAAgCAYAAABZyotbAAADGklEQVR42sVYTW7aQBT+ZsZk0yy8jWoqIxWK1E16A3KDcoLACRqkGKFugE0VAVLgBElOQHqC0BPUm0q0EMVVoWxZNCsYv25MlR/AY2O73xKZefO9ed+b7w0DgFm+ZrquPCdCAYAOwAbQM0btS0SIaa5aJ6AEIhPR49Ge2SxfM6Urb0B4Fowx1nj5o9WMhpTVJ8J7xA3OKsb3VpdNs9YFAaVN30VBbpqr1omogWQwXyxeZDhhexaJqDHNVetho8zyNTNBUgCga9qfQ+5pCnGQuzMbunTlDf4DuOqHYcjtpe7P12k3XjAnPe4MeJC/BCH3+431YZt249KXEPwIANgka1HgnPg0lFm+Zkopv6qU+aasAzQImPSfy+V+N+M05gCghQnrnRw2kfN0pYdPPOlCiObB8MyJXWOqZTnNVesR6EqXUt7cmQ09cWLryE2yVsm/tTOHXLensLyZSt33Q7eQMBpbpznO+dUmB/ME74xR255kTy8BdqywetcYtSqJntjDk5NS3vmRIqKmMWrbALBYLE88f+e3+kmYO1SF2ADRYJAed/6VacbpzoUQRTDmqCTu1+vTQqTEiKhJRDsaYeYIIcpPfz0YnjmC8yMAc4Vyr0deiulxp7ELOSK3vKl1HwzPHCIqKixTCNIllTUWlhwRNdPjztZy1jTNQcQI1DxCkHukq40uRckoM2flKmLpit5Gy2F19RSulEoXuuuiEtuJreCN3+Wwunr2VKBQzq9uW9eJ3GPbyKnoSnUAJRc9v3KO/II2Ru1LIUQGoCsANmO4BlD220iAAdRO37ZPwuxN27X7eOUWaO7aS92fk6+umCMEL4bdVySWKgjUBlDmCMGPdhlbtCRJeQOogl5Il1LWJ1kryPJfhBCDVTISJSal7CsOoDqCPyuUpJTOJGsVjVHbTqwUJ1mrBOAw5jAmgH7SGjtOKI45efvx0JfYcrlvRxKOJfsMx33mrUEQf7bdPeBzMpSYY3z7ZHMAlfXzkJrXU26/QnRVhspdsfKU7EEbvgBQ8Ehe7/r8taXdFzy96WBMj+ycQLbrUm9l5f4C3RupufZdcK8AAAAASUVORK5CYII=";
938
987
 
939
988
  // src/connector/magicEden.ts
989
+ var storage2 = storageStore("SATOSHI_WALLET_MAGICEDEN");
940
990
  var _network2, _event2;
941
991
  var MagicEdenConnector = class extends BaseConnector {
942
992
  constructor() {
@@ -970,7 +1020,7 @@ var MagicEdenConnector = class extends BaseConnector {
970
1020
  };
971
1021
  getAddress(getAddressOptions).catch((error) => reject(error));
972
1022
  });
973
- localStorage.setItem("btc-connect-magicEden-addresses-" + network, JSON.stringify(addresses));
1023
+ storage2 == null ? void 0 : storage2.set(`${network}:addresses`, addresses);
974
1024
  return addresses;
975
1025
  });
976
1026
  __privateGet(this, _event2).setMaxListeners(100);
@@ -997,10 +1047,9 @@ var MagicEdenConnector = class extends BaseConnector {
997
1047
  if (!this.isReady()) {
998
1048
  throw new Error(`${this.metadata.name} is not install!`);
999
1049
  }
1000
- const data = localStorage.getItem("btc-connect-magicEden-addresses-" + __privateGet(this, _network2));
1050
+ const data = storage2 == null ? void 0 : storage2.get(`${__privateGet(this, _network2)}:addresses`);
1001
1051
  if (data) {
1002
- const addresses = JSON.parse(data);
1003
- return addresses.map((item) => item.address);
1052
+ return data.map((item) => item.address);
1004
1053
  } else {
1005
1054
  return [];
1006
1055
  }
@@ -1011,10 +1060,9 @@ var MagicEdenConnector = class extends BaseConnector {
1011
1060
  if (!this.isReady()) {
1012
1061
  throw new Error(`${this.metadata.name} is not install!`);
1013
1062
  }
1014
- const data = localStorage.getItem("btc-connect-magicEden-addresses-" + __privateGet(this, _network2));
1063
+ const data = storage2 == null ? void 0 : storage2.get(`${__privateGet(this, _network2)}:addresses`);
1015
1064
  if (data) {
1016
- const addresses = JSON.parse(data);
1017
- return addresses[0].publicKey;
1065
+ return data[0].publicKey;
1018
1066
  } else {
1019
1067
  return "";
1020
1068
  }
@@ -1127,8 +1175,7 @@ var MagicEdenConnector = class extends BaseConnector {
1127
1175
  });
1128
1176
  }
1129
1177
  disconnect() {
1130
- localStorage.removeItem("btc-connect-magicEden-addresses-Mainnet");
1131
- localStorage.removeItem("btc-connect-magicEden-addresses-Testnet");
1178
+ storage2 == null ? void 0 : storage2.remove(`${__privateGet(this, _network2)}:addresses`);
1132
1179
  }
1133
1180
  };
1134
1181
  _network2 = new WeakMap();
@@ -1222,13 +1269,14 @@ var useConnector = () => {
1222
1269
  const { connectors, setConnectorId } = useConnectProvider();
1223
1270
  const connect = (0, import_react2.useCallback)(
1224
1271
  (connectorId) => __async(void 0, null, function* () {
1272
+ var _a;
1225
1273
  const connector = connectors.find((item) => item.metadata.id === connectorId);
1226
1274
  if (!connector) {
1227
1275
  throw new Error(`connector id ${connectorId} not found`);
1228
1276
  }
1229
1277
  const accounts = yield connector.requestAccounts();
1230
1278
  if (accounts.length > 0) {
1231
- localStorage.setItem("current-connector-id", connector.metadata.id);
1279
+ (_a = storageStore()) == null ? void 0 : _a.set("current-connector-id", connector.metadata.id);
1232
1280
  setConnectorId(connector.metadata.id);
1233
1281
  }
1234
1282
  }),
@@ -2391,10 +2439,11 @@ var ConnectProvider = ({
2391
2439
  version: ((_c = options.aaOptions.accountContracts[((_b = Object.keys(options.aaOptions.accountContracts)) == null ? void 0 : _b[0]) || "BTC"]) == null ? void 0 : _c[0].version) || "1.0.0"
2392
2440
  });
2393
2441
  const getConnectorId = (0, import_react10.useCallback)(() => {
2442
+ var _a2;
2394
2443
  if (typeof window === "undefined") {
2395
2444
  return "";
2396
2445
  }
2397
- const id = localStorage.getItem("current-connector-id");
2446
+ const id = (_a2 = storageStore()) == null ? void 0 : _a2.get("current-connector-id");
2398
2447
  return id != null ? id : "";
2399
2448
  }, []);
2400
2449
  const getConnector = (0, import_react10.useCallback)(() => {
@@ -2536,7 +2585,8 @@ var ConnectProvider = ({
2536
2585
  }
2537
2586
  }, [connectorId, connectors]);
2538
2587
  const disconnect = (0, import_react10.useCallback)(() => {
2539
- localStorage.removeItem("current-connector-id");
2588
+ var _a2;
2589
+ (_a2 = storageStore()) == null ? void 0 : _a2.remove("current-connector-id");
2540
2590
  txConfirmUtils_default.reset();
2541
2591
  if (connector) {
2542
2592
  connector.disconnect();
@@ -2725,7 +2775,9 @@ function BtcWalletSelectorContextProvider({
2725
2775
  new UnisatConnector(),
2726
2776
  new XverseConnector(),
2727
2777
  new OKXConnector(),
2728
- new BitgetConnector()
2778
+ new BitgetConnector(),
2779
+ new MagicEdenConnector(),
2780
+ new BybitConnector()
2729
2781
  ];
2730
2782
  const walletSelectorContextValue = (0, import_react11.useMemo)(() => {
2731
2783
  const simpleFn = {};
@@ -3148,7 +3200,7 @@ function pollTransactionStatuses(network, hashes) {
3148
3200
  var import_transactions = require("@near-js/transactions");
3149
3201
  var import_key_pair = require("near-api-js/lib/utils/key_pair");
3150
3202
  var import_transaction = require("near-api-js/lib/transaction");
3151
- var import_utils9 = require("@near-js/utils");
3203
+ var import_utils13 = require("@near-js/utils");
3152
3204
  var import_bs58 = __toESM(require("bs58"), 1);
3153
3205
  var import_js_sha256 = require("js-sha256");
3154
3206
  var import_near_api_js2 = require("near-api-js");
@@ -3160,36 +3212,37 @@ var STORAGE_KEYS = {
3160
3212
  PUBLIC_KEY: "btc-wallet-publickey",
3161
3213
  BTC_PUBLIC_KEY: "btc-wallet-btc-publickey"
3162
3214
  };
3215
+ var storage3 = storageStore("SATOSHI_WALLET_ACCOUNT");
3163
3216
  var state_default = {
3164
3217
  saveAccount(account) {
3165
3218
  if (!account) {
3166
3219
  this.removeAccount();
3167
3220
  return;
3168
3221
  }
3169
- window.localStorage.setItem(STORAGE_KEYS.ACCOUNT, account);
3222
+ storage3 == null ? void 0 : storage3.set(STORAGE_KEYS.ACCOUNT, account);
3170
3223
  },
3171
3224
  removeAccount() {
3172
- window.localStorage.removeItem(STORAGE_KEYS.ACCOUNT);
3225
+ storage3 == null ? void 0 : storage3.remove(STORAGE_KEYS.ACCOUNT);
3173
3226
  },
3174
3227
  savePublicKey(publicKey) {
3175
3228
  if (!publicKey) {
3176
3229
  this.removePublicKey();
3177
3230
  return;
3178
3231
  }
3179
- window.localStorage.setItem(STORAGE_KEYS.PUBLIC_KEY, publicKey);
3232
+ storage3 == null ? void 0 : storage3.set(STORAGE_KEYS.PUBLIC_KEY, publicKey);
3180
3233
  },
3181
3234
  removePublicKey() {
3182
- window.localStorage.removeItem(STORAGE_KEYS.PUBLIC_KEY);
3235
+ storage3 == null ? void 0 : storage3.remove(STORAGE_KEYS.PUBLIC_KEY);
3183
3236
  },
3184
3237
  saveBtcPublicKey(publicKey) {
3185
3238
  if (!publicKey) {
3186
3239
  this.removeBtcPublicKey();
3187
3240
  return;
3188
3241
  }
3189
- window.localStorage.setItem(STORAGE_KEYS.BTC_PUBLIC_KEY, publicKey);
3242
+ storage3 == null ? void 0 : storage3.set(STORAGE_KEYS.BTC_PUBLIC_KEY, publicKey);
3190
3243
  },
3191
3244
  removeBtcPublicKey() {
3192
- window.localStorage.removeItem(STORAGE_KEYS.BTC_PUBLIC_KEY);
3245
+ storage3 == null ? void 0 : storage3.remove(STORAGE_KEYS.BTC_PUBLIC_KEY);
3193
3246
  },
3194
3247
  clear() {
3195
3248
  this.removeAccount();
@@ -3205,13 +3258,13 @@ var state_default = {
3205
3258
  this.savePublicKey(publicKey);
3206
3259
  },
3207
3260
  getAccount() {
3208
- return window.localStorage.getItem(STORAGE_KEYS.ACCOUNT) || "";
3261
+ return (storage3 == null ? void 0 : storage3.get(STORAGE_KEYS.ACCOUNT)) || "";
3209
3262
  },
3210
3263
  getPublicKey() {
3211
- return window.localStorage.getItem(STORAGE_KEYS.PUBLIC_KEY) || "";
3264
+ return (storage3 == null ? void 0 : storage3.get(STORAGE_KEYS.PUBLIC_KEY)) || "";
3212
3265
  },
3213
3266
  getBtcPublicKey() {
3214
- return window.localStorage.getItem(STORAGE_KEYS.BTC_PUBLIC_KEY) || "";
3267
+ return (storage3 == null ? void 0 : storage3.get(STORAGE_KEYS.BTC_PUBLIC_KEY)) || "";
3215
3268
  },
3216
3269
  isValid() {
3217
3270
  const account = this.getAccount();
@@ -3514,7 +3567,7 @@ function convertTransactionToTxHex(_0) {
3514
3567
  transaction.receiverId,
3515
3568
  BigInt(nearNonceNumber) + BigInt(index),
3516
3569
  newActions,
3517
- (0, import_utils9.baseDecode)(header.hash)
3570
+ (0, import_utils13.baseDecode)(header.hash)
3518
3571
  );
3519
3572
  const txBytes = (0, import_transaction.encodeTransaction)(_transaction);
3520
3573
  const txHex = Array.from(txBytes, (byte) => ("0" + (byte & 255).toString(16)).slice(-2)).join(
@@ -3536,7 +3589,8 @@ function calculateGasStrategy(_0) {
3536
3589
  return __async(this, arguments, function* ({
3537
3590
  csna,
3538
3591
  transactions: transactions2,
3539
- env
3592
+ env,
3593
+ gasStrategy = "auto"
3540
3594
  }) {
3541
3595
  var _a;
3542
3596
  const currentConfig = getWalletConfig(env);
@@ -3568,6 +3622,7 @@ function calculateGasStrategy(_0) {
3568
3622
  const nearAvailableBalance = new import_big.default(nearBalance).minus(transferAmount.near).toNumber();
3569
3623
  console.log("available near balance:", nearAvailableBalance);
3570
3624
  console.log("available gas token balance:", gasTokenBalance);
3625
+ console.log("gas strategy:", gasStrategy);
3571
3626
  const convertTx = yield Promise.all(
3572
3627
  transactions2.map(
3573
3628
  (transaction, index) => convertTransactionToTxHex({
@@ -3579,8 +3634,20 @@ function calculateGasStrategy(_0) {
3579
3634
  })
3580
3635
  )
3581
3636
  );
3582
- if (nearAvailableBalance > 0.5) {
3583
- console.log("near balance is enough, get the protocol fee of each transaction");
3637
+ let useNearPayGas = false;
3638
+ let perTxFee;
3639
+ if (gasStrategy === "near") {
3640
+ console.log("Forcing NEAR as gas token based on gasStrategy");
3641
+ useNearPayGas = true;
3642
+ } else if (gasStrategy === "btc") {
3643
+ console.log("Forcing BTC token as gas token based on gasStrategy");
3644
+ useNearPayGas = false;
3645
+ } else if (nearAvailableBalance > 0.5) {
3646
+ console.log("NEAR balance is enough, using NEAR to pay for gas");
3647
+ useNearPayGas = true;
3648
+ }
3649
+ let gasAmount;
3650
+ if (useNearPayGas) {
3584
3651
  const gasTokens = yield nearCallFunction(
3585
3652
  currentConfig.accountContractId,
3586
3653
  "list_gas_token",
@@ -3588,39 +3655,29 @@ function calculateGasStrategy(_0) {
3588
3655
  { network: currentConfig.network }
3589
3656
  );
3590
3657
  console.log("list_gas_token gas tokens:", gasTokens);
3591
- const perTxFee = Math.max(
3592
- Number(((_a = gasTokens[currentConfig.btcToken]) == null ? void 0 : _a.per_tx_protocol_fee) || 0),
3593
- 100
3594
- );
3658
+ const fee = Math.max(Number(((_a = gasTokens[currentConfig.btcToken]) == null ? void 0 : _a.per_tx_protocol_fee) || 0), 100);
3659
+ perTxFee = fee.toString();
3595
3660
  console.log("perTxFee:", perTxFee);
3596
- const protocolFee = new import_big.default(perTxFee || "0").mul(convertTx.length).toFixed(0);
3597
- console.log("protocolFee:", protocolFee);
3598
- const transferTx = yield createGasTokenTransfer({ csna, amount: protocolFee, env });
3599
- return recalculateGasWithTransfer({
3600
- csna,
3601
- transferTx,
3602
- transactions: convertTx,
3603
- useNearPayGas: true,
3604
- perTxFee: perTxFee.toString(),
3605
- env
3606
- });
3661
+ gasAmount = new import_big.default(perTxFee || "0").mul(convertTx.length).toFixed(0);
3607
3662
  } else {
3608
- console.log("near balance is not enough, predict the gas token amount required");
3609
- const adjustedGas = yield getPredictedGasAmount({
3663
+ gasAmount = yield getPredictedGasAmount({
3610
3664
  accountContractId: currentConfig.accountContractId,
3611
3665
  tokenId: currentConfig.btcToken,
3612
3666
  transactions: convertTx.map((t) => t.txHex),
3613
3667
  env
3614
3668
  });
3615
- const transferTx = yield createGasTokenTransfer({ csna, amount: adjustedGas, env });
3616
- return recalculateGasWithTransfer({
3617
- csna,
3618
- transferTx,
3619
- transactions: convertTx,
3620
- useNearPayGas: false,
3621
- env
3622
- });
3623
3669
  }
3670
+ console.log("useNearPayGas:", useNearPayGas);
3671
+ console.log("gasAmount:", gasAmount);
3672
+ const transferTx = yield createGasTokenTransfer({ csna, amount: gasAmount, env });
3673
+ return recalculateGasWithTransfer({
3674
+ csna,
3675
+ transferTx,
3676
+ transactions: convertTx,
3677
+ useNearPayGas,
3678
+ perTxFee,
3679
+ env
3680
+ });
3624
3681
  });
3625
3682
  }
3626
3683
  function createGasTokenTransfer(_0) {
@@ -3907,11 +3964,13 @@ function getCsnaAccountId(env) {
3907
3964
  });
3908
3965
  }
3909
3966
  function checkDepositDisabledAddress() {
3910
- const data = localStorage.getItem("btc-connect-xverse-addresses-Mainnet");
3967
+ var _a;
3968
+ const data = (_a = storageStore("SATOSHI_WALLET_XVERSE")) == null ? void 0 : _a.get(
3969
+ `Mainnet:addresses`
3970
+ );
3911
3971
  if (!data)
3912
3972
  return;
3913
- const addresses = JSON.parse(data);
3914
- const address = addresses == null ? void 0 : addresses[0];
3973
+ const address = data == null ? void 0 : data[0];
3915
3974
  if (address.walletType === "ledger" && !["p2wpkh", "p2sh"].includes(address.addressType)) {
3916
3975
  throw new Error("Ledger is only supported for p2wpkh and p2sh address");
3917
3976
  }
@@ -3948,7 +4007,7 @@ function executeBTCDepositAndAction(_0) {
3948
4007
  throw new Error("Deposit amount or action is required");
3949
4008
  }
3950
4009
  const csna = yield getCsnaAccountId(env);
3951
- const depositAmount = Number(amount || (action == null ? void 0 : action.amount) || 0);
4010
+ const depositAmount = new import_big2.default(amount || (action == null ? void 0 : action.amount) || 0).round(0, import_big2.default.roundDown).toNumber();
3952
4011
  console.log("depositAmount", depositAmount);
3953
4012
  if (depositAmount <= 0) {
3954
4013
  throw new Error("Invalid deposit amount");
@@ -4052,13 +4111,14 @@ function checkSatoshiWhitelist(btcAccountId, env = "mainnet") {
4052
4111
  return __async(this, null, function* () {
4053
4112
  if (env !== "mainnet")
4054
4113
  return;
4055
- const hasShownNotice = localStorage.getItem("btc-wallet-private-mainnet-notice");
4114
+ const storage5 = storageStore();
4115
+ const hasShownNotice = storage5 == null ? void 0 : storage5.get("private-mainnet-notice");
4056
4116
  if (!hasShownNotice) {
4057
4117
  Dialog.alert({
4058
4118
  title: "Notice",
4059
4119
  message: "You are currently using Satoshi Private Mainnet. This is a private version for testing. Please try a small amount of assets in Ramp"
4060
4120
  });
4061
- localStorage.setItem("btc-wallet-private-mainnet-notice", "true");
4121
+ storage5 == null ? void 0 : storage5.set("private-mainnet-notice", "true");
4062
4122
  }
4063
4123
  if (!btcAccountId)
4064
4124
  return;
@@ -4388,7 +4448,13 @@ function uint8ArrayToHex(uint8Array) {
4388
4448
  }
4389
4449
 
4390
4450
  // src/utils/initWalletButton.ts
4391
- function setupWalletButton(env, wallet, originalWallet, walletUrl) {
4451
+ var storage4 = storageStore("SATOSHI_WALLET_BUTTON");
4452
+ function setupWalletButton({
4453
+ env,
4454
+ nearWallet,
4455
+ btcWallet,
4456
+ walletUrl
4457
+ }) {
4392
4458
  console.log(`setupWalletButton ${walletUrl || ""}`);
4393
4459
  if (document.getElementById("satoshi-wallet-button")) {
4394
4460
  return;
@@ -4411,23 +4477,25 @@ function setupWalletButton(env, wallet, originalWallet, walletUrl) {
4411
4477
  closeImageUrl: "https://assets.deltatrade.ai/wallet-assets/wallet-btn-active.png",
4412
4478
  iframe
4413
4479
  });
4414
- setupButtonClickHandler(button, iframe, wallet, originalWallet);
4480
+ setupButtonClickHandler(button, iframe, nearWallet, btcWallet);
4415
4481
  }
4416
4482
  function createFloatingButtonWithIframe({
4417
4483
  openImageUrl,
4418
4484
  closeImageUrl,
4419
4485
  iframe
4420
4486
  }) {
4487
+ var _a;
4421
4488
  const button = document.createElement("img");
4422
4489
  button.id = "satoshi-wallet-button";
4423
- const isIframeVisible = localStorage.getItem("btc-wallet-iframe-visible") === "true";
4490
+ const isIframeVisible = (_a = storage4 == null ? void 0 : storage4.get("visible")) != null ? _a : true;
4424
4491
  button.src = isIframeVisible ? closeImageUrl : openImageUrl;
4425
4492
  iframe.style.display = isIframeVisible ? "block" : "none";
4426
4493
  const windowWidth = window.innerWidth;
4427
4494
  const windowHeight = window.innerHeight;
4428
- const savedPosition = JSON.parse(
4429
- localStorage.getItem("btc-wallet-button-position") || '{"right": "20px", "bottom": "20px"}'
4430
- );
4495
+ const savedPosition = (storage4 == null ? void 0 : storage4.get("position")) || {
4496
+ right: "20px",
4497
+ bottom: "20px"
4498
+ };
4431
4499
  const right = Math.min(Math.max(20, parseInt(savedPosition.right)), windowWidth - 80);
4432
4500
  const bottom = Math.min(Math.max(20, parseInt(savedPosition.bottom)), windowHeight - 80);
4433
4501
  Object.assign(button.style, {
@@ -4523,13 +4591,10 @@ function createFloatingButtonWithIframe({
4523
4591
  isDragging = false;
4524
4592
  button.style.cursor = "grab";
4525
4593
  button.style.transition = "transform 0.15s ease";
4526
- localStorage.setItem(
4527
- "btc-wallet-button-position",
4528
- JSON.stringify({
4529
- right: button.style.right,
4530
- bottom: button.style.bottom
4531
- })
4532
- );
4594
+ storage4 == null ? void 0 : storage4.set("position", {
4595
+ right: button.style.right,
4596
+ bottom: button.style.bottom
4597
+ });
4533
4598
  if (!isDragEvent) {
4534
4599
  handleButtonClick();
4535
4600
  }
@@ -4543,7 +4608,7 @@ function createFloatingButtonWithIframe({
4543
4608
  const newVisibleState = !isCurrentlyVisible;
4544
4609
  iframe.style.display = newVisibleState ? "block" : "none";
4545
4610
  button.src = newVisibleState ? closeImageUrl : openImageUrl;
4546
- localStorage.setItem("btc-wallet-iframe-visible", String(newVisibleState));
4611
+ storage4 == null ? void 0 : storage4.set("visible", newVisibleState);
4547
4612
  setTimeout(() => {
4548
4613
  if (newVisibleState) {
4549
4614
  iframe.focus();
@@ -4557,11 +4622,12 @@ function createIframe({
4557
4622
  iframeUrl,
4558
4623
  iframeStyle = {}
4559
4624
  }) {
4625
+ var _a;
4560
4626
  const iframe = document.createElement("iframe");
4561
4627
  iframe.id = "satoshi-wallet-iframe";
4562
4628
  iframe.allow = "clipboard-read; clipboard-write";
4563
4629
  iframe.src = iframeUrl;
4564
- const isVisible = localStorage.getItem("btc-wallet-iframe-visible") === "true";
4630
+ const isVisible = (_a = storage4 == null ? void 0 : storage4.get("visible")) != null ? _a : true;
4565
4631
  Object.assign(iframe.style, __spreadValues({
4566
4632
  position: "fixed",
4567
4633
  bottom: "90px",
@@ -4576,12 +4642,12 @@ function createIframe({
4576
4642
  return iframe;
4577
4643
  }
4578
4644
  var currentMessageHandler = null;
4579
- function setupButtonClickHandler(button, iframe, wallet, originalWallet) {
4645
+ function setupButtonClickHandler(button, iframe, nearWallet, btcWallet) {
4580
4646
  return __async(this, null, function* () {
4581
4647
  var _a;
4582
- const accountId = (_a = yield wallet == null ? void 0 : wallet.getAccounts()) == null ? void 0 : _a[0].accountId;
4583
- const originalAccountId = originalWallet.account;
4584
- const originalPublicKey = yield originalWallet.getPublicKey();
4648
+ const accountId = (_a = yield nearWallet == null ? void 0 : nearWallet.getAccounts()) == null ? void 0 : _a[0].accountId;
4649
+ const originalAccountId = btcWallet == null ? void 0 : btcWallet.account;
4650
+ const originalPublicKey = yield btcWallet == null ? void 0 : btcWallet.getPublicKey();
4585
4651
  console.log({ accountId, originalAccountId, originalPublicKey });
4586
4652
  const iframeSrc = new URL(iframe.src);
4587
4653
  iframeSrc.searchParams.set("origin", window.location.origin);
@@ -4590,8 +4656,8 @@ function setupButtonClickHandler(button, iframe, wallet, originalWallet) {
4590
4656
  originalPublicKey && iframeSrc.searchParams.set("originalPublicKey", originalPublicKey);
4591
4657
  iframe.src = iframeSrc.toString();
4592
4658
  const actions = {
4593
- signAndSendTransaction: wallet.signAndSendTransaction,
4594
- signAndSendTransactions: wallet.signAndSendTransactions,
4659
+ signAndSendTransaction: nearWallet.signAndSendTransaction,
4660
+ signAndSendTransactions: nearWallet.signAndSendTransactions,
4595
4661
  executeBTCDepositAndAction,
4596
4662
  getWithdrawTransaction
4597
4663
  };
@@ -4636,6 +4702,7 @@ function setupButtonClickHandler(button, iframe, wallet, originalWallet) {
4636
4702
  });
4637
4703
  }
4638
4704
  function removeWalletButton() {
4705
+ console.log("removeWalletButton");
4639
4706
  const button = document.getElementById("satoshi-wallet-button");
4640
4707
  button == null ? void 0 : button.remove();
4641
4708
  const iframe = document.getElementById("satoshi-wallet-iframe");
@@ -4742,10 +4809,14 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
4742
4809
  if (btcPublicKey) {
4743
4810
  yield getNearAccountByBtcPublicKey(btcPublicKey);
4744
4811
  removeWalletButton();
4745
- setupWalletButton(env, wallet, btcContext, metadata.walletUrl);
4812
+ setupWalletButton({
4813
+ env,
4814
+ nearWallet: wallet,
4815
+ btcWallet: btcContext,
4816
+ walletUrl: metadata.walletUrl
4817
+ });
4746
4818
  }
4747
4819
  } else {
4748
- removeWalletButton();
4749
4820
  connectionUpdateTimeout = setTimeout(() => {
4750
4821
  handleConnectionUpdate();
4751
4822
  }, 5e3);
@@ -4884,7 +4955,8 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
4884
4955
  const { transferGasTransaction, useNearPayGas, gasLimit } = yield calculateGasStrategy({
4885
4956
  csna,
4886
4957
  transactions: trans,
4887
- env
4958
+ env,
4959
+ gasStrategy: metadata.gasStrategy
4888
4960
  });
4889
4961
  console.log("transferGasTransaction:", transferGasTransaction);
4890
4962
  console.log("useNearPayGas:", useNearPayGas);
@@ -4956,9 +5028,10 @@ function setupBTCWallet({
4956
5028
  autoConnect = true,
4957
5029
  syncLogOut = true,
4958
5030
  env = "mainnet",
4959
- walletUrl
5031
+ walletUrl,
5032
+ gasStrategy = "auto"
4960
5033
  } = {}) {
4961
- console.log("\u26A1\uFE0F BTC Wallet Version:", getVersion(), "env:", env);
5034
+ console.log("\u26A1\uFE0F BTC Wallet Version:", getVersion(), "env:", env, "gasStrategy:", gasStrategy);
4962
5035
  const btcWallet = () => __async(this, null, function* () {
4963
5036
  return {
4964
5037
  id: "btc-wallet",
@@ -4973,7 +5046,8 @@ function setupBTCWallet({
4973
5046
  autoConnect,
4974
5047
  syncLogOut,
4975
5048
  env,
4976
- walletUrl
5049
+ walletUrl,
5050
+ gasStrategy
4977
5051
  },
4978
5052
  init: BTCWallet
4979
5053
  };
@@ -4983,11 +5057,30 @@ function setupBTCWallet({
4983
5057
 
4984
5058
  // src/core/setupModal.ts
4985
5059
  var import_ref_modal_ui = require("ref-modal-ui");
5060
+ var subscription;
4986
5061
  function setupWalletSelectorModal(selector, options) {
4987
5062
  if (!selector)
4988
5063
  throw new Error("selector is required");
5064
+ const {
5065
+ showChainGroups = true,
5066
+ showWalletUIForNearAccount = true,
5067
+ env = "mainnet",
5068
+ walletUrl
5069
+ } = options;
5070
+ subscription == null ? void 0 : subscription.unsubscribe();
4989
5071
  const state = selector.store.getState();
4990
5072
  const group = getGroup(state);
5073
+ subscription = selector.store.observable.subscribe((state2) => {
5074
+ const walletId = state2.selectedWalletId;
5075
+ console.log("setupWalletSelectorModal walletId", walletId);
5076
+ if (!walletId)
5077
+ removeWalletButton();
5078
+ if (showWalletUIForNearAccount && walletId !== "btc-wallet") {
5079
+ selector.wallet().then((wallet) => {
5080
+ setupWalletButton({ env, nearWallet: wallet, walletUrl });
5081
+ });
5082
+ }
5083
+ });
4991
5084
  if (group.includes("btc")) {
4992
5085
  document.head.appendChild(document.createElement("style")).textContent = `
4993
5086
  #near-wallet-selector-modal .options-list .btc-wallet {
@@ -4998,7 +5091,7 @@ function setupWalletSelectorModal(selector, options) {
4998
5091
  const modal = (0, import_ref_modal_ui.setupModal)(selector, options);
4999
5092
  const originalShow = modal.show.bind(modal);
5000
5093
  modal.show = () => __async(this, null, function* () {
5001
- const chain = group.length > 1 ? yield openChainModal() : group[0];
5094
+ const chain = group.length > 1 && showChainGroups ? yield openChainModal() : group[0];
5002
5095
  if (chain === "btc") {
5003
5096
  const module2 = state.modules.find((module3) => module3.id === "btc-wallet");
5004
5097
  if (module2) {
@@ -5036,7 +5129,7 @@ function openChainModal() {
5036
5129
  return div;
5037
5130
  };
5038
5131
  return yield Dialog.openModal({
5039
- title: "Choose Chain",
5132
+ title: "Choose Wallet",
5040
5133
  titleStyle: "font-size: 18px; font-weight: 600; color: #fff; text-align: center;padding-bottom: 10px;",
5041
5134
  content
5042
5135
  });
@@ -5055,7 +5148,7 @@ function getGroup(state) {
5055
5148
 
5056
5149
  // src/index.ts
5057
5150
  var getVersion = () => {
5058
- return "0.5.53-beta";
5151
+ return "0.5.56-beta";
5059
5152
  };
5060
5153
  if (typeof window !== "undefined") {
5061
5154
  window.__BTC_WALLET_VERSION = getVersion();