@dynamic-labs/bitcoin 2.1.0-alpha.24 → 2.1.0-alpha.26

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,24 @@
1
1
 
2
+ ## [2.1.0-alpha.26](https://github.com/dynamic-labs/DynamicAuth/compare/v2.1.0-alpha.25...v2.1.0-alpha.26) (2024-05-29)
3
+
4
+
5
+ ### Features
6
+
7
+ * add farcaster login to react native ([#5713](https://github.com/dynamic-labs/DynamicAuth/issues/5713)) ([08f4473](https://github.com/dynamic-labs/DynamicAuth/commit/08f4473eec9b32b82b6f703fa4d5136514a61b25))
8
+
9
+
10
+ ### Bug Fixes
11
+
12
+ * better error handling of invalid mfa otp ([#5759](https://github.com/dynamic-labs/DynamicAuth/issues/5759)) ([72ab01f](https://github.com/dynamic-labs/DynamicAuth/commit/72ab01f8f919f147eeedfabf8b4838802abf308a))
13
+ * show correct status for magic eden btc wallets after ([#5748](https://github.com/dynamic-labs/DynamicAuth/issues/5748)) ([b8f20bb](https://github.com/dynamic-labs/DynamicAuth/commit/b8f20bb796b9a2e88817ef3b0da6ac32e9012b18))
14
+
15
+ ## [2.1.0-alpha.25](https://github.com/dynamic-labs/DynamicAuth/compare/v2.1.0-alpha.24...v2.1.0-alpha.25) (2024-05-27)
16
+
17
+
18
+ ### Bug Fixes
19
+
20
+ * btc balance calculation ([#5737](https://github.com/dynamic-labs/DynamicAuth/issues/5737)) ([9b5ceb3](https://github.com/dynamic-labs/DynamicAuth/commit/9b5ceb32d543037f60d7104f0b81b3abc86ebd10))
21
+
2
22
  ## [2.1.0-alpha.24](https://github.com/dynamic-labs/DynamicAuth/compare/v2.1.0-alpha.23...v2.1.0-alpha.24) (2024-05-26)
3
23
 
4
24
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dynamic-labs/bitcoin",
3
- "version": "2.1.0-alpha.24",
3
+ "version": "2.1.0-alpha.26",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/dynamic-labs/dynamic-auth.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": "2.1.0-alpha.24",
36
- "@dynamic-labs/wallet-book": "2.1.0-alpha.24",
37
- "@dynamic-labs/wallet-connector-core": "2.1.0-alpha.24",
35
+ "@dynamic-labs/utils": "2.1.0-alpha.26",
36
+ "@dynamic-labs/wallet-book": "2.1.0-alpha.26",
37
+ "@dynamic-labs/wallet-connector-core": "2.1.0-alpha.26",
38
38
  "stream": "0.0.2"
39
39
  },
40
40
  "peerDependencies": {}
@@ -19,6 +19,10 @@ class BitcoinSatsConnectConnector extends BitcoinWalletConnector.BitcoinWalletCo
19
19
  constructor(opts) {
20
20
  super(opts);
21
21
  this.currentNetwork = satsConnect.BitcoinNetworkType.Mainnet;
22
+ this.canFetchConnectedAccounts = true;
23
+ // xverse does't support fetching connected accounts without prompting
24
+ // for a connection, so we handle getConnectedAccounts differently
25
+ this.canFetchConnectedAccounts = this.key !== 'xverse';
22
26
  }
23
27
  getAddress() {
24
28
  return _tslib.__awaiter(this, void 0, void 0, function* () {
@@ -30,10 +34,6 @@ class BitcoinSatsConnectConnector extends BitcoinWalletConnector.BitcoinWalletCo
30
34
  if (!supportsSatsConnect.supportsSatsConnect(this)) {
31
35
  return;
32
36
  }
33
- const [connectedAccount] = yield this.getConnectedAccounts();
34
- if (connectedAccount) {
35
- return connectedAccount;
36
- }
37
37
  return new Promise((resolve, reject) => {
38
38
  satsConnect.getAddress({
39
39
  getProvider: () => _tslib.__awaiter(this, void 0, void 0, function* () {
@@ -3,6 +3,7 @@ import { BitcoinWalletConnector, BitcoinWalletConnectorOpts } from './BitcoinWal
3
3
  import { BitcoinTransaction, SatsConnectSignTransactionInput, BitcoinSignPsbtRequest, BitcoinSignPsbtResponse } from './types';
4
4
  export declare abstract class BitcoinSatsConnectConnector extends BitcoinWalletConnector {
5
5
  currentNetwork: BitcoinNetworkType;
6
+ canFetchConnectedAccounts: boolean;
6
7
  constructor(opts: BitcoinWalletConnectorOpts);
7
8
  getAddress(): Promise<string | undefined>;
8
9
  signMessage(messageToSign: string): Promise<string | undefined>;
@@ -15,6 +15,10 @@ class BitcoinSatsConnectConnector extends BitcoinWalletConnector {
15
15
  constructor(opts) {
16
16
  super(opts);
17
17
  this.currentNetwork = BitcoinNetworkType.Mainnet;
18
+ this.canFetchConnectedAccounts = true;
19
+ // xverse does't support fetching connected accounts without prompting
20
+ // for a connection, so we handle getConnectedAccounts differently
21
+ this.canFetchConnectedAccounts = this.key !== 'xverse';
18
22
  }
19
23
  getAddress() {
20
24
  return __awaiter(this, void 0, void 0, function* () {
@@ -26,10 +30,6 @@ class BitcoinSatsConnectConnector extends BitcoinWalletConnector {
26
30
  if (!supportsSatsConnect(this)) {
27
31
  return;
28
32
  }
29
- const [connectedAccount] = yield this.getConnectedAccounts();
30
- if (connectedAccount) {
31
- return connectedAccount;
32
- }
33
33
  return new Promise((resolve, reject) => {
34
34
  getAddress({
35
35
  getProvider: () => __awaiter(this, void 0, void 0, function* () {
@@ -12,6 +12,7 @@ var bitcoinProviderHelper = require('./bitcoinProviderHelper.cjs');
12
12
  var BitcoinLocalStorageCache = require('./BitcoinLocalStorageCache.cjs');
13
13
  var getMempoolApiUrl = require('./utils/getMempoolApiUrl.cjs');
14
14
  var _const = require('./const.cjs');
15
+ var satoshisToBtc = require('./utils/satoshisToBtc/satoshisToBtc.cjs');
15
16
 
16
17
  class BitcoinWalletConnector extends walletConnectorCore.WalletConnectorBase {
17
18
  constructor(opts) {
@@ -76,12 +77,14 @@ class BitcoinWalletConnector extends walletConnectorCore.WalletConnectorBase {
76
77
  return undefined;
77
78
  }
78
79
  const addressInfo = yield response.json();
79
- if (!(addressInfo === null || addressInfo === void 0 ? void 0 : addressInfo.chain_stats)) {
80
+ if (!(addressInfo === null || addressInfo === void 0 ? void 0 : addressInfo.chain_stats) || !(addressInfo === null || addressInfo === void 0 ? void 0 : addressInfo.mempool_stats)) {
80
81
  return undefined;
81
82
  }
82
- const balance = (Number(addressInfo.chain_stats.funded_txo_sum) -
83
- Number(addressInfo.chain_stats.spent_txo_sum)) /
84
- 100000000;
83
+ const confirmedBalanceInSats = Number(addressInfo.chain_stats.funded_txo_sum) -
84
+ Number(addressInfo.chain_stats.spent_txo_sum);
85
+ const unconfirmedBalanceInSats = Number(addressInfo.mempool_stats.funded_txo_sum) -
86
+ Number(addressInfo.mempool_stats.spent_txo_sum);
87
+ const balance = satoshisToBtc.satoshisToBtc(confirmedBalanceInSats + unconfirmedBalanceInSats);
85
88
  yield this.cache.setLastBalance(balance.toString());
86
89
  return balance.toString();
87
90
  });
@@ -104,10 +107,19 @@ class BitcoinWalletConnector extends walletConnectorCore.WalletConnectorBase {
104
107
  }
105
108
  getConnectedAccounts() {
106
109
  return _tslib.__awaiter(this, void 0, void 0, function* () {
110
+ // some wallets like xverse don't support fetching connected accounts
111
+ // without prompting for a connection
112
+ // to avoid this behavior, we cache the connected accounts
107
113
  if (!this.canFetchConnectedAccounts) {
108
114
  return this.getConnectedAccountsFromCache();
109
115
  }
110
- const connectedAccounts = yield this.getAddress();
116
+ // if we decide that is ok to prompt for a connection when fetching connected accounts
117
+ // we shouldn't prompt every time we call this method (which is a lot of times)
118
+ // so we just store in a promise and return the same promise every time
119
+ if (!this.getAddressPromise) {
120
+ this.getAddressPromise = this.getAddress();
121
+ }
122
+ const connectedAccounts = yield this.getAddressPromise;
111
123
  if (!connectedAccounts) {
112
124
  return [];
113
125
  }
@@ -16,6 +16,7 @@ export declare abstract class BitcoinWalletConnector extends WalletConnectorBase
16
16
  cache: IBitcoinSessionCache;
17
17
  connectedChain: Chain;
18
18
  supportedChains: Chain[];
19
+ private getAddressPromise;
19
20
  private bitcoinProviderHelper;
20
21
  wallet: Wallet | undefined;
21
22
  canFetchConnectedAccounts: boolean;
@@ -8,6 +8,7 @@ import { BitcoinProviderHelper } from './bitcoinProviderHelper.js';
8
8
  import { BitcoinLocalStorageCache } from './BitcoinLocalStorageCache.js';
9
9
  import { getMempoolApiUrl } from './utils/getMempoolApiUrl.js';
10
10
  import { HTTP_STATUS_TOO_MANY_REQUESTS, HTTP_STATUS_NOT_FOUND } from './const.js';
11
+ import { satoshisToBtc } from './utils/satoshisToBtc/satoshisToBtc.js';
11
12
 
12
13
  class BitcoinWalletConnector extends WalletConnectorBase {
13
14
  constructor(opts) {
@@ -72,12 +73,14 @@ class BitcoinWalletConnector extends WalletConnectorBase {
72
73
  return undefined;
73
74
  }
74
75
  const addressInfo = yield response.json();
75
- if (!(addressInfo === null || addressInfo === void 0 ? void 0 : addressInfo.chain_stats)) {
76
+ if (!(addressInfo === null || addressInfo === void 0 ? void 0 : addressInfo.chain_stats) || !(addressInfo === null || addressInfo === void 0 ? void 0 : addressInfo.mempool_stats)) {
76
77
  return undefined;
77
78
  }
78
- const balance = (Number(addressInfo.chain_stats.funded_txo_sum) -
79
- Number(addressInfo.chain_stats.spent_txo_sum)) /
80
- 100000000;
79
+ const confirmedBalanceInSats = Number(addressInfo.chain_stats.funded_txo_sum) -
80
+ Number(addressInfo.chain_stats.spent_txo_sum);
81
+ const unconfirmedBalanceInSats = Number(addressInfo.mempool_stats.funded_txo_sum) -
82
+ Number(addressInfo.mempool_stats.spent_txo_sum);
83
+ const balance = satoshisToBtc(confirmedBalanceInSats + unconfirmedBalanceInSats);
81
84
  yield this.cache.setLastBalance(balance.toString());
82
85
  return balance.toString();
83
86
  });
@@ -100,10 +103,19 @@ class BitcoinWalletConnector extends WalletConnectorBase {
100
103
  }
101
104
  getConnectedAccounts() {
102
105
  return __awaiter(this, void 0, void 0, function* () {
106
+ // some wallets like xverse don't support fetching connected accounts
107
+ // without prompting for a connection
108
+ // to avoid this behavior, we cache the connected accounts
103
109
  if (!this.canFetchConnectedAccounts) {
104
110
  return this.getConnectedAccountsFromCache();
105
111
  }
106
- const connectedAccounts = yield this.getAddress();
112
+ // if we decide that is ok to prompt for a connection when fetching connected accounts
113
+ // we shouldn't prompt every time we call this method (which is a lot of times)
114
+ // so we just store in a promise and return the same promise every time
115
+ if (!this.getAddressPromise) {
116
+ this.getAddressPromise = this.getAddress();
117
+ }
118
+ const connectedAccounts = yield this.getAddressPromise;
107
119
  if (!connectedAccounts) {
108
120
  return [];
109
121
  }
@@ -0,0 +1 @@
1
+ export * from './satoshisToBtc';
@@ -0,0 +1,8 @@
1
+ 'use client'
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ const satoshisToBtc = (satoshis) => satoshis / 100000000;
7
+
8
+ exports.satoshisToBtc = satoshisToBtc;
@@ -0,0 +1 @@
1
+ export declare const satoshisToBtc: (satoshis: number) => number;
@@ -0,0 +1,4 @@
1
+ 'use client'
2
+ const satoshisToBtc = (satoshis) => satoshis / 100000000;
3
+
4
+ export { satoshisToBtc };