@multiplechain/bitcoin 0.1.4 → 0.1.6
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/package.json +1 -1
- package/src/adapters/unisat.js +3 -2
- package/src/provider.js +26 -32
- package/src/wallet.js +9 -15
package/package.json
CHANGED
package/src/adapters/unisat.js
CHANGED
|
@@ -27,9 +27,10 @@ module.exports = unisat = (provider) => {
|
|
|
27
27
|
return {
|
|
28
28
|
key: 'unisat',
|
|
29
29
|
name: 'UniSat',
|
|
30
|
-
|
|
30
|
+
supports: ['browser'],
|
|
31
31
|
wallet,
|
|
32
32
|
connect,
|
|
33
|
-
download: 'https://unisat.io/download'
|
|
33
|
+
download: 'https://unisat.io/download',
|
|
34
|
+
detected: Boolean(typeof window.unisat !== 'undefined' && window.unisat.requestAccounts)
|
|
34
35
|
}
|
|
35
36
|
}
|
package/src/provider.js
CHANGED
|
@@ -44,9 +44,13 @@ class Provider {
|
|
|
44
44
|
*/
|
|
45
45
|
connectedWallet;
|
|
46
46
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
47
|
+
/**
|
|
48
|
+
* @param {Object} options
|
|
49
|
+
*/
|
|
50
|
+
constructor(options) {
|
|
51
|
+
|
|
52
|
+
this.testnet = options.testnet;
|
|
53
|
+
this.network = options.testnet ? 'testnet' : 'livenet';
|
|
50
54
|
|
|
51
55
|
if (!this.testnet) {
|
|
52
56
|
this.api = "https://blockstream.info/api/";
|
|
@@ -65,32 +69,6 @@ class Provider {
|
|
|
65
69
|
return 'bitcoin' + ':' + String(address).toUpperCase() + '?amount=' + amount;
|
|
66
70
|
}
|
|
67
71
|
|
|
68
|
-
errorCheck(data) {
|
|
69
|
-
if (typeof data == 'string') {
|
|
70
|
-
if (data == 'Address on invalid network') {
|
|
71
|
-
return {
|
|
72
|
-
error: 'invalid-address'
|
|
73
|
-
}
|
|
74
|
-
} else {
|
|
75
|
-
return {
|
|
76
|
-
error: 'any-error'
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
} else if (data.error) {
|
|
80
|
-
if (data.error == 'not-found-or-invalid-arg') {
|
|
81
|
-
return {
|
|
82
|
-
error: 'invalid-address'
|
|
83
|
-
}
|
|
84
|
-
} else {
|
|
85
|
-
return {
|
|
86
|
-
error: 'any-error'
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
return data;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
72
|
listenTransactions(options, callback) {
|
|
95
73
|
let receiver = options.receiver;
|
|
96
74
|
let ws = new WebSocket(this.wsUrl);
|
|
@@ -152,13 +130,29 @@ class Provider {
|
|
|
152
130
|
}
|
|
153
131
|
|
|
154
132
|
/**
|
|
155
|
-
* @param {Array} filter
|
|
133
|
+
* @param {Array|null} filter
|
|
134
|
+
* @returns {Array}
|
|
135
|
+
*/
|
|
136
|
+
getSupportedWallets(filter) {
|
|
137
|
+
|
|
138
|
+
const Wallet = require('./wallet');
|
|
139
|
+
|
|
140
|
+
const wallets = {
|
|
141
|
+
unisat: new Wallet('unisat', this)
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
return Object.fromEntries(Object.entries(wallets).filter(([key]) => {
|
|
145
|
+
return !filter ? true : filter.includes(key);
|
|
146
|
+
}));
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* @param {Array|null} filter
|
|
156
151
|
* @returns {Array}
|
|
157
152
|
*/
|
|
158
153
|
getDetectedWallets(filter) {
|
|
159
|
-
if (!filter) return this.detectedWallets;
|
|
160
154
|
return Object.fromEntries(Object.entries(this.detectedWallets).filter(([key]) => {
|
|
161
|
-
return filter.includes(key);
|
|
155
|
+
return !filter ? true : filter.includes(key);
|
|
162
156
|
}));
|
|
163
157
|
}
|
|
164
158
|
|
package/src/wallet.js
CHANGED
|
@@ -57,8 +57,8 @@ class Wallet {
|
|
|
57
57
|
/**
|
|
58
58
|
* @returns {String}
|
|
59
59
|
*/
|
|
60
|
-
|
|
61
|
-
return this.adapter.
|
|
60
|
+
getSupports() {
|
|
61
|
+
return this.adapter.supports;
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
/**
|
|
@@ -75,21 +75,18 @@ class Wallet {
|
|
|
75
75
|
return this.adapter.download;
|
|
76
76
|
}
|
|
77
77
|
|
|
78
|
+
/**
|
|
79
|
+
* @returns {Boolean}
|
|
80
|
+
*/
|
|
81
|
+
isDetected() {
|
|
82
|
+
return this.adapter.detected;
|
|
83
|
+
}
|
|
84
|
+
|
|
78
85
|
/**
|
|
79
86
|
* @returns {String}
|
|
80
87
|
*/
|
|
81
88
|
connect() {
|
|
82
89
|
return new Promise((resolve, reject) => {
|
|
83
|
-
let time = 0;
|
|
84
|
-
let timeout = 15;
|
|
85
|
-
let timer = setInterval(async () => {
|
|
86
|
-
time += 1;
|
|
87
|
-
if (time > timeout) {
|
|
88
|
-
clearInterval(timer);
|
|
89
|
-
reject('timeout');
|
|
90
|
-
}
|
|
91
|
-
}, 1000);
|
|
92
|
-
|
|
93
90
|
this.adapter.connect()
|
|
94
91
|
.then(async (connectedAccount) => {
|
|
95
92
|
let network = await this.wallet.getNetwork();
|
|
@@ -102,9 +99,6 @@ class Wallet {
|
|
|
102
99
|
})
|
|
103
100
|
.catch((error) => {
|
|
104
101
|
utils.rejectMessage(error, reject);
|
|
105
|
-
})
|
|
106
|
-
.finally(() => {
|
|
107
|
-
clearInterval(timer);
|
|
108
102
|
});
|
|
109
103
|
});
|
|
110
104
|
}
|