@dynamic-labs/bitcoin 3.0.0-alpha.13 → 3.0.0-alpha.15
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 +46 -0
- package/package.json +4 -4
- package/src/BitcoinLocalStorageCache.cjs +0 -16
- package/src/BitcoinLocalStorageCache.d.ts +0 -7
- package/src/BitcoinLocalStorageCache.js +0 -16
- package/src/connectors/BitcoinWalletConnector.cjs +17 -24
- package/src/connectors/BitcoinWalletConnector.d.ts +1 -1
- package/src/connectors/BitcoinWalletConnector.js +17 -24
- package/src/connectors/PhantomConnector/PhantomConnector.cjs +1 -1
- package/src/connectors/PhantomConnector/PhantomConnector.js +1 -1
- package/src/utils/fetchSatsConnectConnectors/fetchSatsConnectConnectors.cjs +1 -1
- package/src/utils/fetchSatsConnectConnectors/fetchSatsConnectConnectors.js +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,50 @@
|
|
|
1
1
|
|
|
2
|
+
## [3.0.0-alpha.15](https://github.com/dynamic-labs/DynamicAuth/compare/v3.0.0-alpha.14...v3.0.0-alpha.15) (2024-07-11)
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
### Bug Fixes
|
|
6
|
+
|
|
7
|
+
* catch third party wallet construction errors ([#6268](https://github.com/dynamic-labs/DynamicAuth/issues/6268)) ([badef39](https://github.com/dynamic-labs/DynamicAuth/commit/badef39d753c7d29925c6c8680053027bd99b69b))
|
|
8
|
+
* decode all solana transactions ([#6294](https://github.com/dynamic-labs/DynamicAuth/issues/6294)) ([5220ab2](https://github.com/dynamic-labs/DynamicAuth/commit/5220ab29381f3a7f1afc7043332b5a018b47eb0a))
|
|
9
|
+
* passkey cta ([#6255](https://github.com/dynamic-labs/DynamicAuth/issues/6255)) ([1b1b152](https://github.com/dynamic-labs/DynamicAuth/commit/1b1b152a24b409c5d941a9c92a003daf0bbe48a1))
|
|
10
|
+
|
|
11
|
+
## [3.0.0-alpha.14](https://github.com/dynamic-labs/DynamicAuth/compare/v3.0.0-alpha.13...v3.0.0-alpha.14) (2024-07-09)
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
### ⚠ BREAKING CHANGES
|
|
15
|
+
|
|
16
|
+
* remove setPrimaryWallet in favor of useSwitchWallet (#6212)
|
|
17
|
+
* move getBalance method to wallet so it can be fetched for any wallet not just the active one (#6200)
|
|
18
|
+
* make Wallet a class instead of just a type (#6094)
|
|
19
|
+
|
|
20
|
+
### Features
|
|
21
|
+
|
|
22
|
+
* add @dynamic-labs/solana-extension ([#6140](https://github.com/dynamic-labs/DynamicAuth/issues/6140)) ([c0e2a06](https://github.com/dynamic-labs/DynamicAuth/commit/c0e2a067dd83163094b58a15696df8654da47c65))
|
|
23
|
+
* add solana support for multi-asset ([#6222](https://github.com/dynamic-labs/DynamicAuth/issues/6222)) ([9660d79](https://github.com/dynamic-labs/DynamicAuth/commit/9660d7962f1fb01011d68397bb367fdfc5335ca9))
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
### Bug Fixes
|
|
27
|
+
|
|
28
|
+
* allow closing re-connect wallet modal ([#6250](https://github.com/dynamic-labs/DynamicAuth/issues/6250)) ([55ba25b](https://github.com/dynamic-labs/DynamicAuth/commit/55ba25bd3e907629aaa26e788885bfa38f8fe350))
|
|
29
|
+
* move getBalance method to wallet so it can be fetched for any wallet not just the active one ([#6200](https://github.com/dynamic-labs/DynamicAuth/issues/6200)) ([ee94773](https://github.com/dynamic-labs/DynamicAuth/commit/ee94773df9b31462a325666760fcf1fc70dec68a))
|
|
30
|
+
* move getNameService method to wallet so name service data can be fetched for any wallet ([#6205](https://github.com/dynamic-labs/DynamicAuth/issues/6205)) ([6671ae9](https://github.com/dynamic-labs/DynamicAuth/commit/6671ae92532ffc1889e24519e75f47d336ac0da6))
|
|
31
|
+
* relax phone number length validation ([#6226](https://github.com/dynamic-labs/DynamicAuth/issues/6226)) ([f0969b4](https://github.com/dynamic-labs/DynamicAuth/commit/f0969b4fbdafde07125cddecb16b4bfd011ea65e))
|
|
32
|
+
* sdkHasLoaded flipping back to false with otp ([#6242](https://github.com/dynamic-labs/DynamicAuth/issues/6242)) ([32ad9dd](https://github.com/dynamic-labs/DynamicAuth/commit/32ad9dd2dae7775f494506773fb343fe1a249c65))
|
|
33
|
+
* send transaction demo undefined address/value ([#6248](https://github.com/dynamic-labs/DynamicAuth/issues/6248)) ([036a511](https://github.com/dynamic-labs/DynamicAuth/commit/036a511fb848ef461edd9b7a5d79d478b0f1cf23))
|
|
34
|
+
* set last active account on accountChange request ([#6218](https://github.com/dynamic-labs/DynamicAuth/issues/6218)) ([05797d2](https://github.com/dynamic-labs/DynamicAuth/commit/05797d292aab8b4de02555594d4d1bbd4c9543eb))
|
|
35
|
+
* show ledger toggle when linking wallet ([#6202](https://github.com/dynamic-labs/DynamicAuth/issues/6202)) ([a449c0b](https://github.com/dynamic-labs/DynamicAuth/commit/a449c0bfc4e3a75ccd7084b930c48fbd6c14f691))
|
|
36
|
+
* show user wallet in profile view on single wallet mode even if it's not primary ([#6187](https://github.com/dynamic-labs/DynamicAuth/issues/6187)) ([ffaaeb2](https://github.com/dynamic-labs/DynamicAuth/commit/ffaaeb2c6cbb2868a381d85451ae5574024156bb))
|
|
37
|
+
* stop auto-switching to connected secondary wallet if primary wallet is not connected ([#6196](https://github.com/dynamic-labs/DynamicAuth/issues/6196)) ([4e8bcd2](https://github.com/dynamic-labs/DynamicAuth/commit/4e8bcd2d02d3fca54a0ed29c45b386ae99266b84))
|
|
38
|
+
* stop coinbase and solflare popups when secondary ([#6225](https://github.com/dynamic-labs/DynamicAuth/issues/6225)) ([7e9c104](https://github.com/dynamic-labs/DynamicAuth/commit/7e9c1049a09c9fd513c9a2a746d6baac916f1bf4))
|
|
39
|
+
* stop sending double sign request on network switch ([e325709](https://github.com/dynamic-labs/DynamicAuth/commit/e325709bb5d2d1331fe16cc705398fc7b1cc292a))
|
|
40
|
+
* tunrkey solana signer accept uint8array message ([#6137](https://github.com/dynamic-labs/DynamicAuth/issues/6137)) ([70f89ce](https://github.com/dynamic-labs/DynamicAuth/commit/70f89ce0dafa4c99b318c9c5adce59083cd6d284))
|
|
41
|
+
* update formatting of phantom bitcoin publickey ([#6210](https://github.com/dynamic-labs/DynamicAuth/issues/6210)) ([f58cea9](https://github.com/dynamic-labs/DynamicAuth/commit/f58cea99333fd7c6af8f56f637ee32f1f7ce8d76))
|
|
42
|
+
* use white color in farcaster qr code when in dark mode ([#6245](https://github.com/dynamic-labs/DynamicAuth/issues/6245)) ([a91958d](https://github.com/dynamic-labs/DynamicAuth/commit/a91958d8773be138da8f54791c4c67866257bbad))
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
* make Wallet a class instead of just a type ([#6094](https://github.com/dynamic-labs/DynamicAuth/issues/6094)) ([6dc4672](https://github.com/dynamic-labs/DynamicAuth/commit/6dc4672951cfadc22a6c569e74eae3485bd472f3))
|
|
46
|
+
* remove setPrimaryWallet in favor of useSwitchWallet ([#6212](https://github.com/dynamic-labs/DynamicAuth/issues/6212)) ([de125e1](https://github.com/dynamic-labs/DynamicAuth/commit/de125e1ebbc20507e4ec07f337f5f5fd13aabcbe))
|
|
47
|
+
|
|
2
48
|
## [3.0.0-alpha.13](https://github.com/dynamic-labs/DynamicAuth/compare/v3.0.0-alpha.12...v3.0.0-alpha.13) (2024-06-27)
|
|
3
49
|
|
|
4
50
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dynamic-labs/bitcoin",
|
|
3
|
-
"version": "3.0.0-alpha.
|
|
3
|
+
"version": "3.0.0-alpha.15",
|
|
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": "3.0.0-alpha.
|
|
36
|
-
"@dynamic-labs/wallet-book": "3.0.0-alpha.
|
|
37
|
-
"@dynamic-labs/wallet-connector-core": "3.0.0-alpha.
|
|
35
|
+
"@dynamic-labs/utils": "3.0.0-alpha.15",
|
|
36
|
+
"@dynamic-labs/wallet-book": "3.0.0-alpha.15",
|
|
37
|
+
"@dynamic-labs/wallet-connector-core": "3.0.0-alpha.15",
|
|
38
38
|
"stream": "0.0.2"
|
|
39
39
|
},
|
|
40
40
|
"peerDependencies": {}
|
|
@@ -9,7 +9,6 @@ var utils = require('@dynamic-labs/utils');
|
|
|
9
9
|
class BitcoinLocalStorageCache {
|
|
10
10
|
constructor(key) {
|
|
11
11
|
this.CONNECTED_ACCOUNTS_KEY = `bitcoin_${key}_connectedAccounts`;
|
|
12
|
-
this.LAST_BALANCE_KEY = `bitcoin_${key}_lastBalance`;
|
|
13
12
|
}
|
|
14
13
|
getActiveAccount() {
|
|
15
14
|
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
@@ -63,21 +62,6 @@ class BitcoinLocalStorageCache {
|
|
|
63
62
|
return utils.removeItemAsync(this.CONNECTED_ACCOUNTS_KEY);
|
|
64
63
|
});
|
|
65
64
|
}
|
|
66
|
-
getLastBalance() {
|
|
67
|
-
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
68
|
-
return utils.getItemAsync(this.LAST_BALANCE_KEY);
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
setLastBalance(balance) {
|
|
72
|
-
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
73
|
-
return utils.setItemAsync(this.LAST_BALANCE_KEY, balance);
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
clearLastBalance() {
|
|
77
|
-
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
78
|
-
return utils.removeItemAsync(this.LAST_BALANCE_KEY);
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
65
|
}
|
|
82
66
|
|
|
83
67
|
exports.BitcoinLocalStorageCache = BitcoinLocalStorageCache;
|
|
@@ -9,16 +9,12 @@ type BitcoinActiveAccount = {
|
|
|
9
9
|
};
|
|
10
10
|
export declare class BitcoinLocalStorageCache implements IBitcoinSessionCache {
|
|
11
11
|
private readonly CONNECTED_ACCOUNTS_KEY;
|
|
12
|
-
private readonly LAST_BALANCE_KEY;
|
|
13
12
|
constructor(key: string);
|
|
14
13
|
getActiveAccount(): Promise<BitcoinActiveAccount | undefined>;
|
|
15
14
|
getConnectedAccounts(): Promise<BitcoinConnectedAccounts | undefined>;
|
|
16
15
|
getConnectedAccount(address: string): Promise<BitcoinConnectedAccount | undefined>;
|
|
17
16
|
setConnectedAccount(addess: string, account: BitcoinConnectedAccount): Promise<void>;
|
|
18
17
|
clearConnectedAcccounts(): Promise<void>;
|
|
19
|
-
getLastBalance(): Promise<string | undefined>;
|
|
20
|
-
setLastBalance(balance: string): Promise<void>;
|
|
21
|
-
clearLastBalance(): Promise<void>;
|
|
22
18
|
}
|
|
23
19
|
export interface IBitcoinSessionCache {
|
|
24
20
|
clearConnectedAcccounts(): Promise<void>;
|
|
@@ -26,8 +22,5 @@ export interface IBitcoinSessionCache {
|
|
|
26
22
|
getConnectedAccount(address: string): Promise<BitcoinConnectedAccount | undefined>;
|
|
27
23
|
getConnectedAccounts(): Promise<BitcoinConnectedAccounts | undefined>;
|
|
28
24
|
setConnectedAccount(addess: string, account: BitcoinConnectedAccount): Promise<void>;
|
|
29
|
-
clearLastBalance(): Promise<void>;
|
|
30
|
-
getLastBalance(): Promise<string | undefined>;
|
|
31
|
-
setLastBalance(balance: string): Promise<void>;
|
|
32
25
|
}
|
|
33
26
|
export {};
|
|
@@ -5,7 +5,6 @@ import { getItemAsync, setItemAsync, removeItemAsync } from '@dynamic-labs/utils
|
|
|
5
5
|
class BitcoinLocalStorageCache {
|
|
6
6
|
constructor(key) {
|
|
7
7
|
this.CONNECTED_ACCOUNTS_KEY = `bitcoin_${key}_connectedAccounts`;
|
|
8
|
-
this.LAST_BALANCE_KEY = `bitcoin_${key}_lastBalance`;
|
|
9
8
|
}
|
|
10
9
|
getActiveAccount() {
|
|
11
10
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -59,21 +58,6 @@ class BitcoinLocalStorageCache {
|
|
|
59
58
|
return removeItemAsync(this.CONNECTED_ACCOUNTS_KEY);
|
|
60
59
|
});
|
|
61
60
|
}
|
|
62
|
-
getLastBalance() {
|
|
63
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
64
|
-
return getItemAsync(this.LAST_BALANCE_KEY);
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
setLastBalance(balance) {
|
|
68
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
69
|
-
return setItemAsync(this.LAST_BALANCE_KEY, balance);
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
clearLastBalance() {
|
|
73
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
74
|
-
return removeItemAsync(this.LAST_BALANCE_KEY);
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
61
|
}
|
|
78
62
|
|
|
79
63
|
export { BitcoinLocalStorageCache };
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
5
|
|
|
6
6
|
var _tslib = require('../../_virtual/_tslib.cjs');
|
|
7
|
+
var satsConnect = require('sats-connect');
|
|
7
8
|
var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
|
|
8
9
|
var walletBook = require('@dynamic-labs/wallet-book');
|
|
9
10
|
var utils = require('@dynamic-labs/utils');
|
|
@@ -59,34 +60,17 @@ class BitcoinWalletConnector extends walletConnectorCore.WalletConnectorBase {
|
|
|
59
60
|
}
|
|
60
61
|
endSession() {
|
|
61
62
|
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
62
|
-
yield
|
|
63
|
-
this.cache.clearConnectedAcccounts(),
|
|
64
|
-
this.cache.clearLastBalance(),
|
|
65
|
-
]);
|
|
63
|
+
yield this.cache.clearConnectedAcccounts();
|
|
66
64
|
});
|
|
67
65
|
}
|
|
68
|
-
getBalance() {
|
|
66
|
+
getBalance(address) {
|
|
69
67
|
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
70
|
-
|
|
71
|
-
const
|
|
72
|
-
if (!connectedAddress) {
|
|
73
|
-
throw new utils.DynamicError('getBalance - No connected address found!');
|
|
74
|
-
}
|
|
75
|
-
const additionalAddresses = yield this.getAdditionalAddresses(connectedAddress);
|
|
76
|
-
const ordinalsAdditionalAddress = (_a = additionalAddresses.find((address) => address.type === sdkApiCore.WalletAddressType.Ordinals)) === null || _a === void 0 ? void 0 : _a.address;
|
|
77
|
-
const paymentAdditionalAddress = (_b = additionalAddresses.find((address) => address.type === sdkApiCore.WalletAddressType.Payment)) === null || _b === void 0 ? void 0 : _b.address;
|
|
78
|
-
// Some BTC wallet connectors only have 1 address type. when this is the case, it would always be `ordinals`
|
|
79
|
-
// if a BTC walletConnector does NOT have a payment address, just use the ordinal address
|
|
80
|
-
const paymentAddress = paymentAdditionalAddress !== null && paymentAdditionalAddress !== void 0 ? paymentAdditionalAddress : ordinalsAdditionalAddress;
|
|
81
|
-
if (!paymentAddress) {
|
|
82
|
-
throw new utils.DynamicError('getBalance - No payment address found!');
|
|
83
|
-
}
|
|
84
|
-
const API_URL = getMempoolApiUrl.getMempoolApiUrl(paymentAddress);
|
|
85
|
-
const response = yield fetch(`${API_URL}/address/${paymentAddress}`);
|
|
68
|
+
const API_URL = getMempoolApiUrl.getMempoolApiUrl(address);
|
|
69
|
+
const response = yield fetch(`${API_URL}/address/${address}`);
|
|
86
70
|
if (!response.ok) {
|
|
87
71
|
// if the request fails due to rate limits, return cached value
|
|
88
72
|
if (response.status === _const.HTTP_STATUS_TOO_MANY_REQUESTS) {
|
|
89
|
-
return
|
|
73
|
+
return '0';
|
|
90
74
|
}
|
|
91
75
|
// new accounts not yet indexed will return a 404
|
|
92
76
|
if (response.status === _const.HTTP_STATUS_NOT_FOUND) {
|
|
@@ -103,7 +87,6 @@ class BitcoinWalletConnector extends walletConnectorCore.WalletConnectorBase {
|
|
|
103
87
|
const unconfirmedBalanceInSats = Number(addressInfo.mempool_stats.funded_txo_sum) -
|
|
104
88
|
Number(addressInfo.mempool_stats.spent_txo_sum);
|
|
105
89
|
const balance = satoshisToBtc.satoshisToBtc(confirmedBalanceInSats + unconfirmedBalanceInSats);
|
|
106
|
-
yield this.cache.setLastBalance(balance.toString());
|
|
107
90
|
return balance.toString();
|
|
108
91
|
});
|
|
109
92
|
}
|
|
@@ -234,12 +217,14 @@ class BitcoinWalletConnector extends walletConnectorCore.WalletConnectorBase {
|
|
|
234
217
|
const { handleAccountChange, handleChainChange, handleDisconnect } = walletConnectorCore.eventListenerHandlers(this);
|
|
235
218
|
const handleBitcoinAccountChange = (accounts) => _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
236
219
|
let connectedAccounts = accounts;
|
|
220
|
+
let ordinalsAccount, paymentAccount;
|
|
237
221
|
// if accounts is an array of objects, we need to parse them to return only addresses
|
|
238
222
|
// since ordinals is the main address we use, we should return it as the first address
|
|
239
223
|
if (typeof accounts[0] === 'object') {
|
|
240
224
|
connectedAccounts = accounts
|
|
241
|
-
.sort((account) =>
|
|
225
|
+
.sort((account) => account.purpose === satsConnect.AddressPurpose.Ordinals ? -1 : 1)
|
|
242
226
|
.map((account) => account.address);
|
|
227
|
+
[ordinalsAccount, paymentAccount] = connectedAccounts;
|
|
243
228
|
}
|
|
244
229
|
const currentConnectedAccounts = yield this.getConnectedAccountsFromCache();
|
|
245
230
|
// don't do anything if the connected accounts haven't changed
|
|
@@ -251,6 +236,14 @@ class BitcoinWalletConnector extends walletConnectorCore.WalletConnectorBase {
|
|
|
251
236
|
// set the last account change request with the from and to addresses
|
|
252
237
|
// to ensure that the requests are not duplicated
|
|
253
238
|
this.setLastAccountChangeRequest(connectedAccounts[0]);
|
|
239
|
+
if (ordinalsAccount || paymentAccount) {
|
|
240
|
+
this.setConnectedAccountWithAddresses({
|
|
241
|
+
active: true,
|
|
242
|
+
mainAddress: ordinalsAccount !== null && ordinalsAccount !== void 0 ? ordinalsAccount : paymentAccount,
|
|
243
|
+
ordinalsAddress: ordinalsAccount,
|
|
244
|
+
paymentAddress: paymentAccount,
|
|
245
|
+
});
|
|
246
|
+
}
|
|
254
247
|
handleAccountChange(connectedAccounts);
|
|
255
248
|
});
|
|
256
249
|
provider.on('accountsChanged', handleBitcoinAccountChange);
|
|
@@ -32,7 +32,7 @@ export declare abstract class BitcoinWalletConnector extends WalletConnectorBase
|
|
|
32
32
|
isInstalledOnBrowser(): boolean;
|
|
33
33
|
getDeepLink(): string | undefined;
|
|
34
34
|
endSession(): Promise<void>;
|
|
35
|
-
getBalance(): Promise<string | undefined>;
|
|
35
|
+
getBalance(address: string): Promise<string | undefined>;
|
|
36
36
|
getConnectedAccountsFromCache(): Promise<string[]>;
|
|
37
37
|
getConnectedAccounts(): Promise<string[]>;
|
|
38
38
|
getAdditionalAddresses(mainAddress?: string): Promise<WalletAdditionalAddress[]>;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
'use client'
|
|
2
2
|
import { __awaiter } from '../../_virtual/_tslib.js';
|
|
3
|
+
import { AddressPurpose } from 'sats-connect';
|
|
3
4
|
import { WalletConnectorBase, eventListenerHandlers, logger } from '@dynamic-labs/wallet-connector-core';
|
|
4
5
|
import { getWalletBookWallet, findWalletBookWallet } from '@dynamic-labs/wallet-book';
|
|
5
6
|
import { isLedgerAddressViaVerifiedCredentials, DynamicError } from '@dynamic-labs/utils';
|
|
@@ -55,34 +56,17 @@ class BitcoinWalletConnector extends WalletConnectorBase {
|
|
|
55
56
|
}
|
|
56
57
|
endSession() {
|
|
57
58
|
return __awaiter(this, void 0, void 0, function* () {
|
|
58
|
-
yield
|
|
59
|
-
this.cache.clearConnectedAcccounts(),
|
|
60
|
-
this.cache.clearLastBalance(),
|
|
61
|
-
]);
|
|
59
|
+
yield this.cache.clearConnectedAcccounts();
|
|
62
60
|
});
|
|
63
61
|
}
|
|
64
|
-
getBalance() {
|
|
62
|
+
getBalance(address) {
|
|
65
63
|
return __awaiter(this, void 0, void 0, function* () {
|
|
66
|
-
|
|
67
|
-
const
|
|
68
|
-
if (!connectedAddress) {
|
|
69
|
-
throw new DynamicError('getBalance - No connected address found!');
|
|
70
|
-
}
|
|
71
|
-
const additionalAddresses = yield this.getAdditionalAddresses(connectedAddress);
|
|
72
|
-
const ordinalsAdditionalAddress = (_a = additionalAddresses.find((address) => address.type === WalletAddressType.Ordinals)) === null || _a === void 0 ? void 0 : _a.address;
|
|
73
|
-
const paymentAdditionalAddress = (_b = additionalAddresses.find((address) => address.type === WalletAddressType.Payment)) === null || _b === void 0 ? void 0 : _b.address;
|
|
74
|
-
// Some BTC wallet connectors only have 1 address type. when this is the case, it would always be `ordinals`
|
|
75
|
-
// if a BTC walletConnector does NOT have a payment address, just use the ordinal address
|
|
76
|
-
const paymentAddress = paymentAdditionalAddress !== null && paymentAdditionalAddress !== void 0 ? paymentAdditionalAddress : ordinalsAdditionalAddress;
|
|
77
|
-
if (!paymentAddress) {
|
|
78
|
-
throw new DynamicError('getBalance - No payment address found!');
|
|
79
|
-
}
|
|
80
|
-
const API_URL = getMempoolApiUrl(paymentAddress);
|
|
81
|
-
const response = yield fetch(`${API_URL}/address/${paymentAddress}`);
|
|
64
|
+
const API_URL = getMempoolApiUrl(address);
|
|
65
|
+
const response = yield fetch(`${API_URL}/address/${address}`);
|
|
82
66
|
if (!response.ok) {
|
|
83
67
|
// if the request fails due to rate limits, return cached value
|
|
84
68
|
if (response.status === HTTP_STATUS_TOO_MANY_REQUESTS) {
|
|
85
|
-
return
|
|
69
|
+
return '0';
|
|
86
70
|
}
|
|
87
71
|
// new accounts not yet indexed will return a 404
|
|
88
72
|
if (response.status === HTTP_STATUS_NOT_FOUND) {
|
|
@@ -99,7 +83,6 @@ class BitcoinWalletConnector extends WalletConnectorBase {
|
|
|
99
83
|
const unconfirmedBalanceInSats = Number(addressInfo.mempool_stats.funded_txo_sum) -
|
|
100
84
|
Number(addressInfo.mempool_stats.spent_txo_sum);
|
|
101
85
|
const balance = satoshisToBtc(confirmedBalanceInSats + unconfirmedBalanceInSats);
|
|
102
|
-
yield this.cache.setLastBalance(balance.toString());
|
|
103
86
|
return balance.toString();
|
|
104
87
|
});
|
|
105
88
|
}
|
|
@@ -230,12 +213,14 @@ class BitcoinWalletConnector extends WalletConnectorBase {
|
|
|
230
213
|
const { handleAccountChange, handleChainChange, handleDisconnect } = eventListenerHandlers(this);
|
|
231
214
|
const handleBitcoinAccountChange = (accounts) => __awaiter(this, void 0, void 0, function* () {
|
|
232
215
|
let connectedAccounts = accounts;
|
|
216
|
+
let ordinalsAccount, paymentAccount;
|
|
233
217
|
// if accounts is an array of objects, we need to parse them to return only addresses
|
|
234
218
|
// since ordinals is the main address we use, we should return it as the first address
|
|
235
219
|
if (typeof accounts[0] === 'object') {
|
|
236
220
|
connectedAccounts = accounts
|
|
237
|
-
.sort((account) =>
|
|
221
|
+
.sort((account) => account.purpose === AddressPurpose.Ordinals ? -1 : 1)
|
|
238
222
|
.map((account) => account.address);
|
|
223
|
+
[ordinalsAccount, paymentAccount] = connectedAccounts;
|
|
239
224
|
}
|
|
240
225
|
const currentConnectedAccounts = yield this.getConnectedAccountsFromCache();
|
|
241
226
|
// don't do anything if the connected accounts haven't changed
|
|
@@ -247,6 +232,14 @@ class BitcoinWalletConnector extends WalletConnectorBase {
|
|
|
247
232
|
// set the last account change request with the from and to addresses
|
|
248
233
|
// to ensure that the requests are not duplicated
|
|
249
234
|
this.setLastAccountChangeRequest(connectedAccounts[0]);
|
|
235
|
+
if (ordinalsAccount || paymentAccount) {
|
|
236
|
+
this.setConnectedAccountWithAddresses({
|
|
237
|
+
active: true,
|
|
238
|
+
mainAddress: ordinalsAccount !== null && ordinalsAccount !== void 0 ? ordinalsAccount : paymentAccount,
|
|
239
|
+
ordinalsAddress: ordinalsAccount,
|
|
240
|
+
paymentAddress: paymentAccount,
|
|
241
|
+
});
|
|
242
|
+
}
|
|
250
243
|
handleAccountChange(connectedAccounts);
|
|
251
244
|
});
|
|
252
245
|
provider.on('accountsChanged', handleBitcoinAccountChange);
|
|
@@ -27,7 +27,7 @@ class PhantomConnector extends BitcoinWalletConnector.BitcoinWalletConnector {
|
|
|
27
27
|
const { accounts } = yield this.walletMethods.connect();
|
|
28
28
|
const parsedAccounts = accounts.map((account) => ({
|
|
29
29
|
address: account.address,
|
|
30
|
-
publicKey: Buffer.from(account.publicKey).toString('
|
|
30
|
+
publicKey: Buffer.from(account.publicKey).toString('hex'),
|
|
31
31
|
}));
|
|
32
32
|
[paymentAccount, ordinalsAccount] = parsedAccounts;
|
|
33
33
|
// in case it only returns one account, we will use it as both payment and ordinals
|
|
@@ -23,7 +23,7 @@ class PhantomConnector extends BitcoinWalletConnector {
|
|
|
23
23
|
const { accounts } = yield this.walletMethods.connect();
|
|
24
24
|
const parsedAccounts = accounts.map((account) => ({
|
|
25
25
|
address: account.address,
|
|
26
|
-
publicKey: Buffer.from(account.publicKey).toString('
|
|
26
|
+
publicKey: Buffer.from(account.publicKey).toString('hex'),
|
|
27
27
|
}));
|
|
28
28
|
[paymentAccount, ordinalsAccount] = parsedAccounts;
|
|
29
29
|
// in case it only returns one account, we will use it as both payment and ordinals
|
|
@@ -5,12 +5,12 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
|
|
6
6
|
var _const = require('../../const.cjs');
|
|
7
7
|
require('../../../_virtual/_tslib.cjs');
|
|
8
|
+
require('sats-connect');
|
|
8
9
|
require('@dynamic-labs/wallet-connector-core');
|
|
9
10
|
require('@dynamic-labs/wallet-book');
|
|
10
11
|
require('@dynamic-labs/utils');
|
|
11
12
|
require('@dynamic-labs/sdk-api-core');
|
|
12
13
|
require('@wallet-standard/app');
|
|
13
|
-
require('sats-connect');
|
|
14
14
|
require('bitcoinjs-lib');
|
|
15
15
|
var BitcoinSatsConnectConnector = require('../../connectors/BitcoinSatsConnectConnector/BitcoinSatsConnectConnector.cjs');
|
|
16
16
|
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
'use client'
|
|
2
2
|
import { SATSCONNECT_FEATURE } from '../../const.js';
|
|
3
3
|
import '../../../_virtual/_tslib.js';
|
|
4
|
+
import 'sats-connect';
|
|
4
5
|
import '@dynamic-labs/wallet-connector-core';
|
|
5
6
|
import '@dynamic-labs/wallet-book';
|
|
6
7
|
import '@dynamic-labs/utils';
|
|
7
8
|
import '@dynamic-labs/sdk-api-core';
|
|
8
9
|
import '@wallet-standard/app';
|
|
9
|
-
import 'sats-connect';
|
|
10
10
|
import 'bitcoinjs-lib';
|
|
11
11
|
import { BitcoinSatsConnectConnector } from '../../connectors/BitcoinSatsConnectConnector/BitcoinSatsConnectConnector.js';
|
|
12
12
|
|