@dynamic-labs/bitcoin 1.4.12 → 1.4.13

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/CHANGELOG.md CHANGED
@@ -1,4 +1,12 @@
1
1
 
2
+ ### [1.4.13](https://github.com/dynamic-labs/DynamicAuth/compare/v1.4.12...v1.4.13) (2024-06-05)
3
+
4
+
5
+ ### Bug Fixes
6
+
7
+ * bump @solana/web3.js containing new version of rpc-websockets ([#5864](https://github.com/dynamic-labs/DynamicAuth/issues/5864)) ([562ff9b](https://github.com/dynamic-labs/DynamicAuth/commit/562ff9b706c8be62812ace08bcaef96e26dcd841))
8
+ * wallet improvements
9
+
2
10
  ### [1.4.12](https://github.com/dynamic-labs/DynamicAuth/compare/v1.4.11...v1.4.12) (2024-05-22)
3
11
 
4
12
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dynamic-labs/bitcoin",
3
- "version": "1.4.12",
3
+ "version": "1.4.13",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/dynamic-labs/DynamicAuth.git",
@@ -32,9 +32,9 @@
32
32
  "@wallet-standard/base": "1.0.1",
33
33
  "bitcoinjs-lib": "6.1.5",
34
34
  "sats-connect": "2.0.0",
35
- "@dynamic-labs/utils": "1.4.12",
36
- "@dynamic-labs/wallet-book": "1.4.12",
37
- "@dynamic-labs/wallet-connector-core": "1.4.12",
35
+ "@dynamic-labs/utils": "1.4.13",
36
+ "@dynamic-labs/wallet-book": "1.4.13",
37
+ "@dynamic-labs/wallet-connector-core": "1.4.13",
38
38
  "stream": "0.0.2"
39
39
  },
40
40
  "peerDependencies": {}
@@ -11,6 +11,7 @@ var bitcoinProviderHelper = require('./bitcoinProviderHelper.cjs');
11
11
  var BitcoinLocalStorageCache = require('./BitcoinLocalStorageCache.cjs');
12
12
  var getMempoolApiUrl = require('./utils/getMempoolApiUrl.cjs');
13
13
  var _const = require('./const.cjs');
14
+ var satoshisToBtc = require('./utils/satoshisToBtc/satoshisToBtc.cjs');
14
15
 
15
16
  class BitcoinWalletConnector extends walletConnectorCore.WalletConnectorBase {
16
17
  constructor(opts) {
@@ -67,12 +68,14 @@ class BitcoinWalletConnector extends walletConnectorCore.WalletConnectorBase {
67
68
  return undefined;
68
69
  }
69
70
  const addressInfo = yield response.json();
70
- if (!(addressInfo === null || addressInfo === void 0 ? void 0 : addressInfo.chain_stats)) {
71
+ if (!(addressInfo === null || addressInfo === void 0 ? void 0 : addressInfo.chain_stats) || !(addressInfo === null || addressInfo === void 0 ? void 0 : addressInfo.mempool_stats)) {
71
72
  return undefined;
72
73
  }
73
- const balance = (Number(addressInfo.chain_stats.funded_txo_sum) -
74
- Number(addressInfo.chain_stats.spent_txo_sum)) /
75
- 100000000;
74
+ const confirmedBalanceInSats = Number(addressInfo.chain_stats.funded_txo_sum) -
75
+ Number(addressInfo.chain_stats.spent_txo_sum);
76
+ const unconfirmedBalanceInSats = Number(addressInfo.mempool_stats.funded_txo_sum) -
77
+ Number(addressInfo.mempool_stats.spent_txo_sum);
78
+ const balance = satoshisToBtc.satoshisToBtc(confirmedBalanceInSats + unconfirmedBalanceInSats);
76
79
  yield this.cache.setLastBalance(balance.toString());
77
80
  return balance.toString();
78
81
  });
@@ -7,6 +7,7 @@ import { BitcoinProviderHelper } from './bitcoinProviderHelper.js';
7
7
  import { BitcoinLocalStorageCache } from './BitcoinLocalStorageCache.js';
8
8
  import { getMempoolApiUrl } from './utils/getMempoolApiUrl.js';
9
9
  import { HTTP_STATUS_TOO_MANY_REQUESTS, HTTP_STATUS_NOT_FOUND } from './const.js';
10
+ import { satoshisToBtc } from './utils/satoshisToBtc/satoshisToBtc.js';
10
11
 
11
12
  class BitcoinWalletConnector extends WalletConnectorBase {
12
13
  constructor(opts) {
@@ -63,12 +64,14 @@ class BitcoinWalletConnector extends WalletConnectorBase {
63
64
  return undefined;
64
65
  }
65
66
  const addressInfo = yield response.json();
66
- if (!(addressInfo === null || addressInfo === void 0 ? void 0 : addressInfo.chain_stats)) {
67
+ if (!(addressInfo === null || addressInfo === void 0 ? void 0 : addressInfo.chain_stats) || !(addressInfo === null || addressInfo === void 0 ? void 0 : addressInfo.mempool_stats)) {
67
68
  return undefined;
68
69
  }
69
- const balance = (Number(addressInfo.chain_stats.funded_txo_sum) -
70
- Number(addressInfo.chain_stats.spent_txo_sum)) /
71
- 100000000;
70
+ const confirmedBalanceInSats = Number(addressInfo.chain_stats.funded_txo_sum) -
71
+ Number(addressInfo.chain_stats.spent_txo_sum);
72
+ const unconfirmedBalanceInSats = Number(addressInfo.mempool_stats.funded_txo_sum) -
73
+ Number(addressInfo.mempool_stats.spent_txo_sum);
74
+ const balance = satoshisToBtc(confirmedBalanceInSats + unconfirmedBalanceInSats);
72
75
  yield this.cache.setLastBalance(balance.toString());
73
76
  return balance.toString();
74
77
  });
@@ -4,6 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var _tslib = require('../_virtual/_tslib.cjs');
6
6
  var bitcoinjsLib = require('bitcoinjs-lib');
7
+ var utils = require('@dynamic-labs/utils');
7
8
  var BitcoinWalletConnector = require('./BitcoinWalletConnector.cjs');
8
9
  var createSignPsbtOptions = require('./utils/psbt/createSignPsbtOptions.cjs');
9
10
 
@@ -13,8 +14,22 @@ class OkxConnector extends BitcoinWalletConnector.BitcoinWalletConnector {
13
14
  this.name = 'OKX Wallet (Bitcoin)';
14
15
  this.canFetchConnectedAccounts = true;
15
16
  }
17
+ get walletBookWallet() {
18
+ return this.walletBook.wallets[this.key];
19
+ }
16
20
  fetchPublicAddress() {
17
21
  return _tslib.__awaiter(this, void 0, void 0, function* () {
22
+ if (!this.isInstalledOnBrowser() &&
23
+ utils.isMobile() &&
24
+ this.walletBookWallet.mobile &&
25
+ this.walletBookWallet.mobile.inAppBrowser) {
26
+ const inAppBrowserCompiledTemplate = utils.template(this.walletBookWallet.mobile.inAppBrowser);
27
+ const deepLink = inAppBrowserCompiledTemplate({
28
+ encodedDappURI: encodeURIComponent(window.location.toString()),
29
+ });
30
+ window.location.assign(deepLink);
31
+ return;
32
+ }
18
33
  const provider = this.getProvider();
19
34
  if (!provider) {
20
35
  return;
@@ -4,6 +4,7 @@ export declare class OkxConnector extends BitcoinWalletConnector {
4
4
  name: string;
5
5
  canFetchConnectedAccounts: boolean;
6
6
  constructor(opts: BitcoinWalletConnectorOpts);
7
+ private get walletBookWallet();
7
8
  fetchPublicAddress(): Promise<string | undefined>;
8
9
  signMessage(messageToSign: string): Promise<string | undefined>;
9
10
  sendBitcoin(transaction: BitcoinTransaction): Promise<string | undefined>;
@@ -1,5 +1,6 @@
1
1
  import { __awaiter } from '../_virtual/_tslib.js';
2
2
  import { Psbt } from 'bitcoinjs-lib';
3
+ import { isMobile, template } from '@dynamic-labs/utils';
3
4
  import { BitcoinWalletConnector } from './BitcoinWalletConnector.js';
4
5
  import { createPsbtOptions } from './utils/psbt/createSignPsbtOptions.js';
5
6
 
@@ -9,8 +10,22 @@ class OkxConnector extends BitcoinWalletConnector {
9
10
  this.name = 'OKX Wallet (Bitcoin)';
10
11
  this.canFetchConnectedAccounts = true;
11
12
  }
13
+ get walletBookWallet() {
14
+ return this.walletBook.wallets[this.key];
15
+ }
12
16
  fetchPublicAddress() {
13
17
  return __awaiter(this, void 0, void 0, function* () {
18
+ if (!this.isInstalledOnBrowser() &&
19
+ isMobile() &&
20
+ this.walletBookWallet.mobile &&
21
+ this.walletBookWallet.mobile.inAppBrowser) {
22
+ const inAppBrowserCompiledTemplate = template(this.walletBookWallet.mobile.inAppBrowser);
23
+ const deepLink = inAppBrowserCompiledTemplate({
24
+ encodedDappURI: encodeURIComponent(window.location.toString()),
25
+ });
26
+ window.location.assign(deepLink);
27
+ return;
28
+ }
14
29
  const provider = this.getProvider();
15
30
  if (!provider) {
16
31
  return;
package/src/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { OkxConnector } from './OkxConnector';
1
+ import { UnisatConnector } from './UnisatConnector';
2
2
  export { BitcoinWalletConnector } from './BitcoinWalletConnector';
3
3
  export type { BitcoinTransaction } from './types';
4
4
  export * from './utils';
5
- export declare const BitcoinWalletConnectors: (props: any) => (import("dist/packages/wallet-connector-core/src").WalletConnectorConstructor | typeof OkxConnector)[];
5
+ export declare const BitcoinWalletConnectors: (props: any) => (import("dist/packages/wallet-connector-core/src").WalletConnectorConstructor | typeof UnisatConnector)[];
@@ -0,0 +1 @@
1
+ export * from './satoshisToBtc';
@@ -0,0 +1,7 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ const satoshisToBtc = (satoshis) => satoshis / 100000000;
6
+
7
+ exports.satoshisToBtc = satoshisToBtc;
@@ -0,0 +1 @@
1
+ export declare const satoshisToBtc: (satoshis: number) => number;
@@ -0,0 +1,3 @@
1
+ const satoshisToBtc = (satoshis) => satoshis / 100000000;
2
+
3
+ export { satoshisToBtc };