FIX: BugSnag would cycle through sendEvents in offline mode

This commit is contained in:
Marcos Rodriguez Vélez 2021-08-28 01:12:50 -04:00
parent f15f5aa0da
commit 751b526e42
3 changed files with 21 additions and 0 deletions

View file

@ -313,6 +313,7 @@ async function getRandomDynamicPeer() {
* @returns {Promise<Object>}
*/
module.exports.getBalanceByAddress = async function (address) {
if (await isDisabled()) return;
if (!mainClient) throw new Error('Electrum client is not connected');
const script = bitcoin.address.toOutputScript(address);
const hash = bitcoin.crypto.sha256(script);
@ -323,6 +324,10 @@ module.exports.getBalanceByAddress = async function (address) {
};
module.exports.getConfig = async function () {
if (await isDisabled())
return {
connected: 0,
};
if (!mainClient) throw new Error('Electrum client is not connected');
return {
host: mainClient.host,
@ -342,6 +347,7 @@ module.exports.getSecondsSinceLastRequest = function () {
* @returns {Promise<Array>}
*/
module.exports.getTransactionsByAddress = async function (address) {
if (await isDisabled()) return;
if (!mainClient) throw new Error('Electrum client is not connected');
const script = bitcoin.address.toOutputScript(address);
const hash = bitcoin.crypto.sha256(script);
@ -404,6 +410,7 @@ module.exports.getTransactionsFullByAddress = async function (address) {
* @returns {Promise<{balance: number, unconfirmed_balance: number, addresses: object}>}
*/
module.exports.multiGetBalanceByAddress = async function (addresses, batchsize) {
if (await isDisabled()) return;
batchsize = batchsize || 200;
if (!mainClient) throw new Error('Electrum client is not connected');
const ret = { balance: 0, unconfirmed_balance: 0, addresses: {} };
@ -450,6 +457,7 @@ module.exports.multiGetBalanceByAddress = async function (addresses, batchsize)
};
module.exports.multiGetUtxoByAddress = async function (addresses, batchsize) {
if (await isDisabled()) return;
batchsize = batchsize || 100;
if (!mainClient) throw new Error('Electrum client is not connected');
const ret = {};
@ -493,6 +501,7 @@ module.exports.multiGetUtxoByAddress = async function (addresses, batchsize) {
};
module.exports.multiGetHistoryByAddress = async function (addresses, batchsize) {
if (await isDisabled()) return;
batchsize = batchsize || 100;
if (!mainClient) throw new Error('Electrum client is not connected');
const ret = {};
@ -544,6 +553,7 @@ module.exports.multiGetHistoryByAddress = async function (addresses, batchsize)
};
module.exports.multiGetTransactionByTxid = async function (txids, batchsize, verbose = true) {
if (await isDisabled()) return;
batchsize = batchsize || 45;
// this value is fine-tuned so althrough wallets in test suite will occasionally
// throw 'response too large (over 1,000,000 bytes', test suite will pass
@ -779,6 +789,7 @@ module.exports.estimateFees = async function () {
* @returns {Promise<number>} Satoshis per byte
*/
module.exports.estimateFee = async function (numberOfBlocks) {
if (await isDisabled()) return;
if (!mainClient) throw new Error('Electrum client is not connected');
numberOfBlocks = numberOfBlocks || 1;
const coinUnitsPerKilobyte = await mainClient.blockchainEstimatefee(numberOfBlocks);
@ -787,11 +798,13 @@ module.exports.estimateFee = async function (numberOfBlocks) {
};
module.exports.serverFeatures = async function () {
if (await isDisabled()) return;
if (!mainClient) throw new Error('Electrum client is not connected');
return mainClient.server_features();
};
module.exports.broadcast = async function (hex) {
if (await isDisabled()) return;
if (!mainClient) throw new Error('Electrum client is not connected');
try {
const broadcast = await mainClient.blockchainTransaction_broadcast(hex);
@ -802,6 +815,7 @@ module.exports.broadcast = async function (hex) {
};
module.exports.broadcastV2 = async function (hex) {
if (await isDisabled()) return;
if (!mainClient) throw new Error('Electrum client is not connected');
return mainClient.blockchainTransaction_broadcast(hex);
};

View file

@ -246,6 +246,7 @@
"about_release_notes": "Release notes",
"about_review": "Leave us a review",
"about_selftest": "Run self-test",
"about_selftest_electrum_disabled": "Offline mode enabled. Unable to proceed with tests. Please disable Offline Mode and try again.",
"about_selftest_ok": "All internal tests have passed successfully. The wallet works well.",
"about_sm_github": "GitHub",
"about_sm_discord": "Discord Server",

View file

@ -15,6 +15,7 @@ import {
HDAezeedWallet,
SLIP39LegacyP2PKHWallet,
} from '../class';
import { BlueStorageContext } from '../blue_modules/storage-context';
const bitcoin = require('bitcoinjs-lib');
const BlueCrypto = require('react-native-blue-crypto');
const encryption = require('../blue_modules/encryption');
@ -27,6 +28,7 @@ const styles = StyleSheet.create({
});
export default class Selftest extends Component {
static contextType = BlueStorageContext;
constructor(props) {
super(props);
this.state = {
@ -55,6 +57,10 @@ export default class Selftest extends Component {
//
if (this.context.isElectrumDisabled) {
throw new Error(loc.settings.about_selftest_electrum_disabled);
}
if (typeof navigator !== 'undefined' && navigator.product === 'ReactNative') {
await BlueElectrum.ping();
await BlueElectrum.waitTillConnected();